jquery.jqGrid.src.js 422 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367
  1. // ==ClosureCompiler==
  2. // @compilation_level SIMPLE_OPTIMIZATIONS
  3. /*
  4. * @license jqGrid 4.4.3 - jQuery Grid
  5. * Copyright (c) 2008, Tony Tomov, tony@trirand.com
  6. * Dual licensed under the MIT and GPL licenses
  7. * http://www.opensource.org/licenses/mit-license.php
  8. * http://www.gnu.org/licenses/gpl-2.0.html
  9. * Date: 2013-01-21
  10. */
  11. //jsHint options
  12. /*jshint evil:true, eqeqeq:false, eqnull:true, devel:true */
  13. /*global jQuery, DOMParser, ActiveXObject */
  14. (function ($) {
  15. "use strict";
  16. $.jgrid = $.jgrid || {};
  17. $.extend($.jgrid,{
  18. version : "4.4.3",
  19. htmlDecode : function(value){
  20. if(value && (value==' ' || value==' ' || (value.length===1 && value.charCodeAt(0)===160))) { return "";}
  21. return !value ? value : String(value).replace(/&gt;/g, ">").replace(/&lt;/g, "<").replace(/&quot;/g, '"').replace(/&amp;/g, "&");
  22. },
  23. htmlEncode : function (value){
  24. return !value ? value : String(value).replace(/&/g, "&amp;").replace(/\"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
  25. },
  26. format : function(format){ //jqgformat
  27. var args = $.makeArray(arguments).slice(1);
  28. if(format==null) { format = ""; }
  29. return format.replace(/\{(\d+)\}/g, function(m, i){
  30. return args[i];
  31. });
  32. },
  33. getCellIndex : function (cell) {
  34. var c = $(cell);
  35. if (c.is('tr')) { return -1; }
  36. c = (!c.is('td') && !c.is('th') ? c.closest("td,th") : c)[0];
  37. if ($.browser.msie) { return $.inArray(c, c.parentNode.cells); }
  38. return c.cellIndex;
  39. },
  40. stripHtml : function(v) {
  41. v = String(v);
  42. var regexp = /<("[^"]*"|'[^']*'|[^'">])*>/gi;
  43. if (v) {
  44. v = v.replace(regexp,"");
  45. return (v && v !== '&nbsp;' && v !== '&#160;') ? v.replace(/\"/g,"'") : "";
  46. }
  47. return v;
  48. },
  49. stripPref : function (pref, id) {
  50. var obj = $.type( pref );
  51. if( obj == "string" || obj =="number") {
  52. pref = String(pref);
  53. id = pref !== "" ? String(id).replace(String(pref), "") : id;
  54. }
  55. return id;
  56. },
  57. stringToDoc : function (xmlString) {
  58. var xmlDoc;
  59. if(typeof xmlString !== 'string') { return xmlString; }
  60. try {
  61. var parser = new DOMParser();
  62. xmlDoc = parser.parseFromString(xmlString,"text/xml");
  63. }
  64. catch(e) {
  65. xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
  66. xmlDoc.async=false;
  67. xmlDoc.loadXML(xmlString);
  68. }
  69. return (xmlDoc && xmlDoc.documentElement && xmlDoc.documentElement.tagName != 'parsererror') ? xmlDoc : null;
  70. },
  71. parse : function(jsonString) {
  72. var js = jsonString;
  73. if (js.substr(0,9) == "while(1);") { js = js.substr(9); }
  74. if (js.substr(0,2) == "/*") { js = js.substr(2,js.length-4); }
  75. if(!js) { js = "{}"; }
  76. return ($.jgrid.useJSON===true && typeof JSON === 'object' && typeof JSON.parse === 'function') ?
  77. JSON.parse(js) :
  78. eval('(' + js + ')');
  79. },
  80. parseDate : function(format, date) {
  81. var tsp = {m : 1, d : 1, y : 1970, h : 0, i : 0, s : 0, u:0},k,hl,dM, regdate = /[\\\/:_;.,\t\T\s-]/;
  82. if(date && date != null){
  83. date = $.trim(date);
  84. date = date.split(regdate);
  85. if ($.jgrid.formatter.date.masks[format] !== undefined) {
  86. format = $.jgrid.formatter.date.masks[format];
  87. }
  88. format = format.split(regdate);
  89. var dfmt = $.jgrid.formatter.date.monthNames;
  90. var afmt = $.jgrid.formatter.date.AmPm;
  91. var h12to24 = function(ampm, h){
  92. if (ampm === 0){ if (h === 12) { h = 0;} }
  93. else { if (h !== 12) { h += 12; } }
  94. return h;
  95. };
  96. for(k=0,hl=format.length;k<hl;k++){
  97. if(format[k] == 'M') {
  98. dM = $.inArray(date[k],dfmt);
  99. if(dM !== -1 && dM < 12){
  100. date[k] = dM+1;
  101. tsp.m = date[k];
  102. }
  103. }
  104. if(format[k] == 'F') {
  105. dM = $.inArray(date[k],dfmt);
  106. if(dM !== -1 && dM > 11){
  107. date[k] = dM+1-12;
  108. tsp.m = date[k];
  109. }
  110. }
  111. if(format[k] == 'a') {
  112. dM = $.inArray(date[k],afmt);
  113. if(dM !== -1 && dM < 2 && date[k] == afmt[dM]){
  114. date[k] = dM;
  115. tsp.h = h12to24(date[k], tsp.h);
  116. }
  117. }
  118. if(format[k] == 'A') {
  119. dM = $.inArray(date[k],afmt);
  120. if(dM !== -1 && dM > 1 && date[k] == afmt[dM]){
  121. date[k] = dM-2;
  122. tsp.h = h12to24(date[k], tsp.h);
  123. }
  124. }
  125. if (format[k] === 'g') {
  126. tsp.h = parseInt(date[k], 10);
  127. }
  128. if(date[k] !== undefined) {
  129. tsp[format[k].toLowerCase()] = parseInt(date[k],10);
  130. }
  131. }
  132. tsp.m = parseInt(tsp.m,10)-1;
  133. var ty = tsp.y;
  134. if (ty >= 70 && ty <= 99) {tsp.y = 1900+tsp.y;}
  135. else if (ty >=0 && ty <=69) {tsp.y= 2000+tsp.y;}
  136. if(tsp.j !== undefined) { tsp.d = tsp.j; }
  137. if(tsp.n !== undefined) { tsp.m = parseInt(tsp.n,10)-1; }
  138. }
  139. return new Date(tsp.y, tsp.m, tsp.d, tsp.h, tsp.i, tsp.s, tsp.u);
  140. },
  141. jqID : function(sid){
  142. return String(sid).replace(/[!"#$%&'()*+,.\/:;<=>?@\[\\\]\^`{|}~]/g,"\\$&");
  143. },
  144. guid : 1,
  145. uidPref: 'jqg',
  146. randId : function( prefix ) {
  147. return (prefix || $.jgrid.uidPref) + ($.jgrid.guid++);
  148. },
  149. getAccessor : function(obj, expr) {
  150. var ret,p,prm = [], i;
  151. if( typeof expr === 'function') { return expr(obj); }
  152. ret = obj[expr];
  153. if(ret===undefined) {
  154. try {
  155. if ( typeof expr === 'string' ) {
  156. prm = expr.split('.');
  157. }
  158. i = prm.length;
  159. if( i ) {
  160. ret = obj;
  161. while (ret && i--) {
  162. p = prm.shift();
  163. ret = ret[p];
  164. }
  165. }
  166. } catch (e) {}
  167. }
  168. return ret;
  169. },
  170. getXmlData: function (obj, expr, returnObj) {
  171. var ret, m = typeof expr === 'string' ? expr.match(/^(.*)\[(\w+)\]$/) : null;
  172. if (typeof expr === 'function') { return expr(obj); }
  173. if (m && m[2]) {
  174. // m[2] is the attribute selector
  175. // m[1] is an optional element selector
  176. // examples: "[id]", "rows[page]"
  177. return m[1] ? $(m[1], obj).attr(m[2]) : $(obj).attr(m[2]);
  178. }
  179. ret = $(expr, obj);
  180. if (returnObj) { return ret; }
  181. //$(expr, obj).filter(':last'); // we use ':last' to be more compatible with old version of jqGrid
  182. return ret.length > 0 ? $(ret).text() : undefined;
  183. },
  184. cellWidth : function () {
  185. var $testDiv = $("<div class='ui-jqgrid' style='left:10000px'><table class='ui-jqgrid-btable' style='width:5px;'><tr class='jqgrow'><td style='width:5px;'></td></tr></table></div>"),
  186. testCell = $testDiv.appendTo("body")
  187. .find("td")
  188. .width();
  189. $testDiv.remove();
  190. return testCell !== 5;
  191. },
  192. cell_width : true,
  193. ajaxOptions: {},
  194. from : function(source){
  195. // Original Author Hugo Bonacci
  196. // License MIT http://jlinq.codeplex.com/license
  197. var QueryObject=function(d,q){
  198. if(typeof d==="string"){
  199. d=$.data(d);
  200. }
  201. var self=this,
  202. _data=d,
  203. _usecase=true,
  204. _trim=false,
  205. _query=q,
  206. _stripNum = /[\$,%]/g,
  207. _lastCommand=null,
  208. _lastField=null,
  209. _orDepth=0,
  210. _negate=false,
  211. _queuedOperator="",
  212. _sorting=[],
  213. _useProperties=true;
  214. if(typeof d==="object"&&d.push) {
  215. if(d.length>0){
  216. if(typeof d[0]!=="object"){
  217. _useProperties=false;
  218. }else{
  219. _useProperties=true;
  220. }
  221. }
  222. }else{
  223. throw "data provides is not an array";
  224. }
  225. this._hasData=function(){
  226. return _data===null?false:_data.length===0?false:true;
  227. };
  228. this._getStr=function(s){
  229. var phrase=[];
  230. if(_trim){
  231. phrase.push("jQuery.trim(");
  232. }
  233. phrase.push("String("+s+")");
  234. if(_trim){
  235. phrase.push(")");
  236. }
  237. if(!_usecase){
  238. phrase.push(".toLowerCase()");
  239. }
  240. return phrase.join("");
  241. };
  242. this._strComp=function(val){
  243. if(typeof val==="string"){
  244. return".toString()";
  245. }
  246. return"";
  247. };
  248. this._group=function(f,u){
  249. return({field:f.toString(),unique:u,items:[]});
  250. };
  251. this._toStr=function(phrase){
  252. if(_trim){
  253. phrase=$.trim(phrase);
  254. }
  255. phrase=phrase.toString().replace(/\\/g,'\\\\').replace(/\"/g,'\\"');
  256. return _usecase ? phrase : phrase.toLowerCase();
  257. };
  258. this._funcLoop=function(func){
  259. var results=[];
  260. $.each(_data,function(i,v){
  261. results.push(func(v));
  262. });
  263. return results;
  264. };
  265. this._append=function(s){
  266. var i;
  267. if(_query===null){
  268. _query="";
  269. } else {
  270. _query+=_queuedOperator === "" ? " && " :_queuedOperator;
  271. }
  272. for (i=0;i<_orDepth;i++){
  273. _query+="(";
  274. }
  275. if(_negate){
  276. _query+="!";
  277. }
  278. _query+="("+s+")";
  279. _negate=false;
  280. _queuedOperator="";
  281. _orDepth=0;
  282. };
  283. this._setCommand=function(f,c){
  284. _lastCommand=f;
  285. _lastField=c;
  286. };
  287. this._resetNegate=function(){
  288. _negate=false;
  289. };
  290. this._repeatCommand=function(f,v){
  291. if(_lastCommand===null){
  292. return self;
  293. }
  294. if(f!==null&&v!==null){
  295. return _lastCommand(f,v);
  296. }
  297. if(_lastField===null){
  298. return _lastCommand(f);
  299. }
  300. if(!_useProperties){
  301. return _lastCommand(f);
  302. }
  303. return _lastCommand(_lastField,f);
  304. };
  305. this._equals=function(a,b){
  306. return(self._compare(a,b,1)===0);
  307. };
  308. this._compare=function(a,b,d){
  309. var toString = Object.prototype.toString;
  310. if( d === undefined) { d = 1; }
  311. if(a===undefined) { a = null; }
  312. if(b===undefined) { b = null; }
  313. if(a===null && b===null){
  314. return 0;
  315. }
  316. if(a===null&&b!==null){
  317. return 1;
  318. }
  319. if(a!==null&&b===null){
  320. return -1;
  321. }
  322. if (toString.call(a) === '[object Date]' && toString.call(b) === '[object Date]') {
  323. if (a < b) { return -d; }
  324. if (a > b) { return d; }
  325. return 0;
  326. }
  327. if(!_usecase && typeof a !== "number" && typeof b !== "number" ) {
  328. a=String(a);
  329. b=String(b);
  330. }
  331. if(a<b){return -d;}
  332. if(a>b){return d;}
  333. return 0;
  334. };
  335. this._performSort=function(){
  336. if(_sorting.length===0){return;}
  337. _data=self._doSort(_data,0);
  338. };
  339. this._doSort=function(d,q){
  340. var by=_sorting[q].by,
  341. dir=_sorting[q].dir,
  342. type = _sorting[q].type,
  343. dfmt = _sorting[q].datefmt;
  344. if(q==_sorting.length-1){
  345. return self._getOrder(d, by, dir, type, dfmt);
  346. }
  347. q++;
  348. var values=self._getGroup(d,by,dir,type,dfmt), results=[], i, j, sorted;
  349. for(i=0;i<values.length;i++){
  350. sorted=self._doSort(values[i].items,q);
  351. for(j=0;j<sorted.length;j++){
  352. results.push(sorted[j]);
  353. }
  354. }
  355. return results;
  356. };
  357. this._getOrder=function(data,by,dir,type, dfmt){
  358. var sortData=[],_sortData=[], newDir = dir=="a" ? 1 : -1, i,ab,j,
  359. findSortKey;
  360. if(type === undefined ) { type = "text"; }
  361. if (type == 'float' || type== 'number' || type== 'currency' || type== 'numeric') {
  362. findSortKey = function($cell) {
  363. var key = parseFloat( String($cell).replace(_stripNum, ''));
  364. return isNaN(key) ? 0.00 : key;
  365. };
  366. } else if (type=='int' || type=='integer') {
  367. findSortKey = function($cell) {
  368. return $cell ? parseFloat(String($cell).replace(_stripNum, '')) : 0;
  369. };
  370. } else if(type == 'date' || type == 'datetime') {
  371. findSortKey = function($cell) {
  372. return $.jgrid.parseDate(dfmt,$cell).getTime();
  373. };
  374. } else if($.isFunction(type)) {
  375. findSortKey = type;
  376. } else {
  377. findSortKey = function($cell) {
  378. $cell = $cell ? $.trim(String($cell)) : "";
  379. return _usecase ? $cell : $cell.toLowerCase();
  380. };
  381. }
  382. $.each(data,function(i,v){
  383. ab = by!=="" ? $.jgrid.getAccessor(v,by) : v;
  384. if(ab === undefined) { ab = ""; }
  385. ab = findSortKey(ab, v);
  386. _sortData.push({ 'vSort': ab,'index':i});
  387. });
  388. _sortData.sort(function(a,b){
  389. a = a.vSort;
  390. b = b.vSort;
  391. return self._compare(a,b,newDir);
  392. });
  393. j=0;
  394. var nrec= data.length;
  395. // overhead, but we do not change the original data.
  396. while(j<nrec) {
  397. i = _sortData[j].index;
  398. sortData.push(data[i]);
  399. j++;
  400. }
  401. return sortData;
  402. };
  403. this._getGroup=function(data,by,dir,type, dfmt){
  404. var results=[],
  405. group=null,
  406. last=null, val;
  407. $.each(self._getOrder(data,by,dir,type, dfmt),function(i,v){
  408. val = $.jgrid.getAccessor(v, by);
  409. if(val == null) { val = ""; }
  410. if(!self._equals(last,val)){
  411. last=val;
  412. if(group !== null){
  413. results.push(group);
  414. }
  415. group=self._group(by,val);
  416. }
  417. group.items.push(v);
  418. });
  419. if(group !== null){
  420. results.push(group);
  421. }
  422. return results;
  423. };
  424. this.ignoreCase=function(){
  425. _usecase=false;
  426. return self;
  427. };
  428. this.useCase=function(){
  429. _usecase=true;
  430. return self;
  431. };
  432. this.trim=function(){
  433. _trim=true;
  434. return self;
  435. };
  436. this.noTrim=function(){
  437. _trim=false;
  438. return self;
  439. };
  440. this.execute=function(){
  441. var match=_query, results=[];
  442. if(match === null){
  443. return self;
  444. }
  445. $.each(_data,function(){
  446. if(eval(match)){results.push(this);}
  447. });
  448. _data=results;
  449. return self;
  450. };
  451. this.data=function(){
  452. return _data;
  453. };
  454. this.select=function(f){
  455. self._performSort();
  456. if(!self._hasData()){ return[]; }
  457. self.execute();
  458. if($.isFunction(f)){
  459. var results=[];
  460. $.each(_data,function(i,v){
  461. results.push(f(v));
  462. });
  463. return results;
  464. }
  465. return _data;
  466. };
  467. this.hasMatch=function(){
  468. if(!self._hasData()) { return false; }
  469. self.execute();
  470. return _data.length>0;
  471. };
  472. this.andNot=function(f,v,x){
  473. _negate=!_negate;
  474. return self.and(f,v,x);
  475. };
  476. this.orNot=function(f,v,x){
  477. _negate=!_negate;
  478. return self.or(f,v,x);
  479. };
  480. this.not=function(f,v,x){
  481. return self.andNot(f,v,x);
  482. };
  483. this.and=function(f,v,x){
  484. _queuedOperator=" && ";
  485. if(f===undefined){
  486. return self;
  487. }
  488. return self._repeatCommand(f,v,x);
  489. };
  490. this.or=function(f,v,x){
  491. _queuedOperator=" || ";
  492. if(f===undefined) { return self; }
  493. return self._repeatCommand(f,v,x);
  494. };
  495. this.orBegin=function(){
  496. _orDepth++;
  497. return self;
  498. };
  499. this.orEnd=function(){
  500. if (_query !== null){
  501. _query+=")";
  502. }
  503. return self;
  504. };
  505. this.isNot=function(f){
  506. _negate=!_negate;
  507. return self.is(f);
  508. };
  509. this.is=function(f){
  510. self._append('this.'+f);
  511. self._resetNegate();
  512. return self;
  513. };
  514. this._compareValues=function(func,f,v,how,t){
  515. var fld;
  516. if(_useProperties){
  517. fld='jQuery.jgrid.getAccessor(this,\''+f+'\')';
  518. }else{
  519. fld='this';
  520. }
  521. if(v===undefined) { v = null; }
  522. //var val=v===null?f:v,
  523. var val =v,
  524. swst = t.stype === undefined ? "text" : t.stype;
  525. if(v !== null) {
  526. switch(swst) {
  527. case 'int':
  528. case 'integer':
  529. val = (isNaN(Number(val)) || val==="") ? '0' : val; // To be fixed with more inteligent code
  530. fld = 'parseInt('+fld+',10)';
  531. val = 'parseInt('+val+',10)';
  532. break;
  533. case 'float':
  534. case 'number':
  535. case 'numeric':
  536. val = String(val).replace(_stripNum, '');
  537. val = (isNaN(Number(val)) || val==="") ? '0' : val; // To be fixed with more inteligent code
  538. fld = 'parseFloat('+fld+')';
  539. val = 'parseFloat('+val+')';
  540. break;
  541. case 'date':
  542. case 'datetime':
  543. val = String($.jgrid.parseDate(t.newfmt || 'Y-m-d',val).getTime());
  544. fld = 'jQuery.jgrid.parseDate("'+t.srcfmt+'",'+fld+').getTime()';
  545. break;
  546. default :
  547. fld=self._getStr(fld);
  548. val=self._getStr('"'+self._toStr(val)+'"');
  549. }
  550. }
  551. self._append(fld+' '+how+' '+val);
  552. self._setCommand(func,f);
  553. self._resetNegate();
  554. return self;
  555. };
  556. this.equals=function(f,v,t){
  557. return self._compareValues(self.equals,f,v,"==",t);
  558. };
  559. this.notEquals=function(f,v,t){
  560. return self._compareValues(self.equals,f,v,"!==",t);
  561. };
  562. this.isNull = function(f,v,t){
  563. return self._compareValues(self.equals,f,null,"===",t);
  564. };
  565. this.greater=function(f,v,t){
  566. return self._compareValues(self.greater,f,v,">",t);
  567. };
  568. this.less=function(f,v,t){
  569. return self._compareValues(self.less,f,v,"<",t);
  570. };
  571. this.greaterOrEquals=function(f,v,t){
  572. return self._compareValues(self.greaterOrEquals,f,v,">=",t);
  573. };
  574. this.lessOrEquals=function(f,v,t){
  575. return self._compareValues(self.lessOrEquals,f,v,"<=",t);
  576. };
  577. this.startsWith=function(f,v){
  578. var val = (v==null) ? f: v,
  579. length=_trim ? $.trim(val.toString()).length : val.toString().length;
  580. if(_useProperties){
  581. self._append(self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.substr(0,'+length+') == '+self._getStr('"'+self._toStr(v)+'"'));
  582. }else{
  583. length=_trim?$.trim(v.toString()).length:v.toString().length;
  584. self._append(self._getStr('this')+'.substr(0,'+length+') == '+self._getStr('"'+self._toStr(f)+'"'));
  585. }
  586. self._setCommand(self.startsWith,f);
  587. self._resetNegate();
  588. return self;
  589. };
  590. this.endsWith=function(f,v){
  591. var val = (v==null) ? f: v,
  592. length=_trim ? $.trim(val.toString()).length:val.toString().length;
  593. if(_useProperties){
  594. self._append(self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.substr('+self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.length-'+length+','+length+') == "'+self._toStr(v)+'"');
  595. } else {
  596. self._append(self._getStr('this')+'.substr('+self._getStr('this')+'.length-"'+self._toStr(f)+'".length,"'+self._toStr(f)+'".length) == "'+self._toStr(f)+'"');
  597. }
  598. self._setCommand(self.endsWith,f);self._resetNegate();
  599. return self;
  600. };
  601. this.contains=function(f,v){
  602. if(_useProperties){
  603. self._append(self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.indexOf("'+self._toStr(v)+'",0) > -1');
  604. }else{
  605. self._append(self._getStr('this')+'.indexOf("'+self._toStr(f)+'",0) > -1');
  606. }
  607. self._setCommand(self.contains,f);
  608. self._resetNegate();
  609. return self;
  610. };
  611. this.groupBy=function(by,dir,type, datefmt){
  612. if(!self._hasData()){
  613. return null;
  614. }
  615. return self._getGroup(_data,by,dir,type, datefmt);
  616. };
  617. this.orderBy=function(by,dir,stype, dfmt){
  618. dir = dir == null ? "a" :$.trim(dir.toString().toLowerCase());
  619. if(stype == null) { stype = "text"; }
  620. if(dfmt == null) { dfmt = "Y-m-d"; }
  621. if(dir=="desc"||dir=="descending"){dir="d";}
  622. if(dir=="asc"||dir=="ascending"){dir="a";}
  623. _sorting.push({by:by,dir:dir,type:stype, datefmt: dfmt});
  624. return self;
  625. };
  626. return self;
  627. };
  628. return new QueryObject(source,null);
  629. },
  630. getMethod: function (name) {
  631. return this.getAccessor($.fn.jqGrid, name);
  632. },
  633. extend : function(methods) {
  634. $.extend($.fn.jqGrid,methods);
  635. if (!this.no_legacy_api) {
  636. $.fn.extend(methods);
  637. }
  638. }
  639. });
  640. $.fn.jqGrid = function( pin ) {
  641. if (typeof pin === 'string') {
  642. var fn = $.jgrid.getMethod(pin);
  643. if (!fn) {
  644. throw ("jqGrid - No such method: " + pin);
  645. }
  646. var args = $.makeArray(arguments).slice(1);
  647. return fn.apply(this,args);
  648. }
  649. return this.each( function() {
  650. if(this.grid) {return;}
  651. var p = $.extend(true,{
  652. url: "",
  653. height: 150,
  654. page: 1,
  655. rowNum: 20,
  656. rowTotal : null,
  657. records: 0,
  658. pager: "",
  659. pgbuttons: true,
  660. pginput: true,
  661. colModel: [],
  662. rowList: [],
  663. colNames: [],
  664. sortorder: "asc",
  665. sortname: "",
  666. datatype: "xml",
  667. mtype: "GET",
  668. altRows: false,
  669. selarrrow: [],
  670. savedRow: [],
  671. shrinkToFit: true,
  672. xmlReader: {},
  673. jsonReader: {},
  674. subGrid: false,
  675. subGridModel :[],
  676. reccount: 0,
  677. lastpage: 0,
  678. lastsort: 0,
  679. selrow: null,
  680. beforeSelectRow: null,
  681. onSelectRow: null,
  682. onSortCol: null,
  683. ondblClickRow: null,
  684. onRightClickRow: null,
  685. onPaging: null,
  686. onSelectAll: null,
  687. loadComplete: null,
  688. gridComplete: null,
  689. loadError: null,
  690. loadBeforeSend: null,
  691. afterInsertRow: null,
  692. beforeRequest: null,
  693. beforeProcessing : null,
  694. onHeaderClick: null,
  695. viewrecords: false,
  696. loadonce: false,
  697. multiselect: false,
  698. multikey: false,
  699. editurl: null,
  700. search: false,
  701. caption: "",
  702. hidegrid: true,
  703. hiddengrid: false,
  704. postData: {},
  705. userData: {},
  706. treeGrid : false,
  707. treeGridModel : 'nested',
  708. treeReader : {},
  709. treeANode : -1,
  710. ExpandColumn: null,
  711. tree_root_level : 0,
  712. prmNames: {page:"page",rows:"rows", sort: "sidx",order: "sord", search:"_search", nd:"nd", id:"id",oper:"oper",editoper:"edit",addoper:"add",deloper:"del", subgridid:"id", npage: null, totalrows:"totalrows"},
  713. forceFit : false,
  714. gridstate : "visible",
  715. cellEdit: false,
  716. cellsubmit: "remote",
  717. nv:0,
  718. loadui: "enable",
  719. toolbar: [false,""],
  720. scroll: false,
  721. multiboxonly : false,
  722. deselectAfterSort : true,
  723. scrollrows : false,
  724. autowidth: false,
  725. scrollOffset :18,
  726. cellLayout: 5,
  727. subGridWidth: 20,
  728. multiselectWidth: 20,
  729. gridview: false,
  730. rownumWidth: 25,
  731. rownumbers : false,
  732. pagerpos: 'center',
  733. recordpos: 'right',
  734. footerrow : false,
  735. userDataOnFooter : false,
  736. hoverrows : true,
  737. altclass : 'ui-priority-secondary',
  738. viewsortcols : [false,'vertical',true],
  739. resizeclass : '',
  740. autoencode : false,
  741. remapColumns : [],
  742. ajaxGridOptions :{},
  743. direction : "ltr",
  744. toppager: false,
  745. headertitles: false,
  746. scrollTimeout: 40,
  747. data : [],
  748. _index : {},
  749. grouping : false,
  750. groupingView : {groupField:[],groupOrder:[], groupText:[],groupColumnShow:[],groupSummary:[], showSummaryOnHide: false, sortitems:[], sortnames:[], summary:[],summaryval:[], plusicon: 'ui-icon-circlesmall-plus', minusicon: 'ui-icon-circlesmall-minus', displayField: []},
  751. ignoreCase : false,
  752. cmTemplate : {},
  753. idPrefix : ""
  754. }, $.jgrid.defaults, pin || {});
  755. var ts= this, grid={
  756. headers:[],
  757. cols:[],
  758. footers: [],
  759. dragStart: function(i,x,y) {
  760. this.resizing = { idx: i, startX: x.clientX, sOL : y[0]};
  761. this.hDiv.style.cursor = "col-resize";
  762. this.curGbox = $("#rs_m"+$.jgrid.jqID(p.id),"#gbox_"+$.jgrid.jqID(p.id));
  763. this.curGbox.css({display:"block",left:y[0],top:y[1],height:y[2]});
  764. $(ts).triggerHandler("jqGridResizeStart", [x, i]);
  765. if($.isFunction(p.resizeStart)) { p.resizeStart.call(this,x,i); }
  766. document.onselectstart=function(){return false;};
  767. },
  768. dragMove: function(x) {
  769. if(this.resizing) {
  770. var diff = x.clientX-this.resizing.startX,
  771. h = this.headers[this.resizing.idx],
  772. newWidth = p.direction === "ltr" ? h.width + diff : h.width - diff, hn, nWn;
  773. if(newWidth > 33) {
  774. this.curGbox.css({left:this.resizing.sOL+diff});
  775. if(p.forceFit===true ){
  776. hn = this.headers[this.resizing.idx+p.nv];
  777. nWn = p.direction === "ltr" ? hn.width - diff : hn.width + diff;
  778. if(nWn >33) {
  779. h.newWidth = newWidth;
  780. hn.newWidth = nWn;
  781. }
  782. } else {
  783. this.newWidth = p.direction === "ltr" ? p.tblwidth+diff : p.tblwidth-diff;
  784. h.newWidth = newWidth;
  785. }
  786. }
  787. }
  788. },
  789. dragEnd: function() {
  790. this.hDiv.style.cursor = "default";
  791. if(this.resizing) {
  792. var idx = this.resizing.idx,
  793. nw = this.headers[idx].newWidth || this.headers[idx].width;
  794. nw = parseInt(nw,10);
  795. this.resizing = false;
  796. $("#rs_m"+$.jgrid.jqID(p.id)).css("display","none");
  797. p.colModel[idx].width = nw;
  798. this.headers[idx].width = nw;
  799. this.headers[idx].el.style.width = nw + "px";
  800. this.cols[idx].style.width = nw+"px";
  801. if(this.footers.length>0) {this.footers[idx].style.width = nw+"px";}
  802. if(p.forceFit===true){
  803. nw = this.headers[idx+p.nv].newWidth || this.headers[idx+p.nv].width;
  804. this.headers[idx+p.nv].width = nw;
  805. this.headers[idx+p.nv].el.style.width = nw + "px";
  806. this.cols[idx+p.nv].style.width = nw+"px";
  807. if(this.footers.length>0) {this.footers[idx+p.nv].style.width = nw+"px";}
  808. p.colModel[idx+p.nv].width = nw;
  809. } else {
  810. p.tblwidth = this.newWidth || p.tblwidth;
  811. $('table:first',this.bDiv).css("width",p.tblwidth+"px");
  812. $('table:first',this.hDiv).css("width",p.tblwidth+"px");
  813. this.hDiv.scrollLeft = this.bDiv.scrollLeft;
  814. if(p.footerrow) {
  815. $('table:first',this.sDiv).css("width",p.tblwidth+"px");
  816. this.sDiv.scrollLeft = this.bDiv.scrollLeft;
  817. }
  818. }
  819. $(ts).triggerHandler("jqGridResizeStop", [nw, idx]);
  820. if($.isFunction(p.resizeStop)) { p.resizeStop.call(this,nw,idx); }
  821. }
  822. this.curGbox = null;
  823. document.onselectstart=function(){return true;};
  824. },
  825. populateVisible: function() {
  826. if (grid.timer) { clearTimeout(grid.timer); }
  827. grid.timer = null;
  828. var dh = $(grid.bDiv).height();
  829. if (!dh) { return; }
  830. var table = $("table:first", grid.bDiv);
  831. var rows, rh;
  832. if(table[0].rows.length) {
  833. try {
  834. rows = table[0].rows[1];
  835. rh = rows ? $(rows).outerHeight() || grid.prevRowHeight : grid.prevRowHeight;
  836. } catch (pv) {
  837. rh = grid.prevRowHeight;
  838. }
  839. }
  840. if (!rh) { return; }
  841. grid.prevRowHeight = rh;
  842. var rn = p.rowNum;
  843. var scrollTop = grid.scrollTop = grid.bDiv.scrollTop;
  844. var ttop = Math.round(table.position().top) - scrollTop;
  845. var tbot = ttop + table.height();
  846. var div = rh * rn;
  847. var page, npage, empty;
  848. if ( tbot < dh && ttop <= 0 &&
  849. (p.lastpage===undefined||parseInt((tbot + scrollTop + div - 1) / div,10) <= p.lastpage))
  850. {
  851. npage = parseInt((dh - tbot + div - 1) / div,10);
  852. if (tbot >= 0 || npage < 2 || p.scroll === true) {
  853. page = Math.round((tbot + scrollTop) / div) + 1;
  854. ttop = -1;
  855. } else {
  856. ttop = 1;
  857. }
  858. }
  859. if (ttop > 0) {
  860. page = parseInt(scrollTop / div,10) + 1;
  861. npage = parseInt((scrollTop + dh) / div,10) + 2 - page;
  862. empty = true;
  863. }
  864. if (npage) {
  865. if (p.lastpage && (page > p.lastpage || p.lastpage==1 || (page === p.page && page===p.lastpage)) ) {
  866. return;
  867. }
  868. if (grid.hDiv.loading) {
  869. grid.timer = setTimeout(grid.populateVisible, p.scrollTimeout);
  870. } else {
  871. p.page = page;
  872. if (empty) {
  873. grid.selectionPreserver(table[0]);
  874. grid.emptyRows.call(table[0], false, false);
  875. }
  876. grid.populate(npage);
  877. }
  878. }
  879. },
  880. scrollGrid: function( e ) {
  881. if(p.scroll) {
  882. var scrollTop = grid.bDiv.scrollTop;
  883. if(grid.scrollTop === undefined) { grid.scrollTop = 0; }
  884. if (scrollTop != grid.scrollTop) {
  885. grid.scrollTop = scrollTop;
  886. if (grid.timer) { clearTimeout(grid.timer); }
  887. grid.timer = setTimeout(grid.populateVisible, p.scrollTimeout);
  888. }
  889. }
  890. grid.hDiv.scrollLeft = grid.bDiv.scrollLeft;
  891. if(p.footerrow) {
  892. grid.sDiv.scrollLeft = grid.bDiv.scrollLeft;
  893. }
  894. if( e ) { e.stopPropagation(); }
  895. },
  896. selectionPreserver : function(ts) {
  897. var p = ts.p,
  898. sr = p.selrow, sra = p.selarrrow ? $.makeArray(p.selarrrow) : null,
  899. left = ts.grid.bDiv.scrollLeft,
  900. restoreSelection = function() {
  901. var i;
  902. p.selrow = null;
  903. p.selarrrow = [];
  904. if(p.multiselect && sra && sra.length>0) {
  905. for(i=0;i<sra.length;i++){
  906. if (sra[i] != sr) {
  907. $(ts).jqGrid("setSelection",sra[i],false, null);
  908. }
  909. }
  910. }
  911. if (sr) {
  912. $(ts).jqGrid("setSelection",sr,false,null);
  913. }
  914. ts.grid.bDiv.scrollLeft = left;
  915. $(ts).unbind('.selectionPreserver', restoreSelection);
  916. };
  917. $(ts).bind('jqGridGridComplete.selectionPreserver', restoreSelection);
  918. }
  919. };
  920. if(this.tagName.toUpperCase()!='TABLE') {
  921. alert("Element is not a table");
  922. return;
  923. }
  924. if(document.documentMode !== undefined ) { // IE only
  925. if(document.documentMode <= 5) {
  926. alert("Grid can not be used in this ('quirks') mode!");
  927. return;
  928. }
  929. }
  930. $(this).empty().attr("tabindex","0");
  931. this.p = p ;
  932. this.p.useProp = !!$.fn.prop;
  933. var i, dir;
  934. if(this.p.colNames.length === 0) {
  935. for (i=0;i<this.p.colModel.length;i++){
  936. this.p.colNames[i] = this.p.colModel[i].label || this.p.colModel[i].name;
  937. }
  938. }
  939. if( this.p.colNames.length !== this.p.colModel.length ) {
  940. alert($.jgrid.errors.model);
  941. return;
  942. }
  943. var gv = $("<div class='ui-jqgrid-view'></div>"), ii,
  944. isMSIE = $.browser.msie ? true:false;
  945. ts.p.direction = $.trim(ts.p.direction.toLowerCase());
  946. if($.inArray(ts.p.direction,["ltr","rtl"]) == -1) { ts.p.direction = "ltr"; }
  947. dir = ts.p.direction;
  948. $(gv).insertBefore(this);
  949. $(this).appendTo(gv).removeClass("scroll");
  950. var eg = $("<div class='ui-jqgrid ui-widget ui-widget-content ui-corner-all'></div>");
  951. $(eg).insertBefore(gv).attr({"id" : "gbox_"+this.id,"dir":dir});
  952. $(gv).appendTo(eg).attr("id","gview_"+this.id);
  953. if (isMSIE && $.browser.version <= 6) {
  954. ii = '<iframe style="display:block;position:absolute;z-index:-1;filter:Alpha(Opacity=\'0\');" src="javascript:false;"></iframe>';
  955. } else { ii="";}
  956. $("<div class='ui-widget-overlay jqgrid-overlay' id='lui_"+this.id+"'></div>").append(ii).insertBefore(gv);
  957. $("<div class='loading ui-state-default ui-state-active' id='load_"+this.id+"'>"+this.p.loadtext+"</div>").insertBefore(gv);
  958. $(this).attr({cellspacing:"0",cellpadding:"0",border:"0","role":"grid","aria-multiselectable":!!this.p.multiselect,"aria-labelledby":"gbox_"+this.id});
  959. var sortkeys = ["shiftKey","altKey","ctrlKey"],
  960. intNum = function(val,defval) {
  961. val = parseInt(val,10);
  962. if (isNaN(val)) { return defval || 0;}
  963. return val;
  964. },
  965. formatCol = function (pos, rowInd, tv, rawObject, rowId, rdata){
  966. var cm = ts.p.colModel[pos],
  967. ral = cm.align, result="style=\"", clas = cm.classes, nm = cm.name, celp, acp=[];
  968. if(ral) { result += "text-align:"+ral+";"; }
  969. if(cm.hidden===true) { result += "display:none;"; }
  970. if(rowInd===0) {
  971. result += "width: "+grid.headers[pos].width+"px;";
  972. } else if (cm.cellattr && $.isFunction(cm.cellattr))
  973. {
  974. celp = cm.cellattr.call(ts, rowId, tv, rawObject, cm, rdata);
  975. if(celp && typeof celp === "string") {
  976. celp = celp.replace(/style/i,'style').replace(/title/i,'title');
  977. if(celp.indexOf('title') > -1) { cm.title=false;}
  978. if(celp.indexOf('class') > -1) { clas = undefined;}
  979. acp = celp.split("style");
  980. if(acp.length === 2 ) {
  981. acp[1] = $.trim(acp[1].replace("=",""));
  982. if(acp[1].indexOf("'") === 0 || acp[1].indexOf('"') === 0) {
  983. acp[1] = acp[1].substring(1);
  984. }
  985. result += acp[1].replace(/'/gi,'"');
  986. } else {
  987. result += "\"";
  988. }
  989. }
  990. }
  991. if(!acp.length) { acp[0] = ""; result += "\"";}
  992. result += (clas !== undefined ? (" class=\""+clas+"\"") :"") + ((cm.title && tv) ? (" title=\""+$.jgrid.stripHtml(tv)+"\"") :"");
  993. result += " aria-describedby=\""+ts.p.id+"_"+nm+"\"";
  994. return result + acp[0];
  995. },
  996. cellVal = function (val) {
  997. return val == null || val === "" ? "&#160;" : (ts.p.autoencode ? $.jgrid.htmlEncode(val) : String(val));
  998. },
  999. formatter = function (rowId, cellval , colpos, rwdat, _act){
  1000. var cm = ts.p.colModel[colpos],v;
  1001. if(cm.formatter !== undefined) {
  1002. rowId = String(ts.p.idPrefix) !== "" ? $.jgrid.stripPref(ts.p.idPrefix, rowId) : rowId;
  1003. var opts= {rowId: rowId, colModel:cm, gid:ts.p.id, pos:colpos };
  1004. if($.isFunction( cm.formatter ) ) {
  1005. v = cm.formatter.call(ts,cellval,opts,rwdat,_act);
  1006. } else if($.fmatter){
  1007. v = $.fn.fmatter.call(ts,cm.formatter,cellval,opts,rwdat,_act);
  1008. } else {
  1009. v = cellVal(cellval);
  1010. }
  1011. } else {
  1012. v = cellVal(cellval);
  1013. }
  1014. return v;
  1015. },
  1016. addCell = function(rowId,cell,pos,irow, srvr, rdata) {
  1017. var v,prp;
  1018. v = formatter(rowId,cell,pos,srvr,'add');
  1019. prp = formatCol( pos,irow, v, srvr, rowId, rdata);
  1020. return "<td role=\"gridcell\" "+prp+">"+v+"</td>";
  1021. },
  1022. addMulti = function(rowid,pos,irow,checked){
  1023. var v = "<input role=\"checkbox\" type=\"checkbox\""+" id=\"jqg_"+ts.p.id+"_"+rowid+"\" class=\"cbox\" name=\"jqg_"+ts.p.id+"_"+rowid+"\"" + (checked ? "checked=\"checked\"" : "")+"/>",
  1024. prp = formatCol( pos,irow,'',null, rowid, true);
  1025. return "<td role=\"gridcell\" "+prp+">"+v+"</td>";
  1026. },
  1027. addRowNum = function (pos,irow,pG,rN) {
  1028. var v = (parseInt(pG,10)-1)*parseInt(rN,10)+1+irow,
  1029. prp = formatCol( pos,irow,v, null, irow, true);
  1030. return "<td role=\"gridcell\" class=\"ui-state-default jqgrid-rownum\" "+prp+">"+v+"</td>";
  1031. },
  1032. reader = function (datatype) {
  1033. var field, f=[], j=0, i;
  1034. for(i =0; i<ts.p.colModel.length; i++){
  1035. field = ts.p.colModel[i];
  1036. if (field.name !== 'cb' && field.name !=='subgrid' && field.name !=='rn') {
  1037. f[j]= datatype == "local" ?
  1038. field.name :
  1039. ( (datatype=="xml" || datatype === "xmlstring") ? field.xmlmap || field.name : field.jsonmap || field.name );
  1040. j++;
  1041. }
  1042. }
  1043. return f;
  1044. },
  1045. orderedCols = function (offset) {
  1046. var order = ts.p.remapColumns;
  1047. if (!order || !order.length) {
  1048. order = $.map(ts.p.colModel, function(v,i) { return i; });
  1049. }
  1050. if (offset) {
  1051. order = $.map(order, function(v) { return v<offset?null:v-offset; });
  1052. }
  1053. return order;
  1054. },
  1055. emptyRows = function (scroll, locdata) {
  1056. var firstrow;
  1057. if (this.p.deepempty) {
  1058. $(this.rows).slice(1).remove();
  1059. } else {
  1060. firstrow = this.rows.length > 0 ? this.rows[0] : null;
  1061. $(this.firstChild).empty().append(firstrow);
  1062. }
  1063. if (scroll && this.p.scroll) {
  1064. $(this.grid.bDiv.firstChild).css({height: "auto"});
  1065. $(this.grid.bDiv.firstChild.firstChild).css({height: 0, display: "none"});
  1066. if (this.grid.bDiv.scrollTop !== 0) {
  1067. this.grid.bDiv.scrollTop = 0;
  1068. }
  1069. }
  1070. if(locdata === true && this.p.treeGrid) {
  1071. this.p.data = []; this.p._index = {};
  1072. }
  1073. },
  1074. refreshIndex = function() {
  1075. var datalen = ts.p.data.length, idname, i, val,
  1076. ni = ts.p.rownumbers===true ? 1 :0,
  1077. gi = ts.p.multiselect ===true ? 1 :0,
  1078. si = ts.p.subGrid===true ? 1 :0;
  1079. if(ts.p.keyIndex === false || ts.p.loadonce === true) {
  1080. idname = ts.p.localReader.id;
  1081. } else {
  1082. idname = ts.p.colModel[ts.p.keyIndex+gi+si+ni].name;
  1083. }
  1084. for(i =0;i < datalen; i++) {
  1085. val = $.jgrid.getAccessor(ts.p.data[i],idname);
  1086. if (val === undefined) { val=String(i+1); }
  1087. ts.p._index[val] = i;
  1088. }
  1089. },
  1090. constructTr = function(id, hide, altClass, rd, cur, selected) {
  1091. var tabindex = '-1', restAttr = '', attrName, style = hide ? 'display:none;' : '',
  1092. classes = 'ui-widget-content jqgrow ui-row-' + ts.p.direction + altClass + (selected ? ' ui-state-highlight' : ''),
  1093. rowAttrObj = $.isFunction(ts.p.rowattr) ? ts.p.rowattr.call(ts, rd, cur) : {};
  1094. if(!$.isEmptyObject( rowAttrObj )) {
  1095. if (rowAttrObj.hasOwnProperty("id")) {
  1096. id = rowAttrObj.id;
  1097. delete rowAttrObj.id;
  1098. }
  1099. if (rowAttrObj.hasOwnProperty("tabindex")) {
  1100. tabindex = rowAttrObj.tabindex;
  1101. delete rowAttrObj.tabindex;
  1102. }
  1103. if (rowAttrObj.hasOwnProperty("style")) {
  1104. style += rowAttrObj.style;
  1105. delete rowAttrObj.style;
  1106. }
  1107. if (rowAttrObj.hasOwnProperty("class")) {
  1108. classes += ' ' + rowAttrObj['class'];
  1109. delete rowAttrObj['class'];
  1110. }
  1111. // dot't allow to change role attribute
  1112. try { delete rowAttrObj.role; } catch(ra){}
  1113. for (attrName in rowAttrObj) {
  1114. if (rowAttrObj.hasOwnProperty(attrName)) {
  1115. restAttr += ' ' + attrName + '=' + rowAttrObj[attrName];
  1116. }
  1117. }
  1118. }
  1119. return '<tr role="row" id="' + id + '" tabindex="' + tabindex + '" class="' + classes + '"' +
  1120. (style === '' ? '' : ' style="' + style + '"') + restAttr + '>';
  1121. },
  1122. addXmlData = function (xml,t, rcnt, more, adjust) {
  1123. var startReq = new Date(),
  1124. locdata = (ts.p.datatype != "local" && ts.p.loadonce) || ts.p.datatype == "xmlstring",
  1125. xmlid = "_id_", xmlRd = ts.p.xmlReader,
  1126. frd = ts.p.datatype == "local" ? "local" : "xml";
  1127. if(locdata) {
  1128. ts.p.data = [];
  1129. ts.p._index = {};
  1130. ts.p.localReader.id = xmlid;
  1131. }
  1132. ts.p.reccount = 0;
  1133. if($.isXMLDoc(xml)) {
  1134. if(ts.p.treeANode===-1 && !ts.p.scroll) {
  1135. emptyRows.call(ts, false, true);
  1136. rcnt=1;
  1137. } else { rcnt = rcnt > 1 ? rcnt :1; }
  1138. } else { return; }
  1139. 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 ={}, xmlr,rid, rowData=[], cn=(ts.p.altRows === true) ? " "+ts.p.altclass:"",cn1;
  1140. if(ts.p.subGrid===true) {
  1141. si = 1;
  1142. addSubGridCell = $.jgrid.getMethod("addSubGridCell");
  1143. }
  1144. if(!xmlRd.repeatitems) {f = reader(frd);}
  1145. if( ts.p.keyIndex===false) {
  1146. idn = $.isFunction( xmlRd.id ) ? xmlRd.id.call(ts, xml) : xmlRd.id;
  1147. } else {
  1148. idn = ts.p.keyIndex;
  1149. }
  1150. if(f.length>0 && !isNaN(idn)) {
  1151. if (ts.p.remapColumns && ts.p.remapColumns.length) {
  1152. idn = $.inArray(idn, ts.p.remapColumns);
  1153. }
  1154. idn=f[idn];
  1155. }
  1156. if( String(idn).indexOf("[") === -1 ) {
  1157. if (f.length) {
  1158. getId = function( trow, k) {return $(idn,trow).text() || k;};
  1159. } else {
  1160. getId = function( trow, k) {return $(xmlRd.cell,trow).eq(idn).text() || k;};
  1161. }
  1162. }
  1163. else {
  1164. getId = function( trow, k) {return trow.getAttribute(idn.replace(/[\[\]]/g,"")) || k;};
  1165. }
  1166. ts.p.userData = {};
  1167. ts.p.page = $.jgrid.getXmlData( xml,xmlRd.page ) || ts.p.page || 0;
  1168. ts.p.lastpage = $.jgrid.getXmlData( xml,xmlRd.total );
  1169. if(ts.p.lastpage===undefined) { ts.p.lastpage=1; }
  1170. ts.p.records = $.jgrid.getXmlData( xml,xmlRd.records ) || 0;
  1171. if($.isFunction(xmlRd.userdata)) {
  1172. ts.p.userData = xmlRd.userdata.call(ts, xml) || {};
  1173. } else {
  1174. $.jgrid.getXmlData(xml, xmlRd.userdata, true).each(function() {ts.p.userData[this.getAttribute("name")]= $(this).text();});
  1175. }
  1176. var gxml = $.jgrid.getXmlData( xml, xmlRd.root, true);
  1177. gxml = $.jgrid.getXmlData( gxml, xmlRd.row, true);
  1178. if (!gxml) { gxml = []; }
  1179. var gl = gxml.length, j=0, grpdata=[], rn = parseInt(ts.p.rowNum,10), br=ts.p.scroll?$.jgrid.randId():1, altr;
  1180. if (gl > 0 && ts.p.page <= 0) { ts.p.page = 1; }
  1181. if(gxml && gl){
  1182. if (adjust) { rn *= adjust+1; }
  1183. var afterInsRow = $.isFunction(ts.p.afterInsertRow), hiderow=false, groupingPrepare;
  1184. if(ts.p.grouping) {
  1185. hiderow = ts.p.groupingView.groupCollapse === true;
  1186. groupingPrepare = $.jgrid.getMethod("groupingPrepare");
  1187. }
  1188. while (j<gl) {
  1189. xmlr = gxml[j];
  1190. rid = getId(xmlr,br+j);
  1191. rid = ts.p.idPrefix + rid;
  1192. altr = rcnt === 0 ? 0 : rcnt+1;
  1193. cn1 = (altr+j)%2 == 1 ? cn : '';
  1194. var iStartTrTag = rowData.length;
  1195. rowData.push("");
  1196. if( ni ) {
  1197. rowData.push( addRowNum(0,j,ts.p.page,ts.p.rowNum) );
  1198. }
  1199. if( gi ) {
  1200. rowData.push( addMulti(rid,ni,j, false) );
  1201. }
  1202. if( si ) {
  1203. rowData.push( addSubGridCell.call(self,gi+ni,j+rcnt) );
  1204. }
  1205. if(xmlRd.repeatitems){
  1206. if (!F) { F=orderedCols(gi+si+ni); }
  1207. var cells = $.jgrid.getXmlData( xmlr, xmlRd.cell, true);
  1208. $.each(F, function (k) {
  1209. var cell = cells[this];
  1210. if (!cell) { return false; }
  1211. v = cell.textContent || cell.text;
  1212. rd[ts.p.colModel[k+gi+si+ni].name] = v;
  1213. rowData.push( addCell(rid,v,k+gi+si+ni,j+rcnt,xmlr, rd) );
  1214. });
  1215. } else {
  1216. for(i = 0; i < f.length;i++) {
  1217. v = $.jgrid.getXmlData( xmlr, f[i]);
  1218. rd[ts.p.colModel[i+gi+si+ni].name] = v;
  1219. rowData.push( addCell(rid, v, i+gi+si+ni, j+rcnt, xmlr, rd) );
  1220. }
  1221. }
  1222. rowData[iStartTrTag] = constructTr(rid, hiderow, cn1, rd, xmlr, false);
  1223. rowData.push("</tr>");
  1224. if(ts.p.grouping) {
  1225. grpdata = groupingPrepare.call(self,rowData, grpdata, rd, j);
  1226. rowData = [];
  1227. }
  1228. if(locdata || ts.p.treeGrid === true) {
  1229. rd[xmlid] = rid;
  1230. ts.p.data.push(rd);
  1231. ts.p._index[rid] = ts.p.data.length-1;
  1232. }
  1233. if(ts.p.gridview === false ) {
  1234. $("tbody:first",t).append(rowData.join(''));
  1235. self.triggerHandler("jqGridAfterInsertRow", [rid, rd, xmlr]);
  1236. if(afterInsRow) {ts.p.afterInsertRow.call(ts,rid,rd,xmlr);}
  1237. rowData=[];
  1238. }
  1239. rd={};
  1240. ir++;
  1241. j++;
  1242. if(ir==rn) {break;}
  1243. }
  1244. }
  1245. if(ts.p.gridview === true) {
  1246. fpos = ts.p.treeANode > -1 ? ts.p.treeANode: 0;
  1247. if(ts.p.grouping) {
  1248. self.jqGrid('groupingRender',grpdata,ts.p.colModel.length);
  1249. grpdata = null;
  1250. } else if(ts.p.treeGrid === true && fpos > 0) {
  1251. $(ts.rows[fpos]).after(rowData.join(''));
  1252. } else {
  1253. $("tbody:first",t).append(rowData.join(''));
  1254. }
  1255. }
  1256. if(ts.p.subGrid === true ) {
  1257. try {self.jqGrid("addSubGrid",gi+ni);} catch (_){}
  1258. }
  1259. ts.p.totaltime = new Date() - startReq;
  1260. if(ir>0) { if(ts.p.records===0) { ts.p.records=gl;} }
  1261. rowData =null;
  1262. if( ts.p.treeGrid === true) {
  1263. try {self.jqGrid("setTreeNode", fpos+1, ir+fpos+1);} catch (e) {}
  1264. }
  1265. if(!ts.p.treeGrid && !ts.p.scroll) {ts.grid.bDiv.scrollTop = 0;}
  1266. ts.p.reccount=ir;
  1267. ts.p.treeANode = -1;
  1268. if(ts.p.userDataOnFooter) { self.jqGrid("footerData","set",ts.p.userData,true); }
  1269. if(locdata) {
  1270. ts.p.records = gl;
  1271. ts.p.lastpage = Math.ceil(gl/ rn);
  1272. }
  1273. if (!more) { ts.updatepager(false,true); }
  1274. if(locdata) {
  1275. while (ir<gl) {
  1276. xmlr = gxml[ir];
  1277. rid = getId(xmlr,ir+br);
  1278. rid = ts.p.idPrefix + rid;
  1279. if(xmlRd.repeatitems){
  1280. if (!F) { F=orderedCols(gi+si+ni); }
  1281. var cells2 = $.jgrid.getXmlData( xmlr, xmlRd.cell, true);
  1282. $.each(F, function (k) {
  1283. var cell = cells2[this];
  1284. if (!cell) { return false; }
  1285. v = cell.textContent || cell.text;
  1286. rd[ts.p.colModel[k+gi+si+ni].name] = v;
  1287. });
  1288. } else {
  1289. for(i = 0; i < f.length;i++) {
  1290. v = $.jgrid.getXmlData( xmlr, f[i]);
  1291. rd[ts.p.colModel[i+gi+si+ni].name] = v;
  1292. }
  1293. }
  1294. rd[xmlid] = rid;
  1295. ts.p.data.push(rd);
  1296. ts.p._index[rid] = ts.p.data.length-1;
  1297. rd = {};
  1298. ir++;
  1299. }
  1300. }
  1301. },
  1302. addJSONData = function(data,t, rcnt, more, adjust) {
  1303. var startReq = new Date();
  1304. if(data) {
  1305. if(ts.p.treeANode === -1 && !ts.p.scroll) {
  1306. emptyRows.call(ts, false, true);
  1307. rcnt=1;
  1308. } else { rcnt = rcnt > 1 ? rcnt :1; }
  1309. } else { return; }
  1310. var dReader, locid = "_id_", frd,
  1311. locdata = (ts.p.datatype != "local" && ts.p.loadonce) || ts.p.datatype == "jsonstring";
  1312. if(locdata) { ts.p.data = []; ts.p._index = {}; ts.p.localReader.id = locid;}
  1313. ts.p.reccount = 0;
  1314. if(ts.p.datatype == "local") {
  1315. dReader = ts.p.localReader;
  1316. frd= 'local';
  1317. } else {
  1318. dReader = ts.p.jsonReader;
  1319. frd='json';
  1320. }
  1321. var self = $(ts), ir=0,v,i,j,f=[],F,cur,gi=ts.p.multiselect?1:0,si=0,addSubGridCell,ni=ts.p.rownumbers===true?1:0,len,drows,idn,rd={}, fpos, idr,rowData=[],cn=(ts.p.altRows === true) ? " "+ts.p.altclass:"",cn1,lp;
  1322. ts.p.page = $.jgrid.getAccessor(data,dReader.page) || ts.p.page || 0;
  1323. lp = $.jgrid.getAccessor(data,dReader.total);
  1324. if(ts.p.subGrid===true) {
  1325. si = 1;
  1326. addSubGridCell = $.jgrid.getMethod("addSubGridCell");
  1327. }
  1328. ts.p.lastpage = lp === undefined ? 1 : lp;
  1329. ts.p.records = $.jgrid.getAccessor(data,dReader.records) || 0;
  1330. ts.p.userData = $.jgrid.getAccessor(data,dReader.userdata) || {};
  1331. if(!dReader.repeatitems) {
  1332. F = f = reader(frd);
  1333. }
  1334. if( ts.p.keyIndex===false ) {
  1335. idn = $.isFunction(dReader.id) ? dReader.id.call(ts, data) : dReader.id;
  1336. } else {
  1337. idn = ts.p.keyIndex;
  1338. }
  1339. if(f.length>0 && !isNaN(idn)) {
  1340. if (ts.p.remapColumns && ts.p.remapColumns.length) {
  1341. idn = $.inArray(idn, ts.p.remapColumns);
  1342. }
  1343. idn=f[idn];
  1344. }
  1345. drows = $.jgrid.getAccessor(data,dReader.root);
  1346. if (!drows) { drows = []; }
  1347. len = drows.length; i=0;
  1348. if (len > 0 && ts.p.page <= 0) { ts.p.page = 1; }
  1349. var rn = parseInt(ts.p.rowNum,10),br=ts.p.scroll?$.jgrid.randId():1, altr, selected=false, selr;
  1350. if (adjust) { rn *= adjust+1; }
  1351. if(ts.p.datatype === "local" && !ts.p.deselectAfterSort) {
  1352. selected = true;
  1353. }
  1354. var afterInsRow = $.isFunction(ts.p.afterInsertRow), grpdata=[],hiderow=false, groupingPrepare;
  1355. if(ts.p.grouping) {
  1356. hiderow = ts.p.groupingView.groupCollapse === true;
  1357. groupingPrepare = $.jgrid.getMethod("groupingPrepare");
  1358. }
  1359. while (i<len) {
  1360. cur = drows[i];
  1361. idr = $.jgrid.getAccessor(cur,idn);
  1362. if(idr === undefined) {
  1363. idr = br+i;
  1364. if(f.length===0){
  1365. if(dReader.cell){
  1366. var ccur = $.jgrid.getAccessor(cur,dReader.cell);
  1367. idr = ccur !== undefined ? ccur[idn] || idr : idr;
  1368. ccur=null;
  1369. }
  1370. }
  1371. }
  1372. idr = ts.p.idPrefix + idr;
  1373. altr = rcnt === 1 ? 0 : rcnt;
  1374. cn1 = (altr+i)%2 == 1 ? cn : '';
  1375. if( selected) {
  1376. if( ts.p.multiselect) {
  1377. selr = ($.inArray(idr, ts.p.selarrrow) !== -1);
  1378. } else {
  1379. selr = (idr === ts.p.selrow);
  1380. }
  1381. }
  1382. var iStartTrTag = rowData.length;
  1383. rowData.push("");
  1384. if( ni ) {
  1385. rowData.push( addRowNum(0,i,ts.p.page,ts.p.rowNum) );
  1386. }
  1387. if( gi ){
  1388. rowData.push( addMulti(idr,ni,i,selr) );
  1389. }
  1390. if( si ) {
  1391. rowData.push( addSubGridCell.call(self,gi+ni,i+rcnt) );
  1392. }
  1393. if (dReader.repeatitems) {
  1394. if(dReader.cell) {cur = $.jgrid.getAccessor(cur,dReader.cell);}
  1395. if (!F) { F=orderedCols(gi+si+ni); }
  1396. }
  1397. for (j=0;j<F.length;j++) {
  1398. v = $.jgrid.getAccessor(cur,F[j]);
  1399. rd[ts.p.colModel[j+gi+si+ni].name] = v;
  1400. rowData.push( addCell(idr,v,j+gi+si+ni,i+rcnt,cur, rd) );
  1401. }
  1402. rowData[iStartTrTag] = constructTr(idr, hiderow, cn1, rd, cur, selr);
  1403. rowData.push( "</tr>" );
  1404. if(ts.p.grouping) {
  1405. grpdata = groupingPrepare.call(self,rowData, grpdata, rd, i);
  1406. rowData = [];
  1407. }
  1408. if(locdata || ts.p.treeGrid===true) {
  1409. rd[locid] = idr;
  1410. ts.p.data.push(rd);
  1411. ts.p._index[idr] = ts.p.data.length-1;
  1412. }
  1413. if(ts.p.gridview === false ) {
  1414. $("#"+$.jgrid.jqID(ts.p.id)+" tbody:first").append(rowData.join(''));
  1415. self.triggerHandler("jqGridAfterInsertRow", [idr, rd, cur]);
  1416. if(afterInsRow) {ts.p.afterInsertRow.call(ts,idr,rd,cur);}
  1417. rowData=[];//ari=0;
  1418. }
  1419. rd={};
  1420. ir++;
  1421. i++;
  1422. if(ir==rn) { break; }
  1423. }
  1424. if(ts.p.gridview === true ) {
  1425. fpos = ts.p.treeANode > -1 ? ts.p.treeANode: 0;
  1426. if(ts.p.grouping) {
  1427. self.jqGrid('groupingRender',grpdata,ts.p.colModel.length);
  1428. grpdata = null;
  1429. } else if(ts.p.treeGrid === true && fpos > 0) {
  1430. $(ts.rows[fpos]).after(rowData.join(''));
  1431. } else {
  1432. $("#"+$.jgrid.jqID(ts.p.id)+" tbody:first").append(rowData.join(''));
  1433. }
  1434. }
  1435. if(ts.p.subGrid === true ) {
  1436. try { self.jqGrid("addSubGrid",gi+ni);} catch (_){}
  1437. }
  1438. ts.p.totaltime = new Date() - startReq;
  1439. if(ir>0) {
  1440. if(ts.p.records===0) { ts.p.records=len; }
  1441. }
  1442. rowData = null;
  1443. if( ts.p.treeGrid === true) {
  1444. try {self.jqGrid("setTreeNode", fpos+1, ir+fpos+1);} catch (e) {}
  1445. }
  1446. if(!ts.p.treeGrid && !ts.p.scroll) {ts.grid.bDiv.scrollTop = 0;}
  1447. ts.p.reccount=ir;
  1448. ts.p.treeANode = -1;
  1449. if(ts.p.userDataOnFooter) { self.jqGrid("footerData","set",ts.p.userData,true); }
  1450. if(locdata) {
  1451. ts.p.records = len;
  1452. ts.p.lastpage = Math.ceil(len/ rn);
  1453. }
  1454. if (!more) { ts.updatepager(false,true); }
  1455. if(locdata) {
  1456. while (ir<len && drows[ir]) {
  1457. cur = drows[ir];
  1458. idr = $.jgrid.getAccessor(cur,idn);
  1459. if(idr === undefined) {
  1460. idr = br+ir;
  1461. if(f.length===0){
  1462. if(dReader.cell){
  1463. var ccur2 = $.jgrid.getAccessor(cur,dReader.cell);
  1464. idr = ccur2[idn] || idr;
  1465. ccur2=null;
  1466. }
  1467. }
  1468. }
  1469. if(cur) {
  1470. idr = ts.p.idPrefix + idr;
  1471. if (dReader.repeatitems) {
  1472. if(dReader.cell) {cur = $.jgrid.getAccessor(cur,dReader.cell);}
  1473. if (!F) { F=orderedCols(gi+si+ni); }
  1474. }
  1475. for (j=0;j<F.length;j++) {
  1476. v = $.jgrid.getAccessor(cur,F[j]);
  1477. rd[ts.p.colModel[j+gi+si+ni].name] = v;
  1478. }
  1479. rd[locid] = idr;
  1480. ts.p.data.push(rd);
  1481. ts.p._index[idr] = ts.p.data.length-1;
  1482. rd = {};
  1483. }
  1484. ir++;
  1485. }
  1486. }
  1487. },
  1488. addLocalData = function() {
  1489. var st, fndsort=false, cmtypes={}, grtypes=[], grindexes=[], srcformat, sorttype, newformat;
  1490. if(!$.isArray(ts.p.data)) {
  1491. return;
  1492. }
  1493. var grpview = ts.p.grouping ? ts.p.groupingView : false, lengrp, gin;
  1494. $.each(ts.p.colModel,function(){
  1495. sorttype = this.sorttype || "text";
  1496. if(sorttype == "date" || sorttype == "datetime") {
  1497. if(this.formatter && typeof this.formatter === 'string' && this.formatter == 'date') {
  1498. if(this.formatoptions && this.formatoptions.srcformat) {
  1499. srcformat = this.formatoptions.srcformat;
  1500. } else {
  1501. srcformat = $.jgrid.formatter.date.srcformat;
  1502. }
  1503. if(this.formatoptions && this.formatoptions.newformat) {
  1504. newformat = this.formatoptions.newformat;
  1505. } else {
  1506. newformat = $.jgrid.formatter.date.newformat;
  1507. }
  1508. } else {
  1509. srcformat = newformat = this.datefmt || "Y-m-d";
  1510. }
  1511. cmtypes[this.name] = {"stype": sorttype, "srcfmt": srcformat,"newfmt":newformat};
  1512. } else {
  1513. cmtypes[this.name] = {"stype": sorttype, "srcfmt":'',"newfmt":''};
  1514. }
  1515. if(ts.p.grouping ) {
  1516. for(gin =0, lengrp = grpview.groupField.length; gin< lengrp; gin++) {
  1517. if( this.name == grpview.groupField[gin]) {
  1518. var grindex = this.name;
  1519. if (this.index) {
  1520. grindex = this.index;
  1521. }
  1522. grtypes[gin] = cmtypes[grindex];
  1523. grindexes[gin]= grindex;
  1524. }
  1525. }
  1526. }
  1527. if(!fndsort && (this.index == ts.p.sortname || this.name == ts.p.sortname)){
  1528. st = this.name; // ???
  1529. fndsort = true;
  1530. }
  1531. });
  1532. if(ts.p.treeGrid) {
  1533. $(ts).jqGrid("SortTree", st, ts.p.sortorder, cmtypes[st].stype, cmtypes[st].srcfmt);
  1534. return;
  1535. }
  1536. var compareFnMap = {
  1537. 'eq':function(queryObj) {return queryObj.equals;},
  1538. 'ne':function(queryObj) {return queryObj.notEquals;},
  1539. 'lt':function(queryObj) {return queryObj.less;},
  1540. 'le':function(queryObj) {return queryObj.lessOrEquals;},
  1541. 'gt':function(queryObj) {return queryObj.greater;},
  1542. 'ge':function(queryObj) {return queryObj.greaterOrEquals;},
  1543. 'cn':function(queryObj) {return queryObj.contains;},
  1544. 'nc':function(queryObj,op) {return op === "OR" ? queryObj.orNot().contains : queryObj.andNot().contains;},
  1545. 'bw':function(queryObj) {return queryObj.startsWith;},
  1546. 'bn':function(queryObj,op) {return op === "OR" ? queryObj.orNot().startsWith : queryObj.andNot().startsWith;},
  1547. 'en':function(queryObj,op) {return op === "OR" ? queryObj.orNot().endsWith : queryObj.andNot().endsWith;},
  1548. 'ew':function(queryObj) {return queryObj.endsWith;},
  1549. 'ni':function(queryObj,op) {return op === "OR" ? queryObj.orNot().equals : queryObj.andNot().equals;},
  1550. 'in':function(queryObj) {return queryObj.equals;},
  1551. 'nu':function(queryObj) {return queryObj.isNull;},
  1552. 'nn':function(queryObj,op) {return op === "OR" ? queryObj.orNot().isNull : queryObj.andNot().isNull;}
  1553. },
  1554. query = $.jgrid.from(ts.p.data);
  1555. if (ts.p.ignoreCase) { query = query.ignoreCase(); }
  1556. function tojLinq ( group ) {
  1557. var s = 0, index, gor, ror, opr, rule;
  1558. if (group.groups != null) {
  1559. gor = group.groups.length && group.groupOp.toString().toUpperCase() === "OR";
  1560. if (gor) {
  1561. query.orBegin();
  1562. }
  1563. for (index = 0; index < group.groups.length; index++) {
  1564. if (s > 0 && gor) {
  1565. query.or();
  1566. }
  1567. try {
  1568. tojLinq(group.groups[index]);
  1569. } catch (e) {alert(e);}
  1570. s++;
  1571. }
  1572. if (gor) {
  1573. query.orEnd();
  1574. }
  1575. }
  1576. if (group.rules != null) {
  1577. if(s>0) {
  1578. var result = query.select();
  1579. query = $.jgrid.from( result);
  1580. if (ts.p.ignoreCase) { query = query.ignoreCase(); }
  1581. }
  1582. try{
  1583. ror = group.rules.length && group.groupOp.toString().toUpperCase() === "OR";
  1584. if (ror) {
  1585. query.orBegin();
  1586. }
  1587. for (index = 0; index < group.rules.length; index++) {
  1588. rule = group.rules[index];
  1589. opr = group.groupOp.toString().toUpperCase();
  1590. if (compareFnMap[rule.op] && rule.field ) {
  1591. if(s > 0 && opr && opr === "OR") {
  1592. query = query.or();
  1593. }
  1594. query = compareFnMap[rule.op](query, opr)(rule.field, rule.data, cmtypes[rule.field]);
  1595. }
  1596. s++;
  1597. }
  1598. if (ror) {
  1599. query.orEnd();
  1600. }
  1601. } catch (g) {alert(g);}
  1602. }
  1603. }
  1604. if (ts.p.search === true) {
  1605. var srules = ts.p.postData.filters;
  1606. if(srules) {
  1607. if(typeof srules === "string") { srules = $.jgrid.parse(srules);}
  1608. tojLinq( srules );
  1609. } else {
  1610. try {
  1611. query = compareFnMap[ts.p.postData.searchOper](query)(ts.p.postData.searchField, ts.p.postData.searchString,cmtypes[ts.p.postData.searchField]);
  1612. } catch (se){}
  1613. }
  1614. }
  1615. if(ts.p.grouping) {
  1616. for(gin=0; gin<lengrp;gin++) {
  1617. query.orderBy(grindexes[gin],grpview.groupOrder[gin],grtypes[gin].stype, grtypes[gin].srcfmt);
  1618. }
  1619. }
  1620. if (st && ts.p.sortorder && fndsort) {
  1621. if(ts.p.sortorder.toUpperCase() == "DESC") {
  1622. query.orderBy(ts.p.sortname, "d", cmtypes[st].stype, cmtypes[st].srcfmt);
  1623. } else {
  1624. query.orderBy(ts.p.sortname, "a", cmtypes[st].stype, cmtypes[st].srcfmt);
  1625. }
  1626. }
  1627. var queryResults = query.select(),
  1628. recordsperpage = parseInt(ts.p.rowNum,10),
  1629. total = queryResults.length,
  1630. page = parseInt(ts.p.page,10),
  1631. totalpages = Math.ceil(total / recordsperpage),
  1632. retresult = {};
  1633. queryResults = queryResults.slice( (page-1)*recordsperpage , page*recordsperpage );
  1634. query = null;
  1635. cmtypes = null;
  1636. retresult[ts.p.localReader.total] = totalpages;
  1637. retresult[ts.p.localReader.page] = page;
  1638. retresult[ts.p.localReader.records] = total;
  1639. retresult[ts.p.localReader.root] = queryResults;
  1640. retresult[ts.p.localReader.userdata] = ts.p.userData;
  1641. queryResults = null;
  1642. return retresult;
  1643. },
  1644. updatepager = function(rn, dnd) {
  1645. var cp, last, base, from,to,tot,fmt, pgboxes = "", sppg,
  1646. tspg = ts.p.pager ? "_"+$.jgrid.jqID(ts.p.pager.substr(1)) : "",
  1647. tspg_t = ts.p.toppager ? "_"+ts.p.toppager.substr(1) : "";
  1648. base = parseInt(ts.p.page,10)-1;
  1649. if(base < 0) { base = 0; }
  1650. base = base*parseInt(ts.p.rowNum,10);
  1651. to = base + ts.p.reccount;
  1652. if (ts.p.scroll) {
  1653. var rows = $("tbody:first > tr:gt(0)", ts.grid.bDiv);
  1654. base = to - rows.length;
  1655. ts.p.reccount = rows.length;
  1656. var rh = rows.outerHeight() || ts.grid.prevRowHeight;
  1657. if (rh) {
  1658. var top = base * rh;
  1659. var height = parseInt(ts.p.records,10) * rh;
  1660. $(">div:first",ts.grid.bDiv).css({height : height}).children("div:first").css({height:top,display:top?"":"none"});
  1661. }
  1662. ts.grid.bDiv.scrollLeft = ts.grid.hDiv.scrollLeft;
  1663. }
  1664. pgboxes = ts.p.pager || "";
  1665. pgboxes += ts.p.toppager ? (pgboxes ? "," + ts.p.toppager : ts.p.toppager) : "";
  1666. if(pgboxes) {
  1667. fmt = $.jgrid.formatter.integer || {};
  1668. cp = intNum(ts.p.page);
  1669. last = intNum(ts.p.lastpage);
  1670. $(".selbox",pgboxes)[ this.p.useProp ? 'prop' : 'attr' ]("disabled",false);
  1671. if(ts.p.pginput===true) {
  1672. $('.ui-pg-input',pgboxes).val(ts.p.page);
  1673. sppg = ts.p.toppager ? '#sp_1'+tspg+",#sp_1"+tspg_t : '#sp_1'+tspg;
  1674. $(sppg).html($.fmatter ? $.fmatter.util.NumberFormat(ts.p.lastpage,fmt):ts.p.lastpage);
  1675. }
  1676. if (ts.p.viewrecords){
  1677. if(ts.p.reccount === 0) {
  1678. $(".ui-paging-info",pgboxes).html(ts.p.emptyrecords);
  1679. } else {
  1680. from = base+1;
  1681. tot=ts.p.records;
  1682. if($.fmatter) {
  1683. from = $.fmatter.util.NumberFormat(from,fmt);
  1684. to = $.fmatter.util.NumberFormat(to,fmt);
  1685. tot = $.fmatter.util.NumberFormat(tot,fmt);
  1686. }
  1687. $(".ui-paging-info",pgboxes).html($.jgrid.format(ts.p.recordtext,from,to,tot));
  1688. }
  1689. }
  1690. if(ts.p.pgbuttons===true) {
  1691. if(cp<=0) {cp = last = 0;}
  1692. if(cp==1 || cp === 0) {
  1693. $("#first"+tspg+", #prev"+tspg).addClass('ui-state-disabled').removeClass('ui-state-hover');
  1694. if(ts.p.toppager) { $("#first_t"+tspg_t+", #prev_t"+tspg_t).addClass('ui-state-disabled').removeClass('ui-state-hover'); }
  1695. } else {
  1696. $("#first"+tspg+", #prev"+tspg).removeClass('ui-state-disabled');
  1697. if(ts.p.toppager) { $("#first_t"+tspg_t+", #prev_t"+tspg_t).removeClass('ui-state-disabled'); }
  1698. }
  1699. if(cp==last || cp === 0) {
  1700. $("#next"+tspg+", #last"+tspg).addClass('ui-state-disabled').removeClass('ui-state-hover');
  1701. if(ts.p.toppager) { $("#next_t"+tspg_t+", #last_t"+tspg_t).addClass('ui-state-disabled').removeClass('ui-state-hover'); }
  1702. } else {
  1703. $("#next"+tspg+", #last"+tspg).removeClass('ui-state-disabled');
  1704. if(ts.p.toppager) { $("#next_t"+tspg_t+", #last_t"+tspg_t).removeClass('ui-state-disabled'); }
  1705. }
  1706. }
  1707. }
  1708. if(rn===true && ts.p.rownumbers === true) {
  1709. $("td.jqgrid-rownum",ts.rows).each(function(i){
  1710. $(this).html(base+1+i);
  1711. });
  1712. }
  1713. if(dnd && ts.p.jqgdnd) { $(ts).jqGrid('gridDnD','updateDnD');}
  1714. $(ts).triggerHandler("jqGridGridComplete");
  1715. if($.isFunction(ts.p.gridComplete)) {ts.p.gridComplete.call(ts);}
  1716. $(ts).triggerHandler("jqGridAfterGridComplete");
  1717. },
  1718. beginReq = function() {
  1719. ts.grid.hDiv.loading = true;
  1720. if(ts.p.hiddengrid) { return;}
  1721. switch(ts.p.loadui) {
  1722. case "disable":
  1723. break;
  1724. case "enable":
  1725. $("#load_"+$.jgrid.jqID(ts.p.id)).show();
  1726. break;
  1727. case "block":
  1728. $("#lui_"+$.jgrid.jqID(ts.p.id)).show();
  1729. $("#load_"+$.jgrid.jqID(ts.p.id)).show();
  1730. break;
  1731. }
  1732. },
  1733. endReq = function() {
  1734. ts.grid.hDiv.loading = false;
  1735. switch(ts.p.loadui) {
  1736. case "disable":
  1737. break;
  1738. case "enable":
  1739. $("#load_"+$.jgrid.jqID(ts.p.id)).hide();
  1740. break;
  1741. case "block":
  1742. $("#lui_"+$.jgrid.jqID(ts.p.id)).hide();
  1743. $("#load_"+$.jgrid.jqID(ts.p.id)).hide();
  1744. break;
  1745. }
  1746. },
  1747. populate = function (npage) {
  1748. if(!ts.grid.hDiv.loading) {
  1749. var pvis = ts.p.scroll && npage === false,
  1750. prm = {}, dt, dstr, pN=ts.p.prmNames;
  1751. if(ts.p.page <=0) { ts.p.page = 1; }
  1752. if(pN.search !== null) {prm[pN.search] = ts.p.search;} if(pN.nd !== null) {prm[pN.nd] = new Date().getTime();}
  1753. if(pN.rows !== null) {prm[pN.rows]= ts.p.rowNum;} if(pN.page !== null) {prm[pN.page]= ts.p.page;}
  1754. if(pN.sort !== null) {prm[pN.sort]= ts.p.sortname;} if(pN.order !== null) {prm[pN.order]= ts.p.sortorder;}
  1755. if(ts.p.rowTotal !== null && pN.totalrows !== null) { prm[pN.totalrows]= ts.p.rowTotal; }
  1756. var lcf = $.isFunction(ts.p.loadComplete), lc = lcf ? ts.p.loadComplete : null;
  1757. var adjust = 0;
  1758. npage = npage || 1;
  1759. if (npage > 1) {
  1760. if(pN.npage !== null) {
  1761. prm[pN.npage] = npage;
  1762. adjust = npage - 1;
  1763. npage = 1;
  1764. } else {
  1765. lc = function(req) {
  1766. ts.p.page++;
  1767. ts.grid.hDiv.loading = false;
  1768. if (lcf) {
  1769. ts.p.loadComplete.call(ts,req);
  1770. }
  1771. populate(npage-1);
  1772. };
  1773. }
  1774. } else if (pN.npage !== null) {
  1775. delete ts.p.postData[pN.npage];
  1776. }
  1777. if(ts.p.grouping) {
  1778. $(ts).jqGrid('groupingSetup');
  1779. var grp = ts.p.groupingView, gi, gs="";
  1780. for(gi=0;gi<grp.groupField.length;gi++) {
  1781. var index = grp.groupField[gi];
  1782. $.each(ts.p.colModel, function(cmIndex, cmValue) {
  1783. if (cmValue.name == index && cmValue.index){
  1784. index = cmValue.index;
  1785. }
  1786. } );
  1787. gs += index +" "+grp.groupOrder[gi]+", ";
  1788. }
  1789. prm[pN.sort] = gs + prm[pN.sort];
  1790. }
  1791. $.extend(ts.p.postData,prm);
  1792. var rcnt = !ts.p.scroll ? 1 : ts.rows.length-1;
  1793. var bfr = $(ts).triggerHandler("jqGridBeforeRequest");
  1794. if (bfr === false || bfr === 'stop') { return; }
  1795. if ($.isFunction(ts.p.datatype)) { ts.p.datatype.call(ts,ts.p.postData,"load_"+ts.p.id); return;}
  1796. if ($.isFunction(ts.p.beforeRequest)) {
  1797. bfr = ts.p.beforeRequest.call(ts);
  1798. if(bfr === undefined) { bfr = true; }
  1799. if ( bfr === false ) { return; }
  1800. }
  1801. dt = ts.p.datatype.toLowerCase();
  1802. switch(dt)
  1803. {
  1804. case "json":
  1805. case "jsonp":
  1806. case "xml":
  1807. case "script":
  1808. $.ajax($.extend({
  1809. url:ts.p.url,
  1810. type:ts.p.mtype,
  1811. dataType: dt ,
  1812. data: $.isFunction(ts.p.serializeGridData)? ts.p.serializeGridData.call(ts,ts.p.postData) : ts.p.postData,
  1813. success:function(data,st, xhr) {
  1814. if ($.isFunction(ts.p.beforeProcessing)) {
  1815. if (ts.p.beforeProcessing.call(ts, data, st, xhr) === false) {
  1816. endReq();
  1817. return;
  1818. }
  1819. }
  1820. if(dt === "xml") { addXmlData(data,ts.grid.bDiv,rcnt,npage>1,adjust); }
  1821. else { addJSONData(data,ts.grid.bDiv,rcnt,npage>1,adjust); }
  1822. $(ts).triggerHandler("jqGridLoadComplete", [data]);
  1823. if(lc) { lc.call(ts,data); }
  1824. $(ts).triggerHandler("jqGridAfterLoadComplete", [data]);
  1825. if (pvis) { ts.grid.populateVisible(); }
  1826. if( ts.p.loadonce || ts.p.treeGrid) {ts.p.datatype = "local";}
  1827. data=null;
  1828. if (npage === 1) { endReq(); }
  1829. },
  1830. error:function(xhr,st,err){
  1831. if($.isFunction(ts.p.loadError)) { ts.p.loadError.call(ts,xhr,st,err); }
  1832. if (npage === 1) { endReq(); }
  1833. xhr=null;
  1834. },
  1835. beforeSend: function(xhr, settings ){
  1836. var gotoreq = true;
  1837. if($.isFunction(ts.p.loadBeforeSend)) {
  1838. gotoreq = ts.p.loadBeforeSend.call(ts,xhr, settings);
  1839. }
  1840. if(gotoreq === undefined) { gotoreq = true; }
  1841. if(gotoreq === false) {
  1842. return false;
  1843. }
  1844. beginReq();
  1845. }
  1846. },$.jgrid.ajaxOptions, ts.p.ajaxGridOptions));
  1847. break;
  1848. case "xmlstring":
  1849. beginReq();
  1850. dstr = $.jgrid.stringToDoc(ts.p.datastr);
  1851. addXmlData(dstr,ts.grid.bDiv);
  1852. $(ts).triggerHandler("jqGridLoadComplete", [dstr]);
  1853. if(lcf) {ts.p.loadComplete.call(ts,dstr);}
  1854. $(ts).triggerHandler("jqGridAfterLoadComplete", [dstr]);
  1855. ts.p.datatype = "local";
  1856. ts.p.datastr = null;
  1857. endReq();
  1858. break;
  1859. case "jsonstring":
  1860. beginReq();
  1861. if(typeof ts.p.datastr === 'string') { dstr = $.jgrid.parse(ts.p.datastr); }
  1862. else { dstr = ts.p.datastr; }
  1863. addJSONData(dstr,ts.grid.bDiv);
  1864. $(ts).triggerHandler("jqGridLoadComplete", [dstr]);
  1865. if(lcf) {ts.p.loadComplete.call(ts,dstr);}
  1866. $(ts).triggerHandler("jqGridAfterLoadComplete", [dstr]);
  1867. ts.p.datatype = "local";
  1868. ts.p.datastr = null;
  1869. endReq();
  1870. break;
  1871. case "local":
  1872. case "clientside":
  1873. beginReq();
  1874. ts.p.datatype = "local";
  1875. var req = addLocalData();
  1876. addJSONData(req,ts.grid.bDiv,rcnt,npage>1,adjust);
  1877. $(ts).triggerHandler("jqGridLoadComplete", [req]);
  1878. if(lc) { lc.call(ts,req); }
  1879. $(ts).triggerHandler("jqGridAfterLoadComplete", [req]);
  1880. if (pvis) { ts.grid.populateVisible(); }
  1881. endReq();
  1882. break;
  1883. }
  1884. }
  1885. },
  1886. setHeadCheckBox = function ( checked ) {
  1887. $('#cb_'+$.jgrid.jqID(ts.p.id),ts.grid.hDiv)[ts.p.useProp ? 'prop': 'attr']("checked", checked);
  1888. var fid = ts.p.frozenColumns ? ts.p.id+"_frozen" : "";
  1889. if(fid) {
  1890. $('#cb_'+$.jgrid.jqID(ts.p.id),ts.grid.fhDiv)[ts.p.useProp ? 'prop': 'attr']("checked", checked);
  1891. }
  1892. },
  1893. setPager = function (pgid, tp){
  1894. // TBD - consider escaping pgid with pgid = $.jgrid.jqID(pgid);
  1895. var sep = "<td class='ui-pg-button ui-state-disabled' style='width:4px;'><span class='ui-separator'></span></td>",
  1896. pginp = "",
  1897. pgl="<table cellspacing='0' cellpadding='0' border='0' style='table-layout:auto;' class='ui-pg-table'><tbody><tr>",
  1898. str="", pgcnt, lft, cent, rgt, twd, tdw, i,
  1899. clearVals = function(onpaging){
  1900. var ret;
  1901. if ($.isFunction(ts.p.onPaging) ) { ret = ts.p.onPaging.call(ts,onpaging); }
  1902. ts.p.selrow = null;
  1903. if(ts.p.multiselect) {ts.p.selarrrow =[]; setHeadCheckBox( false );}
  1904. ts.p.savedRow = [];
  1905. if(ret=='stop') {return false;}
  1906. return true;
  1907. };
  1908. pgid = pgid.substr(1);
  1909. tp += "_" + pgid;
  1910. pgcnt = "pg_"+pgid;
  1911. lft = pgid+"_left"; cent = pgid+"_center"; rgt = pgid+"_right";
  1912. $("#"+$.jgrid.jqID(pgid) )
  1913. .append("<div id='"+pgcnt+"' class='ui-pager-control' role='group'><table cellspacing='0' cellpadding='0' border='0' class='ui-pg-table' style='width:100%;table-layout:fixed;height:100%;' role='row'><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>")
  1914. .attr("dir","ltr"); //explicit setting
  1915. if(ts.p.rowList.length >0){
  1916. str = "<td dir='"+dir+"'>";
  1917. str +="<select class='ui-pg-selbox' role='listbox'>";
  1918. for(i=0;i<ts.p.rowList.length;i++){
  1919. str +="<option role=\"option\" value=\""+ts.p.rowList[i]+"\""+((ts.p.rowNum == ts.p.rowList[i])?" selected=\"selected\"":"")+">"+ts.p.rowList[i]+"</option>";
  1920. }
  1921. str +="</select></td>";
  1922. }
  1923. if(dir=="rtl") { pgl += str; }
  1924. if(ts.p.pginput===true) { pginp= "<td dir='"+dir+"'>"+$.jgrid.format(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>";}
  1925. if(ts.p.pgbuttons===true) {
  1926. var po=["first"+tp,"prev"+tp, "next"+tp,"last"+tp]; if(dir=="rtl") { po.reverse(); }
  1927. pgl += "<td id='"+po[0]+"' class='ui-pg-button ui-corner-all'><span class='ui-icon ui-icon-seek-first'></span></td>";
  1928. pgl += "<td id='"+po[1]+"' class='ui-pg-button ui-corner-all'><span class='ui-icon ui-icon-seek-prev'></span></td>";
  1929. pgl += pginp !== "" ? sep+pginp+sep:"";
  1930. pgl += "<td id='"+po[2]+"' class='ui-pg-button ui-corner-all'><span class='ui-icon ui-icon-seek-next'></span></td>";
  1931. pgl += "<td id='"+po[3]+"' class='ui-pg-button ui-corner-all'><span class='ui-icon ui-icon-seek-end'></span></td>";
  1932. } else if (pginp !== "") { pgl += pginp; }
  1933. if(dir=="ltr") { pgl += str; }
  1934. pgl += "</tr></tbody></table>";
  1935. if(ts.p.viewrecords===true) {$("td#"+pgid+"_"+ts.p.recordpos,"#"+pgcnt).append("<div dir='"+dir+"' style='text-align:"+ts.p.recordpos+"' class='ui-paging-info'></div>");}
  1936. $("td#"+pgid+"_"+ts.p.pagerpos,"#"+pgcnt).append(pgl);
  1937. tdw = $(".ui-jqgrid").css("font-size") || "11px";
  1938. $(document.body).append("<div id='testpg' class='ui-jqgrid ui-widget ui-widget-content' style='font-size:"+tdw+";visibility:hidden;' ></div>");
  1939. twd = $(pgl).clone().appendTo("#testpg").width();
  1940. $("#testpg").remove();
  1941. if(twd > 0) {
  1942. if(pginp !== "") { twd += 50; } //should be param
  1943. $("td#"+pgid+"_"+ts.p.pagerpos,"#"+pgcnt).width(twd);
  1944. }
  1945. ts.p._nvtd = [];
  1946. ts.p._nvtd[0] = twd ? Math.floor((ts.p.width - twd)/2) : Math.floor(ts.p.width/3);
  1947. ts.p._nvtd[1] = 0;
  1948. pgl=null;
  1949. $('.ui-pg-selbox',"#"+pgcnt).bind('change',function() {
  1950. if(!clearVals('records')) { return false; }
  1951. ts.p.page = Math.round(ts.p.rowNum*(ts.p.page-1)/this.value-0.5)+1;
  1952. ts.p.rowNum = this.value;
  1953. if(ts.p.pager) { $('.ui-pg-selbox',ts.p.pager).val(this.value); }
  1954. if(ts.p.toppager) { $('.ui-pg-selbox',ts.p.toppager).val(this.value); }
  1955. populate();
  1956. return false;
  1957. });
  1958. if(ts.p.pgbuttons===true) {
  1959. $(".ui-pg-button","#"+pgcnt).hover(function(){
  1960. if($(this).hasClass('ui-state-disabled')) {
  1961. this.style.cursor='default';
  1962. } else {
  1963. $(this).addClass('ui-state-hover');
  1964. this.style.cursor='pointer';
  1965. }
  1966. },function() {
  1967. if(!$(this).hasClass('ui-state-disabled')) {
  1968. $(this).removeClass('ui-state-hover');
  1969. this.style.cursor= "default";
  1970. }
  1971. });
  1972. $("#first"+$.jgrid.jqID(tp)+", #prev"+$.jgrid.jqID(tp)+", #next"+$.jgrid.jqID(tp)+", #last"+$.jgrid.jqID(tp)).click( function() {
  1973. var cp = intNum(ts.p.page,1),
  1974. last = intNum(ts.p.lastpage,1), selclick = false,
  1975. fp=true, pp=true, np=true,lp=true;
  1976. if(last ===0 || last===1) {fp=false;pp=false;np=false;lp=false; }
  1977. else if( last>1 && cp >=1) {
  1978. if( cp === 1) { fp=false; pp=false; }
  1979. //else if( cp>1 && cp <last){ }
  1980. else if( cp===last){ np=false;lp=false; }
  1981. } else if( last>1 && cp===0 ) { np=false;lp=false; cp=last-1;}
  1982. if(!clearVals(this.id)) { return false; }
  1983. if( this.id === 'first'+tp && fp ) { ts.p.page=1; selclick=true;}
  1984. if( this.id === 'prev'+tp && pp) { ts.p.page=(cp-1); selclick=true;}
  1985. if( this.id === 'next'+tp && np) { ts.p.page=(cp+1); selclick=true;}
  1986. if( this.id === 'last'+tp && lp) { ts.p.page=last; selclick=true;}
  1987. if(selclick) {
  1988. populate();
  1989. }
  1990. return false;
  1991. });
  1992. }
  1993. if(ts.p.pginput===true) {
  1994. $('input.ui-pg-input',"#"+pgcnt).keypress( function(e) {
  1995. var key = e.charCode || e.keyCode || 0;
  1996. if(key == 13) {
  1997. if(!clearVals('user')) { return false; }
  1998. ts.p.page = ($(this).val()>0) ? $(this).val():ts.p.page;
  1999. populate();
  2000. return false;
  2001. }
  2002. return this;
  2003. });
  2004. }
  2005. },
  2006. sortData = function (index, idxcol,reload,sor){
  2007. if(!ts.p.colModel[idxcol].sortable) { return; }
  2008. var so;
  2009. if(ts.p.savedRow.length > 0) {return;}
  2010. if(!reload) {
  2011. if( ts.p.lastsort == idxcol ) {
  2012. if( ts.p.sortorder == 'asc') {
  2013. ts.p.sortorder = 'desc';
  2014. } else if(ts.p.sortorder == 'desc') { ts.p.sortorder = 'asc';}
  2015. } else { ts.p.sortorder = ts.p.colModel[idxcol].firstsortorder || 'asc'; }
  2016. ts.p.page = 1;
  2017. }
  2018. if(sor) {
  2019. if(ts.p.lastsort == idxcol && ts.p.sortorder == sor && !reload) { return; }
  2020. ts.p.sortorder = sor;
  2021. }
  2022. var previousSelectedTh = ts.grid.headers[ts.p.lastsort].el, newSelectedTh = ts.grid.headers[idxcol].el;
  2023. $("span.ui-grid-ico-sort",previousSelectedTh).addClass('ui-state-disabled');
  2024. $(previousSelectedTh).attr("aria-selected","false");
  2025. $("span.ui-icon-"+ts.p.sortorder,newSelectedTh).removeClass('ui-state-disabled');
  2026. $(newSelectedTh).attr("aria-selected","true");
  2027. if(!ts.p.viewsortcols[0]) {
  2028. if(ts.p.lastsort != idxcol) {
  2029. $("span.s-ico",previousSelectedTh).hide();
  2030. $("span.s-ico",newSelectedTh).show();
  2031. }
  2032. }
  2033. index = index.substring(5 + ts.p.id.length + 1); // bad to be changed!?!
  2034. ts.p.sortname = ts.p.colModel[idxcol].index || index;
  2035. so = ts.p.sortorder;
  2036. if ($(ts).triggerHandler("jqGridSortCol", [index, idxcol, so]) === 'stop') {
  2037. ts.p.lastsort = idxcol;
  2038. return;
  2039. }
  2040. if($.isFunction(ts.p.onSortCol)) {if (ts.p.onSortCol.call(ts,index,idxcol,so)=='stop') {ts.p.lastsort = idxcol; return;}}
  2041. if(ts.p.datatype == "local") {
  2042. if(ts.p.deselectAfterSort) {$(ts).jqGrid("resetSelection");}
  2043. } else {
  2044. ts.p.selrow = null;
  2045. if(ts.p.multiselect){setHeadCheckBox( false );}
  2046. ts.p.selarrrow =[];
  2047. ts.p.savedRow =[];
  2048. }
  2049. if(ts.p.scroll) {
  2050. var sscroll = ts.grid.bDiv.scrollLeft;
  2051. emptyRows.call(ts, true, false);
  2052. ts.grid.hDiv.scrollLeft = sscroll;
  2053. }
  2054. if(ts.p.subGrid && ts.p.datatype=='local') {
  2055. $("td.sgexpanded","#"+$.jgrid.jqID(ts.p.id)).each(function(){
  2056. $(this).trigger("click");
  2057. });
  2058. }
  2059. populate();
  2060. ts.p.lastsort = idxcol;
  2061. if(ts.p.sortname != index && idxcol) {ts.p.lastsort = idxcol;}
  2062. },
  2063. setColWidth = function () {
  2064. 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,
  2065. cl = 0, cr;
  2066. $.each(ts.p.colModel, function() {
  2067. if(this.hidden === undefined) {this.hidden=false;}
  2068. if(ts.p.grouping && ts.p.autowidth) {
  2069. var ind = $.inArray(this.name, ts.p.groupingView.groupField);
  2070. if(ind !== -1) {
  2071. this.hidden = !ts.p.groupingView.groupColumnShow[ind];
  2072. }
  2073. }
  2074. this.widthOrg = cw = intNum(this.width,0);
  2075. if(this.hidden===false){
  2076. initwidth += cw+brd;
  2077. if(this.fixed) {
  2078. gw += cw+brd;
  2079. } else {
  2080. vc++;
  2081. }
  2082. cl++;
  2083. }
  2084. });
  2085. if(isNaN(ts.p.width)) {
  2086. ts.p.width = initwidth + ((ts.p.shrinkToFit ===false && !isNaN(ts.p.height)) ? scw : 0);
  2087. }
  2088. grid.width = ts.p.width;
  2089. ts.p.tblwidth = initwidth;
  2090. if(ts.p.shrinkToFit ===false && ts.p.forceFit === true) {ts.p.forceFit=false;}
  2091. if(ts.p.shrinkToFit===true && vc > 0) {
  2092. aw = grid.width-brd*vc-gw;
  2093. if(!isNaN(ts.p.height)) {
  2094. aw -= scw;
  2095. hs = true;
  2096. }
  2097. initwidth =0;
  2098. $.each(ts.p.colModel, function(i) {
  2099. if(this.hidden === false && !this.fixed){
  2100. cw = Math.round(aw*this.width/(ts.p.tblwidth-brd*vc-gw));
  2101. this.width =cw;
  2102. initwidth += cw;
  2103. lvc = i;
  2104. }
  2105. });
  2106. cr =0;
  2107. if (hs) {
  2108. if(grid.width-gw-(initwidth+brd*vc) !== scw){
  2109. cr = grid.width-gw-(initwidth+brd*vc)-scw;
  2110. }
  2111. } else if(!hs && Math.abs(grid.width-gw-(initwidth+brd*vc)) !== 1) {
  2112. cr = grid.width-gw-(initwidth+brd*vc);
  2113. }
  2114. ts.p.colModel[lvc].width += cr;
  2115. ts.p.tblwidth = initwidth+cr+brd*vc+gw;
  2116. if(ts.p.tblwidth > ts.p.width) {
  2117. ts.p.colModel[lvc].width -= (ts.p.tblwidth - parseInt(ts.p.width,10));
  2118. ts.p.tblwidth = ts.p.width;
  2119. }
  2120. }
  2121. },
  2122. nextVisible= function(iCol) {
  2123. var ret = iCol, j=iCol, i;
  2124. for (i = iCol+1;i<ts.p.colModel.length;i++){
  2125. if(ts.p.colModel[i].hidden !== true ) {
  2126. j=i; break;
  2127. }
  2128. }
  2129. return j-ret;
  2130. },
  2131. getOffset = function (iCol) {
  2132. var i, ret = {}, brd1 = $.jgrid.cell_width ? 0 : ts.p.cellLayout;
  2133. ret[0] = ret[1] = ret[2] = 0;
  2134. for(i=0;i<=iCol;i++){
  2135. if(ts.p.colModel[i].hidden === false ) {
  2136. ret[0] += ts.p.colModel[i].width+brd1;
  2137. }
  2138. }
  2139. if(ts.p.direction=="rtl") { ret[0] = ts.p.width - ret[0]; }
  2140. ret[0] = ret[0] - ts.grid.bDiv.scrollLeft;
  2141. if($(ts.grid.cDiv).is(":visible")) {ret[1] += $(ts.grid.cDiv).height() +parseInt($(ts.grid.cDiv).css("padding-top"),10)+parseInt($(ts.grid.cDiv).css("padding-bottom"),10);}
  2142. if(ts.p.toolbar[0]===true && (ts.p.toolbar[1]=='top' || ts.p.toolbar[1]=='both')) {ret[1] += $(ts.grid.uDiv).height()+parseInt($(ts.grid.uDiv).css("border-top-width"),10)+parseInt($(ts.grid.uDiv).css("border-bottom-width"),10);}
  2143. if(ts.p.toppager) {ret[1] += $(ts.grid.topDiv).height()+parseInt($(ts.grid.topDiv).css("border-bottom-width"),10);}
  2144. ret[2] += $(ts.grid.bDiv).height() + $(ts.grid.hDiv).height();
  2145. return ret;
  2146. },
  2147. getColumnHeaderIndex = function (th) {
  2148. var i, headers = ts.grid.headers, ci = $.jgrid.getCellIndex(th);
  2149. for (i = 0; i < headers.length; i++) {
  2150. if (th === headers[i].el) {
  2151. ci = i;
  2152. break;
  2153. }
  2154. }
  2155. return ci;
  2156. };
  2157. this.p.id = this.id;
  2158. if ($.inArray(ts.p.multikey,sortkeys) == -1 ) {ts.p.multikey = false;}
  2159. ts.p.keyIndex=false;
  2160. for (i=0; i<ts.p.colModel.length;i++) {
  2161. ts.p.colModel[i] = $.extend(true, {}, ts.p.cmTemplate, ts.p.colModel[i].template || {}, ts.p.colModel[i]);
  2162. if (ts.p.keyIndex === false && ts.p.colModel[i].key===true) {
  2163. ts.p.keyIndex = i;
  2164. }
  2165. }
  2166. ts.p.sortorder = ts.p.sortorder.toLowerCase();
  2167. $.jgrid.cell_width = $.jgrid.cellWidth();
  2168. if(ts.p.grouping===true) {
  2169. ts.p.scroll = false;
  2170. ts.p.rownumbers = false;
  2171. //ts.p.subGrid = false; expiremental
  2172. ts.p.treeGrid = false;
  2173. ts.p.gridview = true;
  2174. }
  2175. if(this.p.treeGrid === true) {
  2176. try { $(this).jqGrid("setTreeGrid");} catch (_) {}
  2177. if(ts.p.datatype != "local") { ts.p.localReader = {id: "_id_"}; }
  2178. }
  2179. if(this.p.subGrid) {
  2180. try { $(ts).jqGrid("setSubGrid");} catch (s){}
  2181. }
  2182. if(this.p.multiselect) {
  2183. this.p.colNames.unshift("<input role='checkbox' id='cb_"+this.p.id+"' class='cbox' type='checkbox'/>");
  2184. 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});
  2185. }
  2186. if(this.p.rownumbers) {
  2187. this.p.colNames.unshift("");
  2188. this.p.colModel.unshift({name:'rn',width:ts.p.rownumWidth,sortable:false,resizable:false,hidedlg:true,search:false,align:'center',fixed:true});
  2189. }
  2190. ts.p.xmlReader = $.extend(true,{
  2191. root: "rows",
  2192. row: "row",
  2193. page: "rows>page",
  2194. total: "rows>total",
  2195. records : "rows>records",
  2196. repeatitems: true,
  2197. cell: "cell",
  2198. id: "[id]",
  2199. userdata: "userdata",
  2200. subgrid: {root:"rows", row: "row", repeatitems: true, cell:"cell"}
  2201. }, ts.p.xmlReader);
  2202. ts.p.jsonReader = $.extend(true,{
  2203. root: "rows",
  2204. page: "page",
  2205. total: "total",
  2206. records: "records",
  2207. repeatitems: true,
  2208. cell: "cell",
  2209. id: "id",
  2210. userdata: "userdata",
  2211. subgrid: {root:"rows", repeatitems: true, cell:"cell"}
  2212. },ts.p.jsonReader);
  2213. ts.p.localReader = $.extend(true,{
  2214. root: "rows",
  2215. page: "page",
  2216. total: "total",
  2217. records: "records",
  2218. repeatitems: false,
  2219. cell: "cell",
  2220. id: "id",
  2221. userdata: "userdata",
  2222. subgrid: {root:"rows", repeatitems: true, cell:"cell"}
  2223. },ts.p.localReader);
  2224. if(ts.p.scroll){
  2225. ts.p.pgbuttons = false; ts.p.pginput=false; ts.p.rowList=[];
  2226. }
  2227. if(ts.p.data.length) { refreshIndex(); }
  2228. var thead = "<thead><tr class='ui-jqgrid-labels' role='rowheader'>",
  2229. tdc, idn, w, res, sort,
  2230. td, ptr, tbody, imgs,iac="",idc="";
  2231. if(ts.p.shrinkToFit===true && ts.p.forceFit===true) {
  2232. for (i=ts.p.colModel.length-1;i>=0;i--){
  2233. if(!ts.p.colModel[i].hidden) {
  2234. ts.p.colModel[i].resizable=false;
  2235. break;
  2236. }
  2237. }
  2238. }
  2239. if(ts.p.viewsortcols[1] == 'horizontal') {iac=" ui-i-asc";idc=" ui-i-desc";}
  2240. tdc = isMSIE ? "class='ui-th-div-ie'" :"";
  2241. imgs = "<span class='s-ico' style='display:none'><span sort='asc' class='ui-grid-ico-sort ui-icon-asc"+iac+" ui-state-disabled ui-icon ui-icon-triangle-1-n ui-sort-"+dir+"'></span>";
  2242. imgs += "<span sort='desc' class='ui-grid-ico-sort ui-icon-desc"+idc+" ui-state-disabled ui-icon ui-icon-triangle-1-s ui-sort-"+dir+"'></span></span>";
  2243. for(i=0;i<this.p.colNames.length;i++){
  2244. var tooltip = ts.p.headertitles ? (" title=\""+$.jgrid.stripHtml(ts.p.colNames[i])+"\"") :"";
  2245. thead += "<th id='"+ts.p.id+"_"+ts.p.colModel[i].name+"' role='columnheader' class='ui-state-default ui-th-column ui-th-"+dir+"'"+ tooltip+">";
  2246. idn = ts.p.colModel[i].index || ts.p.colModel[i].name;
  2247. thead += "<div id='jqgh_"+ts.p.id+"_"+ts.p.colModel[i].name+"' "+tdc+">"+ts.p.colNames[i];
  2248. if(!ts.p.colModel[i].width) { ts.p.colModel[i].width = 150; }
  2249. else { ts.p.colModel[i].width = parseInt(ts.p.colModel[i].width,10); }
  2250. if(typeof ts.p.colModel[i].title !== "boolean") { ts.p.colModel[i].title = true; }
  2251. if (idn == ts.p.sortname) {
  2252. ts.p.lastsort = i;
  2253. }
  2254. thead += imgs+"</div></th>";
  2255. }
  2256. thead += "</tr></thead>";
  2257. imgs = null;
  2258. $(this).append(thead);
  2259. $("thead tr:first th",this).hover(function(){$(this).addClass('ui-state-hover');},function(){$(this).removeClass('ui-state-hover');});
  2260. if(this.p.multiselect) {
  2261. var emp=[], chk;
  2262. $('#cb_'+$.jgrid.jqID(ts.p.id),this).bind('click',function(){
  2263. ts.p.selarrrow = [];
  2264. var froz = ts.p.frozenColumns === true ? ts.p.id + "_frozen" : "";
  2265. if (this.checked) {
  2266. $(ts.rows).each(function(i) {
  2267. if (i>0) {
  2268. if(!$(this).hasClass("ui-subgrid") && !$(this).hasClass("jqgroup") && !$(this).hasClass('ui-state-disabled')){
  2269. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id) )[ts.p.useProp ? 'prop': 'attr']("checked",true);
  2270. $(this).addClass("ui-state-highlight").attr("aria-selected","true");
  2271. ts.p.selarrrow.push(this.id);
  2272. ts.p.selrow = this.id;
  2273. if(froz) {
  2274. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id), ts.grid.fbDiv )[ts.p.useProp ? 'prop': 'attr']("checked",true);
  2275. $("#"+$.jgrid.jqID(this.id), ts.grid.fbDiv).addClass("ui-state-highlight");
  2276. }
  2277. }
  2278. }
  2279. });
  2280. chk=true;
  2281. emp=[];
  2282. }
  2283. else {
  2284. $(ts.rows).each(function(i) {
  2285. if(i>0) {
  2286. if(!$(this).hasClass("ui-subgrid") && !$(this).hasClass('ui-state-disabled')){
  2287. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id) )[ts.p.useProp ? 'prop': 'attr']("checked", false);
  2288. $(this).removeClass("ui-state-highlight").attr("aria-selected","false");
  2289. emp.push(this.id);
  2290. if(froz) {
  2291. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id), ts.grid.fbDiv )[ts.p.useProp ? 'prop': 'attr']("checked",false);
  2292. $("#"+$.jgrid.jqID(this.id), ts.grid.fbDiv).removeClass("ui-state-highlight");
  2293. }
  2294. }
  2295. }
  2296. });
  2297. ts.p.selrow = null;
  2298. chk=false;
  2299. }
  2300. $(ts).triggerHandler("jqGridSelectAll", [chk ? ts.p.selarrrow : emp, chk]);
  2301. if($.isFunction(ts.p.onSelectAll)) {ts.p.onSelectAll.call(ts, chk ? ts.p.selarrrow : emp,chk);}
  2302. });
  2303. }
  2304. if(ts.p.autowidth===true) {
  2305. var pw = $(eg).innerWidth();
  2306. ts.p.width = pw > 0? pw: 'nw';
  2307. }
  2308. setColWidth();
  2309. $(eg).css("width",grid.width+"px").append("<div class='ui-jqgrid-resize-mark' id='rs_m"+ts.p.id+"'>&#160;</div>");
  2310. $(gv).css("width",grid.width+"px");
  2311. thead = $("thead:first",ts).get(0);
  2312. var tfoot = "";
  2313. if(ts.p.footerrow) { tfoot += "<table role='grid' style='width:"+ts.p.tblwidth+"px' class='ui-jqgrid-ftable' cellspacing='0' cellpadding='0' border='0'><tbody><tr role='row' class='ui-widget-content footrow footrow-"+dir+"'>"; }
  2314. var thr = $("tr:first",thead),
  2315. firstr = "<tr class='jqgfirstrow' role='row' style='height:auto'>";
  2316. ts.p.disableClick=false;
  2317. $("th",thr).each(function ( j ) {
  2318. w = ts.p.colModel[j].width;
  2319. if(ts.p.colModel[j].resizable === undefined) {ts.p.colModel[j].resizable = true;}
  2320. if(ts.p.colModel[j].resizable){
  2321. res = document.createElement("span");
  2322. $(res).html("&#160;").addClass('ui-jqgrid-resize ui-jqgrid-resize-'+dir);
  2323. if(!$.browser.opera) { $(res).css("cursor","col-resize"); }
  2324. $(this).addClass(ts.p.resizeclass);
  2325. } else {
  2326. res = "";
  2327. }
  2328. $(this).css("width",w+"px").prepend(res);
  2329. var hdcol = "";
  2330. if( ts.p.colModel[j].hidden ) {
  2331. $(this).css("display","none");
  2332. hdcol = "display:none;";
  2333. }
  2334. firstr += "<td role='gridcell' style='height:0px;width:"+w+"px;"+hdcol+"'></td>";
  2335. grid.headers[j] = { width: w, el: this };
  2336. sort = ts.p.colModel[j].sortable;
  2337. if( typeof sort !== 'boolean') {ts.p.colModel[j].sortable = true; sort=true;}
  2338. var nm = ts.p.colModel[j].name;
  2339. if( !(nm == 'cb' || nm=='subgrid' || nm=='rn') ) {
  2340. if(ts.p.viewsortcols[2]){
  2341. $(">div",this).addClass('ui-jqgrid-sortable');
  2342. }
  2343. }
  2344. if(sort) {
  2345. if(ts.p.viewsortcols[0]) {$("div span.s-ico",this).show(); if(j==ts.p.lastsort){ $("div span.ui-icon-"+ts.p.sortorder,this).removeClass("ui-state-disabled");}}
  2346. else if( j == ts.p.lastsort) {$("div span.s-ico",this).show();$("div span.ui-icon-"+ts.p.sortorder,this).removeClass("ui-state-disabled");}
  2347. }
  2348. if(ts.p.footerrow) { tfoot += "<td role='gridcell' "+formatCol(j,0,'', null, '', false)+">&#160;</td>"; }
  2349. }).mousedown(function(e) {
  2350. if ($(e.target).closest("th>span.ui-jqgrid-resize").length != 1) { return; }
  2351. var ci = getColumnHeaderIndex(this);
  2352. if(ts.p.forceFit===true) {ts.p.nv= nextVisible(ci);}
  2353. grid.dragStart(ci, e, getOffset(ci));
  2354. return false;
  2355. }).click(function(e) {
  2356. if (ts.p.disableClick) {
  2357. ts.p.disableClick = false;
  2358. return false;
  2359. }
  2360. var s = "th>div.ui-jqgrid-sortable",r,d;
  2361. if (!ts.p.viewsortcols[2]) { s = "th>div>span>span.ui-grid-ico-sort"; }
  2362. var t = $(e.target).closest(s);
  2363. if (t.length != 1) { return; }
  2364. var ci = getColumnHeaderIndex(this);
  2365. if (!ts.p.viewsortcols[2]) { r=true;d=t.attr("sort"); }
  2366. sortData( $('div',this)[0].id, ci, r, d);
  2367. return false;
  2368. });
  2369. if (ts.p.sortable && $.fn.sortable) {
  2370. try {
  2371. $(ts).jqGrid("sortableColumns", thr);
  2372. } catch (e){}
  2373. }
  2374. if(ts.p.footerrow) { tfoot += "</tr></tbody></table>"; }
  2375. firstr += "</tr>";
  2376. tbody = document.createElement("tbody");
  2377. this.appendChild(tbody);
  2378. $(this).addClass('ui-jqgrid-btable').append(firstr);
  2379. firstr = null;
  2380. var hTable = $("<table class='ui-jqgrid-htable' style='width:"+ts.p.tblwidth+"px' role='grid' aria-labelledby='gbox_"+this.id+"' cellspacing='0' cellpadding='0' border='0'></table>").append(thead),
  2381. hg = (ts.p.caption && ts.p.hiddengrid===true) ? true : false,
  2382. hb = $("<div class='ui-jqgrid-hbox" + (dir=="rtl" ? "-rtl" : "" )+"'></div>");
  2383. thead = null;
  2384. grid.hDiv = document.createElement("div");
  2385. $(grid.hDiv)
  2386. .css({ width: grid.width+"px"})
  2387. .addClass("ui-state-default ui-jqgrid-hdiv")
  2388. .append(hb);
  2389. $(hb).append(hTable);
  2390. hTable = null;
  2391. if(hg) { $(grid.hDiv).hide(); }
  2392. if(ts.p.pager){
  2393. // TBD -- escape ts.p.pager here?
  2394. if(typeof ts.p.pager === "string") {if(ts.p.pager.substr(0,1) !="#") { ts.p.pager = "#"+ts.p.pager;} }
  2395. else { ts.p.pager = "#"+ $(ts.p.pager).attr("id");}
  2396. $(ts.p.pager).css({width: grid.width+"px"}).appendTo(eg).addClass('ui-state-default ui-jqgrid-pager ui-corner-bottom');
  2397. if(hg) {$(ts.p.pager).hide();}
  2398. setPager(ts.p.pager,'');
  2399. }
  2400. if( ts.p.cellEdit === false && ts.p.hoverrows === true) {
  2401. $(ts).bind('mouseover',function(e) {
  2402. ptr = $(e.target).closest("tr.jqgrow");
  2403. if($(ptr).attr("class") !== "ui-subgrid") {
  2404. $(ptr).addClass("ui-state-hover");
  2405. }
  2406. }).bind('mouseout',function(e) {
  2407. ptr = $(e.target).closest("tr.jqgrow");
  2408. $(ptr).removeClass("ui-state-hover");
  2409. });
  2410. }
  2411. var ri,ci, tdHtml;
  2412. $(ts).before(grid.hDiv).click(function(e) {
  2413. td = e.target;
  2414. ptr = $(td,ts.rows).closest("tr.jqgrow");
  2415. if($(ptr).length === 0 || ptr[0].className.indexOf( 'ui-state-disabled' ) > -1 || ($(td,ts).closest("table.ui-jqgrid-btable").attr('id') || '').replace("_frozen","") !== ts.id ) {
  2416. return this;
  2417. }
  2418. var scb = $(td).hasClass("cbox"),
  2419. cSel = $(ts).triggerHandler("jqGridBeforeSelectRow", [ptr[0].id, e]);
  2420. cSel = (cSel === false || cSel === 'stop') ? false : true;
  2421. if(cSel && $.isFunction(ts.p.beforeSelectRow)) { cSel = ts.p.beforeSelectRow.call(ts,ptr[0].id, e); }
  2422. if (td.tagName == 'A' || ((td.tagName == 'INPUT' || td.tagName == 'TEXTAREA' || td.tagName == 'OPTION' || td.tagName == 'SELECT' ) && !scb) ) { return; }
  2423. if(cSel === true) {
  2424. ri = ptr[0].id;
  2425. ci = $.jgrid.getCellIndex(td);
  2426. tdHtml = $(td).closest("td,th").html();
  2427. $(ts).triggerHandler("jqGridCellSelect", [ri,ci,tdHtml,e]);
  2428. if($.isFunction(ts.p.onCellSelect)) {
  2429. ts.p.onCellSelect.call(ts,ri,ci,tdHtml,e);
  2430. }
  2431. if(ts.p.cellEdit === true) {
  2432. if(ts.p.multiselect && scb){
  2433. $(ts).jqGrid("setSelection", ri ,true,e);
  2434. } else {
  2435. ri = ptr[0].rowIndex;
  2436. try {$(ts).jqGrid("editCell",ri,ci,true);} catch (_) {}
  2437. }
  2438. } else if ( !ts.p.multikey ) {
  2439. if(ts.p.multiselect && ts.p.multiboxonly) {
  2440. if(scb){$(ts).jqGrid("setSelection",ri,true,e);}
  2441. else {
  2442. var frz = ts.p.frozenColumns ? ts.p.id+"_frozen" : "";
  2443. $(ts.p.selarrrow).each(function(i,n){
  2444. var ind = ts.rows.namedItem(n);
  2445. $(ind).removeClass("ui-state-highlight");
  2446. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(n))[ts.p.useProp ? 'prop': 'attr']("checked", false);
  2447. if(frz) {
  2448. $("#"+$.jgrid.jqID(n), "#"+$.jgrid.jqID(frz)).removeClass("ui-state-highlight");
  2449. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(n), "#"+$.jgrid.jqID(frz))[ts.p.useProp ? 'prop': 'attr']("checked", false);
  2450. }
  2451. });
  2452. ts.p.selarrrow = [];
  2453. $(ts).jqGrid("setSelection",ri,true,e);
  2454. }
  2455. } else {
  2456. $(ts).jqGrid("setSelection",ri,true,e);
  2457. }
  2458. } else {
  2459. if(e[ts.p.multikey]) {
  2460. $(ts).jqGrid("setSelection",ri,true,e);
  2461. } else if(ts.p.multiselect && scb) {
  2462. scb = $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+ri).is(":checked");
  2463. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+ri)[ts.p.useProp ? 'prop' : 'attr']("checked", scb);
  2464. }
  2465. }
  2466. }
  2467. }).bind('reloadGrid', function(e,opts) {
  2468. if(ts.p.treeGrid ===true) { ts.p.datatype = ts.p.treedatatype;}
  2469. if (opts && opts.current) {
  2470. ts.grid.selectionPreserver(ts);
  2471. }
  2472. if(ts.p.datatype=="local"){ $(ts).jqGrid("resetSelection"); if(ts.p.data.length) { refreshIndex();} }
  2473. else if(!ts.p.treeGrid) {
  2474. ts.p.selrow=null;
  2475. if(ts.p.multiselect) {ts.p.selarrrow =[];setHeadCheckBox(false);}
  2476. ts.p.savedRow = [];
  2477. }
  2478. if(ts.p.scroll) {emptyRows.call(ts, true, false);}
  2479. if (opts && opts.page) {
  2480. var page = opts.page;
  2481. if (page > ts.p.lastpage) { page = ts.p.lastpage; }
  2482. if (page < 1) { page = 1; }
  2483. ts.p.page = page;
  2484. if (ts.grid.prevRowHeight) {
  2485. ts.grid.bDiv.scrollTop = (page - 1) * ts.grid.prevRowHeight * ts.p.rowNum;
  2486. } else {
  2487. ts.grid.bDiv.scrollTop = 0;
  2488. }
  2489. }
  2490. if (ts.grid.prevRowHeight && ts.p.scroll) {
  2491. delete ts.p.lastpage;
  2492. ts.grid.populateVisible();
  2493. } else {
  2494. ts.grid.populate();
  2495. }
  2496. if(ts.p._inlinenav===true) {$(ts).jqGrid('showAddEditButtons');}
  2497. return false;
  2498. })
  2499. .dblclick(function(e) {
  2500. td = e.target;
  2501. ptr = $(td,ts.rows).closest("tr.jqgrow");
  2502. if($(ptr).length === 0 ){return;}
  2503. ri = ptr[0].rowIndex;
  2504. ci = $.jgrid.getCellIndex(td);
  2505. $(ts).triggerHandler("jqGridDblClickRow", [$(ptr).attr("id"),ri,ci,e]);
  2506. if ($.isFunction(this.p.ondblClickRow)) { ts.p.ondblClickRow.call(ts,$(ptr).attr("id"),ri,ci, e); }
  2507. })
  2508. .bind('contextmenu', function(e) {
  2509. td = e.target;
  2510. ptr = $(td,ts.rows).closest("tr.jqgrow");
  2511. if($(ptr).length === 0 ){return;}
  2512. if(!ts.p.multiselect) { $(ts).jqGrid("setSelection",ptr[0].id,true,e); }
  2513. ri = ptr[0].rowIndex;
  2514. ci = $.jgrid.getCellIndex(td);
  2515. $(ts).triggerHandler("jqGridRightClickRow", [$(ptr).attr("id"),ri,ci,e]);
  2516. if ($.isFunction(this.p.onRightClickRow)) { ts.p.onRightClickRow.call(ts,$(ptr).attr("id"),ri,ci, e); }
  2517. });
  2518. grid.bDiv = document.createElement("div");
  2519. if(isMSIE) { if(String(ts.p.height).toLowerCase() === "auto") { ts.p.height = "100%"; } }
  2520. $(grid.bDiv)
  2521. .append($('<div style="position:relative;'+(isMSIE && $.browser.version < 8 ? "height:0.01%;" : "")+'"></div>').append('<div></div>').append(this))
  2522. .addClass("ui-jqgrid-bdiv")
  2523. .css({ height: ts.p.height+(isNaN(ts.p.height)?"":"px"), width: (grid.width)+"px"})
  2524. .scroll(grid.scrollGrid);
  2525. $("table:first",grid.bDiv).css({width:ts.p.tblwidth+"px"});
  2526. if( isMSIE ) {
  2527. if( $("tbody",this).length == 2 ) { $("tbody:gt(0)",this).remove();}
  2528. if( ts.p.multikey) {$(grid.bDiv).bind("selectstart",function(){return false;});}
  2529. } else {
  2530. if( ts.p.multikey) {$(grid.bDiv).bind("mousedown",function(){return false;});}
  2531. }
  2532. if(hg) {$(grid.bDiv).hide();}
  2533. grid.cDiv = document.createElement("div");
  2534. var arf = ts.p.hidegrid===true ? $("<a role='link' href='javascript:void(0)'/>").addClass('ui-jqgrid-titlebar-close HeaderButton').hover(
  2535. function(){ arf.addClass('ui-state-hover');},
  2536. function() {arf.removeClass('ui-state-hover');})
  2537. .append("<span class='ui-icon ui-icon-circle-triangle-n'></span>").css((dir=="rtl"?"left":"right"),"0px") : "";
  2538. $(grid.cDiv).append(arf).append("<span class='ui-jqgrid-title"+(dir=="rtl" ? "-rtl" :"" )+"'>"+ts.p.caption+"</span>")
  2539. .addClass("ui-jqgrid-titlebar ui-widget-header ui-corner-top ui-helper-clearfix");
  2540. $(grid.cDiv).insertBefore(grid.hDiv);
  2541. if( ts.p.toolbar[0] ) {
  2542. grid.uDiv = document.createElement("div");
  2543. if(ts.p.toolbar[1] == "top") {$(grid.uDiv).insertBefore(grid.hDiv);}
  2544. else if (ts.p.toolbar[1]=="bottom" ) {$(grid.uDiv).insertAfter(grid.hDiv);}
  2545. if(ts.p.toolbar[1]=="both") {
  2546. grid.ubDiv = document.createElement("div");
  2547. $(grid.uDiv).insertBefore(grid.hDiv).addClass("ui-userdata ui-state-default").attr("id","t_"+this.id);
  2548. $(grid.ubDiv).insertAfter(grid.hDiv).addClass("ui-userdata ui-state-default").attr("id","tb_"+this.id);
  2549. if(hg) {$(grid.ubDiv).hide();}
  2550. } else {
  2551. $(grid.uDiv).width(grid.width).addClass("ui-userdata ui-state-default").attr("id","t_"+this.id);
  2552. }
  2553. if(hg) {$(grid.uDiv).hide();}
  2554. }
  2555. if(ts.p.toppager) {
  2556. ts.p.toppager = $.jgrid.jqID(ts.p.id)+"_toppager";
  2557. grid.topDiv = $("<div id='"+ts.p.toppager+"'></div>")[0];
  2558. ts.p.toppager = "#"+ts.p.toppager;
  2559. $(grid.topDiv).insertBefore(grid.hDiv).addClass('ui-state-default ui-jqgrid-toppager').width(grid.width);
  2560. setPager(ts.p.toppager,'_t');
  2561. }
  2562. if(ts.p.footerrow) {
  2563. grid.sDiv = $("<div class='ui-jqgrid-sdiv'></div>")[0];
  2564. hb = $("<div class='ui-jqgrid-hbox"+(dir=="rtl"?"-rtl":"")+"'></div>");
  2565. $(grid.sDiv).append(hb).insertAfter(grid.hDiv).width(grid.width);
  2566. $(hb).append(tfoot);
  2567. grid.footers = $(".ui-jqgrid-ftable",grid.sDiv)[0].rows[0].cells;
  2568. if(ts.p.rownumbers) { grid.footers[0].className = 'ui-state-default jqgrid-rownum'; }
  2569. if(hg) {$(grid.sDiv).hide();}
  2570. }
  2571. hb = null;
  2572. if(ts.p.caption) {
  2573. var tdt = ts.p.datatype;
  2574. if(ts.p.hidegrid===true) {
  2575. $(".ui-jqgrid-titlebar-close",grid.cDiv).click( function(e){
  2576. var onHdCl = $.isFunction(ts.p.onHeaderClick),
  2577. elems = ".ui-jqgrid-bdiv, .ui-jqgrid-hdiv, .ui-jqgrid-pager, .ui-jqgrid-sdiv",
  2578. counter, self = this;
  2579. if(ts.p.toolbar[0]===true) {
  2580. if( ts.p.toolbar[1]=='both') {
  2581. elems += ', #' + $(grid.ubDiv).attr('id');
  2582. }
  2583. elems += ', #' + $(grid.uDiv).attr('id');
  2584. }
  2585. counter = $(elems,"#gview_"+$.jgrid.jqID(ts.p.id)).length;
  2586. if(ts.p.gridstate == 'visible') {
  2587. $(elems,"#gbox_"+$.jgrid.jqID(ts.p.id)).slideUp("fast", function() {
  2588. counter--;
  2589. if (counter === 0) {
  2590. $("span",self).removeClass("ui-icon-circle-triangle-n").addClass("ui-icon-circle-triangle-s");
  2591. ts.p.gridstate = 'hidden';
  2592. if($("#gbox_"+$.jgrid.jqID(ts.p.id)).hasClass("ui-resizable")) { $(".ui-resizable-handle","#gbox_"+$.jgrid.jqID(ts.p.id)).hide(); }
  2593. $(ts).triggerHandler("jqGridHeaderClick", [ts.p.gridstate,e]);
  2594. if(onHdCl) {if(!hg) {ts.p.onHeaderClick.call(ts,ts.p.gridstate,e);}}
  2595. }
  2596. });
  2597. } else if(ts.p.gridstate == 'hidden'){
  2598. $(elems,"#gbox_"+$.jgrid.jqID(ts.p.id)).slideDown("fast", function() {
  2599. counter--;
  2600. if (counter === 0) {
  2601. $("span",self).removeClass("ui-icon-circle-triangle-s").addClass("ui-icon-circle-triangle-n");
  2602. if(hg) {ts.p.datatype = tdt;populate();hg=false;}
  2603. ts.p.gridstate = 'visible';
  2604. if($("#gbox_"+$.jgrid.jqID(ts.p.id)).hasClass("ui-resizable")) { $(".ui-resizable-handle","#gbox_"+$.jgrid.jqID(ts.p.id)).show(); }
  2605. $(ts).triggerHandler("jqGridHeaderClick", [ts.p.gridstate,e]);
  2606. if(onHdCl) {if(!hg) {ts.p.onHeaderClick.call(ts,ts.p.gridstate,e);}}
  2607. }
  2608. });
  2609. }
  2610. return false;
  2611. });
  2612. if(hg) {ts.p.datatype="local"; $(".ui-jqgrid-titlebar-close",grid.cDiv).trigger("click");}
  2613. }
  2614. } else {$(grid.cDiv).hide();}
  2615. $(grid.hDiv).after(grid.bDiv)
  2616. .mousemove(function (e) {
  2617. if(grid.resizing){grid.dragMove(e);return false;}
  2618. });
  2619. $(".ui-jqgrid-labels",grid.hDiv).bind("selectstart", function () { return false; });
  2620. $(document).mouseup(function () {
  2621. if(grid.resizing) { grid.dragEnd(); return false;}
  2622. return true;
  2623. });
  2624. ts.formatCol = formatCol;
  2625. ts.sortData = sortData;
  2626. ts.updatepager = updatepager;
  2627. ts.refreshIndex = refreshIndex;
  2628. ts.setHeadCheckBox = setHeadCheckBox;
  2629. ts.constructTr = constructTr;
  2630. ts.formatter = function ( rowId, cellval , colpos, rwdat, act){return formatter(rowId, cellval , colpos, rwdat, act);};
  2631. $.extend(grid,{populate : populate, emptyRows: emptyRows});
  2632. this.grid = grid;
  2633. ts.addXmlData = function(d) {addXmlData(d,ts.grid.bDiv);};
  2634. ts.addJSONData = function(d) {addJSONData(d,ts.grid.bDiv);};
  2635. this.grid.cols = this.rows[0].cells;
  2636. populate();ts.p.hiddengrid=false;
  2637. });
  2638. };
  2639. $.jgrid.extend({
  2640. getGridParam : function(pName) {
  2641. var $t = this[0];
  2642. if (!$t || !$t.grid) {return;}
  2643. if (!pName) { return $t.p; }
  2644. return $t.p[pName] !== undefined ? $t.p[pName] : null;
  2645. },
  2646. setGridParam : function (newParams){
  2647. return this.each(function(){
  2648. if (this.grid && typeof newParams === 'object') {$.extend(true,this.p,newParams);}
  2649. });
  2650. },
  2651. getDataIDs : function () {
  2652. var ids=[], i=0, len, j=0;
  2653. this.each(function(){
  2654. len = this.rows.length;
  2655. if(len && len>0){
  2656. while(i<len) {
  2657. if($(this.rows[i]).hasClass('jqgrow')) {
  2658. ids[j] = this.rows[i].id;
  2659. j++;
  2660. }
  2661. i++;
  2662. }
  2663. }
  2664. });
  2665. return ids;
  2666. },
  2667. setSelection : function(selection,onsr, e) {
  2668. return this.each(function(){
  2669. var $t = this, stat,pt, ner, ia, tpsr, fid;
  2670. if(selection === undefined) { return; }
  2671. onsr = onsr === false ? false : true;
  2672. pt=$t.rows.namedItem(String(selection));
  2673. if(!pt || !pt.className || pt.className.indexOf( 'ui-state-disabled' ) > -1 ) { return; }
  2674. function scrGrid(iR){
  2675. var ch = $($t.grid.bDiv)[0].clientHeight,
  2676. st = $($t.grid.bDiv)[0].scrollTop,
  2677. rpos = $($t.rows[iR]).position().top,
  2678. rh = $t.rows[iR].clientHeight;
  2679. if(rpos+rh >= ch+st) { $($t.grid.bDiv)[0].scrollTop = rpos-(ch+st)+rh+st; }
  2680. else if(rpos < ch+st) {
  2681. if(rpos < st) {
  2682. $($t.grid.bDiv)[0].scrollTop = rpos;
  2683. }
  2684. }
  2685. }
  2686. if($t.p.scrollrows===true) {
  2687. ner = $t.rows.namedItem(selection).rowIndex;
  2688. if(ner >=0 ){
  2689. scrGrid(ner);
  2690. }
  2691. }
  2692. if($t.p.frozenColumns === true ) {
  2693. fid = $t.p.id+"_frozen";
  2694. }
  2695. if(!$t.p.multiselect) {
  2696. if(pt.className !== "ui-subgrid") {
  2697. if( $t.p.selrow != pt.id) {
  2698. $($t.rows.namedItem($t.p.selrow)).removeClass("ui-state-highlight").attr({"aria-selected":"false", "tabindex" : "-1"});
  2699. $(pt).addClass("ui-state-highlight").attr({"aria-selected":"true", "tabindex" : "0"});//.focus();
  2700. if(fid) {
  2701. $("#"+$.jgrid.jqID($t.p.selrow), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight");
  2702. $("#"+$.jgrid.jqID(selection), "#"+$.jgrid.jqID(fid)).addClass("ui-state-highlight");
  2703. }
  2704. stat = true;
  2705. } else {
  2706. stat = false;
  2707. }
  2708. $t.p.selrow = pt.id;
  2709. $($t).triggerHandler("jqGridSelectRow", [pt.id, stat, e]);
  2710. if( $t.p.onSelectRow && onsr) { $t.p.onSelectRow.call($t, pt.id, stat, e); }
  2711. }
  2712. } else {
  2713. //unselect selectall checkbox when deselecting a specific row
  2714. $t.setHeadCheckBox( false );
  2715. $t.p.selrow = pt.id;
  2716. ia = $.inArray($t.p.selrow,$t.p.selarrrow);
  2717. if ( ia === -1 ){
  2718. if(pt.className !== "ui-subgrid") { $(pt).addClass("ui-state-highlight").attr("aria-selected","true");}
  2719. stat = true;
  2720. $t.p.selarrrow.push($t.p.selrow);
  2721. } else {
  2722. if(pt.className !== "ui-subgrid") { $(pt).removeClass("ui-state-highlight").attr("aria-selected","false");}
  2723. stat = false;
  2724. $t.p.selarrrow.splice(ia,1);
  2725. tpsr = $t.p.selarrrow[0];
  2726. $t.p.selrow = (tpsr === undefined) ? null : tpsr;
  2727. }
  2728. $("#jqg_"+$.jgrid.jqID($t.p.id)+"_"+$.jgrid.jqID(pt.id))[$t.p.useProp ? 'prop': 'attr']("checked",stat);
  2729. if(fid) {
  2730. if(ia === -1) {
  2731. $("#"+$.jgrid.jqID(selection), "#"+$.jgrid.jqID(fid)).addClass("ui-state-highlight");
  2732. } else {
  2733. $("#"+$.jgrid.jqID(selection), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight");
  2734. }
  2735. $("#jqg_"+$.jgrid.jqID($t.p.id)+"_"+$.jgrid.jqID(selection), "#"+$.jgrid.jqID(fid))[$t.p.useProp ? 'prop': 'attr']("checked",stat);
  2736. }
  2737. $($t).triggerHandler("jqGridSelectRow", [pt.id, stat, e]);
  2738. if( $t.p.onSelectRow && onsr) { $t.p.onSelectRow.call($t, pt.id , stat, e); }
  2739. }
  2740. });
  2741. },
  2742. resetSelection : function( rowid ){
  2743. return this.each(function(){
  2744. var t = this, ind, sr, fid;
  2745. if( t.p.frozenColumns === true ) {
  2746. fid = t.p.id+"_frozen";
  2747. }
  2748. if(rowid !== undefined ) {
  2749. sr = rowid === t.p.selrow ? t.p.selrow : rowid;
  2750. $("#"+$.jgrid.jqID(t.p.id)+" tbody:first tr#"+$.jgrid.jqID(sr)).removeClass("ui-state-highlight").attr("aria-selected","false");
  2751. if (fid) { $("#"+$.jgrid.jqID(sr), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight"); }
  2752. if(t.p.multiselect) {
  2753. $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(sr), "#"+$.jgrid.jqID(t.p.id))[t.p.useProp ? 'prop': 'attr']("checked",false);
  2754. if(fid) { $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(sr), "#"+$.jgrid.jqID(fid))[t.p.useProp ? 'prop': 'attr']("checked",false); }
  2755. t.setHeadCheckBox( false);
  2756. }
  2757. sr = null;
  2758. } else if(!t.p.multiselect) {
  2759. if(t.p.selrow) {
  2760. $("#"+$.jgrid.jqID(t.p.id)+" tbody:first tr#"+$.jgrid.jqID(t.p.selrow)).removeClass("ui-state-highlight").attr("aria-selected","false");
  2761. if(fid) { $("#"+$.jgrid.jqID(t.p.selrow), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight"); }
  2762. t.p.selrow = null;
  2763. }
  2764. } else {
  2765. $(t.p.selarrrow).each(function(i,n){
  2766. ind = t.rows.namedItem(n);
  2767. $(ind).removeClass("ui-state-highlight").attr("aria-selected","false");
  2768. $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(n))[t.p.useProp ? 'prop': 'attr']("checked",false);
  2769. if(fid) {
  2770. $("#"+$.jgrid.jqID(n), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight");
  2771. $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(n), "#"+$.jgrid.jqID(fid))[t.p.useProp ? 'prop': 'attr']("checked",false);
  2772. }
  2773. });
  2774. t.setHeadCheckBox( false );
  2775. t.p.selarrrow = [];
  2776. }
  2777. if(t.p.cellEdit === true) {
  2778. if(parseInt(t.p.iCol,10)>=0 && parseInt(t.p.iRow,10)>=0) {
  2779. $("td:eq("+t.p.iCol+")",t.rows[t.p.iRow]).removeClass("edit-cell ui-state-highlight");
  2780. $(t.rows[t.p.iRow]).removeClass("selected-row ui-state-hover");
  2781. }
  2782. }
  2783. t.p.savedRow = [];
  2784. });
  2785. },
  2786. getRowData : function( rowid ) {
  2787. var res = {}, resall, getall=false, len, j=0;
  2788. this.each(function(){
  2789. var $t = this,nm,ind;
  2790. if(rowid === undefined) {
  2791. getall = true;
  2792. resall = [];
  2793. len = $t.rows.length;
  2794. } else {
  2795. ind = $t.rows.namedItem(rowid);
  2796. if(!ind) { return res; }
  2797. len = 2;
  2798. }
  2799. while(j<len){
  2800. if(getall) { ind = $t.rows[j]; }
  2801. if( $(ind).hasClass('jqgrow') ) {
  2802. $('td[role="gridcell"]',ind).each( function(i) {
  2803. nm = $t.p.colModel[i].name;
  2804. if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn') {
  2805. if($t.p.treeGrid===true && nm == $t.p.ExpandColumn) {
  2806. res[nm] = $.jgrid.htmlDecode($("span:first",this).html());
  2807. } else {
  2808. try {
  2809. res[nm] = $.unformat.call($t,this,{rowId:ind.id, colModel:$t.p.colModel[i]},i);
  2810. } catch (e){
  2811. res[nm] = $.jgrid.htmlDecode($(this).html());
  2812. }
  2813. }
  2814. }
  2815. });
  2816. if(getall) { resall.push(res); res={}; }
  2817. }
  2818. j++;
  2819. }
  2820. });
  2821. return resall || res;
  2822. },
  2823. delRowData : function(rowid) {
  2824. var success = false, rowInd, ia, ri;
  2825. this.each(function() {
  2826. var $t = this;
  2827. rowInd = $t.rows.namedItem(rowid);
  2828. if(!rowInd) {return false;}
  2829. ri = rowInd.rowIndex;
  2830. $(rowInd).remove();
  2831. $t.p.records--;
  2832. $t.p.reccount--;
  2833. $t.updatepager(true,false);
  2834. success=true;
  2835. if($t.p.multiselect) {
  2836. ia = $.inArray(rowid,$t.p.selarrrow);
  2837. if(ia != -1) { $t.p.selarrrow.splice(ia,1);}
  2838. }
  2839. if ($t.p.multiselect && $t.p.selarrrow.length > 0) {
  2840. $t.p.selrow = $t.p.selarrrow[$t.p.selarrrow.length-1];
  2841. } else {
  2842. $t.p.selrow = null;
  2843. }
  2844. if($t.p.datatype == 'local') {
  2845. var id = $.jgrid.stripPref($t.p.idPrefix, rowid),
  2846. pos = $t.p._index[id];
  2847. if(pos !== undefined) {
  2848. $t.p.data.splice(pos,1);
  2849. $t.refreshIndex();
  2850. }
  2851. }
  2852. if( $t.p.altRows === true && success ) {
  2853. var cn = $t.p.altclass;
  2854. $($t.rows).each(function(i){
  2855. if(i % 2 ==1) { $(this).addClass(cn); }
  2856. else { $(this).removeClass(cn); }
  2857. });
  2858. }
  2859. });
  2860. return success;
  2861. },
  2862. setRowData : function(rowid, data, cssp) {
  2863. var nm, success=true, title;
  2864. this.each(function(){
  2865. if(!this.grid) {return false;}
  2866. var t = this, vl, ind, cp = typeof cssp, lcdata={};
  2867. ind = t.rows.namedItem(rowid);
  2868. if(!ind) { return false; }
  2869. if( data ) {
  2870. try {
  2871. $(this.p.colModel).each(function(i){
  2872. nm = this.name;
  2873. if( data[nm] !== undefined) {
  2874. lcdata[nm] = this.formatter && typeof this.formatter === 'string' && this.formatter == 'date' ? $.unformat.date.call(t,data[nm],this) : data[nm];
  2875. vl = t.formatter( rowid, data[nm], i, data, 'edit');
  2876. title = this.title ? {"title":$.jgrid.stripHtml(vl)} : {};
  2877. if(t.p.treeGrid===true && nm == t.p.ExpandColumn) {
  2878. $("td[role='gridcell']:eq("+i+") > span:first",ind).html(vl).attr(title);
  2879. } else {
  2880. $("td[role='gridcell']:eq("+i+")",ind).html(vl).attr(title);
  2881. }
  2882. }
  2883. });
  2884. if(t.p.datatype == 'local') {
  2885. var id = $.jgrid.stripPref(t.p.idPrefix, rowid),
  2886. pos = t.p._index[id], key;
  2887. if(t.p.treeGrid) {
  2888. for(key in t.p.treeReader){
  2889. if(t.p.treeReader.hasOwnProperty(key)) {
  2890. delete lcdata[t.p.treeReader[key]];
  2891. }
  2892. }
  2893. }
  2894. if(pos !== undefined) {
  2895. t.p.data[pos] = $.extend(true, t.p.data[pos], lcdata);
  2896. }
  2897. lcdata = null;
  2898. }
  2899. } catch (e) {
  2900. success = false;
  2901. }
  2902. }
  2903. if(success) {
  2904. if(cp === 'string') {$(ind).addClass(cssp);} else if(cp === 'object') {$(ind).css(cssp);}
  2905. $(t).triggerHandler("jqGridAfterGridComplete");
  2906. }
  2907. });
  2908. return success;
  2909. },
  2910. addRowData : function(rowid,rdata,pos,src) {
  2911. if(!pos) {pos = "last";}
  2912. var success = false, nm, row, gi, si, ni,sind, i, v, prp="", aradd, cnm, cn, data, cm, id;
  2913. if(rdata) {
  2914. if($.isArray(rdata)) {
  2915. aradd=true;
  2916. pos = "last";
  2917. cnm = rowid;
  2918. } else {
  2919. rdata = [rdata];
  2920. aradd = false;
  2921. }
  2922. this.each(function() {
  2923. var t = this, datalen = rdata.length;
  2924. ni = t.p.rownumbers===true ? 1 :0;
  2925. gi = t.p.multiselect ===true ? 1 :0;
  2926. si = t.p.subGrid===true ? 1 :0;
  2927. if(!aradd) {
  2928. if(rowid !== undefined) { rowid = String(rowid);}
  2929. else {
  2930. rowid = $.jgrid.randId();
  2931. if(t.p.keyIndex !== false) {
  2932. cnm = t.p.colModel[t.p.keyIndex+gi+si+ni].name;
  2933. if(rdata[0][cnm] !== undefined) { rowid = rdata[0][cnm]; }
  2934. }
  2935. }
  2936. }
  2937. cn = t.p.altclass;
  2938. var k = 0, cna ="", lcdata = {},
  2939. air = $.isFunction(t.p.afterInsertRow) ? true : false;
  2940. while(k < datalen) {
  2941. data = rdata[k];
  2942. row=[];
  2943. if(aradd) {
  2944. try {
  2945. rowid = data[cnm];
  2946. if(rowid===undefined) {
  2947. rowid = $.jgrid.randId();
  2948. }
  2949. }
  2950. catch (e) {rowid = $.jgrid.randId();}
  2951. cna = t.p.altRows === true ? (t.rows.length-1)%2 === 0 ? cn : "" : "";
  2952. }
  2953. id = rowid;
  2954. rowid = t.p.idPrefix + rowid;
  2955. if(ni){
  2956. prp = t.formatCol(0,1,'',null,rowid, true);
  2957. row[row.length] = "<td role=\"gridcell\" class=\"ui-state-default jqgrid-rownum\" "+prp+">0</td>";
  2958. }
  2959. if(gi) {
  2960. v = "<input role=\"checkbox\" type=\"checkbox\""+" id=\"jqg_"+t.p.id+"_"+rowid+"\" class=\"cbox\"/>";
  2961. prp = t.formatCol(ni,1,'', null, rowid, true);
  2962. row[row.length] = "<td role=\"gridcell\" "+prp+">"+v+"</td>";
  2963. }
  2964. if(si) {
  2965. row[row.length] = $(t).jqGrid("addSubGridCell",gi+ni,1);
  2966. }
  2967. for(i = gi+si+ni; i < t.p.colModel.length;i++){
  2968. cm = t.p.colModel[i];
  2969. nm = cm.name;
  2970. lcdata[nm] = data[nm];
  2971. v = t.formatter( rowid, $.jgrid.getAccessor(data,nm), i, data );
  2972. prp = t.formatCol(i,1,v, data, rowid, lcdata);
  2973. row[row.length] = "<td role=\"gridcell\" "+prp+">"+v+"</td>";
  2974. }
  2975. row.unshift( t.constructTr(rowid, false, cna, lcdata, data, false ) );
  2976. row[row.length] = "</tr>";
  2977. if(t.rows.length === 0){
  2978. $("table:first",t.grid.bDiv).append(row.join(''));
  2979. } else {
  2980. switch (pos) {
  2981. case 'last':
  2982. $(t.rows[t.rows.length-1]).after(row.join(''));
  2983. sind = t.rows.length-1;
  2984. break;
  2985. case 'first':
  2986. $(t.rows[0]).after(row.join(''));
  2987. sind = 1;
  2988. break;
  2989. case 'after':
  2990. sind = t.rows.namedItem(src);
  2991. if (sind) {
  2992. if($(t.rows[sind.rowIndex+1]).hasClass("ui-subgrid")) { $(t.rows[sind.rowIndex+1]).after(row); }
  2993. else { $(sind).after(row.join('')); }
  2994. }
  2995. sind++;
  2996. break;
  2997. case 'before':
  2998. sind = t.rows.namedItem(src);
  2999. if(sind) {$(sind).before(row.join(''));sind=sind.rowIndex;}
  3000. sind--;
  3001. break;
  3002. }
  3003. }
  3004. if(t.p.subGrid===true) {
  3005. $(t).jqGrid("addSubGrid",gi+ni, sind);
  3006. }
  3007. t.p.records++;
  3008. t.p.reccount++;
  3009. $(t).triggerHandler("jqGridAfterInsertRow", [rowid,data,data]);
  3010. if(air) { t.p.afterInsertRow.call(t,rowid,data,data); }
  3011. k++;
  3012. if(t.p.datatype == 'local') {
  3013. lcdata[t.p.localReader.id] = id;
  3014. t.p._index[id] = t.p.data.length;
  3015. t.p.data.push(lcdata);
  3016. lcdata = {};
  3017. }
  3018. }
  3019. if( t.p.altRows === true && !aradd) {
  3020. if (pos == "last") {
  3021. if ((t.rows.length-1)%2 == 1) {$(t.rows[t.rows.length-1]).addClass(cn);}
  3022. } else {
  3023. $(t.rows).each(function(i){
  3024. if(i % 2 ==1) { $(this).addClass(cn); }
  3025. else { $(this).removeClass(cn); }
  3026. });
  3027. }
  3028. }
  3029. t.updatepager(true,true);
  3030. success = true;
  3031. });
  3032. }
  3033. return success;
  3034. },
  3035. footerData : function(action,data, format) {
  3036. var nm, success=false, res={}, title;
  3037. function isEmpty(obj) {
  3038. var i;
  3039. for(i in obj) {
  3040. if (obj.hasOwnProperty(i)) { return false; }
  3041. }
  3042. return true;
  3043. }
  3044. if(action === undefined) { action = "get"; }
  3045. if(typeof format !== "boolean") { format = true; }
  3046. action = action.toLowerCase();
  3047. this.each(function(){
  3048. var t = this, vl;
  3049. if(!t.grid || !t.p.footerrow) {return false;}
  3050. if(action == "set") { if(isEmpty(data)) { return false; } }
  3051. success=true;
  3052. $(this.p.colModel).each(function(i){
  3053. nm = this.name;
  3054. if(action == "set") {
  3055. if( data[nm] !== undefined) {
  3056. vl = format ? t.formatter( "", data[nm], i, data, 'edit') : data[nm];
  3057. title = this.title ? {"title":$.jgrid.stripHtml(vl)} : {};
  3058. $("tr.footrow td:eq("+i+")",t.grid.sDiv).html(vl).attr(title);
  3059. success = true;
  3060. }
  3061. } else if(action == "get") {
  3062. res[nm] = $("tr.footrow td:eq("+i+")",t.grid.sDiv).html();
  3063. }
  3064. });
  3065. });
  3066. return action == "get" ? res : success;
  3067. },
  3068. showHideCol : function(colname,show) {
  3069. return this.each(function() {
  3070. var $t = this, fndh=false, brd=$.jgrid.cell_width ? 0: $t.p.cellLayout, cw;
  3071. if (!$t.grid ) {return;}
  3072. if( typeof colname === 'string') {colname=[colname];}
  3073. show = show != "none" ? "" : "none";
  3074. var sw = show === "" ? true :false,
  3075. gh = $t.p.groupHeader && (typeof $t.p.groupHeader === 'object' || $.isFunction($t.p.groupHeader) );
  3076. if(gh) { $($t).jqGrid('destroyGroupHeader', false); }
  3077. $(this.p.colModel).each(function(i) {
  3078. if ($.inArray(this.name,colname) !== -1 && this.hidden === sw) {
  3079. if($t.p.frozenColumns === true && this.frozen === true) {
  3080. return true;
  3081. }
  3082. $("tr",$t.grid.hDiv).each(function(){
  3083. $(this.cells[i]).css("display", show);
  3084. });
  3085. $($t.rows).each(function(){
  3086. if (!$(this).hasClass("jqgroup")) {
  3087. $(this.cells[i]).css("display", show);
  3088. }
  3089. });
  3090. if($t.p.footerrow) { $("tr.footrow td:eq("+i+")", $t.grid.sDiv).css("display", show); }
  3091. cw = parseInt(this.width,10);
  3092. if(show === "none") {
  3093. $t.p.tblwidth -= cw+brd;
  3094. } else {
  3095. $t.p.tblwidth += cw+brd;
  3096. }
  3097. this.hidden = !sw;
  3098. fndh=true;
  3099. $($t).triggerHandler("jqGridShowHideCol", [sw,this.name,i]);
  3100. }
  3101. });
  3102. if(fndh===true) {
  3103. if($t.p.shrinkToFit === true && !isNaN($t.p.height)) { $t.p.tblwidth += parseInt($t.p.scrollOffset,10);}
  3104. $($t).jqGrid("setGridWidth",$t.p.shrinkToFit === true ? $t.p.tblwidth : $t.p.width );
  3105. }
  3106. if( gh ) {
  3107. $($t).jqGrid('setGroupHeaders',$t.p.groupHeader);
  3108. }
  3109. });
  3110. },
  3111. hideCol : function (colname) {
  3112. return this.each(function(){$(this).jqGrid("showHideCol",colname,"none");});
  3113. },
  3114. showCol : function(colname) {
  3115. return this.each(function(){$(this).jqGrid("showHideCol",colname,"");});
  3116. },
  3117. remapColumns : function(permutation, updateCells, keepHeader)
  3118. {
  3119. function resortArray(a) {
  3120. var ac;
  3121. if (a.length) {
  3122. ac = $.makeArray(a);
  3123. } else {
  3124. ac = $.extend({}, a);
  3125. }
  3126. $.each(permutation, function(i) {
  3127. a[i] = ac[this];
  3128. });
  3129. }
  3130. var ts = this.get(0);
  3131. function resortRows(parent, clobj) {
  3132. $(">tr"+(clobj||""), parent).each(function() {
  3133. var row = this;
  3134. var elems = $.makeArray(row.cells);
  3135. $.each(permutation, function() {
  3136. var e = elems[this];
  3137. if (e) {
  3138. row.appendChild(e);
  3139. }
  3140. });
  3141. });
  3142. }
  3143. resortArray(ts.p.colModel);
  3144. resortArray(ts.p.colNames);
  3145. resortArray(ts.grid.headers);
  3146. resortRows($("thead:first", ts.grid.hDiv), keepHeader && ":not(.ui-jqgrid-labels)");
  3147. if (updateCells) {
  3148. resortRows($("#"+$.jgrid.jqID(ts.p.id)+" tbody:first"), ".jqgfirstrow, tr.jqgrow, tr.jqfoot");
  3149. }
  3150. if (ts.p.footerrow) {
  3151. resortRows($("tbody:first", ts.grid.sDiv));
  3152. }
  3153. if (ts.p.remapColumns) {
  3154. if (!ts.p.remapColumns.length){
  3155. ts.p.remapColumns = $.makeArray(permutation);
  3156. } else {
  3157. resortArray(ts.p.remapColumns);
  3158. }
  3159. }
  3160. ts.p.lastsort = $.inArray(ts.p.lastsort, permutation);
  3161. if(ts.p.treeGrid) { ts.p.expColInd = $.inArray(ts.p.expColInd, permutation); }
  3162. $(ts).triggerHandler("jqGridRemapColumns", [permutation, updateCells, keepHeader]);
  3163. },
  3164. setGridWidth : function(nwidth, shrink) {
  3165. return this.each(function(){
  3166. if (!this.grid ) {return;}
  3167. var $t = this, cw,
  3168. initwidth = 0, brd=$.jgrid.cell_width ? 0: $t.p.cellLayout, lvc, vc=0, hs=false, scw=$t.p.scrollOffset, aw, gw=0,
  3169. cl = 0,cr;
  3170. if(typeof shrink !== 'boolean') {
  3171. shrink=$t.p.shrinkToFit;
  3172. }
  3173. if(isNaN(nwidth)) {return;}
  3174. nwidth = parseInt(nwidth,10);
  3175. $t.grid.width = $t.p.width = nwidth;
  3176. $("#gbox_"+$.jgrid.jqID($t.p.id)).css("width",nwidth+"px");
  3177. $("#gview_"+$.jgrid.jqID($t.p.id)).css("width",nwidth+"px");
  3178. $($t.grid.bDiv).css("width",nwidth+"px");
  3179. $($t.grid.hDiv).css("width",nwidth+"px");
  3180. if($t.p.pager ) {$($t.p.pager).css("width",nwidth+"px");}
  3181. if($t.p.toppager ) {$($t.p.toppager).css("width",nwidth+"px");}
  3182. if($t.p.toolbar[0] === true){
  3183. $($t.grid.uDiv).css("width",nwidth+"px");
  3184. if($t.p.toolbar[1]=="both") {$($t.grid.ubDiv).css("width",nwidth+"px");}
  3185. }
  3186. if($t.p.footerrow) { $($t.grid.sDiv).css("width",nwidth+"px"); }
  3187. if(shrink ===false && $t.p.forceFit === true) {$t.p.forceFit=false;}
  3188. if(shrink===true) {
  3189. $.each($t.p.colModel, function() {
  3190. if(this.hidden===false){
  3191. cw = this.widthOrg;
  3192. initwidth += cw+brd;
  3193. if(this.fixed) {
  3194. gw += cw+brd;
  3195. } else {
  3196. vc++;
  3197. }
  3198. cl++;
  3199. }
  3200. });
  3201. if(vc === 0) { return; }
  3202. $t.p.tblwidth = initwidth;
  3203. aw = nwidth-brd*vc-gw;
  3204. if(!isNaN($t.p.height)) {
  3205. if($($t.grid.bDiv)[0].clientHeight < $($t.grid.bDiv)[0].scrollHeight || $t.rows.length === 1){
  3206. hs = true;
  3207. aw -= scw;
  3208. }
  3209. }
  3210. initwidth =0;
  3211. var cle = $t.grid.cols.length >0;
  3212. $.each($t.p.colModel, function(i) {
  3213. if(this.hidden === false && !this.fixed){
  3214. cw = this.widthOrg;
  3215. cw = Math.round(aw*cw/($t.p.tblwidth-brd*vc-gw));
  3216. if (cw < 0) { return; }
  3217. this.width =cw;
  3218. initwidth += cw;
  3219. $t.grid.headers[i].width=cw;
  3220. $t.grid.headers[i].el.style.width=cw+"px";
  3221. if($t.p.footerrow) { $t.grid.footers[i].style.width = cw+"px"; }
  3222. if(cle) { $t.grid.cols[i].style.width = cw+"px"; }
  3223. lvc = i;
  3224. }
  3225. });
  3226. if (!lvc) { return; }
  3227. cr =0;
  3228. if (hs) {
  3229. if(nwidth-gw-(initwidth+brd*vc) !== scw){
  3230. cr = nwidth-gw-(initwidth+brd*vc)-scw;
  3231. }
  3232. } else if( Math.abs(nwidth-gw-(initwidth+brd*vc)) !== 1) {
  3233. cr = nwidth-gw-(initwidth+brd*vc);
  3234. }
  3235. $t.p.colModel[lvc].width += cr;
  3236. $t.p.tblwidth = initwidth+cr+brd*vc+gw;
  3237. if($t.p.tblwidth > nwidth) {
  3238. var delta = $t.p.tblwidth - parseInt(nwidth,10);
  3239. $t.p.tblwidth = nwidth;
  3240. cw = $t.p.colModel[lvc].width = $t.p.colModel[lvc].width-delta;
  3241. } else {
  3242. cw= $t.p.colModel[lvc].width;
  3243. }
  3244. $t.grid.headers[lvc].width = cw;
  3245. $t.grid.headers[lvc].el.style.width=cw+"px";
  3246. if(cle) { $t.grid.cols[lvc].style.width = cw+"px"; }
  3247. if($t.p.footerrow) {
  3248. $t.grid.footers[lvc].style.width = cw+"px";
  3249. }
  3250. }
  3251. if($t.p.tblwidth) {
  3252. $('table:first',$t.grid.bDiv).css("width",$t.p.tblwidth+"px");
  3253. $('table:first',$t.grid.hDiv).css("width",$t.p.tblwidth+"px");
  3254. $t.grid.hDiv.scrollLeft = $t.grid.bDiv.scrollLeft;
  3255. if($t.p.footerrow) {
  3256. $('table:first',$t.grid.sDiv).css("width",$t.p.tblwidth+"px");
  3257. }
  3258. }
  3259. });
  3260. },
  3261. setGridHeight : function (nh) {
  3262. return this.each(function (){
  3263. var $t = this;
  3264. if(!$t.grid) {return;}
  3265. var bDiv = $($t.grid.bDiv);
  3266. bDiv.css({height: nh+(isNaN(nh)?"":"px")});
  3267. if($t.p.frozenColumns === true){
  3268. //follow the original set height to use 16, better scrollbar width detection
  3269. $('#'+$.jgrid.jqID($t.p.id)+"_frozen").parent().height(bDiv.height() - 16);
  3270. }
  3271. $t.p.height = nh;
  3272. if ($t.p.scroll) { $t.grid.populateVisible(); }
  3273. });
  3274. },
  3275. setCaption : function (newcap){
  3276. return this.each(function(){
  3277. this.p.caption=newcap;
  3278. $("span.ui-jqgrid-title, span.ui-jqgrid-title-rtl",this.grid.cDiv).html(newcap);
  3279. $(this.grid.cDiv).show();
  3280. });
  3281. },
  3282. setLabel : function(colname, nData, prop, attrp ){
  3283. return this.each(function(){
  3284. var $t = this, pos=-1;
  3285. if(!$t.grid) {return;}
  3286. if(colname !== undefined) {
  3287. $($t.p.colModel).each(function(i){
  3288. if (this.name == colname) {
  3289. pos = i;return false;
  3290. }
  3291. });
  3292. } else { return; }
  3293. if(pos>=0) {
  3294. var thecol = $("tr.ui-jqgrid-labels th:eq("+pos+")",$t.grid.hDiv);
  3295. if (nData){
  3296. var ico = $(".s-ico",thecol);
  3297. $("[id^=jqgh_]",thecol).empty().html(nData).append(ico);
  3298. $t.p.colNames[pos] = nData;
  3299. }
  3300. if (prop) {
  3301. if(typeof prop === 'string') {$(thecol).addClass(prop);} else {$(thecol).css(prop);}
  3302. }
  3303. if(typeof attrp === 'object') {$(thecol).attr(attrp);}
  3304. }
  3305. });
  3306. },
  3307. setCell : function(rowid,colname,nData,cssp,attrp, forceupd) {
  3308. return this.each(function(){
  3309. var $t = this, pos =-1,v, title;
  3310. if(!$t.grid) {return;}
  3311. if(isNaN(colname)) {
  3312. $($t.p.colModel).each(function(i){
  3313. if (this.name == colname) {
  3314. pos = i;return false;
  3315. }
  3316. });
  3317. } else {pos = parseInt(colname,10);}
  3318. if(pos>=0) {
  3319. var ind = $t.rows.namedItem(rowid);
  3320. if (ind){
  3321. var tcell = $("td:eq("+pos+")",ind);
  3322. if(nData !== "" || forceupd === true) {
  3323. v = $t.formatter(rowid, nData, pos,ind,'edit');
  3324. title = $t.p.colModel[pos].title ? {"title":$.jgrid.stripHtml(v)} : {};
  3325. if($t.p.treeGrid && $(".tree-wrap",$(tcell)).length>0) {
  3326. $("span",$(tcell)).html(v).attr(title);
  3327. } else {
  3328. $(tcell).html(v).attr(title);
  3329. }
  3330. if($t.p.datatype == "local") {
  3331. var cm = $t.p.colModel[pos], index;
  3332. nData = cm.formatter && typeof cm.formatter === 'string' && cm.formatter == 'date' ? $.unformat.date.call($t,nData,cm) : nData;
  3333. index = $t.p._index[rowid];
  3334. if(index !== undefined) {
  3335. $t.p.data[index][cm.name] = nData;
  3336. }
  3337. }
  3338. }
  3339. if(typeof cssp === 'string'){
  3340. $(tcell).addClass(cssp);
  3341. } else if(cssp) {
  3342. $(tcell).css(cssp);
  3343. }
  3344. if(typeof attrp === 'object') {$(tcell).attr(attrp);}
  3345. }
  3346. }
  3347. });
  3348. },
  3349. getCell : function(rowid,col) {
  3350. var ret = false;
  3351. this.each(function(){
  3352. var $t=this, pos=-1;
  3353. if(!$t.grid) {return;}
  3354. if(isNaN(col)) {
  3355. $($t.p.colModel).each(function(i){
  3356. if (this.name === col) {
  3357. pos = i;return false;
  3358. }
  3359. });
  3360. } else {pos = parseInt(col,10);}
  3361. if(pos>=0) {
  3362. var ind = $t.rows.namedItem(rowid);
  3363. if(ind) {
  3364. try {
  3365. ret = $.unformat.call($t,$("td:eq("+pos+")",ind),{rowId:ind.id, colModel:$t.p.colModel[pos]},pos);
  3366. } catch (e){
  3367. ret = $.jgrid.htmlDecode($("td:eq("+pos+")",ind).html());
  3368. }
  3369. }
  3370. }
  3371. });
  3372. return ret;
  3373. },
  3374. getCol : function (col, obj, mathopr) {
  3375. var ret = [], val, sum=0, min, max, v;
  3376. obj = typeof obj !== 'boolean' ? false : obj;
  3377. if(mathopr === undefined) { mathopr = false; }
  3378. this.each(function(){
  3379. var $t=this, pos=-1;
  3380. if(!$t.grid) {return;}
  3381. if(isNaN(col)) {
  3382. $($t.p.colModel).each(function(i){
  3383. if (this.name === col) {
  3384. pos = i;return false;
  3385. }
  3386. });
  3387. } else {pos = parseInt(col,10);}
  3388. if(pos>=0) {
  3389. var ln = $t.rows.length, i =0;
  3390. if (ln && ln>0){
  3391. while(i<ln){
  3392. if($($t.rows[i]).hasClass('jqgrow')) {
  3393. try {
  3394. val = $.unformat.call($t,$($t.rows[i].cells[pos]),{rowId:$t.rows[i].id, colModel:$t.p.colModel[pos]},pos);
  3395. } catch (e) {
  3396. val = $.jgrid.htmlDecode($t.rows[i].cells[pos].innerHTML);
  3397. }
  3398. if(mathopr) {
  3399. v = parseFloat(val);
  3400. sum += v;
  3401. if (max === undefined) {max = min = v;}
  3402. min = Math.min(min, v);
  3403. max = Math.max(max, v);
  3404. }
  3405. else if(obj) { ret.push( {id:$t.rows[i].id,value:val} ); }
  3406. else { ret.push( val ); }
  3407. }
  3408. i++;
  3409. }
  3410. if(mathopr) {
  3411. switch(mathopr.toLowerCase()){
  3412. case 'sum': ret =sum; break;
  3413. case 'avg': ret = sum/ln; break;
  3414. case 'count': ret = ln; break;
  3415. case 'min': ret = min; break;
  3416. case 'max': ret = max; break;
  3417. }
  3418. }
  3419. }
  3420. }
  3421. });
  3422. return ret;
  3423. },
  3424. clearGridData : function(clearfooter) {
  3425. return this.each(function(){
  3426. var $t = this;
  3427. if(!$t.grid) {return;}
  3428. if(typeof clearfooter !== 'boolean') { clearfooter = false; }
  3429. if($t.p.deepempty) {$("#"+$.jgrid.jqID($t.p.id)+" tbody:first tr:gt(0)").remove();}
  3430. else {
  3431. var trf = $("#"+$.jgrid.jqID($t.p.id)+" tbody:first tr:first")[0];
  3432. $("#"+$.jgrid.jqID($t.p.id)+" tbody:first").empty().append(trf);
  3433. }
  3434. if($t.p.footerrow && clearfooter) { $(".ui-jqgrid-ftable td",$t.grid.sDiv).html("&#160;"); }
  3435. $t.p.selrow = null; $t.p.selarrrow= []; $t.p.savedRow = [];
  3436. $t.p.records = 0;$t.p.page=1;$t.p.lastpage=0;$t.p.reccount=0;
  3437. $t.p.data = []; $t.p._index = {};
  3438. $t.updatepager(true,false);
  3439. });
  3440. },
  3441. getInd : function(rowid,rc){
  3442. var ret =false,rw;
  3443. this.each(function(){
  3444. rw = this.rows.namedItem(rowid);
  3445. if(rw) {
  3446. ret = rc===true ? rw: rw.rowIndex;
  3447. }
  3448. });
  3449. return ret;
  3450. },
  3451. bindKeys : function( settings ){
  3452. var o = $.extend({
  3453. onEnter: null,
  3454. onSpace: null,
  3455. onLeftKey: null,
  3456. onRightKey: null,
  3457. scrollingRows : true
  3458. },settings || {});
  3459. return this.each(function(){
  3460. var $t = this;
  3461. if( !$('body').is('[role]') ){$('body').attr('role','application');}
  3462. $t.p.scrollrows = o.scrollingRows;
  3463. $($t).keydown(function(event){
  3464. var target = $($t).find('tr[tabindex=0]')[0], id, r, mind,
  3465. expanded = $t.p.treeReader.expanded_field;
  3466. //check for arrow keys
  3467. if(target) {
  3468. mind = $t.p._index[target.id];
  3469. if(event.keyCode === 37 || event.keyCode === 38 || event.keyCode === 39 || event.keyCode === 40){
  3470. // up key
  3471. if(event.keyCode === 38 ){
  3472. r = target.previousSibling;
  3473. id = "";
  3474. if(r) {
  3475. if($(r).is(":hidden")) {
  3476. while(r) {
  3477. r = r.previousSibling;
  3478. if(!$(r).is(":hidden") && $(r).hasClass('jqgrow')) {id = r.id;break;}
  3479. }
  3480. } else {
  3481. id = r.id;
  3482. }
  3483. }
  3484. $($t).jqGrid('setSelection', id, true, event);
  3485. event.preventDefault();
  3486. }
  3487. //if key is down arrow
  3488. if(event.keyCode === 40){
  3489. r = target.nextSibling;
  3490. id ="";
  3491. if(r) {
  3492. if($(r).is(":hidden")) {
  3493. while(r) {
  3494. r = r.nextSibling;
  3495. if(!$(r).is(":hidden") && $(r).hasClass('jqgrow') ) {id = r.id;break;}
  3496. }
  3497. } else {
  3498. id = r.id;
  3499. }
  3500. }
  3501. $($t).jqGrid('setSelection', id, true, event);
  3502. event.preventDefault();
  3503. }
  3504. // left
  3505. if(event.keyCode === 37 ){
  3506. if($t.p.treeGrid && $t.p.data[mind][expanded]) {
  3507. $(target).find("div.treeclick").trigger('click');
  3508. }
  3509. $($t).triggerHandler("jqGridKeyLeft", [$t.p.selrow]);
  3510. if($.isFunction(o.onLeftKey)) {
  3511. o.onLeftKey.call($t, $t.p.selrow);
  3512. }
  3513. }
  3514. // right
  3515. if(event.keyCode === 39 ){
  3516. if($t.p.treeGrid && !$t.p.data[mind][expanded]) {
  3517. $(target).find("div.treeclick").trigger('click');
  3518. }
  3519. $($t).triggerHandler("jqGridKeyRight", [$t.p.selrow]);
  3520. if($.isFunction(o.onRightKey)) {
  3521. o.onRightKey.call($t, $t.p.selrow);
  3522. }
  3523. }
  3524. }
  3525. //check if enter was pressed on a grid or treegrid node
  3526. else if( event.keyCode === 13 ){
  3527. $($t).triggerHandler("jqGridKeyEnter", [$t.p.selrow]);
  3528. if($.isFunction(o.onEnter)) {
  3529. o.onEnter.call($t, $t.p.selrow);
  3530. }
  3531. } else if(event.keyCode === 32) {
  3532. $($t).triggerHandler("jqGridKeySpace", [$t.p.selrow]);
  3533. if($.isFunction(o.onSpace)) {
  3534. o.onSpace.call($t, $t.p.selrow);
  3535. }
  3536. }
  3537. }
  3538. });
  3539. });
  3540. },
  3541. unbindKeys : function(){
  3542. return this.each(function(){
  3543. $(this).unbind('keydown');
  3544. });
  3545. },
  3546. getLocalRow : function (rowid) {
  3547. var ret = false, ind;
  3548. this.each(function(){
  3549. if(rowid !== undefined) {
  3550. ind = this.p._index[rowid];
  3551. if(ind >= 0 ) {
  3552. ret = this.p.data[ind];
  3553. }
  3554. }
  3555. });
  3556. return ret;
  3557. }
  3558. });
  3559. })(jQuery);
  3560. /*jshint eqeqeq:false */
  3561. /*global jQuery */
  3562. (function($){
  3563. /**
  3564. * jqGrid extension for custom methods
  3565. * Tony Tomov tony@trirand.com
  3566. * http://trirand.com/blog/
  3567. *
  3568. * Wildraid wildraid@mail.ru
  3569. * Oleg Kiriljuk oleg.kiriljuk@ok-soft-gmbh.com
  3570. * Dual licensed under the MIT and GPL licenses:
  3571. * http://www.opensource.org/licenses/mit-license.php
  3572. * http://www.gnu.org/licenses/gpl-2.0.html
  3573. **/
  3574. "use strict";
  3575. $.jgrid.extend({
  3576. getColProp : function(colname){
  3577. var ret ={}, $t = this[0];
  3578. if ( !$t.grid ) { return false; }
  3579. var cM = $t.p.colModel, i;
  3580. for ( i=0;i<cM.length;i++ ) {
  3581. if ( cM[i].name == colname ) {
  3582. ret = cM[i];
  3583. break;
  3584. }
  3585. }
  3586. return ret;
  3587. },
  3588. setColProp : function(colname, obj){
  3589. //do not set width will not work
  3590. return this.each(function(){
  3591. if ( this.grid ) {
  3592. if ( obj ) {
  3593. var cM = this.p.colModel, i;
  3594. for ( i=0;i<cM.length;i++ ) {
  3595. if ( cM[i].name == colname ) {
  3596. $.extend(true, this.p.colModel[i],obj);
  3597. break;
  3598. }
  3599. }
  3600. }
  3601. }
  3602. });
  3603. },
  3604. sortGrid : function(colname,reload, sor){
  3605. return this.each(function(){
  3606. var $t=this,idx=-1,i;
  3607. if ( !$t.grid ) { return;}
  3608. if ( !colname ) { colname = $t.p.sortname; }
  3609. for ( i=0;i<$t.p.colModel.length;i++ ) {
  3610. if ( $t.p.colModel[i].index == colname || $t.p.colModel[i].name==colname ) {
  3611. idx = i;
  3612. break;
  3613. }
  3614. }
  3615. if ( idx!=-1 ){
  3616. var sort = $t.p.colModel[idx].sortable;
  3617. if ( typeof sort !== 'boolean' ) { sort = true; }
  3618. if ( typeof reload !=='boolean' ) { reload = false; }
  3619. if ( sort ) { $t.sortData("jqgh_"+$t.p.id+"_" + colname, idx, reload, sor); }
  3620. }
  3621. });
  3622. },
  3623. clearBeforeUnload : function () {
  3624. return this.each(function(){
  3625. var grid = this.grid;
  3626. grid.emptyRows.call(this, true, true); // this work quick enough and reduce the size of memory leaks if we have someone
  3627. //$(document).unbind("mouseup"); // TODO add namespace
  3628. $(grid.hDiv).unbind("mousemove"); // TODO add namespace
  3629. $(this).unbind();
  3630. grid.dragEnd = null;
  3631. grid.dragMove = null;
  3632. grid.dragStart = null;
  3633. grid.emptyRows = null;
  3634. grid.populate = null;
  3635. grid.populateVisible = null;
  3636. grid.scrollGrid = null;
  3637. grid.selectionPreserver = null;
  3638. grid.bDiv = null;
  3639. grid.cDiv = null;
  3640. grid.hDiv = null;
  3641. grid.cols = null;
  3642. var i, l = grid.headers.length;
  3643. for (i = 0; i < l; i++) {
  3644. grid.headers[i].el = null;
  3645. }
  3646. this.formatCol = null;
  3647. this.sortData = null;
  3648. this.updatepager = null;
  3649. this.refreshIndex = null;
  3650. this.setHeadCheckBox = null;
  3651. this.constructTr = null;
  3652. this.formatter = null;
  3653. this.addXmlData = null;
  3654. this.addJSONData = null;
  3655. });
  3656. },
  3657. GridDestroy : function () {
  3658. return this.each(function(){
  3659. if ( this.grid ) {
  3660. if ( this.p.pager ) { // if not part of grid
  3661. $(this.p.pager).remove();
  3662. }
  3663. try {
  3664. $(this).jqGrid('clearBeforeUnload');
  3665. $("#gbox_"+$.jgrid.jqID(this.id)).remove();
  3666. } catch (_) {}
  3667. }
  3668. });
  3669. },
  3670. GridUnload : function(){
  3671. return this.each(function(){
  3672. if ( !this.grid ) {return;}
  3673. var defgrid = {id: $(this).attr('id'),cl: $(this).attr('class')};
  3674. if (this.p.pager) {
  3675. $(this.p.pager).empty().removeClass("ui-state-default ui-jqgrid-pager corner-bottom");
  3676. }
  3677. var newtable = document.createElement('table');
  3678. $(newtable).attr({id:defgrid.id});
  3679. newtable.className = defgrid.cl;
  3680. var gid = $.jgrid.jqID(this.id);
  3681. $(newtable).removeClass("ui-jqgrid-btable");
  3682. if( $(this.p.pager).parents("#gbox_"+gid).length === 1 ) {
  3683. $(newtable).insertBefore("#gbox_"+gid).show();
  3684. $(this.p.pager).insertBefore("#gbox_"+gid);
  3685. } else {
  3686. $(newtable).insertBefore("#gbox_"+gid).show();
  3687. }
  3688. $(this).jqGrid('clearBeforeUnload');
  3689. $("#gbox_"+gid).remove();
  3690. });
  3691. },
  3692. setGridState : function(state) {
  3693. return this.each(function(){
  3694. if ( !this.grid ) {return;}
  3695. var $t = this;
  3696. if(state == 'hidden'){
  3697. $(".ui-jqgrid-bdiv, .ui-jqgrid-hdiv","#gview_"+$.jgrid.jqID($t.p.id)).slideUp("fast");
  3698. if($t.p.pager) {$($t.p.pager).slideUp("fast");}
  3699. if($t.p.toppager) {$($t.p.toppager).slideUp("fast");}
  3700. if($t.p.toolbar[0]===true) {
  3701. if( $t.p.toolbar[1]=='both') {
  3702. $($t.grid.ubDiv).slideUp("fast");
  3703. }
  3704. $($t.grid.uDiv).slideUp("fast");
  3705. }
  3706. if($t.p.footerrow) { $(".ui-jqgrid-sdiv","#gbox_"+$.jgrid.jqID($t.p.id)).slideUp("fast"); }
  3707. $(".ui-jqgrid-titlebar-close span",$t.grid.cDiv).removeClass("ui-icon-circle-triangle-n").addClass("ui-icon-circle-triangle-s");
  3708. $t.p.gridstate = 'hidden';
  3709. } else if(state=='visible') {
  3710. $(".ui-jqgrid-hdiv, .ui-jqgrid-bdiv","#gview_"+$.jgrid.jqID($t.p.id)).slideDown("fast");
  3711. if($t.p.pager) {$($t.p.pager).slideDown("fast");}
  3712. if($t.p.toppager) {$($t.p.toppager).slideDown("fast");}
  3713. if($t.p.toolbar[0]===true) {
  3714. if( $t.p.toolbar[1]=='both') {
  3715. $($t.grid.ubDiv).slideDown("fast");
  3716. }
  3717. $($t.grid.uDiv).slideDown("fast");
  3718. }
  3719. if($t.p.footerrow) { $(".ui-jqgrid-sdiv","#gbox_"+$.jgrid.jqID($t.p.id)).slideDown("fast"); }
  3720. $(".ui-jqgrid-titlebar-close span",$t.grid.cDiv).removeClass("ui-icon-circle-triangle-s").addClass("ui-icon-circle-triangle-n");
  3721. $t.p.gridstate = 'visible';
  3722. }
  3723. });
  3724. },
  3725. filterToolbar : function(p){
  3726. p = $.extend({
  3727. autosearch: true,
  3728. searchOnEnter : true,
  3729. beforeSearch: null,
  3730. afterSearch: null,
  3731. beforeClear: null,
  3732. afterClear: null,
  3733. searchurl : '',
  3734. stringResult: false,
  3735. groupOp: 'AND',
  3736. defaultSearch : "bw"
  3737. },p || {});
  3738. return this.each(function(){
  3739. var $t = this;
  3740. if(this.ftoolbar) { return; }
  3741. var triggerToolbar = function() {
  3742. var sdata={}, j=0, v, nm, sopt={},so;
  3743. $.each($t.p.colModel,function(){
  3744. nm = this.index || this.name;
  3745. so = (this.searchoptions && this.searchoptions.sopt) ? this.searchoptions.sopt[0] : this.stype=='select'? 'eq' : p.defaultSearch;
  3746. v = $("#gs_"+$.jgrid.jqID(this.name), (this.frozen===true && $t.p.frozenColumns === true) ? $t.grid.fhDiv : $t.grid.hDiv).val();
  3747. if(v) {
  3748. sdata[nm] = v;
  3749. sopt[nm] = so;
  3750. j++;
  3751. } else {
  3752. try {
  3753. delete $t.p.postData[nm];
  3754. } catch (z) {}
  3755. }
  3756. });
  3757. var sd = j>0 ? true : false;
  3758. if(p.stringResult === true || $t.p.datatype == "local") {
  3759. var ruleGroup = "{\"groupOp\":\"" + p.groupOp + "\",\"rules\":[";
  3760. var gi=0;
  3761. $.each(sdata,function(i,n){
  3762. if (gi > 0) {ruleGroup += ",";}
  3763. ruleGroup += "{\"field\":\"" + i + "\",";
  3764. ruleGroup += "\"op\":\"" + sopt[i] + "\",";
  3765. n+="";
  3766. ruleGroup += "\"data\":\"" + n.replace(/\\/g,'\\\\').replace(/\"/g,'\\"') + "\"}";
  3767. gi++;
  3768. });
  3769. ruleGroup += "]}";
  3770. $.extend($t.p.postData,{filters:ruleGroup});
  3771. $.each(['searchField', 'searchString', 'searchOper'], function(i, n){
  3772. if($t.p.postData.hasOwnProperty(n)) { delete $t.p.postData[n];}
  3773. });
  3774. } else {
  3775. $.extend($t.p.postData,sdata);
  3776. }
  3777. var saveurl;
  3778. if($t.p.searchurl) {
  3779. saveurl = $t.p.url;
  3780. $($t).jqGrid("setGridParam",{url:$t.p.searchurl});
  3781. }
  3782. var bsr = $($t).triggerHandler("jqGridToolbarBeforeSearch") === 'stop' ? true : false;
  3783. if(!bsr && $.isFunction(p.beforeSearch)){bsr = p.beforeSearch.call($t);}
  3784. if(!bsr) { $($t).jqGrid("setGridParam",{search:sd}).trigger("reloadGrid",[{page:1}]); }
  3785. if(saveurl) {$($t).jqGrid("setGridParam",{url:saveurl});}
  3786. $($t).triggerHandler("jqGridToolbarAfterSearch");
  3787. if($.isFunction(p.afterSearch)){p.afterSearch.call($t);}
  3788. };
  3789. var clearToolbar = function(trigger){
  3790. var sdata={}, j=0, nm;
  3791. trigger = (typeof trigger !== 'boolean') ? true : trigger;
  3792. $.each($t.p.colModel,function(){
  3793. var v;
  3794. if(this.searchoptions && this.searchoptions.defaultValue !== undefined) { v = this.searchoptions.defaultValue; }
  3795. nm = this.index || this.name;
  3796. switch (this.stype) {
  3797. case 'select' :
  3798. $("#gs_"+$.jgrid.jqID(this.name)+" option",(this.frozen===true && $t.p.frozenColumns === true) ? $t.grid.fhDiv : $t.grid.hDiv).each(function (i){
  3799. if(i===0) { this.selected = true; }
  3800. if ($(this).val() == v) {
  3801. this.selected = true;
  3802. return false;
  3803. }
  3804. });
  3805. if ( v !== undefined ) {
  3806. // post the key and not the text
  3807. sdata[nm] = v;
  3808. j++;
  3809. } else {
  3810. try {
  3811. delete $t.p.postData[nm];
  3812. } catch(e) {}
  3813. }
  3814. break;
  3815. case 'text':
  3816. $("#gs_"+$.jgrid.jqID(this.name),(this.frozen===true && $t.p.frozenColumns === true) ? $t.grid.fhDiv : $t.grid.hDiv).val(v);
  3817. if(v !== undefined) {
  3818. sdata[nm] = v;
  3819. j++;
  3820. } else {
  3821. try {
  3822. delete $t.p.postData[nm];
  3823. } catch (y){}
  3824. }
  3825. break;
  3826. }
  3827. });
  3828. var sd = j>0 ? true : false;
  3829. if(p.stringResult === true || $t.p.datatype == "local") {
  3830. var ruleGroup = "{\"groupOp\":\"" + p.groupOp + "\",\"rules\":[";
  3831. var gi=0;
  3832. $.each(sdata,function(i,n){
  3833. if (gi > 0) {ruleGroup += ",";}
  3834. ruleGroup += "{\"field\":\"" + i + "\",";
  3835. ruleGroup += "\"op\":\"" + "eq" + "\",";
  3836. n+="";
  3837. ruleGroup += "\"data\":\"" + n.replace(/\\/g,'\\\\').replace(/\"/g,'\\"') + "\"}";
  3838. gi++;
  3839. });
  3840. ruleGroup += "]}";
  3841. $.extend($t.p.postData,{filters:ruleGroup});
  3842. $.each(['searchField', 'searchString', 'searchOper'], function(i, n){
  3843. if($t.p.postData.hasOwnProperty(n)) { delete $t.p.postData[n];}
  3844. });
  3845. } else {
  3846. $.extend($t.p.postData,sdata);
  3847. }
  3848. var saveurl;
  3849. if($t.p.searchurl) {
  3850. saveurl = $t.p.url;
  3851. $($t).jqGrid("setGridParam",{url:$t.p.searchurl});
  3852. }
  3853. var bcv = $($t).triggerHandler("jqGridToolbarBeforeClear") === 'stop' ? true : false;
  3854. if(!bcv && $.isFunction(p.beforeClear)){bcv = p.beforeClear.call($t);}
  3855. if(!bcv) {
  3856. if(trigger) {
  3857. $($t).jqGrid("setGridParam",{search:sd}).trigger("reloadGrid",[{page:1}]);
  3858. }
  3859. }
  3860. if(saveurl) {$($t).jqGrid("setGridParam",{url:saveurl});}
  3861. $($t).triggerHandler("jqGridToolbarAfterClear");
  3862. if($.isFunction(p.afterClear)){p.afterClear();}
  3863. };
  3864. var toggleToolbar = function(){
  3865. var trow = $("tr.ui-search-toolbar",$t.grid.hDiv),
  3866. trow2 = $t.p.frozenColumns === true ? $("tr.ui-search-toolbar",$t.grid.fhDiv) : false;
  3867. if(trow.css("display")=='none') {
  3868. trow.show();
  3869. if(trow2) {
  3870. trow2.show();
  3871. }
  3872. } else {
  3873. trow.hide();
  3874. if(trow2) {
  3875. trow2.hide();
  3876. }
  3877. }
  3878. };
  3879. // create the row
  3880. var tr = $("<tr class='ui-search-toolbar' role='rowheader'></tr>");
  3881. var timeoutHnd;
  3882. $.each($t.p.colModel,function(){
  3883. var cm=this, thd , th, soptions,surl,self;
  3884. th = $("<th role='columnheader' class='ui-state-default ui-th-column ui-th-"+$t.p.direction+"'></th>");
  3885. thd = $("<div style='position:relative;height:100%;padding-right:0.3em;'></div>");
  3886. if(this.hidden===true) { $(th).css("display","none");}
  3887. this.search = this.search === false ? false : true;
  3888. if(this.stype === undefined) {this.stype='text';}
  3889. soptions = $.extend({},this.searchoptions || {});
  3890. if(this.search){
  3891. switch (this.stype)
  3892. {
  3893. case "select":
  3894. surl = this.surl || soptions.dataUrl;
  3895. if(surl) {
  3896. // data returned should have already constructed html select
  3897. // primitive jQuery load
  3898. self = thd;
  3899. $.ajax($.extend({
  3900. url: surl,
  3901. dataType: "html",
  3902. success: function(res) {
  3903. if(soptions.buildSelect !== undefined) {
  3904. var d = soptions.buildSelect(res);
  3905. if (d) { $(self).append(d); }
  3906. } else {
  3907. $(self).append(res);
  3908. }
  3909. if(soptions.defaultValue !== undefined) { $("select",self).val(soptions.defaultValue); }
  3910. $("select",self).attr({name:cm.index || cm.name, id: "gs_"+cm.name});
  3911. if(soptions.attr) {$("select",self).attr(soptions.attr);}
  3912. $("select",self).css({width: "100%"});
  3913. // preserve autoserch
  3914. $.jgrid.bindEv( $("select",self)[0], soptions, $t);
  3915. if(p.autosearch===true){
  3916. $("select",self).change(function(){
  3917. triggerToolbar();
  3918. return false;
  3919. });
  3920. }
  3921. res=null;
  3922. }
  3923. }, $.jgrid.ajaxOptions, $t.p.ajaxSelectOptions || {} ));
  3924. } else {
  3925. var oSv, sep, delim;
  3926. if(cm.searchoptions) {
  3927. oSv = cm.searchoptions.value === undefined ? "" : cm.searchoptions.value;
  3928. sep = cm.searchoptions.separator === undefined ? ":" : cm.searchoptions.separator;
  3929. delim = cm.searchoptions.delimiter === undefined ? ";" : cm.searchoptions.delimiter;
  3930. } else if(cm.editoptions) {
  3931. oSv = cm.editoptions.value === undefined ? "" : cm.editoptions.value;
  3932. sep = cm.editoptions.separator === undefined ? ":" : cm.editoptions.separator;
  3933. delim = cm.editoptions.delimiter === undefined ? ";" : cm.editoptions.delimiter;
  3934. }
  3935. if (oSv) {
  3936. var elem = document.createElement("select");
  3937. elem.style.width = "100%";
  3938. $(elem).attr({name:cm.index || cm.name, id: "gs_"+cm.name});
  3939. var so, sv, ov, key, k;
  3940. if(typeof oSv === "string") {
  3941. so = oSv.split(delim);
  3942. for(k=0; k<so.length;k++){
  3943. sv = so[k].split(sep);
  3944. ov = document.createElement("option");
  3945. ov.value = sv[0]; ov.innerHTML = sv[1];
  3946. elem.appendChild(ov);
  3947. }
  3948. } else if(typeof oSv === "object" ) {
  3949. for (key in oSv) {
  3950. if(oSv.hasOwnProperty(key)) {
  3951. ov = document.createElement("option");
  3952. ov.value = key; ov.innerHTML = oSv[key];
  3953. elem.appendChild(ov);
  3954. }
  3955. }
  3956. }
  3957. if(soptions.defaultValue !== undefined) { $(elem).val(soptions.defaultValue); }
  3958. if(soptions.attr) {$(elem).attr(soptions.attr);}
  3959. $.jgrid.bindEv( elem , soptions, $t);
  3960. $(thd).append(elem);
  3961. if(p.autosearch===true){
  3962. $(elem).change(function(){
  3963. triggerToolbar();
  3964. return false;
  3965. });
  3966. }
  3967. }
  3968. }
  3969. break;
  3970. case 'text':
  3971. var df = soptions.defaultValue !== undefined ? soptions.defaultValue: "";
  3972. $(thd).append("<input type='text' style='width:95%;padding:0px;' name='"+(cm.index || cm.name)+"' id='gs_"+cm.name+"' value='"+df+"'/>");
  3973. if(soptions.attr) {$("input",thd).attr(soptions.attr);}
  3974. $.jgrid.bindEv( $("input",thd)[0], soptions, $t);
  3975. if(p.autosearch===true){
  3976. if(p.searchOnEnter) {
  3977. $("input",thd).keypress(function(e){
  3978. var key = e.charCode || e.keyCode || 0;
  3979. if(key == 13){
  3980. triggerToolbar();
  3981. return false;
  3982. }
  3983. return this;
  3984. });
  3985. } else {
  3986. $("input",thd).keydown(function(e){
  3987. var key = e.which;
  3988. switch (key) {
  3989. case 13:
  3990. return false;
  3991. case 9 :
  3992. case 16:
  3993. case 37:
  3994. case 38:
  3995. case 39:
  3996. case 40:
  3997. case 27:
  3998. break;
  3999. default :
  4000. if(timeoutHnd) { clearTimeout(timeoutHnd); }
  4001. timeoutHnd = setTimeout(function(){triggerToolbar();},500);
  4002. }
  4003. });
  4004. }
  4005. }
  4006. break;
  4007. }
  4008. }
  4009. $(th).append(thd);
  4010. $(tr).append(th);
  4011. });
  4012. $("table thead",$t.grid.hDiv).append(tr);
  4013. this.ftoolbar = true;
  4014. this.triggerToolbar = triggerToolbar;
  4015. this.clearToolbar = clearToolbar;
  4016. this.toggleToolbar = toggleToolbar;
  4017. });
  4018. },
  4019. destroyFilterToolbar: function () {
  4020. return this.each(function () {
  4021. if (!this.ftoolbar) {
  4022. return;
  4023. }
  4024. this.triggerToolbar = null;
  4025. this.clearToolbar = null;
  4026. this.toggleToolbar = null;
  4027. this.ftoolbar = false;
  4028. $(this.grid.hDiv).find("table thead tr.ui-search-toolbar").remove();
  4029. });
  4030. },
  4031. destroyGroupHeader : function(nullHeader)
  4032. {
  4033. if(nullHeader === undefined) {
  4034. nullHeader = true;
  4035. }
  4036. return this.each(function()
  4037. {
  4038. var $t = this, $tr, i, l, headers, $th, $resizing, grid = $t.grid,
  4039. thead = $("table.ui-jqgrid-htable thead", grid.hDiv), cm = $t.p.colModel, hc;
  4040. if(!grid) { return; }
  4041. $(this).unbind('.setGroupHeaders');
  4042. $tr = $("<tr>", {role: "rowheader"}).addClass("ui-jqgrid-labels");
  4043. headers = grid.headers;
  4044. for (i = 0, l = headers.length; i < l; i++) {
  4045. hc = cm[i].hidden ? "none" : "";
  4046. $th = $(headers[i].el)
  4047. .width(headers[i].width)
  4048. .css('display',hc);
  4049. try {
  4050. $th.removeAttr("rowSpan");
  4051. } catch (rs) {
  4052. //IE 6/7
  4053. $th.attr("rowSpan",1);
  4054. }
  4055. $tr.append($th);
  4056. $resizing = $th.children("span.ui-jqgrid-resize");
  4057. if ($resizing.length>0) {// resizable column
  4058. $resizing[0].style.height = "";
  4059. }
  4060. $th.children("div")[0].style.top = "";
  4061. }
  4062. $(thead).children('tr.ui-jqgrid-labels').remove();
  4063. $(thead).prepend($tr);
  4064. if(nullHeader === true) {
  4065. $($t).jqGrid('setGridParam',{ 'groupHeader': null});
  4066. }
  4067. });
  4068. },
  4069. setGroupHeaders : function ( o ) {
  4070. o = $.extend({
  4071. useColSpanStyle : false,
  4072. groupHeaders: []
  4073. },o || {});
  4074. return this.each(function(){
  4075. this.p.groupHeader = o;
  4076. var ts = this,
  4077. i, cmi, skip = 0, $tr, $colHeader, th, $th, thStyle,
  4078. iCol,
  4079. cghi,
  4080. //startColumnName,
  4081. numberOfColumns,
  4082. titleText,
  4083. cVisibleColumns,
  4084. colModel = ts.p.colModel,
  4085. cml = colModel.length,
  4086. ths = ts.grid.headers,
  4087. $htable = $("table.ui-jqgrid-htable", ts.grid.hDiv),
  4088. $trLabels = $htable.children("thead").children("tr.ui-jqgrid-labels:last").addClass("jqg-second-row-header"),
  4089. $thead = $htable.children("thead"),
  4090. $theadInTable,
  4091. $firstHeaderRow = $htable.find(".jqg-first-row-header");
  4092. if($firstHeaderRow[0] === undefined) {
  4093. $firstHeaderRow = $('<tr>', {role: "row", "aria-hidden": "true"}).addClass("jqg-first-row-header").css("height", "auto");
  4094. } else {
  4095. $firstHeaderRow.empty();
  4096. }
  4097. var $firstRow,
  4098. inColumnHeader = function (text, columnHeaders) {
  4099. var length = columnHeaders.length, i;
  4100. for (i = 0; i < length; i++) {
  4101. if (columnHeaders[i].startColumnName === text) {
  4102. return i;
  4103. }
  4104. }
  4105. return -1;
  4106. };
  4107. $(ts).prepend($thead);
  4108. $tr = $('<tr>', {role: "rowheader"}).addClass("ui-jqgrid-labels jqg-third-row-header");
  4109. for (i = 0; i < cml; i++) {
  4110. th = ths[i].el;
  4111. $th = $(th);
  4112. cmi = colModel[i];
  4113. // build the next cell for the first header row
  4114. thStyle = { height: '0px', width: ths[i].width + 'px', display: (cmi.hidden ? 'none' : '')};
  4115. $("<th>", {role: 'gridcell'}).css(thStyle).addClass("ui-first-th-"+ts.p.direction).appendTo($firstHeaderRow);
  4116. th.style.width = ""; // remove unneeded style
  4117. iCol = inColumnHeader(cmi.name, o.groupHeaders);
  4118. if (iCol >= 0) {
  4119. cghi = o.groupHeaders[iCol];
  4120. numberOfColumns = cghi.numberOfColumns;
  4121. titleText = cghi.titleText;
  4122. // caclulate the number of visible columns from the next numberOfColumns columns
  4123. for (cVisibleColumns = 0, iCol = 0; iCol < numberOfColumns && (i + iCol < cml); iCol++) {
  4124. if (!colModel[i + iCol].hidden) {
  4125. cVisibleColumns++;
  4126. }
  4127. }
  4128. // The next numberOfColumns headers will be moved in the next row
  4129. // in the current row will be placed the new column header with the titleText.
  4130. // The text will be over the cVisibleColumns columns
  4131. $colHeader = $('<th>').attr({role: "columnheader"})
  4132. .addClass("ui-state-default ui-th-column-header ui-th-"+ts.p.direction)
  4133. .css({'height':'22px', 'border-top': '0px none'})
  4134. .html(titleText);
  4135. if(cVisibleColumns > 0) {
  4136. $colHeader.attr("colspan", String(cVisibleColumns));
  4137. }
  4138. if (ts.p.headertitles) {
  4139. $colHeader.attr("title", $colHeader.text());
  4140. }
  4141. // hide if not a visible cols
  4142. if( cVisibleColumns === 0) {
  4143. $colHeader.hide();
  4144. }
  4145. $th.before($colHeader); // insert new column header before the current
  4146. $tr.append(th); // move the current header in the next row
  4147. // set the coumter of headers which will be moved in the next row
  4148. skip = numberOfColumns - 1;
  4149. } else {
  4150. if (skip === 0) {
  4151. if (o.useColSpanStyle) {
  4152. // expand the header height to two rows
  4153. $th.attr("rowspan", "2");
  4154. } else {
  4155. $('<th>', {role: "columnheader"})
  4156. .addClass("ui-state-default ui-th-column-header ui-th-"+ts.p.direction)
  4157. .css({"display": cmi.hidden ? 'none' : '', 'border-top': '0px none'})
  4158. .insertBefore($th);
  4159. $tr.append(th);
  4160. }
  4161. } else {
  4162. // move the header to the next row
  4163. //$th.css({"padding-top": "2px", height: "19px"});
  4164. $tr.append(th);
  4165. skip--;
  4166. }
  4167. }
  4168. }
  4169. $theadInTable = $(ts).children("thead");
  4170. $theadInTable.prepend($firstHeaderRow);
  4171. $tr.insertAfter($trLabels);
  4172. $htable.append($theadInTable);
  4173. if (o.useColSpanStyle) {
  4174. // Increase the height of resizing span of visible headers
  4175. $htable.find("span.ui-jqgrid-resize").each(function () {
  4176. var $parent = $(this).parent();
  4177. if ($parent.is(":visible")) {
  4178. this.style.cssText = 'height: ' + $parent.height() + 'px !important; cursor: col-resize;';
  4179. }
  4180. });
  4181. // Set position of the sortable div (the main lable)
  4182. // with the column header text to the middle of the cell.
  4183. // One should not do this for hidden headers.
  4184. $htable.find("div.ui-jqgrid-sortable").each(function () {
  4185. var $ts = $(this), $parent = $ts.parent();
  4186. if ($parent.is(":visible") && $parent.is(":has(span.ui-jqgrid-resize)")) {
  4187. $ts.css('top', ($parent.height() - $ts.outerHeight()) / 2 + 'px');
  4188. }
  4189. });
  4190. }
  4191. $firstRow = $theadInTable.find("tr.jqg-first-row-header");
  4192. $(ts).bind('jqGridResizeStop.setGroupHeaders', function (e, nw, idx) {
  4193. $firstRow.find('th').eq(idx).width(nw);
  4194. });
  4195. });
  4196. },
  4197. setFrozenColumns : function () {
  4198. return this.each(function() {
  4199. if ( !this.grid ) {return;}
  4200. var $t = this, cm = $t.p.colModel,i=0, len = cm.length, maxfrozen = -1, frozen= false;
  4201. // TODO treeGrid and grouping Support
  4202. if($t.p.subGrid === true || $t.p.treeGrid === true || $t.p.cellEdit === true || $t.p.sortable || $t.p.scroll || $t.p.grouping )
  4203. {
  4204. return;
  4205. }
  4206. if($t.p.rownumbers) { i++; }
  4207. if($t.p.multiselect) { i++; }
  4208. // get the max index of frozen col
  4209. while(i<len)
  4210. {
  4211. // from left, no breaking frozen
  4212. if(cm[i].frozen === true)
  4213. {
  4214. frozen = true;
  4215. maxfrozen = i;
  4216. } else {
  4217. break;
  4218. }
  4219. i++;
  4220. }
  4221. if( maxfrozen>=0 && frozen) {
  4222. var top = $t.p.caption ? $($t.grid.cDiv).outerHeight() : 0,
  4223. hth = $(".ui-jqgrid-htable","#gview_"+$.jgrid.jqID($t.p.id)).height();
  4224. //headers
  4225. if($t.p.toppager) {
  4226. top = top + $($t.grid.topDiv).outerHeight();
  4227. }
  4228. if($t.p.toolbar[0] === true) {
  4229. if($t.p.toolbar[1] != "bottom") {
  4230. top = top + $($t.grid.uDiv).outerHeight();
  4231. }
  4232. }
  4233. $t.grid.fhDiv = $('<div style="position:absolute;left:0px;top:'+top+'px;height:'+hth+'px;" class="frozen-div ui-state-default ui-jqgrid-hdiv"></div>');
  4234. $t.grid.fbDiv = $('<div style="position:absolute;left:0px;top:'+(parseInt(top,10)+parseInt(hth,10) + 1)+'px;overflow-y:hidden" class="frozen-bdiv ui-jqgrid-bdiv"></div>');
  4235. $("#gview_"+$.jgrid.jqID($t.p.id)).append($t.grid.fhDiv);
  4236. var htbl = $(".ui-jqgrid-htable","#gview_"+$.jgrid.jqID($t.p.id)).clone(true);
  4237. // groupheader support - only if useColSpanstyle is false
  4238. if($t.p.groupHeader) {
  4239. $("tr.jqg-first-row-header, tr.jqg-third-row-header", htbl).each(function(){
  4240. $("th:gt("+maxfrozen+")",this).remove();
  4241. });
  4242. var swapfroz = -1, fdel = -1;
  4243. $("tr.jqg-second-row-header th", htbl).each(function(){
  4244. var cs= parseInt($(this).attr("colspan"),10);
  4245. if(cs) {
  4246. swapfroz = swapfroz+cs;
  4247. fdel++;
  4248. }
  4249. if(swapfroz === maxfrozen) {
  4250. return false;
  4251. }
  4252. });
  4253. if(swapfroz !== maxfrozen) {
  4254. fdel = maxfrozen;
  4255. }
  4256. $("tr.jqg-second-row-header", htbl).each(function(){
  4257. $("th:gt("+fdel+")",this).remove();
  4258. });
  4259. } else {
  4260. $("tr",htbl).each(function(){
  4261. $("th:gt("+maxfrozen+")",this).remove();
  4262. });
  4263. }
  4264. $(htbl).width(1);
  4265. // resizing stuff
  4266. $($t.grid.fhDiv).append(htbl)
  4267. .mousemove(function (e) {
  4268. if($t.grid.resizing){ $t.grid.dragMove(e);return false; }
  4269. });
  4270. $($t).bind('jqGridResizeStop.setFrozenColumns', function (e, w, index) {
  4271. var rhth = $(".ui-jqgrid-htable",$t.grid.fhDiv);
  4272. $("th:eq("+index+")",rhth).width( w );
  4273. var btd = $(".ui-jqgrid-btable",$t.grid.fbDiv);
  4274. $("tr:first td:eq("+index+")",btd).width( w );
  4275. });
  4276. // sorting stuff
  4277. $($t).bind('jqGridOnSortCol.setFrozenColumns', function (index, idxcol) {
  4278. var previousSelectedTh = $("tr.ui-jqgrid-labels:last th:eq("+$t.p.lastsort+")",$t.grid.fhDiv), newSelectedTh = $("tr.ui-jqgrid-labels:last th:eq("+idxcol+")",$t.grid.fhDiv);
  4279. $("span.ui-grid-ico-sort",previousSelectedTh).addClass('ui-state-disabled');
  4280. $(previousSelectedTh).attr("aria-selected","false");
  4281. $("span.ui-icon-"+$t.p.sortorder,newSelectedTh).removeClass('ui-state-disabled');
  4282. $(newSelectedTh).attr("aria-selected","true");
  4283. if(!$t.p.viewsortcols[0]) {
  4284. if($t.p.lastsort != idxcol) {
  4285. $("span.s-ico",previousSelectedTh).hide();
  4286. $("span.s-ico",newSelectedTh).show();
  4287. }
  4288. }
  4289. });
  4290. // data stuff
  4291. //TODO support for setRowData
  4292. $("#gview_"+$.jgrid.jqID($t.p.id)).append($t.grid.fbDiv);
  4293. $($t.grid.bDiv).scroll(function () {
  4294. $($t.grid.fbDiv).scrollTop($(this).scrollTop());
  4295. });
  4296. if($t.p.hoverrows === true) {
  4297. $("#"+$.jgrid.jqID($t.p.id)).unbind('mouseover').unbind('mouseout');
  4298. }
  4299. $($t).bind('jqGridAfterGridComplete.setFrozenColumns', function () {
  4300. $("#"+$.jgrid.jqID($t.p.id)+"_frozen").remove();
  4301. $($t.grid.fbDiv).height($($t.grid.bDiv).height()-16);
  4302. var btbl = $("#"+$.jgrid.jqID($t.p.id)).clone(true);
  4303. $("tr",btbl).each(function(){
  4304. $("td:gt("+maxfrozen+")",this).remove();
  4305. });
  4306. $(btbl).width(1).attr("id",$t.p.id+"_frozen");
  4307. $($t.grid.fbDiv).append(btbl);
  4308. if($t.p.hoverrows === true) {
  4309. $("tr.jqgrow", btbl).hover(
  4310. function(){ $(this).addClass("ui-state-hover"); $("#"+$.jgrid.jqID(this.id), "#"+$.jgrid.jqID($t.p.id)).addClass("ui-state-hover"); },
  4311. function(){ $(this).removeClass("ui-state-hover"); $("#"+$.jgrid.jqID(this.id), "#"+$.jgrid.jqID($t.p.id)).removeClass("ui-state-hover"); }
  4312. );
  4313. $("tr.jqgrow", "#"+$.jgrid.jqID($t.p.id)).hover(
  4314. function(){ $(this).addClass("ui-state-hover"); $("#"+$.jgrid.jqID(this.id), "#"+$.jgrid.jqID($t.p.id)+"_frozen").addClass("ui-state-hover");},
  4315. function(){ $(this).removeClass("ui-state-hover"); $("#"+$.jgrid.jqID(this.id), "#"+$.jgrid.jqID($t.p.id)+"_frozen").removeClass("ui-state-hover"); }
  4316. );
  4317. }
  4318. btbl=null;
  4319. });
  4320. $t.p.frozenColumns = true;
  4321. }
  4322. });
  4323. },
  4324. destroyFrozenColumns : function() {
  4325. return this.each(function() {
  4326. if ( !this.grid ) {return;}
  4327. if(this.p.frozenColumns === true) {
  4328. var $t = this;
  4329. $($t.grid.fhDiv).remove();
  4330. $($t.grid.fbDiv).remove();
  4331. $t.grid.fhDiv = null; $t.grid.fbDiv=null;
  4332. $(this).unbind('.setFrozenColumns');
  4333. if($t.p.hoverrows === true) {
  4334. var ptr;
  4335. $("#"+$.jgrid.jqID($t.p.id)).bind('mouseover',function(e) {
  4336. ptr = $(e.target).closest("tr.jqgrow");
  4337. if($(ptr).attr("class") !== "ui-subgrid") {
  4338. $(ptr).addClass("ui-state-hover");
  4339. }
  4340. }).bind('mouseout',function(e) {
  4341. ptr = $(e.target).closest("tr.jqgrow");
  4342. $(ptr).removeClass("ui-state-hover");
  4343. });
  4344. }
  4345. this.p.frozenColumns = false;
  4346. }
  4347. });
  4348. }
  4349. });
  4350. })(jQuery);
  4351. /*
  4352. * jqModal - Minimalist Modaling with jQuery
  4353. * (http://dev.iceburg.net/jquery/jqmodal/)
  4354. *
  4355. * Copyright (c) 2007,2008 Brice Burgess <bhb@iceburg.net>
  4356. * Dual licensed under the MIT and GPL licenses:
  4357. * http://www.opensource.org/licenses/mit-license.php
  4358. * http://www.gnu.org/licenses/gpl.html
  4359. *
  4360. * $Version: 07/06/2008 +r13
  4361. */
  4362. (function($) {
  4363. $.fn.jqm=function(o){
  4364. var p={
  4365. overlay: 50,
  4366. closeoverlay : true,
  4367. overlayClass: 'jqmOverlay',
  4368. closeClass: 'jqmClose',
  4369. trigger: '.jqModal',
  4370. ajax: F,
  4371. ajaxText: '',
  4372. target: F,
  4373. modal: F,
  4374. toTop: F,
  4375. onShow: F,
  4376. onHide: F,
  4377. onLoad: F
  4378. };
  4379. return this.each(function(){if(this._jqm)return H[this._jqm].c=$.extend({},H[this._jqm].c,o);s++;this._jqm=s;
  4380. H[s]={c:$.extend(p,$.jqm.params,o),a:F,w:$(this).addClass('jqmID'+s),s:s};
  4381. if(p.trigger)$(this).jqmAddTrigger(p.trigger);
  4382. });};
  4383. $.fn.jqmAddClose=function(e){return hs(this,e,'jqmHide');};
  4384. $.fn.jqmAddTrigger=function(e){return hs(this,e,'jqmShow');};
  4385. $.fn.jqmShow=function(t){return this.each(function(){$.jqm.open(this._jqm,t);});};
  4386. $.fn.jqmHide=function(t){return this.each(function(){$.jqm.close(this._jqm,t)});};
  4387. $.jqm = {
  4388. hash:{},
  4389. 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);
  4390. if(c.modal) {if(!A[0])setTimeout(function(){L('bind');},1);A.push(s);}
  4391. else if(c.overlay > 0) {if(c.closeoverlay) h.w.jqmAddClose(o);}
  4392. else o=F;
  4393. h.o=(o)?o.addClass(c.overlayClass).prependTo('body'):F;
  4394. if(ie6){try{$('html,body').css({height:'100%',width:'100%'});if(o){o=o.css({position:'absolute'})[0];for(var y in {Top:1,Left:1})o.style.setExpression(y.toLowerCase(),"(_=(document.documentElement.scroll"+y+" || document.body.scroll"+y+"))+'px'");}}catch(__){}}
  4395. 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;
  4396. 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);});}
  4397. else if(cc)h.w.jqmAddClose($(cc,h.w));
  4398. if(c.toTop&&h.o)h.w.before('<span id="jqmP'+h.w[0]._jqm+'"></span>').insertAfter(h.o);
  4399. (c.onShow)?c.onShow(h):h.w.show();e(h);return F;
  4400. },
  4401. close:function(s){var h=H[s];if(!h.a)return F;h.a=F;
  4402. if(A[0]){A.pop();if(!A[0])L('unbind');}
  4403. if(h.c.toTop&&h.o)$('#jqmP'+h.w[0]._jqm).after(h.w).remove();
  4404. if(h.c.onHide)h.c.onHide(h);else{h.w.hide();if(h.o)h.o.remove();} return F;
  4405. },
  4406. params:{}};
  4407. var s=0,H=$.jqm.hash,A=[],ie6=$.browser.msie&&($.browser.version == "6.0"),F=false,
  4408. e=function(h){var i=$('<iframe src="javascript:false;document.write(\'\');" class="jqm"></iframe>').css({opacity:0});if(ie6)if(h.o)h.o.html('<p style="width:100%;height:100%"/>').prepend(i);else if(!$('iframe.jqm',h.w)[0])h.w.prepend(i); f(h);},
  4409. f=function(h){try{$(':input:visible',h.w)[0].focus();}catch(_){}},
  4410. L=function(t){$(document)[t]("keypress",m)[t]("keydown",m)[t]("mousedown",m);},
  4411. m=function(e){var h=H[A[A.length-1]],r=(!$(e.target).parents('.jqmID'+h.s)[0]);if(r)f(h);return !r;},
  4412. hs=function(w,t,c){return w.each(function(){var s=this._jqm;$(t).each(function() {
  4413. 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;});}this[c].push(s);});});};
  4414. })(jQuery);/*
  4415. * jqDnR - Minimalistic Drag'n'Resize for jQuery.
  4416. *
  4417. * Copyright (c) 2007 Brice Burgess <bhb@iceburg.net>, http://www.iceburg.net
  4418. * Licensed under the MIT License:
  4419. * http://www.opensource.org/licenses/mit-license.php
  4420. *
  4421. * $Version: 2007.08.19 +r2
  4422. */
  4423. (function($){
  4424. $.fn.jqDrag=function(h){return i(this,h,'d');};
  4425. $.fn.jqResize=function(h,ar){return i(this,h,'r',ar);};
  4426. $.jqDnR={
  4427. dnr:{},
  4428. e:0,
  4429. drag:function(v){
  4430. if(M.k == 'd'){E.css({left:M.X+v.pageX-M.pX,top:M.Y+v.pageY-M.pY});}
  4431. else {
  4432. E.css({width:Math.max(v.pageX-M.pX+M.W,0),height:Math.max(v.pageY-M.pY+M.H,0)});
  4433. if(M1){E1.css({width:Math.max(v.pageX-M1.pX+M1.W,0),height:Math.max(v.pageY-M1.pY+M1.H,0)});}
  4434. }
  4435. return false;
  4436. },
  4437. stop:function(){
  4438. //E.css('opacity',M.o);
  4439. $(document).unbind('mousemove',J.drag).unbind('mouseup',J.stop);
  4440. }
  4441. };
  4442. var J=$.jqDnR,M=J.dnr,E=J.e,E1,M1,
  4443. i=function(e,h,k,aR){
  4444. return e.each(function(){
  4445. h=(h)?$(h,e):e;
  4446. h.bind('mousedown',{e:e,k:k},function(v){
  4447. var d=v.data,p={};E=d.e;E1 = aR ? $(aR) : false;
  4448. // attempt utilization of dimensions plugin to fix IE issues
  4449. if(E.css('position') != 'relative'){try{E.position(p);}catch(e){}}
  4450. M={
  4451. X:p.left||f('left')||0,
  4452. Y:p.top||f('top')||0,
  4453. W:f('width')||E[0].scrollWidth||0,
  4454. H:f('height')||E[0].scrollHeight||0,
  4455. pX:v.pageX,
  4456. pY:v.pageY,
  4457. k:d.k
  4458. //o:E.css('opacity')
  4459. };
  4460. // also resize
  4461. if(E1 && d.k != 'd'){
  4462. M1={
  4463. X:p.left||f1('left')||0,
  4464. Y:p.top||f1('top')||0,
  4465. W:E1[0].offsetWidth||f1('width')||0,
  4466. H:E1[0].offsetHeight||f1('height')||0,
  4467. pX:v.pageX,
  4468. pY:v.pageY,
  4469. k:d.k
  4470. };
  4471. } else {M1 = false;}
  4472. //E.css({opacity:0.8});
  4473. if($("input.hasDatepicker",E[0])[0]) {
  4474. try {$("input.hasDatepicker",E[0]).datepicker('hide');}catch (dpe){}
  4475. }
  4476. $(document).mousemove($.jqDnR.drag).mouseup($.jqDnR.stop);
  4477. return false;
  4478. });
  4479. });
  4480. },
  4481. f=function(k){return parseInt(E.css(k),10)||false;},
  4482. f1=function(k){return parseInt(E1.css(k),10)||false;};
  4483. })(jQuery);/*
  4484. The below work is licensed under Creative Commons GNU LGPL License.
  4485. Original work:
  4486. License: http://creativecommons.org/licenses/LGPL/2.1/
  4487. Author: Stefan Goessner/2006
  4488. Web: http://goessner.net/
  4489. Modifications made:
  4490. Version: 0.9-p5
  4491. Description: Restructured code, JSLint validated (no strict whitespaces),
  4492. added handling of empty arrays, empty strings, and int/floats values.
  4493. Author: Michael Schøler/2008-01-29
  4494. Web: http://michael.hinnerup.net/blog/2008/01/26/converting-json-to-xml-and-xml-to-json/
  4495. Description: json2xml added support to convert functions as CDATA
  4496. so it will be easy to write characters that cause some problems when convert
  4497. Author: Tony Tomov
  4498. */
  4499. /*global alert */
  4500. var xmlJsonClass = {
  4501. // Param "xml": Element or document DOM node.
  4502. // Param "tab": Tab or indent string for pretty output formatting omit or use empty string "" to supress.
  4503. // Returns: JSON string
  4504. xml2json: function(xml, tab) {
  4505. if (xml.nodeType === 9) {
  4506. // document node
  4507. xml = xml.documentElement;
  4508. }
  4509. var nws = this.removeWhite(xml);
  4510. var obj = this.toObj(nws);
  4511. var json = this.toJson(obj, xml.nodeName, "\t");
  4512. return "{\n" + tab + (tab ? json.replace(/\t/g, tab) : json.replace(/\t|\n/g, "")) + "\n}";
  4513. },
  4514. // Param "o": JavaScript object
  4515. // Param "tab": tab or indent string for pretty output formatting omit or use empty string "" to supress.
  4516. // Returns: XML string
  4517. json2xml: function(o, tab) {
  4518. var toXml = function(v, name, ind) {
  4519. var xml = "";
  4520. var i, n;
  4521. if (v instanceof Array) {
  4522. if (v.length === 0) {
  4523. xml += ind + "<"+name+">__EMPTY_ARRAY_</"+name+">\n";
  4524. }
  4525. else {
  4526. for (i = 0, n = v.length; i < n; i += 1) {
  4527. var sXml = ind + toXml(v[i], name, ind+"\t") + "\n";
  4528. xml += sXml;
  4529. }
  4530. }
  4531. }
  4532. else if (typeof(v) === "object") {
  4533. var hasChild = false;
  4534. xml += ind + "<" + name;
  4535. var m;
  4536. for (m in v) if (v.hasOwnProperty(m)) {
  4537. if (m.charAt(0) === "@") {
  4538. xml += " " + m.substr(1) + "=\"" + v[m].toString() + "\"";
  4539. }
  4540. else {
  4541. hasChild = true;
  4542. }
  4543. }
  4544. xml += hasChild ? ">" : "/>";
  4545. if (hasChild) {
  4546. for (m in v) if (v.hasOwnProperty(m)) {
  4547. if (m === "#text") {
  4548. xml += v[m];
  4549. }
  4550. else if (m === "#cdata") {
  4551. xml += "<![CDATA[" + v[m] + "]]>";
  4552. }
  4553. else if (m.charAt(0) !== "@") {
  4554. xml += toXml(v[m], m, ind+"\t");
  4555. }
  4556. }
  4557. xml += (xml.charAt(xml.length - 1) === "\n" ? ind : "") + "</" + name + ">";
  4558. }
  4559. }
  4560. else if (typeof(v) === "function") {
  4561. xml += ind + "<" + name + ">" + "<![CDATA[" + v + "]]>" + "</" + name + ">";
  4562. }
  4563. else {
  4564. if (v === undefined ) { v = ""; }
  4565. if (v.toString() === "\"\"" || v.toString().length === 0) {
  4566. xml += ind + "<" + name + ">__EMPTY_STRING_</" + name + ">";
  4567. }
  4568. else {
  4569. xml += ind + "<" + name + ">" + v.toString() + "</" + name + ">";
  4570. }
  4571. }
  4572. return xml;
  4573. };
  4574. var xml = "";
  4575. var m;
  4576. for (m in o) if (o.hasOwnProperty(m)) {
  4577. xml += toXml(o[m], m, "");
  4578. }
  4579. return tab ? xml.replace(/\t/g, tab) : xml.replace(/\t|\n/g, "");
  4580. },
  4581. // Internal methods
  4582. toObj: function(xml) {
  4583. var o = {};
  4584. var FuncTest = /function/i;
  4585. if (xml.nodeType === 1) {
  4586. // element node ..
  4587. if (xml.attributes.length) {
  4588. // element with attributes ..
  4589. var i;
  4590. for (i = 0; i < xml.attributes.length; i += 1) {
  4591. o["@" + xml.attributes[i].nodeName] = (xml.attributes[i].nodeValue || "").toString();
  4592. }
  4593. }
  4594. if (xml.firstChild) {
  4595. // element has child nodes ..
  4596. var textChild = 0, cdataChild = 0, hasElementChild = false;
  4597. var n;
  4598. for (n = xml.firstChild; n; n = n.nextSibling) {
  4599. if (n.nodeType === 1) {
  4600. hasElementChild = true;
  4601. }
  4602. else if (n.nodeType === 3 && n.nodeValue.match(/[^ \f\n\r\t\v]/)) {
  4603. // non-whitespace text
  4604. textChild += 1;
  4605. }
  4606. else if (n.nodeType === 4) {
  4607. // cdata section node
  4608. cdataChild += 1;
  4609. }
  4610. }
  4611. if (hasElementChild) {
  4612. if (textChild < 2 && cdataChild < 2) {
  4613. // structured element with evtl. a single text or/and cdata node ..
  4614. this.removeWhite(xml);
  4615. for (n = xml.firstChild; n; n = n.nextSibling) {
  4616. if (n.nodeType === 3) {
  4617. // text node
  4618. o["#text"] = this.escape(n.nodeValue);
  4619. }
  4620. else if (n.nodeType === 4) {
  4621. // cdata node
  4622. if (FuncTest.test(n.nodeValue)) {
  4623. o[n.nodeName] = [o[n.nodeName], n.nodeValue];
  4624. } else {
  4625. o["#cdata"] = this.escape(n.nodeValue);
  4626. }
  4627. }
  4628. else if (o[n.nodeName]) {
  4629. // multiple occurence of element ..
  4630. if (o[n.nodeName] instanceof Array) {
  4631. o[n.nodeName][o[n.nodeName].length] = this.toObj(n);
  4632. }
  4633. else {
  4634. o[n.nodeName] = [o[n.nodeName], this.toObj(n)];
  4635. }
  4636. }
  4637. else {
  4638. // first occurence of element ..
  4639. o[n.nodeName] = this.toObj(n);
  4640. }
  4641. }
  4642. }
  4643. else {
  4644. // mixed content
  4645. if (!xml.attributes.length) {
  4646. o = this.escape(this.innerXml(xml));
  4647. }
  4648. else {
  4649. o["#text"] = this.escape(this.innerXml(xml));
  4650. }
  4651. }
  4652. }
  4653. else if (textChild) {
  4654. // pure text
  4655. if (!xml.attributes.length) {
  4656. o = this.escape(this.innerXml(xml));
  4657. if (o === "__EMPTY_ARRAY_") {
  4658. o = "[]";
  4659. } else if (o === "__EMPTY_STRING_") {
  4660. o = "";
  4661. }
  4662. }
  4663. else {
  4664. o["#text"] = this.escape(this.innerXml(xml));
  4665. }
  4666. }
  4667. else if (cdataChild) {
  4668. // cdata
  4669. if (cdataChild > 1) {
  4670. o = this.escape(this.innerXml(xml));
  4671. }
  4672. else {
  4673. for (n = xml.firstChild; n; n = n.nextSibling) {
  4674. if(FuncTest.test(xml.firstChild.nodeValue)) {
  4675. o = xml.firstChild.nodeValue;
  4676. break;
  4677. } else {
  4678. o["#cdata"] = this.escape(n.nodeValue);
  4679. }
  4680. }
  4681. }
  4682. }
  4683. }
  4684. if (!xml.attributes.length && !xml.firstChild) {
  4685. o = null;
  4686. }
  4687. }
  4688. else if (xml.nodeType === 9) {
  4689. // document.node
  4690. o = this.toObj(xml.documentElement);
  4691. }
  4692. else {
  4693. alert("unhandled node type: " + xml.nodeType);
  4694. }
  4695. return o;
  4696. },
  4697. toJson: function(o, name, ind, wellform) {
  4698. if(wellform === undefined) wellform = true;
  4699. var json = name ? ("\"" + name + "\"") : "", tab = "\t", newline = "\n";
  4700. if(!wellform) {
  4701. tab= ""; newline= "";
  4702. }
  4703. if (o === "[]") {
  4704. json += (name ? ":[]" : "[]");
  4705. }
  4706. else if (o instanceof Array) {
  4707. var n, i, ar=[];
  4708. for (i = 0, n = o.length; i < n; i += 1) {
  4709. ar[i] = this.toJson(o[i], "", ind + tab, wellform);
  4710. }
  4711. json += (name ? ":[" : "[") + (ar.length > 1 ? (newline + ind + tab + ar.join(","+newline + ind + tab) + newline + ind) : ar.join("")) + "]";
  4712. }
  4713. else if (o === null) {
  4714. json += (name && ":") + "null";
  4715. }
  4716. else if (typeof(o) === "object") {
  4717. var arr = [], m;
  4718. for (m in o) {
  4719. if (o.hasOwnProperty(m)) {
  4720. arr[arr.length] = this.toJson(o[m], m, ind + tab, wellform);
  4721. }
  4722. }
  4723. json += (name ? ":{" : "{") + (arr.length > 1 ? (newline + ind + tab + arr.join(","+newline + ind + tab) + newline + ind) : arr.join("")) + "}";
  4724. }
  4725. else if (typeof(o) === "string") {
  4726. /*
  4727. var objRegExp = /(^-?\d+\.?\d*$)/;
  4728. var FuncTest = /function/i;
  4729. var os = o.toString();
  4730. if (objRegExp.test(os) || FuncTest.test(os) || os==="false" || os==="true") {
  4731. // int or float
  4732. json += (name && ":") + "\"" +os + "\"";
  4733. }
  4734. else {
  4735. */
  4736. json += (name && ":") + "\"" + o.replace(/\\/g,'\\\\').replace(/\"/g,'\\"') + "\"";
  4737. //}
  4738. }
  4739. else {
  4740. json += (name && ":") + o.toString();
  4741. }
  4742. return json;
  4743. },
  4744. innerXml: function(node) {
  4745. var s = "";
  4746. if ("innerHTML" in node) {
  4747. s = node.innerHTML;
  4748. }
  4749. else {
  4750. var asXml = function(n) {
  4751. var s = "", i;
  4752. if (n.nodeType === 1) {
  4753. s += "<" + n.nodeName;
  4754. for (i = 0; i < n.attributes.length; i += 1) {
  4755. s += " " + n.attributes[i].nodeName + "=\"" + (n.attributes[i].nodeValue || "").toString() + "\"";
  4756. }
  4757. if (n.firstChild) {
  4758. s += ">";
  4759. for (var c = n.firstChild; c; c = c.nextSibling) {
  4760. s += asXml(c);
  4761. }
  4762. s += "</" + n.nodeName + ">";
  4763. }
  4764. else {
  4765. s += "/>";
  4766. }
  4767. }
  4768. else if (n.nodeType === 3) {
  4769. s += n.nodeValue;
  4770. }
  4771. else if (n.nodeType === 4) {
  4772. s += "<![CDATA[" + n.nodeValue + "]]>";
  4773. }
  4774. return s;
  4775. };
  4776. for (var c = node.firstChild; c; c = c.nextSibling) {
  4777. s += asXml(c);
  4778. }
  4779. }
  4780. return s;
  4781. },
  4782. escape: function(txt) {
  4783. return txt.replace(/[\\]/g, "\\\\").replace(/[\"]/g, '\\"').replace(/[\n]/g, '\\n').replace(/[\r]/g, '\\r');
  4784. },
  4785. removeWhite: function(e) {
  4786. e.normalize();
  4787. var n;
  4788. for (n = e.firstChild; n; ) {
  4789. if (n.nodeType === 3) {
  4790. // text node
  4791. if (!n.nodeValue.match(/[^ \f\n\r\t\v]/)) {
  4792. // pure whitespace text node
  4793. var nxt = n.nextSibling;
  4794. e.removeChild(n);
  4795. n = nxt;
  4796. }
  4797. else {
  4798. n = n.nextSibling;
  4799. }
  4800. }
  4801. else if (n.nodeType === 1) {
  4802. // element node
  4803. this.removeWhite(n);
  4804. n = n.nextSibling;
  4805. }
  4806. else {
  4807. // any other node
  4808. n = n.nextSibling;
  4809. }
  4810. }
  4811. return e;
  4812. }
  4813. };/*
  4814. **
  4815. * formatter for values but most of the values if for jqGrid
  4816. * Some of this was inspired and based on how YUI does the table datagrid but in jQuery fashion
  4817. * we are trying to keep it as light as possible
  4818. * Joshua Burnett josh@9ci.com
  4819. * http://www.greenbill.com
  4820. *
  4821. * Changes from Tony Tomov tony@trirand.com
  4822. * Dual licensed under the MIT and GPL licenses:
  4823. * http://www.opensource.org/licenses/mit-license.php
  4824. * http://www.gnu.org/licenses/gpl-2.0.html
  4825. *
  4826. **/
  4827. /*jshint eqeqeq:false */
  4828. /*global jQuery */
  4829. (function($) {
  4830. "use strict";
  4831. $.fmatter = {};
  4832. //opts can be id:row id for the row, rowdata:the data for the row, colmodel:the column model for this column
  4833. //example {id:1234,}
  4834. $.extend($.fmatter,{
  4835. isBoolean : function(o) {
  4836. return typeof o === 'boolean';
  4837. },
  4838. isObject : function(o) {
  4839. return (o && (typeof o === 'object' || $.isFunction(o))) || false;
  4840. },
  4841. isString : function(o) {
  4842. return typeof o === 'string';
  4843. },
  4844. isNumber : function(o) {
  4845. return typeof o === 'number' && isFinite(o);
  4846. },
  4847. isNull : function(o) {
  4848. return o === null;
  4849. },
  4850. isUndefined : function(o) {
  4851. return o === undefined;
  4852. },
  4853. isValue : function (o) {
  4854. return (this.isObject(o) || this.isString(o) || this.isNumber(o) || this.isBoolean(o));
  4855. },
  4856. isEmpty : function(o) {
  4857. if(!this.isString(o) && this.isValue(o)) {
  4858. return false;
  4859. }
  4860. if (!this.isValue(o)){
  4861. return true;
  4862. }
  4863. o = $.trim(o).replace(/\&nbsp\;/ig,'').replace(/\&#160\;/ig,'');
  4864. return o==="";
  4865. }
  4866. });
  4867. $.fn.fmatter = function(formatType, cellval, opts, rwd, act) {
  4868. // build main options before element iteration
  4869. var v=cellval;
  4870. opts = $.extend({}, $.jgrid.formatter, opts);
  4871. try {
  4872. v = $.fn.fmatter[formatType].call(this, cellval, opts, rwd, act);
  4873. } catch(fe){}
  4874. return v;
  4875. };
  4876. $.fmatter.util = {
  4877. // Taken from YAHOO utils
  4878. NumberFormat : function(nData,opts) {
  4879. if(!$.fmatter.isNumber(nData)) {
  4880. nData *= 1;
  4881. }
  4882. if($.fmatter.isNumber(nData)) {
  4883. var bNegative = (nData < 0);
  4884. var sOutput = String(nData);
  4885. var sDecimalSeparator = opts.decimalSeparator || ".";
  4886. var nDotIndex;
  4887. if($.fmatter.isNumber(opts.decimalPlaces)) {
  4888. // Round to the correct decimal place
  4889. var nDecimalPlaces = opts.decimalPlaces;
  4890. var nDecimal = Math.pow(10, nDecimalPlaces);
  4891. sOutput = String(Math.round(nData*nDecimal)/nDecimal);
  4892. nDotIndex = sOutput.lastIndexOf(".");
  4893. if(nDecimalPlaces > 0) {
  4894. // Add the decimal separator
  4895. if(nDotIndex < 0) {
  4896. sOutput += sDecimalSeparator;
  4897. nDotIndex = sOutput.length-1;
  4898. }
  4899. // Replace the "."
  4900. else if(sDecimalSeparator !== "."){
  4901. sOutput = sOutput.replace(".",sDecimalSeparator);
  4902. }
  4903. // Add missing zeros
  4904. while((sOutput.length - 1 - nDotIndex) < nDecimalPlaces) {
  4905. sOutput += "0";
  4906. }
  4907. }
  4908. }
  4909. if(opts.thousandsSeparator) {
  4910. var sThousandsSeparator = opts.thousandsSeparator;
  4911. nDotIndex = sOutput.lastIndexOf(sDecimalSeparator);
  4912. nDotIndex = (nDotIndex > -1) ? nDotIndex : sOutput.length;
  4913. var sNewOutput = sOutput.substring(nDotIndex);
  4914. var nCount = -1, i;
  4915. for (i=nDotIndex; i>0; i--) {
  4916. nCount++;
  4917. if ((nCount%3 === 0) && (i !== nDotIndex) && (!bNegative || (i > 1))) {
  4918. sNewOutput = sThousandsSeparator + sNewOutput;
  4919. }
  4920. sNewOutput = sOutput.charAt(i-1) + sNewOutput;
  4921. }
  4922. sOutput = sNewOutput;
  4923. }
  4924. // Prepend prefix
  4925. sOutput = (opts.prefix) ? opts.prefix + sOutput : sOutput;
  4926. // Append suffix
  4927. sOutput = (opts.suffix) ? sOutput + opts.suffix : sOutput;
  4928. return sOutput;
  4929. }
  4930. return nData;
  4931. },
  4932. // Tony Tomov
  4933. // PHP implementation. Sorry not all options are supported.
  4934. // Feel free to add them if you want
  4935. DateFormat : function (format, date, newformat, opts) {
  4936. var token = /\\.|[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]/g,
  4937. timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
  4938. timezoneClip = /[^-+\dA-Z]/g,
  4939. msDateRegExp = new RegExp("^\/Date\\((([-+])?[0-9]+)(([-+])([0-9]{2})([0-9]{2}))?\\)\/$"),
  4940. msMatch = ((typeof date === 'string') ? date.match(msDateRegExp): null),
  4941. pad = function (value, length) {
  4942. value = String(value);
  4943. length = parseInt(length,10) || 2;
  4944. while (value.length < length) { value = '0' + value; }
  4945. return value;
  4946. },
  4947. ts = {m : 1, d : 1, y : 1970, h : 0, i : 0, s : 0, u:0},
  4948. timestamp=0, dM, k,hl,
  4949. dateFormat=["i18n"];
  4950. // Internationalization strings
  4951. dateFormat.i18n = {
  4952. dayNames: opts.dayNames,
  4953. monthNames: opts.monthNames
  4954. };
  4955. if( opts.masks.hasOwnProperty(format) ) { format = opts.masks[format]; }
  4956. if( !isNaN( date - 0 ) && String(format).toLowerCase() == "u") {
  4957. //Unix timestamp
  4958. timestamp = new Date( parseFloat(date)*1000 );
  4959. } else if(date.constructor === Date) {
  4960. timestamp = date;
  4961. // Microsoft date format support
  4962. } else if( msMatch !== null ) {
  4963. timestamp = new Date(parseInt(msMatch[1], 10));
  4964. if (msMatch[3]) {
  4965. var offset = Number(msMatch[5]) * 60 + Number(msMatch[6]);
  4966. offset *= ((msMatch[4] == '-') ? 1 : -1);
  4967. offset -= timestamp.getTimezoneOffset();
  4968. timestamp.setTime(Number(Number(timestamp) + (offset * 60 * 1000)));
  4969. }
  4970. } else {
  4971. date = String(date).split(/[\\\/:_;.,\t\T\s-]/);
  4972. format = format.split(/[\\\/:_;.,\t\T\s-]/);
  4973. // parsing for month names
  4974. for(k=0,hl=format.length;k<hl;k++){
  4975. if(format[k] == 'M') {
  4976. dM = $.inArray(date[k],dateFormat.i18n.monthNames);
  4977. if(dM !== -1 && dM < 12){date[k] = dM+1;}
  4978. }
  4979. if(format[k] == 'F') {
  4980. dM = $.inArray(date[k],dateFormat.i18n.monthNames);
  4981. if(dM !== -1 && dM > 11){date[k] = dM+1-12;}
  4982. }
  4983. if(date[k]) {
  4984. ts[format[k].toLowerCase()] = parseInt(date[k],10);
  4985. }
  4986. }
  4987. if(ts.f) {ts.m = ts.f;}
  4988. if( ts.m === 0 && ts.y === 0 && ts.d === 0) {
  4989. return "&#160;" ;
  4990. }
  4991. ts.m = parseInt(ts.m,10)-1;
  4992. var ty = ts.y;
  4993. if (ty >= 70 && ty <= 99) {ts.y = 1900+ts.y;}
  4994. else if (ty >=0 && ty <=69) {ts.y= 2000+ts.y;}
  4995. timestamp = new Date(ts.y, ts.m, ts.d, ts.h, ts.i, ts.s, ts.u);
  4996. }
  4997. if( opts.masks.hasOwnProperty(newformat) ) {
  4998. newformat = opts.masks[newformat];
  4999. } else if ( !newformat ) {
  5000. newformat = 'Y-m-d';
  5001. }
  5002. var
  5003. G = timestamp.getHours(),
  5004. i = timestamp.getMinutes(),
  5005. j = timestamp.getDate(),
  5006. n = timestamp.getMonth() + 1,
  5007. o = timestamp.getTimezoneOffset(),
  5008. s = timestamp.getSeconds(),
  5009. u = timestamp.getMilliseconds(),
  5010. w = timestamp.getDay(),
  5011. Y = timestamp.getFullYear(),
  5012. N = (w + 6) % 7 + 1,
  5013. z = (new Date(Y, n - 1, j) - new Date(Y, 0, 1)) / 86400000,
  5014. flags = {
  5015. // Day
  5016. d: pad(j),
  5017. D: dateFormat.i18n.dayNames[w],
  5018. j: j,
  5019. l: dateFormat.i18n.dayNames[w + 7],
  5020. N: N,
  5021. S: opts.S(j),
  5022. //j < 11 || j > 13 ? ['st', 'nd', 'rd', 'th'][Math.min((j - 1) % 10, 3)] : 'th',
  5023. w: w,
  5024. z: z,
  5025. // Week
  5026. 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),
  5027. // Month
  5028. F: dateFormat.i18n.monthNames[n - 1 + 12],
  5029. m: pad(n),
  5030. M: dateFormat.i18n.monthNames[n - 1],
  5031. n: n,
  5032. t: '?',
  5033. // Year
  5034. L: '?',
  5035. o: '?',
  5036. Y: Y,
  5037. y: String(Y).substring(2),
  5038. // Time
  5039. a: G < 12 ? opts.AmPm[0] : opts.AmPm[1],
  5040. A: G < 12 ? opts.AmPm[2] : opts.AmPm[3],
  5041. B: '?',
  5042. g: G % 12 || 12,
  5043. G: G,
  5044. h: pad(G % 12 || 12),
  5045. H: pad(G),
  5046. i: pad(i),
  5047. s: pad(s),
  5048. u: u,
  5049. // Timezone
  5050. e: '?',
  5051. I: '?',
  5052. O: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
  5053. P: '?',
  5054. T: (String(timestamp).match(timezone) || [""]).pop().replace(timezoneClip, ""),
  5055. Z: '?',
  5056. // Full Date/Time
  5057. c: '?',
  5058. r: '?',
  5059. U: Math.floor(timestamp / 1000)
  5060. };
  5061. return newformat.replace(token, function ($0) {
  5062. return flags.hasOwnProperty($0) ? flags[$0] : $0.substring(1);
  5063. });
  5064. }
  5065. };
  5066. $.fn.fmatter.defaultFormat = function(cellval, opts) {
  5067. return ($.fmatter.isValue(cellval) && cellval!=="" ) ? cellval : opts.defaultValue || "&#160;";
  5068. };
  5069. $.fn.fmatter.email = function(cellval, opts) {
  5070. if(!$.fmatter.isEmpty(cellval)) {
  5071. return "<a href=\"mailto:" + cellval + "\">" + cellval + "</a>";
  5072. }
  5073. return $.fn.fmatter.defaultFormat(cellval,opts );
  5074. };
  5075. $.fn.fmatter.checkbox =function(cval, opts) {
  5076. var op = $.extend({},opts.checkbox), ds;
  5077. if(opts.colModel !== undefined && !$.fmatter.isUndefined(opts.colModel.formatoptions)) {
  5078. op = $.extend({},op,opts.colModel.formatoptions);
  5079. }
  5080. if(op.disabled===true) {ds = "disabled=\"disabled\"";} else {ds="";}
  5081. if($.fmatter.isEmpty(cval) || $.fmatter.isUndefined(cval) ) {cval = $.fn.fmatter.defaultFormat(cval,op);}
  5082. cval=String(cval);
  5083. cval=cval.toLowerCase();
  5084. var bchk = cval.search(/(false|0|no|n|off)/i)<0 ? " checked='checked' " : "";
  5085. return "<input type=\"checkbox\" " + bchk + " value=\""+ cval+"\" offval=\"no\" "+ds+ "/>";
  5086. };
  5087. $.fn.fmatter.link = function(cellval, opts) {
  5088. var op = {target:opts.target};
  5089. var target = "";
  5090. if(opts.colModel !== undefined && !$.fmatter.isUndefined(opts.colModel.formatoptions)) {
  5091. op = $.extend({},op,opts.colModel.formatoptions);
  5092. }
  5093. if(op.target) {target = 'target=' + op.target;}
  5094. if(!$.fmatter.isEmpty(cellval)) {
  5095. return "<a "+target+" href=\"" + cellval + "\">" + cellval + "</a>";
  5096. }
  5097. return $.fn.fmatter.defaultFormat(cellval,opts);
  5098. };
  5099. $.fn.fmatter.showlink = function(cellval, opts) {
  5100. var op = {baseLinkUrl: opts.baseLinkUrl,showAction:opts.showAction, addParam: opts.addParam || "", target: opts.target, idName: opts.idName},
  5101. target = "", idUrl;
  5102. if(opts.colModel !== undefined && !$.fmatter.isUndefined(opts.colModel.formatoptions)) {
  5103. op = $.extend({},op,opts.colModel.formatoptions);
  5104. }
  5105. if(op.target) {target = 'target=' + op.target;}
  5106. idUrl = op.baseLinkUrl+op.showAction + '?'+ op.idName+'='+opts.rowId+op.addParam;
  5107. if($.fmatter.isString(cellval) || $.fmatter.isNumber(cellval)) { //add this one even if its blank string
  5108. return "<a "+target+" href=\"" + idUrl + "\">" + cellval + "</a>";
  5109. }
  5110. return $.fn.fmatter.defaultFormat(cellval,opts);
  5111. };
  5112. $.fn.fmatter.integer = function(cellval, opts) {
  5113. var op = $.extend({},opts.integer);
  5114. if(opts.colModel !== undefined && !$.fmatter.isUndefined(opts.colModel.formatoptions)) {
  5115. op = $.extend({},op,opts.colModel.formatoptions);
  5116. }
  5117. if($.fmatter.isEmpty(cellval)) {
  5118. return op.defaultValue;
  5119. }
  5120. return $.fmatter.util.NumberFormat(cellval,op);
  5121. };
  5122. $.fn.fmatter.number = function (cellval, opts) {
  5123. var op = $.extend({},opts.number);
  5124. if(opts.colModel !== undefined && !$.fmatter.isUndefined(opts.colModel.formatoptions)) {
  5125. op = $.extend({},op,opts.colModel.formatoptions);
  5126. }
  5127. if($.fmatter.isEmpty(cellval)) {
  5128. return op.defaultValue;
  5129. }
  5130. return $.fmatter.util.NumberFormat(cellval,op);
  5131. };
  5132. $.fn.fmatter.currency = function (cellval, opts) {
  5133. var op = $.extend({},opts.currency);
  5134. if(opts.colModel !== undefined && !$.fmatter.isUndefined(opts.colModel.formatoptions)) {
  5135. op = $.extend({},op,opts.colModel.formatoptions);
  5136. }
  5137. if($.fmatter.isEmpty(cellval)) {
  5138. return op.defaultValue;
  5139. }
  5140. return $.fmatter.util.NumberFormat(cellval,op);
  5141. };
  5142. $.fn.fmatter.date = function (cellval, opts, rwd, act) {
  5143. var op = $.extend({},opts.date);
  5144. if(opts.colModel !== undefined && !$.fmatter.isUndefined(opts.colModel.formatoptions)) {
  5145. op = $.extend({},op,opts.colModel.formatoptions);
  5146. }
  5147. if(!op.reformatAfterEdit && act=='edit'){
  5148. return $.fn.fmatter.defaultFormat(cellval, opts);
  5149. }
  5150. if(!$.fmatter.isEmpty(cellval)) {
  5151. return $.fmatter.util.DateFormat(op.srcformat,cellval,op.newformat,op);
  5152. }
  5153. return $.fn.fmatter.defaultFormat(cellval, opts);
  5154. };
  5155. $.fn.fmatter.select = function (cellval,opts) {
  5156. // jqGrid specific
  5157. cellval = String(cellval);
  5158. var oSelect = false, ret=[], sep, delim;
  5159. if(!$.fmatter.isUndefined(opts.colModel.formatoptions)){
  5160. oSelect= opts.colModel.formatoptions.value;
  5161. sep = opts.colModel.formatoptions.separator === undefined ? ":" : opts.colModel.formatoptions.separator;
  5162. delim = opts.colModel.formatoptions.delimiter === undefined ? ";" : opts.colModel.formatoptions.delimiter;
  5163. } else if(!$.fmatter.isUndefined(opts.colModel.editoptions)){
  5164. oSelect= opts.colModel.editoptions.value;
  5165. sep = opts.colModel.editoptions.separator === undefined ? ":" : opts.colModel.editoptions.separator;
  5166. delim = opts.colModel.editoptions.delimiter === undefined ? ";" : opts.colModel.editoptions.delimiter;
  5167. }
  5168. if (oSelect) {
  5169. var msl = opts.colModel.editoptions.multiple === true ? true : false,
  5170. scell = [], sv;
  5171. if(msl) {scell = cellval.split(",");scell = $.map(scell,function(n){return $.trim(n);});}
  5172. if ($.fmatter.isString(oSelect)) {
  5173. // mybe here we can use some caching with care ????
  5174. var so = oSelect.split(delim), j=0, i;
  5175. for(i=0; i<so.length;i++){
  5176. sv = so[i].split(sep);
  5177. if(sv.length > 2 ) {
  5178. sv[1] = $.map(sv,function(n,i){if(i>0) {return n;}}).join(sep);
  5179. }
  5180. if(msl) {
  5181. if($.inArray(sv[0],scell)>-1) {
  5182. ret[j] = sv[1];
  5183. j++;
  5184. }
  5185. } else if($.trim(sv[0])==$.trim(cellval)) {
  5186. ret[0] = sv[1];
  5187. break;
  5188. }
  5189. }
  5190. } else if($.fmatter.isObject(oSelect)) {
  5191. // this is quicker
  5192. if(msl) {
  5193. ret = $.map(scell, function(n){
  5194. return oSelect[n];
  5195. });
  5196. } else {
  5197. ret[0] = oSelect[cellval] || "";
  5198. }
  5199. }
  5200. }
  5201. cellval = ret.join(", ");
  5202. return cellval === "" ? $.fn.fmatter.defaultFormat(cellval,opts) : cellval;
  5203. };
  5204. $.fn.fmatter.rowactions = function(act) {
  5205. var $tr = $(this).closest("tr.jqgrow"),
  5206. $actionsDiv = $(this).parent(),
  5207. rid = $tr.attr("id"),
  5208. $grid = $(this).closest("table.ui-jqgrid-btable"),
  5209. $t = $grid[0],
  5210. p = $t.p,
  5211. cm = p.colModel[$.jgrid.getCellIndex(this)],
  5212. op = {
  5213. keys: false,
  5214. onEdit: null,
  5215. onSuccess: null,
  5216. afterSave: null,
  5217. onError: null,
  5218. afterRestore: null,
  5219. extraparam: {},
  5220. url: null,
  5221. restoreAfterError: true,
  5222. mtype: "POST",
  5223. delOptions: {},
  5224. editOptions: {}
  5225. },
  5226. saverow = function(rowid, res) {
  5227. if($.isFunction(op.afterSave)) { op.afterSave.call($t, rowid, res); }
  5228. $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show();
  5229. $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide();
  5230. },
  5231. restorerow = function(rowid) {
  5232. if($.isFunction(op.afterRestore)) { op.afterRestore.call($t, rowid); }
  5233. $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show();
  5234. $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide();
  5235. };
  5236. if (!$.fmatter.isUndefined(cm.formatoptions)) {
  5237. op = $.extend(op,cm.formatoptions);
  5238. }
  5239. if (!$.fmatter.isUndefined(p.editOptions)) {
  5240. op.editOptions = p.editOptions;
  5241. }
  5242. if (!$.fmatter.isUndefined(p.delOptions)) {
  5243. op.delOptions = p.delOptions;
  5244. }
  5245. if ($tr.hasClass("jqgrid-new-row")){
  5246. op.extraparam[p.prmNames.oper] = p.prmNames.addoper;
  5247. }
  5248. var actop = {
  5249. keys: op.keys,
  5250. oneditfunc: op.onEdit,
  5251. successfunc: op.onSuccess,
  5252. url: op.url,
  5253. extraparam: op.extraparam,
  5254. aftersavefunc: saverow,
  5255. errorfunc: op.onError,
  5256. afterrestorefunc: restorerow,
  5257. restoreAfterError: op.restoreAfterError,
  5258. mtype: op.mtype
  5259. };
  5260. switch(act)
  5261. {
  5262. case 'edit':
  5263. $grid.jqGrid('editRow', rid, actop);
  5264. $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").hide();
  5265. $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").show();
  5266. $grid.triggerHandler("jqGridAfterGridComplete");
  5267. break;
  5268. case 'save':
  5269. if ($grid.jqGrid('saveRow', rid, actop)) {
  5270. $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show();
  5271. $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide();
  5272. $grid.triggerHandler("jqGridAfterGridComplete");
  5273. }
  5274. break;
  5275. case 'cancel' :
  5276. $grid.jqGrid('restoreRow', rid, restorerow);
  5277. $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show();
  5278. $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide();
  5279. $grid.triggerHandler("jqGridAfterGridComplete");
  5280. break;
  5281. case 'del':
  5282. $grid.jqGrid('delGridRow', rid, op.delOptions);
  5283. break;
  5284. case 'formedit':
  5285. $grid.jqGrid('setSelection', rid);
  5286. $grid.jqGrid('editGridRow', rid, op.editOptions);
  5287. break;
  5288. }
  5289. };
  5290. $.fn.fmatter.actions = function(cellval,opts) {
  5291. var op={keys:false, editbutton:true, delbutton:true, editformbutton: false},
  5292. rowid=opts.rowId, str="",ocl;
  5293. if(!$.fmatter.isUndefined(opts.colModel.formatoptions)) {
  5294. op = $.extend(op,opts.colModel.formatoptions);
  5295. }
  5296. if(rowid === undefined || $.fmatter.isEmpty(rowid)) {return "";}
  5297. if(op.editformbutton){
  5298. ocl = "onclick=jQuery.fn.fmatter.rowactions.call(this,'formedit'); onmouseover=jQuery(this).addClass('ui-state-hover'); onmouseout=jQuery(this).removeClass('ui-state-hover'); ";
  5299. str += "<div title='"+$.jgrid.nav.edittitle+"' style='float:left;cursor:pointer;' class='ui-pg-div ui-inline-edit' "+ocl+"><span class='ui-icon ui-icon-pencil'></span></div>";
  5300. } else if(op.editbutton){
  5301. ocl = "onclick=jQuery.fn.fmatter.rowactions.call(this,'edit'); onmouseover=jQuery(this).addClass('ui-state-hover'); onmouseout=jQuery(this).removeClass('ui-state-hover') ";
  5302. str += "<div title='"+$.jgrid.nav.edittitle+"' style='float:left;cursor:pointer;' class='ui-pg-div ui-inline-edit' "+ocl+"><span class='ui-icon ui-icon-pencil'></span></div>";
  5303. }
  5304. if(op.delbutton) {
  5305. ocl = "onclick=jQuery.fn.fmatter.rowactions.call(this,'del'); onmouseover=jQuery(this).addClass('ui-state-hover'); onmouseout=jQuery(this).removeClass('ui-state-hover'); ";
  5306. str += "<div title='"+$.jgrid.nav.deltitle+"' style='float:left;margin-left:5px;' class='ui-pg-div ui-inline-del' "+ocl+"><span class='ui-icon ui-icon-trash'></span></div>";
  5307. }
  5308. ocl = "onclick=jQuery.fn.fmatter.rowactions.call(this,'save'); onmouseover=jQuery(this).addClass('ui-state-hover'); onmouseout=jQuery(this).removeClass('ui-state-hover'); ";
  5309. str += "<div title='"+$.jgrid.edit.bSubmit+"' style='float:left;display:none' class='ui-pg-div ui-inline-save' "+ocl+"><span class='ui-icon ui-icon-disk'></span></div>";
  5310. ocl = "onclick=jQuery.fn.fmatter.rowactions.call(this,'cancel'); onmouseover=jQuery(this).addClass('ui-state-hover'); onmouseout=jQuery(this).removeClass('ui-state-hover'); ";
  5311. str += "<div title='"+$.jgrid.edit.bCancel+"' style='float:left;display:none;margin-left:5px;' class='ui-pg-div ui-inline-cancel' "+ocl+"><span class='ui-icon ui-icon-cancel'></span></div>";
  5312. return "<div style='margin-left:8px;'>" + str + "</div>";
  5313. };
  5314. $.unformat = function (cellval,options,pos,cnt) {
  5315. // specific for jqGrid only
  5316. var ret, formatType = options.colModel.formatter,
  5317. op =options.colModel.formatoptions || {}, sep,
  5318. re = /([\.\*\_\'\(\)\{\}\+\?\\])/g,
  5319. unformatFunc = options.colModel.unformat||($.fn.fmatter[formatType] && $.fn.fmatter[formatType].unformat);
  5320. if(unformatFunc !== undefined && $.isFunction(unformatFunc) ) {
  5321. ret = unformatFunc.call(this, $(cellval).text(), options, cellval);
  5322. } else if(!$.fmatter.isUndefined(formatType) && $.fmatter.isString(formatType) ) {
  5323. var opts = $.jgrid.formatter || {}, stripTag;
  5324. switch(formatType) {
  5325. case 'integer' :
  5326. op = $.extend({},opts.integer,op);
  5327. sep = op.thousandsSeparator.replace(re,"\\$1");
  5328. stripTag = new RegExp(sep, "g");
  5329. ret = $(cellval).text().replace(stripTag,'');
  5330. break;
  5331. case 'number' :
  5332. op = $.extend({},opts.number,op);
  5333. sep = op.thousandsSeparator.replace(re,"\\$1");
  5334. stripTag = new RegExp(sep, "g");
  5335. ret = $(cellval).text().replace(stripTag,"").replace(op.decimalSeparator,'.');
  5336. break;
  5337. case 'currency':
  5338. op = $.extend({},opts.currency,op);
  5339. sep = op.thousandsSeparator.replace(re,"\\$1");
  5340. stripTag = new RegExp(sep, "g");
  5341. ret = $(cellval).text();
  5342. if (op.prefix && op.prefix.length) {
  5343. ret = ret.substr(op.prefix.length);
  5344. }
  5345. if (op.suffix && op.suffix.length) {
  5346. ret = ret.substr(0, ret.length - op.suffix.length);
  5347. }
  5348. ret = ret.replace(stripTag,'').replace(op.decimalSeparator,'.');
  5349. break;
  5350. case 'checkbox':
  5351. var cbv = (options.colModel.editoptions) ? options.colModel.editoptions.value.split(":") : ["Yes","No"];
  5352. ret = $('input',cellval).is(":checked") ? cbv[0] : cbv[1];
  5353. break;
  5354. case 'select' :
  5355. ret = $.unformat.select(cellval,options,pos,cnt);
  5356. break;
  5357. case 'actions':
  5358. return "";
  5359. default:
  5360. ret= $(cellval).text();
  5361. }
  5362. }
  5363. return ret !== undefined ? ret : cnt===true ? $(cellval).text() : $.jgrid.htmlDecode($(cellval).html());
  5364. };
  5365. $.unformat.select = function (cellval,options,pos,cnt) {
  5366. // Spacial case when we have local data and perform a sort
  5367. // cnt is set to true only in sortDataArray
  5368. var ret = [];
  5369. var cell = $(cellval).text();
  5370. if(cnt===true) {return cell;}
  5371. var op = $.extend({}, !$.fmatter.isUndefined(options.colModel.formatoptions) ? options.colModel.formatoptions: options.colModel.editoptions),
  5372. sep = op.separator === undefined ? ":" : op.separator,
  5373. delim = op.delimiter === undefined ? ";" : op.delimiter;
  5374. if(op.value){
  5375. var oSelect = op.value,
  5376. msl = op.multiple === true ? true : false,
  5377. scell = [], sv;
  5378. if(msl) {scell = cell.split(",");scell = $.map(scell,function(n){return $.trim(n);});}
  5379. if ($.fmatter.isString(oSelect)) {
  5380. var so = oSelect.split(delim), j=0, i;
  5381. for(i=0; i<so.length;i++){
  5382. sv = so[i].split(sep);
  5383. if(sv.length > 2 ) {
  5384. sv[1] = $.map(sv,function(n,i){if(i>0) {return n;}}).join(sep);
  5385. }
  5386. if(msl) {
  5387. if($.inArray(sv[1],scell)>-1) {
  5388. ret[j] = sv[0];
  5389. j++;
  5390. }
  5391. } else if($.trim(sv[1])==$.trim(cell)) {
  5392. ret[0] = sv[0];
  5393. break;
  5394. }
  5395. }
  5396. } else if($.fmatter.isObject(oSelect) || $.isArray(oSelect) ){
  5397. if(!msl) {scell[0] = cell;}
  5398. ret = $.map(scell, function(n){
  5399. var rv;
  5400. $.each(oSelect, function(i,val){
  5401. if (val == n) {
  5402. rv = i;
  5403. return false;
  5404. }
  5405. });
  5406. if( rv !== undefined ) {return rv;}
  5407. });
  5408. }
  5409. return ret.join(", ");
  5410. }
  5411. return cell || "";
  5412. };
  5413. $.unformat.date = function (cellval, opts) {
  5414. var op = $.jgrid.formatter.date || {};
  5415. if(!$.fmatter.isUndefined(opts.formatoptions)) {
  5416. op = $.extend({},op,opts.formatoptions);
  5417. }
  5418. if(!$.fmatter.isEmpty(cellval)) {
  5419. return $.fmatter.util.DateFormat(op.newformat,cellval,op.srcformat,op);
  5420. }
  5421. return $.fn.fmatter.defaultFormat(cellval, opts);
  5422. };
  5423. })(jQuery);
  5424. /*jshint eqeqeq:false */
  5425. /*global jQuery */
  5426. (function($){
  5427. /*
  5428. * jqGrid common function
  5429. * Tony Tomov tony@trirand.com
  5430. * http://trirand.com/blog/
  5431. * Dual licensed under the MIT and GPL licenses:
  5432. * http://www.opensource.org/licenses/mit-license.php
  5433. * http://www.gnu.org/licenses/gpl-2.0.html
  5434. */
  5435. "use strict";
  5436. $.extend($.jgrid,{
  5437. // Modal functions
  5438. showModal : function(h) {
  5439. h.w.show();
  5440. },
  5441. closeModal : function(h) {
  5442. h.w.hide().attr("aria-hidden","true");
  5443. if(h.o) {h.o.remove();}
  5444. },
  5445. hideModal : function (selector,o) {
  5446. o = $.extend({jqm : true, gb :''}, o || {});
  5447. if(o.onClose) {
  5448. var oncret = o.gb && typeof o.gb === "string" && o.gb.substr(0,6) === "#gbox_" ? o.onClose.call($("#" + o.gb.substr(6))[0], selector) : o.onClose(selector);
  5449. if (typeof oncret === 'boolean' && !oncret ) { return; }
  5450. }
  5451. if ($.fn.jqm && o.jqm === true) {
  5452. $(selector).attr("aria-hidden","true").jqmHide();
  5453. } else {
  5454. if(o.gb !== '') {
  5455. try {$(".jqgrid-overlay:first",o.gb).hide();} catch (e){}
  5456. }
  5457. $(selector).hide().attr("aria-hidden","true");
  5458. }
  5459. },
  5460. //Helper functions
  5461. findPos : function(obj) {
  5462. var curleft = 0, curtop = 0;
  5463. if (obj.offsetParent) {
  5464. do {
  5465. curleft += obj.offsetLeft;
  5466. curtop += obj.offsetTop;
  5467. } while (obj = obj.offsetParent);
  5468. //do not change obj == obj.offsetParent
  5469. }
  5470. return [curleft,curtop];
  5471. },
  5472. createModal : function(aIDs, content, p, insertSelector, posSelector, appendsel, css) {
  5473. p = $.extend(true, {}, $.jgrid.jqModal || {}, p);
  5474. var mw = document.createElement('div'), rtlsup, self = this;
  5475. css = $.extend({}, css || {});
  5476. rtlsup = $(p.gbox).attr("dir") == "rtl" ? true : false;
  5477. mw.className= "ui-widget ui-widget-content ui-corner-all ui-jqdialog";
  5478. mw.id = aIDs.themodal;
  5479. var mh = document.createElement('div');
  5480. mh.className = "ui-jqdialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix";
  5481. mh.id = aIDs.modalhead;
  5482. $(mh).append("<span class='ui-jqdialog-title'>"+p.caption+"</span>");
  5483. var ahr= $("<a href='javascript:void(0)' class='ui-jqdialog-titlebar-close ui-corner-all'></a>")
  5484. .hover(function(){ahr.addClass('ui-state-hover');},
  5485. function(){ahr.removeClass('ui-state-hover');})
  5486. .append("<span class='ui-icon ui-icon-closethick'></span>");
  5487. $(mh).append(ahr);
  5488. if(rtlsup) {
  5489. mw.dir = "rtl";
  5490. $(".ui-jqdialog-title",mh).css("float","right");
  5491. $(".ui-jqdialog-titlebar-close",mh).css("left",0.3+"em");
  5492. } else {
  5493. mw.dir = "ltr";
  5494. $(".ui-jqdialog-title",mh).css("float","left");
  5495. $(".ui-jqdialog-titlebar-close",mh).css("right",0.3+"em");
  5496. }
  5497. var mc = document.createElement('div');
  5498. $(mc).addClass("ui-jqdialog-content ui-widget-content").attr("id",aIDs.modalcontent);
  5499. $(mc).append(content);
  5500. mw.appendChild(mc);
  5501. $(mw).prepend(mh);
  5502. if(appendsel===true) { $('body').append(mw); } //append as first child in body -for alert dialog
  5503. else if (typeof appendsel === "string") {
  5504. $(appendsel).append(mw);
  5505. } else {$(mw).insertBefore(insertSelector);}
  5506. $(mw).css(css);
  5507. if(p.jqModal === undefined) {p.jqModal = true;} // internal use
  5508. var coord = {};
  5509. if ( $.fn.jqm && p.jqModal === true) {
  5510. if(p.left ===0 && p.top===0 && p.overlay) {
  5511. var pos = [];
  5512. pos = $.jgrid.findPos(posSelector);
  5513. p.left = pos[0] + 4;
  5514. p.top = pos[1] + 4;
  5515. }
  5516. coord.top = p.top+"px";
  5517. coord.left = p.left;
  5518. } else if(p.left !==0 || p.top!==0) {
  5519. coord.left = p.left;
  5520. coord.top = p.top+"px";
  5521. }
  5522. $("a.ui-jqdialog-titlebar-close",mh).click(function(){
  5523. var oncm = $("#"+$.jgrid.jqID(aIDs.themodal)).data("onClose") || p.onClose;
  5524. var gboxclose = $("#"+$.jgrid.jqID(aIDs.themodal)).data("gbox") || p.gbox;
  5525. self.hideModal("#"+$.jgrid.jqID(aIDs.themodal),{gb:gboxclose,jqm:p.jqModal,onClose:oncm});
  5526. return false;
  5527. });
  5528. if (p.width === 0 || !p.width) {p.width = 300;}
  5529. if(p.height === 0 || !p.height) {p.height =200;}
  5530. if(!p.zIndex) {
  5531. var parentZ = $(insertSelector).parents("*[role=dialog]").filter(':first').css("z-index");
  5532. if(parentZ) {
  5533. p.zIndex = parseInt(parentZ,10)+2;
  5534. } else {
  5535. p.zIndex = 950;
  5536. }
  5537. }
  5538. var rtlt = 0;
  5539. if( rtlsup && coord.left && !appendsel) {
  5540. rtlt = $(p.gbox).width()- (!isNaN(p.width) ? parseInt(p.width,10) :0) - 8; // to do
  5541. // just in case
  5542. coord.left = parseInt(coord.left,10) + parseInt(rtlt,10);
  5543. }
  5544. if(coord.left) { coord.left += "px"; }
  5545. $(mw).css($.extend({
  5546. width: isNaN(p.width) ? "auto": p.width+"px",
  5547. height:isNaN(p.height) ? "auto" : p.height + "px",
  5548. zIndex:p.zIndex,
  5549. overflow: 'hidden'
  5550. },coord))
  5551. .attr({tabIndex: "-1","role":"dialog","aria-labelledby":aIDs.modalhead,"aria-hidden":"true"});
  5552. if(p.drag === undefined) { p.drag=true;}
  5553. if(p.resize === undefined) {p.resize=true;}
  5554. if (p.drag) {
  5555. $(mh).css('cursor','move');
  5556. if($.fn.jqDrag) {
  5557. $(mw).jqDrag(mh);
  5558. } else {
  5559. try {
  5560. $(mw).draggable({handle: $("#"+$.jgrid.jqID(mh.id))});
  5561. } catch (e) {}
  5562. }
  5563. }
  5564. if(p.resize) {
  5565. if($.fn.jqResize) {
  5566. $(mw).append("<div class='jqResize ui-resizable-handle ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se'></div>");
  5567. $("#"+$.jgrid.jqID(aIDs.themodal)).jqResize(".jqResize",aIDs.scrollelm ? "#"+$.jgrid.jqID(aIDs.scrollelm) : false);
  5568. } else {
  5569. try {
  5570. $(mw).resizable({handles: 'se, sw',alsoResize: aIDs.scrollelm ? "#"+$.jgrid.jqID(aIDs.scrollelm) : false});
  5571. } catch (r) {}
  5572. }
  5573. }
  5574. if(p.closeOnEscape === true){
  5575. $(mw).keydown( function( e ) {
  5576. if( e.which == 27 ) {
  5577. var cone = $("#"+$.jgrid.jqID(aIDs.themodal)).data("onClose") || p.onClose;
  5578. self.hideModal("#"+$.jgrid.jqID(aIDs.themodal),{gb:p.gbox,jqm:p.jqModal,onClose: cone});
  5579. }
  5580. });
  5581. }
  5582. },
  5583. viewModal : function (selector,o){
  5584. o = $.extend({
  5585. toTop: true,
  5586. overlay: 10,
  5587. modal: false,
  5588. overlayClass : 'ui-widget-overlay',
  5589. onShow: $.jgrid.showModal,
  5590. onHide: $.jgrid.closeModal,
  5591. gbox: '',
  5592. jqm : true,
  5593. jqM : true
  5594. }, o || {});
  5595. if ($.fn.jqm && o.jqm === true) {
  5596. if(o.jqM) { $(selector).attr("aria-hidden","false").jqm(o).jqmShow(); }
  5597. else {$(selector).attr("aria-hidden","false").jqmShow();}
  5598. } else {
  5599. if(o.gbox !== '') {
  5600. $(".jqgrid-overlay:first",o.gbox).show();
  5601. $(selector).data("gbox",o.gbox);
  5602. }
  5603. $(selector).show().attr("aria-hidden","false");
  5604. try{$(':input:visible',selector)[0].focus();}catch(_){}
  5605. }
  5606. },
  5607. info_dialog : function(caption, content,c_b, modalopt) {
  5608. var mopt = {
  5609. width:290,
  5610. height:'auto',
  5611. dataheight: 'auto',
  5612. drag: true,
  5613. resize: false,
  5614. left:250,
  5615. top:170,
  5616. zIndex : 1000,
  5617. jqModal : true,
  5618. modal : false,
  5619. closeOnEscape : true,
  5620. align: 'center',
  5621. buttonalign : 'center',
  5622. buttons : []
  5623. // {text:'textbutt', id:"buttid", onClick : function(){...}}
  5624. // 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...
  5625. };
  5626. $.extend(true, mopt, $.jgrid.jqModal || {}, {caption:"<b>"+caption+"</b>"}, modalopt || {});
  5627. var jm = mopt.jqModal, self = this;
  5628. if($.fn.jqm && !jm) { jm = false; }
  5629. // in case there is no jqModal
  5630. var buttstr ="", i;
  5631. if(mopt.buttons.length > 0) {
  5632. for(i=0;i<mopt.buttons.length;i++) {
  5633. if(mopt.buttons[i].id === undefined) { mopt.buttons[i].id = "info_button_"+i; }
  5634. buttstr += "<a href='javascript:void(0)' id='"+mopt.buttons[i].id+"' class='fm-button ui-state-default ui-corner-all'>"+mopt.buttons[i].text+"</a>";
  5635. }
  5636. }
  5637. var dh = isNaN(mopt.dataheight) ? mopt.dataheight : mopt.dataheight+"px",
  5638. cn = "text-align:"+mopt.align+";";
  5639. var cnt = "<div id='info_id'>";
  5640. cnt += "<div id='infocnt' style='margin:0px;padding-bottom:1em;width:100%;overflow:auto;position:relative;height:"+dh+";"+cn+"'>"+content+"</div>";
  5641. cnt += c_b ? "<div class='ui-widget-content ui-helper-clearfix' style='text-align:"+mopt.buttonalign+";padding-bottom:0.8em;padding-top:0.5em;background-image: none;border-width: 1px 0 0 0;'><a href='javascript:void(0)' id='closedialog' class='fm-button ui-state-default ui-corner-all'>"+c_b+"</a>"+buttstr+"</div>" :
  5642. buttstr !== "" ? "<div class='ui-widget-content ui-helper-clearfix' style='text-align:"+mopt.buttonalign+";padding-bottom:0.8em;padding-top:0.5em;background-image: none;border-width: 1px 0 0 0;'>"+buttstr+"</div>" : "";
  5643. cnt += "</div>";
  5644. try {
  5645. if($("#info_dialog").attr("aria-hidden") == "false") {
  5646. $.jgrid.hideModal("#info_dialog",{jqm:jm});
  5647. }
  5648. $("#info_dialog").remove();
  5649. } catch (e){}
  5650. $.jgrid.createModal({
  5651. themodal:'info_dialog',
  5652. modalhead:'info_head',
  5653. modalcontent:'info_content',
  5654. scrollelm: 'infocnt'},
  5655. cnt,
  5656. mopt,
  5657. '','',true
  5658. );
  5659. // attach onclick after inserting into the dom
  5660. if(buttstr) {
  5661. $.each(mopt.buttons,function(i){
  5662. $("#"+$.jgrid.jqID(this.id),"#info_id").bind('click',function(){mopt.buttons[i].onClick.call($("#info_dialog")); return false;});
  5663. });
  5664. }
  5665. $("#closedialog", "#info_id").click(function(){
  5666. self.hideModal("#info_dialog",{jqm:jm});
  5667. return false;
  5668. });
  5669. $(".fm-button","#info_dialog").hover(
  5670. function(){$(this).addClass('ui-state-hover');},
  5671. function(){$(this).removeClass('ui-state-hover');}
  5672. );
  5673. if($.isFunction(mopt.beforeOpen) ) { mopt.beforeOpen(); }
  5674. $.jgrid.viewModal("#info_dialog",{
  5675. onHide: function(h) {
  5676. h.w.hide().remove();
  5677. if(h.o) { h.o.remove(); }
  5678. },
  5679. modal :mopt.modal,
  5680. jqm:jm
  5681. });
  5682. if($.isFunction(mopt.afterOpen) ) { mopt.afterOpen(); }
  5683. try{ $("#info_dialog").focus();} catch (m){}
  5684. },
  5685. bindEv: function (el, opt, $t) {
  5686. if($.isFunction(opt.dataInit)) {
  5687. opt.dataInit.call($t,el);
  5688. }
  5689. if(opt.dataEvents) {
  5690. $.each(opt.dataEvents, function() {
  5691. if (this.data !== undefined) {
  5692. $(el).bind(this.type, this.data, this.fn);
  5693. } else {
  5694. $(el).bind(this.type, this.fn);
  5695. }
  5696. });
  5697. }
  5698. },
  5699. // Form Functions
  5700. createEl : function(eltype,options,vl,autowidth, ajaxso) {
  5701. var elem = "", $t = this;
  5702. function setAttributes(elm, atr, exl ) {
  5703. var exclude = ['dataInit','dataEvents','dataUrl', 'buildSelect','sopt', 'searchhidden', 'defaultValue', 'attr', 'custom_element', 'custom_value'];
  5704. if(exl !== undefined && $.isArray(exl)) {
  5705. $.merge(exclude, exl);
  5706. }
  5707. $.each(atr, function(key, value){
  5708. if($.inArray(key, exclude) === -1) {
  5709. $(elm).attr(key,value);
  5710. }
  5711. });
  5712. if(!atr.hasOwnProperty('id')) {
  5713. $(elm).attr('id', $.jgrid.randId());
  5714. }
  5715. }
  5716. switch (eltype)
  5717. {
  5718. case "textarea" :
  5719. elem = document.createElement("textarea");
  5720. if(autowidth) {
  5721. if(!options.cols) { $(elem).css({width:"98%"});}
  5722. } else if (!options.cols) { options.cols = 20; }
  5723. if(!options.rows) { options.rows = 2; }
  5724. if(vl=='&nbsp;' || vl=='&#160;' || (vl.length==1 && vl.charCodeAt(0)==160)) {vl="";}
  5725. elem.value = vl;
  5726. setAttributes(elem, options);
  5727. $(elem).attr({"role":"textbox","multiline":"true"});
  5728. break;
  5729. case "checkbox" : //what code for simple checkbox
  5730. elem = document.createElement("input");
  5731. elem.type = "checkbox";
  5732. if( !options.value ) {
  5733. var vl1 = vl.toLowerCase();
  5734. if(vl1.search(/(false|0|no|off|undefined)/i)<0 && vl1!=="") {
  5735. elem.checked=true;
  5736. elem.defaultChecked=true;
  5737. elem.value = vl;
  5738. } else {
  5739. elem.value = "on";
  5740. }
  5741. $(elem).attr("offval","off");
  5742. } else {
  5743. var cbval = options.value.split(":");
  5744. if(vl === cbval[0]) {
  5745. elem.checked=true;
  5746. elem.defaultChecked=true;
  5747. }
  5748. elem.value = cbval[0];
  5749. $(elem).attr("offval",cbval[1]);
  5750. }
  5751. setAttributes(elem, options, ['value']);
  5752. $(elem).attr("role","checkbox");
  5753. break;
  5754. case "select" :
  5755. elem = document.createElement("select");
  5756. elem.setAttribute("role","select");
  5757. var msl, ovm = [];
  5758. if(options.multiple===true) {
  5759. msl = true;
  5760. elem.multiple="multiple";
  5761. $(elem).attr("aria-multiselectable","true");
  5762. } else { msl = false; }
  5763. if(options.dataUrl !== undefined) {
  5764. var rowid = options.name ? String(options.id).substring(0, String(options.id).length - String(options.name).length - 1) : String(options.id),
  5765. postData = options.postData || ajaxso.postData;
  5766. if ($t.p && $t.p.idPrefix) {
  5767. rowid = $.jgrid.stripPref($t.p.idPrefix, rowid);
  5768. } else {
  5769. postData = undefined; // don't use postData for searching from jqFilter. One can implement the feature in the future if required.
  5770. }
  5771. $.ajax($.extend({
  5772. url: options.dataUrl,
  5773. type : "GET",
  5774. dataType: "html",
  5775. data: $.isFunction(postData) ? postData.call($t, rowid, vl, String(options.name)) : postData,
  5776. context: {elem:elem, options:options, vl:vl},
  5777. success: function(data){
  5778. var a, ovm = [], elem = this.elem, vl = this.vl,
  5779. options = $.extend({},this.options),
  5780. msl = options.multiple===true;
  5781. if($.isFunction(options.buildSelect)) {
  5782. var b = options.buildSelect.call($t,data);
  5783. a = $(b).html();
  5784. } else {
  5785. a = $(data).html();
  5786. }
  5787. if(a) {
  5788. $(elem).append(a);
  5789. setAttributes(elem, options);
  5790. if(options.size === undefined) { options.size = msl ? 3 : 1;}
  5791. if(msl) {
  5792. ovm = vl.split(",");
  5793. ovm = $.map(ovm,function(n){return $.trim(n);});
  5794. } else {
  5795. ovm[0] = $.trim(vl);
  5796. }
  5797. //$(elem).attr(options);
  5798. setTimeout(function(){
  5799. $("option",elem).each(function(i){
  5800. //if(i===0) { this.selected = ""; }
  5801. // fix IE8/IE7 problem with selecting of the first item on multiple=true
  5802. if (i === 0 && elem.multiple) { this.selected = false; }
  5803. $(this).attr("role","option");
  5804. if($.inArray($.trim($(this).text()),ovm) > -1 || $.inArray($.trim($(this).val()),ovm) > -1 ) {
  5805. this.selected= "selected";
  5806. }
  5807. });
  5808. },0);
  5809. }
  5810. }
  5811. },ajaxso || {}));
  5812. } else if(options.value) {
  5813. var i;
  5814. if(options.size === undefined) {
  5815. options.size = msl ? 3 : 1;
  5816. }
  5817. if(msl) {
  5818. ovm = vl.split(",");
  5819. ovm = $.map(ovm,function(n){return $.trim(n);});
  5820. }
  5821. if(typeof options.value === 'function') { options.value = options.value(); }
  5822. var so,sv, ov,
  5823. sep = options.separator === undefined ? ":" : options.separator,
  5824. delim = options.delimiter === undefined ? ";" : options.delimiter;
  5825. if(typeof options.value === 'string') {
  5826. so = options.value.split(delim);
  5827. for(i=0; i<so.length;i++){
  5828. sv = so[i].split(sep);
  5829. if(sv.length > 2 ) {
  5830. sv[1] = $.map(sv,function(n,ii){if(ii>0) { return n;} }).join(sep);
  5831. }
  5832. ov = document.createElement("option");
  5833. ov.setAttribute("role","option");
  5834. ov.value = sv[0]; ov.innerHTML = sv[1];
  5835. elem.appendChild(ov);
  5836. if (!msl && ($.trim(sv[0]) == $.trim(vl) || $.trim(sv[1]) == $.trim(vl))) { ov.selected ="selected"; }
  5837. if (msl && ($.inArray($.trim(sv[1]), ovm)>-1 || $.inArray($.trim(sv[0]), ovm)>-1)) {ov.selected ="selected";}
  5838. }
  5839. } else if (typeof options.value === 'object') {
  5840. var oSv = options.value, key;
  5841. for (key in oSv) {
  5842. if (oSv.hasOwnProperty(key ) ){
  5843. ov = document.createElement("option");
  5844. ov.setAttribute("role","option");
  5845. ov.value = key; ov.innerHTML = oSv[key];
  5846. elem.appendChild(ov);
  5847. if (!msl && ( $.trim(key) == $.trim(vl) || $.trim(oSv[key]) == $.trim(vl)) ) { ov.selected ="selected"; }
  5848. if (msl && ($.inArray($.trim(oSv[key]),ovm)>-1 || $.inArray($.trim(key),ovm)>-1)) { ov.selected ="selected"; }
  5849. }
  5850. }
  5851. }
  5852. setAttributes(elem, options, ['value']);
  5853. }
  5854. break;
  5855. case "text" :
  5856. case "password" :
  5857. case "button" :
  5858. var role;
  5859. if(eltype=="button") { role = "button"; }
  5860. else { role = "textbox"; }
  5861. elem = document.createElement("input");
  5862. elem.type = eltype;
  5863. elem.value = vl;
  5864. setAttributes(elem, options);
  5865. if(eltype != "button"){
  5866. if(autowidth) {
  5867. if(!options.size) { $(elem).css({width:"98%"}); }
  5868. } else if (!options.size) { options.size = 20; }
  5869. }
  5870. $(elem).attr("role",role);
  5871. break;
  5872. case "image" :
  5873. case "file" :
  5874. elem = document.createElement("input");
  5875. elem.type = eltype;
  5876. setAttributes(elem, options);
  5877. break;
  5878. case "custom" :
  5879. elem = document.createElement("span");
  5880. try {
  5881. if($.isFunction(options.custom_element)) {
  5882. var celm = options.custom_element.call($t,vl,options);
  5883. if(celm) {
  5884. celm = $(celm).addClass("customelement").attr({id:options.id,name:options.name});
  5885. $(elem).empty().append(celm);
  5886. } else {
  5887. throw "e2";
  5888. }
  5889. } else {
  5890. throw "e1";
  5891. }
  5892. } catch (e) {
  5893. if (e=="e1") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_element' "+$.jgrid.edit.msg.nodefined, $.jgrid.edit.bClose);}
  5894. if (e=="e2") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_element' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose);}
  5895. else { $.jgrid.info_dialog($.jgrid.errors.errcap,typeof e==="string"?e:e.message,$.jgrid.edit.bClose); }
  5896. }
  5897. break;
  5898. }
  5899. return elem;
  5900. },
  5901. // Date Validation Javascript
  5902. checkDate : function (format, date) {
  5903. var daysInFebruary = function(year){
  5904. // February has 29 days in any year evenly divisible by four,
  5905. // EXCEPT for centurial years which are not also divisible by 400.
  5906. return (((year % 4 === 0) && ( year % 100 !== 0 || (year % 400 === 0))) ? 29 : 28 );
  5907. },
  5908. daysArray = function(n) {
  5909. var i;
  5910. for (i = 1; i <= n; i++) {
  5911. this[i] = 31;
  5912. if (i==4 || i==6 || i==9 || i==11) {this[i] = 30;}
  5913. if (i==2) {this[i] = 29;}
  5914. }
  5915. return this;
  5916. };
  5917. var tsp = {}, sep;
  5918. format = format.toLowerCase();
  5919. //we search for /,-,. for the date separator
  5920. if(format.indexOf("/") != -1) {
  5921. sep = "/";
  5922. } else if(format.indexOf("-") != -1) {
  5923. sep = "-";
  5924. } else if(format.indexOf(".") != -1) {
  5925. sep = ".";
  5926. } else {
  5927. sep = "/";
  5928. }
  5929. format = format.split(sep);
  5930. date = date.split(sep);
  5931. if (date.length != 3) { return false; }
  5932. var j=-1,yln, dln=-1, mln=-1, i;
  5933. for(i=0;i<format.length;i++){
  5934. var dv = isNaN(date[i]) ? 0 : parseInt(date[i],10);
  5935. tsp[format[i]] = dv;
  5936. yln = format[i];
  5937. if(yln.indexOf("y") != -1) { j=i; }
  5938. if(yln.indexOf("m") != -1) { mln=i; }
  5939. if(yln.indexOf("d") != -1) { dln=i; }
  5940. }
  5941. if (format[j] == "y" || format[j] == "yyyy") {
  5942. yln=4;
  5943. } else if(format[j] =="yy"){
  5944. yln = 2;
  5945. } else {
  5946. yln = -1;
  5947. }
  5948. var daysInMonth = daysArray(12),
  5949. strDate;
  5950. if (j === -1) {
  5951. return false;
  5952. }
  5953. strDate = tsp[format[j]].toString();
  5954. if(yln == 2 && strDate.length == 1) {yln = 1;}
  5955. if (strDate.length != yln || (tsp[format[j]]===0 && date[j]!="00")){
  5956. return false;
  5957. }
  5958. if(mln === -1) {
  5959. return false;
  5960. }
  5961. strDate = tsp[format[mln]].toString();
  5962. if (strDate.length<1 || tsp[format[mln]]<1 || tsp[format[mln]]>12){
  5963. return false;
  5964. }
  5965. if(dln === -1) {
  5966. return false;
  5967. }
  5968. strDate = tsp[format[dln]].toString();
  5969. 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]]]){
  5970. return false;
  5971. }
  5972. return true;
  5973. },
  5974. isEmpty : function(val)
  5975. {
  5976. if (val.match(/^\s+$/) || val === "") {
  5977. return true;
  5978. }
  5979. return false;
  5980. },
  5981. checkTime : function(time){
  5982. // checks only hh:ss (and optional am/pm)
  5983. var re = /^(\d{1,2}):(\d{2})([ap]m)?$/,regs;
  5984. if(!$.jgrid.isEmpty(time))
  5985. {
  5986. regs = time.match(re);
  5987. if(regs) {
  5988. if(regs[3]) {
  5989. if(regs[1] < 1 || regs[1] > 12) { return false; }
  5990. } else {
  5991. if(regs[1] > 23) { return false; }
  5992. }
  5993. if(regs[2] > 59) {
  5994. return false;
  5995. }
  5996. } else {
  5997. return false;
  5998. }
  5999. }
  6000. return true;
  6001. },
  6002. checkValues : function(val, valref,g, customobject, nam) {
  6003. var edtrul,i, nm, dft, len;
  6004. if(customobject === undefined) {
  6005. if(typeof valref==='string'){
  6006. for( i =0, len=g.p.colModel.length;i<len; i++){
  6007. if(g.p.colModel[i].name==valref) {
  6008. edtrul = g.p.colModel[i].editrules;
  6009. valref = i;
  6010. try { nm = g.p.colModel[i].formoptions.label; } catch (e) {}
  6011. break;
  6012. }
  6013. }
  6014. } else if(valref >=0) {
  6015. edtrul = g.p.colModel[valref].editrules;
  6016. }
  6017. } else {
  6018. edtrul = customobject;
  6019. nm = nam===undefined ? "_" : nam;
  6020. }
  6021. if(edtrul) {
  6022. if(!nm) { nm = g.p.colNames[valref]; }
  6023. if(edtrul.required === true) {
  6024. if( $.jgrid.isEmpty(val) ) { return [false,nm+": "+$.jgrid.edit.msg.required,""]; }
  6025. }
  6026. // force required
  6027. var rqfield = edtrul.required === false ? false : true;
  6028. if(edtrul.number === true) {
  6029. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  6030. if(isNaN(val)) { return [false,nm+": "+$.jgrid.edit.msg.number,""]; }
  6031. }
  6032. }
  6033. if(edtrul.minValue !== undefined && !isNaN(edtrul.minValue)) {
  6034. if (parseFloat(val) < parseFloat(edtrul.minValue) ) { return [false,nm+": "+$.jgrid.edit.msg.minValue+" "+edtrul.minValue,""];}
  6035. }
  6036. if(edtrul.maxValue !== undefined && !isNaN(edtrul.maxValue)) {
  6037. if (parseFloat(val) > parseFloat(edtrul.maxValue) ) { return [false,nm+": "+$.jgrid.edit.msg.maxValue+" "+edtrul.maxValue,""];}
  6038. }
  6039. var filter;
  6040. if(edtrul.email === true) {
  6041. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  6042. // taken from $ Validate plugin
  6043. 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;
  6044. if(!filter.test(val)) {return [false,nm+": "+$.jgrid.edit.msg.email,""];}
  6045. }
  6046. }
  6047. if(edtrul.integer === true) {
  6048. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  6049. if(isNaN(val)) { return [false,nm+": "+$.jgrid.edit.msg.integer,""]; }
  6050. if ((val % 1 !== 0) || (val.indexOf('.') != -1)) { return [false,nm+": "+$.jgrid.edit.msg.integer,""];}
  6051. }
  6052. }
  6053. if(edtrul.date === true) {
  6054. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  6055. if(g.p.colModel[valref].formatoptions && g.p.colModel[valref].formatoptions.newformat) {
  6056. dft = g.p.colModel[valref].formatoptions.newformat;
  6057. } else {
  6058. dft = g.p.colModel[valref].datefmt || "Y-m-d";
  6059. }
  6060. if(!$.jgrid.checkDate (dft, val)) { return [false,nm+": "+$.jgrid.edit.msg.date+" - "+dft,""]; }
  6061. }
  6062. }
  6063. if(edtrul.time === true) {
  6064. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  6065. if(!$.jgrid.checkTime (val)) { return [false,nm+": "+$.jgrid.edit.msg.date+" - hh:mm (am/pm)",""]; }
  6066. }
  6067. }
  6068. if(edtrul.url === true) {
  6069. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  6070. filter = /^(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
  6071. if(!filter.test(val)) {return [false,nm+": "+$.jgrid.edit.msg.url,""];}
  6072. }
  6073. }
  6074. if(edtrul.custom === true) {
  6075. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  6076. if($.isFunction(edtrul.custom_func)) {
  6077. var ret = edtrul.custom_func.call(g,val,nm);
  6078. return $.isArray(ret) ? ret : [false,$.jgrid.edit.msg.customarray,""];
  6079. }
  6080. return [false,$.jgrid.edit.msg.customfcheck,""];
  6081. }
  6082. }
  6083. }
  6084. return [true,"",""];
  6085. }
  6086. });
  6087. })(jQuery);
  6088. /*
  6089. * jqFilter jQuery jqGrid filter addon.
  6090. * Copyright (c) 2011, Tony Tomov, tony@trirand.com
  6091. * Dual licensed under the MIT and GPL licenses
  6092. * http://www.opensource.org/licenses/mit-license.php
  6093. * http://www.gnu.org/licenses/gpl-2.0.html
  6094. *
  6095. * The work is inspired from this Stefan Pirvu
  6096. * http://www.codeproject.com/KB/scripting/json-filtering.aspx
  6097. *
  6098. * The filter uses JSON entities to hold filter rules and groups. Here is an example of a filter:
  6099. { "groupOp": "AND",
  6100. "groups" : [
  6101. { "groupOp": "OR",
  6102. "rules": [
  6103. { "field": "name", "op": "eq", "data": "England" },
  6104. { "field": "id", "op": "le", "data": "5"}
  6105. ]
  6106. }
  6107. ],
  6108. "rules": [
  6109. { "field": "name", "op": "eq", "data": "Romania" },
  6110. { "field": "id", "op": "le", "data": "1"}
  6111. ]
  6112. }
  6113. */
  6114. /*jshint eqeqeq:false, eqnull:true, devel:true */
  6115. /*global jQuery */
  6116. (function ($) {
  6117. "use strict";
  6118. $.fn.jqFilter = function( arg ) {
  6119. if (typeof arg === 'string') {
  6120. var fn = $.fn.jqFilter[arg];
  6121. if (!fn) {
  6122. throw ("jqFilter - No such method: " + arg);
  6123. }
  6124. var args = $.makeArray(arguments).slice(1);
  6125. return fn.apply(this,args);
  6126. }
  6127. var p = $.extend(true,{
  6128. filter: null,
  6129. columns: [],
  6130. onChange : null,
  6131. afterRedraw : null,
  6132. checkValues : null,
  6133. error: false,
  6134. errmsg : "",
  6135. errorcheck : true,
  6136. showQuery : true,
  6137. sopt : null,
  6138. ops : [
  6139. {"name": "eq", "description": "equal", "operator":"="},
  6140. {"name": "ne", "description": "not equal", "operator":"<>"},
  6141. {"name": "lt", "description": "less", "operator":"<"},
  6142. {"name": "le", "description": "less or equal","operator":"<="},
  6143. {"name": "gt", "description": "greater", "operator":">"},
  6144. {"name": "ge", "description": "greater or equal", "operator":">="},
  6145. {"name": "bw", "description": "begins with", "operator":"LIKE"},
  6146. {"name": "bn", "description": "does not begin with", "operator":"NOT LIKE"},
  6147. {"name": "in", "description": "in", "operator":"IN"},
  6148. {"name": "ni", "description": "not in", "operator":"NOT IN"},
  6149. {"name": "ew", "description": "ends with", "operator":"LIKE"},
  6150. {"name": "en", "description": "does not end with", "operator":"NOT LIKE"},
  6151. {"name": "cn", "description": "contains", "operator":"LIKE"},
  6152. {"name": "nc", "description": "does not contain", "operator":"NOT LIKE"},
  6153. {"name": "nu", "description": "is null", "operator":"IS NULL"},
  6154. {"name": "nn", "description": "is not null", "operator":"IS NOT NULL"}
  6155. ],
  6156. numopts : ['eq','ne', 'lt', 'le', 'gt', 'ge', 'nu', 'nn', 'in', 'ni'],
  6157. stropts : ['eq', 'ne', 'bw', 'bn', 'ew', 'en', 'cn', 'nc', 'nu', 'nn', 'in', 'ni'],
  6158. strarr : ['text', 'string', 'blob'],
  6159. _gridsopt : [], // grid translated strings, do not tuch
  6160. groupOps : [{ op: "AND", text: "AND" }, { op: "OR", text: "OR" }],
  6161. groupButton : true,
  6162. ruleButtons : true,
  6163. direction : "ltr"
  6164. }, $.jgrid.filter, arg || {});
  6165. return this.each( function() {
  6166. if (this.filter) {return;}
  6167. this.p = p;
  6168. // setup filter in case if they is not defined
  6169. if (this.p.filter === null || this.p.filter === undefined) {
  6170. this.p.filter = {
  6171. groupOp: this.p.groupOps[0].op,
  6172. rules: [],
  6173. groups: []
  6174. };
  6175. }
  6176. var i, len = this.p.columns.length, cl,
  6177. isIE = /msie/i.test(navigator.userAgent) && !window.opera;
  6178. // translating the options
  6179. if(this.p._gridsopt.length) {
  6180. // ['eq','ne','lt','le','gt','ge','bw','bn','in','ni','ew','en','cn','nc']
  6181. for(i=0;i<this.p._gridsopt.length;i++) {
  6182. this.p.ops[i].description = this.p._gridsopt[i];
  6183. }
  6184. }
  6185. this.p.initFilter = $.extend(true,{},this.p.filter);
  6186. // set default values for the columns if they are not set
  6187. if( !len ) {return;}
  6188. for(i=0; i < len; i++) {
  6189. cl = this.p.columns[i];
  6190. if( cl.stype ) {
  6191. // grid compatibility
  6192. cl.inputtype = cl.stype;
  6193. } else if(!cl.inputtype) {
  6194. cl.inputtype = 'text';
  6195. }
  6196. if( cl.sorttype ) {
  6197. // grid compatibility
  6198. cl.searchtype = cl.sorttype;
  6199. } else if (!cl.searchtype) {
  6200. cl.searchtype = 'string';
  6201. }
  6202. if(cl.hidden === undefined) {
  6203. // jqGrid compatibility
  6204. cl.hidden = false;
  6205. }
  6206. if(!cl.label) {
  6207. cl.label = cl.name;
  6208. }
  6209. if(cl.index) {
  6210. cl.name = cl.index;
  6211. }
  6212. if(!cl.hasOwnProperty('searchoptions')) {
  6213. cl.searchoptions = {};
  6214. }
  6215. if(!cl.hasOwnProperty('searchrules')) {
  6216. cl.searchrules = {};
  6217. }
  6218. }
  6219. if(this.p.showQuery) {
  6220. $(this).append("<table class='queryresult ui-widget ui-widget-content' style='display:block;max-width:440px;border:0px none;' dir='"+this.p.direction+"'><tbody><tr><td class='query'></td></tr></tbody></table>");
  6221. }
  6222. /*
  6223. *Perform checking.
  6224. *
  6225. */
  6226. var checkData = function(val, colModelItem) {
  6227. var ret = [true,""];
  6228. if($.isFunction(colModelItem.searchrules)) {
  6229. ret = colModelItem.searchrules(val, colModelItem);
  6230. } else if($.jgrid && $.jgrid.checkValues) {
  6231. try {
  6232. ret = $.jgrid.checkValues(val, -1, null, colModelItem.searchrules, colModelItem.label);
  6233. } catch (e) {}
  6234. }
  6235. if(ret && ret.length && ret[0] === false) {
  6236. p.error = !ret[0];
  6237. p.errmsg = ret[1];
  6238. }
  6239. };
  6240. /* moving to common
  6241. randId = function() {
  6242. return Math.floor(Math.random()*10000).toString();
  6243. };
  6244. */
  6245. this.onchange = function ( ){
  6246. // clear any error
  6247. this.p.error = false;
  6248. this.p.errmsg="";
  6249. return $.isFunction(this.p.onChange) ? this.p.onChange.call( this, this.p ) : false;
  6250. };
  6251. /*
  6252. * Redraw the filter every time when new field is added/deleted
  6253. * and field is changed
  6254. */
  6255. this.reDraw = function() {
  6256. $("table.group:first",this).remove();
  6257. var t = this.createTableForGroup(p.filter, null);
  6258. $(this).append(t);
  6259. if($.isFunction(this.p.afterRedraw) ) {
  6260. this.p.afterRedraw.call(this, this.p);
  6261. }
  6262. };
  6263. /*
  6264. * Creates a grouping data for the filter
  6265. * @param group - object
  6266. * @param parentgroup - object
  6267. */
  6268. this.createTableForGroup = function(group, parentgroup) {
  6269. var that = this, i;
  6270. // this table will hold all the group (tables) and rules (rows)
  6271. var table = $("<table class='group ui-widget ui-widget-content' style='border:0px none;'><tbody></tbody></table>"),
  6272. // create error message row
  6273. align = "left";
  6274. if(this.p.direction == "rtl") {
  6275. align = "right";
  6276. table.attr("dir","rtl");
  6277. }
  6278. if(parentgroup === null) {
  6279. table.append("<tr class='error' style='display:none;'><th colspan='5' class='ui-state-error' align='"+align+"'></th></tr>");
  6280. }
  6281. var tr = $("<tr></tr>");
  6282. table.append(tr);
  6283. // this header will hold the group operator type and group action buttons for
  6284. // creating subgroup "+ {}", creating rule "+" or deleting the group "-"
  6285. var th = $("<th colspan='5' align='"+align+"'></th>");
  6286. tr.append(th);
  6287. if(this.p.ruleButtons === true) {
  6288. // dropdown for: choosing group operator type
  6289. var groupOpSelect = $("<select class='opsel'></select>");
  6290. th.append(groupOpSelect);
  6291. // populate dropdown with all posible group operators: or, and
  6292. var str= "", selected;
  6293. for (i = 0; i < p.groupOps.length; i++) {
  6294. selected = group.groupOp === that.p.groupOps[i].op ? " selected='selected'" :"";
  6295. str += "<option value='"+that.p.groupOps[i].op+"'" + selected+">"+that.p.groupOps[i].text+"</option>";
  6296. }
  6297. groupOpSelect
  6298. .append(str)
  6299. .bind('change',function() {
  6300. group.groupOp = $(groupOpSelect).val();
  6301. that.onchange(); // signals that the filter has changed
  6302. });
  6303. }
  6304. // button for adding a new subgroup
  6305. var inputAddSubgroup ="<span></span>";
  6306. if(this.p.groupButton) {
  6307. inputAddSubgroup = $("<input type='button' value='+ {}' title='Add subgroup' class='add-group'/>");
  6308. inputAddSubgroup.bind('click',function() {
  6309. if (group.groups === undefined ) {
  6310. group.groups = [];
  6311. }
  6312. group.groups.push({
  6313. groupOp: p.groupOps[0].op,
  6314. rules: [],
  6315. groups: []
  6316. }); // adding a new group
  6317. that.reDraw(); // the html has changed, force reDraw
  6318. that.onchange(); // signals that the filter has changed
  6319. return false;
  6320. });
  6321. }
  6322. th.append(inputAddSubgroup);
  6323. if(this.p.ruleButtons === true) {
  6324. // button for adding a new rule
  6325. var inputAddRule = $("<input type='button' value='+' title='Add rule' class='add-rule ui-add'/>"), cm;
  6326. inputAddRule.bind('click',function() {
  6327. //if(!group) { group = {};}
  6328. if (group.rules === undefined) {
  6329. group.rules = [];
  6330. }
  6331. for (i = 0; i < that.p.columns.length; i++) {
  6332. // but show only serchable and serchhidden = true fields
  6333. var searchable = (that.p.columns[i].search === undefined) ? true: that.p.columns[i].search ,
  6334. hidden = (that.p.columns[i].hidden === true),
  6335. ignoreHiding = (that.p.columns[i].searchoptions.searchhidden === true);
  6336. if ((ignoreHiding && searchable) || (searchable && !hidden)) {
  6337. cm = that.p.columns[i];
  6338. break;
  6339. }
  6340. }
  6341. var opr;
  6342. if( cm.searchoptions.sopt ) {opr = cm.searchoptions.sopt;}
  6343. else if(that.p.sopt) { opr= that.p.sopt; }
  6344. else if ( $.inArray(cm.searchtype, that.p.strarr) !== -1 ) {opr = that.p.stropts;}
  6345. else {opr = that.p.numopts;}
  6346. group.rules.push({
  6347. field: cm.name,
  6348. op: opr[0],
  6349. data: ""
  6350. }); // adding a new rule
  6351. that.reDraw(); // the html has changed, force reDraw
  6352. // for the moment no change have been made to the rule, so
  6353. // this will not trigger onchange event
  6354. return false;
  6355. });
  6356. th.append(inputAddRule);
  6357. }
  6358. // button for delete the group
  6359. if (parentgroup !== null) { // ignore the first group
  6360. var inputDeleteGroup = $("<input type='button' value='-' title='Delete group' class='delete-group'/>");
  6361. th.append(inputDeleteGroup);
  6362. inputDeleteGroup.bind('click',function() {
  6363. // remove group from parent
  6364. for (i = 0; i < parentgroup.groups.length; i++) {
  6365. if (parentgroup.groups[i] === group) {
  6366. parentgroup.groups.splice(i, 1);
  6367. break;
  6368. }
  6369. }
  6370. that.reDraw(); // the html has changed, force reDraw
  6371. that.onchange(); // signals that the filter has changed
  6372. return false;
  6373. });
  6374. }
  6375. // append subgroup rows
  6376. if (group.groups !== undefined) {
  6377. for (i = 0; i < group.groups.length; i++) {
  6378. var trHolderForSubgroup = $("<tr></tr>");
  6379. table.append(trHolderForSubgroup);
  6380. var tdFirstHolderForSubgroup = $("<td class='first'></td>");
  6381. trHolderForSubgroup.append(tdFirstHolderForSubgroup);
  6382. var tdMainHolderForSubgroup = $("<td colspan='4'></td>");
  6383. tdMainHolderForSubgroup.append(this.createTableForGroup(group.groups[i], group));
  6384. trHolderForSubgroup.append(tdMainHolderForSubgroup);
  6385. }
  6386. }
  6387. if(group.groupOp === undefined) {
  6388. group.groupOp = that.p.groupOps[0].op;
  6389. }
  6390. // append rules rows
  6391. if (group.rules !== undefined) {
  6392. for (i = 0; i < group.rules.length; i++) {
  6393. table.append(
  6394. this.createTableRowForRule(group.rules[i], group)
  6395. );
  6396. }
  6397. }
  6398. return table;
  6399. };
  6400. /*
  6401. * Create the rule data for the filter
  6402. */
  6403. this.createTableRowForRule = function(rule, group ) {
  6404. // save current entity in a variable so that it could
  6405. // be referenced in anonimous method calls
  6406. var that=this, tr = $("<tr></tr>"),
  6407. //document.createElement("tr"),
  6408. // first column used for padding
  6409. //tdFirstHolderForRule = document.createElement("td"),
  6410. i, op, trpar, cm, str="", selected;
  6411. //tdFirstHolderForRule.setAttribute("class", "first");
  6412. tr.append("<td class='first'></td>");
  6413. // create field container
  6414. var ruleFieldTd = $("<td class='columns'></td>");
  6415. tr.append(ruleFieldTd);
  6416. // dropdown for: choosing field
  6417. var ruleFieldSelect = $("<select></select>"), ina, aoprs = [];
  6418. ruleFieldTd.append(ruleFieldSelect);
  6419. ruleFieldSelect.bind('change',function() {
  6420. rule.field = $(ruleFieldSelect).val();
  6421. trpar = $(this).parents("tr:first");
  6422. for (i=0;i<that.p.columns.length;i++) {
  6423. if(that.p.columns[i].name === rule.field) {
  6424. cm = that.p.columns[i];
  6425. break;
  6426. }
  6427. }
  6428. if(!cm) {return;}
  6429. cm.searchoptions.id = $.jgrid.randId();
  6430. if(isIE && cm.inputtype === "text") {
  6431. if(!cm.searchoptions.size) {
  6432. cm.searchoptions.size = 10;
  6433. }
  6434. }
  6435. var elm = $.jgrid.createEl(cm.inputtype,cm.searchoptions, "", true, that.p.ajaxSelectOptions, true);
  6436. $(elm).addClass("input-elm");
  6437. //that.createElement(rule, "");
  6438. if( cm.searchoptions.sopt ) {op = cm.searchoptions.sopt;}
  6439. else if(that.p.sopt) { op= that.p.sopt; }
  6440. else if ($.inArray(cm.searchtype, that.p.strarr) !== -1) {op = that.p.stropts;}
  6441. else {op = that.p.numopts;}
  6442. // operators
  6443. var s ="", so = 0;
  6444. aoprs = [];
  6445. $.each(that.p.ops, function() { aoprs.push(this.name); });
  6446. for ( i = 0 ; i < op.length; i++) {
  6447. ina = $.inArray(op[i],aoprs);
  6448. if(ina !== -1) {
  6449. if(so===0) {
  6450. rule.op = that.p.ops[ina].name;
  6451. }
  6452. s += "<option value='"+that.p.ops[ina].name+"'>"+that.p.ops[ina].description+"</option>";
  6453. so++;
  6454. }
  6455. }
  6456. $(".selectopts",trpar).empty().append( s );
  6457. $(".selectopts",trpar)[0].selectedIndex = 0;
  6458. if( $.browser.msie && $.browser.version < 9) {
  6459. var sw = parseInt($("select.selectopts",trpar)[0].offsetWidth, 10) + 1;
  6460. $(".selectopts",trpar).width( sw );
  6461. $(".selectopts",trpar).css("width","auto");
  6462. }
  6463. // data
  6464. $(".data",trpar).empty().append( elm );
  6465. $.jgrid.bindEv( elm, cm.searchoptions, that);
  6466. $(".input-elm",trpar).bind('change',function( e ) {
  6467. var tmo = $(this).hasClass("ui-autocomplete-input") ? 200 :0;
  6468. setTimeout(function(){
  6469. var elem = e.target;
  6470. rule.data = elem.nodeName.toUpperCase() === "SPAN" && cm.searchoptions && $.isFunction(cm.searchoptions.custom_value) ?
  6471. cm.searchoptions.custom_value($(elem).children(".customelement:first"), 'get') : elem.value;
  6472. that.onchange(); // signals that the filter has changed
  6473. }, tmo);
  6474. });
  6475. setTimeout(function(){ //IE, Opera, Chrome
  6476. rule.data = $(elm).val();
  6477. that.onchange(); // signals that the filter has changed
  6478. }, 0);
  6479. });
  6480. // populate drop down with user provided column definitions
  6481. var j=0;
  6482. for (i = 0; i < that.p.columns.length; i++) {
  6483. // but show only serchable and serchhidden = true fields
  6484. var searchable = (that.p.columns[i].search === undefined) ? true: that.p.columns[i].search,
  6485. hidden = (that.p.columns[i].hidden === true),
  6486. ignoreHiding = (that.p.columns[i].searchoptions.searchhidden === true);
  6487. if ((ignoreHiding && searchable) || (searchable && !hidden)) {
  6488. selected = "";
  6489. if(rule.field === that.p.columns[i].name) {
  6490. selected = " selected='selected'";
  6491. j=i;
  6492. }
  6493. str += "<option value='"+that.p.columns[i].name+"'" +selected+">"+that.p.columns[i].label+"</option>";
  6494. }
  6495. }
  6496. ruleFieldSelect.append( str );
  6497. // create operator container
  6498. var ruleOperatorTd = $("<td class='operators'></td>");
  6499. tr.append(ruleOperatorTd);
  6500. cm = p.columns[j];
  6501. // create it here so it can be referentiated in the onchange event
  6502. //var RD = that.createElement(rule, rule.data);
  6503. cm.searchoptions.id = $.jgrid.randId();
  6504. if(isIE && cm.inputtype === "text") {
  6505. if(!cm.searchoptions.size) {
  6506. cm.searchoptions.size = 10;
  6507. }
  6508. }
  6509. var ruleDataInput = $.jgrid.createEl(cm.inputtype,cm.searchoptions, rule.data, true, that.p.ajaxSelectOptions, true);
  6510. if(rule.op == 'nu' || rule.op == 'nn') {
  6511. $(ruleDataInput).attr('readonly','true');
  6512. $(ruleDataInput).attr('disabled','true');
  6513. } //retain the state of disabled text fields in case of null ops
  6514. // dropdown for: choosing operator
  6515. var ruleOperatorSelect = $("<select class='selectopts'></select>");
  6516. ruleOperatorTd.append(ruleOperatorSelect);
  6517. ruleOperatorSelect.bind('change',function() {
  6518. rule.op = $(ruleOperatorSelect).val();
  6519. trpar = $(this).parents("tr:first");
  6520. var rd = $(".input-elm",trpar)[0];
  6521. if (rule.op === "nu" || rule.op === "nn") { // disable for operator "is null" and "is not null"
  6522. rule.data = "";
  6523. rd.value = "";
  6524. rd.setAttribute("readonly", "true");
  6525. rd.setAttribute("disabled", "true");
  6526. } else {
  6527. rd.removeAttribute("readonly");
  6528. rd.removeAttribute("disabled");
  6529. }
  6530. that.onchange(); // signals that the filter has changed
  6531. });
  6532. // populate drop down with all available operators
  6533. if( cm.searchoptions.sopt ) {op = cm.searchoptions.sopt;}
  6534. else if(that.p.sopt) { op= that.p.sopt; }
  6535. else if ($.inArray(cm.searchtype, that.p.strarr) !== -1) {op = that.p.stropts;}
  6536. else {op = that.p.numopts;}
  6537. str="";
  6538. $.each(that.p.ops, function() { aoprs.push(this.name); });
  6539. for ( i = 0; i < op.length; i++) {
  6540. ina = $.inArray(op[i],aoprs);
  6541. if(ina !== -1) {
  6542. selected = rule.op === that.p.ops[ina].name ? " selected='selected'" : "";
  6543. str += "<option value='"+that.p.ops[ina].name+"'"+selected+">"+that.p.ops[ina].description+"</option>";
  6544. }
  6545. }
  6546. ruleOperatorSelect.append( str );
  6547. // create data container
  6548. var ruleDataTd = $("<td class='data'></td>");
  6549. tr.append(ruleDataTd);
  6550. // textbox for: data
  6551. // is created previously
  6552. //ruleDataInput.setAttribute("type", "text");
  6553. ruleDataTd.append(ruleDataInput);
  6554. $.jgrid.bindEv( ruleDataInput, cm.searchoptions, that);
  6555. $(ruleDataInput)
  6556. .addClass("input-elm")
  6557. .bind('change', function() {
  6558. rule.data = cm.inputtype === 'custom' ? cm.searchoptions.custom_value($(this).children(".customelement:first"),'get') : $(this).val();
  6559. that.onchange(); // signals that the filter has changed
  6560. });
  6561. // create action container
  6562. var ruleDeleteTd = $("<td></td>");
  6563. tr.append(ruleDeleteTd);
  6564. // create button for: delete rule
  6565. if(this.p.ruleButtons === true) {
  6566. var ruleDeleteInput = $("<input type='button' value='-' title='Delete rule' class='delete-rule ui-del'/>");
  6567. ruleDeleteTd.append(ruleDeleteInput);
  6568. //$(ruleDeleteInput).html("").height(20).width(30).button({icons: { primary: "ui-icon-minus", text:false}});
  6569. ruleDeleteInput.bind('click',function() {
  6570. // remove rule from group
  6571. for (i = 0; i < group.rules.length; i++) {
  6572. if (group.rules[i] === rule) {
  6573. group.rules.splice(i, 1);
  6574. break;
  6575. }
  6576. }
  6577. that.reDraw(); // the html has changed, force reDraw
  6578. that.onchange(); // signals that the filter has changed
  6579. return false;
  6580. });
  6581. }
  6582. return tr;
  6583. };
  6584. this.getStringForGroup = function(group) {
  6585. var s = "(", index;
  6586. if (group.groups !== undefined) {
  6587. for (index = 0; index < group.groups.length; index++) {
  6588. if (s.length > 1) {
  6589. s += " " + group.groupOp + " ";
  6590. }
  6591. try {
  6592. s += this.getStringForGroup(group.groups[index]);
  6593. } catch (eg) {alert(eg);}
  6594. }
  6595. }
  6596. if (group.rules !== undefined) {
  6597. try{
  6598. for (index = 0; index < group.rules.length; index++) {
  6599. if (s.length > 1) {
  6600. s += " " + group.groupOp + " ";
  6601. }
  6602. s += this.getStringForRule(group.rules[index]);
  6603. }
  6604. } catch (e) {alert(e);}
  6605. }
  6606. s += ")";
  6607. if (s === "()") {
  6608. return ""; // ignore groups that don't have rules
  6609. }
  6610. return s;
  6611. };
  6612. this.getStringForRule = function(rule) {
  6613. var opUF = "",opC="", i, cm, ret, val,
  6614. numtypes = ['int', 'integer', 'float', 'number', 'currency']; // jqGrid
  6615. for (i = 0; i < this.p.ops.length; i++) {
  6616. if (this.p.ops[i].name === rule.op) {
  6617. opUF = this.p.ops[i].operator;
  6618. opC = this.p.ops[i].name;
  6619. break;
  6620. }
  6621. }
  6622. for (i=0; i<this.p.columns.length; i++) {
  6623. if(this.p.columns[i].name === rule.field) {
  6624. cm = this.p.columns[i];
  6625. break;
  6626. }
  6627. }
  6628. if (cm == null) { return ""; }
  6629. val = rule.data;
  6630. if(opC === 'bw' || opC === 'bn') { val = val+"%"; }
  6631. if(opC === 'ew' || opC === 'en') { val = "%"+val; }
  6632. if(opC === 'cn' || opC === 'nc') { val = "%"+val+"%"; }
  6633. if(opC === 'in' || opC === 'ni') { val = " ("+val+")"; }
  6634. if(p.errorcheck) { checkData(rule.data, cm); }
  6635. if($.inArray(cm.searchtype, numtypes) !== -1 || opC === 'nn' || opC === 'nu') { ret = rule.field + " " + opUF + " " + val; }
  6636. else { ret = rule.field + " " + opUF + " \"" + val + "\""; }
  6637. return ret;
  6638. };
  6639. this.resetFilter = function () {
  6640. this.p.filter = $.extend(true,{},this.p.initFilter);
  6641. this.reDraw();
  6642. this.onchange();
  6643. };
  6644. this.hideError = function() {
  6645. $("th.ui-state-error", this).html("");
  6646. $("tr.error", this).hide();
  6647. };
  6648. this.showError = function() {
  6649. $("th.ui-state-error", this).html(this.p.errmsg);
  6650. $("tr.error", this).show();
  6651. };
  6652. this.toUserFriendlyString = function() {
  6653. return this.getStringForGroup(p.filter);
  6654. };
  6655. this.toString = function() {
  6656. // this will obtain a string that can be used to match an item.
  6657. var that = this;
  6658. function getStringRule(rule) {
  6659. if(that.p.errorcheck) {
  6660. var i, cm;
  6661. for (i=0; i<that.p.columns.length; i++) {
  6662. if(that.p.columns[i].name === rule.field) {
  6663. cm = that.p.columns[i];
  6664. break;
  6665. }
  6666. }
  6667. if(cm) {checkData(rule.data, cm);}
  6668. }
  6669. return rule.op + "(item." + rule.field + ",'" + rule.data + "')";
  6670. }
  6671. function getStringForGroup(group) {
  6672. var s = "(", index;
  6673. if (group.groups !== undefined) {
  6674. for (index = 0; index < group.groups.length; index++) {
  6675. if (s.length > 1) {
  6676. if (group.groupOp === "OR") {
  6677. s += " || ";
  6678. }
  6679. else {
  6680. s += " && ";
  6681. }
  6682. }
  6683. s += getStringForGroup(group.groups[index]);
  6684. }
  6685. }
  6686. if (group.rules !== undefined) {
  6687. for (index = 0; index < group.rules.length; index++) {
  6688. if (s.length > 1) {
  6689. if (group.groupOp === "OR") {
  6690. s += " || ";
  6691. }
  6692. else {
  6693. s += " && ";
  6694. }
  6695. }
  6696. s += getStringRule(group.rules[index]);
  6697. }
  6698. }
  6699. s += ")";
  6700. if (s === "()") {
  6701. return ""; // ignore groups that don't have rules
  6702. }
  6703. return s;
  6704. }
  6705. return getStringForGroup(this.p.filter);
  6706. };
  6707. // Here we init the filter
  6708. this.reDraw();
  6709. if(this.p.showQuery) {
  6710. this.onchange();
  6711. }
  6712. // mark is as created so that it will not be created twice on this element
  6713. this.filter = true;
  6714. });
  6715. };
  6716. $.extend($.fn.jqFilter,{
  6717. /*
  6718. * Return SQL like string. Can be used directly
  6719. */
  6720. toSQLString : function()
  6721. {
  6722. var s ="";
  6723. this.each(function(){
  6724. s = this.toUserFriendlyString();
  6725. });
  6726. return s;
  6727. },
  6728. /*
  6729. * Return filter data as object.
  6730. */
  6731. filterData : function()
  6732. {
  6733. var s;
  6734. this.each(function(){
  6735. s = this.p.filter;
  6736. });
  6737. return s;
  6738. },
  6739. getParameter : function (param) {
  6740. if(param !== undefined) {
  6741. if (this.p.hasOwnProperty(param) ) {
  6742. return this.p[param];
  6743. }
  6744. }
  6745. return this.p;
  6746. },
  6747. resetFilter: function() {
  6748. return this.each(function(){
  6749. this.resetFilter();
  6750. });
  6751. },
  6752. addFilter: function (pfilter) {
  6753. if (typeof pfilter === "string") {
  6754. pfilter = $.jgrid.parse( pfilter );
  6755. }
  6756. this.each(function(){
  6757. this.p.filter = pfilter;
  6758. this.reDraw();
  6759. this.onchange();
  6760. });
  6761. }
  6762. });
  6763. })(jQuery);
  6764. /*jshint eqeqeq:false, eqnull:true, devel:true */
  6765. /*global xmlJsonClass, jQuery */
  6766. (function($){
  6767. /**
  6768. * jqGrid extension for form editing Grid Data
  6769. * Tony Tomov tony@trirand.com
  6770. * http://trirand.com/blog/
  6771. * Dual licensed under the MIT and GPL licenses:
  6772. * http://www.opensource.org/licenses/mit-license.php
  6773. * http://www.gnu.org/licenses/gpl-2.0.html
  6774. **/
  6775. "use strict";
  6776. var rp_ge = {};
  6777. $.jgrid.extend({
  6778. searchGrid : function (p) {
  6779. p = $.extend(true, {
  6780. recreateFilter: false,
  6781. drag: true,
  6782. sField:'searchField',
  6783. sValue:'searchString',
  6784. sOper: 'searchOper',
  6785. sFilter: 'filters',
  6786. loadDefaults: true, // this options activates loading of default filters from grid's postData for Multipe Search only.
  6787. beforeShowSearch: null,
  6788. afterShowSearch : null,
  6789. onInitializeSearch: null,
  6790. afterRedraw : null,
  6791. afterChange: null,
  6792. closeAfterSearch : false,
  6793. closeAfterReset: false,
  6794. closeOnEscape : false,
  6795. searchOnEnter : false,
  6796. multipleSearch : false,
  6797. multipleGroup : false,
  6798. //cloneSearchRowOnAdd: true,
  6799. top : 150,
  6800. left: 350,
  6801. jqModal : true,
  6802. modal: false,
  6803. resize : true,
  6804. width: 450,
  6805. height: 'auto',
  6806. dataheight: 'auto',
  6807. showQuery: false,
  6808. errorcheck : true,
  6809. // translation
  6810. // if you want to change or remove the order change it in sopt
  6811. // ['eq','ne','lt','le','gt','ge','bw','bn','in','ni','ew','en','cn','nc'],
  6812. sopt: null,
  6813. stringResult: undefined,
  6814. onClose : null,
  6815. onSearch : null,
  6816. onReset : null,
  6817. toTop : true,
  6818. overlay : 30,
  6819. columns : [],
  6820. tmplNames : null,
  6821. tmplFilters : null,
  6822. // translations - later in lang file
  6823. tmplLabel : ' Template: ',
  6824. showOnLoad: false,
  6825. layer: null
  6826. }, $.jgrid.search, p || {});
  6827. return this.each(function() {
  6828. var $t = this;
  6829. if(!$t.grid) {return;}
  6830. var fid = "fbox_"+$t.p.id,
  6831. showFrm = true,
  6832. IDs = {themodal:'searchmod'+fid,modalhead:'searchhd'+fid,modalcontent:'searchcnt'+fid, scrollelm : fid},
  6833. defaultFilters = $t.p.postData[p.sFilter];
  6834. if(typeof defaultFilters === "string") {
  6835. defaultFilters = $.jgrid.parse( defaultFilters );
  6836. }
  6837. if(p.recreateFilter === true) {
  6838. $("#"+$.jgrid.jqID(IDs.themodal)).remove();
  6839. }
  6840. function showFilter(_filter) {
  6841. showFrm = $($t).triggerHandler("jqGridFilterBeforeShow", [_filter]);
  6842. if(showFrm === undefined) {
  6843. showFrm = true;
  6844. }
  6845. if(showFrm && $.isFunction(p.beforeShowSearch)) {
  6846. showFrm = p.beforeShowSearch.call($t,_filter);
  6847. }
  6848. if(showFrm) {
  6849. $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{gbox:"#gbox_"+$.jgrid.jqID(fid),jqm:p.jqModal, modal:p.modal, overlay: p.overlay, toTop: p.toTop});
  6850. $($t).triggerHandler("jqGridFilterAfterShow", [_filter]);
  6851. if($.isFunction(p.afterShowSearch)) {
  6852. p.afterShowSearch.call($t, _filter);
  6853. }
  6854. }
  6855. }
  6856. if ( $("#"+$.jgrid.jqID(IDs.themodal))[0] !== undefined ) {
  6857. showFilter($("#fbox_"+$.jgrid.jqID(+$t.p.id)));
  6858. } else {
  6859. var fil = $("<div><div id='"+fid+"' class='searchFilter' style='overflow:auto'></div></div>").insertBefore("#gview_"+$.jgrid.jqID($t.p.id)),
  6860. align = "left", butleft ="";
  6861. if($t.p.direction == "rtl") {
  6862. align = "right";
  6863. butleft = " style='text-align:left'";
  6864. fil.attr("dir","rtl");
  6865. }
  6866. var columns = $.extend([],$t.p.colModel),
  6867. bS ="<a href='javascript:void(0)' id='"+fid+"_search' class='fm-button ui-state-default ui-corner-all fm-button-icon-right ui-reset'><span class='ui-icon ui-icon-search'></span>"+p.Find+"</a>",
  6868. bC ="<a href='javascript:void(0)' id='"+fid+"_reset' class='fm-button ui-state-default ui-corner-all fm-button-icon-left ui-search'><span class='ui-icon ui-icon-arrowreturnthick-1-w'></span>"+p.Reset+"</a>",
  6869. bQ = "", tmpl="", colnm, found = false, bt, cmi=-1;
  6870. if(p.showQuery) {
  6871. bQ ="<a href='javascript:void(0)' id='"+fid+"_query' class='fm-button ui-state-default ui-corner-all fm-button-icon-left'><span class='ui-icon ui-icon-comment'></span>Query</a>";
  6872. }
  6873. if(!p.columns.length) {
  6874. $.each(columns, function(i,n){
  6875. if(!n.label) {
  6876. n.label = $t.p.colNames[i];
  6877. }
  6878. // find first searchable column and set it if no default filter
  6879. if(!found) {
  6880. var searchable = (n.search === undefined) ? true: n.search ,
  6881. hidden = (n.hidden === true),
  6882. ignoreHiding = (n.searchoptions && n.searchoptions.searchhidden === true);
  6883. if ((ignoreHiding && searchable) || (searchable && !hidden)) {
  6884. found = true;
  6885. colnm = n.index || n.name;
  6886. cmi =i;
  6887. }
  6888. }
  6889. });
  6890. } else {
  6891. columns = p.columns;
  6892. }
  6893. // old behaviour
  6894. if( (!defaultFilters && colnm) || p.multipleSearch === false ) {
  6895. var cmop = "eq";
  6896. if(cmi >=0 && columns[cmi].searchoptions && columns[cmi].searchoptions.sopt) {
  6897. cmop = columns[cmi].searchoptions.sopt[0];
  6898. } else if(p.sopt && p.sopt.length) {
  6899. cmop = p.sopt[0];
  6900. }
  6901. defaultFilters = {"groupOp": "AND",rules:[{"field":colnm,"op":cmop,"data":""}]};
  6902. }
  6903. found = false;
  6904. if(p.tmplNames && p.tmplNames.length) {
  6905. found = true;
  6906. tmpl = p.tmplLabel;
  6907. tmpl += "<select class='ui-template'>";
  6908. tmpl += "<option value='default'>Default</option>";
  6909. $.each(p.tmplNames, function(i,n){
  6910. tmpl += "<option value='"+i+"'>"+n+"</option>";
  6911. });
  6912. tmpl += "</select>";
  6913. }
  6914. bt = "<table class='EditTable' style='border:0px none;margin-top:5px' id='"+fid+"_2'><tbody><tr><td colspan='2'><hr class='ui-widget-content' style='margin:1px'/></td></tr><tr><td class='EditButton' style='text-align:"+align+"'>"+bC+tmpl+"</td><td class='EditButton' "+butleft+">"+bQ+bS+"</td></tr></tbody></table>";
  6915. fid = $.jgrid.jqID( fid);
  6916. $("#"+fid).jqFilter({
  6917. columns : columns,
  6918. filter: p.loadDefaults ? defaultFilters : null,
  6919. showQuery: p.showQuery,
  6920. errorcheck : p.errorcheck,
  6921. sopt: p.sopt,
  6922. groupButton : p.multipleGroup,
  6923. ruleButtons : p.multipleSearch,
  6924. afterRedraw : p.afterRedraw,
  6925. _gridsopt : $.jgrid.search.odata,
  6926. ajaxSelectOptions: $t.p.ajaxSelectOptions,
  6927. groupOps: p.groupOps,
  6928. onChange : function() {
  6929. if(this.p.showQuery) {
  6930. $('.query',this).html(this.toUserFriendlyString());
  6931. }
  6932. if ($.isFunction(p.afterChange)) {
  6933. p.afterChange.call($t, $("#"+fid), p);
  6934. }
  6935. },
  6936. direction : $t.p.direction
  6937. });
  6938. fil.append( bt );
  6939. if(found && p.tmplFilters && p.tmplFilters.length) {
  6940. $(".ui-template", fil).bind('change', function(){
  6941. var curtempl = $(this).val();
  6942. if(curtempl=="default") {
  6943. $("#"+fid).jqFilter('addFilter', defaultFilters);
  6944. } else {
  6945. $("#"+fid).jqFilter('addFilter', p.tmplFilters[parseInt(curtempl,10)]);
  6946. }
  6947. return false;
  6948. });
  6949. }
  6950. if(p.multipleGroup === true) {p.multipleSearch = true;}
  6951. $($t).triggerHandler("jqGridFilterInitialize", [$("#"+fid)]);
  6952. if($.isFunction(p.onInitializeSearch) ) {
  6953. p.onInitializeSearch.call($t, $("#"+fid));
  6954. }
  6955. p.gbox = "#gbox_"+fid;
  6956. if (p.layer) {
  6957. $.jgrid.createModal(IDs ,fil,p,"#gview_"+$.jgrid.jqID($t.p.id),$("#gbox_"+$.jgrid.jqID($t.p.id))[0], "#"+$.jgrid.jqID(p.layer), {position: "relative"});
  6958. } else {
  6959. $.jgrid.createModal(IDs ,fil,p,"#gview_"+$.jgrid.jqID($t.p.id),$("#gbox_"+$.jgrid.jqID($t.p.id))[0]);
  6960. }
  6961. if (p.searchOnEnter || p.closeOnEscape) {
  6962. $("#"+$.jgrid.jqID(IDs.themodal)).keydown(function (e) {
  6963. var $target = $(e.target);
  6964. if (p.searchOnEnter && e.which === 13 && // 13 === $.ui.keyCode.ENTER
  6965. !$target.hasClass('add-group') && !$target.hasClass('add-rule') &&
  6966. !$target.hasClass('delete-group') && !$target.hasClass('delete-rule') &&
  6967. (!$target.hasClass("fm-button") || !$target.is("[id$=_query]"))) {
  6968. $("#"+fid+"_search").focus().click();
  6969. return false;
  6970. }
  6971. if (p.closeOnEscape && e.which === 27) { // 27 === $.ui.keyCode.ESCAPE
  6972. $("#"+$.jgrid.jqID(IDs.modalhead)).find(".ui-jqdialog-titlebar-close").focus().click();
  6973. return false;
  6974. }
  6975. });
  6976. }
  6977. if(bQ) {
  6978. $("#"+fid+"_query").bind('click', function(){
  6979. $(".queryresult", fil).toggle();
  6980. return false;
  6981. });
  6982. }
  6983. if (p.stringResult===undefined) {
  6984. // to provide backward compatibility, inferring stringResult value from multipleSearch
  6985. p.stringResult = p.multipleSearch;
  6986. }
  6987. $("#"+fid+"_search").bind('click', function(){
  6988. var fl = $("#"+fid),
  6989. sdata={}, res ,
  6990. filters = fl.jqFilter('filterData');
  6991. if(p.errorcheck) {
  6992. fl[0].hideError();
  6993. if(!p.showQuery) {fl.jqFilter('toSQLString');}
  6994. if(fl[0].p.error) {
  6995. fl[0].showError();
  6996. return false;
  6997. }
  6998. }
  6999. if(p.stringResult) {
  7000. try {
  7001. // xmlJsonClass or JSON.stringify
  7002. res = xmlJsonClass.toJson(filters, '', '', false);
  7003. } catch (e) {
  7004. try {
  7005. res = JSON.stringify(filters);
  7006. } catch (e2) { }
  7007. }
  7008. if(typeof res==="string") {
  7009. sdata[p.sFilter] = res;
  7010. $.each([p.sField,p.sValue, p.sOper], function() {sdata[this] = "";});
  7011. }
  7012. } else {
  7013. if(p.multipleSearch) {
  7014. sdata[p.sFilter] = filters;
  7015. $.each([p.sField,p.sValue, p.sOper], function() {sdata[this] = "";});
  7016. } else {
  7017. sdata[p.sField] = filters.rules[0].field;
  7018. sdata[p.sValue] = filters.rules[0].data;
  7019. sdata[p.sOper] = filters.rules[0].op;
  7020. sdata[p.sFilter] = "";
  7021. }
  7022. }
  7023. $t.p.search = true;
  7024. $.extend($t.p.postData,sdata);
  7025. $($t).triggerHandler("jqGridFilterSearch");
  7026. if($.isFunction(p.onSearch) ) {
  7027. p.onSearch.call($t);
  7028. }
  7029. $($t).trigger("reloadGrid",[{page:1}]);
  7030. if(p.closeAfterSearch) {
  7031. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:p.jqModal,onClose: p.onClose});
  7032. }
  7033. return false;
  7034. });
  7035. $("#"+fid+"_reset").bind('click', function(){
  7036. var sdata={},
  7037. fl = $("#"+fid);
  7038. $t.p.search = false;
  7039. if(p.multipleSearch===false) {
  7040. sdata[p.sField] = sdata[p.sValue] = sdata[p.sOper] = "";
  7041. } else {
  7042. sdata[p.sFilter] = "";
  7043. }
  7044. fl[0].resetFilter();
  7045. if(found) {
  7046. $(".ui-template", fil).val("default");
  7047. }
  7048. $.extend($t.p.postData,sdata);
  7049. $($t).triggerHandler("jqGridFilterReset");
  7050. if($.isFunction(p.onReset) ) {
  7051. p.onReset.call($t);
  7052. }
  7053. $($t).trigger("reloadGrid",[{page:1}]);
  7054. return false;
  7055. });
  7056. showFilter($("#"+fid));
  7057. $(".fm-button:not(.ui-state-disabled)",fil).hover(
  7058. function(){$(this).addClass('ui-state-hover');},
  7059. function(){$(this).removeClass('ui-state-hover');}
  7060. );
  7061. }
  7062. });
  7063. },
  7064. editGridRow : function(rowid, p){
  7065. p = $.extend(true, {
  7066. top : 30,
  7067. left: 250,
  7068. width: 550,
  7069. height: 'auto',
  7070. dataheight: 'auto',
  7071. modal: false,
  7072. overlay : 30,
  7073. drag: true,
  7074. resize: true,
  7075. url: null,
  7076. mtype : "POST",
  7077. clearAfterAdd :true,
  7078. closeAfterEdit : false,
  7079. reloadAfterSubmit : true,
  7080. onInitializeForm: null,
  7081. beforeInitData: null,
  7082. beforeShowForm: null,
  7083. afterShowForm: null,
  7084. beforeSubmit: null,
  7085. afterSubmit: null,
  7086. onclickSubmit: null,
  7087. afterComplete: null,
  7088. onclickPgButtons : null,
  7089. afterclickPgButtons: null,
  7090. editData : {},
  7091. recreateForm : false,
  7092. jqModal : true,
  7093. closeOnEscape : false,
  7094. addedrow : "first",
  7095. topinfo : '',
  7096. bottominfo: '',
  7097. saveicon : [],
  7098. closeicon : [],
  7099. savekey: [false,13],
  7100. navkeys: [false,38,40],
  7101. checkOnSubmit : false,
  7102. checkOnUpdate : false,
  7103. _savedData : {},
  7104. processing : false,
  7105. onClose : null,
  7106. ajaxEditOptions : {},
  7107. serializeEditData : null,
  7108. viewPagerButtons : true
  7109. }, $.jgrid.edit, p || {});
  7110. rp_ge[$(this)[0].p.id] = p;
  7111. return this.each(function(){
  7112. var $t = this;
  7113. if (!$t.grid || !rowid) {return;}
  7114. var gID = $t.p.id,
  7115. frmgr = "FrmGrid_"+gID, frmtborg = "TblGrid_"+gID, frmtb = "#"+$.jgrid.jqID(frmtborg),
  7116. IDs = {themodal:'editmod'+gID,modalhead:'edithd'+gID,modalcontent:'editcnt'+gID, scrollelm : frmgr},
  7117. onBeforeShow = $.isFunction(rp_ge[$t.p.id].beforeShowForm) ? rp_ge[$t.p.id].beforeShowForm : false,
  7118. onAfterShow = $.isFunction(rp_ge[$t.p.id].afterShowForm) ? rp_ge[$t.p.id].afterShowForm : false,
  7119. onBeforeInit = $.isFunction(rp_ge[$t.p.id].beforeInitData) ? rp_ge[$t.p.id].beforeInitData : false,
  7120. onInitializeForm = $.isFunction(rp_ge[$t.p.id].onInitializeForm) ? rp_ge[$t.p.id].onInitializeForm : false,
  7121. showFrm = true,
  7122. maxCols = 1, maxRows=0, postdata, extpost, newData, diff, frmoper;
  7123. frmgr = $.jgrid.jqID(frmgr);
  7124. if (rowid === "new") {
  7125. rowid = "_empty";
  7126. frmoper = "add";
  7127. p.caption=rp_ge[$t.p.id].addCaption;
  7128. } else {
  7129. p.caption=rp_ge[$t.p.id].editCaption;
  7130. frmoper = "edit";
  7131. }
  7132. if(p.recreateForm===true && $("#"+$.jgrid.jqID(IDs.themodal))[0] !== undefined) {
  7133. $("#"+$.jgrid.jqID(IDs.themodal)).remove();
  7134. }
  7135. var closeovrl = true;
  7136. if(p.checkOnUpdate && p.jqModal && !p.modal) {
  7137. closeovrl = false;
  7138. }
  7139. function getFormData(){
  7140. $(frmtb+" > tbody > tr > td > .FormElement").each(function() {
  7141. var celm = $(".customelement", this);
  7142. if (celm.length) {
  7143. var elem = celm[0], nm = $(elem).attr('name');
  7144. $.each($t.p.colModel, function(){
  7145. if(this.name === nm && this.editoptions && $.isFunction(this.editoptions.custom_value)) {
  7146. try {
  7147. postdata[nm] = this.editoptions.custom_value.call($t, $("#"+$.jgrid.jqID(nm),frmtb),'get');
  7148. if (postdata[nm] === undefined) {throw "e1";}
  7149. } catch (e) {
  7150. if (e==="e1") {$.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose);}
  7151. else {$.jgrid.info_dialog($.jgrid.errors.errcap,e.message,$.jgrid.edit.bClose);}
  7152. }
  7153. return true;
  7154. }
  7155. });
  7156. } else {
  7157. switch ($(this).get(0).type) {
  7158. case "checkbox":
  7159. if($(this).is(":checked")) {
  7160. postdata[this.name]= $(this).val();
  7161. }else {
  7162. var ofv = $(this).attr("offval");
  7163. postdata[this.name]= ofv;
  7164. }
  7165. break;
  7166. case "select-one":
  7167. postdata[this.name]= $("option:selected",this).val();
  7168. extpost[this.name]= $("option:selected",this).text();
  7169. break;
  7170. case "select-multiple":
  7171. postdata[this.name]= $(this).val();
  7172. if(postdata[this.name]) {postdata[this.name] = postdata[this.name].join(",");}
  7173. else {postdata[this.name] ="";}
  7174. var selectedText = [];
  7175. $("option:selected",this).each(
  7176. function(i,selected){
  7177. selectedText[i] = $(selected).text();
  7178. }
  7179. );
  7180. extpost[this.name]= selectedText.join(",");
  7181. break;
  7182. case "password":
  7183. case "text":
  7184. case "textarea":
  7185. case "button":
  7186. postdata[this.name] = $(this).val();
  7187. break;
  7188. }
  7189. if($t.p.autoencode) {postdata[this.name] = $.jgrid.htmlEncode(postdata[this.name]);}
  7190. }
  7191. });
  7192. return true;
  7193. }
  7194. function createData(rowid,obj,tb,maxcols){
  7195. var nm, hc,trdata, cnt=0,tmp, dc,elc, retpos=[], ind=false,
  7196. tdtmpl = "<td class='CaptionTD'>&#160;</td><td class='DataTD'>&#160;</td>", tmpl="", i; //*2
  7197. for (i =1; i<=maxcols;i++) {
  7198. tmpl += tdtmpl;
  7199. }
  7200. if(rowid != '_empty') {
  7201. ind = $(obj).jqGrid("getInd",rowid);
  7202. }
  7203. $(obj.p.colModel).each( function(i) {
  7204. nm = this.name;
  7205. // hidden fields are included in the form
  7206. if(this.editrules && this.editrules.edithidden === true) {
  7207. hc = false;
  7208. } else {
  7209. hc = this.hidden === true ? true : false;
  7210. }
  7211. dc = hc ? "style='display:none'" : "";
  7212. if ( nm !== 'cb' && nm !== 'subgrid' && this.editable===true && nm !== 'rn') {
  7213. if(ind === false) {
  7214. tmp = "";
  7215. } else {
  7216. if(nm == obj.p.ExpandColumn && obj.p.treeGrid === true) {
  7217. tmp = $("td[role='gridcell']:eq("+i+")",obj.rows[ind]).text();
  7218. } else {
  7219. try {
  7220. tmp = $.unformat.call(obj, $("td[role='gridcell']:eq("+i+")",obj.rows[ind]),{rowId:rowid, colModel:this},i);
  7221. } catch (_) {
  7222. tmp = (this.edittype && this.edittype == "textarea") ? $("td[role='gridcell']:eq("+i+")",obj.rows[ind]).text() : $("td[role='gridcell']:eq("+i+")",obj.rows[ind]).html();
  7223. }
  7224. if(!tmp || tmp == "&nbsp;" || tmp == "&#160;" || (tmp.length==1 && tmp.charCodeAt(0)==160) ) {tmp='';}
  7225. }
  7226. }
  7227. var opt = $.extend({}, this.editoptions || {} ,{id:nm,name:nm}),
  7228. frmopt = $.extend({}, {elmprefix:'',elmsuffix:'',rowabove:false,rowcontent:''}, this.formoptions || {}),
  7229. rp = parseInt(frmopt.rowpos,10) || cnt+1,
  7230. cp = parseInt((parseInt(frmopt.colpos,10) || 1)*2,10);
  7231. if(rowid == "_empty" && opt.defaultValue ) {
  7232. tmp = $.isFunction(opt.defaultValue) ? opt.defaultValue.call($t) : opt.defaultValue;
  7233. }
  7234. if(!this.edittype) {this.edittype = "text";}
  7235. if($t.p.autoencode) {tmp = $.jgrid.htmlDecode(tmp);}
  7236. elc = $.jgrid.createEl.call($t,this.edittype,opt,tmp,false,$.extend({},$.jgrid.ajaxOptions,obj.p.ajaxSelectOptions || {}));
  7237. if(tmp === "" && this.edittype == "checkbox") {tmp = $(elc).attr("offval");}
  7238. if(tmp === "" && this.edittype == "select") {tmp = $("option:eq(0)",elc).text();}
  7239. if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {rp_ge[$t.p.id]._savedData[nm] = tmp;}
  7240. $(elc).addClass("FormElement");
  7241. if(this.edittype == 'text' || this.edittype == 'textarea') {
  7242. $(elc).addClass("ui-widget-content ui-corner-all");
  7243. }
  7244. trdata = $(tb).find("tr[rowpos="+rp+"]");
  7245. if(frmopt.rowabove) {
  7246. var newdata = $("<tr><td class='contentinfo' colspan='"+(maxcols*2)+"'>"+frmopt.rowcontent+"</td></tr>");
  7247. $(tb).append(newdata);
  7248. newdata[0].rp = rp;
  7249. }
  7250. if ( trdata.length===0 ) {
  7251. trdata = $("<tr "+dc+" rowpos='"+rp+"'></tr>").addClass("FormData").attr("id","tr_"+nm);
  7252. $(trdata).append(tmpl);
  7253. $(tb).append(trdata);
  7254. trdata[0].rp = rp;
  7255. }
  7256. $("td:eq("+(cp-2)+")",trdata[0]).html(frmopt.label === undefined ? obj.p.colNames[i]: frmopt.label);
  7257. $("td:eq("+(cp-1)+")",trdata[0]).append(frmopt.elmprefix).append(elc).append(frmopt.elmsuffix);
  7258. if($.isFunction(opt.custom_value) && rowid !== "_empty" ) {
  7259. opt.custom_value.call($t, $("#"+nm,"#"+frmgr),'set',tmp);
  7260. }
  7261. $.jgrid.bindEv( elc, opt, $t);
  7262. retpos[cnt] = i;
  7263. cnt++;
  7264. }
  7265. });
  7266. if( cnt > 0) {
  7267. 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='"+obj.p.id+"_id' value='"+rowid+"'/></td></tr>");
  7268. idrow[0].rp = cnt+999;
  7269. $(tb).append(idrow);
  7270. if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {rp_ge[$t.p.id]._savedData[obj.p.id+"_id"] = rowid;}
  7271. }
  7272. return retpos;
  7273. }
  7274. function fillData(rowid,obj,fmid){
  7275. var nm,cnt=0,tmp, fld,opt,vl,vlc;
  7276. if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {rp_ge[$t.p.id]._savedData = {};rp_ge[$t.p.id]._savedData[obj.p.id+"_id"]=rowid;}
  7277. var cm = obj.p.colModel;
  7278. if(rowid == '_empty') {
  7279. $(cm).each(function(){
  7280. nm = this.name;
  7281. opt = $.extend({}, this.editoptions || {} );
  7282. fld = $("#"+$.jgrid.jqID(nm),"#"+fmid);
  7283. if(fld && fld.length && fld[0] !== null) {
  7284. vl = "";
  7285. if(opt.defaultValue ) {
  7286. vl = $.isFunction(opt.defaultValue) ? opt.defaultValue.call($t) : opt.defaultValue;
  7287. if(fld[0].type=='checkbox') {
  7288. vlc = vl.toLowerCase();
  7289. if(vlc.search(/(false|0|no|off|undefined)/i)<0 && vlc!=="") {
  7290. fld[0].checked = true;
  7291. fld[0].defaultChecked = true;
  7292. fld[0].value = vl;
  7293. } else {
  7294. fld[0].checked = false;
  7295. fld[0].defaultChecked = false;
  7296. }
  7297. } else {fld.val(vl);}
  7298. } else {
  7299. if( fld[0].type=='checkbox' ) {
  7300. fld[0].checked = false;
  7301. fld[0].defaultChecked = false;
  7302. vl = $(fld).attr("offval");
  7303. } else if (fld[0].type && fld[0].type.substr(0,6)=='select') {
  7304. fld[0].selectedIndex = 0;
  7305. } else {
  7306. fld.val(vl);
  7307. }
  7308. }
  7309. if(rp_ge[$t.p.id].checkOnSubmit===true || rp_ge[$t.p.id].checkOnUpdate) {rp_ge[$t.p.id]._savedData[nm] = vl;}
  7310. }
  7311. });
  7312. $("#id_g","#"+fmid).val(rowid);
  7313. return;
  7314. }
  7315. var tre = $(obj).jqGrid("getInd",rowid,true);
  7316. if(!tre) {return;}
  7317. $('td[role="gridcell"]',tre).each( function(i) {
  7318. nm = cm[i].name;
  7319. // hidden fields are included in the form
  7320. if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn' && cm[i].editable===true) {
  7321. if(nm == obj.p.ExpandColumn && obj.p.treeGrid === true) {
  7322. tmp = $(this).text();
  7323. } else {
  7324. try {
  7325. tmp = $.unformat.call(obj, $(this),{rowId:rowid, colModel:cm[i]},i);
  7326. } catch (_) {
  7327. tmp = cm[i].edittype=="textarea" ? $(this).text() : $(this).html();
  7328. }
  7329. }
  7330. if($t.p.autoencode) {tmp = $.jgrid.htmlDecode(tmp);}
  7331. if(rp_ge[$t.p.id].checkOnSubmit===true || rp_ge[$t.p.id].checkOnUpdate) {rp_ge[$t.p.id]._savedData[nm] = tmp;}
  7332. nm = $.jgrid.jqID(nm);
  7333. switch (cm[i].edittype) {
  7334. case "password":
  7335. case "text":
  7336. case "button" :
  7337. case "image":
  7338. case "textarea":
  7339. if(tmp == "&nbsp;" || tmp == "&#160;" || (tmp.length==1 && tmp.charCodeAt(0)==160) ) {tmp='';}
  7340. $("#"+nm,"#"+fmid).val(tmp);
  7341. break;
  7342. case "select":
  7343. var opv = tmp.split(",");
  7344. opv = $.map(opv,function(n){return $.trim(n);});
  7345. $("#"+nm+" option","#"+fmid).each(function(){
  7346. if (!cm[i].editoptions.multiple && ($.trim(tmp) == $.trim($(this).text()) || opv[0] == $.trim($(this).text()) || opv[0] == $.trim($(this).val())) ){
  7347. this.selected= true;
  7348. } else if (cm[i].editoptions.multiple){
  7349. if( $.inArray($.trim($(this).text()), opv ) > -1 || $.inArray($.trim($(this).val()), opv ) > -1 ){
  7350. this.selected = true;
  7351. }else{
  7352. this.selected = false;
  7353. }
  7354. } else {
  7355. this.selected = false;
  7356. }
  7357. });
  7358. break;
  7359. case "checkbox":
  7360. tmp = String(tmp);
  7361. if(cm[i].editoptions && cm[i].editoptions.value) {
  7362. var cb = cm[i].editoptions.value.split(":");
  7363. if(cb[0] == tmp) {
  7364. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("checked",true);
  7365. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("defaultChecked",true); //ie
  7366. } else {
  7367. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("checked", false);
  7368. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("defaultChecked", false); //ie
  7369. }
  7370. } else {
  7371. tmp = tmp.toLowerCase();
  7372. if(tmp.search(/(false|0|no|off|undefined)/i)<0 && tmp!=="") {
  7373. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("checked",true);
  7374. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("defaultChecked",true); //ie
  7375. } else {
  7376. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("checked", false);
  7377. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("defaultChecked", false); //ie
  7378. }
  7379. }
  7380. break;
  7381. case 'custom' :
  7382. try {
  7383. if(cm[i].editoptions && $.isFunction(cm[i].editoptions.custom_value)) {
  7384. cm[i].editoptions.custom_value.call($t, $("#"+nm,"#"+fmid),'set',tmp);
  7385. } else {throw "e1";}
  7386. } catch (e) {
  7387. if (e=="e1") {$.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.nodefined,$.jgrid.edit.bClose);}
  7388. else {$.jgrid.info_dialog($.jgrid.errors.errcap,e.message,$.jgrid.edit.bClose);}
  7389. }
  7390. break;
  7391. }
  7392. cnt++;
  7393. }
  7394. });
  7395. if(cnt>0) {$("#id_g",frmtb).val(rowid);}
  7396. }
  7397. function setNulls() {
  7398. $.each($t.p.colModel, function(i,n){
  7399. if(n.editoptions && n.editoptions.NullIfEmpty === true) {
  7400. if(postdata.hasOwnProperty(n.name) && postdata[n.name] === "") {
  7401. postdata[n.name] = 'null';
  7402. }
  7403. }
  7404. });
  7405. }
  7406. function postIt() {
  7407. var copydata, ret=[true,"",""], onCS = {}, opers = $t.p.prmNames, idname, oper, key, selr, i;
  7408. var retvals = $($t).triggerHandler("jqGridAddEditBeforeCheckValues", [$("#"+frmgr), frmoper]);
  7409. if(retvals && typeof retvals === 'object') {postdata = retvals;}
  7410. if($.isFunction(rp_ge[$t.p.id].beforeCheckValues)) {
  7411. retvals = rp_ge[$t.p.id].beforeCheckValues.call($t, postdata,$("#"+frmgr),postdata[$t.p.id+"_id"] == "_empty" ? opers.addoper : opers.editoper);
  7412. if(retvals && typeof retvals === 'object') {postdata = retvals;}
  7413. }
  7414. for( key in postdata ){
  7415. if(postdata.hasOwnProperty(key)) {
  7416. ret = $.jgrid.checkValues.call($t,postdata[key],key,$t);
  7417. if(ret[0] === false) {break;}
  7418. }
  7419. }
  7420. setNulls();
  7421. if(ret[0]) {
  7422. onCS = $($t).triggerHandler("jqGridAddEditClickSubmit", [rp_ge[$t.p.id], postdata, frmoper]);
  7423. if( onCS === undefined && $.isFunction( rp_ge[$t.p.id].onclickSubmit)) {
  7424. onCS = rp_ge[$t.p.id].onclickSubmit.call($t, rp_ge[$t.p.id], postdata) || {};
  7425. }
  7426. ret = $($t).triggerHandler("jqGridAddEditBeforeSubmit", [postdata, $("#"+frmgr), frmoper]);
  7427. if(ret === undefined) {
  7428. ret = [true,"",""];
  7429. }
  7430. if( ret[0] && $.isFunction(rp_ge[$t.p.id].beforeSubmit)) {
  7431. ret = rp_ge[$t.p.id].beforeSubmit.call($t,postdata,$("#"+frmgr));
  7432. }
  7433. }
  7434. if(ret[0] && !rp_ge[$t.p.id].processing) {
  7435. rp_ge[$t.p.id].processing = true;
  7436. $("#sData", frmtb+"_2").addClass('ui-state-active');
  7437. oper = opers.oper;
  7438. idname = opers.id;
  7439. // we add to pos data array the action - the name is oper
  7440. postdata[oper] = ($.trim(postdata[$t.p.id+"_id"]) == "_empty") ? opers.addoper : opers.editoper;
  7441. if(postdata[oper] != opers.addoper) {
  7442. postdata[idname] = postdata[$t.p.id+"_id"];
  7443. } else {
  7444. // check to see if we have allredy this field in the form and if yes lieve it
  7445. if( postdata[idname] === undefined ) {postdata[idname] = postdata[$t.p.id+"_id"];}
  7446. }
  7447. delete postdata[$t.p.id+"_id"];
  7448. postdata = $.extend(postdata,rp_ge[$t.p.id].editData,onCS);
  7449. if($t.p.treeGrid === true) {
  7450. if(postdata[oper] == opers.addoper) {
  7451. selr = $($t).jqGrid("getGridParam", 'selrow');
  7452. var tr_par_id = $t.p.treeGridModel == 'adjacency' ? $t.p.treeReader.parent_id_field : 'parent_id';
  7453. postdata[tr_par_id] = selr;
  7454. }
  7455. for(i in $t.p.treeReader){
  7456. if($t.p.treeReader.hasOwnProperty(i)) {
  7457. var itm = $t.p.treeReader[i];
  7458. if(postdata.hasOwnProperty(itm)) {
  7459. if(postdata[oper] == opers.addoper && i === 'parent_id_field') {continue;}
  7460. delete postdata[itm];
  7461. }
  7462. }
  7463. }
  7464. }
  7465. postdata[idname] = $.jgrid.stripPref($t.p.idPrefix, postdata[idname]);
  7466. var ajaxOptions = $.extend({
  7467. url: rp_ge[$t.p.id].url || $($t).jqGrid('getGridParam','editurl'),
  7468. type: rp_ge[$t.p.id].mtype,
  7469. data: $.isFunction(rp_ge[$t.p.id].serializeEditData) ? rp_ge[$t.p.id].serializeEditData.call($t,postdata) : postdata,
  7470. complete:function(data,status){
  7471. var key;
  7472. postdata[idname] = $t.p.idPrefix + postdata[idname];
  7473. if(status != "success") {
  7474. ret[0] = false;
  7475. ret[1] = $($t).triggerHandler("jqGridAddEditErrorTextFormat", [data, frmoper]);
  7476. if ($.isFunction(rp_ge[$t.p.id].errorTextFormat)) {
  7477. ret[1] = rp_ge[$t.p.id].errorTextFormat.call($t, data);
  7478. } else {
  7479. ret[1] = status + " Status: '" + data.statusText + "'. Error code: " + data.status;
  7480. }
  7481. } else {
  7482. // data is posted successful
  7483. // execute aftersubmit with the returned data from server
  7484. ret = $($t).triggerHandler("jqGridAddEditAfterSubmit", [data, postdata, frmoper]);
  7485. if(ret === undefined) {
  7486. ret = [true,"",""];
  7487. }
  7488. if( ret[0] && $.isFunction(rp_ge[$t.p.id].afterSubmit) ) {
  7489. ret = rp_ge[$t.p.id].afterSubmit.call($t, data,postdata);
  7490. }
  7491. }
  7492. if(ret[0] === false) {
  7493. $("#FormError>td",frmtb).html(ret[1]);
  7494. $("#FormError",frmtb).show();
  7495. } else {
  7496. // remove some values if formattaer select or checkbox
  7497. $.each($t.p.colModel, function(){
  7498. if(extpost[this.name] && this.formatter && this.formatter=='select') {
  7499. try {delete extpost[this.name];} catch (e) {}
  7500. }
  7501. });
  7502. postdata = $.extend(postdata,extpost);
  7503. if($t.p.autoencode) {
  7504. $.each(postdata,function(n,v){
  7505. postdata[n] = $.jgrid.htmlDecode(v);
  7506. });
  7507. }
  7508. //rp_ge[$t.p.id].reloadAfterSubmit = rp_ge[$t.p.id].reloadAfterSubmit && $t.p.datatype != "local";
  7509. // the action is add
  7510. if(postdata[oper] == opers.addoper ) {
  7511. //id processing
  7512. // user not set the id ret[2]
  7513. if(!ret[2]) {ret[2] = $.jgrid.randId();}
  7514. postdata[idname] = ret[2];
  7515. if(rp_ge[$t.p.id].closeAfterAdd) {
  7516. if(rp_ge[$t.p.id].reloadAfterSubmit) {$($t).trigger("reloadGrid");}
  7517. else {
  7518. if($t.p.treeGrid === true){
  7519. $($t).jqGrid("addChildNode",ret[2],selr,postdata );
  7520. } else {
  7521. $($t).jqGrid("addRowData",ret[2],postdata,p.addedrow);
  7522. $($t).jqGrid("setSelection",ret[2]);
  7523. }
  7524. }
  7525. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose});
  7526. } else if (rp_ge[$t.p.id].clearAfterAdd) {
  7527. if(rp_ge[$t.p.id].reloadAfterSubmit) {$($t).trigger("reloadGrid");}
  7528. else {
  7529. if($t.p.treeGrid === true){
  7530. $($t).jqGrid("addChildNode",ret[2],selr,postdata );
  7531. } else {
  7532. $($t).jqGrid("addRowData",ret[2],postdata,p.addedrow);
  7533. }
  7534. }
  7535. fillData("_empty",$t,frmgr);
  7536. } else {
  7537. if(rp_ge[$t.p.id].reloadAfterSubmit) {$($t).trigger("reloadGrid");}
  7538. else {
  7539. if($t.p.treeGrid === true){
  7540. $($t).jqGrid("addChildNode",ret[2],selr,postdata );
  7541. } else {
  7542. $($t).jqGrid("addRowData",ret[2],postdata,p.addedrow);
  7543. }
  7544. }
  7545. }
  7546. } else {
  7547. // the action is update
  7548. if(rp_ge[$t.p.id].reloadAfterSubmit) {
  7549. $($t).trigger("reloadGrid");
  7550. if( !rp_ge[$t.p.id].closeAfterEdit ) {setTimeout(function(){$($t).jqGrid("setSelection",postdata[idname]);},1000);}
  7551. } else {
  7552. if($t.p.treeGrid === true) {
  7553. $($t).jqGrid("setTreeRow", postdata[idname],postdata);
  7554. } else {
  7555. $($t).jqGrid("setRowData", postdata[idname],postdata);
  7556. }
  7557. }
  7558. 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});}
  7559. }
  7560. if($.isFunction(rp_ge[$t.p.id].afterComplete)) {
  7561. copydata = data;
  7562. setTimeout(function(){
  7563. $($t).triggerHandler("jqGridAddEditAfterComplete", [copydata, postdata, $("#"+frmgr), frmoper]);
  7564. rp_ge[$t.p.id].afterComplete.call($t, copydata, postdata, $("#"+frmgr));
  7565. copydata=null;
  7566. },500);
  7567. }
  7568. if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {
  7569. $("#"+frmgr).data("disabled",false);
  7570. if(rp_ge[$t.p.id]._savedData[$t.p.id+"_id"] !="_empty"){
  7571. for(key in rp_ge[$t.p.id]._savedData) {
  7572. if(rp_ge[$t.p.id]._savedData.hasOwnProperty(key) && postdata[key]) {
  7573. rp_ge[$t.p.id]._savedData[key] = postdata[key];
  7574. }
  7575. }
  7576. }
  7577. }
  7578. }
  7579. rp_ge[$t.p.id].processing=false;
  7580. $("#sData", frmtb+"_2").removeClass('ui-state-active');
  7581. try{$(':input:visible',"#"+frmgr)[0].focus();} catch (e){}
  7582. }
  7583. }, $.jgrid.ajaxOptions, rp_ge[$t.p.id].ajaxEditOptions );
  7584. if (!ajaxOptions.url && !rp_ge[$t.p.id].useDataProxy) {
  7585. if ($.isFunction($t.p.dataProxy)) {
  7586. rp_ge[$t.p.id].useDataProxy = true;
  7587. } else {
  7588. ret[0]=false;ret[1] += " "+$.jgrid.errors.nourl;
  7589. }
  7590. }
  7591. if (ret[0]) {
  7592. if (rp_ge[$t.p.id].useDataProxy) {
  7593. var dpret = $t.p.dataProxy.call($t, ajaxOptions, "set_"+$t.p.id);
  7594. if(dpret === undefined) {
  7595. dpret = [true, ""];
  7596. }
  7597. if(dpret[0] === false ) {
  7598. ret[0] = false;
  7599. ret[1] = dpret[1] || "Error deleting the selected row!" ;
  7600. } else {
  7601. if(ajaxOptions.data.oper == opers.addoper && rp_ge[$t.p.id].closeAfterAdd ) {
  7602. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});
  7603. }
  7604. if(ajaxOptions.data.oper == opers.editoper && rp_ge[$t.p.id].closeAfterEdit ) {
  7605. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});
  7606. }
  7607. }
  7608. } else {
  7609. $.ajax(ajaxOptions);
  7610. }
  7611. }
  7612. }
  7613. if(ret[0] === false) {
  7614. $("#FormError>td",frmtb).html(ret[1]);
  7615. $("#FormError",frmtb).show();
  7616. // return;
  7617. }
  7618. }
  7619. function compareData(nObj, oObj ) {
  7620. var ret = false,key;
  7621. for (key in nObj) {
  7622. if(nObj.hasOwnProperty(key) && nObj[key] != oObj[key]) {
  7623. ret = true;
  7624. break;
  7625. }
  7626. }
  7627. return ret;
  7628. }
  7629. function checkUpdates () {
  7630. var stat = true;
  7631. $("#FormError",frmtb).hide();
  7632. if(rp_ge[$t.p.id].checkOnUpdate) {
  7633. postdata = {};extpost={};
  7634. getFormData();
  7635. newData = $.extend({},postdata,extpost);
  7636. diff = compareData(newData,rp_ge[$t.p.id]._savedData);
  7637. if(diff) {
  7638. $("#"+frmgr).data("disabled",true);
  7639. $(".confirm","#"+IDs.themodal).show();
  7640. stat = false;
  7641. }
  7642. }
  7643. return stat;
  7644. }
  7645. function restoreInline()
  7646. {
  7647. var i;
  7648. if (rowid !== "_empty" && $t.p.savedRow !== undefined && $t.p.savedRow.length > 0 && $.isFunction($.fn.jqGrid.restoreRow)) {
  7649. for (i=0;i<$t.p.savedRow.length;i++) {
  7650. if ($t.p.savedRow[i].id == rowid) {
  7651. $($t).jqGrid('restoreRow',rowid);
  7652. break;
  7653. }
  7654. }
  7655. }
  7656. }
  7657. function updateNav(cr, posarr){
  7658. var totr = posarr[1].length-1;
  7659. if (cr===0) {
  7660. $("#pData",frmtb+"_2").addClass('ui-state-disabled');
  7661. } else if( posarr[1][cr-1] !== undefined && $("#"+$.jgrid.jqID(posarr[1][cr-1])).hasClass('ui-state-disabled')) {
  7662. $("#pData",frmtb+"_2").addClass('ui-state-disabled');
  7663. } else {
  7664. $("#pData",frmtb+"_2").removeClass('ui-state-disabled');
  7665. }
  7666. if (cr==totr) {
  7667. $("#nData",frmtb+"_2").addClass('ui-state-disabled');
  7668. } else if( posarr[1][cr+1] !== undefined && $("#"+$.jgrid.jqID(posarr[1][cr+1])).hasClass('ui-state-disabled')) {
  7669. $("#nData",frmtb+"_2").addClass('ui-state-disabled');
  7670. } else {
  7671. $("#nData",frmtb+"_2").removeClass('ui-state-disabled');
  7672. }
  7673. }
  7674. function getCurrPos() {
  7675. var rowsInGrid = $($t).jqGrid("getDataIDs"),
  7676. selrow = $("#id_g",frmtb).val(),
  7677. pos = $.inArray(selrow,rowsInGrid);
  7678. return [pos,rowsInGrid];
  7679. }
  7680. if ( $("#"+$.jgrid.jqID(IDs.themodal))[0] !== undefined ) {
  7681. showFrm = $($t).triggerHandler("jqGridAddEditBeforeInitData", [$("#"+$.jgrid.jqID(frmgr)), frmoper]);
  7682. if(showFrm === undefined) {
  7683. showFrm = true;
  7684. }
  7685. if(showFrm && onBeforeInit) {
  7686. showFrm = onBeforeInit.call($t,$("#"+frmgr));
  7687. }
  7688. if(showFrm === false) {return;}
  7689. restoreInline();
  7690. $(".ui-jqdialog-title","#"+$.jgrid.jqID(IDs.modalhead)).html(p.caption);
  7691. $("#FormError",frmtb).hide();
  7692. if(rp_ge[$t.p.id].topinfo) {
  7693. $(".topinfo",frmtb).html(rp_ge[$t.p.id].topinfo);
  7694. $(".tinfo",frmtb).show();
  7695. } else {
  7696. $(".tinfo",frmtb).hide();
  7697. }
  7698. if(rp_ge[$t.p.id].bottominfo) {
  7699. $(".bottominfo",frmtb+"_2").html(rp_ge[$t.p.id].bottominfo);
  7700. $(".binfo",frmtb+"_2").show();
  7701. } else {
  7702. $(".binfo",frmtb+"_2").hide();
  7703. }
  7704. // filldata
  7705. fillData(rowid,$t,frmgr);
  7706. ///
  7707. if(rowid=="_empty" || !rp_ge[$t.p.id].viewPagerButtons) {
  7708. $("#pData, #nData",frmtb+"_2").hide();
  7709. } else {
  7710. $("#pData, #nData",frmtb+"_2").show();
  7711. }
  7712. if(rp_ge[$t.p.id].processing===true) {
  7713. rp_ge[$t.p.id].processing=false;
  7714. $("#sData", frmtb+"_2").removeClass('ui-state-active');
  7715. }
  7716. if($("#"+frmgr).data("disabled")===true) {
  7717. $(".confirm","#"+$.jgrid.jqID(IDs.themodal)).hide();
  7718. $("#"+frmgr).data("disabled",false);
  7719. }
  7720. $($t).triggerHandler("jqGridAddEditBeforeShowForm", [$("#"+frmgr), frmoper]);
  7721. if(onBeforeShow) { onBeforeShow.call($t, $("#"+frmgr)); }
  7722. $("#"+$.jgrid.jqID(IDs.themodal)).data("onClose",rp_ge[$t.p.id].onClose);
  7723. $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{gbox:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, jqM: false, overlay: p.overlay, modal:p.modal});
  7724. if(!closeovrl) {
  7725. $(".jqmOverlay").click(function(){
  7726. if(!checkUpdates()) {return false;}
  7727. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});
  7728. return false;
  7729. });
  7730. }
  7731. $($t).triggerHandler("jqGridAddEditAfterShowForm", [$("#"+frmgr), frmoper]);
  7732. if(onAfterShow) { onAfterShow.call($t, $("#"+frmgr)); }
  7733. } else {
  7734. var dh = isNaN(p.dataheight) ? p.dataheight : p.dataheight+"px",
  7735. frm = $("<form name='FormPost' id='"+frmgr+"' class='FormGrid' onSubmit='return false;' style='width:100%;overflow:auto;position:relative;height:"+dh+";'></form>").data("disabled",false),
  7736. tbl = $("<table id='"+frmtborg+"' class='EditTable' cellspacing='0' cellpadding='0' border='0'><tbody></tbody></table>");
  7737. showFrm = $($t).triggerHandler("jqGridAddEditBeforeInitData", [$("#"+frmgr), frmoper]);
  7738. if(showFrm === undefined) {
  7739. showFrm = true;
  7740. }
  7741. if(showFrm && onBeforeInit) {
  7742. showFrm = onBeforeInit.call($t,$("#"+frmgr));
  7743. }
  7744. if(showFrm === false) {return;}
  7745. restoreInline();
  7746. $($t.p.colModel).each( function() {
  7747. var fmto = this.formoptions;
  7748. maxCols = Math.max(maxCols, fmto ? fmto.colpos || 0 : 0 );
  7749. maxRows = Math.max(maxRows, fmto ? fmto.rowpos || 0 : 0 );
  7750. });
  7751. $(frm).append(tbl);
  7752. var flr = $("<tr id='FormError' style='display:none'><td class='ui-state-error' colspan='"+(maxCols*2)+"'></td></tr>");
  7753. flr[0].rp = 0;
  7754. $(tbl).append(flr);
  7755. //topinfo
  7756. flr = $("<tr style='display:none' class='tinfo'><td class='topinfo' colspan='"+(maxCols*2)+"'>"+rp_ge[$t.p.id].topinfo+"</td></tr>");
  7757. flr[0].rp = 0;
  7758. $(tbl).append(flr);
  7759. // set the id.
  7760. // use carefull only to change here colproperties.
  7761. // create data
  7762. var rtlb = $t.p.direction == "rtl" ? true :false,
  7763. bp = rtlb ? "nData" : "pData",
  7764. bn = rtlb ? "pData" : "nData";
  7765. createData(rowid,$t,tbl,maxCols);
  7766. // buttons at footer
  7767. var bP = "<a href='javascript:void(0)' id='"+bp+"' class='fm-button ui-state-default ui-corner-left'><span class='ui-icon ui-icon-triangle-1-w'></span></a>",
  7768. bN = "<a href='javascript:void(0)' id='"+bn+"' class='fm-button ui-state-default ui-corner-right'><span class='ui-icon ui-icon-triangle-1-e'></span></a>",
  7769. bS ="<a href='javascript:void(0)' id='sData' class='fm-button ui-state-default ui-corner-all'>"+p.bSubmit+"</a>",
  7770. bC ="<a href='javascript:void(0)' id='cData' class='fm-button ui-state-default ui-corner-all'>"+p.bCancel+"</a>";
  7771. var bt = "<table border='0' cellspacing='0' cellpadding='0' class='EditTable' id='"+frmtborg+"_2'><tbody><tr><td colspan='2'><hr class='ui-widget-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>";
  7772. bt += "<tr style='display:none' class='binfo'><td class='bottominfo' colspan='2'>"+rp_ge[$t.p.id].bottominfo+"</td></tr>";
  7773. bt += "</tbody></table>";
  7774. if(maxRows > 0) {
  7775. var sd=[];
  7776. $.each($(tbl)[0].rows,function(i,r){
  7777. sd[i] = r;
  7778. });
  7779. sd.sort(function(a,b){
  7780. if(a.rp > b.rp) {return 1;}
  7781. if(a.rp < b.rp) {return -1;}
  7782. return 0;
  7783. });
  7784. $.each(sd, function(index, row) {
  7785. $('tbody',tbl).append(row);
  7786. });
  7787. }
  7788. p.gbox = "#gbox_"+$.jgrid.jqID(gID);
  7789. var cle = false;
  7790. if(p.closeOnEscape===true){
  7791. p.closeOnEscape = false;
  7792. cle = true;
  7793. }
  7794. var tms = $("<span></span>").append(frm).append(bt);
  7795. $.jgrid.createModal(IDs,tms,p,"#gview_"+$.jgrid.jqID($t.p.id),$("#gbox_"+$.jgrid.jqID($t.p.id))[0]);
  7796. if(rtlb) {
  7797. $("#pData, #nData",frmtb+"_2").css("float","right");
  7798. $(".EditButton",frmtb+"_2").css("text-align","left");
  7799. }
  7800. if(rp_ge[$t.p.id].topinfo) {$(".tinfo",frmtb).show();}
  7801. if(rp_ge[$t.p.id].bottominfo) {$(".binfo",frmtb+"_2").show();}
  7802. tms = null;bt=null;
  7803. $("#"+$.jgrid.jqID(IDs.themodal)).keydown( function( e ) {
  7804. var wkey = e.target;
  7805. if ($("#"+frmgr).data("disabled")===true ) {return false;}//??
  7806. if(rp_ge[$t.p.id].savekey[0] === true && e.which == rp_ge[$t.p.id].savekey[1]) { // save
  7807. if(wkey.tagName != "TEXTAREA") {
  7808. $("#sData", frmtb+"_2").trigger("click");
  7809. return false;
  7810. }
  7811. }
  7812. if(e.which === 27) {
  7813. if(!checkUpdates()) {return false;}
  7814. if(cle) {$.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:p.gbox,jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});}
  7815. return false;
  7816. }
  7817. if(rp_ge[$t.p.id].navkeys[0]===true) {
  7818. if($("#id_g",frmtb).val() == "_empty") {return true;}
  7819. if(e.which == rp_ge[$t.p.id].navkeys[1]){ //up
  7820. $("#pData", frmtb+"_2").trigger("click");
  7821. return false;
  7822. }
  7823. if(e.which == rp_ge[$t.p.id].navkeys[2]){ //down
  7824. $("#nData", frmtb+"_2").trigger("click");
  7825. return false;
  7826. }
  7827. }
  7828. });
  7829. if(p.checkOnUpdate) {
  7830. $("a.ui-jqdialog-titlebar-close span","#"+$.jgrid.jqID(IDs.themodal)).removeClass("jqmClose");
  7831. $("a.ui-jqdialog-titlebar-close","#"+$.jgrid.jqID(IDs.themodal)).unbind("click")
  7832. .click(function(){
  7833. if(!checkUpdates()) {return false;}
  7834. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose});
  7835. return false;
  7836. });
  7837. }
  7838. p.saveicon = $.extend([true,"left","ui-icon-disk"],p.saveicon);
  7839. p.closeicon = $.extend([true,"left","ui-icon-close"],p.closeicon);
  7840. // beforeinitdata after creation of the form
  7841. if(p.saveicon[0]===true) {
  7842. $("#sData",frmtb+"_2").addClass(p.saveicon[1] == "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  7843. .append("<span class='ui-icon "+p.saveicon[2]+"'></span>");
  7844. }
  7845. if(p.closeicon[0]===true) {
  7846. $("#cData",frmtb+"_2").addClass(p.closeicon[1] == "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  7847. .append("<span class='ui-icon "+p.closeicon[2]+"'></span>");
  7848. }
  7849. if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {
  7850. bS ="<a href='javascript:void(0)' id='sNew' class='fm-button ui-state-default ui-corner-all' style='z-index:1002'>"+p.bYes+"</a>";
  7851. bN ="<a href='javascript:void(0)' id='nNew' class='fm-button ui-state-default ui-corner-all' style='z-index:1002'>"+p.bNo+"</a>";
  7852. bC ="<a href='javascript:void(0)' id='cNew' class='fm-button ui-state-default ui-corner-all' style='z-index:1002'>"+p.bExit+"</a>";
  7853. var ii, zI = p.zIndex || 999;zI ++;
  7854. if ($.browser.msie && $.browser.version ==6) {
  7855. ii = '<iframe style="display:block;position:absolute;z-index:-1;filter:Alpha(Opacity=\'0\');" src="javascript:false;"></iframe>';
  7856. } else {ii="";}
  7857. $("<div class='ui-widget-overlay jqgrid-overlay confirm' style='z-index:"+zI+";display:none;'>&#160;"+ii+"</div><div class='confirm ui-widget-content ui-jqconfirm' style='z-index:"+(zI+1)+"'>"+p.saveData+"<br/><br/>"+bS+bN+bC+"</div>").insertAfter("#"+frmgr);
  7858. $("#sNew","#"+$.jgrid.jqID(IDs.themodal)).click(function(){
  7859. postIt();
  7860. $("#"+frmgr).data("disabled",false);
  7861. $(".confirm","#"+$.jgrid.jqID(IDs.themodal)).hide();
  7862. return false;
  7863. });
  7864. $("#nNew","#"+$.jgrid.jqID(IDs.themodal)).click(function(){
  7865. $(".confirm","#"+$.jgrid.jqID(IDs.themodal)).hide();
  7866. $("#"+frmgr).data("disabled",false);
  7867. setTimeout(function(){$(":input","#"+frmgr)[0].focus();},0);
  7868. return false;
  7869. });
  7870. $("#cNew","#"+$.jgrid.jqID(IDs.themodal)).click(function(){
  7871. $(".confirm","#"+$.jgrid.jqID(IDs.themodal)).hide();
  7872. $("#"+frmgr).data("disabled",false);
  7873. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose});
  7874. return false;
  7875. });
  7876. }
  7877. // here initform - only once
  7878. $($t).triggerHandler("jqGridAddEditInitializeForm", [$("#"+frmgr), frmoper]);
  7879. if(onInitializeForm) {onInitializeForm.call($t,$("#"+frmgr));}
  7880. if(rowid=="_empty" || !rp_ge[$t.p.id].viewPagerButtons) {$("#pData,#nData",frmtb+"_2").hide();} else {$("#pData,#nData",frmtb+"_2").show();}
  7881. $($t).triggerHandler("jqGridAddEditBeforeShowForm", [$("#"+frmgr), frmoper]);
  7882. if(onBeforeShow) { onBeforeShow.call($t, $("#"+frmgr));}
  7883. $("#"+$.jgrid.jqID(IDs.themodal)).data("onClose",rp_ge[$t.p.id].onClose);
  7884. $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{gbox:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, overlay: p.overlay,modal:p.modal});
  7885. if(!closeovrl) {
  7886. $(".jqmOverlay").click(function(){
  7887. if(!checkUpdates()) {return false;}
  7888. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});
  7889. return false;
  7890. });
  7891. }
  7892. $($t).triggerHandler("jqGridAddEditAfterShowForm", [$("#"+frmgr), frmoper]);
  7893. if(onAfterShow) { onAfterShow.call($t, $("#"+frmgr)); }
  7894. $(".fm-button","#"+$.jgrid.jqID(IDs.themodal)).hover(
  7895. function(){$(this).addClass('ui-state-hover');},
  7896. function(){$(this).removeClass('ui-state-hover');}
  7897. );
  7898. $("#sData", frmtb+"_2").click(function(){
  7899. postdata = {};extpost={};
  7900. $("#FormError",frmtb).hide();
  7901. // all depend on ret array
  7902. //ret[0] - succes
  7903. //ret[1] - msg if not succes
  7904. //ret[2] - the id that will be set if reload after submit false
  7905. getFormData();
  7906. if(postdata[$t.p.id+"_id"] == "_empty") {postIt();}
  7907. else if(p.checkOnSubmit===true ) {
  7908. newData = $.extend({},postdata,extpost);
  7909. diff = compareData(newData,rp_ge[$t.p.id]._savedData);
  7910. if(diff) {
  7911. $("#"+frmgr).data("disabled",true);
  7912. $(".confirm","#"+$.jgrid.jqID(IDs.themodal)).show();
  7913. } else {
  7914. postIt();
  7915. }
  7916. } else {
  7917. postIt();
  7918. }
  7919. return false;
  7920. });
  7921. $("#cData", frmtb+"_2").click(function(){
  7922. if(!checkUpdates()) {return false;}
  7923. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose});
  7924. return false;
  7925. });
  7926. $("#nData", frmtb+"_2").click(function(){
  7927. if(!checkUpdates()) {return false;}
  7928. $("#FormError",frmtb).hide();
  7929. var npos = getCurrPos();
  7930. npos[0] = parseInt(npos[0],10);
  7931. if(npos[0] != -1 && npos[1][npos[0]+1]) {
  7932. $($t).triggerHandler("jqGridAddEditClickPgButtons", ['next',$("#"+frmgr),npos[1][npos[0]]]);
  7933. var nposret;
  7934. if($.isFunction(p.onclickPgButtons)) {
  7935. nposret = p.onclickPgButtons.call($t, 'next',$("#"+frmgr),npos[1][npos[0]]);
  7936. if( nposret !== undefined && nposret === false ) {return false;}
  7937. }
  7938. if( $("#"+$.jgrid.jqID(npos[1][npos[0]+1])).hasClass('ui-state-disabled')) {return false;}
  7939. fillData(npos[1][npos[0]+1],$t,frmgr);
  7940. $($t).jqGrid("setSelection",npos[1][npos[0]+1]);
  7941. $($t).triggerHandler("jqGridAddEditAfterClickPgButtons", ['next',$("#"+frmgr),npos[1][npos[0]]]);
  7942. if($.isFunction(p.afterclickPgButtons)) {
  7943. p.afterclickPgButtons.call($t, 'next',$("#"+frmgr),npos[1][npos[0]+1]);
  7944. }
  7945. updateNav(npos[0]+1,npos);
  7946. }
  7947. return false;
  7948. });
  7949. $("#pData", frmtb+"_2").click(function(){
  7950. if(!checkUpdates()) {return false;}
  7951. $("#FormError",frmtb).hide();
  7952. var ppos = getCurrPos();
  7953. if(ppos[0] != -1 && ppos[1][ppos[0]-1]) {
  7954. $($t).triggerHandler("jqGridAddEditClickPgButtons", ['prev',$("#"+frmgr),ppos[1][ppos[0]]]);
  7955. var pposret;
  7956. if($.isFunction(p.onclickPgButtons)) {
  7957. pposret = p.onclickPgButtons.call($t, 'prev',$("#"+frmgr),ppos[1][ppos[0]]);
  7958. if( pposret !== undefined && pposret === false ) {return false;}
  7959. }
  7960. if( $("#"+$.jgrid.jqID(ppos[1][ppos[0]-1])).hasClass('ui-state-disabled')) {return false;}
  7961. fillData(ppos[1][ppos[0]-1],$t,frmgr);
  7962. $($t).jqGrid("setSelection",ppos[1][ppos[0]-1]);
  7963. $($t).triggerHandler("jqGridAddEditAfterClickPgButtons", ['prev',$("#"+frmgr),ppos[1][ppos[0]]]);
  7964. if($.isFunction(p.afterclickPgButtons)) {
  7965. p.afterclickPgButtons.call($t, 'prev',$("#"+frmgr),ppos[1][ppos[0]-1]);
  7966. }
  7967. updateNav(ppos[0]-1,ppos);
  7968. }
  7969. return false;
  7970. });
  7971. }
  7972. var posInit =getCurrPos();
  7973. updateNav(posInit[0],posInit);
  7974. });
  7975. },
  7976. viewGridRow : function(rowid, p){
  7977. p = $.extend(true, {
  7978. top : 0,
  7979. left: 0,
  7980. width: 0,
  7981. height: 'auto',
  7982. dataheight: 'auto',
  7983. modal: false,
  7984. overlay: 30,
  7985. drag: true,
  7986. resize: true,
  7987. jqModal: true,
  7988. closeOnEscape : false,
  7989. labelswidth: '30%',
  7990. closeicon: [],
  7991. navkeys: [false,38,40],
  7992. onClose: null,
  7993. beforeShowForm : null,
  7994. beforeInitData : null,
  7995. viewPagerButtons : true
  7996. }, $.jgrid.view, p || {});
  7997. rp_ge[$(this)[0].p.id] = p;
  7998. return this.each(function(){
  7999. var $t = this;
  8000. if (!$t.grid || !rowid) {return;}
  8001. var gID = $t.p.id,
  8002. frmgr = "ViewGrid_"+$.jgrid.jqID( gID ), frmtb = "ViewTbl_" + $.jgrid.jqID( gID ),
  8003. frmgr_id = "ViewGrid_"+gID, frmtb_id = "ViewTbl_"+gID,
  8004. IDs = {themodal:'viewmod'+gID,modalhead:'viewhd'+gID,modalcontent:'viewcnt'+gID, scrollelm : frmgr},
  8005. onBeforeInit = $.isFunction(rp_ge[$t.p.id].beforeInitData) ? rp_ge[$t.p.id].beforeInitData : false,
  8006. showFrm = true,
  8007. maxCols = 1, maxRows=0;
  8008. function focusaref(){ //Sfari 3 issues
  8009. if(rp_ge[$t.p.id].closeOnEscape===true || rp_ge[$t.p.id].navkeys[0]===true) {
  8010. setTimeout(function(){$(".ui-jqdialog-titlebar-close","#"+$.jgrid.jqID(IDs.modalhead)).focus();},0);
  8011. }
  8012. }
  8013. function createData(rowid,obj,tb,maxcols){
  8014. var nm, hc,trdata, cnt=0,tmp, dc, retpos=[], ind=false, i,
  8015. tdtmpl = "<td class='CaptionTD form-view-label ui-widget-content' width='"+p.labelswidth+"'>&#160;</td><td class='DataTD form-view-data ui-helper-reset ui-widget-content'>&#160;</td>", tmpl="",
  8016. tdtmpl2 = "<td class='CaptionTD form-view-label ui-widget-content'>&#160;</td><td class='DataTD form-view-data ui-widget-content'>&#160;</td>",
  8017. fmtnum = ['integer','number','currency'],max1 =0, max2=0 ,maxw,setme, viewfld;
  8018. for (i=1;i<=maxcols;i++) {
  8019. tmpl += i == 1 ? tdtmpl : tdtmpl2;
  8020. }
  8021. // find max number align rigth with property formatter
  8022. $(obj.p.colModel).each( function() {
  8023. if(this.editrules && this.editrules.edithidden === true) {
  8024. hc = false;
  8025. } else {
  8026. hc = this.hidden === true ? true : false;
  8027. }
  8028. if(!hc && this.align==='right') {
  8029. if(this.formatter && $.inArray(this.formatter,fmtnum) !== -1 ) {
  8030. max1 = Math.max(max1,parseInt(this.width,10));
  8031. } else {
  8032. max2 = Math.max(max2,parseInt(this.width,10));
  8033. }
  8034. }
  8035. });
  8036. maxw = max1 !==0 ? max1 : max2 !==0 ? max2 : 0;
  8037. ind = $(obj).jqGrid("getInd",rowid);
  8038. $(obj.p.colModel).each( function(i) {
  8039. nm = this.name;
  8040. setme = false;
  8041. // hidden fields are included in the form
  8042. if(this.editrules && this.editrules.edithidden === true) {
  8043. hc = false;
  8044. } else {
  8045. hc = this.hidden === true ? true : false;
  8046. }
  8047. dc = hc ? "style='display:none'" : "";
  8048. viewfld = (typeof this.viewable !== 'boolean') ? true : this.viewable;
  8049. if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn' && viewfld) {
  8050. if(ind === false) {
  8051. tmp = "";
  8052. } else {
  8053. if(nm == obj.p.ExpandColumn && obj.p.treeGrid === true) {
  8054. tmp = $("td:eq("+i+")",obj.rows[ind]).text();
  8055. } else {
  8056. tmp = $("td:eq("+i+")",obj.rows[ind]).html();
  8057. }
  8058. }
  8059. setme = this.align === 'right' && maxw !==0 ? true : false;
  8060. var frmopt = $.extend({},{rowabove:false,rowcontent:''}, this.formoptions || {}),
  8061. rp = parseInt(frmopt.rowpos,10) || cnt+1,
  8062. cp = parseInt((parseInt(frmopt.colpos,10) || 1)*2,10);
  8063. if(frmopt.rowabove) {
  8064. var newdata = $("<tr><td class='contentinfo' colspan='"+(maxcols*2)+"'>"+frmopt.rowcontent+"</td></tr>");
  8065. $(tb).append(newdata);
  8066. newdata[0].rp = rp;
  8067. }
  8068. trdata = $(tb).find("tr[rowpos="+rp+"]");
  8069. if ( trdata.length===0 ) {
  8070. trdata = $("<tr "+dc+" rowpos='"+rp+"'></tr>").addClass("FormData").attr("id","trv_"+nm);
  8071. $(trdata).append(tmpl);
  8072. $(tb).append(trdata);
  8073. trdata[0].rp = rp;
  8074. }
  8075. $("td:eq("+(cp-2)+")",trdata[0]).html('<b>'+ (frmopt.label === undefined ? obj.p.colNames[i]: frmopt.label)+'</b>');
  8076. $("td:eq("+(cp-1)+")",trdata[0]).append("<span>"+tmp+"</span>").attr("id","v_"+nm);
  8077. if(setme){
  8078. $("td:eq("+(cp-1)+") span",trdata[0]).css({'text-align':'right',width:maxw+"px"});
  8079. }
  8080. retpos[cnt] = i;
  8081. cnt++;
  8082. }
  8083. });
  8084. if( cnt > 0) {
  8085. 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>");
  8086. idrow[0].rp = cnt+99;
  8087. $(tb).append(idrow);
  8088. }
  8089. return retpos;
  8090. }
  8091. function fillData(rowid,obj){
  8092. var nm, hc,cnt=0,tmp, opt,trv;
  8093. trv = $(obj).jqGrid("getInd",rowid,true);
  8094. if(!trv) {return;}
  8095. $('td',trv).each( function(i) {
  8096. nm = obj.p.colModel[i].name;
  8097. // hidden fields are included in the form
  8098. if(obj.p.colModel[i].editrules && obj.p.colModel[i].editrules.edithidden === true) {
  8099. hc = false;
  8100. } else {
  8101. hc = obj.p.colModel[i].hidden === true ? true : false;
  8102. }
  8103. if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn') {
  8104. if(nm == obj.p.ExpandColumn && obj.p.treeGrid === true) {
  8105. tmp = $(this).text();
  8106. } else {
  8107. tmp = $(this).html();
  8108. }
  8109. opt = $.extend({},obj.p.colModel[i].editoptions || {});
  8110. nm = $.jgrid.jqID("v_"+nm);
  8111. $("#"+nm+" span","#"+frmtb).html(tmp);
  8112. if (hc) {$("#"+nm,"#"+frmtb).parents("tr:first").hide();}
  8113. cnt++;
  8114. }
  8115. });
  8116. if(cnt>0) {$("#id_g","#"+frmtb).val(rowid);}
  8117. }
  8118. function updateNav(cr,posarr){
  8119. var totr = posarr[1].length-1;
  8120. if (cr===0) {
  8121. $("#pData","#"+frmtb+"_2").addClass('ui-state-disabled');
  8122. } else if( posarr[1][cr-1] !== undefined && $("#"+$.jgrid.jqID(posarr[1][cr-1])).hasClass('ui-state-disabled')) {
  8123. $("#pData",frmtb+"_2").addClass('ui-state-disabled');
  8124. } else {
  8125. $("#pData","#"+frmtb+"_2").removeClass('ui-state-disabled');
  8126. }
  8127. if (cr==totr) {
  8128. $("#nData","#"+frmtb+"_2").addClass('ui-state-disabled');
  8129. } else if( posarr[1][cr+1] !== undefined && $("#"+$.jgrid.jqID(posarr[1][cr+1])).hasClass('ui-state-disabled')) {
  8130. $("#nData",frmtb+"_2").addClass('ui-state-disabled');
  8131. } else {
  8132. $("#nData","#"+frmtb+"_2").removeClass('ui-state-disabled');
  8133. }
  8134. }
  8135. function getCurrPos() {
  8136. var rowsInGrid = $($t).jqGrid("getDataIDs"),
  8137. selrow = $("#id_g","#"+frmtb).val(),
  8138. pos = $.inArray(selrow,rowsInGrid);
  8139. return [pos,rowsInGrid];
  8140. }
  8141. if ( $("#"+$.jgrid.jqID(IDs.themodal))[0] !== undefined ) {
  8142. if(onBeforeInit) {
  8143. showFrm = onBeforeInit.call($t,$("#"+frmgr));
  8144. if(showFrm === undefined) {
  8145. showFrm = true;
  8146. }
  8147. }
  8148. if(showFrm === false) {return;}
  8149. $(".ui-jqdialog-title","#"+$.jgrid.jqID(IDs.modalhead)).html(p.caption);
  8150. $("#FormError","#"+frmtb).hide();
  8151. fillData(rowid,$t);
  8152. if($.isFunction(rp_ge[$t.p.id].beforeShowForm)) {rp_ge[$t.p.id].beforeShowForm.call($t,$("#"+frmgr));}
  8153. $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{gbox:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, jqM: false, overlay: p.overlay, modal:p.modal});
  8154. focusaref();
  8155. } else {
  8156. var dh = isNaN(p.dataheight) ? p.dataheight : p.dataheight+"px";
  8157. var frm = $("<form name='FormPost' id='"+frmgr_id+"' class='FormGrid' style='width:100%;overflow:auto;position:relative;height:"+dh+";'></form>"),
  8158. tbl =$("<table id='"+frmtb_id+"' class='EditTable' cellspacing='1' cellpadding='2' border='0' style='table-layout:fixed'><tbody></tbody></table>");
  8159. if(onBeforeInit) {
  8160. showFrm = onBeforeInit.call($t,$("#"+frmgr));
  8161. if(showFrm === undefined) {
  8162. showFrm = true;
  8163. }
  8164. }
  8165. if(showFrm === false) {return;}
  8166. $($t.p.colModel).each( function() {
  8167. var fmto = this.formoptions;
  8168. maxCols = Math.max(maxCols, fmto ? fmto.colpos || 0 : 0 );
  8169. maxRows = Math.max(maxRows, fmto ? fmto.rowpos || 0 : 0 );
  8170. });
  8171. // set the id.
  8172. $(frm).append(tbl);
  8173. createData(rowid, $t, tbl, maxCols);
  8174. var rtlb = $t.p.direction == "rtl" ? true :false,
  8175. bp = rtlb ? "nData" : "pData",
  8176. bn = rtlb ? "pData" : "nData",
  8177. // buttons at footer
  8178. bP = "<a href='javascript:void(0)' id='"+bp+"' class='fm-button ui-state-default ui-corner-left'><span class='ui-icon ui-icon-triangle-1-w'></span></a>",
  8179. bN = "<a href='javascript:void(0)' id='"+bn+"' class='fm-button ui-state-default ui-corner-right'><span class='ui-icon ui-icon-triangle-1-e'></span></a>",
  8180. bC ="<a href='javascript:void(0)' id='cData' class='fm-button ui-state-default ui-corner-all'>"+p.bClose+"</a>";
  8181. if(maxRows > 0) {
  8182. var sd=[];
  8183. $.each($(tbl)[0].rows,function(i,r){
  8184. sd[i] = r;
  8185. });
  8186. sd.sort(function(a,b){
  8187. if(a.rp > b.rp) {return 1;}
  8188. if(a.rp < b.rp) {return -1;}
  8189. return 0;
  8190. });
  8191. $.each(sd, function(index, row) {
  8192. $('tbody',tbl).append(row);
  8193. });
  8194. }
  8195. p.gbox = "#gbox_"+$.jgrid.jqID(gID);
  8196. var bt = $("<span></span>").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>");
  8197. $.jgrid.createModal(IDs,bt,p,"#gview_"+$.jgrid.jqID($t.p.id),$("#gview_"+$.jgrid.jqID($t.p.id))[0]);
  8198. if(rtlb) {
  8199. $("#pData, #nData","#"+frmtb+"_2").css("float","right");
  8200. $(".EditButton","#"+frmtb+"_2").css("text-align","left");
  8201. }
  8202. if(!p.viewPagerButtons) {$("#pData, #nData","#"+frmtb+"_2").hide();}
  8203. bt = null;
  8204. $("#"+IDs.themodal).keydown( function( e ) {
  8205. if(e.which === 27) {
  8206. if(rp_ge[$t.p.id].closeOnEscape) {$.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:p.gbox,jqm:p.jqModal, onClose: p.onClose});}
  8207. return false;
  8208. }
  8209. if(p.navkeys[0]===true) {
  8210. if(e.which === p.navkeys[1]){ //up
  8211. $("#pData", "#"+frmtb+"_2").trigger("click");
  8212. return false;
  8213. }
  8214. if(e.which === p.navkeys[2]){ //down
  8215. $("#nData", "#"+frmtb+"_2").trigger("click");
  8216. return false;
  8217. }
  8218. }
  8219. });
  8220. p.closeicon = $.extend([true,"left","ui-icon-close"],p.closeicon);
  8221. if(p.closeicon[0]===true) {
  8222. $("#cData","#"+frmtb+"_2").addClass(p.closeicon[1] == "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  8223. .append("<span class='ui-icon "+p.closeicon[2]+"'></span>");
  8224. }
  8225. if($.isFunction(p.beforeShowForm)) {p.beforeShowForm.call($t,$("#"+frmgr));}
  8226. $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{gbox:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, modal:p.modal});
  8227. $(".fm-button:not(.ui-state-disabled)","#"+frmtb+"_2").hover(
  8228. function(){$(this).addClass('ui-state-hover');},
  8229. function(){$(this).removeClass('ui-state-hover');}
  8230. );
  8231. focusaref();
  8232. $("#cData", "#"+frmtb+"_2").click(function(){
  8233. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: p.onClose});
  8234. return false;
  8235. });
  8236. $("#nData", "#"+frmtb+"_2").click(function(){
  8237. $("#FormError","#"+frmtb).hide();
  8238. var npos = getCurrPos();
  8239. npos[0] = parseInt(npos[0],10);
  8240. if(npos[0] != -1 && npos[1][npos[0]+1]) {
  8241. if($.isFunction(p.onclickPgButtons)) {
  8242. p.onclickPgButtons.call($t,'next',$("#"+frmgr),npos[1][npos[0]]);
  8243. }
  8244. fillData(npos[1][npos[0]+1],$t);
  8245. $($t).jqGrid("setSelection",npos[1][npos[0]+1]);
  8246. if($.isFunction(p.afterclickPgButtons)) {
  8247. p.afterclickPgButtons.call($t,'next',$("#"+frmgr),npos[1][npos[0]+1]);
  8248. }
  8249. updateNav(npos[0]+1,npos);
  8250. }
  8251. focusaref();
  8252. return false;
  8253. });
  8254. $("#pData", "#"+frmtb+"_2").click(function(){
  8255. $("#FormError","#"+frmtb).hide();
  8256. var ppos = getCurrPos();
  8257. if(ppos[0] != -1 && ppos[1][ppos[0]-1]) {
  8258. if($.isFunction(p.onclickPgButtons)) {
  8259. p.onclickPgButtons.call($t,'prev',$("#"+frmgr),ppos[1][ppos[0]]);
  8260. }
  8261. fillData(ppos[1][ppos[0]-1],$t);
  8262. $($t).jqGrid("setSelection",ppos[1][ppos[0]-1]);
  8263. if($.isFunction(p.afterclickPgButtons)) {
  8264. p.afterclickPgButtons.call($t,'prev',$("#"+frmgr),ppos[1][ppos[0]-1]);
  8265. }
  8266. updateNav(ppos[0]-1,ppos);
  8267. }
  8268. focusaref();
  8269. return false;
  8270. });
  8271. }
  8272. var posInit =getCurrPos();
  8273. updateNav(posInit[0],posInit);
  8274. });
  8275. },
  8276. delGridRow : function(rowids,p) {
  8277. p = $.extend(true, {
  8278. top : 200,
  8279. left: 420,
  8280. width: 240,
  8281. height: 'auto',
  8282. dataheight : 'auto',
  8283. modal: false,
  8284. overlay: 30,
  8285. drag: true,
  8286. resize: true,
  8287. url : '',
  8288. mtype : "POST",
  8289. reloadAfterSubmit: true,
  8290. beforeShowForm: null,
  8291. beforeInitData : null,
  8292. afterShowForm: null,
  8293. beforeSubmit: null,
  8294. onclickSubmit: null,
  8295. afterSubmit: null,
  8296. jqModal : true,
  8297. closeOnEscape : false,
  8298. delData: {},
  8299. delicon : [],
  8300. cancelicon : [],
  8301. onClose : null,
  8302. ajaxDelOptions : {},
  8303. processing : false,
  8304. serializeDelData : null,
  8305. useDataProxy : false
  8306. }, $.jgrid.del, p ||{});
  8307. rp_ge[$(this)[0].p.id] = p;
  8308. return this.each(function(){
  8309. var $t = this;
  8310. if (!$t.grid ) {return;}
  8311. if(!rowids) {return;}
  8312. var onBeforeShow = $.isFunction( rp_ge[$t.p.id].beforeShowForm ),
  8313. onAfterShow = $.isFunction( rp_ge[$t.p.id].afterShowForm ),
  8314. onBeforeInit = $.isFunction(rp_ge[$t.p.id].beforeInitData) ? rp_ge[$t.p.id].beforeInitData : false,
  8315. gID = $t.p.id, onCS = {},
  8316. showFrm = true,
  8317. dtbl = "DelTbl_"+$.jgrid.jqID(gID),postd, idname, opers, oper,
  8318. dtbl_id = "DelTbl_" + gID,
  8319. IDs = {themodal:'delmod'+gID,modalhead:'delhd'+gID,modalcontent:'delcnt'+gID, scrollelm: dtbl};
  8320. if ($.isArray(rowids)) {rowids = rowids.join();}
  8321. if ( $("#"+$.jgrid.jqID(IDs.themodal))[0] !== undefined ) {
  8322. if(onBeforeInit) {
  8323. showFrm = onBeforeInit.call($t,$("#"+dtbl));
  8324. if(showFrm === undefined) {
  8325. showFrm = true;
  8326. }
  8327. }
  8328. if(showFrm === false) {return;}
  8329. $("#DelData>td","#"+dtbl).text(rowids);
  8330. $("#DelError","#"+dtbl).hide();
  8331. if( rp_ge[$t.p.id].processing === true) {
  8332. rp_ge[$t.p.id].processing=false;
  8333. $("#dData", "#"+dtbl).removeClass('ui-state-active');
  8334. }
  8335. if(onBeforeShow) {rp_ge[$t.p.id].beforeShowForm.call($t,$("#"+dtbl));}
  8336. $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{gbox:"#gbox_"+$.jgrid.jqID(gID),jqm:rp_ge[$t.p.id].jqModal,jqM: false, overlay: rp_ge[$t.p.id].overlay, modal:rp_ge[$t.p.id].modal});
  8337. if(onAfterShow) {rp_ge[$t.p.id].afterShowForm.call($t,$("#"+dtbl));}
  8338. } else {
  8339. var dh = isNaN(rp_ge[$t.p.id].dataheight) ? rp_ge[$t.p.id].dataheight : rp_ge[$t.p.id].dataheight+"px";
  8340. var tbl = "<div id='"+dtbl_id+"' class='formdata' style='width:100%;overflow:auto;position:relative;height:"+dh+";'>";
  8341. tbl += "<table class='DelTable'><tbody>";
  8342. // error data
  8343. tbl += "<tr id='DelError' style='display:none'><td class='ui-state-error'></td></tr>";
  8344. tbl += "<tr id='DelData' style='display:none'><td >"+rowids+"</td></tr>";
  8345. tbl += "<tr><td class=\"delmsg\" style=\"white-space:pre;\">"+rp_ge[$t.p.id].msg+"</td></tr><tr><td >&#160;</td></tr>";
  8346. // buttons at footer
  8347. tbl += "</tbody></table></div>";
  8348. var bS = "<a href='javascript:void(0)' id='dData' class='fm-button ui-state-default ui-corner-all'>"+p.bSubmit+"</a>",
  8349. bC = "<a href='javascript:void(0)' id='eData' class='fm-button ui-state-default ui-corner-all'>"+p.bCancel+"</a>";
  8350. tbl += "<table cellspacing='0' cellpadding='0' border='0' class='EditTable' id='"+dtbl+"_2'><tbody><tr><td><hr class='ui-widget-content' style='margin:1px'/></td></tr><tr><td class='DelButton EditButton'>"+bS+"&#160;"+bC+"</td></tr></tbody></table>";
  8351. p.gbox = "#gbox_"+$.jgrid.jqID(gID);
  8352. $.jgrid.createModal(IDs,tbl,p,"#gview_"+$.jgrid.jqID($t.p.id),$("#gview_"+$.jgrid.jqID($t.p.id))[0]);
  8353. if(onBeforeInit) {
  8354. showFrm = onBeforeInit.call($t,$("#"+dtbl));
  8355. if(showFrm === undefined) {
  8356. showFrm = true;
  8357. }
  8358. }
  8359. if(showFrm === false) {return;}
  8360. $(".fm-button","#"+dtbl+"_2").hover(
  8361. function(){$(this).addClass('ui-state-hover');},
  8362. function(){$(this).removeClass('ui-state-hover');}
  8363. );
  8364. p.delicon = $.extend([true,"left","ui-icon-scissors"],rp_ge[$t.p.id].delicon);
  8365. p.cancelicon = $.extend([true,"left","ui-icon-cancel"],rp_ge[$t.p.id].cancelicon);
  8366. if(p.delicon[0]===true) {
  8367. $("#dData","#"+dtbl+"_2").addClass(p.delicon[1] == "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  8368. .append("<span class='ui-icon "+p.delicon[2]+"'></span>");
  8369. }
  8370. if(p.cancelicon[0]===true) {
  8371. $("#eData","#"+dtbl+"_2").addClass(p.cancelicon[1] == "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  8372. .append("<span class='ui-icon "+p.cancelicon[2]+"'></span>");
  8373. }
  8374. $("#dData","#"+dtbl+"_2").click(function(){
  8375. var ret=[true,""], pk,
  8376. postdata = $("#DelData>td","#"+dtbl).text(); //the pair is name=val1,val2,...
  8377. onCS = {};
  8378. if( $.isFunction( rp_ge[$t.p.id].onclickSubmit ) ) {onCS = rp_ge[$t.p.id].onclickSubmit.call($t,rp_ge[$t.p.id], postdata) || {};}
  8379. if( $.isFunction( rp_ge[$t.p.id].beforeSubmit ) ) {ret = rp_ge[$t.p.id].beforeSubmit.call($t,postdata);}
  8380. if(ret[0] && !rp_ge[$t.p.id].processing) {
  8381. rp_ge[$t.p.id].processing = true;
  8382. opers = $t.p.prmNames;
  8383. postd = $.extend({},rp_ge[$t.p.id].delData, onCS);
  8384. oper = opers.oper;
  8385. postd[oper] = opers.deloper;
  8386. idname = opers.id;
  8387. postdata = String(postdata).split(",");
  8388. if(!postdata.length) { return false; }
  8389. for(pk in postdata) {
  8390. if(postdata.hasOwnProperty(pk)) {
  8391. postdata[pk] = $.jgrid.stripPref($t.p.idPrefix, postdata[pk]);
  8392. }
  8393. }
  8394. postd[idname] = postdata.join();
  8395. $(this).addClass('ui-state-active');
  8396. var ajaxOptions = $.extend({
  8397. url: rp_ge[$t.p.id].url || $($t).jqGrid('getGridParam','editurl'),
  8398. type: rp_ge[$t.p.id].mtype,
  8399. data: $.isFunction(rp_ge[$t.p.id].serializeDelData) ? rp_ge[$t.p.id].serializeDelData.call($t,postd) : postd,
  8400. complete:function(data,status){
  8401. var i;
  8402. if(status != "success") {
  8403. ret[0] = false;
  8404. if ($.isFunction(rp_ge[$t.p.id].errorTextFormat)) {
  8405. ret[1] = rp_ge[$t.p.id].errorTextFormat.call($t,data);
  8406. } else {
  8407. ret[1] = status + " Status: '" + data.statusText + "'. Error code: " + data.status;
  8408. }
  8409. } else {
  8410. // data is posted successful
  8411. // execute aftersubmit with the returned data from server
  8412. if( $.isFunction( rp_ge[$t.p.id].afterSubmit ) ) {
  8413. ret = rp_ge[$t.p.id].afterSubmit.call($t,data,postd);
  8414. }
  8415. }
  8416. if(ret[0] === false) {
  8417. $("#DelError>td","#"+dtbl).html(ret[1]);
  8418. $("#DelError","#"+dtbl).show();
  8419. } else {
  8420. if(rp_ge[$t.p.id].reloadAfterSubmit && $t.p.datatype != "local") {
  8421. $($t).trigger("reloadGrid");
  8422. } else {
  8423. if($t.p.treeGrid===true){
  8424. try {$($t).jqGrid("delTreeNode",$t.p.idPrefix+postdata[0]);} catch(e){}
  8425. } else {
  8426. for(i=0;i<postdata.length;i++) {
  8427. $($t).jqGrid("delRowData",$t.p.idPrefix+ postdata[i]);
  8428. }
  8429. }
  8430. $t.p.selrow = null;
  8431. $t.p.selarrrow = [];
  8432. }
  8433. if($.isFunction(rp_ge[$t.p.id].afterComplete)) {
  8434. setTimeout(function(){rp_ge[$t.p.id].afterComplete.call($t,data,postdata);},500);
  8435. }
  8436. }
  8437. rp_ge[$t.p.id].processing=false;
  8438. $("#dData", "#"+dtbl+"_2").removeClass('ui-state-active');
  8439. if(ret[0]) {$.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});}
  8440. }
  8441. }, $.jgrid.ajaxOptions, rp_ge[$t.p.id].ajaxDelOptions);
  8442. if (!ajaxOptions.url && !rp_ge[$t.p.id].useDataProxy) {
  8443. if ($.isFunction($t.p.dataProxy)) {
  8444. rp_ge[$t.p.id].useDataProxy = true;
  8445. } else {
  8446. ret[0]=false;ret[1] += " "+$.jgrid.errors.nourl;
  8447. }
  8448. }
  8449. if (ret[0]) {
  8450. if (rp_ge[$t.p.id].useDataProxy) {
  8451. var dpret = $t.p.dataProxy.call($t, ajaxOptions, "del_"+$t.p.id);
  8452. if(dpret === undefined) {
  8453. dpret = [true, ""];
  8454. }
  8455. if(dpret[0] === false ) {
  8456. ret[0] = false;
  8457. ret[1] = dpret[1] || "Error deleting the selected row!" ;
  8458. } else {
  8459. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});
  8460. }
  8461. }
  8462. else {$.ajax(ajaxOptions);}
  8463. }
  8464. }
  8465. if(ret[0] === false) {
  8466. $("#DelError>td","#"+dtbl).html(ret[1]);
  8467. $("#DelError","#"+dtbl).show();
  8468. }
  8469. return false;
  8470. });
  8471. $("#eData", "#"+dtbl+"_2").click(function(){
  8472. $.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});
  8473. return false;
  8474. });
  8475. if(onBeforeShow) {rp_ge[$t.p.id].beforeShowForm.call($t,$("#"+dtbl));}
  8476. $.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});
  8477. if(onAfterShow) {rp_ge[$t.p.id].afterShowForm.call($t,$("#"+dtbl));}
  8478. }
  8479. if(rp_ge[$t.p.id].closeOnEscape===true) {
  8480. setTimeout(function(){$(".ui-jqdialog-titlebar-close","#"+$.jgrid.jqID(IDs.modalhead)).focus();},0);
  8481. }
  8482. });
  8483. },
  8484. navGrid : function (elem, o, pEdit,pAdd,pDel,pSearch, pView) {
  8485. o = $.extend({
  8486. edit: true,
  8487. editicon: "ui-icon-pencil",
  8488. add: true,
  8489. addicon:"ui-icon-plus",
  8490. del: true,
  8491. delicon:"ui-icon-trash",
  8492. search: true,
  8493. searchicon:"ui-icon-search",
  8494. refresh: true,
  8495. refreshicon:"ui-icon-refresh",
  8496. refreshstate: 'firstpage',
  8497. view: false,
  8498. viewicon : "ui-icon-document",
  8499. position : "left",
  8500. closeOnEscape : true,
  8501. beforeRefresh : null,
  8502. afterRefresh : null,
  8503. cloneToTop : false,
  8504. alertwidth : 200,
  8505. alertheight : 'auto',
  8506. alerttop: null,
  8507. alertleft: null,
  8508. alertzIndex : null
  8509. }, $.jgrid.nav, o ||{});
  8510. return this.each(function() {
  8511. if(this.nav) {return;}
  8512. var alertIDs = {themodal: 'alertmod_' + this.p.id, modalhead: 'alerthd_' + this.p.id,modalcontent: 'alertcnt_' + this.p.id},
  8513. $t = this, twd, tdw;
  8514. if(!$t.grid || typeof elem !== 'string') {return;}
  8515. if ($("#"+alertIDs.themodal)[0] === undefined) {
  8516. if(!o.alerttop && !o.alertleft) {
  8517. if (window.innerWidth !== undefined) {
  8518. o.alertleft = window.innerWidth;
  8519. o.alerttop = window.innerHeight;
  8520. } else if (document.documentElement !== undefined && document.documentElement.clientWidth !== undefined && document.documentElement.clientWidth !== 0) {
  8521. o.alertleft = document.documentElement.clientWidth;
  8522. o.alerttop = document.documentElement.clientHeight;
  8523. } else {
  8524. o.alertleft=1024;
  8525. o.alerttop=768;
  8526. }
  8527. o.alertleft = o.alertleft/2 - parseInt(o.alertwidth,10)/2;
  8528. o.alerttop = o.alerttop/2-25;
  8529. }
  8530. $.jgrid.createModal(alertIDs,
  8531. "<div>"+o.alerttext+"</div><span tabindex='0'><span tabindex='-1' id='jqg_alrt'></span></span>",
  8532. {
  8533. gbox:"#gbox_"+$.jgrid.jqID($t.p.id),
  8534. jqModal:true,
  8535. drag:true,
  8536. resize:true,
  8537. caption:o.alertcap,
  8538. top:o.alerttop,
  8539. left:o.alertleft,
  8540. width:o.alertwidth,
  8541. height: o.alertheight,
  8542. closeOnEscape:o.closeOnEscape,
  8543. zIndex: o.alertzIndex
  8544. },
  8545. "#gview_"+$.jgrid.jqID($t.p.id),
  8546. $("#gbox_"+$.jgrid.jqID($t.p.id))[0],
  8547. true
  8548. );
  8549. }
  8550. var clone = 1, i,
  8551. onHoverIn = function () {
  8552. if (!$(this).hasClass('ui-state-disabled')) {
  8553. $(this).addClass("ui-state-hover");
  8554. }
  8555. },
  8556. onHoverOut = function () {
  8557. $(this).removeClass("ui-state-hover");
  8558. };
  8559. if(o.cloneToTop && $t.p.toppager) {clone = 2;}
  8560. for(i = 0; i<clone; i++) {
  8561. var tbd,
  8562. navtbl = $("<table cellspacing='0' cellpadding='0' border='0' class='ui-pg-table navtable' style='float:left;table-layout:auto;'><tbody><tr></tr></tbody></table>"),
  8563. sep = "<td class='ui-pg-button ui-state-disabled' style='width:4px;'><span class='ui-separator'></span></td>",
  8564. pgid, elemids;
  8565. if(i===0) {
  8566. pgid = elem;
  8567. elemids = $t.p.id;
  8568. if(pgid == $t.p.toppager) {
  8569. elemids += "_top";
  8570. clone = 1;
  8571. }
  8572. } else {
  8573. pgid = $t.p.toppager;
  8574. elemids = $t.p.id+"_top";
  8575. }
  8576. if($t.p.direction == "rtl") {$(navtbl).attr("dir","rtl").css("float","right");}
  8577. if (o.add) {
  8578. pAdd = pAdd || {};
  8579. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  8580. $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.addicon+"'></span>"+o.addtext+"</div>");
  8581. $("tr",navtbl).append(tbd);
  8582. $(tbd,navtbl)
  8583. .attr({"title":o.addtitle || "",id : pAdd.id || "add_"+elemids})
  8584. .click(function(){
  8585. if (!$(this).hasClass('ui-state-disabled')) {
  8586. if ($.isFunction( o.addfunc )) {
  8587. o.addfunc.call($t);
  8588. } else {
  8589. $($t).jqGrid("editGridRow","new",pAdd);
  8590. }
  8591. }
  8592. return false;
  8593. }).hover(onHoverIn, onHoverOut);
  8594. tbd = null;
  8595. }
  8596. if (o.edit) {
  8597. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  8598. pEdit = pEdit || {};
  8599. $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.editicon+"'></span>"+o.edittext+"</div>");
  8600. $("tr",navtbl).append(tbd);
  8601. $(tbd,navtbl)
  8602. .attr({"title":o.edittitle || "",id: pEdit.id || "edit_"+elemids})
  8603. .click(function(){
  8604. if (!$(this).hasClass('ui-state-disabled')) {
  8605. var sr = $t.p.selrow;
  8606. if (sr) {
  8607. if($.isFunction( o.editfunc ) ) {
  8608. o.editfunc.call($t, sr);
  8609. } else {
  8610. $($t).jqGrid("editGridRow",sr,pEdit);
  8611. }
  8612. } else {
  8613. $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:true});
  8614. $("#jqg_alrt").focus();
  8615. }
  8616. }
  8617. return false;
  8618. }).hover(onHoverIn, onHoverOut);
  8619. tbd = null;
  8620. }
  8621. if (o.view) {
  8622. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  8623. pView = pView || {};
  8624. $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.viewicon+"'></span>"+o.viewtext+"</div>");
  8625. $("tr",navtbl).append(tbd);
  8626. $(tbd,navtbl)
  8627. .attr({"title":o.viewtitle || "",id: pView.id || "view_"+elemids})
  8628. .click(function(){
  8629. if (!$(this).hasClass('ui-state-disabled')) {
  8630. var sr = $t.p.selrow;
  8631. if (sr) {
  8632. if($.isFunction( o.viewfunc ) ) {
  8633. o.viewfunc.call($t, sr);
  8634. } else {
  8635. $($t).jqGrid("viewGridRow",sr,pView);
  8636. }
  8637. } else {
  8638. $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:true});
  8639. $("#jqg_alrt").focus();
  8640. }
  8641. }
  8642. return false;
  8643. }).hover(onHoverIn, onHoverOut);
  8644. tbd = null;
  8645. }
  8646. if (o.del) {
  8647. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  8648. pDel = pDel || {};
  8649. $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.delicon+"'></span>"+o.deltext+"</div>");
  8650. $("tr",navtbl).append(tbd);
  8651. $(tbd,navtbl)
  8652. .attr({"title":o.deltitle || "",id: pDel.id || "del_"+elemids})
  8653. .click(function(){
  8654. if (!$(this).hasClass('ui-state-disabled')) {
  8655. var dr;
  8656. if($t.p.multiselect) {
  8657. dr = $t.p.selarrrow;
  8658. if(dr.length===0) {dr = null;}
  8659. } else {
  8660. dr = $t.p.selrow;
  8661. }
  8662. if(dr){
  8663. if($.isFunction( o.delfunc )){
  8664. o.delfunc.call($t, dr);
  8665. }else{
  8666. $($t).jqGrid("delGridRow",dr,pDel);
  8667. }
  8668. } else {
  8669. $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:true});$("#jqg_alrt").focus();
  8670. }
  8671. }
  8672. return false;
  8673. }).hover(onHoverIn, onHoverOut);
  8674. tbd = null;
  8675. }
  8676. if(o.add || o.edit || o.del || o.view) {$("tr",navtbl).append(sep);}
  8677. if (o.search) {
  8678. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  8679. pSearch = pSearch || {};
  8680. $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.searchicon+"'></span>"+o.searchtext+"</div>");
  8681. $("tr",navtbl).append(tbd);
  8682. $(tbd,navtbl)
  8683. .attr({"title":o.searchtitle || "",id:pSearch.id || "search_"+elemids})
  8684. .click(function(){
  8685. if (!$(this).hasClass('ui-state-disabled')) {
  8686. if($.isFunction( o.searchfunc )) {
  8687. o.searchfunc.call($t, pSearch);
  8688. } else {
  8689. $($t).jqGrid("searchGrid",pSearch);
  8690. }
  8691. }
  8692. return false;
  8693. }).hover(onHoverIn, onHoverOut);
  8694. if (pSearch.showOnLoad && pSearch.showOnLoad === true) {
  8695. $(tbd,navtbl).click();
  8696. }
  8697. tbd = null;
  8698. }
  8699. if (o.refresh) {
  8700. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  8701. $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.refreshicon+"'></span>"+o.refreshtext+"</div>");
  8702. $("tr",navtbl).append(tbd);
  8703. $(tbd,navtbl)
  8704. .attr({"title":o.refreshtitle || "",id: "refresh_"+elemids})
  8705. .click(function(){
  8706. if (!$(this).hasClass('ui-state-disabled')) {
  8707. if($.isFunction(o.beforeRefresh)) {o.beforeRefresh.call($t);}
  8708. $t.p.search = false;
  8709. try {
  8710. var gID = $t.p.id;
  8711. $t.p.postData.filters ="";
  8712. $("#fbox_"+$.jgrid.jqID(gID)).jqFilter('resetFilter');
  8713. if($.isFunction($t.clearToolbar)) {$t.clearToolbar.call($t,false);}
  8714. } catch (e) {}
  8715. switch (o.refreshstate) {
  8716. case 'firstpage':
  8717. $($t).trigger("reloadGrid", [{page:1}]);
  8718. break;
  8719. case 'current':
  8720. $($t).trigger("reloadGrid", [{current:true}]);
  8721. break;
  8722. }
  8723. if($.isFunction(o.afterRefresh)) {o.afterRefresh.call($t);}
  8724. }
  8725. return false;
  8726. }).hover(onHoverIn, onHoverOut);
  8727. tbd = null;
  8728. }
  8729. tdw = $(".ui-jqgrid").css("font-size") || "11px";
  8730. $('body').append("<div id='testpg2' class='ui-jqgrid ui-widget ui-widget-content' style='font-size:"+tdw+";visibility:hidden;' ></div>");
  8731. twd = $(navtbl).clone().appendTo("#testpg2").width();
  8732. $("#testpg2").remove();
  8733. $(pgid+"_"+o.position,pgid).append(navtbl);
  8734. if($t.p._nvtd) {
  8735. if(twd > $t.p._nvtd[0] ) {
  8736. $(pgid+"_"+o.position,pgid).width(twd);
  8737. $t.p._nvtd[0] = twd;
  8738. }
  8739. $t.p._nvtd[1] = twd;
  8740. }
  8741. tdw =null;twd=null;navtbl =null;
  8742. this.nav = true;
  8743. }
  8744. });
  8745. },
  8746. navButtonAdd : function (elem, p) {
  8747. p = $.extend({
  8748. caption : "newButton",
  8749. title: '',
  8750. buttonicon : 'ui-icon-newwin',
  8751. onClickButton: null,
  8752. position : "last",
  8753. cursor : 'pointer'
  8754. }, p ||{});
  8755. return this.each(function() {
  8756. if( !this.grid) {return;}
  8757. if( typeof elem === "string" && elem.indexOf("#") !== 0) {elem = "#"+$.jgrid.jqID(elem);}
  8758. var findnav = $(".navtable",elem)[0], $t = this;
  8759. if (findnav) {
  8760. if( p.id && $("#"+$.jgrid.jqID(p.id), findnav)[0] !== undefined ) {return;}
  8761. var tbd = $("<td></td>");
  8762. if(p.buttonicon.toString().toUpperCase() == "NONE") {
  8763. $(tbd).addClass('ui-pg-button ui-corner-all').append("<div class='ui-pg-div'>"+p.caption+"</div>");
  8764. } else {
  8765. $(tbd).addClass('ui-pg-button ui-corner-all').append("<div class='ui-pg-div'><span class='ui-icon "+p.buttonicon+"'></span>"+p.caption+"</div>");
  8766. }
  8767. if(p.id) {$(tbd).attr("id",p.id);}
  8768. if(p.position=='first'){
  8769. if(findnav.rows[0].cells.length ===0 ) {
  8770. $("tr",findnav).append(tbd);
  8771. } else {
  8772. $("tr td:eq(0)",findnav).before(tbd);
  8773. }
  8774. } else {
  8775. $("tr",findnav).append(tbd);
  8776. }
  8777. $(tbd,findnav)
  8778. .attr("title",p.title || "")
  8779. .click(function(e){
  8780. if (!$(this).hasClass('ui-state-disabled')) {
  8781. if ($.isFunction(p.onClickButton) ) {p.onClickButton.call($t,e);}
  8782. }
  8783. return false;
  8784. })
  8785. .hover(
  8786. function () {
  8787. if (!$(this).hasClass('ui-state-disabled')) {
  8788. $(this).addClass('ui-state-hover');
  8789. }
  8790. },
  8791. function () {$(this).removeClass("ui-state-hover");}
  8792. );
  8793. }
  8794. });
  8795. },
  8796. navSeparatorAdd:function (elem,p) {
  8797. p = $.extend({
  8798. sepclass : "ui-separator",
  8799. sepcontent: '',
  8800. position : "last"
  8801. }, p ||{});
  8802. return this.each(function() {
  8803. if( !this.grid) {return;}
  8804. if( typeof elem === "string" && elem.indexOf("#") !== 0) {elem = "#"+$.jgrid.jqID(elem);}
  8805. var findnav = $(".navtable",elem)[0];
  8806. if(findnav) {
  8807. var sep = "<td class='ui-pg-button ui-state-disabled' style='width:4px;'><span class='"+p.sepclass+"'></span>"+p.sepcontent+"</td>";
  8808. if (p.position === 'first') {
  8809. if (findnav.rows[0].cells.length === 0) {
  8810. $("tr", findnav).append(sep);
  8811. } else {
  8812. $("tr td:eq(0)", findnav).before(sep);
  8813. }
  8814. } else {
  8815. $("tr", findnav).append(sep);
  8816. }
  8817. }
  8818. });
  8819. },
  8820. GridToForm : function( rowid, formid ) {
  8821. return this.each(function(){
  8822. var $t = this, i;
  8823. if (!$t.grid) {return;}
  8824. var rowdata = $($t).jqGrid("getRowData",rowid);
  8825. if (rowdata) {
  8826. for(i in rowdata) {
  8827. if(rowdata.hasOwnProperty(i)) {
  8828. if ( $("[name="+$.jgrid.jqID(i)+"]",formid).is("input:radio") || $("[name="+$.jgrid.jqID(i)+"]",formid).is("input:checkbox")) {
  8829. $("[name="+$.jgrid.jqID(i)+"]",formid).each( function() {
  8830. if( $(this).val() == rowdata[i] ) {
  8831. $(this)[$t.p.useProp ? 'prop': 'attr']("checked",true);
  8832. } else {
  8833. $(this)[$t.p.useProp ? 'prop': 'attr']("checked", false);
  8834. }
  8835. });
  8836. } else {
  8837. // this is very slow on big table and form.
  8838. $("[name="+$.jgrid.jqID(i)+"]",formid).val(rowdata[i]);
  8839. }
  8840. }
  8841. }
  8842. }
  8843. });
  8844. },
  8845. FormToGrid : function(rowid, formid, mode, position){
  8846. return this.each(function() {
  8847. var $t = this;
  8848. if(!$t.grid) {return;}
  8849. if(!mode) {mode = 'set';}
  8850. if(!position) {position = 'first';}
  8851. var fields = $(formid).serializeArray();
  8852. var griddata = {};
  8853. $.each(fields, function(i, field){
  8854. griddata[field.name] = field.value;
  8855. });
  8856. if(mode=='add') {$($t).jqGrid("addRowData",rowid,griddata, position);}
  8857. else if(mode=='set') {$($t).jqGrid("setRowData",rowid,griddata);}
  8858. });
  8859. }
  8860. });
  8861. })(jQuery);
  8862. /*jshint eqeqeq:false, eqnull:true, devel:true */
  8863. /*global jQuery */
  8864. (function($){
  8865. /**
  8866. * jqGrid extension for manipulating Grid Data
  8867. * Tony Tomov tony@trirand.com
  8868. * http://trirand.com/blog/
  8869. * Dual licensed under the MIT and GPL licenses:
  8870. * http://www.opensource.org/licenses/mit-license.php
  8871. * http://www.gnu.org/licenses/gpl-2.0.html
  8872. **/
  8873. "use strict";
  8874. $.jgrid.inlineEdit = $.jgrid.inlineEdit || {};
  8875. $.jgrid.extend({
  8876. //Editing
  8877. editRow : function(rowid,keys,oneditfunc,successfunc, url, extraparam, aftersavefunc,errorfunc, afterrestorefunc) {
  8878. // Compatible mode old versions
  8879. var o={}, args = $.makeArray(arguments).slice(1);
  8880. if( $.type(args[0]) === "object" ) {
  8881. o = args[0];
  8882. } else {
  8883. if (keys !== undefined) { o.keys = keys; }
  8884. if ($.isFunction(oneditfunc)) { o.oneditfunc = oneditfunc; }
  8885. if ($.isFunction(successfunc)) { o.successfunc = successfunc; }
  8886. if (url !== undefined) { o.url = url; }
  8887. if (extraparam !== undefined) { o.extraparam = extraparam; }
  8888. if ($.isFunction(aftersavefunc)) { o.aftersavefunc = aftersavefunc; }
  8889. if ($.isFunction(errorfunc)) { o.errorfunc = errorfunc; }
  8890. if ($.isFunction(afterrestorefunc)) { o.afterrestorefunc = afterrestorefunc; }
  8891. // last two not as param, but as object (sorry)
  8892. //if (restoreAfterError !== undefined) { o.restoreAfterError = restoreAfterError; }
  8893. //if (mtype !== undefined) { o.mtype = mtype || "POST"; }
  8894. }
  8895. o = $.extend(true, {
  8896. keys : false,
  8897. oneditfunc: null,
  8898. successfunc: null,
  8899. url: null,
  8900. extraparam: {},
  8901. aftersavefunc: null,
  8902. errorfunc: null,
  8903. afterrestorefunc: null,
  8904. restoreAfterError: true,
  8905. mtype: "POST"
  8906. }, $.jgrid.inlineEdit, o );
  8907. // End compatible
  8908. return this.each(function(){
  8909. var $t = this, nm, tmp, editable, cnt=0, focus=null, svr={}, ind,cm;
  8910. if (!$t.grid ) { return; }
  8911. ind = $($t).jqGrid("getInd",rowid,true);
  8912. if( ind === false ) {return;}
  8913. editable = $(ind).attr("editable") || "0";
  8914. if (editable == "0" && !$(ind).hasClass("not-editable-row")) {
  8915. cm = $t.p.colModel;
  8916. $('td[role="gridcell"]',ind).each( function(i) {
  8917. nm = cm[i].name;
  8918. var treeg = $t.p.treeGrid===true && nm == $t.p.ExpandColumn;
  8919. if(treeg) { tmp = $("span:first",this).html();}
  8920. else {
  8921. try {
  8922. tmp = $.unformat.call($t,this,{rowId:rowid, colModel:cm[i]},i);
  8923. } catch (_) {
  8924. tmp = ( cm[i].edittype && cm[i].edittype == 'textarea' ) ? $(this).text() : $(this).html();
  8925. }
  8926. }
  8927. if ( nm != 'cb' && nm != 'subgrid' && nm != 'rn') {
  8928. if($t.p.autoencode) { tmp = $.jgrid.htmlDecode(tmp); }
  8929. svr[nm]=tmp;
  8930. if(cm[i].editable===true) {
  8931. if(focus===null) { focus = i; }
  8932. if (treeg) { $("span:first",this).html(""); }
  8933. else { $(this).html(""); }
  8934. var opt = $.extend({},cm[i].editoptions || {},{id:rowid+"_"+nm,name:nm});
  8935. if(!cm[i].edittype) { cm[i].edittype = "text"; }
  8936. if(tmp == "&nbsp;" || tmp == "&#160;" || (tmp.length==1 && tmp.charCodeAt(0)==160) ) {tmp='';}
  8937. var elc = $.jgrid.createEl.call($t,cm[i].edittype,opt,tmp,true,$.extend({},$.jgrid.ajaxOptions,$t.p.ajaxSelectOptions || {}));
  8938. $(elc).addClass("editable");
  8939. if(treeg) { $("span:first",this).append(elc); }
  8940. else { $(this).append(elc); }
  8941. $.jgrid.bindEv( elc, opt, $t);
  8942. //Again IE
  8943. if(cm[i].edittype == "select" && cm[i].editoptions!==undefined && cm[i].editoptions.multiple===true && cm[i].editoptions.dataUrl===undefined && $.browser.msie) {
  8944. $(elc).width($(elc).width());
  8945. }
  8946. cnt++;
  8947. }
  8948. }
  8949. });
  8950. if(cnt > 0) {
  8951. svr.id = rowid; $t.p.savedRow.push(svr);
  8952. $(ind).attr("editable","1");
  8953. $("td:eq("+focus+") input",ind).focus();
  8954. if(o.keys===true) {
  8955. $(ind).bind("keydown",function(e) {
  8956. if (e.keyCode === 27) {
  8957. $($t).jqGrid("restoreRow",rowid, o.afterrestorefunc);
  8958. if($t.p._inlinenav) {
  8959. try {
  8960. $($t).jqGrid('showAddEditButtons');
  8961. } catch (eer1) {}
  8962. }
  8963. return false;
  8964. }
  8965. if (e.keyCode === 13) {
  8966. var ta = e.target;
  8967. if(ta.tagName == 'TEXTAREA') { return true; }
  8968. if( $($t).jqGrid("saveRow", rowid, o ) ) {
  8969. if($t.p._inlinenav) {
  8970. try {
  8971. $($t).jqGrid('showAddEditButtons');
  8972. } catch (eer2) {}
  8973. }
  8974. }
  8975. return false;
  8976. }
  8977. });
  8978. }
  8979. $($t).triggerHandler("jqGridInlineEditRow", [rowid, o]);
  8980. if( $.isFunction(o.oneditfunc)) { o.oneditfunc.call($t, rowid); }
  8981. }
  8982. }
  8983. });
  8984. },
  8985. saveRow : function(rowid, successfunc, url, extraparam, aftersavefunc,errorfunc, afterrestorefunc) {
  8986. // Compatible mode old versions
  8987. var args = $.makeArray(arguments).slice(1), o = {};
  8988. if( $.type(args[0]) === "object" ) {
  8989. o = args[0];
  8990. } else {
  8991. if ($.isFunction(successfunc)) { o.successfunc = successfunc; }
  8992. if (url !== undefined) { o.url = url; }
  8993. if (extraparam !== undefined) { o.extraparam = extraparam; }
  8994. if ($.isFunction(aftersavefunc)) { o.aftersavefunc = aftersavefunc; }
  8995. if ($.isFunction(errorfunc)) { o.errorfunc = errorfunc; }
  8996. if ($.isFunction(afterrestorefunc)) { o.afterrestorefunc = afterrestorefunc; }
  8997. }
  8998. o = $.extend(true, {
  8999. successfunc: null,
  9000. url: null,
  9001. extraparam: {},
  9002. aftersavefunc: null,
  9003. errorfunc: null,
  9004. afterrestorefunc: null,
  9005. restoreAfterError: true,
  9006. mtype: "POST"
  9007. }, $.jgrid.inlineEdit, o );
  9008. // End compatible
  9009. var success = false;
  9010. var $t = this[0], nm, tmp={}, tmp2={}, tmp3= {}, editable, fr, cv, ind;
  9011. if (!$t.grid ) { return success; }
  9012. ind = $($t).jqGrid("getInd",rowid,true);
  9013. if(ind === false) {return success;}
  9014. editable = $(ind).attr("editable");
  9015. o.url = o.url || $t.p.editurl;
  9016. if (editable==="1") {
  9017. var cm;
  9018. $('td[role="gridcell"]',ind).each(function(i) {
  9019. cm = $t.p.colModel[i];
  9020. nm = cm.name;
  9021. if ( nm != 'cb' && nm != 'subgrid' && cm.editable===true && nm != 'rn' && !$(this).hasClass('not-editable-cell')) {
  9022. switch (cm.edittype) {
  9023. case "checkbox":
  9024. var cbv = ["Yes","No"];
  9025. if(cm.editoptions ) {
  9026. cbv = cm.editoptions.value.split(":");
  9027. }
  9028. tmp[nm]= $("input",this).is(":checked") ? cbv[0] : cbv[1];
  9029. break;
  9030. case 'text':
  9031. case 'password':
  9032. case 'textarea':
  9033. case "button" :
  9034. tmp[nm]=$("input, textarea",this).val();
  9035. break;
  9036. case 'select':
  9037. if(!cm.editoptions.multiple) {
  9038. tmp[nm] = $("select option:selected",this).val();
  9039. tmp2[nm] = $("select option:selected", this).text();
  9040. } else {
  9041. var sel = $("select",this), selectedText = [];
  9042. tmp[nm] = $(sel).val();
  9043. if(tmp[nm]) { tmp[nm]= tmp[nm].join(","); } else { tmp[nm] =""; }
  9044. $("select option:selected",this).each(
  9045. function(i,selected){
  9046. selectedText[i] = $(selected).text();
  9047. }
  9048. );
  9049. tmp2[nm] = selectedText.join(",");
  9050. }
  9051. if(cm.formatter && cm.formatter == 'select') { tmp2={}; }
  9052. break;
  9053. case 'custom' :
  9054. try {
  9055. if(cm.editoptions && $.isFunction(cm.editoptions.custom_value)) {
  9056. tmp[nm] = cm.editoptions.custom_value.call($t, $(".customelement",this),'get');
  9057. if (tmp[nm] === undefined) { throw "e2"; }
  9058. } else { throw "e1"; }
  9059. } catch (e) {
  9060. if (e=="e1") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.nodefined,$.jgrid.edit.bClose); }
  9061. if (e=="e2") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose); }
  9062. else { $.jgrid.info_dialog($.jgrid.errors.errcap,e.message,$.jgrid.edit.bClose); }
  9063. }
  9064. break;
  9065. }
  9066. cv = $.jgrid.checkValues(tmp[nm],i,$t);
  9067. if(cv[0] === false) {
  9068. cv[1] = tmp[nm] + " " + cv[1];
  9069. return false;
  9070. }
  9071. if($t.p.autoencode) { tmp[nm] = $.jgrid.htmlEncode(tmp[nm]); }
  9072. if(o.url !== 'clientArray' && cm.editoptions && cm.editoptions.NullIfEmpty === true) {
  9073. if(tmp[nm] === "") {
  9074. tmp3[nm] = 'null';
  9075. }
  9076. }
  9077. }
  9078. });
  9079. if (cv[0] === false){
  9080. try {
  9081. var positions = $.jgrid.findPos($("#"+$.jgrid.jqID(rowid), $t.grid.bDiv)[0]);
  9082. $.jgrid.info_dialog($.jgrid.errors.errcap,cv[1],$.jgrid.edit.bClose,{left:positions[0],top:positions[1]});
  9083. } catch (e) {
  9084. alert(cv[1]);
  9085. }
  9086. return success;
  9087. }
  9088. var idname, opers = $t.p.prmNames, oldRowId = rowid;
  9089. if ($t.p.keyIndex === false) {
  9090. idname = opers.id;
  9091. } else {
  9092. idname = $t.p.colModel[$t.p.keyIndex +
  9093. ($t.p.rownumbers === true ? 1 : 0) +
  9094. ($t.p.multiselect === true ? 1 : 0) +
  9095. ($t.p.subGrid === true ? 1 : 0)].name;
  9096. }
  9097. if(tmp) {
  9098. tmp[opers.oper] = opers.editoper;
  9099. if (tmp[idname] === undefined) {
  9100. tmp[idname] = rowid;
  9101. } else if (ind.id !== $t.p.idPrefix + tmp[idname]) {
  9102. // rename rowid
  9103. var oldid = $.jgrid.stripPref($t.p.idPrefix, rowid);
  9104. if ($t.p._index[oldid] !== undefined) {
  9105. $t.p._index[tmp[idname]] = $t.p._index[oldid];
  9106. delete $t.p._index[oldid];
  9107. }
  9108. rowid = $t.p.idPrefix + tmp[idname];
  9109. $(ind).attr("id", rowid);
  9110. if ($t.p.selrow === oldRowId) {
  9111. $t.p.selrow = rowid;
  9112. }
  9113. if ($.isArray($t.p.selarrrow)) {
  9114. var i = $.inArray(oldRowId, $t.p.selarrrow);
  9115. if (i>=0) {
  9116. $t.p.selarrrow[i] = rowid;
  9117. }
  9118. }
  9119. if ($t.p.multiselect) {
  9120. var newCboxId = "jqg_" + $t.p.id + "_" + rowid;
  9121. $("input.cbox",ind)
  9122. .attr("id", newCboxId)
  9123. .attr("name", newCboxId);
  9124. }
  9125. // TODO: to test the case of frozen columns
  9126. }
  9127. if($t.p.inlineData === undefined) { $t.p.inlineData ={}; }
  9128. tmp = $.extend({},tmp,$t.p.inlineData,o.extraparam);
  9129. }
  9130. if (o.url == 'clientArray') {
  9131. tmp = $.extend({},tmp, tmp2);
  9132. if($t.p.autoencode) {
  9133. $.each(tmp,function(n,v){
  9134. tmp[n] = $.jgrid.htmlDecode(v);
  9135. });
  9136. }
  9137. var k, resp = $($t).jqGrid("setRowData",rowid,tmp);
  9138. $(ind).attr("editable","0");
  9139. for(k=0;k<$t.p.savedRow.length;k++) {
  9140. if( $t.p.savedRow[k].id == oldRowId) {fr = k; break;}
  9141. }
  9142. if(fr >= 0) { $t.p.savedRow.splice(fr,1); }
  9143. $($t).triggerHandler("jqGridInlineAfterSaveRow", [rowid, resp, tmp, o]);
  9144. if( $.isFunction(o.aftersavefunc) ) { o.aftersavefunc.call($t, rowid,resp, o); }
  9145. success = true;
  9146. $(ind).unbind("keydown");
  9147. } else {
  9148. $("#lui_"+$.jgrid.jqID($t.p.id)).show();
  9149. tmp3 = $.extend({},tmp,tmp3);
  9150. tmp3[idname] = $.jgrid.stripPref($t.p.idPrefix, tmp3[idname]);
  9151. $.ajax($.extend({
  9152. url:o.url,
  9153. data: $.isFunction($t.p.serializeRowData) ? $t.p.serializeRowData.call($t, tmp3) : tmp3,
  9154. type: o.mtype,
  9155. async : false, //?!?
  9156. complete: function(res,stat){
  9157. $("#lui_"+$.jgrid.jqID($t.p.id)).hide();
  9158. if (stat === "success"){
  9159. var ret = true, sucret, k;
  9160. sucret = $($t).triggerHandler("jqGridInlineSuccessSaveRow", [res, rowid, o]);
  9161. if (!$.isArray(sucret)) {sucret = [true, tmp];}
  9162. if (sucret[0] && $.isFunction(o.successfunc)) {sucret = o.successfunc.call($t, res);}
  9163. if($.isArray(sucret)) {
  9164. // expect array - status, data, rowid
  9165. ret = sucret[0];
  9166. tmp = sucret[1] || tmp;
  9167. } else {
  9168. ret = sucret;
  9169. }
  9170. if (ret===true) {
  9171. if($t.p.autoencode) {
  9172. $.each(tmp,function(n,v){
  9173. tmp[n] = $.jgrid.htmlDecode(v);
  9174. });
  9175. }
  9176. tmp = $.extend({},tmp, tmp2);
  9177. $($t).jqGrid("setRowData",rowid,tmp);
  9178. $(ind).attr("editable","0");
  9179. for(k=0;k<$t.p.savedRow.length;k++) {
  9180. if( $t.p.savedRow[k].id == rowid) {fr = k; break;}
  9181. }
  9182. if(fr >= 0) { $t.p.savedRow.splice(fr,1); }
  9183. $($t).triggerHandler("jqGridInlineAfterSaveRow", [rowid, res, tmp, o]);
  9184. if( $.isFunction(o.aftersavefunc) ) { o.aftersavefunc.call($t, rowid,res); }
  9185. success = true;
  9186. $(ind).unbind("keydown");
  9187. } else {
  9188. $($t).triggerHandler("jqGridInlineErrorSaveRow", [rowid, res, stat, null, o]);
  9189. if($.isFunction(o.errorfunc) ) {
  9190. o.errorfunc.call($t, rowid, res, stat, null);
  9191. }
  9192. if(o.restoreAfterError === true) {
  9193. $($t).jqGrid("restoreRow",rowid, o.afterrestorefunc);
  9194. }
  9195. }
  9196. }
  9197. },
  9198. error:function(res,stat,err){
  9199. $("#lui_"+$.jgrid.jqID($t.p.id)).hide();
  9200. $($t).triggerHandler("jqGridInlineErrorSaveRow", [rowid, res, stat, err, o]);
  9201. if($.isFunction(o.errorfunc) ) {
  9202. o.errorfunc.call($t, rowid, res, stat, err);
  9203. } else {
  9204. var rT = res.responseText || res.statusText;
  9205. try {
  9206. $.jgrid.info_dialog($.jgrid.errors.errcap,'<div class="ui-state-error">'+ rT +'</div>', $.jgrid.edit.bClose,{buttonalign:'right'});
  9207. } catch(e) {
  9208. alert(rT);
  9209. }
  9210. }
  9211. if(o.restoreAfterError === true) {
  9212. $($t).jqGrid("restoreRow",rowid, o.afterrestorefunc);
  9213. }
  9214. }
  9215. }, $.jgrid.ajaxOptions, $t.p.ajaxRowOptions || {}));
  9216. }
  9217. }
  9218. return success;
  9219. },
  9220. restoreRow : function(rowid, afterrestorefunc) {
  9221. // Compatible mode old versions
  9222. var args = $.makeArray(arguments).slice(1), o={};
  9223. if( $.type(args[0]) === "object" ) {
  9224. o = args[0];
  9225. } else {
  9226. if ($.isFunction(afterrestorefunc)) { o.afterrestorefunc = afterrestorefunc; }
  9227. }
  9228. o = $.extend(true, $.jgrid.inlineEdit, o );
  9229. // End compatible
  9230. return this.each(function(){
  9231. var $t= this, fr, ind, ares={}, k;
  9232. if (!$t.grid ) { return; }
  9233. ind = $($t).jqGrid("getInd",rowid,true);
  9234. if(ind === false) {return;}
  9235. for(k=0;k<$t.p.savedRow.length;k++) {
  9236. if( $t.p.savedRow[k].id == rowid) {fr = k; break;}
  9237. }
  9238. if(fr >= 0) {
  9239. if($.isFunction($.fn.datepicker)) {
  9240. try {
  9241. $("input.hasDatepicker","#"+$.jgrid.jqID(ind.id)).datepicker('hide');
  9242. } catch (e) {}
  9243. }
  9244. $.each($t.p.colModel, function(){
  9245. if(this.editable === true && $t.p.savedRow[fr].hasOwnProperty(this.name)) {
  9246. ares[this.name] = $t.p.savedRow[fr][this.name];
  9247. }
  9248. });
  9249. $($t).jqGrid("setRowData",rowid,ares);
  9250. $(ind).attr("editable","0").unbind("keydown");
  9251. $t.p.savedRow.splice(fr,1);
  9252. if($("#"+$.jgrid.jqID(rowid), "#"+$.jgrid.jqID($t.p.id)).hasClass("jqgrid-new-row")){
  9253. setTimeout(function(){$($t).jqGrid("delRowData",rowid);},0);
  9254. }
  9255. }
  9256. $($t).triggerHandler("jqGridInlineAfterRestoreRow", [rowid]);
  9257. if ($.isFunction(o.afterrestorefunc))
  9258. {
  9259. o.afterrestorefunc.call($t, rowid);
  9260. }
  9261. });
  9262. },
  9263. addRow : function ( p ) {
  9264. p = $.extend(true, {
  9265. rowID : null,
  9266. initdata : {},
  9267. position :"first",
  9268. useDefValues : true,
  9269. useFormatter : false,
  9270. addRowParams : {extraparam:{}}
  9271. },p || {});
  9272. return this.each(function(){
  9273. if (!this.grid ) { return; }
  9274. var $t = this;
  9275. p.rowID = $.isFunction(p.rowID) ? p.rowID.call($t, p) : ( (p.rowID != null) ? p.rowID : $.jgrid.randId());
  9276. if(p.useDefValues === true) {
  9277. $($t.p.colModel).each(function(){
  9278. if( this.editoptions && this.editoptions.defaultValue ) {
  9279. var opt = this.editoptions.defaultValue,
  9280. tmp = $.isFunction(opt) ? opt.call($t) : opt;
  9281. p.initdata[this.name] = tmp;
  9282. }
  9283. });
  9284. }
  9285. $($t).jqGrid('addRowData', p.rowID, p.initdata, p.position);
  9286. p.rowID = $t.p.idPrefix + p.rowID;
  9287. $("#"+$.jgrid.jqID(p.rowID), "#"+$.jgrid.jqID($t.p.id)).addClass("jqgrid-new-row");
  9288. if(p.useFormatter) {
  9289. $("#"+$.jgrid.jqID(p.rowID)+" .ui-inline-edit", "#"+$.jgrid.jqID($t.p.id)).click();
  9290. } else {
  9291. var opers = $t.p.prmNames,
  9292. oper = opers.oper;
  9293. p.addRowParams.extraparam[oper] = opers.addoper;
  9294. $($t).jqGrid('editRow', p.rowID, p.addRowParams);
  9295. $($t).jqGrid('setSelection', p.rowID);
  9296. }
  9297. });
  9298. },
  9299. inlineNav : function (elem, o) {
  9300. o = $.extend({
  9301. edit: true,
  9302. editicon: "ui-icon-pencil",
  9303. add: true,
  9304. addicon:"ui-icon-plus",
  9305. save: true,
  9306. saveicon:"ui-icon-disk",
  9307. cancel: true,
  9308. cancelicon:"ui-icon-cancel",
  9309. addParams : {},
  9310. editParams : {},
  9311. restoreAfterSelect : true
  9312. }, $.jgrid.nav, o ||{});
  9313. return this.each(function(){
  9314. if (!this.grid ) { return; }
  9315. var $t = this, onSelect, gID = $.jgrid.jqID($t.p.id);
  9316. $t.p._inlinenav = true;
  9317. // detect the formatactions column
  9318. if(o.addParams.useFormatter === true) {
  9319. var cm = $t.p.colModel,i;
  9320. for (i = 0; i<cm.length; i++) {
  9321. if(cm[i].formatter && cm[i].formatter === "actions" ) {
  9322. if(cm[i].formatoptions) {
  9323. var defaults = {
  9324. keys:false,
  9325. onEdit : null,
  9326. onSuccess: null,
  9327. afterSave:null,
  9328. onError: null,
  9329. afterRestore: null,
  9330. extraparam: {},
  9331. url: null
  9332. },
  9333. ap = $.extend( defaults, cm[i].formatoptions );
  9334. o.addParams.addRowParams = {
  9335. "keys" : ap.keys,
  9336. "oneditfunc" : ap.onEdit,
  9337. "successfunc" : ap.onSuccess,
  9338. "url" : ap.url,
  9339. "extraparam" : ap.extraparam,
  9340. "aftersavefunc" : ap.afterSavef,
  9341. "errorfunc": ap.onError,
  9342. "afterrestorefunc" : ap.afterRestore
  9343. };
  9344. }
  9345. break;
  9346. }
  9347. }
  9348. }
  9349. if(o.add) {
  9350. $($t).jqGrid('navButtonAdd', elem,{
  9351. caption : o.addtext,
  9352. title : o.addtitle,
  9353. buttonicon : o.addicon,
  9354. id : $t.p.id+"_iladd",
  9355. onClickButton : function () {
  9356. $($t).jqGrid('addRow', o.addParams);
  9357. if(!o.addParams.useFormatter) {
  9358. $("#"+gID+"_ilsave").removeClass('ui-state-disabled');
  9359. $("#"+gID+"_ilcancel").removeClass('ui-state-disabled');
  9360. $("#"+gID+"_iladd").addClass('ui-state-disabled');
  9361. $("#"+gID+"_iledit").addClass('ui-state-disabled');
  9362. }
  9363. }
  9364. });
  9365. }
  9366. if(o.edit) {
  9367. $($t).jqGrid('navButtonAdd', elem,{
  9368. caption : o.edittext,
  9369. title : o.edittitle,
  9370. buttonicon : o.editicon,
  9371. id : $t.p.id+"_iledit",
  9372. onClickButton : function () {
  9373. var sr = $($t).jqGrid('getGridParam','selrow');
  9374. if(sr) {
  9375. $($t).jqGrid('editRow', sr, o.editParams);
  9376. $("#"+gID+"_ilsave").removeClass('ui-state-disabled');
  9377. $("#"+gID+"_ilcancel").removeClass('ui-state-disabled');
  9378. $("#"+gID+"_iladd").addClass('ui-state-disabled');
  9379. $("#"+gID+"_iledit").addClass('ui-state-disabled');
  9380. } else {
  9381. $.jgrid.viewModal("#alertmod",{gbox:"#gbox_"+gID,jqm:true});$("#jqg_alrt").focus();
  9382. }
  9383. }
  9384. });
  9385. }
  9386. if(o.save) {
  9387. $($t).jqGrid('navButtonAdd', elem,{
  9388. caption : o.savetext || '',
  9389. title : o.savetitle || 'Save row',
  9390. buttonicon : o.saveicon,
  9391. id : $t.p.id+"_ilsave",
  9392. onClickButton : function () {
  9393. var sr = $t.p.savedRow[0].id;
  9394. if(sr) {
  9395. var opers = $t.p.prmNames,
  9396. oper = opers.oper;
  9397. if(!o.editParams.extraparam) {
  9398. o.editParams.extraparam = {};
  9399. }
  9400. if($("#"+$.jgrid.jqID(sr), "#"+gID ).hasClass("jqgrid-new-row")) {
  9401. o.editParams.extraparam[oper] = opers.addoper;
  9402. } else {
  9403. o.editParams.extraparam[oper] = opers.editoper;
  9404. }
  9405. if( $($t).jqGrid('saveRow', sr, o.editParams) ) {
  9406. $($t).jqGrid('showAddEditButtons');
  9407. }
  9408. } else {
  9409. $.jgrid.viewModal("#alertmod",{gbox:"#gbox_"+gID,jqm:true});$("#jqg_alrt").focus();
  9410. }
  9411. }
  9412. });
  9413. $("#"+gID+"_ilsave").addClass('ui-state-disabled');
  9414. }
  9415. if(o.cancel) {
  9416. $($t).jqGrid('navButtonAdd', elem,{
  9417. caption : o.canceltext || '',
  9418. title : o.canceltitle || 'Cancel row editing',
  9419. buttonicon : o.cancelicon,
  9420. id : $t.p.id+"_ilcancel",
  9421. onClickButton : function () {
  9422. var sr = $t.p.savedRow[0].id;
  9423. if(sr) {
  9424. $($t).jqGrid('restoreRow', sr, o.editParams);
  9425. $($t).jqGrid('showAddEditButtons');
  9426. } else {
  9427. $.jgrid.viewModal("#alertmod",{gbox:"#gbox_"+gID,jqm:true});$("#jqg_alrt").focus();
  9428. }
  9429. }
  9430. });
  9431. $("#"+gID+"_ilcancel").addClass('ui-state-disabled');
  9432. }
  9433. if(o.restoreAfterSelect === true) {
  9434. if($.isFunction($t.p.beforeSelectRow)) {
  9435. onSelect = $t.p.beforeSelectRow;
  9436. } else {
  9437. onSelect = false;
  9438. }
  9439. $t.p.beforeSelectRow = function(id, stat) {
  9440. var ret = true;
  9441. if($t.p.savedRow.length > 0 && $t.p._inlinenav===true && ( id !== $t.p.selrow && $t.p.selrow !==null) ) {
  9442. if($t.p.selrow == o.addParams.rowID ) {
  9443. $($t).jqGrid('delRowData', $t.p.selrow);
  9444. } else {
  9445. $($t).jqGrid('restoreRow', $t.p.selrow, o.editParams);
  9446. }
  9447. $($t).jqGrid('showAddEditButtons');
  9448. }
  9449. if(onSelect) {
  9450. ret = onSelect.call($t, id, stat);
  9451. }
  9452. return ret;
  9453. };
  9454. }
  9455. });
  9456. },
  9457. showAddEditButtons : function() {
  9458. return this.each(function(){
  9459. if (!this.grid ) { return; }
  9460. var gID = $.jgrid.jqID(this.p.id);
  9461. $("#"+gID+"_ilsave").addClass('ui-state-disabled');
  9462. $("#"+gID+"_ilcancel").addClass('ui-state-disabled');
  9463. $("#"+gID+"_iladd").removeClass('ui-state-disabled');
  9464. $("#"+gID+"_iledit").removeClass('ui-state-disabled');
  9465. });
  9466. }
  9467. //end inline edit
  9468. });
  9469. })(jQuery);
  9470. /*jshint eqeqeq:false */
  9471. /*global jQuery */
  9472. (function($){
  9473. /*
  9474. **
  9475. * jqGrid extension for cellediting Grid Data
  9476. * Tony Tomov tony@trirand.com
  9477. * http://trirand.com/blog/
  9478. * Dual licensed under the MIT and GPL licenses:
  9479. * http://www.opensource.org/licenses/mit-license.php
  9480. * http://www.gnu.org/licenses/gpl-2.0.html
  9481. **/
  9482. /**
  9483. * all events and options here are aded anonynous and not in the base grid
  9484. * since the array is to big. Here is the order of execution.
  9485. * From this point we use jQuery isFunction
  9486. * formatCell
  9487. * beforeEditCell,
  9488. * onSelectCell (used only for noneditable cels)
  9489. * afterEditCell,
  9490. * beforeSaveCell, (called before validation of values if any)
  9491. * beforeSubmitCell (if cellsubmit remote (ajax))
  9492. * afterSubmitCell(if cellsubmit remote (ajax)),
  9493. * afterSaveCell,
  9494. * errorCell,
  9495. * serializeCellData - new
  9496. * Options
  9497. * cellsubmit (remote,clientArray) (added in grid options)
  9498. * cellurl
  9499. * ajaxCellOptions
  9500. * */
  9501. "use strict";
  9502. $.jgrid.extend({
  9503. editCell : function (iRow,iCol, ed){
  9504. return this.each(function (){
  9505. var $t = this, nm, tmp,cc, cm;
  9506. if (!$t.grid || $t.p.cellEdit !== true) {return;}
  9507. iCol = parseInt(iCol,10);
  9508. // select the row that can be used for other methods
  9509. $t.p.selrow = $t.rows[iRow].id;
  9510. if (!$t.p.knv) {$($t).jqGrid("GridNav");}
  9511. // check to see if we have already edited cell
  9512. if ($t.p.savedRow.length>0) {
  9513. // prevent second click on that field and enable selects
  9514. if (ed===true ) {
  9515. if(iRow == $t.p.iRow && iCol == $t.p.iCol){
  9516. return;
  9517. }
  9518. }
  9519. // save the cell
  9520. $($t).jqGrid("saveCell",$t.p.savedRow[0].id,$t.p.savedRow[0].ic);
  9521. } else {
  9522. window.setTimeout(function () { $("#"+$.jgrid.jqID($t.p.knv)).attr("tabindex","-1").focus();},0);
  9523. }
  9524. cm = $t.p.colModel[iCol];
  9525. nm = cm.name;
  9526. if (nm=='subgrid' || nm=='cb' || nm=='rn') {return;}
  9527. cc = $("td:eq("+iCol+")",$t.rows[iRow]);
  9528. if (cm.editable===true && ed===true && !cc.hasClass("not-editable-cell")) {
  9529. if(parseInt($t.p.iCol,10)>=0 && parseInt($t.p.iRow,10)>=0) {
  9530. $("td:eq("+$t.p.iCol+")",$t.rows[$t.p.iRow]).removeClass("edit-cell ui-state-highlight");
  9531. $($t.rows[$t.p.iRow]).removeClass("selected-row ui-state-hover");
  9532. }
  9533. $(cc).addClass("edit-cell ui-state-highlight");
  9534. $($t.rows[iRow]).addClass("selected-row ui-state-hover");
  9535. try {
  9536. tmp = $.unformat.call($t,cc,{rowId: $t.rows[iRow].id, colModel:cm},iCol);
  9537. } catch (_) {
  9538. tmp = ( cm.edittype && cm.edittype == 'textarea' ) ? $(cc).text() : $(cc).html();
  9539. }
  9540. if($t.p.autoencode) { tmp = $.jgrid.htmlDecode(tmp); }
  9541. if (!cm.edittype) {cm.edittype = "text";}
  9542. $t.p.savedRow.push({id:iRow,ic:iCol,name:nm,v:tmp});
  9543. if(tmp === "&nbsp;" || tmp === "&#160;" || (tmp.length===1 && tmp.charCodeAt(0)===160) ) {tmp='';}
  9544. if($.isFunction($t.p.formatCell)) {
  9545. var tmp2 = $t.p.formatCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
  9546. if(tmp2 !== undefined ) {tmp = tmp2;}
  9547. }
  9548. var opt = $.extend({}, cm.editoptions || {} ,{id:iRow+"_"+nm,name:nm});
  9549. var elc = $.jgrid.createEl.call($t,cm.edittype,opt,tmp,true,$.extend({},$.jgrid.ajaxOptions,$t.p.ajaxSelectOptions || {}));
  9550. $($t).triggerHandler("jqGridBeforeEditCell", [$t.rows[iRow].id, nm, tmp, iRow, iCol]);
  9551. if ($.isFunction($t.p.beforeEditCell)) {
  9552. $t.p.beforeEditCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
  9553. }
  9554. $(cc).html("").append(elc).attr("tabindex","0");
  9555. $.jgrid.bindEv( elc, opt, $t);
  9556. window.setTimeout(function () { $(elc).focus();},0);
  9557. $("input, select, textarea",cc).bind("keydown",function(e) {
  9558. if (e.keyCode === 27) {
  9559. if($("input.hasDatepicker",cc).length >0) {
  9560. if( $(".ui-datepicker").is(":hidden") ) { $($t).jqGrid("restoreCell",iRow,iCol); }
  9561. else { $("input.hasDatepicker",cc).datepicker('hide'); }
  9562. } else {
  9563. $($t).jqGrid("restoreCell",iRow,iCol);
  9564. }
  9565. } //ESC
  9566. if (e.keyCode === 13) {
  9567. $($t).jqGrid("saveCell",iRow,iCol);
  9568. // Prevent default action
  9569. return false;
  9570. } //Enter
  9571. if (e.keyCode === 9) {
  9572. if(!$t.grid.hDiv.loading ) {
  9573. if (e.shiftKey) {$($t).jqGrid("prevCell",iRow,iCol);} //Shift TAb
  9574. else {$($t).jqGrid("nextCell",iRow,iCol);} //Tab
  9575. } else {
  9576. return false;
  9577. }
  9578. }
  9579. e.stopPropagation();
  9580. });
  9581. $($t).triggerHandler("jqGridAfterEditCell", [$t.rows[iRow].id, nm, tmp, iRow, iCol]);
  9582. if ($.isFunction($t.p.afterEditCell)) {
  9583. $t.p.afterEditCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
  9584. }
  9585. } else {
  9586. if (parseInt($t.p.iCol,10)>=0 && parseInt($t.p.iRow,10)>=0) {
  9587. $("td:eq("+$t.p.iCol+")",$t.rows[$t.p.iRow]).removeClass("edit-cell ui-state-highlight");
  9588. $($t.rows[$t.p.iRow]).removeClass("selected-row ui-state-hover");
  9589. }
  9590. cc.addClass("edit-cell ui-state-highlight");
  9591. $($t.rows[iRow]).addClass("selected-row ui-state-hover");
  9592. tmp = cc.html().replace(/\&#160\;/ig,'');
  9593. $($t).triggerHandler("jqGridSelectCell", [$t.rows[iRow].id, nm, tmp, iRow, iCol]);
  9594. if ($.isFunction($t.p.onSelectCell)) {
  9595. $t.p.onSelectCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
  9596. }
  9597. }
  9598. $t.p.iCol = iCol; $t.p.iRow = iRow;
  9599. });
  9600. },
  9601. saveCell : function (iRow, iCol){
  9602. return this.each(function(){
  9603. var $t= this, fr;
  9604. if (!$t.grid || $t.p.cellEdit !== true) {return;}
  9605. if ( $t.p.savedRow.length >= 1) {fr = 0;} else {fr=null;}
  9606. if(fr !== null) {
  9607. var cc = $("td:eq("+iCol+")",$t.rows[iRow]),v,v2,
  9608. cm = $t.p.colModel[iCol], nm = cm.name, nmjq = $.jgrid.jqID(nm) ;
  9609. switch (cm.edittype) {
  9610. case "select":
  9611. if(!cm.editoptions.multiple) {
  9612. v = $("#"+iRow+"_"+nmjq+" option:selected",$t.rows[iRow]).val();
  9613. v2 = $("#"+iRow+"_"+nmjq+" option:selected",$t.rows[iRow]).text();
  9614. } else {
  9615. var sel = $("#"+iRow+"_"+nmjq,$t.rows[iRow]), selectedText = [];
  9616. v = $(sel).val();
  9617. if(v) { v.join(",");} else { v=""; }
  9618. $("option:selected",sel).each(
  9619. function(i,selected){
  9620. selectedText[i] = $(selected).text();
  9621. }
  9622. );
  9623. v2 = selectedText.join(",");
  9624. }
  9625. if(cm.formatter) { v2 = v; }
  9626. break;
  9627. case "checkbox":
  9628. var cbv = ["Yes","No"];
  9629. if(cm.editoptions){
  9630. cbv = cm.editoptions.value.split(":");
  9631. }
  9632. v = $("#"+iRow+"_"+nmjq,$t.rows[iRow]).is(":checked") ? cbv[0] : cbv[1];
  9633. v2=v;
  9634. break;
  9635. case "password":
  9636. case "text":
  9637. case "textarea":
  9638. case "button" :
  9639. v = $("#"+iRow+"_"+nmjq,$t.rows[iRow]).val();
  9640. v2=v;
  9641. break;
  9642. case 'custom' :
  9643. try {
  9644. if(cm.editoptions && $.isFunction(cm.editoptions.custom_value)) {
  9645. v = cm.editoptions.custom_value.call($t, $(".customelement",cc),'get');
  9646. if (v===undefined) { throw "e2";} else { v2=v; }
  9647. } else { throw "e1"; }
  9648. } catch (e) {
  9649. if (e=="e1") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.nodefined,$.jgrid.edit.bClose); }
  9650. if (e=="e2") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose); }
  9651. else {$.jgrid.info_dialog($.jgrid.errors.errcap,e.message,$.jgrid.edit.bClose); }
  9652. }
  9653. break;
  9654. }
  9655. // The common approach is if nothing changed do not do anything
  9656. if (v2 !== $t.p.savedRow[fr].v){
  9657. var vvv = $($t).triggerHandler("jqGridBeforeSaveCell", [$t.rows[iRow].id, nm, v, iRow, iCol]);
  9658. if (vvv) {v = vvv; v2=vvv;}
  9659. if ($.isFunction($t.p.beforeSaveCell)) {
  9660. var vv = $t.p.beforeSaveCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
  9661. if (vv) {v = vv; v2=vv;}
  9662. }
  9663. var cv = $.jgrid.checkValues(v,iCol,$t);
  9664. if(cv[0] === true) {
  9665. var addpost = $($t).triggerHandler("jqGridBeforeSubmitCell", [$t.rows[iRow].id, nm, v, iRow, iCol]) || {};
  9666. if ($.isFunction($t.p.beforeSubmitCell)) {
  9667. addpost = $t.p.beforeSubmitCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
  9668. if (!addpost) {addpost={};}
  9669. }
  9670. if( $("input.hasDatepicker",cc).length >0) { $("input.hasDatepicker",cc).datepicker('hide'); }
  9671. if ($t.p.cellsubmit == 'remote') {
  9672. if ($t.p.cellurl) {
  9673. var postdata = {};
  9674. if($t.p.autoencode) { v = $.jgrid.htmlEncode(v); }
  9675. postdata[nm] = v;
  9676. var idname,oper, opers;
  9677. opers = $t.p.prmNames;
  9678. idname = opers.id;
  9679. oper = opers.oper;
  9680. postdata[idname] = $.jgrid.stripPref($t.p.idPrefix, $t.rows[iRow].id);
  9681. postdata[oper] = opers.editoper;
  9682. postdata = $.extend(addpost,postdata);
  9683. $("#lui_"+$.jgrid.jqID($t.p.id)).show();
  9684. $t.grid.hDiv.loading = true;
  9685. $.ajax( $.extend( {
  9686. url: $t.p.cellurl,
  9687. data :$.isFunction($t.p.serializeCellData) ? $t.p.serializeCellData.call($t, postdata) : postdata,
  9688. type: "POST",
  9689. complete: function (result, stat) {
  9690. $("#lui_"+$t.p.id).hide();
  9691. $t.grid.hDiv.loading = false;
  9692. if (stat == 'success') {
  9693. var ret = $($t).triggerHandler("jqGridAfterSubmitCell", [$t, result, postdata.id, nm, v, iRow, iCol]) || [true, ''];
  9694. if (ret[0] === true && $.isFunction($t.p.afterSubmitCell)) {
  9695. ret = $t.p.afterSubmitCell.call($t, result,postdata.id,nm,v,iRow,iCol);
  9696. }
  9697. if(ret[0] === true){
  9698. $(cc).empty();
  9699. $($t).jqGrid("setCell",$t.rows[iRow].id, iCol, v2, false, false, true);
  9700. $(cc).addClass("dirty-cell");
  9701. $($t.rows[iRow]).addClass("edited");
  9702. $($t).triggerHandler("jqGridAfterSaveCell", [$t.rows[iRow].id, nm, v, iRow, iCol]);
  9703. if ($.isFunction($t.p.afterSaveCell)) {
  9704. $t.p.afterSaveCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
  9705. }
  9706. $t.p.savedRow.splice(0,1);
  9707. } else {
  9708. $.jgrid.info_dialog($.jgrid.errors.errcap,ret[1],$.jgrid.edit.bClose);
  9709. $($t).jqGrid("restoreCell",iRow,iCol);
  9710. }
  9711. }
  9712. },
  9713. error:function(res,stat,err) {
  9714. $("#lui_"+$.jgrid.jqID($t.p.id)).hide();
  9715. $t.grid.hDiv.loading = false;
  9716. $($t).triggerHandler("jqGridErrorCell", [res, stat, err]);
  9717. if ($.isFunction($t.p.errorCell)) {
  9718. $t.p.errorCell.call($t, res,stat,err);
  9719. $($t).jqGrid("restoreCell",iRow,iCol);
  9720. } else {
  9721. $.jgrid.info_dialog($.jgrid.errors.errcap,res.status+" : "+res.statusText+"<br/>"+stat,$.jgrid.edit.bClose);
  9722. $($t).jqGrid("restoreCell",iRow,iCol);
  9723. }
  9724. }
  9725. }, $.jgrid.ajaxOptions, $t.p.ajaxCellOptions || {}));
  9726. } else {
  9727. try {
  9728. $.jgrid.info_dialog($.jgrid.errors.errcap,$.jgrid.errors.nourl,$.jgrid.edit.bClose);
  9729. $($t).jqGrid("restoreCell",iRow,iCol);
  9730. } catch (e) {}
  9731. }
  9732. }
  9733. if ($t.p.cellsubmit == 'clientArray') {
  9734. $(cc).empty();
  9735. $($t).jqGrid("setCell",$t.rows[iRow].id,iCol, v2, false, false, true);
  9736. $(cc).addClass("dirty-cell");
  9737. $($t.rows[iRow]).addClass("edited");
  9738. $($t).triggerHandler("jqGridAfterSaveCell", [$t.rows[iRow].id, nm, v, iRow, iCol]);
  9739. if ($.isFunction($t.p.afterSaveCell)) {
  9740. $t.p.afterSaveCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
  9741. }
  9742. $t.p.savedRow.splice(0,1);
  9743. }
  9744. } else {
  9745. try {
  9746. window.setTimeout(function(){$.jgrid.info_dialog($.jgrid.errors.errcap,v+" "+cv[1],$.jgrid.edit.bClose);},100);
  9747. $($t).jqGrid("restoreCell",iRow,iCol);
  9748. } catch (e) {}
  9749. }
  9750. } else {
  9751. $($t).jqGrid("restoreCell",iRow,iCol);
  9752. }
  9753. }
  9754. if ($.browser.opera) {
  9755. $("#"+$.jgrid.jqID($t.p.knv)).attr("tabindex","-1").focus();
  9756. } else {
  9757. window.setTimeout(function () { $("#"+$.jgrid.jqID($t.p.knv)).attr("tabindex","-1").focus();},0);
  9758. }
  9759. });
  9760. },
  9761. restoreCell : function(iRow, iCol) {
  9762. return this.each(function(){
  9763. var $t= this, fr;
  9764. if (!$t.grid || $t.p.cellEdit !== true ) {return;}
  9765. if ( $t.p.savedRow.length >= 1) {fr = 0;} else {fr=null;}
  9766. if(fr !== null) {
  9767. var cc = $("td:eq("+iCol+")",$t.rows[iRow]);
  9768. // datepicker fix
  9769. if($.isFunction($.fn.datepicker)) {
  9770. try {
  9771. $("input.hasDatepicker",cc).datepicker('hide');
  9772. } catch (e) {}
  9773. }
  9774. $(cc).empty().attr("tabindex","-1");
  9775. $($t).jqGrid("setCell",$t.rows[iRow].id, iCol, $t.p.savedRow[fr].v, false, false, true);
  9776. $($t).triggerHandler("jqGridAfterRestoreCell", [$t.rows[iRow].id, $t.p.savedRow[fr].v, iRow, iCol]);
  9777. if ($.isFunction($t.p.afterRestoreCell)) {
  9778. $t.p.afterRestoreCell.call($t, $t.rows[iRow].id, $t.p.savedRow[fr].v, iRow, iCol);
  9779. }
  9780. $t.p.savedRow.splice(0,1);
  9781. }
  9782. window.setTimeout(function () { $("#"+$t.p.knv).attr("tabindex","-1").focus();},0);
  9783. });
  9784. },
  9785. nextCell : function (iRow,iCol) {
  9786. return this.each(function (){
  9787. var $t = this, nCol=false, i;
  9788. if (!$t.grid || $t.p.cellEdit !== true) {return;}
  9789. // try to find next editable cell
  9790. for (i=iCol+1; i<$t.p.colModel.length; i++) {
  9791. if ( $t.p.colModel[i].editable ===true) {
  9792. nCol = i; break;
  9793. }
  9794. }
  9795. if(nCol !== false) {
  9796. $($t).jqGrid("editCell",iRow,nCol,true);
  9797. } else {
  9798. if ($t.p.savedRow.length >0) {
  9799. $($t).jqGrid("saveCell",iRow,iCol);
  9800. }
  9801. }
  9802. });
  9803. },
  9804. prevCell : function (iRow,iCol) {
  9805. return this.each(function (){
  9806. var $t = this, nCol=false, i;
  9807. if (!$t.grid || $t.p.cellEdit !== true) {return;}
  9808. // try to find next editable cell
  9809. for (i=iCol-1; i>=0; i--) {
  9810. if ( $t.p.colModel[i].editable ===true) {
  9811. nCol = i; break;
  9812. }
  9813. }
  9814. if(nCol !== false) {
  9815. $($t).jqGrid("editCell",iRow,nCol,true);
  9816. } else {
  9817. if ($t.p.savedRow.length >0) {
  9818. $($t).jqGrid("saveCell",iRow,iCol);
  9819. }
  9820. }
  9821. });
  9822. },
  9823. GridNav : function() {
  9824. return this.each(function () {
  9825. var $t = this;
  9826. if (!$t.grid || $t.p.cellEdit !== true ) {return;}
  9827. // trick to process keydown on non input elements
  9828. $t.p.knv = $t.p.id + "_kn";
  9829. var selection = $("<div style='position:fixed;top:-1000000px;width:1px;height:1px;' tabindex='0'><div tabindex='-1' style='width:1px;height:1px;' id='"+$t.p.knv+"'></div></div>"),
  9830. i, kdir;
  9831. function scrollGrid(iR, iC, tp){
  9832. if (tp.substr(0,1)=='v') {
  9833. var ch = $($t.grid.bDiv)[0].clientHeight,
  9834. st = $($t.grid.bDiv)[0].scrollTop,
  9835. nROT = $t.rows[iR].offsetTop+$t.rows[iR].clientHeight,
  9836. pROT = $t.rows[iR].offsetTop;
  9837. if(tp == 'vd') {
  9838. if(nROT >= ch) {
  9839. $($t.grid.bDiv)[0].scrollTop = $($t.grid.bDiv)[0].scrollTop + $t.rows[iR].clientHeight;
  9840. }
  9841. }
  9842. if(tp == 'vu'){
  9843. if (pROT < st ) {
  9844. $($t.grid.bDiv)[0].scrollTop = $($t.grid.bDiv)[0].scrollTop - $t.rows[iR].clientHeight;
  9845. }
  9846. }
  9847. }
  9848. if(tp=='h') {
  9849. var cw = $($t.grid.bDiv)[0].clientWidth,
  9850. sl = $($t.grid.bDiv)[0].scrollLeft,
  9851. nCOL = $t.rows[iR].cells[iC].offsetLeft+$t.rows[iR].cells[iC].clientWidth,
  9852. pCOL = $t.rows[iR].cells[iC].offsetLeft;
  9853. if(nCOL >= cw+parseInt(sl,10)) {
  9854. $($t.grid.bDiv)[0].scrollLeft = $($t.grid.bDiv)[0].scrollLeft + $t.rows[iR].cells[iC].clientWidth;
  9855. } else if (pCOL < sl) {
  9856. $($t.grid.bDiv)[0].scrollLeft = $($t.grid.bDiv)[0].scrollLeft - $t.rows[iR].cells[iC].clientWidth;
  9857. }
  9858. }
  9859. }
  9860. function findNextVisible(iC,act){
  9861. var ind, i;
  9862. if(act == 'lft') {
  9863. ind = iC+1;
  9864. for (i=iC;i>=0;i--){
  9865. if ($t.p.colModel[i].hidden !== true) {
  9866. ind = i;
  9867. break;
  9868. }
  9869. }
  9870. }
  9871. if(act == 'rgt') {
  9872. ind = iC-1;
  9873. for (i=iC; i<$t.p.colModel.length;i++){
  9874. if ($t.p.colModel[i].hidden !== true) {
  9875. ind = i;
  9876. break;
  9877. }
  9878. }
  9879. }
  9880. return ind;
  9881. }
  9882. $(selection).insertBefore($t.grid.cDiv);
  9883. $("#"+$t.p.knv)
  9884. .focus()
  9885. .keydown(function (e){
  9886. kdir = e.keyCode;
  9887. if($t.p.direction == "rtl") {
  9888. if(kdir===37) { kdir = 39;}
  9889. else if (kdir===39) { kdir = 37; }
  9890. }
  9891. switch (kdir) {
  9892. case 38:
  9893. if ($t.p.iRow-1 >0 ) {
  9894. scrollGrid($t.p.iRow-1,$t.p.iCol,'vu');
  9895. $($t).jqGrid("editCell",$t.p.iRow-1,$t.p.iCol,false);
  9896. }
  9897. break;
  9898. case 40 :
  9899. if ($t.p.iRow+1 <= $t.rows.length-1) {
  9900. scrollGrid($t.p.iRow+1,$t.p.iCol,'vd');
  9901. $($t).jqGrid("editCell",$t.p.iRow+1,$t.p.iCol,false);
  9902. }
  9903. break;
  9904. case 37 :
  9905. if ($t.p.iCol -1 >= 0) {
  9906. i = findNextVisible($t.p.iCol-1,'lft');
  9907. scrollGrid($t.p.iRow, i,'h');
  9908. $($t).jqGrid("editCell",$t.p.iRow, i,false);
  9909. }
  9910. break;
  9911. case 39 :
  9912. if ($t.p.iCol +1 <= $t.p.colModel.length-1) {
  9913. i = findNextVisible($t.p.iCol+1,'rgt');
  9914. scrollGrid($t.p.iRow,i,'h');
  9915. $($t).jqGrid("editCell",$t.p.iRow,i,false);
  9916. }
  9917. break;
  9918. case 13:
  9919. if (parseInt($t.p.iCol,10)>=0 && parseInt($t.p.iRow,10)>=0) {
  9920. $($t).jqGrid("editCell",$t.p.iRow,$t.p.iCol,true);
  9921. }
  9922. break;
  9923. default :
  9924. return true;
  9925. }
  9926. return false;
  9927. });
  9928. });
  9929. },
  9930. getChangedCells : function (mthd) {
  9931. var ret=[];
  9932. if (!mthd) {mthd='all';}
  9933. this.each(function(){
  9934. var $t= this,nm;
  9935. if (!$t.grid || $t.p.cellEdit !== true ) {return;}
  9936. $($t.rows).each(function(j){
  9937. var res = {};
  9938. if ($(this).hasClass("edited")) {
  9939. $('td',this).each( function(i) {
  9940. nm = $t.p.colModel[i].name;
  9941. if ( nm !== 'cb' && nm !== 'subgrid') {
  9942. if (mthd=='dirty') {
  9943. if ($(this).hasClass('dirty-cell')) {
  9944. try {
  9945. res[nm] = $.unformat.call($t,this,{rowId:$t.rows[j].id, colModel:$t.p.colModel[i]},i);
  9946. } catch (e){
  9947. res[nm] = $.jgrid.htmlDecode($(this).html());
  9948. }
  9949. }
  9950. } else {
  9951. try {
  9952. res[nm] = $.unformat.call($t,this,{rowId:$t.rows[j].id,colModel:$t.p.colModel[i]},i);
  9953. } catch (e) {
  9954. res[nm] = $.jgrid.htmlDecode($(this).html());
  9955. }
  9956. }
  9957. }
  9958. });
  9959. res.id = this.id;
  9960. ret.push(res);
  9961. }
  9962. });
  9963. });
  9964. return ret;
  9965. }
  9966. /// end cell editing
  9967. });
  9968. })(jQuery);
  9969. /*jshint eqeqeq:false */
  9970. /*global jQuery */
  9971. (function($){
  9972. /**
  9973. * jqGrid extension for SubGrid Data
  9974. * Tony Tomov tony@trirand.com
  9975. * http://trirand.com/blog/
  9976. * Dual licensed under the MIT and GPL licenses:
  9977. * http://www.opensource.org/licenses/mit-license.php
  9978. * http://www.gnu.org/licenses/gpl-2.0.html
  9979. **/
  9980. "use strict";
  9981. $.jgrid.extend({
  9982. setSubGrid : function () {
  9983. return this.each(function (){
  9984. var $t = this, cm, i,
  9985. suboptions = {
  9986. plusicon : "ui-icon-plus",
  9987. minusicon : "ui-icon-minus",
  9988. openicon: "ui-icon-carat-1-sw",
  9989. expandOnLoad: false,
  9990. delayOnLoad : 50,
  9991. selectOnExpand : false,
  9992. reloadOnExpand : true
  9993. };
  9994. $t.p.subGridOptions = $.extend(suboptions, $t.p.subGridOptions || {});
  9995. $t.p.colNames.unshift("");
  9996. $t.p.colModel.unshift({name:'subgrid',width: ($.browser.safari || $.browser.webkit) ? $t.p.subGridWidth+$t.p.cellLayout : $t.p.subGridWidth,sortable: false,resizable:false,hidedlg:true,search:false,fixed:true});
  9997. cm = $t.p.subGridModel;
  9998. if(cm[0]) {
  9999. cm[0].align = $.extend([],cm[0].align || []);
  10000. for(i=0;i<cm[0].name.length;i++) { cm[0].align[i] = cm[0].align[i] || 'left';}
  10001. }
  10002. });
  10003. },
  10004. addSubGridCell :function (pos,iRow) {
  10005. var prp='',ic,sid;
  10006. this.each(function(){
  10007. prp = this.formatCol(pos,iRow);
  10008. sid= this.p.id;
  10009. ic = this.p.subGridOptions.plusicon;
  10010. });
  10011. return "<td role=\"gridcell\" aria-describedby=\""+sid+"_subgrid\" class=\"ui-sgcollapsed sgcollapsed\" "+prp+"><a href='javascript:void(0);'><span class='ui-icon "+ic+"'></span></a></td>";
  10012. },
  10013. addSubGrid : function( pos, sind ) {
  10014. return this.each(function(){
  10015. var ts = this;
  10016. if (!ts.grid ) { return; }
  10017. //-------------------------
  10018. var subGridCell = function(trdiv,cell,pos)
  10019. {
  10020. var tddiv = $("<td align='"+ts.p.subGridModel[0].align[pos]+"'></td>").html(cell);
  10021. $(trdiv).append(tddiv);
  10022. };
  10023. var subGridXml = function(sjxml, sbid){
  10024. var tddiv, i, sgmap,
  10025. dummy = $("<table cellspacing='0' cellpadding='0' border='0'><tbody></tbody></table>"),
  10026. trdiv = $("<tr></tr>");
  10027. for (i = 0; i<ts.p.subGridModel[0].name.length; i++) {
  10028. tddiv = $("<th class='ui-state-default ui-th-subgrid ui-th-column ui-th-"+ts.p.direction+"'></th>");
  10029. $(tddiv).html(ts.p.subGridModel[0].name[i]);
  10030. $(tddiv).width( ts.p.subGridModel[0].width[i]);
  10031. $(trdiv).append(tddiv);
  10032. }
  10033. $(dummy).append(trdiv);
  10034. if (sjxml){
  10035. sgmap = ts.p.xmlReader.subgrid;
  10036. $(sgmap.root+" "+sgmap.row, sjxml).each( function(){
  10037. trdiv = $("<tr class='ui-widget-content ui-subtblcell'></tr>");
  10038. if(sgmap.repeatitems === true) {
  10039. $(sgmap.cell,this).each( function(i) {
  10040. subGridCell(trdiv, $(this).text() || '&#160;',i);
  10041. });
  10042. } else {
  10043. var f = ts.p.subGridModel[0].mapping || ts.p.subGridModel[0].name;
  10044. if (f) {
  10045. for (i=0;i<f.length;i++) {
  10046. subGridCell(trdiv, $(f[i],this).text() || '&#160;',i);
  10047. }
  10048. }
  10049. }
  10050. $(dummy).append(trdiv);
  10051. });
  10052. }
  10053. var pID = $("table:first",ts.grid.bDiv).attr("id")+"_";
  10054. $("#"+$.jgrid.jqID(pID+sbid)).append(dummy);
  10055. ts.grid.hDiv.loading = false;
  10056. $("#load_"+$.jgrid.jqID(ts.p.id)).hide();
  10057. return false;
  10058. };
  10059. var subGridJson = function(sjxml, sbid){
  10060. var tddiv,result,i,cur, sgmap,j,
  10061. dummy = $("<table cellspacing='0' cellpadding='0' border='0'><tbody></tbody></table>"),
  10062. trdiv = $("<tr></tr>");
  10063. for (i = 0; i<ts.p.subGridModel[0].name.length; i++) {
  10064. tddiv = $("<th class='ui-state-default ui-th-subgrid ui-th-column ui-th-"+ts.p.direction+"'></th>");
  10065. $(tddiv).html(ts.p.subGridModel[0].name[i]);
  10066. $(tddiv).width( ts.p.subGridModel[0].width[i]);
  10067. $(trdiv).append(tddiv);
  10068. }
  10069. $(dummy).append(trdiv);
  10070. if (sjxml){
  10071. sgmap = ts.p.jsonReader.subgrid;
  10072. result = $.jgrid.getAccessor(sjxml, sgmap.root);
  10073. if ( result !== undefined ) {
  10074. for (i=0;i<result.length;i++) {
  10075. cur = result[i];
  10076. trdiv = $("<tr class='ui-widget-content ui-subtblcell'></tr>");
  10077. if(sgmap.repeatitems === true) {
  10078. if(sgmap.cell) { cur=cur[sgmap.cell]; }
  10079. for (j=0;j<cur.length;j++) {
  10080. subGridCell(trdiv, cur[j] || '&#160;',j);
  10081. }
  10082. } else {
  10083. var f = ts.p.subGridModel[0].mapping || ts.p.subGridModel[0].name;
  10084. if(f.length) {
  10085. for (j=0;j<f.length;j++) {
  10086. subGridCell(trdiv, cur[f[j]] || '&#160;',j);
  10087. }
  10088. }
  10089. }
  10090. $(dummy).append(trdiv);
  10091. }
  10092. }
  10093. }
  10094. var pID = $("table:first",ts.grid.bDiv).attr("id")+"_";
  10095. $("#"+$.jgrid.jqID(pID+sbid)).append(dummy);
  10096. ts.grid.hDiv.loading = false;
  10097. $("#load_"+$.jgrid.jqID(ts.p.id)).hide();
  10098. return false;
  10099. };
  10100. var populatesubgrid = function( rd )
  10101. {
  10102. var sid,dp, i, j;
  10103. sid = $(rd).attr("id");
  10104. dp = {nd_: (new Date().getTime())};
  10105. dp[ts.p.prmNames.subgridid]=sid;
  10106. if(!ts.p.subGridModel[0]) { return false; }
  10107. if(ts.p.subGridModel[0].params) {
  10108. for(j=0; j < ts.p.subGridModel[0].params.length; j++) {
  10109. for(i=0; i<ts.p.colModel.length; i++) {
  10110. if(ts.p.colModel[i].name === ts.p.subGridModel[0].params[j]) {
  10111. dp[ts.p.colModel[i].name]= $("td:eq("+i+")",rd).text().replace(/\&#160\;/ig,'');
  10112. }
  10113. }
  10114. }
  10115. }
  10116. if(!ts.grid.hDiv.loading) {
  10117. ts.grid.hDiv.loading = true;
  10118. $("#load_"+$.jgrid.jqID(ts.p.id)).show();
  10119. if(!ts.p.subgridtype) { ts.p.subgridtype = ts.p.datatype; }
  10120. if($.isFunction(ts.p.subgridtype)) {
  10121. ts.p.subgridtype.call(ts, dp);
  10122. } else {
  10123. ts.p.subgridtype = ts.p.subgridtype.toLowerCase();
  10124. }
  10125. switch(ts.p.subgridtype) {
  10126. case "xml":
  10127. case "json":
  10128. $.ajax($.extend({
  10129. type:ts.p.mtype,
  10130. url: ts.p.subGridUrl,
  10131. dataType:ts.p.subgridtype,
  10132. data: $.isFunction(ts.p.serializeSubGridData)? ts.p.serializeSubGridData.call(ts, dp) : dp,
  10133. complete: function(sxml) {
  10134. if(ts.p.subgridtype === "xml") {
  10135. subGridXml(sxml.responseXML, sid);
  10136. } else {
  10137. subGridJson($.jgrid.parse(sxml.responseText),sid);
  10138. }
  10139. sxml=null;
  10140. }
  10141. }, $.jgrid.ajaxOptions, ts.p.ajaxSubgridOptions || {}));
  10142. break;
  10143. }
  10144. }
  10145. return false;
  10146. };
  10147. var _id, pID,atd, nhc=0, bfsc, r;
  10148. $.each(ts.p.colModel,function(){
  10149. if(this.hidden === true || this.name === 'rn' || this.name === 'cb') {
  10150. nhc++;
  10151. }
  10152. });
  10153. var len = ts.rows.length, i=1;
  10154. if( sind !== undefined && sind > 0) {
  10155. i = sind;
  10156. len = sind+1;
  10157. }
  10158. while(i < len) {
  10159. if($(ts.rows[i]).hasClass('jqgrow')) {
  10160. $(ts.rows[i].cells[pos]).bind('click', function() {
  10161. var tr = $(this).parent("tr")[0];
  10162. r = tr.nextSibling;
  10163. if($(this).hasClass("sgcollapsed")) {
  10164. pID = ts.p.id;
  10165. _id = tr.id;
  10166. if(ts.p.subGridOptions.reloadOnExpand === true || ( ts.p.subGridOptions.reloadOnExpand === false && !$(r).hasClass('ui-subgrid') ) ) {
  10167. atd = pos >=1 ? "<td colspan='"+pos+"'>&#160;</td>":"";
  10168. bfsc = $(ts).triggerHandler("jqGridSubGridBeforeExpand", [pID + "_" + _id, _id]);
  10169. bfsc = (bfsc === false || bfsc === 'stop') ? false : true;
  10170. if(bfsc && $.isFunction(ts.p.subGridBeforeExpand)) {
  10171. bfsc = ts.p.subGridBeforeExpand.call(ts, pID+"_"+_id,_id);
  10172. }
  10173. if(bfsc === false) {return false;}
  10174. $(tr).after( "<tr role='row' class='ui-subgrid'>"+atd+"<td class='ui-widget-content subgrid-cell'><span class='ui-icon "+ts.p.subGridOptions.openicon+"'></span></td><td colspan='"+parseInt(ts.p.colNames.length-1-nhc,10)+"' class='ui-widget-content subgrid-data'><div id="+pID+"_"+_id+" class='tablediv'></div></td></tr>" );
  10175. $(ts).triggerHandler("jqGridSubGridRowExpanded", [pID + "_" + _id, _id]);
  10176. if( $.isFunction(ts.p.subGridRowExpanded)) {
  10177. ts.p.subGridRowExpanded.call(ts, pID+"_"+ _id,_id);
  10178. } else {
  10179. populatesubgrid(tr);
  10180. }
  10181. } else {
  10182. $(r).show();
  10183. }
  10184. $(this).html("<a href='javascript:void(0);'><span class='ui-icon "+ts.p.subGridOptions.minusicon+"'></span></a>").removeClass("sgcollapsed").addClass("sgexpanded");
  10185. if(ts.p.subGridOptions.selectOnExpand) {
  10186. $(ts).jqGrid('setSelection',_id);
  10187. }
  10188. } else if($(this).hasClass("sgexpanded")) {
  10189. bfsc = $(ts).triggerHandler("jqGridSubGridRowColapsed", [pID + "_" + _id, _id]);
  10190. bfsc = (bfsc === false || bfsc === 'stop') ? false : true;
  10191. if( bfsc && $.isFunction(ts.p.subGridRowColapsed)) {
  10192. _id = tr.id;
  10193. bfsc = ts.p.subGridRowColapsed.call(ts, pID+"_"+_id,_id );
  10194. }
  10195. if(bfsc===false) {return false;}
  10196. if(ts.p.subGridOptions.reloadOnExpand === true) {
  10197. $(r).remove(".ui-subgrid");
  10198. } else if($(r).hasClass('ui-subgrid')) { // incase of dynamic deleting
  10199. $(r).hide();
  10200. }
  10201. $(this).html("<a href='javascript:void(0);'><span class='ui-icon "+ts.p.subGridOptions.plusicon+"'></span></a>").removeClass("sgexpanded").addClass("sgcollapsed");
  10202. }
  10203. return false;
  10204. });
  10205. }
  10206. i++;
  10207. }
  10208. if(ts.p.subGridOptions.expandOnLoad === true) {
  10209. $(ts.rows).filter('.jqgrow').each(function(index,row){
  10210. $(row.cells[0]).click();
  10211. });
  10212. }
  10213. ts.subGridXml = function(xml,sid) {subGridXml(xml,sid);};
  10214. ts.subGridJson = function(json,sid) {subGridJson(json,sid);};
  10215. });
  10216. },
  10217. expandSubGridRow : function(rowid) {
  10218. return this.each(function () {
  10219. var $t = this;
  10220. if(!$t.grid && !rowid) {return;}
  10221. if($t.p.subGrid===true) {
  10222. var rc = $(this).jqGrid("getInd",rowid,true);
  10223. if(rc) {
  10224. var sgc = $("td.sgcollapsed",rc)[0];
  10225. if(sgc) {
  10226. $(sgc).trigger("click");
  10227. }
  10228. }
  10229. }
  10230. });
  10231. },
  10232. collapseSubGridRow : function(rowid) {
  10233. return this.each(function () {
  10234. var $t = this;
  10235. if(!$t.grid && !rowid) {return;}
  10236. if($t.p.subGrid===true) {
  10237. var rc = $(this).jqGrid("getInd",rowid,true);
  10238. if(rc) {
  10239. var sgc = $("td.sgexpanded",rc)[0];
  10240. if(sgc) {
  10241. $(sgc).trigger("click");
  10242. }
  10243. }
  10244. }
  10245. });
  10246. },
  10247. toggleSubGridRow : function(rowid) {
  10248. return this.each(function () {
  10249. var $t = this;
  10250. if(!$t.grid && !rowid) {return;}
  10251. if($t.p.subGrid===true) {
  10252. var rc = $(this).jqGrid("getInd",rowid,true);
  10253. if(rc) {
  10254. var sgc = $("td.sgcollapsed",rc)[0];
  10255. if(sgc) {
  10256. $(sgc).trigger("click");
  10257. } else {
  10258. sgc = $("td.sgexpanded",rc)[0];
  10259. if(sgc) {
  10260. $(sgc).trigger("click");
  10261. }
  10262. }
  10263. }
  10264. }
  10265. });
  10266. }
  10267. });
  10268. })(jQuery);
  10269. /**
  10270. * jqGrid extension - Tree Grid
  10271. * Tony Tomov tony@trirand.com
  10272. * http://trirand.com/blog/
  10273. * Dual licensed under the MIT and GPL licenses:
  10274. * http://www.opensource.org/licenses/mit-license.php
  10275. * http://www.gnu.org/licenses/gpl.html
  10276. **/
  10277. /*jshint eqeqeq:false */
  10278. /*global jQuery */
  10279. (function($) {
  10280. "use strict";
  10281. $.jgrid.extend({
  10282. setTreeNode : function(i, len){
  10283. return this.each(function(){
  10284. var $t = this;
  10285. if( !$t.grid || !$t.p.treeGrid ) {return;}
  10286. var expCol = $t.p.expColInd,
  10287. expanded = $t.p.treeReader.expanded_field,
  10288. isLeaf = $t.p.treeReader.leaf_field,
  10289. level = $t.p.treeReader.level_field,
  10290. icon = $t.p.treeReader.icon_field,
  10291. loaded = $t.p.treeReader.loaded, lft, rgt, curLevel, ident,lftpos, twrap,
  10292. ldat, lf;
  10293. while(i<len) {
  10294. var ind = $t.rows[i].id, dind = $t.p._index[ind], expan;
  10295. ldat = $t.p.data[dind];
  10296. //$t.rows[i].level = ldat[level];
  10297. if($t.p.treeGridModel == 'nested') {
  10298. if(!ldat[isLeaf]) {
  10299. lft = parseInt(ldat[$t.p.treeReader.left_field],10);
  10300. rgt = parseInt(ldat[$t.p.treeReader.right_field],10);
  10301. // NS Model
  10302. ldat[isLeaf] = (rgt === lft+1) ? 'true' : 'false';
  10303. $t.rows[i].cells[$t.p._treeleafpos].innerHTML = ldat[isLeaf];
  10304. }
  10305. }
  10306. //else {
  10307. //row.parent_id = rd[$t.p.treeReader.parent_id_field];
  10308. //}
  10309. curLevel = parseInt(ldat[level],10);
  10310. if($t.p.tree_root_level === 0) {
  10311. ident = curLevel+1;
  10312. lftpos = curLevel;
  10313. } else {
  10314. ident = curLevel;
  10315. lftpos = curLevel -1;
  10316. }
  10317. twrap = "<div class='tree-wrap tree-wrap-"+$t.p.direction+"' style='width:"+(ident*18)+"px;'>";
  10318. twrap += "<div style='"+($t.p.direction=="rtl" ? "right:" : "left:")+(lftpos*18)+"px;' class='ui-icon ";
  10319. if(ldat[loaded] !== undefined) {
  10320. if(ldat[loaded]=="true" || ldat[loaded]===true) {
  10321. ldat[loaded] = true;
  10322. } else {
  10323. ldat[loaded] = false;
  10324. }
  10325. }
  10326. if(ldat[isLeaf] == "true" || ldat[isLeaf] === true) {
  10327. twrap += ((ldat[icon] !== undefined && ldat[icon] !== "") ? ldat[icon] : $t.p.treeIcons.leaf)+" tree-leaf treeclick";
  10328. ldat[isLeaf] = true;
  10329. lf="leaf";
  10330. } else {
  10331. ldat[isLeaf] = false;
  10332. lf="";
  10333. }
  10334. ldat[expanded] = ((ldat[expanded] == "true" || ldat[expanded] === true) ? true : false) && (ldat[loaded] || ldat[loaded] === undefined);
  10335. if(ldat[expanded] === false) {
  10336. twrap += ((ldat[isLeaf] === true) ? "'" : $t.p.treeIcons.plus+" tree-plus treeclick'");
  10337. } else {
  10338. twrap += ((ldat[isLeaf] === true) ? "'" : $t.p.treeIcons.minus+" tree-minus treeclick'");
  10339. }
  10340. twrap += "></div></div>";
  10341. $($t.rows[i].cells[expCol]).wrapInner("<span class='cell-wrapper"+lf+"'></span>").prepend(twrap);
  10342. if(curLevel !== parseInt($t.p.tree_root_level,10)) {
  10343. var pn = $($t).jqGrid('getNodeParent',ldat);
  10344. expan = pn && pn.hasOwnProperty(expanded) ? pn[expanded] : true;
  10345. if( !expan ){
  10346. $($t.rows[i]).css("display","none");
  10347. }
  10348. }
  10349. $($t.rows[i].cells[expCol])
  10350. .find("div.treeclick")
  10351. .bind("click",function(e){
  10352. var target = e.target || e.srcElement,
  10353. ind2 =$(target,$t.rows).closest("tr.jqgrow")[0].id,
  10354. pos = $t.p._index[ind2];
  10355. if(!$t.p.data[pos][isLeaf]){
  10356. if($t.p.data[pos][expanded]){
  10357. $($t).jqGrid("collapseRow",$t.p.data[pos]);
  10358. $($t).jqGrid("collapseNode",$t.p.data[pos]);
  10359. } else {
  10360. $($t).jqGrid("expandRow",$t.p.data[pos]);
  10361. $($t).jqGrid("expandNode",$t.p.data[pos]);
  10362. }
  10363. }
  10364. return false;
  10365. });
  10366. if($t.p.ExpandColClick === true) {
  10367. $($t.rows[i].cells[expCol])
  10368. .find("span.cell-wrapper")
  10369. .css("cursor","pointer")
  10370. .bind("click",function(e) {
  10371. var target = e.target || e.srcElement,
  10372. ind2 =$(target,$t.rows).closest("tr.jqgrow")[0].id,
  10373. pos = $t.p._index[ind2];
  10374. if(!$t.p.data[pos][isLeaf]){
  10375. if($t.p.data[pos][expanded]){
  10376. $($t).jqGrid("collapseRow",$t.p.data[pos]);
  10377. $($t).jqGrid("collapseNode",$t.p.data[pos]);
  10378. } else {
  10379. $($t).jqGrid("expandRow",$t.p.data[pos]);
  10380. $($t).jqGrid("expandNode",$t.p.data[pos]);
  10381. }
  10382. }
  10383. $($t).jqGrid("setSelection",ind2);
  10384. return false;
  10385. });
  10386. }
  10387. i++;
  10388. }
  10389. });
  10390. },
  10391. setTreeGrid : function() {
  10392. return this.each(function (){
  10393. var $t = this, i=0, pico, ecol = false, nm, key, tkey, dupcols=[];
  10394. if(!$t.p.treeGrid) {return;}
  10395. if(!$t.p.treedatatype ) {$.extend($t.p,{treedatatype: $t.p.datatype});}
  10396. $t.p.subGrid = false;$t.p.altRows =false;
  10397. $t.p.pgbuttons = false;$t.p.pginput = false;
  10398. $t.p.gridview = true;
  10399. if($t.p.rowTotal === null ) { $t.p.rowNum = 10000; }
  10400. $t.p.multiselect = false;$t.p.rowList = [];
  10401. $t.p.expColInd = 0;
  10402. pico = 'ui-icon-triangle-1-' + ($t.p.direction=="rtl" ? 'w' : 'e');
  10403. $t.p.treeIcons = $.extend({plus:pico,minus:'ui-icon-triangle-1-s',leaf:'ui-icon-radio-off'},$t.p.treeIcons || {});
  10404. if($t.p.treeGridModel == 'nested') {
  10405. $t.p.treeReader = $.extend({
  10406. level_field: "level",
  10407. left_field:"lft",
  10408. right_field: "rgt",
  10409. leaf_field: "isLeaf",
  10410. expanded_field: "expanded",
  10411. loaded: "loaded",
  10412. icon_field: "icon"
  10413. },$t.p.treeReader);
  10414. } else if($t.p.treeGridModel == 'adjacency') {
  10415. $t.p.treeReader = $.extend({
  10416. level_field: "level",
  10417. parent_id_field: "parent",
  10418. leaf_field: "isLeaf",
  10419. expanded_field: "expanded",
  10420. loaded: "loaded",
  10421. icon_field: "icon"
  10422. },$t.p.treeReader );
  10423. }
  10424. for ( key in $t.p.colModel){
  10425. if($t.p.colModel.hasOwnProperty(key)) {
  10426. nm = $t.p.colModel[key].name;
  10427. if( nm == $t.p.ExpandColumn && !ecol ) {
  10428. ecol = true;
  10429. $t.p.expColInd = i;
  10430. }
  10431. i++;
  10432. //
  10433. for(tkey in $t.p.treeReader) {
  10434. if($t.p.treeReader.hasOwnProperty(tkey) && $t.p.treeReader[tkey] == nm) {
  10435. dupcols.push(nm);
  10436. }
  10437. }
  10438. }
  10439. }
  10440. $.each($t.p.treeReader,function(j,n){
  10441. if(n && $.inArray(n, dupcols) === -1){
  10442. if(j==='leaf_field') { $t.p._treeleafpos= i; }
  10443. i++;
  10444. $t.p.colNames.push(n);
  10445. $t.p.colModel.push({name:n,width:1,hidden:true,sortable:false,resizable:false,hidedlg:true,editable:true,search:false});
  10446. }
  10447. });
  10448. });
  10449. },
  10450. expandRow: function (record){
  10451. this.each(function(){
  10452. var $t = this;
  10453. if(!$t.grid || !$t.p.treeGrid) {return;}
  10454. var childern = $($t).jqGrid("getNodeChildren",record),
  10455. //if ($($t).jqGrid("isVisibleNode",record)) {
  10456. expanded = $t.p.treeReader.expanded_field,
  10457. rows = $t.rows;
  10458. $(childern).each(function(){
  10459. var id = $.jgrid.getAccessor(this,$t.p.localReader.id);
  10460. $(rows.namedItem(id)).css("display","");
  10461. if(this[expanded]) {
  10462. $($t).jqGrid("expandRow",this);
  10463. }
  10464. });
  10465. //}
  10466. });
  10467. },
  10468. collapseRow : function (record) {
  10469. this.each(function(){
  10470. var $t = this;
  10471. if(!$t.grid || !$t.p.treeGrid) {return;}
  10472. var childern = $($t).jqGrid("getNodeChildren",record),
  10473. expanded = $t.p.treeReader.expanded_field,
  10474. rows = $t.rows;
  10475. $(childern).each(function(){
  10476. var id = $.jgrid.getAccessor(this,$t.p.localReader.id);
  10477. $(rows.namedItem(id)).css("display","none");
  10478. if(this[expanded]){
  10479. $($t).jqGrid("collapseRow",this);
  10480. }
  10481. });
  10482. });
  10483. },
  10484. // NS ,adjacency models
  10485. getRootNodes : function() {
  10486. var result = [];
  10487. this.each(function(){
  10488. var $t = this;
  10489. if(!$t.grid || !$t.p.treeGrid) {return;}
  10490. switch ($t.p.treeGridModel) {
  10491. case 'nested' :
  10492. var level = $t.p.treeReader.level_field;
  10493. $($t.p.data).each(function(){
  10494. if(parseInt(this[level],10) === parseInt($t.p.tree_root_level,10)) {
  10495. result.push(this);
  10496. }
  10497. });
  10498. break;
  10499. case 'adjacency' :
  10500. var parent_id = $t.p.treeReader.parent_id_field;
  10501. $($t.p.data).each(function(){
  10502. if(this[parent_id] === null || String(this[parent_id]).toLowerCase() == "null") {
  10503. result.push(this);
  10504. }
  10505. });
  10506. break;
  10507. }
  10508. });
  10509. return result;
  10510. },
  10511. getNodeDepth : function(rc) {
  10512. var ret = null;
  10513. this.each(function(){
  10514. if(!this.grid || !this.p.treeGrid) {return;}
  10515. var $t = this;
  10516. switch ($t.p.treeGridModel) {
  10517. case 'nested' :
  10518. var level = $t.p.treeReader.level_field;
  10519. ret = parseInt(rc[level],10) - parseInt($t.p.tree_root_level,10);
  10520. break;
  10521. case 'adjacency' :
  10522. ret = $($t).jqGrid("getNodeAncestors",rc).length;
  10523. break;
  10524. }
  10525. });
  10526. return ret;
  10527. },
  10528. getNodeParent : function(rc) {
  10529. var result = null;
  10530. this.each(function(){
  10531. var $t = this;
  10532. if(!$t.grid || !$t.p.treeGrid) {return;}
  10533. switch ($t.p.treeGridModel) {
  10534. case 'nested' :
  10535. var lftc = $t.p.treeReader.left_field,
  10536. rgtc = $t.p.treeReader.right_field,
  10537. levelc = $t.p.treeReader.level_field,
  10538. lft = parseInt(rc[lftc],10), rgt = parseInt(rc[rgtc],10), level = parseInt(rc[levelc],10);
  10539. $(this.p.data).each(function(){
  10540. if(parseInt(this[levelc],10) === level-1 && parseInt(this[lftc],10) < lft && parseInt(this[rgtc],10) > rgt) {
  10541. result = this;
  10542. return false;
  10543. }
  10544. });
  10545. break;
  10546. case 'adjacency' :
  10547. var parent_id = $t.p.treeReader.parent_id_field,
  10548. dtid = $t.p.localReader.id;
  10549. $(this.p.data).each(function(){
  10550. if(this[dtid] == rc[parent_id] ) {
  10551. result = this;
  10552. return false;
  10553. }
  10554. });
  10555. break;
  10556. }
  10557. });
  10558. return result;
  10559. },
  10560. getNodeChildren : function(rc) {
  10561. var result = [];
  10562. this.each(function(){
  10563. var $t = this;
  10564. if(!$t.grid || !$t.p.treeGrid) {return;}
  10565. switch ($t.p.treeGridModel) {
  10566. case 'nested' :
  10567. var lftc = $t.p.treeReader.left_field,
  10568. rgtc = $t.p.treeReader.right_field,
  10569. levelc = $t.p.treeReader.level_field,
  10570. lft = parseInt(rc[lftc],10), rgt = parseInt(rc[rgtc],10), level = parseInt(rc[levelc],10);
  10571. $(this.p.data).each(function(){
  10572. if(parseInt(this[levelc],10) === level+1 && parseInt(this[lftc],10) > lft && parseInt(this[rgtc],10) < rgt) {
  10573. result.push(this);
  10574. }
  10575. });
  10576. break;
  10577. case 'adjacency' :
  10578. var parent_id = $t.p.treeReader.parent_id_field,
  10579. dtid = $t.p.localReader.id;
  10580. $(this.p.data).each(function(){
  10581. if(this[parent_id] == rc[dtid]) {
  10582. result.push(this);
  10583. }
  10584. });
  10585. break;
  10586. }
  10587. });
  10588. return result;
  10589. },
  10590. getFullTreeNode : function(rc) {
  10591. var result = [];
  10592. this.each(function(){
  10593. var $t = this, len;
  10594. if(!$t.grid || !$t.p.treeGrid) {return;}
  10595. switch ($t.p.treeGridModel) {
  10596. case 'nested' :
  10597. var lftc = $t.p.treeReader.left_field,
  10598. rgtc = $t.p.treeReader.right_field,
  10599. levelc = $t.p.treeReader.level_field,
  10600. lft = parseInt(rc[lftc],10), rgt = parseInt(rc[rgtc],10), level = parseInt(rc[levelc],10);
  10601. $(this.p.data).each(function(){
  10602. if(parseInt(this[levelc],10) >= level && parseInt(this[lftc],10) >= lft && parseInt(this[lftc],10) <= rgt) {
  10603. result.push(this);
  10604. }
  10605. });
  10606. break;
  10607. case 'adjacency' :
  10608. if(rc) {
  10609. result.push(rc);
  10610. var parent_id = $t.p.treeReader.parent_id_field,
  10611. dtid = $t.p.localReader.id;
  10612. $(this.p.data).each(function(i){
  10613. len = result.length;
  10614. for (i = 0; i < len; i++) {
  10615. if (result[i][dtid] == this[parent_id]) {
  10616. result.push(this);
  10617. break;
  10618. }
  10619. }
  10620. });
  10621. }
  10622. break;
  10623. }
  10624. });
  10625. return result;
  10626. },
  10627. // End NS, adjacency Model
  10628. getNodeAncestors : function(rc) {
  10629. var ancestors = [];
  10630. this.each(function(){
  10631. if(!this.grid || !this.p.treeGrid) {return;}
  10632. var parent = $(this).jqGrid("getNodeParent",rc);
  10633. while (parent) {
  10634. ancestors.push(parent);
  10635. parent = $(this).jqGrid("getNodeParent",parent);
  10636. }
  10637. });
  10638. return ancestors;
  10639. },
  10640. isVisibleNode : function(rc) {
  10641. var result = true;
  10642. this.each(function(){
  10643. var $t = this;
  10644. if(!$t.grid || !$t.p.treeGrid) {return;}
  10645. var ancestors = $($t).jqGrid("getNodeAncestors",rc),
  10646. expanded = $t.p.treeReader.expanded_field;
  10647. $(ancestors).each(function(){
  10648. result = result && this[expanded];
  10649. if(!result) {return false;}
  10650. });
  10651. });
  10652. return result;
  10653. },
  10654. isNodeLoaded : function(rc) {
  10655. var result;
  10656. this.each(function(){
  10657. var $t = this;
  10658. if(!$t.grid || !$t.p.treeGrid) {return;}
  10659. var isLeaf = $t.p.treeReader.leaf_field;
  10660. if(rc !== undefined ) {
  10661. if(rc.loaded !== undefined) {
  10662. result = rc.loaded;
  10663. } else if( rc[isLeaf] || $($t).jqGrid("getNodeChildren",rc).length > 0){
  10664. result = true;
  10665. } else {
  10666. result = false;
  10667. }
  10668. } else {
  10669. result = false;
  10670. }
  10671. });
  10672. return result;
  10673. },
  10674. expandNode : function(rc) {
  10675. return this.each(function(){
  10676. if(!this.grid || !this.p.treeGrid) {return;}
  10677. var expanded = this.p.treeReader.expanded_field,
  10678. parent = this.p.treeReader.parent_id_field,
  10679. loaded = this.p.treeReader.loaded,
  10680. level = this.p.treeReader.level_field,
  10681. lft = this.p.treeReader.left_field,
  10682. rgt = this.p.treeReader.right_field;
  10683. if(!rc[expanded]) {
  10684. var id = $.jgrid.getAccessor(rc,this.p.localReader.id);
  10685. var rc1 = $("#"+$.jgrid.jqID(id),this.grid.bDiv)[0];
  10686. var position = this.p._index[id];
  10687. if( $(this).jqGrid("isNodeLoaded",this.p.data[position]) ) {
  10688. rc[expanded] = true;
  10689. $("div.treeclick",rc1).removeClass(this.p.treeIcons.plus+" tree-plus").addClass(this.p.treeIcons.minus+" tree-minus");
  10690. } else if (!this.grid.hDiv.loading) {
  10691. rc[expanded] = true;
  10692. $("div.treeclick",rc1).removeClass(this.p.treeIcons.plus+" tree-plus").addClass(this.p.treeIcons.minus+" tree-minus");
  10693. this.p.treeANode = rc1.rowIndex;
  10694. this.p.datatype = this.p.treedatatype;
  10695. if(this.p.treeGridModel == 'nested') {
  10696. $(this).jqGrid("setGridParam",{postData:{nodeid:id,n_left:rc[lft],n_right:rc[rgt],n_level:rc[level]}});
  10697. } else {
  10698. $(this).jqGrid("setGridParam",{postData:{nodeid:id,parentid:rc[parent],n_level:rc[level]}} );
  10699. }
  10700. $(this).trigger("reloadGrid");
  10701. rc[loaded] = true;
  10702. if(this.p.treeGridModel == 'nested') {
  10703. $(this).jqGrid("setGridParam",{postData:{nodeid:'',n_left:'',n_right:'',n_level:''}});
  10704. } else {
  10705. $(this).jqGrid("setGridParam",{postData:{nodeid:'',parentid:'',n_level:''}});
  10706. }
  10707. }
  10708. }
  10709. });
  10710. },
  10711. collapseNode : function(rc) {
  10712. return this.each(function(){
  10713. if(!this.grid || !this.p.treeGrid) {return;}
  10714. var expanded = this.p.treeReader.expanded_field;
  10715. if(rc[expanded]) {
  10716. rc[expanded] = false;
  10717. var id = $.jgrid.getAccessor(rc,this.p.localReader.id);
  10718. var rc1 = $("#"+$.jgrid.jqID(id),this.grid.bDiv)[0];
  10719. $("div.treeclick",rc1).removeClass(this.p.treeIcons.minus+" tree-minus").addClass(this.p.treeIcons.plus+" tree-plus");
  10720. }
  10721. });
  10722. },
  10723. SortTree : function( sortname, newDir, st, datefmt) {
  10724. return this.each(function(){
  10725. if(!this.grid || !this.p.treeGrid) {return;}
  10726. var i, len,
  10727. rec, records = [], $t = this, query, roots,
  10728. rt = $(this).jqGrid("getRootNodes");
  10729. // Sorting roots
  10730. query = $.jgrid.from(rt);
  10731. query.orderBy(sortname,newDir,st, datefmt);
  10732. roots = query.select();
  10733. // Sorting children
  10734. for (i = 0, len = roots.length; i < len; i++) {
  10735. rec = roots[i];
  10736. records.push(rec);
  10737. $(this).jqGrid("collectChildrenSortTree",records, rec, sortname, newDir,st, datefmt);
  10738. }
  10739. $.each(records, function(index) {
  10740. var id = $.jgrid.getAccessor(this,$t.p.localReader.id);
  10741. $('#'+$.jgrid.jqID($t.p.id)+ ' tbody tr:eq('+index+')').after($('tr#'+$.jgrid.jqID(id),$t.grid.bDiv));
  10742. });
  10743. query = null;roots=null;records=null;
  10744. });
  10745. },
  10746. collectChildrenSortTree : function(records, rec, sortname, newDir,st, datefmt) {
  10747. return this.each(function(){
  10748. if(!this.grid || !this.p.treeGrid) {return;}
  10749. var i, len,
  10750. child, ch, query, children;
  10751. ch = $(this).jqGrid("getNodeChildren",rec);
  10752. query = $.jgrid.from(ch);
  10753. query.orderBy(sortname, newDir, st, datefmt);
  10754. children = query.select();
  10755. for (i = 0, len = children.length; i < len; i++) {
  10756. child = children[i];
  10757. records.push(child);
  10758. $(this).jqGrid("collectChildrenSortTree",records, child, sortname, newDir, st, datefmt);
  10759. }
  10760. });
  10761. },
  10762. // experimental
  10763. setTreeRow : function(rowid, data) {
  10764. var success=false;
  10765. this.each(function(){
  10766. var t = this;
  10767. if(!t.grid || !t.p.treeGrid) {return;}
  10768. success = $(t).jqGrid("setRowData",rowid,data);
  10769. });
  10770. return success;
  10771. },
  10772. delTreeNode : function (rowid) {
  10773. return this.each(function () {
  10774. var $t = this, rid = $t.p.localReader.id, i,
  10775. left = $t.p.treeReader.left_field,
  10776. right = $t.p.treeReader.right_field, myright, width, res, key;
  10777. if(!$t.grid || !$t.p.treeGrid) {return;}
  10778. var rc = $t.p._index[rowid];
  10779. if (rc !== undefined) {
  10780. // nested
  10781. myright = parseInt($t.p.data[rc][right],10);
  10782. width = myright - parseInt($t.p.data[rc][left],10) + 1;
  10783. var dr = $($t).jqGrid("getFullTreeNode",$t.p.data[rc]);
  10784. if(dr.length>0){
  10785. for (i=0;i<dr.length;i++){
  10786. $($t).jqGrid("delRowData",dr[i][rid]);
  10787. }
  10788. }
  10789. if( $t.p.treeGridModel === "nested") {
  10790. // ToDo - update grid data
  10791. res = $.jgrid.from($t.p.data)
  10792. .greater(left,myright,{stype:'integer'})
  10793. .select();
  10794. if(res.length) {
  10795. for( key in res) {
  10796. if(res.hasOwnProperty(key)) {
  10797. res[key][left] = parseInt(res[key][left],10) - width ;
  10798. }
  10799. }
  10800. }
  10801. res = $.jgrid.from($t.p.data)
  10802. .greater(right,myright,{stype:'integer'})
  10803. .select();
  10804. if(res.length) {
  10805. for( key in res) {
  10806. if(res.hasOwnProperty(key)) {
  10807. res[key][right] = parseInt(res[key][right],10) - width ;
  10808. }
  10809. }
  10810. }
  10811. }
  10812. }
  10813. });
  10814. },
  10815. addChildNode : function( nodeid, parentid, data, expandData ) {
  10816. //return this.each(function(){
  10817. var $t = this[0];
  10818. if(data) {
  10819. // we suppose tha the id is autoincremet and
  10820. var expanded = $t.p.treeReader.expanded_field,
  10821. isLeaf = $t.p.treeReader.leaf_field,
  10822. level = $t.p.treeReader.level_field,
  10823. //icon = $t.p.treeReader.icon_field,
  10824. parent = $t.p.treeReader.parent_id_field,
  10825. left = $t.p.treeReader.left_field,
  10826. right = $t.p.treeReader.right_field,
  10827. loaded = $t.p.treeReader.loaded,
  10828. method, parentindex, parentdata, parentlevel, i, len, max=0, rowind = parentid, leaf, maxright;
  10829. if(expandData===undefined) {expandData = false;}
  10830. if ( nodeid === undefined || nodeid === null ) {
  10831. i = $t.p.data.length-1;
  10832. if( i>= 0 ) {
  10833. while(i>=0){max = Math.max(max, parseInt($t.p.data[i][$t.p.localReader.id],10)); i--;}
  10834. }
  10835. nodeid = max+1;
  10836. }
  10837. var prow = $($t).jqGrid('getInd', parentid);
  10838. leaf = false;
  10839. // if not a parent we assume root
  10840. if ( parentid === undefined || parentid === null || parentid==="") {
  10841. parentid = null;
  10842. rowind = null;
  10843. method = 'last';
  10844. parentlevel = $t.p.tree_root_level;
  10845. i = $t.p.data.length+1;
  10846. } else {
  10847. method = 'after';
  10848. parentindex = $t.p._index[parentid];
  10849. parentdata = $t.p.data[parentindex];
  10850. parentid = parentdata[$t.p.localReader.id];
  10851. parentlevel = parseInt(parentdata[level],10)+1;
  10852. var childs = $($t).jqGrid('getFullTreeNode', parentdata);
  10853. // if there are child nodes get the last index of it
  10854. if(childs.length) {
  10855. i = childs[childs.length-1][$t.p.localReader.id];
  10856. rowind = i;
  10857. i = $($t).jqGrid('getInd',rowind)+1;
  10858. } else {
  10859. i = $($t).jqGrid('getInd', parentid)+1;
  10860. }
  10861. // if the node is leaf
  10862. if(parentdata[isLeaf]) {
  10863. leaf = true;
  10864. parentdata[expanded] = true;
  10865. //var prow = $($t).jqGrid('getInd', parentid);
  10866. $($t.rows[prow])
  10867. .find("span.cell-wrapperleaf").removeClass("cell-wrapperleaf").addClass("cell-wrapper")
  10868. .end()
  10869. .find("div.tree-leaf").removeClass($t.p.treeIcons.leaf+" tree-leaf").addClass($t.p.treeIcons.minus+" tree-minus");
  10870. $t.p.data[parentindex][isLeaf] = false;
  10871. parentdata[loaded] = true;
  10872. }
  10873. }
  10874. len = i+1;
  10875. if( data[expanded]===undefined) {data[expanded]= false;}
  10876. if( data[loaded]===undefined ) { data[loaded] = false;}
  10877. data[level] = parentlevel;
  10878. if( data[isLeaf]===undefined) {data[isLeaf]= true;}
  10879. if( $t.p.treeGridModel === "adjacency") {
  10880. data[parent] = parentid;
  10881. }
  10882. if( $t.p.treeGridModel === "nested") {
  10883. // this method requiere more attention
  10884. var query, res, key;
  10885. //maxright = parseInt(maxright,10);
  10886. // ToDo - update grid data
  10887. if(parentid !== null) {
  10888. maxright = parseInt(parentdata[right],10);
  10889. query = $.jgrid.from($t.p.data);
  10890. query = query.greaterOrEquals(right,maxright,{stype:'integer'});
  10891. res = query.select();
  10892. if(res.length) {
  10893. for( key in res) {
  10894. if(res.hasOwnProperty(key)) {
  10895. res[key][left] = res[key][left] > maxright ? parseInt(res[key][left],10) +2 : res[key][left];
  10896. res[key][right] = res[key][right] >= maxright ? parseInt(res[key][right],10) +2 : res[key][right];
  10897. }
  10898. }
  10899. }
  10900. data[left] = maxright;
  10901. data[right]= maxright+1;
  10902. } else {
  10903. maxright = parseInt( $($t).jqGrid('getCol', right, false, 'max'), 10);
  10904. res = $.jgrid.from($t.p.data)
  10905. .greater(left,maxright,{stype:'integer'})
  10906. .select();
  10907. if(res.length) {
  10908. for( key in res) {
  10909. if(res.hasOwnProperty(key)) {
  10910. res[key][left] = parseInt(res[key][left],10) +2 ;
  10911. }
  10912. }
  10913. }
  10914. res = $.jgrid.from($t.p.data)
  10915. .greater(right,maxright,{stype:'integer'})
  10916. .select();
  10917. if(res.length) {
  10918. for( key in res) {
  10919. if(res.hasOwnProperty(key)) {
  10920. res[key][right] = parseInt(res[key][right],10) +2 ;
  10921. }
  10922. }
  10923. }
  10924. data[left] = maxright+1;
  10925. data[right] = maxright + 2;
  10926. }
  10927. }
  10928. if( parentid === null || $($t).jqGrid("isNodeLoaded",parentdata) || leaf ) {
  10929. $($t).jqGrid('addRowData', nodeid, data, method, rowind);
  10930. $($t).jqGrid('setTreeNode', i, len);
  10931. }
  10932. if(parentdata && !parentdata[expanded] && expandData) {
  10933. $($t.rows[prow])
  10934. .find("div.treeclick")
  10935. .click();
  10936. }
  10937. }
  10938. //});
  10939. }
  10940. });
  10941. })(jQuery);
  10942. /*jshint eqeqeq:false, eqnull:true */
  10943. /*global jQuery */
  10944. // Grouping module
  10945. (function($){
  10946. "use strict";
  10947. $.extend($.jgrid,{
  10948. template : function(format){ //jqgformat
  10949. var args = $.makeArray(arguments).slice(1), j, al = args.length;
  10950. if(format==null) { format = ""; }
  10951. return format.replace(/\{([\w\-]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g, function(m,i){
  10952. if(!isNaN(parseInt(i,10))) {
  10953. return args[parseInt(i,10)];
  10954. }
  10955. for(j=0; j < al;j++) {
  10956. if($.isArray(args[j])) {
  10957. var nmarr = args[ j ],
  10958. k = nmarr.length;
  10959. while(k--) {
  10960. if(i===nmarr[k].nm) {
  10961. return nmarr[k].v;
  10962. }
  10963. }
  10964. }
  10965. }
  10966. });
  10967. }
  10968. });
  10969. $.jgrid.extend({
  10970. groupingSetup : function () {
  10971. return this.each(function (){
  10972. var $t = this, i, j, cml, cm = $t.p.colModel, grp = $t.p.groupingView;
  10973. if(grp !== null && ( (typeof grp === 'object') || $.isFunction(grp) ) ) {
  10974. if(!grp.groupField.length) {
  10975. $t.p.grouping = false;
  10976. } else {
  10977. if (grp.visibiltyOnNextGrouping === undefined) {
  10978. grp.visibiltyOnNextGrouping = [];
  10979. }
  10980. grp.lastvalues=[];
  10981. grp.groups =[];
  10982. grp.counters =[];
  10983. for(i=0;i<grp.groupField.length;i++) {
  10984. if(!grp.groupOrder[i]) {
  10985. grp.groupOrder[i] = 'asc';
  10986. }
  10987. if(!grp.groupText[i]) {
  10988. grp.groupText[i] = '{0}';
  10989. }
  10990. if( typeof grp.groupColumnShow[i] !== 'boolean') {
  10991. grp.groupColumnShow[i] = true;
  10992. }
  10993. if( typeof grp.groupSummary[i] !== 'boolean') {
  10994. grp.groupSummary[i] = false;
  10995. }
  10996. if(grp.groupColumnShow[i] === true) {
  10997. grp.visibiltyOnNextGrouping[i] = true;
  10998. $($t).jqGrid('showCol',grp.groupField[i]);
  10999. } else {
  11000. grp.visibiltyOnNextGrouping[i] = $("#"+$.jgrid.jqID($t.p.id+"_"+grp.groupField[i])).is(":visible");
  11001. $($t).jqGrid('hideCol',grp.groupField[i]);
  11002. }
  11003. }
  11004. grp.summary =[];
  11005. for(j=0, cml = cm.length; j < cml; j++) {
  11006. if(cm[j].summaryType) {
  11007. grp.summary.push({nm:cm[j].name,st:cm[j].summaryType, v: '', sr: cm[j].summaryRound, srt: cm[j].summaryRoundType || 'round'});
  11008. }
  11009. }
  11010. }
  11011. } else {
  11012. $t.p.grouping = false;
  11013. }
  11014. });
  11015. },
  11016. groupingPrepare : function (rData, gdata, record, irow) {
  11017. this.each(function(){
  11018. var grp = this.p.groupingView, $t= this, i,
  11019. grlen = grp.groupField.length,
  11020. fieldName,
  11021. v,
  11022. displayName,
  11023. displayValue,
  11024. changed = 0;
  11025. for(i=0;i<grlen;i++) {
  11026. fieldName = grp.groupField[i];
  11027. displayName = grp.displayField[i];
  11028. v = record[fieldName];
  11029. displayValue = displayName == null ? null : record[displayName];
  11030. if( displayValue == null ) {
  11031. displayValue = v;
  11032. }
  11033. if( v !== undefined ) {
  11034. if(irow === 0 ) {
  11035. // First record always starts a new group
  11036. grp.groups.push({idx:i,dataIndex:fieldName,value:v, displayValue: displayValue, startRow: irow, cnt:1, summary : [] } );
  11037. grp.lastvalues[i] = v;
  11038. grp.counters[i] = {cnt:1, pos:grp.groups.length-1, summary: $.extend(true,[],grp.summary)};
  11039. $.each(grp.counters[i].summary,function() {
  11040. if ($.isFunction(this.st)) {
  11041. this.v = this.st.call($t, this.v, this.nm, record);
  11042. } else {
  11043. this.v = $($t).jqGrid('groupingCalculations.handler',this.st, this.v, this.nm, this.sr, this.srt, record);
  11044. }
  11045. });
  11046. grp.groups[grp.counters[i].pos].summary = grp.counters[i].summary;
  11047. } else {
  11048. if( typeof v !== "object" && grp.lastvalues[i] !== v ) {
  11049. // This record is not in same group as previous one
  11050. grp.groups.push({idx:i,dataIndex:fieldName,value:v, displayValue: displayValue, startRow: irow, cnt:1, summary : [] } );
  11051. grp.lastvalues[i] = v;
  11052. changed = 1;
  11053. grp.counters[i] = {cnt:1, pos:grp.groups.length-1, summary: $.extend(true,[],grp.summary)};
  11054. $.each(grp.counters[i].summary,function() {
  11055. if ($.isFunction(this.st)) {
  11056. this.v = this.st.call($t, this.v, this.nm, record);
  11057. } else {
  11058. this.v = $($t).jqGrid('groupingCalculations.handler',this.st, this.v, this.nm, this.sr, this.srt, record);
  11059. }
  11060. });
  11061. grp.groups[grp.counters[i].pos].summary = grp.counters[i].summary;
  11062. } else {
  11063. if (changed === 1) {
  11064. // This group has changed because an earlier group changed.
  11065. grp.groups.push({idx:i,dataIndex:fieldName,value:v, displayValue: displayValue, startRow: irow, cnt:1, summary : [] } );
  11066. grp.lastvalues[i] = v;
  11067. grp.counters[i] = {cnt:1, pos:grp.groups.length-1, summary: $.extend(true,[],grp.summary)};
  11068. $.each(grp.counters[i].summary,function() {
  11069. if ($.isFunction(this.st)) {
  11070. this.v = this.st.call($t, this.v, this.nm, record);
  11071. } else {
  11072. this.v = $($t).jqGrid('groupingCalculations.handler',this.st, this.v, this.nm, this.sr, this.srt, record);
  11073. }
  11074. });
  11075. grp.groups[grp.counters[i].pos].summary = grp.counters[i].summary;
  11076. } else {
  11077. grp.counters[i].cnt += 1;
  11078. grp.groups[grp.counters[i].pos].cnt = grp.counters[i].cnt;
  11079. $.each(grp.counters[i].summary,function() {
  11080. if ($.isFunction(this.st)) {
  11081. this.v = this.st.call($t, this.v, this.nm, record);
  11082. } else {
  11083. this.v = $($t).jqGrid('groupingCalculations.handler',this.st, this.v, this.nm, this.sr, this.srt, record);
  11084. }
  11085. });
  11086. grp.groups[grp.counters[i].pos].summary = grp.counters[i].summary;
  11087. }
  11088. }
  11089. }
  11090. }
  11091. }
  11092. gdata.push( rData );
  11093. });
  11094. return gdata;
  11095. },
  11096. groupingToggle : function(hid){
  11097. this.each(function(){
  11098. var $t = this,
  11099. grp = $t.p.groupingView,
  11100. strpos = hid.split('_'),
  11101. //uid = hid.substring(0,strpos+1),
  11102. num = parseInt(strpos[strpos.length-2], 10);
  11103. strpos.splice(strpos.length-2,2);
  11104. var uid = strpos.join("_"),
  11105. minus = grp.minusicon,
  11106. plus = grp.plusicon,
  11107. tar = $("#"+$.jgrid.jqID(hid)),
  11108. r = tar.length ? tar[0].nextSibling : null,
  11109. tarspan = $("#"+$.jgrid.jqID(hid)+" span."+"tree-wrap-"+$t.p.direction),
  11110. collapsed = false, tspan;
  11111. if( tarspan.hasClass(minus) ) {
  11112. if(grp.showSummaryOnHide) {
  11113. if(r){
  11114. while(r) {
  11115. if($(r).hasClass('jqfoot') ) {
  11116. var lv = parseInt($(r).attr("jqfootlevel"),10);
  11117. if( lv <= num) {
  11118. break;
  11119. }
  11120. }
  11121. $(r).hide();
  11122. r = r.nextSibling;
  11123. }
  11124. }
  11125. } else {
  11126. if(r){
  11127. while(r) {
  11128. if( $(r).hasClass(uid+"_"+String(num) ) || $(r).hasClass(uid+"_"+String(num-1))) { break; }
  11129. $(r).hide();
  11130. r = r.nextSibling;
  11131. }
  11132. }
  11133. }
  11134. tarspan.removeClass(minus).addClass(plus);
  11135. collapsed = true;
  11136. } else {
  11137. if(r){
  11138. while(r) {
  11139. if($(r).hasClass(uid+"_"+String(num)) || $(r).hasClass(uid+"_"+String(num-1)) ) { break; }
  11140. $(r).show();
  11141. tspan = $(r).find("span."+"tree-wrap-"+$t.p.direction);
  11142. if( tspan && $(tspan).hasClass(plus) ) {
  11143. $(tspan).removeClass(plus).addClass(minus);
  11144. }
  11145. r = r.nextSibling;
  11146. }
  11147. }
  11148. tarspan.removeClass(plus).addClass(minus);
  11149. }
  11150. $($t).triggerHandler("jqGridGroupingClickGroup", [hid , collapsed]);
  11151. if( $.isFunction($t.p.onClickGroup)) { $t.p.onClickGroup.call($t, hid , collapsed); }
  11152. });
  11153. return false;
  11154. },
  11155. groupingRender : function (grdata, colspans ) {
  11156. return this.each(function(){
  11157. var $t = this,
  11158. grp = $t.p.groupingView,
  11159. str = "", icon = "", hid, clid, pmrtl = grp.groupCollapse ? grp.plusicon : grp.minusicon, gv, cp=[], len =grp.groupField.length;
  11160. pmrtl += " tree-wrap-"+$t.p.direction;
  11161. $.each($t.p.colModel, function (i,n){
  11162. var ii;
  11163. for(ii=0;ii<len;ii++) {
  11164. if(grp.groupField[ii] === n.name ) {
  11165. cp[ii] = i;
  11166. break;
  11167. }
  11168. }
  11169. });
  11170. var toEnd = 0;
  11171. function findGroupIdx( ind , offset, grp) {
  11172. var ret = false, i;
  11173. if(offset===0) {
  11174. ret = grp[ind];
  11175. } else {
  11176. var id = grp[ind].idx;
  11177. if(id===0) {
  11178. ret = grp[ind];
  11179. } else {
  11180. for(i=ind;i >= 0; i--) {
  11181. if(grp[i].idx === id-offset) {
  11182. ret = grp[i];
  11183. break;
  11184. }
  11185. }
  11186. }
  11187. }
  11188. return ret;
  11189. }
  11190. var sumreverse = $.makeArray(grp.groupSummary);
  11191. sumreverse.reverse();
  11192. $.each(grp.groups,function(i,n){
  11193. toEnd++;
  11194. clid = $t.p.id+"ghead_"+n.idx;
  11195. hid = clid+"_"+i;
  11196. icon = "<span style='cursor:pointer;' class='ui-icon "+pmrtl+"' onclick=\"jQuery('#"+$.jgrid.jqID($t.p.id)+"').jqGrid('groupingToggle','"+hid+"');return false;\"></span>";
  11197. try {
  11198. gv = $t.formatter(hid, n.displayValue, cp[n.idx], n.value );
  11199. } catch (egv) {
  11200. gv = n.displayValue;
  11201. }
  11202. str += "<tr id=\""+hid+"\" role=\"row\" class= \"ui-widget-content jqgroup ui-row-"+$t.p.direction+" "+clid+"\"><td style=\"padding-left:"+(n.idx * 12) + "px;"+"\" colspan=\""+colspans+"\">"+icon+$.jgrid.template(grp.groupText[n.idx], gv, n.cnt, n.summary)+"</td></tr>";
  11203. var leaf = len-1 === n.idx;
  11204. if( leaf ) {
  11205. var gg = grp.groups[i+1], k, kk, ik;
  11206. var end = gg !== undefined ? grp.groups[i+1].startRow : grdata.length;
  11207. for(kk=n.startRow;kk<end;kk++) {
  11208. str += grdata[kk].join('');
  11209. }
  11210. var jj;
  11211. if (gg !== undefined) {
  11212. for (jj = 0; jj < grp.groupField.length; jj++) {
  11213. if (gg.dataIndex === grp.groupField[jj]) {
  11214. break;
  11215. }
  11216. }
  11217. toEnd = grp.groupField.length - jj;
  11218. }
  11219. for (ik = 0; ik < toEnd; ik++) {
  11220. if(!sumreverse[ik]) { continue; }
  11221. var hhdr = "";
  11222. if(grp.groupCollapse && !grp.showSummaryOnHide) {
  11223. hhdr = " style=\"display:none;\"";
  11224. }
  11225. str += "<tr"+hhdr+" jqfootlevel=\""+(n.idx-ik)+"\" role=\"row\" class=\"ui-widget-content jqfoot ui-row-"+$t.p.direction+"\">";
  11226. var fdata = findGroupIdx(i, ik, grp.groups),
  11227. cm = $t.p.colModel,
  11228. vv, grlen = fdata.cnt;
  11229. for(k=0; k<colspans;k++) {
  11230. var tmpdata = "<td "+$t.formatCol(k,1,'')+">&#160;</td>",
  11231. tplfld = "{0}";
  11232. $.each(fdata.summary,function(){
  11233. if(this.nm === cm[k].name) {
  11234. if(cm[k].summaryTpl) {
  11235. tplfld = cm[k].summaryTpl;
  11236. }
  11237. if(typeof this.st === 'string' && this.st.toLowerCase() === 'avg') {
  11238. if(this.v && grlen > 0) {
  11239. this.v = (this.v/grlen);
  11240. }
  11241. }
  11242. try {
  11243. vv = $t.formatter('', this.v, k, this);
  11244. } catch (ef) {
  11245. vv = this.v;
  11246. }
  11247. tmpdata= "<td "+$t.formatCol(k,1,'')+">"+$.jgrid.format(tplfld,vv)+ "</td>";
  11248. return false;
  11249. }
  11250. });
  11251. str += tmpdata;
  11252. }
  11253. str += "</tr>";
  11254. }
  11255. toEnd = jj;
  11256. }
  11257. });
  11258. $("#"+$.jgrid.jqID($t.p.id)+" tbody:first").append(str);
  11259. // free up memory
  11260. str = null;
  11261. });
  11262. },
  11263. groupingGroupBy : function (name, options ) {
  11264. return this.each(function(){
  11265. var $t = this;
  11266. if(typeof name === "string") {
  11267. name = [name];
  11268. }
  11269. var grp = $t.p.groupingView;
  11270. $t.p.grouping = true;
  11271. //Set default, in case visibilityOnNextGrouping is undefined
  11272. if (grp.visibiltyOnNextGrouping === undefined) {
  11273. grp.visibiltyOnNextGrouping = [];
  11274. }
  11275. var i;
  11276. // show previous hidden groups if they are hidden and weren't removed yet
  11277. for(i=0;i<grp.groupField.length;i++) {
  11278. if(!grp.groupColumnShow[i] && grp.visibiltyOnNextGrouping[i]) {
  11279. $($t).jqGrid('showCol',grp.groupField[i]);
  11280. }
  11281. }
  11282. // set visibility status of current group columns on next grouping
  11283. for(i=0;i<name.length;i++) {
  11284. grp.visibiltyOnNextGrouping[i] = $("#"+$.jgrid.jqID($t.p.id)+"_"+$.jgrid.jqID(name[i])).is(":visible");
  11285. }
  11286. $t.p.groupingView = $.extend($t.p.groupingView, options || {});
  11287. grp.groupField = name;
  11288. $($t).trigger("reloadGrid");
  11289. });
  11290. },
  11291. groupingRemove : function (current) {
  11292. return this.each(function(){
  11293. var $t = this;
  11294. if(current === undefined) {
  11295. current = true;
  11296. }
  11297. $t.p.grouping = false;
  11298. if(current===true) {
  11299. var grp = $t.p.groupingView, i;
  11300. // show previous hidden groups if they are hidden and weren't removed yet
  11301. for(i=0;i<grp.groupField.length;i++) {
  11302. if (!grp.groupColumnShow[i] && grp.visibiltyOnNextGrouping[i]) {
  11303. $($t).jqGrid('showCol', grp.groupField);
  11304. }
  11305. }
  11306. $("tr.jqgroup, tr.jqfoot","#"+$.jgrid.jqID($t.p.id)+" tbody:first").remove();
  11307. $("tr.jqgrow:hidden","#"+$.jgrid.jqID($t.p.id)+" tbody:first").show();
  11308. } else {
  11309. $($t).trigger("reloadGrid");
  11310. }
  11311. });
  11312. },
  11313. groupingCalculations : {
  11314. handler: function(fn, v, field, round, roundType, rc) {
  11315. var funcs = {
  11316. sum: function() {
  11317. return parseFloat(v||0) + parseFloat((rc[field]||0));
  11318. },
  11319. min: function() {
  11320. if(v==="") {
  11321. return parseFloat(rc[field]||0);
  11322. }
  11323. return Math.min(parseFloat(v),parseFloat(rc[field]||0));
  11324. },
  11325. max: function() {
  11326. if(v==="") {
  11327. return parseFloat(rc[field]||0);
  11328. }
  11329. return Math.max(parseFloat(v),parseFloat(rc[field]||0));
  11330. },
  11331. count: function() {
  11332. if(v==="") {v=0;}
  11333. if(rc.hasOwnProperty(field)) {
  11334. return v+1;
  11335. }
  11336. return 0;
  11337. },
  11338. avg: function() {
  11339. // the same as sum, but at end we divide it
  11340. // so use sum instead of duplicating the code (?)
  11341. return funcs.sum();
  11342. }
  11343. };
  11344. if(!funcs[fn]) {
  11345. throw ("jqGrid Grouping No such method: " + fn);
  11346. }
  11347. var res = funcs[fn]();
  11348. if (round != null) {
  11349. if (roundType == 'fixed') {
  11350. res = res.toFixed(round);
  11351. } else {
  11352. var mul = Math.pow(10, round);
  11353. res = Math.round(res * mul) / mul;
  11354. }
  11355. }
  11356. return res;
  11357. }
  11358. }
  11359. });
  11360. })(jQuery);
  11361. /*jshint eqeqeq:false, eqnull:true, devel:true */
  11362. /*global jQuery, xmlJsonClass */
  11363. (function($){
  11364. /*
  11365. * jqGrid extension for constructing Grid Data from external file
  11366. * Tony Tomov tony@trirand.com
  11367. * http://trirand.com/blog/
  11368. * Dual licensed under the MIT and GPL licenses:
  11369. * http://www.opensource.org/licenses/mit-license.php
  11370. * http://www.gnu.org/licenses/gpl-2.0.html
  11371. **/
  11372. "use strict";
  11373. $.jgrid.extend({
  11374. jqGridImport : function(o) {
  11375. o = $.extend({
  11376. imptype : "xml", // xml, json, xmlstring, jsonstring
  11377. impstring: "",
  11378. impurl: "",
  11379. mtype: "GET",
  11380. impData : {},
  11381. xmlGrid :{
  11382. config : "roots>grid",
  11383. data: "roots>rows"
  11384. },
  11385. jsonGrid :{
  11386. config : "grid",
  11387. data: "data"
  11388. },
  11389. ajaxOptions :{}
  11390. }, o || {});
  11391. return this.each(function(){
  11392. var $t = this;
  11393. var xmlConvert = function (xml,o) {
  11394. var cnfg = $(o.xmlGrid.config,xml)[0];
  11395. var xmldata = $(o.xmlGrid.data,xml)[0], jstr, jstr1, key;
  11396. if(xmlJsonClass.xml2json && $.jgrid.parse) {
  11397. jstr = xmlJsonClass.xml2json(cnfg," ");
  11398. jstr = $.jgrid.parse(jstr);
  11399. for(key in jstr) {
  11400. if(jstr.hasOwnProperty(key)) {
  11401. jstr1=jstr[key];
  11402. }
  11403. }
  11404. if(xmldata) {
  11405. // save the datatype
  11406. var svdatatype = jstr.grid.datatype;
  11407. jstr.grid.datatype = 'xmlstring';
  11408. jstr.grid.datastr = xml;
  11409. $($t).jqGrid( jstr1 ).jqGrid("setGridParam",{datatype:svdatatype});
  11410. } else {
  11411. $($t).jqGrid( jstr1 );
  11412. }
  11413. jstr = null;jstr1=null;
  11414. } else {
  11415. alert("xml2json or parse are not present");
  11416. }
  11417. };
  11418. var jsonConvert = function (jsonstr,o){
  11419. if (jsonstr && typeof jsonstr == 'string') {
  11420. var _jsonparse = false;
  11421. if($.jgrid.useJSON) {
  11422. $.jgrid.useJSON = false;
  11423. _jsonparse = true;
  11424. }
  11425. var json = $.jgrid.parse(jsonstr);
  11426. if(_jsonparse) { $.jgrid.useJSON = true; }
  11427. var gprm = json[o.jsonGrid.config];
  11428. var jdata = json[o.jsonGrid.data];
  11429. if(jdata) {
  11430. var svdatatype = gprm.datatype;
  11431. gprm.datatype = 'jsonstring';
  11432. gprm.datastr = jdata;
  11433. $($t).jqGrid( gprm ).jqGrid("setGridParam",{datatype:svdatatype});
  11434. } else {
  11435. $($t).jqGrid( gprm );
  11436. }
  11437. }
  11438. };
  11439. switch (o.imptype){
  11440. case 'xml':
  11441. $.ajax($.extend({
  11442. url:o.impurl,
  11443. type:o.mtype,
  11444. data: o.impData,
  11445. dataType:"xml",
  11446. complete: function(xml,stat) {
  11447. if(stat == 'success') {
  11448. xmlConvert(xml.responseXML,o);
  11449. $($t).triggerHandler("jqGridImportComplete", [xml, o]);
  11450. if($.isFunction(o.importComplete)) {
  11451. o.importComplete(xml);
  11452. }
  11453. }
  11454. xml=null;
  11455. }
  11456. }, o.ajaxOptions));
  11457. break;
  11458. case 'xmlstring' :
  11459. // we need to make just the conversion and use the same code as xml
  11460. if(o.impstring && typeof o.impstring == 'string') {
  11461. var xmld = $.jgrid.stringToDoc(o.impstring);
  11462. if(xmld) {
  11463. xmlConvert(xmld,o);
  11464. $($t).triggerHandler("jqGridImportComplete", [xmld, o]);
  11465. if($.isFunction(o.importComplete)) {
  11466. o.importComplete(xmld);
  11467. }
  11468. o.impstring = null;
  11469. }
  11470. xmld = null;
  11471. }
  11472. break;
  11473. case 'json':
  11474. $.ajax($.extend({
  11475. url:o.impurl,
  11476. type:o.mtype,
  11477. data: o.impData,
  11478. dataType:"json",
  11479. complete: function(json) {
  11480. try {
  11481. jsonConvert(json.responseText,o );
  11482. $($t).triggerHandler("jqGridImportComplete", [json, o]);
  11483. if($.isFunction(o.importComplete)) {
  11484. o.importComplete(json);
  11485. }
  11486. } catch (ee){}
  11487. json=null;
  11488. }
  11489. }, o.ajaxOptions ));
  11490. break;
  11491. case 'jsonstring' :
  11492. if(o.impstring && typeof o.impstring == 'string') {
  11493. jsonConvert(o.impstring,o );
  11494. $($t).triggerHandler("jqGridImportComplete", [o.impstring, o]);
  11495. if($.isFunction(o.importComplete)) {
  11496. o.importComplete(o.impstring);
  11497. }
  11498. o.impstring = null;
  11499. }
  11500. break;
  11501. }
  11502. });
  11503. },
  11504. jqGridExport : function(o) {
  11505. o = $.extend({
  11506. exptype : "xmlstring",
  11507. root: "grid",
  11508. ident: "\t"
  11509. }, o || {});
  11510. var ret = null;
  11511. this.each(function () {
  11512. if(!this.grid) { return;}
  11513. var key, gprm = $.extend(true, {},$(this).jqGrid("getGridParam"));
  11514. // we need to check for:
  11515. // 1.multiselect, 2.subgrid 3. treegrid and remove the unneded columns from colNames
  11516. if(gprm.rownumbers) {
  11517. gprm.colNames.splice(0,1);
  11518. gprm.colModel.splice(0,1);
  11519. }
  11520. if(gprm.multiselect) {
  11521. gprm.colNames.splice(0,1);
  11522. gprm.colModel.splice(0,1);
  11523. }
  11524. if(gprm.subGrid) {
  11525. gprm.colNames.splice(0,1);
  11526. gprm.colModel.splice(0,1);
  11527. }
  11528. gprm.knv = null;
  11529. if(gprm.treeGrid) {
  11530. for (key in gprm.treeReader) {
  11531. if(gprm.treeReader.hasOwnProperty(key)) {
  11532. gprm.colNames.splice(gprm.colNames.length-1);
  11533. gprm.colModel.splice(gprm.colModel.length-1);
  11534. }
  11535. }
  11536. }
  11537. switch (o.exptype) {
  11538. case 'xmlstring' :
  11539. ret = "<"+o.root+">"+xmlJsonClass.json2xml(gprm,o.ident)+"</"+o.root+">";
  11540. break;
  11541. case 'jsonstring' :
  11542. ret = "{"+ xmlJsonClass.toJson(gprm,o.root,o.ident,false)+"}";
  11543. if(gprm.postData.filters !== undefined) {
  11544. ret=ret.replace(/filters":"/,'filters":');
  11545. ret=ret.replace(/}]}"/,'}]}');
  11546. }
  11547. break;
  11548. }
  11549. });
  11550. return ret;
  11551. },
  11552. excelExport : function(o) {
  11553. o = $.extend({
  11554. exptype : "remote",
  11555. url : null,
  11556. oper: "oper",
  11557. tag: "excel",
  11558. exportOptions : {}
  11559. }, o || {});
  11560. return this.each(function(){
  11561. if(!this.grid) { return;}
  11562. var url;
  11563. if(o.exptype == "remote") {
  11564. var pdata = $.extend({},this.p.postData);
  11565. pdata[o.oper] = o.tag;
  11566. var params = jQuery.param(pdata);
  11567. if(o.url.indexOf("?") != -1) { url = o.url+"&"+params; }
  11568. else { url = o.url+"?"+params; }
  11569. window.location = url;
  11570. }
  11571. });
  11572. }
  11573. });
  11574. })(jQuery);
  11575. /*jshint evil:true, eqeqeq:false, eqnull:true, devel:true */
  11576. /*global jQuery */
  11577. (function($){
  11578. /*
  11579. **
  11580. * jqGrid addons using jQuery UI
  11581. * Author: Mark Williams
  11582. * Dual licensed under the MIT and GPL licenses:
  11583. * http://www.opensource.org/licenses/mit-license.php
  11584. * http://www.gnu.org/licenses/gpl-2.0.html
  11585. * depends on jQuery UI
  11586. **/
  11587. "use strict";
  11588. if ($.browser.msie && $.browser.version==8) {
  11589. $.expr[":"].hidden = function(elem) {
  11590. return elem.offsetWidth === 0 || elem.offsetHeight === 0 ||
  11591. elem.style.display == "none";
  11592. };
  11593. }
  11594. // requiere load multiselect before grid
  11595. $.jgrid._multiselect = false;
  11596. if($.ui) {
  11597. if ($.ui.multiselect ) {
  11598. if($.ui.multiselect.prototype._setSelected) {
  11599. var setSelected = $.ui.multiselect.prototype._setSelected;
  11600. $.ui.multiselect.prototype._setSelected = function(item,selected) {
  11601. var ret = setSelected.call(this,item,selected);
  11602. if (selected && this.selectedList) {
  11603. var elt = this.element;
  11604. this.selectedList.find('li').each(function() {
  11605. if ($(this).data('optionLink')) {
  11606. $(this).data('optionLink').remove().appendTo(elt);
  11607. }
  11608. });
  11609. }
  11610. return ret;
  11611. };
  11612. }
  11613. if($.ui.multiselect.prototype.destroy) {
  11614. $.ui.multiselect.prototype.destroy = function() {
  11615. this.element.show();
  11616. this.container.remove();
  11617. if ($.Widget === undefined) {
  11618. $.widget.prototype.destroy.apply(this, arguments);
  11619. } else {
  11620. $.Widget.prototype.destroy.apply(this, arguments);
  11621. }
  11622. };
  11623. }
  11624. $.jgrid._multiselect = true;
  11625. }
  11626. }
  11627. $.jgrid.extend({
  11628. sortableColumns : function (tblrow)
  11629. {
  11630. return this.each(function (){
  11631. var ts = this, tid= $.jgrid.jqID( ts.p.id );
  11632. function start() {ts.p.disableClick = true;}
  11633. var sortable_opts = {
  11634. "tolerance" : "pointer",
  11635. "axis" : "x",
  11636. "scrollSensitivity": "1",
  11637. "items": '>th:not(:has(#jqgh_'+tid+'_cb'+',#jqgh_'+tid+'_rn'+',#jqgh_'+tid+'_subgrid),:hidden)',
  11638. "placeholder": {
  11639. element: function(item) {
  11640. var el = $(document.createElement(item[0].nodeName))
  11641. .addClass(item[0].className+" ui-sortable-placeholder ui-state-highlight")
  11642. .removeClass("ui-sortable-helper")[0];
  11643. return el;
  11644. },
  11645. update: function(self, p) {
  11646. p.height(self.currentItem.innerHeight() - parseInt(self.currentItem.css('paddingTop')||0, 10) - parseInt(self.currentItem.css('paddingBottom')||0, 10));
  11647. p.width(self.currentItem.innerWidth() - parseInt(self.currentItem.css('paddingLeft')||0, 10) - parseInt(self.currentItem.css('paddingRight')||0, 10));
  11648. }
  11649. },
  11650. "update": function(event, ui) {
  11651. var p = $(ui.item).parent(),
  11652. th = $(">th", p),
  11653. colModel = ts.p.colModel,
  11654. cmMap = {}, tid= ts.p.id+"_";
  11655. $.each(colModel, function(i) { cmMap[this.name]=i; });
  11656. var permutation = [];
  11657. th.each(function() {
  11658. var id = $(">div", this).get(0).id.replace(/^jqgh_/, "").replace(tid,"");
  11659. if (cmMap.hasOwnProperty(id)) {
  11660. permutation.push(cmMap[id]);
  11661. }
  11662. });
  11663. $(ts).jqGrid("remapColumns",permutation, true, true);
  11664. if ($.isFunction(ts.p.sortable.update)) {
  11665. ts.p.sortable.update(permutation);
  11666. }
  11667. setTimeout(function(){ts.p.disableClick=false;}, 50);
  11668. }
  11669. };
  11670. if (ts.p.sortable.options) {
  11671. $.extend(sortable_opts, ts.p.sortable.options);
  11672. } else if ($.isFunction(ts.p.sortable)) {
  11673. ts.p.sortable = { "update" : ts.p.sortable };
  11674. }
  11675. if (sortable_opts.start) {
  11676. var s = sortable_opts.start;
  11677. sortable_opts.start = function(e,ui) {
  11678. start();
  11679. s.call(this,e,ui);
  11680. };
  11681. } else {
  11682. sortable_opts.start = start;
  11683. }
  11684. if (ts.p.sortable.exclude) {
  11685. sortable_opts.items += ":not("+ts.p.sortable.exclude+")";
  11686. }
  11687. tblrow.sortable(sortable_opts).data("sortable").floating = true;
  11688. });
  11689. },
  11690. columnChooser : function(opts) {
  11691. var self = this;
  11692. if($("#colchooser_"+$.jgrid.jqID(self[0].p.id)).length ) { return; }
  11693. var selector = $('<div id="colchooser_'+self[0].p.id+'" style="position:relative;overflow:hidden"><div><select multiple="multiple"></select></div></div>');
  11694. var select = $('select', selector);
  11695. function insert(perm,i,v) {
  11696. if(i>=0){
  11697. var a = perm.slice();
  11698. var b = a.splice(i,Math.max(perm.length-i,i));
  11699. if(i>perm.length) { i = perm.length; }
  11700. a[i] = v;
  11701. return a.concat(b);
  11702. }
  11703. }
  11704. opts = $.extend({
  11705. "width" : 420,
  11706. "height" : 240,
  11707. "classname" : null,
  11708. "done" : function(perm) { if (perm) { self.jqGrid("remapColumns", perm, true); } },
  11709. /* msel is either the name of a ui widget class that
  11710. extends a multiselect, or a function that supports
  11711. creating a multiselect object (with no argument,
  11712. or when passed an object), and destroying it (when
  11713. passed the string "destroy"). */
  11714. "msel" : "multiselect",
  11715. /* "msel_opts" : {}, */
  11716. /* dlog is either the name of a ui widget class that
  11717. behaves in a dialog-like way, or a function, that
  11718. supports creating a dialog (when passed dlog_opts)
  11719. or destroying a dialog (when passed the string
  11720. "destroy")
  11721. */
  11722. "dlog" : "dialog",
  11723. "dialog_opts" : {
  11724. "minWidth": 470
  11725. },
  11726. /* dlog_opts is either an option object to be passed
  11727. to "dlog", or (more likely) a function that creates
  11728. the options object.
  11729. The default produces a suitable options object for
  11730. ui.dialog */
  11731. "dlog_opts" : function(opts) {
  11732. var buttons = {};
  11733. buttons[opts.bSubmit] = function() {
  11734. opts.apply_perm();
  11735. opts.cleanup(false);
  11736. };
  11737. buttons[opts.bCancel] = function() {
  11738. opts.cleanup(true);
  11739. };
  11740. return $.extend(true, {
  11741. "buttons": buttons,
  11742. "close": function() {
  11743. opts.cleanup(true);
  11744. },
  11745. "modal" : opts.modal || false,
  11746. "resizable": opts.resizable || true,
  11747. "width": opts.width+20
  11748. }, opts.dialog_opts || {});
  11749. },
  11750. /* Function to get the permutation array, and pass it to the
  11751. "done" function */
  11752. "apply_perm" : function() {
  11753. $('option',select).each(function() {
  11754. if (this.selected) {
  11755. self.jqGrid("showCol", colModel[this.value].name);
  11756. } else {
  11757. self.jqGrid("hideCol", colModel[this.value].name);
  11758. }
  11759. });
  11760. var perm = [];
  11761. //fixedCols.slice(0);
  11762. $('option:selected',select).each(function() { perm.push(parseInt(this.value,10)); });
  11763. $.each(perm, function() { delete colMap[colModel[parseInt(this,10)].name]; });
  11764. $.each(colMap, function() {
  11765. var ti = parseInt(this,10);
  11766. perm = insert(perm,ti,ti);
  11767. });
  11768. if (opts.done) {
  11769. opts.done.call(self, perm);
  11770. }
  11771. },
  11772. /* Function to cleanup the dialog, and select. Also calls the
  11773. done function with no permutation (to indicate that the
  11774. columnChooser was aborted */
  11775. "cleanup" : function(calldone) {
  11776. call(opts.dlog, selector, 'destroy');
  11777. call(opts.msel, select, 'destroy');
  11778. selector.remove();
  11779. if (calldone && opts.done) {
  11780. opts.done.call(self);
  11781. }
  11782. },
  11783. "msel_opts" : {}
  11784. }, $.jgrid.col, opts || {});
  11785. if($.ui) {
  11786. if ($.ui.multiselect ) {
  11787. if(opts.msel == "multiselect") {
  11788. if(!$.jgrid._multiselect) {
  11789. // should be in language file
  11790. alert("Multiselect plugin loaded after jqGrid. Please load the plugin before the jqGrid!");
  11791. return;
  11792. }
  11793. opts.msel_opts = $.extend($.ui.multiselect.defaults,opts.msel_opts);
  11794. }
  11795. }
  11796. }
  11797. if (opts.caption) {
  11798. selector.attr("title", opts.caption);
  11799. }
  11800. if (opts.classname) {
  11801. selector.addClass(opts.classname);
  11802. select.addClass(opts.classname);
  11803. }
  11804. if (opts.width) {
  11805. $(">div",selector).css({"width": opts.width,"margin":"0 auto"});
  11806. select.css("width", opts.width);
  11807. }
  11808. if (opts.height) {
  11809. $(">div",selector).css("height", opts.height);
  11810. select.css("height", opts.height - 10);
  11811. }
  11812. var colModel = self.jqGrid("getGridParam", "colModel");
  11813. var colNames = self.jqGrid("getGridParam", "colNames");
  11814. var colMap = {}, fixedCols = [];
  11815. select.empty();
  11816. $.each(colModel, function(i) {
  11817. colMap[this.name] = i;
  11818. if (this.hidedlg) {
  11819. if (!this.hidden) {
  11820. fixedCols.push(i);
  11821. }
  11822. return;
  11823. }
  11824. select.append("<option value='"+i+"' "+
  11825. (this.hidden?"":"selected='selected'")+">"+$.jgrid.stripHtml(colNames[i])+"</option>");
  11826. });
  11827. function call(fn, obj) {
  11828. if (!fn) { return; }
  11829. if (typeof fn == 'string') {
  11830. if ($.fn[fn]) {
  11831. $.fn[fn].apply(obj, $.makeArray(arguments).slice(2));
  11832. }
  11833. } else if ($.isFunction(fn)) {
  11834. fn.apply(obj, $.makeArray(arguments).slice(2));
  11835. }
  11836. }
  11837. var dopts = $.isFunction(opts.dlog_opts) ? opts.dlog_opts.call(self, opts) : opts.dlog_opts;
  11838. call(opts.dlog, selector, dopts);
  11839. var mopts = $.isFunction(opts.msel_opts) ? opts.msel_opts.call(self, opts) : opts.msel_opts;
  11840. call(opts.msel, select, mopts);
  11841. },
  11842. sortableRows : function (opts) {
  11843. // Can accept all sortable options and events
  11844. return this.each(function(){
  11845. var $t = this;
  11846. if(!$t.grid) { return; }
  11847. // Currently we disable a treeGrid sortable
  11848. if($t.p.treeGrid) { return; }
  11849. if($.fn.sortable) {
  11850. opts = $.extend({
  11851. "cursor":"move",
  11852. "axis" : "y",
  11853. "items": ".jqgrow"
  11854. },
  11855. opts || {});
  11856. if(opts.start && $.isFunction(opts.start)) {
  11857. opts._start_ = opts.start;
  11858. delete opts.start;
  11859. } else {opts._start_=false;}
  11860. if(opts.update && $.isFunction(opts.update)) {
  11861. opts._update_ = opts.update;
  11862. delete opts.update;
  11863. } else {opts._update_ = false;}
  11864. opts.start = function(ev,ui) {
  11865. $(ui.item).css("border-width","0px");
  11866. $("td",ui.item).each(function(i){
  11867. this.style.width = $t.grid.cols[i].style.width;
  11868. });
  11869. if($t.p.subGrid) {
  11870. var subgid = $(ui.item).attr("id");
  11871. try {
  11872. $($t).jqGrid('collapseSubGridRow',subgid);
  11873. } catch (e) {}
  11874. }
  11875. if(opts._start_) {
  11876. opts._start_.apply(this,[ev,ui]);
  11877. }
  11878. };
  11879. opts.update = function (ev,ui) {
  11880. $(ui.item).css("border-width","");
  11881. if($t.p.rownumbers === true) {
  11882. $("td.jqgrid-rownum",$t.rows).each(function( i ){
  11883. $(this).html( i+1+(parseInt($t.p.page,10)-1)*parseInt($t.p.rowNum,10) );
  11884. });
  11885. }
  11886. if(opts._update_) {
  11887. opts._update_.apply(this,[ev,ui]);
  11888. }
  11889. };
  11890. $("tbody:first",$t).sortable(opts);
  11891. $("tbody:first",$t).disableSelection();
  11892. }
  11893. });
  11894. },
  11895. gridDnD : function(opts) {
  11896. return this.each(function(){
  11897. var $t = this, i, cn;
  11898. if(!$t.grid) { return; }
  11899. // Currently we disable a treeGrid drag and drop
  11900. if($t.p.treeGrid) { return; }
  11901. if(!$.fn.draggable || !$.fn.droppable) { return; }
  11902. function updateDnD ()
  11903. {
  11904. var datadnd = $.data($t,"dnd");
  11905. $("tr.jqgrow:not(.ui-draggable)",$t).draggable($.isFunction(datadnd.drag) ? datadnd.drag.call($($t),datadnd) : datadnd.drag);
  11906. }
  11907. var appender = "<table id='jqgrid_dnd' class='ui-jqgrid-dnd'></table>";
  11908. if($("#jqgrid_dnd")[0] === undefined) {
  11909. $('body').append(appender);
  11910. }
  11911. if(typeof opts == 'string' && opts == 'updateDnD' && $t.p.jqgdnd===true) {
  11912. updateDnD();
  11913. return;
  11914. }
  11915. opts = $.extend({
  11916. "drag" : function (opts) {
  11917. return $.extend({
  11918. start : function (ev, ui) {
  11919. var i, subgid;
  11920. // if we are in subgrid mode try to collapse the node
  11921. if($t.p.subGrid) {
  11922. subgid = $(ui.helper).attr("id");
  11923. try {
  11924. $($t).jqGrid('collapseSubGridRow',subgid);
  11925. } catch (e) {}
  11926. }
  11927. // hack
  11928. // drag and drop does not insert tr in table, when the table has no rows
  11929. // we try to insert new empty row on the target(s)
  11930. for (i=0;i<$.data($t,"dnd").connectWith.length;i++){
  11931. if($($.data($t,"dnd").connectWith[i]).jqGrid('getGridParam','reccount') == "0" ){
  11932. $($.data($t,"dnd").connectWith[i]).jqGrid('addRowData','jqg_empty_row',{});
  11933. }
  11934. }
  11935. ui.helper.addClass("ui-state-highlight");
  11936. $("td",ui.helper).each(function(i) {
  11937. this.style.width = $t.grid.headers[i].width+"px";
  11938. });
  11939. if(opts.onstart && $.isFunction(opts.onstart) ) { opts.onstart.call($($t),ev,ui); }
  11940. },
  11941. stop :function(ev,ui) {
  11942. var i, ids;
  11943. if(ui.helper.dropped && !opts.dragcopy) {
  11944. ids = $(ui.helper).attr("id");
  11945. if(ids === undefined) { ids = $(this).attr("id"); }
  11946. $($t).jqGrid('delRowData',ids );
  11947. }
  11948. // if we have a empty row inserted from start event try to delete it
  11949. for (i=0;i<$.data($t,"dnd").connectWith.length;i++){
  11950. $($.data($t,"dnd").connectWith[i]).jqGrid('delRowData','jqg_empty_row');
  11951. }
  11952. if(opts.onstop && $.isFunction(opts.onstop) ) { opts.onstop.call($($t),ev,ui); }
  11953. }
  11954. },opts.drag_opts || {});
  11955. },
  11956. "drop" : function (opts) {
  11957. return $.extend({
  11958. accept: function(d) {
  11959. if (!$(d).hasClass('jqgrow')) { return d;}
  11960. var tid = $(d).closest("table.ui-jqgrid-btable");
  11961. if(tid.length > 0 && $.data(tid[0],"dnd") !== undefined) {
  11962. var cn = $.data(tid[0],"dnd").connectWith;
  11963. return $.inArray('#'+$.jgrid.jqID(this.id),cn) != -1 ? true : false;
  11964. }
  11965. return false;
  11966. },
  11967. drop: function(ev, ui) {
  11968. if (!$(ui.draggable).hasClass('jqgrow')) { return; }
  11969. var accept = $(ui.draggable).attr("id");
  11970. var getdata = ui.draggable.parent().parent().jqGrid('getRowData',accept);
  11971. if(!opts.dropbyname) {
  11972. var j =0, tmpdata = {}, nm, key;
  11973. var dropmodel = $("#"+$.jgrid.jqID(this.id)).jqGrid('getGridParam','colModel');
  11974. try {
  11975. for (key in getdata) {
  11976. if (getdata.hasOwnProperty(key)) {
  11977. nm = dropmodel[j].name;
  11978. if( !(nm == 'cb' || nm =='rn' || nm == 'subgrid' )) {
  11979. if(getdata.hasOwnProperty(key) && dropmodel[j]) {
  11980. tmpdata[nm] = getdata[key];
  11981. }
  11982. }
  11983. j++;
  11984. }
  11985. }
  11986. getdata = tmpdata;
  11987. } catch (e) {}
  11988. }
  11989. ui.helper.dropped = true;
  11990. if(opts.beforedrop && $.isFunction(opts.beforedrop) ) {
  11991. //parameters to this callback - event, element, data to be inserted, sender, reciever
  11992. // should return object which will be inserted into the reciever
  11993. var datatoinsert = opts.beforedrop.call(this,ev,ui,getdata,$('#'+$.jgrid.jqID($t.p.id)),$(this));
  11994. if (datatoinsert !== undefined && datatoinsert !== null && typeof datatoinsert == "object") { getdata = datatoinsert; }
  11995. }
  11996. if(ui.helper.dropped) {
  11997. var grid;
  11998. if(opts.autoid) {
  11999. if($.isFunction(opts.autoid)) {
  12000. grid = opts.autoid.call(this,getdata);
  12001. } else {
  12002. grid = Math.ceil(Math.random()*1000);
  12003. grid = opts.autoidprefix+grid;
  12004. }
  12005. }
  12006. // NULL is interpreted as undefined while null as object
  12007. $("#"+$.jgrid.jqID(this.id)).jqGrid('addRowData',grid,getdata,opts.droppos);
  12008. }
  12009. if(opts.ondrop && $.isFunction(opts.ondrop) ) { opts.ondrop.call(this,ev,ui, getdata); }
  12010. }}, opts.drop_opts || {});
  12011. },
  12012. "onstart" : null,
  12013. "onstop" : null,
  12014. "beforedrop": null,
  12015. "ondrop" : null,
  12016. "drop_opts" : {
  12017. "activeClass": "ui-state-active",
  12018. "hoverClass": "ui-state-hover"
  12019. },
  12020. "drag_opts" : {
  12021. "revert": "invalid",
  12022. "helper": "clone",
  12023. "cursor": "move",
  12024. "appendTo" : "#jqgrid_dnd",
  12025. "zIndex": 5000
  12026. },
  12027. "dragcopy": false,
  12028. "dropbyname" : false,
  12029. "droppos" : "first",
  12030. "autoid" : true,
  12031. "autoidprefix" : "dnd_"
  12032. }, opts || {});
  12033. if(!opts.connectWith) { return; }
  12034. opts.connectWith = opts.connectWith.split(",");
  12035. opts.connectWith = $.map(opts.connectWith,function(n){return $.trim(n);});
  12036. $.data($t,"dnd",opts);
  12037. if($t.p.reccount != "0" && !$t.p.jqgdnd) {
  12038. updateDnD();
  12039. }
  12040. $t.p.jqgdnd = true;
  12041. for (i=0;i<opts.connectWith.length;i++){
  12042. cn =opts.connectWith[i];
  12043. $(cn).droppable($.isFunction(opts.drop) ? opts.drop.call($($t),opts) : opts.drop);
  12044. }
  12045. });
  12046. },
  12047. gridResize : function(opts) {
  12048. return this.each(function(){
  12049. var $t = this, gID = $.jgrid.jqID($t.p.id);
  12050. if(!$t.grid || !$.fn.resizable) { return; }
  12051. opts = $.extend({}, opts || {});
  12052. if(opts.alsoResize ) {
  12053. opts._alsoResize_ = opts.alsoResize;
  12054. delete opts.alsoResize;
  12055. } else {
  12056. opts._alsoResize_ = false;
  12057. }
  12058. if(opts.stop && $.isFunction(opts.stop)) {
  12059. opts._stop_ = opts.stop;
  12060. delete opts.stop;
  12061. } else {
  12062. opts._stop_ = false;
  12063. }
  12064. opts.stop = function (ev, ui) {
  12065. $($t).jqGrid('setGridParam',{height:$("#gview_"+gID+" .ui-jqgrid-bdiv").height()});
  12066. $($t).jqGrid('setGridWidth',ui.size.width,opts.shrinkToFit);
  12067. if(opts._stop_) { opts._stop_.call($t,ev,ui); }
  12068. };
  12069. if(opts._alsoResize_) {
  12070. var optstest = "{\'#gview_"+gID+" .ui-jqgrid-bdiv\':true,'" +opts._alsoResize_+"':true}";
  12071. opts.alsoResize = eval('('+optstest+')'); // the only way that I found to do this
  12072. } else {
  12073. opts.alsoResize = $(".ui-jqgrid-bdiv","#gview_"+gID);
  12074. }
  12075. delete opts._alsoResize_;
  12076. $("#gbox_"+gID).resizable(opts);
  12077. });
  12078. }
  12079. });
  12080. })(jQuery);
  12081. /*
  12082. Transform a table to a jqGrid.
  12083. Peter Romianowski <peter.romianowski@optivo.de>
  12084. If the first column of the table contains checkboxes or
  12085. radiobuttons then the jqGrid is made selectable.
  12086. */
  12087. // Addition - selector can be a class or id
  12088. function tableToGrid(selector, options) {
  12089. jQuery(selector).each(function() {
  12090. if(this.grid) {return;} //Adedd from Tony Tomov
  12091. // This is a small "hack" to make the width of the jqGrid 100%
  12092. jQuery(this).width("99%");
  12093. var w = jQuery(this).width();
  12094. // Text whether we have single or multi select
  12095. var inputCheckbox = jQuery('tr td:first-child input[type=checkbox]:first', jQuery(this));
  12096. var inputRadio = jQuery('tr td:first-child input[type=radio]:first', jQuery(this));
  12097. var selectMultiple = inputCheckbox.length > 0;
  12098. var selectSingle = !selectMultiple && inputRadio.length > 0;
  12099. var selectable = selectMultiple || selectSingle;
  12100. //var inputName = inputCheckbox.attr("name") || inputRadio.attr("name");
  12101. // Build up the columnModel and the data
  12102. var colModel = [];
  12103. var colNames = [];
  12104. jQuery('th', jQuery(this)).each(function() {
  12105. if (colModel.length === 0 && selectable) {
  12106. colModel.push({
  12107. name: '__selection__',
  12108. index: '__selection__',
  12109. width: 0,
  12110. hidden: true
  12111. });
  12112. colNames.push('__selection__');
  12113. } else {
  12114. colModel.push({
  12115. name: jQuery(this).attr("id") || jQuery.trim(jQuery.jgrid.stripHtml(jQuery(this).html())).split(' ').join('_'),
  12116. index: jQuery(this).attr("id") || jQuery.trim(jQuery.jgrid.stripHtml(jQuery(this).html())).split(' ').join('_'),
  12117. width: jQuery(this).width() || 150
  12118. });
  12119. colNames.push(jQuery(this).html());
  12120. }
  12121. });
  12122. var data = [];
  12123. var rowIds = [];
  12124. var rowChecked = [];
  12125. jQuery('tbody > tr', jQuery(this)).each(function() {
  12126. var row = {};
  12127. var rowPos = 0;
  12128. jQuery('td', jQuery(this)).each(function() {
  12129. if (rowPos === 0 && selectable) {
  12130. var input = jQuery('input', jQuery(this));
  12131. var rowId = input.attr("value");
  12132. rowIds.push(rowId || data.length);
  12133. if (input.is(":checked")) {
  12134. rowChecked.push(rowId);
  12135. }
  12136. row[colModel[rowPos].name] = input.attr("value");
  12137. } else {
  12138. row[colModel[rowPos].name] = jQuery(this).html();
  12139. }
  12140. rowPos++;
  12141. });
  12142. if(rowPos >0) { data.push(row); }
  12143. });
  12144. // Clear the original HTML table
  12145. jQuery(this).empty();
  12146. // Mark it as jqGrid
  12147. jQuery(this).addClass("scroll");
  12148. jQuery(this).jqGrid(jQuery.extend({
  12149. datatype: "local",
  12150. width: w,
  12151. colNames: colNames,
  12152. colModel: colModel,
  12153. multiselect: selectMultiple
  12154. //inputName: inputName,
  12155. //inputValueCol: imputName != null ? "__selection__" : null
  12156. }, options || {}));
  12157. // Add data
  12158. var a;
  12159. for (a = 0; a < data.length; a++) {
  12160. var id = null;
  12161. if (rowIds.length > 0) {
  12162. id = rowIds[a];
  12163. if (id && id.replace) {
  12164. // We have to do this since the value of a checkbox
  12165. // or radio button can be anything
  12166. id = encodeURIComponent(id).replace(/[.\-%]/g, "_");
  12167. }
  12168. }
  12169. if (id === null) {
  12170. id = a + 1;
  12171. }
  12172. jQuery(this).jqGrid("addRowData",id, data[a]);
  12173. }
  12174. // Set the selection
  12175. for (a = 0; a < rowChecked.length; a++) {
  12176. jQuery(this).jqGrid("setSelection",rowChecked[a]);
  12177. }
  12178. });
  12179. };