jquery.jqGrid.src.js 449 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235
  1. // ==ClosureCompiler==
  2. // @compilation_level SIMPLE_OPTIMIZATIONS
  3. /**
  4. * @license jqGrid 4.6.0 - 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: 2014-02-20
  10. */
  11. //jsHint options
  12. /*jshint evil:true, eqeqeq:false, eqnull:true, devel:true */
  13. /*global jQuery */
  14. (function ($) {
  15. "use strict";
  16. $.jgrid = $.jgrid || {};
  17. $.extend($.jgrid,{
  18. version : "4.6.0",
  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. msie : navigator.appName === 'Microsoft Internet Explorer',
  34. msiever : function () {
  35. var rv = -1;
  36. var ua = navigator.userAgent;
  37. var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
  38. if (re.exec(ua) != null) {
  39. rv = parseFloat( RegExp.$1 );
  40. }
  41. return rv;
  42. },
  43. getCellIndex : function (cell) {
  44. var c = $(cell);
  45. if (c.is('tr')) { return -1; }
  46. c = (!c.is('td') && !c.is('th') ? c.closest("td,th") : c)[0];
  47. if ($.jgrid.msie) { return $.inArray(c, c.parentNode.cells); }
  48. return c.cellIndex;
  49. },
  50. stripHtml : function(v) {
  51. v = String(v);
  52. var regexp = /<("[^"]*"|'[^']*'|[^'">])*>/gi;
  53. if (v) {
  54. v = v.replace(regexp,"");
  55. return (v && v !== '&nbsp;' && v !== '&#160;') ? v.replace(/\"/g,"'") : "";
  56. }
  57. return v;
  58. },
  59. stripPref : function (pref, id) {
  60. var obj = $.type( pref );
  61. if( obj === "string" || obj === "number") {
  62. pref = String(pref);
  63. id = pref !== "" ? String(id).replace(String(pref), "") : id;
  64. }
  65. return id;
  66. },
  67. parse : function(jsonString) {
  68. var js = jsonString;
  69. if (js.substr(0,9) === "while(1);") { js = js.substr(9); }
  70. if (js.substr(0,2) === "/*") { js = js.substr(2,js.length-4); }
  71. if(!js) { js = "{}"; }
  72. return ($.jgrid.useJSON===true && typeof JSON === 'object' && typeof JSON.parse === 'function') ?
  73. JSON.parse(js) :
  74. eval('(' + js + ')');
  75. },
  76. parseDate : function(format, date, newformat, opts) {
  77. var token = /\\.|[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]/g,
  78. timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
  79. timezoneClip = /[^-+\dA-Z]/g,
  80. msDateRegExp = new RegExp("^\/Date\\((([-+])?[0-9]+)(([-+])([0-9]{2})([0-9]{2}))?\\)\/$"),
  81. msMatch = ((typeof date === 'string') ? date.match(msDateRegExp): null),
  82. pad = function (value, length) {
  83. value = String(value);
  84. length = parseInt(length,10) || 2;
  85. while (value.length < length) { value = '0' + value; }
  86. return value;
  87. },
  88. ts = {m : 1, d : 1, y : 1970, h : 0, i : 0, s : 0, u:0},
  89. timestamp=0, dM, k,hl,
  90. h12to24 = function(ampm, h){
  91. if (ampm === 0){ if (h === 12) { h = 0;} }
  92. else { if (h !== 12) { h += 12; } }
  93. return h;
  94. };
  95. if(opts === undefined) {
  96. opts = $.jgrid.formatter.date;
  97. }
  98. // old lang files
  99. if(opts.parseRe === undefined ) {
  100. opts.parseRe = /[#%\\\/:_;.,\t\s-]/;
  101. }
  102. if( opts.masks.hasOwnProperty(format) ) { format = opts.masks[format]; }
  103. if(date && date != null) {
  104. if( !isNaN( date - 0 ) && String(format).toLowerCase() === "u") {
  105. //Unix timestamp
  106. timestamp = new Date( parseFloat(date)*1000 );
  107. } else if(date.constructor === Date) {
  108. timestamp = date;
  109. // Microsoft date format support
  110. } else if( msMatch !== null ) {
  111. timestamp = new Date(parseInt(msMatch[1], 10));
  112. if (msMatch[3]) {
  113. var offset = Number(msMatch[5]) * 60 + Number(msMatch[6]);
  114. offset *= ((msMatch[4] === '-') ? 1 : -1);
  115. offset -= timestamp.getTimezoneOffset();
  116. timestamp.setTime(Number(Number(timestamp) + (offset * 60 * 1000)));
  117. }
  118. } else {
  119. var offset = 0;
  120. //Support ISO8601Long that have Z at the end to indicate UTC timezone
  121. if(opts.srcformat === 'ISO8601Long' && date.charAt(date.length - 1) === 'Z') {
  122. offset -= (new Date()).getTimezoneOffset();
  123. }
  124. date = String(date).replace(/\T/g,"#").replace(/\t/,"%").split(opts.parseRe);
  125. format = format.replace(/\T/g,"#").replace(/\t/,"%").split(opts.parseRe);
  126. // parsing for month names
  127. for(k=0,hl=format.length;k<hl;k++){
  128. if(format[k] === 'M') {
  129. dM = $.inArray(date[k],opts.monthNames);
  130. if(dM !== -1 && dM < 12){date[k] = dM+1; ts.m = date[k];}
  131. }
  132. if(format[k] === 'F') {
  133. dM = $.inArray(date[k],opts.monthNames,12);
  134. if(dM !== -1 && dM > 11){date[k] = dM+1-12; ts.m = date[k];}
  135. }
  136. if(format[k] === 'a') {
  137. dM = $.inArray(date[k],opts.AmPm);
  138. if(dM !== -1 && dM < 2 && date[k] === opts.AmPm[dM]){
  139. date[k] = dM;
  140. ts.h = h12to24(date[k], ts.h);
  141. }
  142. }
  143. if(format[k] === 'A') {
  144. dM = $.inArray(date[k],opts.AmPm);
  145. if(dM !== -1 && dM > 1 && date[k] === opts.AmPm[dM]){
  146. date[k] = dM-2;
  147. ts.h = h12to24(date[k], ts.h);
  148. }
  149. }
  150. if (format[k] === 'g') {
  151. ts.h = parseInt(date[k], 10);
  152. }
  153. if(date[k] !== undefined) {
  154. ts[format[k].toLowerCase()] = parseInt(date[k],10);
  155. }
  156. }
  157. if(ts.f) {ts.m = ts.f;}
  158. if( ts.m === 0 && ts.y === 0 && ts.d === 0) {
  159. return "&#160;" ;
  160. }
  161. ts.m = parseInt(ts.m,10)-1;
  162. var ty = ts.y;
  163. if (ty >= 70 && ty <= 99) {ts.y = 1900+ts.y;}
  164. else if (ty >=0 && ty <=69) {ts.y= 2000+ts.y;}
  165. timestamp = new Date(ts.y, ts.m, ts.d, ts.h, ts.i, ts.s, ts.u);
  166. //Apply offset to show date as local time.
  167. if(offset > 0) {
  168. timestamp.setTime(Number(Number(timestamp) + (offset * 60 * 1000)));
  169. }
  170. }
  171. } else {
  172. timestamp = new Date(ts.y, ts.m, ts.d, ts.h, ts.i, ts.s, ts.u);
  173. }
  174. if( newformat === undefined ) {
  175. return timestamp;
  176. }
  177. if( opts.masks.hasOwnProperty(newformat) ) {
  178. newformat = opts.masks[newformat];
  179. } else if ( !newformat ) {
  180. newformat = 'Y-m-d';
  181. }
  182. var
  183. G = timestamp.getHours(),
  184. i = timestamp.getMinutes(),
  185. j = timestamp.getDate(),
  186. n = timestamp.getMonth() + 1,
  187. o = timestamp.getTimezoneOffset(),
  188. s = timestamp.getSeconds(),
  189. u = timestamp.getMilliseconds(),
  190. w = timestamp.getDay(),
  191. Y = timestamp.getFullYear(),
  192. N = (w + 6) % 7 + 1,
  193. z = (new Date(Y, n - 1, j) - new Date(Y, 0, 1)) / 86400000,
  194. flags = {
  195. // Day
  196. d: pad(j),
  197. D: opts.dayNames[w],
  198. j: j,
  199. l: opts.dayNames[w + 7],
  200. N: N,
  201. S: opts.S(j),
  202. //j < 11 || j > 13 ? ['st', 'nd', 'rd', 'th'][Math.min((j - 1) % 10, 3)] : 'th',
  203. w: w,
  204. z: z,
  205. // Week
  206. 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),
  207. // Month
  208. F: opts.monthNames[n - 1 + 12],
  209. m: pad(n),
  210. M: opts.monthNames[n - 1],
  211. n: n,
  212. t: '?',
  213. // Year
  214. L: '?',
  215. o: '?',
  216. Y: Y,
  217. y: String(Y).substring(2),
  218. // Time
  219. a: G < 12 ? opts.AmPm[0] : opts.AmPm[1],
  220. A: G < 12 ? opts.AmPm[2] : opts.AmPm[3],
  221. B: '?',
  222. g: G % 12 || 12,
  223. G: G,
  224. h: pad(G % 12 || 12),
  225. H: pad(G),
  226. i: pad(i),
  227. s: pad(s),
  228. u: u,
  229. // Timezone
  230. e: '?',
  231. I: '?',
  232. O: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
  233. P: '?',
  234. T: (String(timestamp).match(timezone) || [""]).pop().replace(timezoneClip, ""),
  235. Z: '?',
  236. // Full Date/Time
  237. c: '?',
  238. r: '?',
  239. U: Math.floor(timestamp / 1000)
  240. };
  241. return newformat.replace(token, function ($0) {
  242. return flags.hasOwnProperty($0) ? flags[$0] : $0.substring(1);
  243. });
  244. },
  245. jqID : function(sid){
  246. return String(sid).replace(/[!"#$%&'()*+,.\/:; <=>?@\[\\\]\^`{|}~]/g,"\\$&");
  247. },
  248. guid : 1,
  249. uidPref: 'jqg',
  250. randId : function( prefix ) {
  251. return (prefix || $.jgrid.uidPref) + ($.jgrid.guid++);
  252. },
  253. getAccessor : function(obj, expr) {
  254. var ret,p,prm = [], i;
  255. if( typeof expr === 'function') { return expr(obj); }
  256. ret = obj[expr];
  257. if(ret===undefined) {
  258. try {
  259. if ( typeof expr === 'string' ) {
  260. prm = expr.split('.');
  261. }
  262. i = prm.length;
  263. if( i ) {
  264. ret = obj;
  265. while (ret && i--) {
  266. p = prm.shift();
  267. ret = ret[p];
  268. }
  269. }
  270. } catch (e) {}
  271. }
  272. return ret;
  273. },
  274. getXmlData: function (obj, expr, returnObj) {
  275. var ret, m = typeof expr === 'string' ? expr.match(/^(.*)\[(\w+)\]$/) : null;
  276. if (typeof expr === 'function') { return expr(obj); }
  277. if (m && m[2]) {
  278. // m[2] is the attribute selector
  279. // m[1] is an optional element selector
  280. // examples: "[id]", "rows[page]"
  281. return m[1] ? $(m[1], obj).attr(m[2]) : $(obj).attr(m[2]);
  282. }
  283. ret = $(expr, obj);
  284. if (returnObj) { return ret; }
  285. //$(expr, obj).filter(':last'); // we use ':last' to be more compatible with old version of jqGrid
  286. return ret.length > 0 ? $(ret).text() : undefined;
  287. },
  288. cellWidth : function () {
  289. var $testDiv = $("<div class='ui-jqgrid' style='left:10000px'><table class='ui-jqgrid-btable' style='width:5px;'><tr class='jqgrow'><td style='width:5px;display:block;'></td></tr></table></div>"),
  290. testCell = $testDiv.appendTo("body")
  291. .find("td")
  292. .width();
  293. $testDiv.remove();
  294. return Math.abs(testCell-5) > 0.1;
  295. },
  296. cell_width : true,
  297. ajaxOptions: {},
  298. from : function(source){
  299. // Original Author Hugo Bonacci
  300. // License MIT http://jlinq.codeplex.com/license
  301. var QueryObject=function(d,q){
  302. if(typeof d==="string"){
  303. d=$.data(d);
  304. }
  305. var self=this,
  306. _data=d,
  307. _usecase=true,
  308. _trim=false,
  309. _query=q,
  310. _stripNum = /[\$,%]/g,
  311. _lastCommand=null,
  312. _lastField=null,
  313. _orDepth=0,
  314. _negate=false,
  315. _queuedOperator="",
  316. _sorting=[],
  317. _useProperties=true;
  318. if(typeof d==="object"&&d.push) {
  319. if(d.length>0){
  320. if(typeof d[0]!=="object"){
  321. _useProperties=false;
  322. }else{
  323. _useProperties=true;
  324. }
  325. }
  326. }else{
  327. throw "data provides is not an array";
  328. }
  329. this._hasData=function(){
  330. return _data===null?false:_data.length===0?false:true;
  331. };
  332. this._getStr=function(s){
  333. var phrase=[];
  334. if(_trim){
  335. phrase.push("jQuery.trim(");
  336. }
  337. phrase.push("String("+s+")");
  338. if(_trim){
  339. phrase.push(")");
  340. }
  341. if(!_usecase){
  342. phrase.push(".toLowerCase()");
  343. }
  344. return phrase.join("");
  345. };
  346. this._strComp=function(val){
  347. if(typeof val==="string"){
  348. return".toString()";
  349. }
  350. return"";
  351. };
  352. this._group=function(f,u){
  353. return({field:f.toString(),unique:u,items:[]});
  354. };
  355. this._toStr=function(phrase){
  356. if(_trim){
  357. phrase=$.trim(phrase);
  358. }
  359. phrase=phrase.toString().replace(/\\/g,'\\\\').replace(/\"/g,'\\"');
  360. return _usecase ? phrase : phrase.toLowerCase();
  361. };
  362. this._funcLoop=function(func){
  363. var results=[];
  364. $.each(_data,function(i,v){
  365. results.push(func(v));
  366. });
  367. return results;
  368. };
  369. this._append=function(s){
  370. var i;
  371. if(_query===null){
  372. _query="";
  373. } else {
  374. _query+=_queuedOperator === "" ? " && " :_queuedOperator;
  375. }
  376. for (i=0;i<_orDepth;i++){
  377. _query+="(";
  378. }
  379. if(_negate){
  380. _query+="!";
  381. }
  382. _query+="("+s+")";
  383. _negate=false;
  384. _queuedOperator="";
  385. _orDepth=0;
  386. };
  387. this._setCommand=function(f,c){
  388. _lastCommand=f;
  389. _lastField=c;
  390. };
  391. this._resetNegate=function(){
  392. _negate=false;
  393. };
  394. this._repeatCommand=function(f,v){
  395. if(_lastCommand===null){
  396. return self;
  397. }
  398. if(f!==null&&v!==null){
  399. return _lastCommand(f,v);
  400. }
  401. if(_lastField===null){
  402. return _lastCommand(f);
  403. }
  404. if(!_useProperties){
  405. return _lastCommand(f);
  406. }
  407. return _lastCommand(_lastField,f);
  408. };
  409. this._equals=function(a,b){
  410. return(self._compare(a,b,1)===0);
  411. };
  412. this._compare=function(a,b,d){
  413. var toString = Object.prototype.toString;
  414. if( d === undefined) { d = 1; }
  415. if(a===undefined) { a = null; }
  416. if(b===undefined) { b = null; }
  417. if(a===null && b===null){
  418. return 0;
  419. }
  420. if(a===null&&b!==null){
  421. return 1;
  422. }
  423. if(a!==null&&b===null){
  424. return -1;
  425. }
  426. if (toString.call(a) === '[object Date]' && toString.call(b) === '[object Date]') {
  427. if (a < b) { return -d; }
  428. if (a > b) { return d; }
  429. return 0;
  430. }
  431. if(!_usecase && typeof a !== "number" && typeof b !== "number" ) {
  432. a=String(a);
  433. b=String(b);
  434. }
  435. if(a<b){return -d;}
  436. if(a>b){return d;}
  437. return 0;
  438. };
  439. this._performSort=function(){
  440. if(_sorting.length===0){return;}
  441. _data=self._doSort(_data,0);
  442. };
  443. this._doSort=function(d,q){
  444. var by=_sorting[q].by,
  445. dir=_sorting[q].dir,
  446. type = _sorting[q].type,
  447. dfmt = _sorting[q].datefmt,
  448. sfunc = _sorting[q].sfunc;
  449. if(q===_sorting.length-1){
  450. return self._getOrder(d, by, dir, type, dfmt, sfunc);
  451. }
  452. q++;
  453. var values=self._getGroup(d,by,dir,type,dfmt), results=[], i, j, sorted;
  454. for(i=0;i<values.length;i++){
  455. sorted=self._doSort(values[i].items,q);
  456. for(j=0;j<sorted.length;j++){
  457. results.push(sorted[j]);
  458. }
  459. }
  460. return results;
  461. };
  462. this._getOrder=function(data,by,dir,type, dfmt, sfunc){
  463. var sortData=[],_sortData=[], newDir = dir==="a" ? 1 : -1, i,ab,j,
  464. findSortKey;
  465. if(type === undefined ) { type = "text"; }
  466. if (type === 'float' || type=== 'number' || type=== 'currency' || type=== 'numeric') {
  467. findSortKey = function($cell) {
  468. var key = parseFloat( String($cell).replace(_stripNum, ''));
  469. return isNaN(key) ? 0.00 : key;
  470. };
  471. } else if (type==='int' || type==='integer') {
  472. findSortKey = function($cell) {
  473. return $cell ? parseFloat(String($cell).replace(_stripNum, '')) : 0;
  474. };
  475. } else if(type === 'date' || type === 'datetime') {
  476. findSortKey = function($cell) {
  477. return $.jgrid.parseDate(dfmt,$cell).getTime();
  478. };
  479. } else if($.isFunction(type)) {
  480. findSortKey = type;
  481. } else {
  482. findSortKey = function($cell) {
  483. $cell = $cell ? $.trim(String($cell)) : "";
  484. return _usecase ? $cell : $cell.toLowerCase();
  485. };
  486. }
  487. $.each(data,function(i,v){
  488. ab = by!=="" ? $.jgrid.getAccessor(v,by) : v;
  489. if(ab === undefined) { ab = ""; }
  490. ab = findSortKey(ab, v);
  491. _sortData.push({ 'vSort': ab,'index':i});
  492. });
  493. if($.isFunction(sfunc)) {
  494. _sortData.sort(function(a,b){
  495. a = a.vSort;
  496. b = b.vSort;
  497. return sfunc.call(this,a,b,newDir);
  498. });
  499. } else {
  500. _sortData.sort(function(a,b){
  501. a = a.vSort;
  502. b = b.vSort;
  503. return self._compare(a,b,newDir);
  504. });
  505. }
  506. j=0;
  507. var nrec= data.length;
  508. // overhead, but we do not change the original data.
  509. while(j<nrec) {
  510. i = _sortData[j].index;
  511. sortData.push(data[i]);
  512. j++;
  513. }
  514. return sortData;
  515. };
  516. this._getGroup=function(data,by,dir,type, dfmt){
  517. var results=[],
  518. group=null,
  519. last=null, val;
  520. $.each(self._getOrder(data,by,dir,type, dfmt),function(i,v){
  521. val = $.jgrid.getAccessor(v, by);
  522. if(val == null) { val = ""; }
  523. if(!self._equals(last,val)){
  524. last=val;
  525. if(group !== null){
  526. results.push(group);
  527. }
  528. group=self._group(by,val);
  529. }
  530. group.items.push(v);
  531. });
  532. if(group !== null){
  533. results.push(group);
  534. }
  535. return results;
  536. };
  537. this.ignoreCase=function(){
  538. _usecase=false;
  539. return self;
  540. };
  541. this.useCase=function(){
  542. _usecase=true;
  543. return self;
  544. };
  545. this.trim=function(){
  546. _trim=true;
  547. return self;
  548. };
  549. this.noTrim=function(){
  550. _trim=false;
  551. return self;
  552. };
  553. this.execute=function(){
  554. var match=_query, results=[];
  555. if(match === null){
  556. return self;
  557. }
  558. $.each(_data,function(){
  559. if(eval(match)){results.push(this);}
  560. });
  561. _data=results;
  562. return self;
  563. };
  564. this.data=function(){
  565. return _data;
  566. };
  567. this.select=function(f){
  568. self._performSort();
  569. if(!self._hasData()){ return[]; }
  570. self.execute();
  571. if($.isFunction(f)){
  572. var results=[];
  573. $.each(_data,function(i,v){
  574. results.push(f(v));
  575. });
  576. return results;
  577. }
  578. return _data;
  579. };
  580. this.hasMatch=function(){
  581. if(!self._hasData()) { return false; }
  582. self.execute();
  583. return _data.length>0;
  584. };
  585. this.andNot=function(f,v,x){
  586. _negate=!_negate;
  587. return self.and(f,v,x);
  588. };
  589. this.orNot=function(f,v,x){
  590. _negate=!_negate;
  591. return self.or(f,v,x);
  592. };
  593. this.not=function(f,v,x){
  594. return self.andNot(f,v,x);
  595. };
  596. this.and=function(f,v,x){
  597. _queuedOperator=" && ";
  598. if(f===undefined){
  599. return self;
  600. }
  601. return self._repeatCommand(f,v,x);
  602. };
  603. this.or=function(f,v,x){
  604. _queuedOperator=" || ";
  605. if(f===undefined) { return self; }
  606. return self._repeatCommand(f,v,x);
  607. };
  608. this.orBegin=function(){
  609. _orDepth++;
  610. return self;
  611. };
  612. this.orEnd=function(){
  613. if (_query !== null){
  614. _query+=")";
  615. }
  616. return self;
  617. };
  618. this.isNot=function(f){
  619. _negate=!_negate;
  620. return self.is(f);
  621. };
  622. this.is=function(f){
  623. self._append('this.'+f);
  624. self._resetNegate();
  625. return self;
  626. };
  627. this._compareValues=function(func,f,v,how,t){
  628. var fld;
  629. if(_useProperties){
  630. fld='jQuery.jgrid.getAccessor(this,\''+f+'\')';
  631. }else{
  632. fld='this';
  633. }
  634. if(v===undefined) { v = null; }
  635. //var val=v===null?f:v,
  636. var val =v,
  637. swst = t.stype === undefined ? "text" : t.stype;
  638. if(v !== null) {
  639. switch(swst) {
  640. case 'int':
  641. case 'integer':
  642. val = (isNaN(Number(val)) || val==="") ? '0' : val; // To be fixed with more inteligent code
  643. fld = 'parseInt('+fld+',10)';
  644. val = 'parseInt('+val+',10)';
  645. break;
  646. case 'float':
  647. case 'number':
  648. case 'numeric':
  649. val = String(val).replace(_stripNum, '');
  650. val = (isNaN(Number(val)) || val==="") ? '0' : val; // To be fixed with more inteligent code
  651. fld = 'parseFloat('+fld+')';
  652. val = 'parseFloat('+val+')';
  653. break;
  654. case 'date':
  655. case 'datetime':
  656. val = String($.jgrid.parseDate(t.newfmt || 'Y-m-d',val).getTime());
  657. fld = 'jQuery.jgrid.parseDate("'+t.srcfmt+'",'+fld+').getTime()';
  658. break;
  659. default :
  660. fld=self._getStr(fld);
  661. val=self._getStr('"'+self._toStr(val)+'"');
  662. }
  663. }
  664. self._append(fld+' '+how+' '+val);
  665. self._setCommand(func,f);
  666. self._resetNegate();
  667. return self;
  668. };
  669. this.equals=function(f,v,t){
  670. return self._compareValues(self.equals,f,v,"==",t);
  671. };
  672. this.notEquals=function(f,v,t){
  673. return self._compareValues(self.equals,f,v,"!==",t);
  674. };
  675. this.isNull = function(f,v,t){
  676. return self._compareValues(self.equals,f,null,"===",t);
  677. };
  678. this.greater=function(f,v,t){
  679. return self._compareValues(self.greater,f,v,">",t);
  680. };
  681. this.less=function(f,v,t){
  682. return self._compareValues(self.less,f,v,"<",t);
  683. };
  684. this.greaterOrEquals=function(f,v,t){
  685. return self._compareValues(self.greaterOrEquals,f,v,">=",t);
  686. };
  687. this.lessOrEquals=function(f,v,t){
  688. return self._compareValues(self.lessOrEquals,f,v,"<=",t);
  689. };
  690. this.startsWith=function(f,v){
  691. var val = (v==null) ? f: v,
  692. length=_trim ? $.trim(val.toString()).length : val.toString().length;
  693. if(_useProperties){
  694. self._append(self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.substr(0,'+length+') == '+self._getStr('"'+self._toStr(v)+'"'));
  695. }else{
  696. if (v!=null) { length=_trim?$.trim(v.toString()).length:v.toString().length; }
  697. self._append(self._getStr('this')+'.substr(0,'+length+') == '+self._getStr('"'+self._toStr(f)+'"'));
  698. }
  699. self._setCommand(self.startsWith,f);
  700. self._resetNegate();
  701. return self;
  702. };
  703. this.endsWith=function(f,v){
  704. var val = (v==null) ? f: v,
  705. length=_trim ? $.trim(val.toString()).length:val.toString().length;
  706. if(_useProperties){
  707. self._append(self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.substr('+self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.length-'+length+','+length+') == "'+self._toStr(v)+'"');
  708. } else {
  709. self._append(self._getStr('this')+'.substr('+self._getStr('this')+'.length-"'+self._toStr(f)+'".length,"'+self._toStr(f)+'".length) == "'+self._toStr(f)+'"');
  710. }
  711. self._setCommand(self.endsWith,f);self._resetNegate();
  712. return self;
  713. };
  714. this.contains=function(f,v){
  715. if(_useProperties){
  716. self._append(self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.indexOf("'+self._toStr(v)+'",0) > -1');
  717. }else{
  718. self._append(self._getStr('this')+'.indexOf("'+self._toStr(f)+'",0) > -1');
  719. }
  720. self._setCommand(self.contains,f);
  721. self._resetNegate();
  722. return self;
  723. };
  724. this.groupBy=function(by,dir,type, datefmt){
  725. if(!self._hasData()){
  726. return null;
  727. }
  728. return self._getGroup(_data,by,dir,type, datefmt);
  729. };
  730. this.orderBy=function(by,dir,stype, dfmt, sfunc){
  731. dir = dir == null ? "a" :$.trim(dir.toString().toLowerCase());
  732. if(stype == null) { stype = "text"; }
  733. if(dfmt == null) { dfmt = "Y-m-d"; }
  734. if(sfunc == null) { sfunc = false; }
  735. if(dir==="desc"||dir==="descending"){dir="d";}
  736. if(dir==="asc"||dir==="ascending"){dir="a";}
  737. _sorting.push({by:by,dir:dir,type:stype, datefmt: dfmt, sfunc: sfunc});
  738. return self;
  739. };
  740. return self;
  741. };
  742. return new QueryObject(source,null);
  743. },
  744. getMethod: function (name) {
  745. return this.getAccessor($.fn.jqGrid, name);
  746. },
  747. extend : function(methods) {
  748. $.extend($.fn.jqGrid,methods);
  749. if (!this.no_legacy_api) {
  750. $.fn.extend(methods);
  751. }
  752. }
  753. });
  754. $.fn.jqGrid = function( pin ) {
  755. if (typeof pin === 'string') {
  756. var fn = $.jgrid.getMethod(pin);
  757. if (!fn) {
  758. throw ("jqGrid - No such method: " + pin);
  759. }
  760. var args = $.makeArray(arguments).slice(1);
  761. return fn.apply(this,args);
  762. }
  763. return this.each( function() {
  764. if(this.grid) {return;}
  765. var p = $.extend(true,{
  766. url: "",
  767. height: 150,
  768. page: 1,
  769. rowNum: 20,
  770. rowTotal : null,
  771. records: 0,
  772. pager: "",
  773. pgbuttons: true,
  774. pginput: true,
  775. colModel: [],
  776. rowList: [],
  777. colNames: [],
  778. sortorder: "asc",
  779. sortname: "",
  780. datatype: "xml",
  781. mtype: "GET",
  782. altRows: false,
  783. selarrrow: [],
  784. savedRow: [],
  785. shrinkToFit: true,
  786. xmlReader: {},
  787. jsonReader: {},
  788. subGrid: false,
  789. subGridModel :[],
  790. reccount: 0,
  791. lastpage: 0,
  792. lastsort: 0,
  793. selrow: null,
  794. beforeSelectRow: null,
  795. onSelectRow: null,
  796. onSortCol: null,
  797. ondblClickRow: null,
  798. onRightClickRow: null,
  799. onPaging: null,
  800. onSelectAll: null,
  801. onInitGrid : null,
  802. loadComplete: null,
  803. gridComplete: null,
  804. loadError: null,
  805. loadBeforeSend: null,
  806. afterInsertRow: null,
  807. beforeRequest: null,
  808. beforeProcessing : null,
  809. onHeaderClick: null,
  810. viewrecords: false,
  811. loadonce: false,
  812. multiselect: false,
  813. multikey: false,
  814. editurl: null,
  815. search: false,
  816. caption: "",
  817. hidegrid: true,
  818. hiddengrid: false,
  819. postData: {},
  820. userData: {},
  821. treeGrid : false,
  822. treeGridModel : 'nested',
  823. treeReader : {},
  824. treeANode : -1,
  825. ExpandColumn: null,
  826. tree_root_level : 0,
  827. 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"},
  828. forceFit : false,
  829. gridstate : "visible",
  830. cellEdit: false,
  831. cellsubmit: "remote",
  832. nv:0,
  833. loadui: "enable",
  834. toolbar: [false,""],
  835. scroll: false,
  836. multiboxonly : false,
  837. deselectAfterSort : true,
  838. scrollrows : false,
  839. autowidth: false,
  840. scrollOffset :18,
  841. cellLayout: 5,
  842. subGridWidth: 20,
  843. multiselectWidth: 20,
  844. gridview: false,
  845. rownumWidth: 25,
  846. rownumbers : false,
  847. pagerpos: 'center',
  848. recordpos: 'right',
  849. footerrow : false,
  850. userDataOnFooter : false,
  851. hoverrows : true,
  852. altclass : 'ui-priority-secondary',
  853. viewsortcols : [false,'vertical',true],
  854. resizeclass : '',
  855. autoencode : false,
  856. remapColumns : [],
  857. ajaxGridOptions :{},
  858. direction : "ltr",
  859. toppager: false,
  860. headertitles: false,
  861. scrollTimeout: 40,
  862. data : [],
  863. _index : {},
  864. grouping : false,
  865. groupingView : {groupField:[],groupOrder:[], groupText:[],groupColumnShow:[],groupSummary:[], showSummaryOnHide: false, sortitems:[], sortnames:[], summary:[],summaryval:[], plusicon: 'ui-icon-circlesmall-plus', minusicon: 'ui-icon-circlesmall-minus', displayField: [], groupSummaryPos:[], formatDisplayField : [], _locgr : false},
  866. ignoreCase : false,
  867. cmTemplate : {},
  868. idPrefix : "",
  869. multiSort : false
  870. }, $.jgrid.defaults, pin || {});
  871. var ts= this, grid={
  872. headers:[],
  873. cols:[],
  874. footers: [],
  875. dragStart: function(i,x,y) {
  876. var gridLeftPos = $(this.bDiv).offset().left;
  877. this.resizing = { idx: i, startX: x.clientX, sOL : x.clientX - gridLeftPos };
  878. this.hDiv.style.cursor = "col-resize";
  879. this.curGbox = $("#rs_m"+$.jgrid.jqID(p.id),"#gbox_"+$.jgrid.jqID(p.id));
  880. this.curGbox.css({display:"block",left:x.clientX-gridLeftPos,top:y[1],height:y[2]});
  881. $(ts).triggerHandler("jqGridResizeStart", [x, i]);
  882. if($.isFunction(p.resizeStart)) { p.resizeStart.call(ts,x,i); }
  883. document.onselectstart=function(){return false;};
  884. },
  885. dragMove: function(x) {
  886. if(this.resizing) {
  887. var diff = x.clientX-this.resizing.startX,
  888. h = this.headers[this.resizing.idx],
  889. newWidth = p.direction === "ltr" ? h.width + diff : h.width - diff, hn, nWn;
  890. if(newWidth > 33) {
  891. this.curGbox.css({left:this.resizing.sOL+diff});
  892. if(p.forceFit===true ){
  893. hn = this.headers[this.resizing.idx+p.nv];
  894. nWn = p.direction === "ltr" ? hn.width - diff : hn.width + diff;
  895. if(nWn >33) {
  896. h.newWidth = newWidth;
  897. hn.newWidth = nWn;
  898. }
  899. } else {
  900. this.newWidth = p.direction === "ltr" ? p.tblwidth+diff : p.tblwidth-diff;
  901. h.newWidth = newWidth;
  902. }
  903. }
  904. }
  905. },
  906. dragEnd: function() {
  907. this.hDiv.style.cursor = "default";
  908. if(this.resizing) {
  909. var idx = this.resizing.idx,
  910. nw = this.headers[idx].newWidth || this.headers[idx].width;
  911. nw = parseInt(nw,10);
  912. this.resizing = false;
  913. $("#rs_m"+$.jgrid.jqID(p.id)).css("display","none");
  914. p.colModel[idx].width = nw;
  915. this.headers[idx].width = nw;
  916. this.headers[idx].el.style.width = nw + "px";
  917. this.cols[idx].style.width = nw+"px";
  918. if(this.footers.length>0) {this.footers[idx].style.width = nw+"px";}
  919. if(p.forceFit===true){
  920. nw = this.headers[idx+p.nv].newWidth || this.headers[idx+p.nv].width;
  921. this.headers[idx+p.nv].width = nw;
  922. this.headers[idx+p.nv].el.style.width = nw + "px";
  923. this.cols[idx+p.nv].style.width = nw+"px";
  924. if(this.footers.length>0) {this.footers[idx+p.nv].style.width = nw+"px";}
  925. p.colModel[idx+p.nv].width = nw;
  926. } else {
  927. p.tblwidth = this.newWidth || p.tblwidth;
  928. $('table:first',this.bDiv).css("width",p.tblwidth+"px");
  929. $('table:first',this.hDiv).css("width",p.tblwidth+"px");
  930. this.hDiv.scrollLeft = this.bDiv.scrollLeft;
  931. if(p.footerrow) {
  932. $('table:first',this.sDiv).css("width",p.tblwidth+"px");
  933. this.sDiv.scrollLeft = this.bDiv.scrollLeft;
  934. }
  935. }
  936. $(ts).triggerHandler("jqGridResizeStop", [nw, idx]);
  937. if($.isFunction(p.resizeStop)) { p.resizeStop.call(ts,nw,idx); }
  938. }
  939. this.curGbox = null;
  940. document.onselectstart=function(){return true;};
  941. },
  942. populateVisible: function() {
  943. if (grid.timer) { clearTimeout(grid.timer); }
  944. grid.timer = null;
  945. var dh = $(grid.bDiv).height();
  946. if (!dh) { return; }
  947. var table = $("table:first", grid.bDiv);
  948. var rows, rh;
  949. if(table[0].rows.length) {
  950. try {
  951. rows = table[0].rows[1];
  952. rh = rows ? $(rows).outerHeight() || grid.prevRowHeight : grid.prevRowHeight;
  953. } catch (pv) {
  954. rh = grid.prevRowHeight;
  955. }
  956. }
  957. if (!rh) { return; }
  958. grid.prevRowHeight = rh;
  959. var rn = p.rowNum;
  960. var scrollTop = grid.scrollTop = grid.bDiv.scrollTop;
  961. var ttop = Math.round(table.position().top) - scrollTop;
  962. var tbot = ttop + table.height();
  963. var div = rh * rn;
  964. var page, npage, empty;
  965. if ( tbot < dh && ttop <= 0 &&
  966. (p.lastpage===undefined||parseInt((tbot + scrollTop + div - 1) / div,10) <= p.lastpage))
  967. {
  968. npage = parseInt((dh - tbot + div - 1) / div,10);
  969. if (tbot >= 0 || npage < 2 || p.scroll === true) {
  970. page = Math.round((tbot + scrollTop) / div) + 1;
  971. ttop = -1;
  972. } else {
  973. ttop = 1;
  974. }
  975. }
  976. if (ttop > 0) {
  977. page = parseInt(scrollTop / div,10) + 1;
  978. npage = parseInt((scrollTop + dh) / div,10) + 2 - page;
  979. empty = true;
  980. }
  981. if (npage) {
  982. if (p.lastpage && (page > p.lastpage || p.lastpage===1 || (page === p.page && page===p.lastpage)) ) {
  983. return;
  984. }
  985. if (grid.hDiv.loading) {
  986. grid.timer = setTimeout(grid.populateVisible, p.scrollTimeout);
  987. } else {
  988. p.page = page;
  989. if (empty) {
  990. grid.selectionPreserver(table[0]);
  991. grid.emptyRows.call(table[0], false, false);
  992. }
  993. grid.populate(npage);
  994. }
  995. }
  996. },
  997. scrollGrid: function( e ) {
  998. if(p.scroll) {
  999. var scrollTop = grid.bDiv.scrollTop;
  1000. if(grid.scrollTop === undefined) { grid.scrollTop = 0; }
  1001. if (scrollTop !== grid.scrollTop) {
  1002. grid.scrollTop = scrollTop;
  1003. if (grid.timer) { clearTimeout(grid.timer); }
  1004. grid.timer = setTimeout(grid.populateVisible, p.scrollTimeout);
  1005. }
  1006. }
  1007. grid.hDiv.scrollLeft = grid.bDiv.scrollLeft;
  1008. if(p.footerrow) {
  1009. grid.sDiv.scrollLeft = grid.bDiv.scrollLeft;
  1010. }
  1011. if( e ) { e.stopPropagation(); }
  1012. },
  1013. selectionPreserver : function(ts) {
  1014. var p = ts.p,
  1015. sr = p.selrow, sra = p.selarrrow ? $.makeArray(p.selarrrow) : null,
  1016. left = ts.grid.bDiv.scrollLeft,
  1017. restoreSelection = function() {
  1018. var i;
  1019. p.selrow = null;
  1020. p.selarrrow = [];
  1021. if(p.multiselect && sra && sra.length>0) {
  1022. for(i=0;i<sra.length;i++){
  1023. if (sra[i] !== sr) {
  1024. $(ts).jqGrid("setSelection",sra[i],false, null);
  1025. }
  1026. }
  1027. }
  1028. if (sr) {
  1029. $(ts).jqGrid("setSelection",sr,false,null);
  1030. }
  1031. ts.grid.bDiv.scrollLeft = left;
  1032. $(ts).unbind('.selectionPreserver', restoreSelection);
  1033. };
  1034. $(ts).bind('jqGridGridComplete.selectionPreserver', restoreSelection);
  1035. }
  1036. };
  1037. if(this.tagName.toUpperCase() !== 'TABLE') {
  1038. alert("Element is not a table");
  1039. return;
  1040. }
  1041. if(document.documentMode !== undefined ) { // IE only
  1042. if(document.documentMode <= 5) {
  1043. alert("Grid can not be used in this ('quirks') mode!");
  1044. return;
  1045. }
  1046. }
  1047. $(this).empty().attr("tabindex","0");
  1048. this.p = p ;
  1049. this.p.useProp = !!$.fn.prop;
  1050. var i, dir;
  1051. if(this.p.colNames.length === 0) {
  1052. for (i=0;i<this.p.colModel.length;i++){
  1053. this.p.colNames[i] = this.p.colModel[i].label || this.p.colModel[i].name;
  1054. }
  1055. }
  1056. if( this.p.colNames.length !== this.p.colModel.length ) {
  1057. alert($.jgrid.errors.model);
  1058. return;
  1059. }
  1060. var gv = $("<div class='ui-jqgrid-view'></div>"),
  1061. isMSIE = $.jgrid.msie;
  1062. ts.p.direction = $.trim(ts.p.direction.toLowerCase());
  1063. if($.inArray(ts.p.direction,["ltr","rtl"]) === -1) { ts.p.direction = "ltr"; }
  1064. dir = ts.p.direction;
  1065. $(gv).insertBefore(this);
  1066. $(this).removeClass("scroll").appendTo(gv);
  1067. var eg = $("<div class='ui-jqgrid ui-widget ui-widget-content ui-corner-all'></div>");
  1068. $(eg).attr({"id" : "gbox_"+this.id,"dir":dir}).insertBefore(gv);
  1069. $(gv).attr("id","gview_"+this.id).appendTo(eg);
  1070. $("<div class='ui-widget-overlay jqgrid-overlay' id='lui_"+this.id+"'></div>").insertBefore(gv);
  1071. $("<div class='loading ui-state-default ui-state-active' id='load_"+this.id+"'>"+this.p.loadtext+"</div>").insertBefore(gv);
  1072. $(this).attr({cellspacing:"0",cellpadding:"0",border:"0","role":"grid","aria-multiselectable":!!this.p.multiselect,"aria-labelledby":"gbox_"+this.id});
  1073. var sortkeys = ["shiftKey","altKey","ctrlKey"],
  1074. intNum = function(val,defval) {
  1075. val = parseInt(val,10);
  1076. if (isNaN(val)) { return defval || 0;}
  1077. return val;
  1078. },
  1079. formatCol = function (pos, rowInd, tv, rawObject, rowId, rdata){
  1080. var cm = ts.p.colModel[pos],
  1081. ral = cm.align, result="style=\"", clas = cm.classes, nm = cm.name, celp, acp=[];
  1082. if(ral) { result += "text-align:"+ral+";"; }
  1083. if(cm.hidden===true) { result += "display:none;"; }
  1084. if(rowInd===0) {
  1085. result += "width: "+grid.headers[pos].width+"px;";
  1086. } else if (cm.cellattr && $.isFunction(cm.cellattr))
  1087. {
  1088. celp = cm.cellattr.call(ts, rowId, tv, rawObject, cm, rdata);
  1089. if(celp && typeof celp === "string") {
  1090. celp = celp.replace(/style/i,'style').replace(/title/i,'title');
  1091. if(celp.indexOf('title') > -1) { cm.title=false;}
  1092. if(celp.indexOf('class') > -1) { clas = undefined;}
  1093. acp = celp.replace('-style','-sti').split(/style/);
  1094. if(acp.length === 2 ) {
  1095. acp[1] = $.trim(acp[1].replace('-sti','-style').replace("=",""));
  1096. if(acp[1].indexOf("'") === 0 || acp[1].indexOf('"') === 0) {
  1097. acp[1] = acp[1].substring(1);
  1098. }
  1099. result += acp[1].replace(/'/gi,'"');
  1100. } else {
  1101. result += "\"";
  1102. }
  1103. }
  1104. }
  1105. if(!acp.length) { acp[0] = ""; result += "\"";}
  1106. result += (clas !== undefined ? (" class=\""+clas+"\"") :"") + ((cm.title && tv) ? (" title=\""+$.jgrid.stripHtml(tv)+"\"") :"");
  1107. result += " aria-describedby=\""+ts.p.id+"_"+nm+"\"";
  1108. return result + acp[0];
  1109. },
  1110. cellVal = function (val) {
  1111. return val == null || val === "" ? "&#160;" : (ts.p.autoencode ? $.jgrid.htmlEncode(val) : String(val));
  1112. },
  1113. formatter = function (rowId, cellval , colpos, rwdat, _act){
  1114. var cm = ts.p.colModel[colpos],v;
  1115. if(cm.formatter !== undefined) {
  1116. rowId = String(ts.p.idPrefix) !== "" ? $.jgrid.stripPref(ts.p.idPrefix, rowId) : rowId;
  1117. var opts= {rowId: rowId, colModel:cm, gid:ts.p.id, pos:colpos };
  1118. if($.isFunction( cm.formatter ) ) {
  1119. v = cm.formatter.call(ts,cellval,opts,rwdat,_act);
  1120. } else if($.fmatter){
  1121. v = $.fn.fmatter.call(ts,cm.formatter,cellval,opts,rwdat,_act);
  1122. } else {
  1123. v = cellVal(cellval);
  1124. }
  1125. } else {
  1126. v = cellVal(cellval);
  1127. }
  1128. return v;
  1129. },
  1130. addCell = function(rowId,cell,pos,irow, srvr, rdata) {
  1131. var v,prp;
  1132. v = formatter(rowId,cell,pos,srvr,'add');
  1133. prp = formatCol( pos,irow, v, srvr, rowId, rdata);
  1134. return "<td role=\"gridcell\" "+prp+">"+v+"</td>";
  1135. },
  1136. addMulti = function(rowid,pos,irow,checked){
  1137. var v = "<input role=\"checkbox\" type=\"checkbox\""+" id=\"jqg_"+ts.p.id+"_"+rowid+"\" class=\"cbox\" name=\"jqg_"+ts.p.id+"_"+rowid+"\"" + (checked ? "checked=\"checked\"" : "")+"/>",
  1138. prp = formatCol( pos,irow,'',null, rowid, true);
  1139. return "<td role=\"gridcell\" "+prp+">"+v+"</td>";
  1140. },
  1141. addRowNum = function (pos,irow,pG,rN) {
  1142. var v = (parseInt(pG,10)-1)*parseInt(rN,10)+1+irow,
  1143. prp = formatCol( pos,irow,v, null, irow, true);
  1144. return "<td role=\"gridcell\" class=\"ui-state-default jqgrid-rownum\" "+prp+">"+v+"</td>";
  1145. },
  1146. reader = function (datatype) {
  1147. var field, f=[], j=0, i;
  1148. for(i =0; i<ts.p.colModel.length; i++){
  1149. field = ts.p.colModel[i];
  1150. if (field.name !== 'cb' && field.name !=='subgrid' && field.name !=='rn') {
  1151. f[j]= datatype === "local" ?
  1152. field.name :
  1153. ( (datatype==="xml" || datatype === "xmlstring") ? field.xmlmap || field.name : field.jsonmap || field.name );
  1154. if(ts.p.keyIndex !== false && field.key===true ) {
  1155. ts.p.keyName = f[j];
  1156. }
  1157. j++;
  1158. }
  1159. }
  1160. return f;
  1161. },
  1162. orderedCols = function (offset) {
  1163. var order = ts.p.remapColumns;
  1164. if (!order || !order.length) {
  1165. order = $.map(ts.p.colModel, function(v,i) { return i; });
  1166. }
  1167. if (offset) {
  1168. order = $.map(order, function(v) { return v<offset?null:v-offset; });
  1169. }
  1170. return order;
  1171. },
  1172. emptyRows = function (scroll, locdata) {
  1173. var firstrow;
  1174. if (this.p.deepempty) {
  1175. $(this.rows).slice(1).remove();
  1176. } else {
  1177. firstrow = this.rows.length > 0 ? this.rows[0] : null;
  1178. $(this.firstChild).empty().append(firstrow);
  1179. }
  1180. if (scroll && this.p.scroll) {
  1181. $(this.grid.bDiv.firstChild).css({height: "auto"});
  1182. $(this.grid.bDiv.firstChild.firstChild).css({height: 0, display: "none"});
  1183. if (this.grid.bDiv.scrollTop !== 0) {
  1184. this.grid.bDiv.scrollTop = 0;
  1185. }
  1186. }
  1187. if(locdata === true && this.p.treeGrid) {
  1188. this.p.data = []; this.p._index = {};
  1189. }
  1190. },
  1191. refreshIndex = function() {
  1192. var datalen = ts.p.data.length, idname, i, val,
  1193. ni = ts.p.rownumbers===true ? 1 :0,
  1194. gi = ts.p.multiselect ===true ? 1 :0,
  1195. si = ts.p.subGrid===true ? 1 :0;
  1196. if(ts.p.keyIndex === false || ts.p.loadonce === true) {
  1197. idname = ts.p.localReader.id;
  1198. } else {
  1199. idname = ts.p.colModel[ts.p.keyIndex+gi+si+ni].name;
  1200. }
  1201. for(i =0;i < datalen; i++) {
  1202. val = $.jgrid.getAccessor(ts.p.data[i],idname);
  1203. if (val === undefined) { val=String(i+1); }
  1204. ts.p._index[val] = i;
  1205. }
  1206. },
  1207. constructTr = function(id, hide, altClass, rd, cur, selected) {
  1208. var tabindex = '-1', restAttr = '', attrName, style = hide ? 'display:none;' : '',
  1209. classes = 'ui-widget-content jqgrow ui-row-' + ts.p.direction + (altClass ? ' ' + altClass : '') + (selected ? ' ui-state-highlight' : ''),
  1210. rowAttrObj = $(ts).triggerHandler("jqGridRowAttr", [rd, cur, id]);
  1211. if( typeof rowAttrObj !== "object" ) {
  1212. rowAttrObj = $.isFunction(ts.p.rowattr) ? ts.p.rowattr.call(ts, rd, cur, id) :{};
  1213. }
  1214. if(!$.isEmptyObject( rowAttrObj )) {
  1215. if (rowAttrObj.hasOwnProperty("id")) {
  1216. id = rowAttrObj.id;
  1217. delete rowAttrObj.id;
  1218. }
  1219. if (rowAttrObj.hasOwnProperty("tabindex")) {
  1220. tabindex = rowAttrObj.tabindex;
  1221. delete rowAttrObj.tabindex;
  1222. }
  1223. if (rowAttrObj.hasOwnProperty("style")) {
  1224. style += rowAttrObj.style;
  1225. delete rowAttrObj.style;
  1226. }
  1227. if (rowAttrObj.hasOwnProperty("class")) {
  1228. classes += ' ' + rowAttrObj['class'];
  1229. delete rowAttrObj['class'];
  1230. }
  1231. // dot't allow to change role attribute
  1232. try { delete rowAttrObj.role; } catch(ra){}
  1233. for (attrName in rowAttrObj) {
  1234. if (rowAttrObj.hasOwnProperty(attrName)) {
  1235. restAttr += ' ' + attrName + '=' + rowAttrObj[attrName];
  1236. }
  1237. }
  1238. }
  1239. return '<tr role="row" id="' + id + '" tabindex="' + tabindex + '" class="' + classes + '"' +
  1240. (style === '' ? '' : ' style="' + style + '"') + restAttr + '>';
  1241. },
  1242. addXmlData = function (xml,t, rcnt, more, adjust) {
  1243. var startReq = new Date(),
  1244. locdata = (ts.p.datatype !== "local" && ts.p.loadonce) || ts.p.datatype === "xmlstring",
  1245. xmlid = "_id_", xmlRd = ts.p.xmlReader,
  1246. frd = ts.p.datatype === "local" ? "local" : "xml";
  1247. if(locdata) {
  1248. ts.p.data = [];
  1249. ts.p._index = {};
  1250. ts.p.localReader.id = xmlid;
  1251. }
  1252. ts.p.reccount = 0;
  1253. if($.isXMLDoc(xml)) {
  1254. if(ts.p.treeANode===-1 && !ts.p.scroll) {
  1255. emptyRows.call(ts, false, true);
  1256. rcnt=1;
  1257. } else { rcnt = rcnt > 1 ? rcnt :1; }
  1258. } else { return; }
  1259. 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;
  1260. if(ts.p.subGrid===true) {
  1261. si = 1;
  1262. addSubGridCell = $.jgrid.getMethod("addSubGridCell");
  1263. }
  1264. if(!xmlRd.repeatitems) {f = reader(frd);}
  1265. if( ts.p.keyIndex===false) {
  1266. idn = $.isFunction( xmlRd.id ) ? xmlRd.id.call(ts, xml) : xmlRd.id;
  1267. } else {
  1268. idn = ts.p.keyIndex;
  1269. }
  1270. if(f.length>0 && !isNaN(idn)) {
  1271. idn=ts.p.keyName;
  1272. }
  1273. if( String(idn).indexOf("[") === -1 ) {
  1274. if (f.length) {
  1275. getId = function( trow, k) {return $(idn,trow).text() || k;};
  1276. } else {
  1277. getId = function( trow, k) {return $(xmlRd.cell,trow).eq(idn).text() || k;};
  1278. }
  1279. }
  1280. else {
  1281. getId = function( trow, k) {return trow.getAttribute(idn.replace(/[\[\]]/g,"")) || k;};
  1282. }
  1283. ts.p.userData = {};
  1284. ts.p.page = intNum($.jgrid.getXmlData(xml, xmlRd.page), ts.p.page);
  1285. ts.p.lastpage = intNum($.jgrid.getXmlData(xml, xmlRd.total), 1);
  1286. ts.p.records = intNum($.jgrid.getXmlData(xml, xmlRd.records));
  1287. if($.isFunction(xmlRd.userdata)) {
  1288. ts.p.userData = xmlRd.userdata.call(ts, xml) || {};
  1289. } else {
  1290. $.jgrid.getXmlData(xml, xmlRd.userdata, true).each(function() {ts.p.userData[this.getAttribute("name")]= $(this).text();});
  1291. }
  1292. var gxml = $.jgrid.getXmlData( xml, xmlRd.root, true);
  1293. gxml = $.jgrid.getXmlData( gxml, xmlRd.row, true);
  1294. if (!gxml) { gxml = []; }
  1295. var gl = gxml.length, j=0, grpdata=[], rn = parseInt(ts.p.rowNum,10), br=ts.p.scroll?$.jgrid.randId():1, altr;
  1296. if (gl > 0 && ts.p.page <= 0) { ts.p.page = 1; }
  1297. if(gxml && gl){
  1298. if (adjust) { rn *= adjust+1; }
  1299. var afterInsRow = $.isFunction(ts.p.afterInsertRow), hiderow=false, groupingPrepare;
  1300. if(ts.p.grouping) {
  1301. hiderow = ts.p.groupingView.groupCollapse === true;
  1302. groupingPrepare = $.jgrid.getMethod("groupingPrepare");
  1303. }
  1304. while (j<gl) {
  1305. xmlr = gxml[j];
  1306. rid = getId(xmlr,br+j);
  1307. rid = ts.p.idPrefix + rid;
  1308. altr = rcnt === 0 ? 0 : rcnt+1;
  1309. cn1 = (altr+j)%2 === 1 ? cn : '';
  1310. var iStartTrTag = rowData.length;
  1311. rowData.push("");
  1312. if( ni ) {
  1313. rowData.push( addRowNum(0,j,ts.p.page,ts.p.rowNum) );
  1314. }
  1315. if( gi ) {
  1316. rowData.push( addMulti(rid,ni,j, false) );
  1317. }
  1318. if( si ) {
  1319. rowData.push( addSubGridCell.call(self,gi+ni,j+rcnt) );
  1320. }
  1321. if(xmlRd.repeatitems){
  1322. if (!F) { F=orderedCols(gi+si+ni); }
  1323. var cells = $.jgrid.getXmlData( xmlr, xmlRd.cell, true);
  1324. $.each(F, function (k) {
  1325. var cell = cells[this];
  1326. if (!cell) { return false; }
  1327. v = cell.textContent || cell.text;
  1328. rd[ts.p.colModel[k+gi+si+ni].name] = v;
  1329. rowData.push( addCell(rid,v,k+gi+si+ni,j+rcnt,xmlr, rd) );
  1330. });
  1331. } else {
  1332. for(i = 0; i < f.length;i++) {
  1333. v = $.jgrid.getXmlData( xmlr, f[i]);
  1334. rd[ts.p.colModel[i+gi+si+ni].name] = v;
  1335. rowData.push( addCell(rid, v, i+gi+si+ni, j+rcnt, xmlr, rd) );
  1336. }
  1337. }
  1338. rowData[iStartTrTag] = constructTr(rid, hiderow, cn1, rd, xmlr, false);
  1339. rowData.push("</tr>");
  1340. if(ts.p.grouping) {
  1341. grpdata.push( rowData );
  1342. if(!ts.p.groupingView._locgr) {
  1343. groupingPrepare.call(self, rd, j );
  1344. }
  1345. rowData = [];
  1346. }
  1347. if(locdata || ts.p.treeGrid === true) {
  1348. rd[xmlid] = $.jgrid.stripPref(ts.p.idPrefix, rid);
  1349. ts.p.data.push(rd);
  1350. ts.p._index[rd[xmlid]] = ts.p.data.length-1;
  1351. }
  1352. if(ts.p.gridview === false ) {
  1353. $("tbody:first",t).append(rowData.join(''));
  1354. self.triggerHandler("jqGridAfterInsertRow", [rid, rd, xmlr]);
  1355. if(afterInsRow) {ts.p.afterInsertRow.call(ts,rid,rd,xmlr);}
  1356. rowData=[];
  1357. }
  1358. rd={};
  1359. ir++;
  1360. j++;
  1361. if(ir===rn) {break;}
  1362. }
  1363. }
  1364. if(ts.p.gridview === true) {
  1365. fpos = ts.p.treeANode > -1 ? ts.p.treeANode: 0;
  1366. if(ts.p.grouping) {
  1367. if(!locdata) {
  1368. self.jqGrid('groupingRender',grpdata,ts.p.colModel.length, ts.p.page, rn);
  1369. }
  1370. grpdata = null;
  1371. } else if(ts.p.treeGrid === true && fpos > 0) {
  1372. $(ts.rows[fpos]).after(rowData.join(''));
  1373. } else {
  1374. $("tbody:first",t).append(rowData.join(''));
  1375. }
  1376. }
  1377. if(ts.p.subGrid === true ) {
  1378. try {self.jqGrid("addSubGrid",gi+ni);} catch (_){}
  1379. }
  1380. ts.p.totaltime = new Date() - startReq;
  1381. if(ir>0) { if(ts.p.records===0) { ts.p.records=gl;} }
  1382. rowData =null;
  1383. if( ts.p.treeGrid === true) {
  1384. try {self.jqGrid("setTreeNode", fpos+1, ir+fpos+1);} catch (e) {}
  1385. }
  1386. if(!ts.p.treeGrid && !ts.p.scroll) {ts.grid.bDiv.scrollTop = 0;}
  1387. ts.p.reccount=ir;
  1388. ts.p.treeANode = -1;
  1389. if(ts.p.userDataOnFooter) { self.jqGrid("footerData","set",ts.p.userData,true); }
  1390. if(locdata) {
  1391. ts.p.records = gl;
  1392. ts.p.lastpage = Math.ceil(gl/ rn);
  1393. }
  1394. if (!more) { ts.updatepager(false,true); }
  1395. if(locdata) {
  1396. while (ir<gl) {
  1397. xmlr = gxml[ir];
  1398. rid = getId(xmlr,ir+br);
  1399. rid = ts.p.idPrefix + rid;
  1400. if(xmlRd.repeatitems){
  1401. if (!F) { F=orderedCols(gi+si+ni); }
  1402. var cells2 = $.jgrid.getXmlData( xmlr, xmlRd.cell, true);
  1403. $.each(F, function (k) {
  1404. var cell = cells2[this];
  1405. if (!cell) { return false; }
  1406. v = cell.textContent || cell.text;
  1407. rd[ts.p.colModel[k+gi+si+ni].name] = v;
  1408. });
  1409. } else {
  1410. for(i = 0; i < f.length;i++) {
  1411. v = $.jgrid.getXmlData( xmlr, f[i]);
  1412. rd[ts.p.colModel[i+gi+si+ni].name] = v;
  1413. }
  1414. }
  1415. rd[xmlid] = $.jgrid.stripPref(ts.p.idPrefix, rid);
  1416. if(ts.p.grouping) {
  1417. groupingPrepare.call(self, rd, ir );
  1418. }
  1419. ts.p.data.push(rd);
  1420. ts.p._index[rd[xmlid]] = ts.p.data.length-1;
  1421. rd = {};
  1422. ir++;
  1423. }
  1424. if(ts.p.grouping) {
  1425. ts.p.groupingView._locgr = true;
  1426. self.jqGrid('groupingRender', grpdata, ts.p.colModel.length, ts.p.page, rn);
  1427. grpdata = null;
  1428. }
  1429. }
  1430. },
  1431. addJSONData = function(data,t, rcnt, more, adjust) {
  1432. var startReq = new Date();
  1433. if(data) {
  1434. if(ts.p.treeANode === -1 && !ts.p.scroll) {
  1435. emptyRows.call(ts, false, true);
  1436. rcnt=1;
  1437. } else { rcnt = rcnt > 1 ? rcnt :1; }
  1438. } else { return; }
  1439. var dReader, locid = "_id_", frd,
  1440. locdata = (ts.p.datatype !== "local" && ts.p.loadonce) || ts.p.datatype === "jsonstring";
  1441. if(locdata) { ts.p.data = []; ts.p._index = {}; ts.p.localReader.id = locid;}
  1442. ts.p.reccount = 0;
  1443. if(ts.p.datatype === "local") {
  1444. dReader = ts.p.localReader;
  1445. frd= 'local';
  1446. } else {
  1447. dReader = ts.p.jsonReader;
  1448. frd='json';
  1449. }
  1450. var self = $(ts), ir=0,v,i,j,f=[],cur,gi=ts.p.multiselect?1:0,si=ts.p.subGrid===true?1:0,addSubGridCell,ni=ts.p.rownumbers===true?1:0,arrayReader=orderedCols(gi+si+ni),objectReader=reader(frd),rowReader,len,drows,idn,rd={}, fpos, idr,rowData=[],cn=(ts.p.altRows === true) ? ts.p.altclass:"",cn1;
  1451. ts.p.page = intNum($.jgrid.getAccessor(data,dReader.page), ts.p.page);
  1452. ts.p.lastpage = intNum($.jgrid.getAccessor(data,dReader.total), 1);
  1453. ts.p.records = intNum($.jgrid.getAccessor(data,dReader.records));
  1454. ts.p.userData = $.jgrid.getAccessor(data,dReader.userdata) || {};
  1455. if(si) {
  1456. addSubGridCell = $.jgrid.getMethod("addSubGridCell");
  1457. }
  1458. if( ts.p.keyIndex===false ) {
  1459. idn = $.isFunction(dReader.id) ? dReader.id.call(ts, data) : dReader.id;
  1460. } else {
  1461. idn = ts.p.keyIndex;
  1462. }
  1463. if(!dReader.repeatitems) {
  1464. f = objectReader;
  1465. if(f.length>0 && !isNaN(idn)) {
  1466. idn=ts.p.keyName;
  1467. }
  1468. }
  1469. drows = $.jgrid.getAccessor(data,dReader.root);
  1470. if (drows == null && $.isArray(data)) { drows = data; }
  1471. if (!drows) { drows = []; }
  1472. len = drows.length; i=0;
  1473. if (len > 0 && ts.p.page <= 0) { ts.p.page = 1; }
  1474. var rn = parseInt(ts.p.rowNum,10),br=ts.p.scroll?$.jgrid.randId():1, altr, selected=false, selr;
  1475. if (adjust) { rn *= adjust+1; }
  1476. if(ts.p.datatype === "local" && !ts.p.deselectAfterSort) {
  1477. selected = true;
  1478. }
  1479. var afterInsRow = $.isFunction(ts.p.afterInsertRow), grpdata=[],hiderow=false, groupingPrepare;
  1480. if(ts.p.grouping) {
  1481. hiderow = ts.p.groupingView.groupCollapse === true;
  1482. groupingPrepare = $.jgrid.getMethod("groupingPrepare");
  1483. }
  1484. while (i<len) {
  1485. cur = drows[i];
  1486. idr = $.jgrid.getAccessor(cur,idn);
  1487. if(idr === undefined) {
  1488. if (typeof idn === "number" && ts.p.colModel[idn+gi+si+ni] != null) {
  1489. // reread id by name
  1490. idr = $.jgrid.getAccessor(cur,ts.p.colModel[idn+gi+si+ni].name);
  1491. }
  1492. if(idr === undefined) {
  1493. idr = br+i;
  1494. if(f.length===0){
  1495. if(dReader.cell){
  1496. var ccur = $.jgrid.getAccessor(cur,dReader.cell) || cur;
  1497. idr = ccur != null && ccur[idn] !== undefined ? ccur[idn] : idr;
  1498. ccur=null;
  1499. }
  1500. }
  1501. }
  1502. }
  1503. idr = ts.p.idPrefix + idr;
  1504. altr = rcnt === 1 ? 0 : rcnt;
  1505. cn1 = (altr+i)%2 === 1 ? cn : '';
  1506. if( selected) {
  1507. if( ts.p.multiselect) {
  1508. selr = ($.inArray(idr, ts.p.selarrrow) !== -1);
  1509. } else {
  1510. selr = (idr === ts.p.selrow);
  1511. }
  1512. }
  1513. var iStartTrTag = rowData.length;
  1514. rowData.push("");
  1515. if( ni ) {
  1516. rowData.push( addRowNum(0,i,ts.p.page,ts.p.rowNum) );
  1517. }
  1518. if( gi ){
  1519. rowData.push( addMulti(idr,ni,i,selr) );
  1520. }
  1521. if( si ) {
  1522. rowData.push( addSubGridCell.call(self,gi+ni,i+rcnt) );
  1523. }
  1524. rowReader=objectReader;
  1525. if (dReader.repeatitems) {
  1526. if(dReader.cell) {cur = $.jgrid.getAccessor(cur,dReader.cell) || cur;}
  1527. if ($.isArray(cur)) { rowReader=arrayReader; }
  1528. }
  1529. for (j=0;j<rowReader.length;j++) {
  1530. v = $.jgrid.getAccessor(cur,rowReader[j]);
  1531. rd[ts.p.colModel[j+gi+si+ni].name] = v;
  1532. rowData.push( addCell(idr,v,j+gi+si+ni,i+rcnt,cur, rd) );
  1533. }
  1534. rowData[iStartTrTag] = constructTr(idr, hiderow, cn1, rd, cur, selr);
  1535. rowData.push( "</tr>" );
  1536. if(ts.p.grouping) {
  1537. grpdata.push( rowData );
  1538. if(!ts.p.groupingView._locgr) {
  1539. groupingPrepare.call(self, rd, i);
  1540. }
  1541. rowData = [];
  1542. }
  1543. if(locdata || ts.p.treeGrid===true) {
  1544. rd[locid] = $.jgrid.stripPref(ts.p.idPrefix, idr);
  1545. ts.p.data.push(rd);
  1546. ts.p._index[rd[locid]] = ts.p.data.length-1;
  1547. }
  1548. if(ts.p.gridview === false ) {
  1549. $("#"+$.jgrid.jqID(ts.p.id)+" tbody:first").append(rowData.join(''));
  1550. self.triggerHandler("jqGridAfterInsertRow", [idr, rd, cur]);
  1551. if(afterInsRow) {ts.p.afterInsertRow.call(ts,idr,rd,cur);}
  1552. rowData=[];//ari=0;
  1553. }
  1554. rd={};
  1555. ir++;
  1556. i++;
  1557. if(ir===rn) { break; }
  1558. }
  1559. if(ts.p.gridview === true ) {
  1560. fpos = ts.p.treeANode > -1 ? ts.p.treeANode: 0;
  1561. if(ts.p.grouping) {
  1562. if(!locdata) {
  1563. self.jqGrid('groupingRender', grpdata, ts.p.colModel.length, ts.p.page, rn);
  1564. grpdata = null;
  1565. }
  1566. } else if(ts.p.treeGrid === true && fpos > 0) {
  1567. $(ts.rows[fpos]).after(rowData.join(''));
  1568. } else {
  1569. $("#"+$.jgrid.jqID(ts.p.id)+" tbody:first").append(rowData.join(''));
  1570. }
  1571. }
  1572. if(ts.p.subGrid === true ) {
  1573. try { self.jqGrid("addSubGrid",gi+ni);} catch (_){}
  1574. }
  1575. ts.p.totaltime = new Date() - startReq;
  1576. if(ir>0) {
  1577. if(ts.p.records===0) { ts.p.records=len; }
  1578. }
  1579. rowData = null;
  1580. if( ts.p.treeGrid === true) {
  1581. try {self.jqGrid("setTreeNode", fpos+1, ir+fpos+1);} catch (e) {}
  1582. }
  1583. if(!ts.p.treeGrid && !ts.p.scroll) {ts.grid.bDiv.scrollTop = 0;}
  1584. ts.p.reccount=ir;
  1585. ts.p.treeANode = -1;
  1586. if(ts.p.userDataOnFooter) { self.jqGrid("footerData","set",ts.p.userData,true); }
  1587. if(locdata) {
  1588. ts.p.records = len;
  1589. ts.p.lastpage = Math.ceil(len/ rn);
  1590. }
  1591. if (!more) { ts.updatepager(false,true); }
  1592. if(locdata) {
  1593. while (ir<len && drows[ir]) {
  1594. cur = drows[ir];
  1595. idr = $.jgrid.getAccessor(cur,idn);
  1596. if(idr === undefined) {
  1597. if (typeof idn === "number" && ts.p.colModel[idn+gi+si+ni] != null) {
  1598. // reread id by name
  1599. idr = $.jgrid.getAccessor(cur,ts.p.colModel[idn+gi+si+ni].name);
  1600. }
  1601. if(idr === undefined) {
  1602. idr = br+ir;
  1603. if(f.length===0){
  1604. if(dReader.cell){
  1605. var ccur2 = $.jgrid.getAccessor(cur,dReader.cell) || cur;
  1606. idr = ccur2 != null && ccur2[idn] !== undefined ? ccur2[idn] : idr;
  1607. ccur2=null;
  1608. }
  1609. }
  1610. }
  1611. }
  1612. if(cur) {
  1613. idr = ts.p.idPrefix + idr;
  1614. rowReader=objectReader;
  1615. if (dReader.repeatitems) {
  1616. if(dReader.cell) {cur = $.jgrid.getAccessor(cur,dReader.cell) || cur;}
  1617. if ($.isArray(cur)) { rowReader=arrayReader; }
  1618. }
  1619. for (j=0;j<rowReader.length;j++) {
  1620. rd[ts.p.colModel[j+gi+si+ni].name] = $.jgrid.getAccessor(cur,rowReader[j]);
  1621. }
  1622. rd[locid] = $.jgrid.stripPref(ts.p.idPrefix, idr);
  1623. if(ts.p.grouping) {
  1624. groupingPrepare.call(self, rd, ir );
  1625. }
  1626. ts.p.data.push(rd);
  1627. ts.p._index[rd[locid]] = ts.p.data.length-1;
  1628. rd = {};
  1629. }
  1630. ir++;
  1631. }
  1632. if(ts.p.grouping) {
  1633. ts.p.groupingView._locgr = true;
  1634. self.jqGrid('groupingRender', grpdata, ts.p.colModel.length, ts.p.page, rn);
  1635. grpdata = null;
  1636. }
  1637. }
  1638. },
  1639. addLocalData = function() {
  1640. var st = ts.p.multiSort ? [] : "", sto=[], fndsort=false, cmtypes={}, grtypes=[], grindexes=[], srcformat, sorttype, newformat;
  1641. if(!$.isArray(ts.p.data)) {
  1642. return;
  1643. }
  1644. var grpview = ts.p.grouping ? ts.p.groupingView : false, lengrp, gin;
  1645. $.each(ts.p.colModel,function(){
  1646. sorttype = this.sorttype || "text";
  1647. if(sorttype === "date" || sorttype === "datetime") {
  1648. if(this.formatter && typeof this.formatter === 'string' && this.formatter === 'date') {
  1649. if(this.formatoptions && this.formatoptions.srcformat) {
  1650. srcformat = this.formatoptions.srcformat;
  1651. } else {
  1652. srcformat = $.jgrid.formatter.date.srcformat;
  1653. }
  1654. if(this.formatoptions && this.formatoptions.newformat) {
  1655. newformat = this.formatoptions.newformat;
  1656. } else {
  1657. newformat = $.jgrid.formatter.date.newformat;
  1658. }
  1659. } else {
  1660. srcformat = newformat = this.datefmt || "Y-m-d";
  1661. }
  1662. cmtypes[this.name] = {"stype": sorttype, "srcfmt": srcformat,"newfmt":newformat, "sfunc": this.sortfunc || null};
  1663. } else {
  1664. cmtypes[this.name] = {"stype": sorttype, "srcfmt":'',"newfmt":'', "sfunc": this.sortfunc || null};
  1665. }
  1666. if(ts.p.grouping ) {
  1667. for(gin =0, lengrp = grpview.groupField.length; gin< lengrp; gin++) {
  1668. if( this.name === grpview.groupField[gin]) {
  1669. var grindex = this.name;
  1670. if (this.index) {
  1671. grindex = this.index;
  1672. }
  1673. grtypes[gin] = cmtypes[grindex];
  1674. grindexes[gin]= grindex;
  1675. }
  1676. }
  1677. }
  1678. if(ts.p.multiSort) {
  1679. if(this.lso) {
  1680. st.push(this.name);
  1681. var tmplso= this.lso.split("-");
  1682. sto.push( tmplso[tmplso.length-1] );
  1683. }
  1684. } else {
  1685. if(!fndsort && (this.index === ts.p.sortname || this.name === ts.p.sortname)){
  1686. st = this.name; // ???
  1687. fndsort = true;
  1688. }
  1689. }
  1690. });
  1691. if(ts.p.treeGrid) {
  1692. $(ts).jqGrid("SortTree", st, ts.p.sortorder, cmtypes[st].stype || 'text', cmtypes[st].srcfmt || '');
  1693. return;
  1694. }
  1695. var compareFnMap = {
  1696. 'eq':function(queryObj) {return queryObj.equals;},
  1697. 'ne':function(queryObj) {return queryObj.notEquals;},
  1698. 'lt':function(queryObj) {return queryObj.less;},
  1699. 'le':function(queryObj) {return queryObj.lessOrEquals;},
  1700. 'gt':function(queryObj) {return queryObj.greater;},
  1701. 'ge':function(queryObj) {return queryObj.greaterOrEquals;},
  1702. 'cn':function(queryObj) {return queryObj.contains;},
  1703. 'nc':function(queryObj,op) {return op === "OR" ? queryObj.orNot().contains : queryObj.andNot().contains;},
  1704. 'bw':function(queryObj) {return queryObj.startsWith;},
  1705. 'bn':function(queryObj,op) {return op === "OR" ? queryObj.orNot().startsWith : queryObj.andNot().startsWith;},
  1706. 'en':function(queryObj,op) {return op === "OR" ? queryObj.orNot().endsWith : queryObj.andNot().endsWith;},
  1707. 'ew':function(queryObj) {return queryObj.endsWith;},
  1708. 'ni':function(queryObj,op) {return op === "OR" ? queryObj.orNot().equals : queryObj.andNot().equals;},
  1709. 'in':function(queryObj) {return queryObj.equals;},
  1710. 'nu':function(queryObj) {return queryObj.isNull;},
  1711. 'nn':function(queryObj,op) {return op === "OR" ? queryObj.orNot().isNull : queryObj.andNot().isNull;}
  1712. },
  1713. query = $.jgrid.from(ts.p.data);
  1714. if (ts.p.ignoreCase) { query = query.ignoreCase(); }
  1715. function tojLinq ( group ) {
  1716. var s = 0, index, gor, ror, opr, rule;
  1717. if (group.groups != null) {
  1718. gor = group.groups.length && group.groupOp.toString().toUpperCase() === "OR";
  1719. if (gor) {
  1720. query.orBegin();
  1721. }
  1722. for (index = 0; index < group.groups.length; index++) {
  1723. if (s > 0 && gor) {
  1724. query.or();
  1725. }
  1726. try {
  1727. tojLinq(group.groups[index]);
  1728. } catch (e) {alert(e);}
  1729. s++;
  1730. }
  1731. if (gor) {
  1732. query.orEnd();
  1733. }
  1734. }
  1735. if (group.rules != null) {
  1736. //if(s>0) {
  1737. // var result = query.select();
  1738. // query = $.jgrid.from( result);
  1739. // if (ts.p.ignoreCase) { query = query.ignoreCase(); }
  1740. //}
  1741. try{
  1742. ror = group.rules.length && group.groupOp.toString().toUpperCase() === "OR";
  1743. if (ror) {
  1744. query.orBegin();
  1745. }
  1746. for (index = 0; index < group.rules.length; index++) {
  1747. rule = group.rules[index];
  1748. opr = group.groupOp.toString().toUpperCase();
  1749. if (compareFnMap[rule.op] && rule.field ) {
  1750. if(s > 0 && opr && opr === "OR") {
  1751. query = query.or();
  1752. }
  1753. query = compareFnMap[rule.op](query, opr)(rule.field, rule.data, cmtypes[rule.field]);
  1754. }
  1755. s++;
  1756. }
  1757. if (ror) {
  1758. query.orEnd();
  1759. }
  1760. } catch (g) {alert(g);}
  1761. }
  1762. }
  1763. if (ts.p.search === true) {
  1764. var srules = ts.p.postData.filters;
  1765. if(srules) {
  1766. if(typeof srules === "string") { srules = $.jgrid.parse(srules);}
  1767. tojLinq( srules );
  1768. } else {
  1769. try {
  1770. query = compareFnMap[ts.p.postData.searchOper](query)(ts.p.postData.searchField, ts.p.postData.searchString,cmtypes[ts.p.postData.searchField]);
  1771. } catch (se){}
  1772. }
  1773. }
  1774. if(ts.p.grouping) {
  1775. for(gin=0; gin<lengrp;gin++) {
  1776. query.orderBy(grindexes[gin],grpview.groupOrder[gin],grtypes[gin].stype, grtypes[gin].srcfmt);
  1777. }
  1778. }
  1779. if(ts.p.multiSort) {
  1780. $.each(st,function(i){
  1781. query.orderBy(this, sto[i], cmtypes[this].stype, cmtypes[this].srcfmt, cmtypes[this].sfunc);
  1782. });
  1783. } else {
  1784. if (st && ts.p.sortorder && fndsort) {
  1785. if(ts.p.sortorder.toUpperCase() === "DESC") {
  1786. query.orderBy(ts.p.sortname, "d", cmtypes[st].stype, cmtypes[st].srcfmt, cmtypes[st].sfunc);
  1787. } else {
  1788. query.orderBy(ts.p.sortname, "a", cmtypes[st].stype, cmtypes[st].srcfmt, cmtypes[st].sfunc);
  1789. }
  1790. }
  1791. }
  1792. var queryResults = query.select(),
  1793. recordsperpage = parseInt(ts.p.rowNum,10),
  1794. total = queryResults.length,
  1795. page = parseInt(ts.p.page,10),
  1796. totalpages = Math.ceil(total / recordsperpage),
  1797. retresult = {};
  1798. if((ts.p.search || ts.p.resetsearch) && ts.p.grouping && ts.p.groupingView._locgr) {
  1799. ts.p.groupingView.groups =[];
  1800. var j, grPrepare = $.jgrid.getMethod("groupingPrepare"), key, udc;
  1801. if(ts.p.footerrow && ts.p.userDataOnFooter) {
  1802. for (key in ts.p.userData) {
  1803. if(ts.p.userData.hasOwnProperty(key)) {
  1804. ts.p.userData[key] = 0;
  1805. }
  1806. }
  1807. udc = true;
  1808. }
  1809. for(j=0; j<total; j++) {
  1810. if(udc) {
  1811. for(key in ts.p.userData){
  1812. ts.p.userData[key] += parseFloat(queryResults[j][key] || 0);
  1813. }
  1814. }
  1815. grPrepare.call($(ts),queryResults[j],j, recordsperpage );
  1816. }
  1817. }
  1818. queryResults = queryResults.slice( (page-1)*recordsperpage , page*recordsperpage );
  1819. query = null;
  1820. cmtypes = null;
  1821. retresult[ts.p.localReader.total] = totalpages;
  1822. retresult[ts.p.localReader.page] = page;
  1823. retresult[ts.p.localReader.records] = total;
  1824. retresult[ts.p.localReader.root] = queryResults;
  1825. retresult[ts.p.localReader.userdata] = ts.p.userData;
  1826. queryResults = null;
  1827. return retresult;
  1828. },
  1829. updatepager = function(rn, dnd) {
  1830. var cp, last, base, from,to,tot,fmt, pgboxes = "", sppg,
  1831. tspg = ts.p.pager ? "_"+$.jgrid.jqID(ts.p.pager.substr(1)) : "",
  1832. tspg_t = ts.p.toppager ? "_"+ts.p.toppager.substr(1) : "";
  1833. base = parseInt(ts.p.page,10)-1;
  1834. if(base < 0) { base = 0; }
  1835. base = base*parseInt(ts.p.rowNum,10);
  1836. to = base + ts.p.reccount;
  1837. if (ts.p.scroll) {
  1838. var rows = $("tbody:first > tr:gt(0)", ts.grid.bDiv);
  1839. base = to - rows.length;
  1840. ts.p.reccount = rows.length;
  1841. var rh = rows.outerHeight() || ts.grid.prevRowHeight;
  1842. if (rh) {
  1843. var top = base * rh;
  1844. var height = parseInt(ts.p.records,10) * rh;
  1845. $(">div:first",ts.grid.bDiv).css({height : height}).children("div:first").css({height:top,display:top?"":"none"});
  1846. if (ts.grid.bDiv.scrollTop == 0 && ts.p.page > 1) {
  1847. ts.grid.bDiv.scrollTop = ts.p.rowNum * (ts.p.page - 1) * rh;
  1848. }
  1849. }
  1850. ts.grid.bDiv.scrollLeft = ts.grid.hDiv.scrollLeft;
  1851. }
  1852. pgboxes = ts.p.pager || "";
  1853. pgboxes += ts.p.toppager ? (pgboxes ? "," + ts.p.toppager : ts.p.toppager) : "";
  1854. if(pgboxes) {
  1855. fmt = $.jgrid.formatter.integer || {};
  1856. cp = intNum(ts.p.page);
  1857. last = intNum(ts.p.lastpage);
  1858. $(".selbox",pgboxes)[ this.p.useProp ? 'prop' : 'attr' ]("disabled",false);
  1859. if(ts.p.pginput===true) {
  1860. $('.ui-pg-input',pgboxes).val(ts.p.page);
  1861. sppg = ts.p.toppager ? '#sp_1'+tspg+",#sp_1"+tspg_t : '#sp_1'+tspg;
  1862. $(sppg).html($.fmatter ? $.fmatter.util.NumberFormat(ts.p.lastpage,fmt):ts.p.lastpage);
  1863. }
  1864. if (ts.p.viewrecords){
  1865. if(ts.p.reccount === 0) {
  1866. $(".ui-paging-info",pgboxes).html(ts.p.emptyrecords);
  1867. } else {
  1868. from = base+1;
  1869. tot=ts.p.records;
  1870. if($.fmatter) {
  1871. from = $.fmatter.util.NumberFormat(from,fmt);
  1872. to = $.fmatter.util.NumberFormat(to,fmt);
  1873. tot = $.fmatter.util.NumberFormat(tot,fmt);
  1874. }
  1875. $(".ui-paging-info",pgboxes).html($.jgrid.format(ts.p.recordtext,from,to,tot));
  1876. }
  1877. }
  1878. if(ts.p.pgbuttons===true) {
  1879. if(cp<=0) {cp = last = 0;}
  1880. if(cp===1 || cp === 0) {
  1881. $("#first"+tspg+", #prev"+tspg).addClass('ui-state-disabled').removeClass('ui-state-hover');
  1882. if(ts.p.toppager) { $("#first_t"+tspg_t+", #prev_t"+tspg_t).addClass('ui-state-disabled').removeClass('ui-state-hover'); }
  1883. } else {
  1884. $("#first"+tspg+", #prev"+tspg).removeClass('ui-state-disabled');
  1885. if(ts.p.toppager) { $("#first_t"+tspg_t+", #prev_t"+tspg_t).removeClass('ui-state-disabled'); }
  1886. }
  1887. if(cp===last || cp === 0) {
  1888. $("#next"+tspg+", #last"+tspg).addClass('ui-state-disabled').removeClass('ui-state-hover');
  1889. if(ts.p.toppager) { $("#next_t"+tspg_t+", #last_t"+tspg_t).addClass('ui-state-disabled').removeClass('ui-state-hover'); }
  1890. } else {
  1891. $("#next"+tspg+", #last"+tspg).removeClass('ui-state-disabled');
  1892. if(ts.p.toppager) { $("#next_t"+tspg_t+", #last_t"+tspg_t).removeClass('ui-state-disabled'); }
  1893. }
  1894. }
  1895. }
  1896. if(rn===true && ts.p.rownumbers === true) {
  1897. $(">td.jqgrid-rownum",ts.rows).each(function(i){
  1898. $(this).html(base+1+i);
  1899. });
  1900. }
  1901. if(dnd && ts.p.jqgdnd) { $(ts).jqGrid('gridDnD','updateDnD');}
  1902. $(ts).triggerHandler("jqGridGridComplete");
  1903. if($.isFunction(ts.p.gridComplete)) {ts.p.gridComplete.call(ts);}
  1904. $(ts).triggerHandler("jqGridAfterGridComplete");
  1905. },
  1906. beginReq = function() {
  1907. ts.grid.hDiv.loading = true;
  1908. if(ts.p.hiddengrid) { return;}
  1909. switch(ts.p.loadui) {
  1910. case "disable":
  1911. break;
  1912. case "enable":
  1913. $("#load_"+$.jgrid.jqID(ts.p.id)).show();
  1914. break;
  1915. case "block":
  1916. $("#lui_"+$.jgrid.jqID(ts.p.id)).show();
  1917. $("#load_"+$.jgrid.jqID(ts.p.id)).show();
  1918. break;
  1919. }
  1920. },
  1921. endReq = function() {
  1922. ts.grid.hDiv.loading = false;
  1923. switch(ts.p.loadui) {
  1924. case "disable":
  1925. break;
  1926. case "enable":
  1927. $("#load_"+$.jgrid.jqID(ts.p.id)).hide();
  1928. break;
  1929. case "block":
  1930. $("#lui_"+$.jgrid.jqID(ts.p.id)).hide();
  1931. $("#load_"+$.jgrid.jqID(ts.p.id)).hide();
  1932. break;
  1933. }
  1934. },
  1935. populate = function (npage) {
  1936. if(!ts.grid.hDiv.loading) {
  1937. var pvis = ts.p.scroll && npage === false,
  1938. prm = {}, dt, dstr, pN=ts.p.prmNames;
  1939. if(ts.p.page <=0) { ts.p.page = Math.min(1,ts.p.lastpage); }
  1940. if(pN.search !== null) {prm[pN.search] = ts.p.search;} if(pN.nd !== null) {prm[pN.nd] = new Date().getTime();}
  1941. if(pN.rows !== null) {prm[pN.rows]= ts.p.rowNum;} if(pN.page !== null) {prm[pN.page]= ts.p.page;}
  1942. if(pN.sort !== null) {prm[pN.sort]= ts.p.sortname;} if(pN.order !== null) {prm[pN.order]= ts.p.sortorder;}
  1943. if(ts.p.rowTotal !== null && pN.totalrows !== null) { prm[pN.totalrows]= ts.p.rowTotal; }
  1944. var lcf = $.isFunction(ts.p.loadComplete), lc = lcf ? ts.p.loadComplete : null;
  1945. var adjust = 0;
  1946. npage = npage || 1;
  1947. if (npage > 1) {
  1948. if(pN.npage !== null) {
  1949. prm[pN.npage] = npage;
  1950. adjust = npage - 1;
  1951. npage = 1;
  1952. } else {
  1953. lc = function(req) {
  1954. ts.p.page++;
  1955. ts.grid.hDiv.loading = false;
  1956. if (lcf) {
  1957. ts.p.loadComplete.call(ts,req);
  1958. }
  1959. populate(npage-1);
  1960. };
  1961. }
  1962. } else if (pN.npage !== null) {
  1963. delete ts.p.postData[pN.npage];
  1964. }
  1965. if(ts.p.grouping) {
  1966. $(ts).jqGrid('groupingSetup');
  1967. var grp = ts.p.groupingView, gi, gs="";
  1968. for(gi=0;gi<grp.groupField.length;gi++) {
  1969. var index = grp.groupField[gi];
  1970. $.each(ts.p.colModel, function(cmIndex, cmValue) {
  1971. if (cmValue.name === index && cmValue.index){
  1972. index = cmValue.index;
  1973. }
  1974. } );
  1975. gs += index +" "+grp.groupOrder[gi]+", ";
  1976. }
  1977. prm[pN.sort] = gs + prm[pN.sort];
  1978. }
  1979. $.extend(ts.p.postData,prm);
  1980. var rcnt = !ts.p.scroll ? 1 : ts.rows.length-1;
  1981. var bfr = $(ts).triggerHandler("jqGridBeforeRequest");
  1982. if (bfr === false || bfr === 'stop') { return; }
  1983. if ($.isFunction(ts.p.datatype)) { ts.p.datatype.call(ts,ts.p.postData,"load_"+ts.p.id, rcnt, npage, adjust); return;}
  1984. if ($.isFunction(ts.p.beforeRequest)) {
  1985. bfr = ts.p.beforeRequest.call(ts);
  1986. if(bfr === undefined) { bfr = true; }
  1987. if ( bfr === false ) { return; }
  1988. }
  1989. dt = ts.p.datatype.toLowerCase();
  1990. switch(dt)
  1991. {
  1992. case "json":
  1993. case "jsonp":
  1994. case "xml":
  1995. case "script":
  1996. $.ajax($.extend({
  1997. url:ts.p.url,
  1998. type:ts.p.mtype,
  1999. dataType: dt ,
  2000. data: $.isFunction(ts.p.serializeGridData)? ts.p.serializeGridData.call(ts,ts.p.postData) : ts.p.postData,
  2001. success:function(data,st, xhr) {
  2002. if ($.isFunction(ts.p.beforeProcessing)) {
  2003. if (ts.p.beforeProcessing.call(ts, data, st, xhr) === false) {
  2004. endReq();
  2005. return;
  2006. }
  2007. }
  2008. if(dt === "xml") { addXmlData(data,ts.grid.bDiv,rcnt,npage>1,adjust); }
  2009. else { addJSONData(data,ts.grid.bDiv,rcnt,npage>1,adjust); }
  2010. $(ts).triggerHandler("jqGridLoadComplete", [data]);
  2011. if(lc) { lc.call(ts,data); }
  2012. $(ts).triggerHandler("jqGridAfterLoadComplete", [data]);
  2013. if (pvis) { ts.grid.populateVisible(); }
  2014. if( ts.p.loadonce || ts.p.treeGrid) {ts.p.datatype = "local";}
  2015. data=null;
  2016. if (npage === 1) { endReq(); }
  2017. },
  2018. error:function(xhr,st,err){
  2019. if($.isFunction(ts.p.loadError)) { ts.p.loadError.call(ts,xhr,st,err); }
  2020. if (npage === 1) { endReq(); }
  2021. xhr=null;
  2022. },
  2023. beforeSend: function(xhr, settings ){
  2024. var gotoreq = true;
  2025. if($.isFunction(ts.p.loadBeforeSend)) {
  2026. gotoreq = ts.p.loadBeforeSend.call(ts,xhr, settings);
  2027. }
  2028. if(gotoreq === undefined) { gotoreq = true; }
  2029. if(gotoreq === false) {
  2030. return false;
  2031. }
  2032. beginReq();
  2033. }
  2034. },$.jgrid.ajaxOptions, ts.p.ajaxGridOptions));
  2035. break;
  2036. case "xmlstring":
  2037. beginReq();
  2038. dstr = typeof ts.p.datastr !== 'string' ? ts.p.datastr : $.parseXML(ts.p.datastr);
  2039. addXmlData(dstr,ts.grid.bDiv);
  2040. $(ts).triggerHandler("jqGridLoadComplete", [dstr]);
  2041. if(lcf) {ts.p.loadComplete.call(ts,dstr);}
  2042. $(ts).triggerHandler("jqGridAfterLoadComplete", [dstr]);
  2043. ts.p.datatype = "local";
  2044. ts.p.datastr = null;
  2045. endReq();
  2046. break;
  2047. case "jsonstring":
  2048. beginReq();
  2049. if(typeof ts.p.datastr === 'string') { dstr = $.jgrid.parse(ts.p.datastr); }
  2050. else { dstr = ts.p.datastr; }
  2051. addJSONData(dstr,ts.grid.bDiv);
  2052. $(ts).triggerHandler("jqGridLoadComplete", [dstr]);
  2053. if(lcf) {ts.p.loadComplete.call(ts,dstr);}
  2054. $(ts).triggerHandler("jqGridAfterLoadComplete", [dstr]);
  2055. ts.p.datatype = "local";
  2056. ts.p.datastr = null;
  2057. endReq();
  2058. break;
  2059. case "local":
  2060. case "clientside":
  2061. beginReq();
  2062. ts.p.datatype = "local";
  2063. var req = addLocalData();
  2064. addJSONData(req,ts.grid.bDiv,rcnt,npage>1,adjust);
  2065. $(ts).triggerHandler("jqGridLoadComplete", [req]);
  2066. if(lc) { lc.call(ts,req); }
  2067. $(ts).triggerHandler("jqGridAfterLoadComplete", [req]);
  2068. if (pvis) { ts.grid.populateVisible(); }
  2069. endReq();
  2070. break;
  2071. }
  2072. }
  2073. },
  2074. setHeadCheckBox = function ( checked ) {
  2075. $('#cb_'+$.jgrid.jqID(ts.p.id),ts.grid.hDiv)[ts.p.useProp ? 'prop': 'attr']("checked", checked);
  2076. var fid = ts.p.frozenColumns ? ts.p.id+"_frozen" : "";
  2077. if(fid) {
  2078. $('#cb_'+$.jgrid.jqID(ts.p.id),ts.grid.fhDiv)[ts.p.useProp ? 'prop': 'attr']("checked", checked);
  2079. }
  2080. },
  2081. setPager = function (pgid, tp){
  2082. // TBD - consider escaping pgid with pgid = $.jgrid.jqID(pgid);
  2083. var sep = "<td class='ui-pg-button ui-state-disabled' style='width:4px;'><span class='ui-separator'></span></td>",
  2084. pginp = "",
  2085. pgl="<table cellspacing='0' cellpadding='0' border='0' style='table-layout:auto;' class='ui-pg-table'><tbody><tr>",
  2086. str="", pgcnt, lft, cent, rgt, twd, tdw, i,
  2087. clearVals = function(onpaging){
  2088. var ret;
  2089. if ($.isFunction(ts.p.onPaging) ) { ret = ts.p.onPaging.call(ts,onpaging); }
  2090. if(ret==='stop') {return false;}
  2091. ts.p.selrow = null;
  2092. if(ts.p.multiselect) {ts.p.selarrrow =[]; setHeadCheckBox( false );}
  2093. ts.p.savedRow = [];
  2094. return true;
  2095. };
  2096. pgid = pgid.substr(1);
  2097. tp += "_" + pgid;
  2098. pgcnt = "pg_"+pgid;
  2099. lft = pgid+"_left"; cent = pgid+"_center"; rgt = pgid+"_right";
  2100. $("#"+$.jgrid.jqID(pgid) )
  2101. .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>")
  2102. .attr("dir","ltr"); //explicit setting
  2103. if(ts.p.rowList.length >0){
  2104. str = "<td dir='"+dir+"'>";
  2105. str +="<select class='ui-pg-selbox' role='listbox'>";
  2106. for(i=0;i<ts.p.rowList.length;i++){
  2107. str +="<option role=\"option\" value=\""+ts.p.rowList[i]+"\""+((ts.p.rowNum === ts.p.rowList[i])?" selected=\"selected\"":"")+">"+ts.p.rowList[i]+"</option>";
  2108. }
  2109. str +="</select></td>";
  2110. }
  2111. if(dir==="rtl") { pgl += str; }
  2112. 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>";}
  2113. if(ts.p.pgbuttons===true) {
  2114. var po=["first"+tp,"prev"+tp, "next"+tp,"last"+tp]; if(dir==="rtl") { po.reverse(); }
  2115. pgl += "<td id='"+po[0]+"' class='ui-pg-button ui-corner-all'><span class='ui-icon ui-icon-seek-first'></span></td>";
  2116. pgl += "<td id='"+po[1]+"' class='ui-pg-button ui-corner-all'><span class='ui-icon ui-icon-seek-prev'></span></td>";
  2117. pgl += pginp !== "" ? sep+pginp+sep:"";
  2118. pgl += "<td id='"+po[2]+"' class='ui-pg-button ui-corner-all'><span class='ui-icon ui-icon-seek-next'></span></td>";
  2119. pgl += "<td id='"+po[3]+"' class='ui-pg-button ui-corner-all'><span class='ui-icon ui-icon-seek-end'></span></td>";
  2120. } else if (pginp !== "") { pgl += pginp; }
  2121. if(dir==="ltr") { pgl += str; }
  2122. pgl += "</tr></tbody></table>";
  2123. 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>");}
  2124. $("td#"+pgid+"_"+ts.p.pagerpos,"#"+pgcnt).append(pgl);
  2125. tdw = $(".ui-jqgrid").css("font-size") || "11px";
  2126. $(document.body).append("<div id='testpg' class='ui-jqgrid ui-widget ui-widget-content' style='font-size:"+tdw+";visibility:hidden;' ></div>");
  2127. twd = $(pgl).clone().appendTo("#testpg").width();
  2128. $("#testpg").remove();
  2129. if(twd > 0) {
  2130. if(pginp !== "") { twd += 50; } //should be param
  2131. $("td#"+pgid+"_"+ts.p.pagerpos,"#"+pgcnt).width(twd);
  2132. }
  2133. ts.p._nvtd = [];
  2134. ts.p._nvtd[0] = twd ? Math.floor((ts.p.width - twd)/2) : Math.floor(ts.p.width/3);
  2135. ts.p._nvtd[1] = 0;
  2136. pgl=null;
  2137. $('.ui-pg-selbox',"#"+pgcnt).bind('change',function() {
  2138. if(!clearVals('records')) { return false; }
  2139. ts.p.page = Math.round(ts.p.rowNum*(ts.p.page-1)/this.value-0.5)+1;
  2140. ts.p.rowNum = this.value;
  2141. if(ts.p.pager) { $('.ui-pg-selbox',ts.p.pager).val(this.value); }
  2142. if(ts.p.toppager) { $('.ui-pg-selbox',ts.p.toppager).val(this.value); }
  2143. populate();
  2144. return false;
  2145. });
  2146. if(ts.p.pgbuttons===true) {
  2147. $(".ui-pg-button","#"+pgcnt).hover(function(){
  2148. if($(this).hasClass('ui-state-disabled')) {
  2149. this.style.cursor='default';
  2150. } else {
  2151. $(this).addClass('ui-state-hover');
  2152. this.style.cursor='pointer';
  2153. }
  2154. },function() {
  2155. if(!$(this).hasClass('ui-state-disabled')) {
  2156. $(this).removeClass('ui-state-hover');
  2157. this.style.cursor= "default";
  2158. }
  2159. });
  2160. $("#first"+$.jgrid.jqID(tp)+", #prev"+$.jgrid.jqID(tp)+", #next"+$.jgrid.jqID(tp)+", #last"+$.jgrid.jqID(tp)).click( function() {
  2161. if ($(this).hasClass("ui-state-disabled")) {
  2162. return false;
  2163. }
  2164. var cp = intNum(ts.p.page,1),
  2165. last = intNum(ts.p.lastpage,1), selclick = false,
  2166. fp=true, pp=true, np=true,lp=true;
  2167. if(last ===0 || last===1) {fp=false;pp=false;np=false;lp=false; }
  2168. else if( last>1 && cp >=1) {
  2169. if( cp === 1) { fp=false; pp=false; }
  2170. //else if( cp>1 && cp <last){ }
  2171. else if( cp===last){ np=false;lp=false; }
  2172. } else if( last>1 && cp===0 ) { np=false;lp=false; cp=last-1;}
  2173. if(!clearVals(this.id)) { return false; }
  2174. if( this.id === 'first'+tp && fp ) { ts.p.page=1; selclick=true;}
  2175. if( this.id === 'prev'+tp && pp) { ts.p.page=(cp-1); selclick=true;}
  2176. if( this.id === 'next'+tp && np) { ts.p.page=(cp+1); selclick=true;}
  2177. if( this.id === 'last'+tp && lp) { ts.p.page=last; selclick=true;}
  2178. if(selclick) {
  2179. populate();
  2180. }
  2181. return false;
  2182. });
  2183. }
  2184. if(ts.p.pginput===true) {
  2185. $('input.ui-pg-input',"#"+pgcnt).keypress( function(e) {
  2186. var key = e.charCode || e.keyCode || 0;
  2187. if(key === 13) {
  2188. if(!clearVals('user')) { return false; }
  2189. $(this).val( intNum( $(this).val(), 1));
  2190. ts.p.page = ($(this).val()>0) ? $(this).val():ts.p.page;
  2191. populate();
  2192. return false;
  2193. }
  2194. return this;
  2195. });
  2196. }
  2197. },
  2198. multiSort = function(iCol, obj ) {
  2199. var splas, sort="", cm = ts.p.colModel, fs=false, ls,
  2200. selTh = ts.p.frozenColumns ? obj : ts.grid.headers[iCol].el, so="";
  2201. $("span.ui-grid-ico-sort",selTh).addClass('ui-state-disabled');
  2202. $(selTh).attr("aria-selected","false");
  2203. if(cm[iCol].lso) {
  2204. if(cm[iCol].lso==="asc") {
  2205. cm[iCol].lso += "-desc";
  2206. so = "desc";
  2207. } else if(cm[iCol].lso==="desc") {
  2208. cm[iCol].lso += "-asc";
  2209. so = "asc";
  2210. } else if(cm[iCol].lso==="asc-desc" || cm[iCol].lso==="desc-asc") {
  2211. cm[iCol].lso="";
  2212. }
  2213. } else {
  2214. cm[iCol].lso = so = cm[iCol].firstsortorder || 'asc';
  2215. }
  2216. if( so ) {
  2217. $("span.s-ico",selTh).show();
  2218. $("span.ui-icon-"+so,selTh).removeClass('ui-state-disabled');
  2219. $(selTh).attr("aria-selected","true");
  2220. } else {
  2221. if(!ts.p.viewsortcols[0]) {
  2222. $("span.s-ico",selTh).hide();
  2223. }
  2224. }
  2225. ts.p.sortorder = "";
  2226. $.each(cm, function(i){
  2227. if(this.lso) {
  2228. if(i>0 && fs) {
  2229. sort += ", ";
  2230. }
  2231. splas = this.lso.split("-");
  2232. sort += cm[i].index || cm[i].name;
  2233. sort += " "+splas[splas.length-1];
  2234. fs = true;
  2235. ts.p.sortorder = splas[splas.length-1];
  2236. }
  2237. });
  2238. ls = sort.lastIndexOf(ts.p.sortorder);
  2239. sort = sort.substring(0, ls);
  2240. ts.p.sortname = sort;
  2241. },
  2242. sortData = function (index, idxcol,reload,sor, obj){
  2243. if(!ts.p.colModel[idxcol].sortable) { return; }
  2244. if(ts.p.savedRow.length > 0) {return;}
  2245. if(!reload) {
  2246. if( ts.p.lastsort === idxcol ) {
  2247. if( ts.p.sortorder === 'asc') {
  2248. ts.p.sortorder = 'desc';
  2249. } else if(ts.p.sortorder === 'desc') { ts.p.sortorder = 'asc';}
  2250. } else { ts.p.sortorder = ts.p.colModel[idxcol].firstsortorder || 'asc'; }
  2251. ts.p.page = 1;
  2252. }
  2253. if(ts.p.multiSort) {
  2254. multiSort( idxcol, obj);
  2255. } else {
  2256. if(sor) {
  2257. if(ts.p.lastsort === idxcol && ts.p.sortorder === sor && !reload) { return; }
  2258. ts.p.sortorder = sor;
  2259. }
  2260. var previousSelectedTh = ts.grid.headers[ts.p.lastsort].el, newSelectedTh = ts.p.frozenColumns ? obj : ts.grid.headers[idxcol].el;
  2261. $("span.ui-grid-ico-sort",previousSelectedTh).addClass('ui-state-disabled');
  2262. $(previousSelectedTh).attr("aria-selected","false");
  2263. if(ts.p.frozenColumns) {
  2264. ts.grid.fhDiv.find("span.ui-grid-ico-sort").addClass('ui-state-disabled');
  2265. ts.grid.fhDiv.find("th").attr("aria-selected","false");
  2266. }
  2267. $("span.ui-icon-"+ts.p.sortorder,newSelectedTh).removeClass('ui-state-disabled');
  2268. $(newSelectedTh).attr("aria-selected","true");
  2269. if(!ts.p.viewsortcols[0]) {
  2270. if(ts.p.lastsort !== idxcol) {
  2271. if(ts.p.frozenColumns){
  2272. ts.grid.fhDiv.find("span.s-ico").hide();
  2273. }
  2274. $("span.s-ico",previousSelectedTh).hide();
  2275. $("span.s-ico",newSelectedTh).show();
  2276. }
  2277. }
  2278. index = index.substring(5 + ts.p.id.length + 1); // bad to be changed!?!
  2279. ts.p.sortname = ts.p.colModel[idxcol].index || index;
  2280. }
  2281. if ($(ts).triggerHandler("jqGridSortCol", [ts.p.sortname, idxcol, ts.p.sortorder]) === 'stop') {
  2282. ts.p.lastsort = idxcol;
  2283. return;
  2284. }
  2285. if($.isFunction(ts.p.onSortCol)) {if (ts.p.onSortCol.call(ts, ts.p.sortname, idxcol, ts.p.sortorder)==='stop') {ts.p.lastsort = idxcol; return;}}
  2286. if(ts.p.datatype === "local") {
  2287. if(ts.p.deselectAfterSort) {$(ts).jqGrid("resetSelection");}
  2288. } else {
  2289. ts.p.selrow = null;
  2290. if(ts.p.multiselect){setHeadCheckBox( false );}
  2291. ts.p.selarrrow =[];
  2292. ts.p.savedRow =[];
  2293. }
  2294. if(ts.p.scroll) {
  2295. var sscroll = ts.grid.bDiv.scrollLeft;
  2296. emptyRows.call(ts, true, false);
  2297. ts.grid.hDiv.scrollLeft = sscroll;
  2298. }
  2299. if(ts.p.subGrid && ts.p.datatype === 'local') {
  2300. $("td.sgexpanded","#"+$.jgrid.jqID(ts.p.id)).each(function(){
  2301. $(this).trigger("click");
  2302. });
  2303. }
  2304. populate();
  2305. ts.p.lastsort = idxcol;
  2306. if(ts.p.sortname !== index && idxcol) {ts.p.lastsort = idxcol;}
  2307. },
  2308. setColWidth = function () {
  2309. var initwidth = 0, brd=$.jgrid.cell_width? 0: intNum(ts.p.cellLayout,0), vc=0, lvc, scw=intNum(ts.p.scrollOffset,0),cw,hs=false,aw,gw=0,cr;
  2310. $.each(ts.p.colModel, function() {
  2311. if(this.hidden === undefined) {this.hidden=false;}
  2312. if(ts.p.grouping && ts.p.autowidth) {
  2313. var ind = $.inArray(this.name, ts.p.groupingView.groupField);
  2314. if(ind >= 0 && ts.p.groupingView.groupColumnShow.length > ind) {
  2315. this.hidden = !ts.p.groupingView.groupColumnShow[ind];
  2316. }
  2317. }
  2318. this.widthOrg = cw = intNum(this.width,0);
  2319. if(this.hidden===false){
  2320. initwidth += cw+brd;
  2321. if(this.fixed) {
  2322. gw += cw+brd;
  2323. } else {
  2324. vc++;
  2325. }
  2326. }
  2327. });
  2328. if(isNaN(ts.p.width)) {
  2329. ts.p.width = initwidth + ((ts.p.shrinkToFit ===false && !isNaN(ts.p.height)) ? scw : 0);
  2330. }
  2331. grid.width = ts.p.width;
  2332. ts.p.tblwidth = initwidth;
  2333. if(ts.p.shrinkToFit ===false && ts.p.forceFit === true) {ts.p.forceFit=false;}
  2334. if(ts.p.shrinkToFit===true && vc > 0) {
  2335. aw = grid.width-brd*vc-gw;
  2336. if(!isNaN(ts.p.height)) {
  2337. aw -= scw;
  2338. hs = true;
  2339. }
  2340. initwidth =0;
  2341. $.each(ts.p.colModel, function(i) {
  2342. if(this.hidden === false && !this.fixed){
  2343. cw = Math.round(aw*this.width/(ts.p.tblwidth-brd*vc-gw));
  2344. this.width =cw;
  2345. initwidth += cw;
  2346. lvc = i;
  2347. }
  2348. });
  2349. cr =0;
  2350. if (hs) {
  2351. if(grid.width-gw-(initwidth+brd*vc) !== scw){
  2352. cr = grid.width-gw-(initwidth+brd*vc)-scw;
  2353. }
  2354. } else if(!hs && Math.abs(grid.width-gw-(initwidth+brd*vc)) !== 1) {
  2355. cr = grid.width-gw-(initwidth+brd*vc);
  2356. }
  2357. ts.p.colModel[lvc].width += cr;
  2358. ts.p.tblwidth = initwidth+cr+brd*vc+gw;
  2359. if(ts.p.tblwidth > ts.p.width) {
  2360. ts.p.colModel[lvc].width -= (ts.p.tblwidth - parseInt(ts.p.width,10));
  2361. ts.p.tblwidth = ts.p.width;
  2362. }
  2363. }
  2364. },
  2365. nextVisible= function(iCol) {
  2366. var ret = iCol, j=iCol, i;
  2367. for (i = iCol+1;i<ts.p.colModel.length;i++){
  2368. if(ts.p.colModel[i].hidden !== true ) {
  2369. j=i; break;
  2370. }
  2371. }
  2372. return j-ret;
  2373. },
  2374. getOffset = function (iCol) {
  2375. var $th = $(ts.grid.headers[iCol].el), ret = [$th.position().left + $th.outerWidth()];
  2376. if(ts.p.direction==="rtl") { ret[0] = ts.p.width - ret[0]; }
  2377. ret[0] -= ts.grid.bDiv.scrollLeft;
  2378. ret.push($(ts.grid.hDiv).position().top);
  2379. ret.push($(ts.grid.bDiv).offset().top - $(ts.grid.hDiv).offset().top + $(ts.grid.bDiv).height());
  2380. return ret;
  2381. },
  2382. getColumnHeaderIndex = function (th) {
  2383. var i, headers = ts.grid.headers, ci = $.jgrid.getCellIndex(th);
  2384. for (i = 0; i < headers.length; i++) {
  2385. if (th === headers[i].el) {
  2386. ci = i;
  2387. break;
  2388. }
  2389. }
  2390. return ci;
  2391. };
  2392. this.p.id = this.id;
  2393. if ($.inArray(ts.p.multikey,sortkeys) === -1 ) {ts.p.multikey = false;}
  2394. ts.p.keyIndex=false;
  2395. ts.p.keyName=false;
  2396. for (i=0; i<ts.p.colModel.length;i++) {
  2397. ts.p.colModel[i] = $.extend(true, {}, ts.p.cmTemplate, ts.p.colModel[i].template || {}, ts.p.colModel[i]);
  2398. if (ts.p.keyIndex === false && ts.p.colModel[i].key===true) {
  2399. ts.p.keyIndex = i;
  2400. }
  2401. }
  2402. ts.p.sortorder = ts.p.sortorder.toLowerCase();
  2403. $.jgrid.cell_width = $.jgrid.cellWidth();
  2404. if(ts.p.grouping===true) {
  2405. ts.p.scroll = false;
  2406. ts.p.rownumbers = false;
  2407. //ts.p.subGrid = false; expiremental
  2408. ts.p.treeGrid = false;
  2409. ts.p.gridview = true;
  2410. }
  2411. if(this.p.treeGrid === true) {
  2412. try { $(this).jqGrid("setTreeGrid");} catch (_) {}
  2413. if(ts.p.datatype !== "local") { ts.p.localReader = {id: "_id_"}; }
  2414. }
  2415. if(this.p.subGrid) {
  2416. try { $(ts).jqGrid("setSubGrid");} catch (s){}
  2417. }
  2418. if(this.p.multiselect) {
  2419. this.p.colNames.unshift("<input role='checkbox' id='cb_"+this.p.id+"' class='cbox' type='checkbox'/>");
  2420. 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});
  2421. }
  2422. if(this.p.rownumbers) {
  2423. this.p.colNames.unshift("");
  2424. this.p.colModel.unshift({name:'rn',width:ts.p.rownumWidth,sortable:false,resizable:false,hidedlg:true,search:false,align:'center',fixed:true});
  2425. }
  2426. ts.p.xmlReader = $.extend(true,{
  2427. root: "rows",
  2428. row: "row",
  2429. page: "rows>page",
  2430. total: "rows>total",
  2431. records : "rows>records",
  2432. repeatitems: true,
  2433. cell: "cell",
  2434. id: "[id]",
  2435. userdata: "userdata",
  2436. subgrid: {root:"rows", row: "row", repeatitems: true, cell:"cell"}
  2437. }, ts.p.xmlReader);
  2438. ts.p.jsonReader = $.extend(true,{
  2439. root: "rows",
  2440. page: "page",
  2441. total: "total",
  2442. records: "records",
  2443. repeatitems: true,
  2444. cell: "cell",
  2445. id: "id",
  2446. userdata: "userdata",
  2447. subgrid: {root:"rows", repeatitems: true, cell:"cell"}
  2448. },ts.p.jsonReader);
  2449. ts.p.localReader = $.extend(true,{
  2450. root: "rows",
  2451. page: "page",
  2452. total: "total",
  2453. records: "records",
  2454. repeatitems: false,
  2455. cell: "cell",
  2456. id: "id",
  2457. userdata: "userdata",
  2458. subgrid: {root:"rows", repeatitems: true, cell:"cell"}
  2459. },ts.p.localReader);
  2460. if(ts.p.scroll){
  2461. ts.p.pgbuttons = false; ts.p.pginput=false; ts.p.rowList=[];
  2462. }
  2463. if(ts.p.data.length) { refreshIndex(); }
  2464. var thead = "<thead><tr class='ui-jqgrid-labels' role='rowheader'>",
  2465. tdc, idn, w, res, sort,
  2466. td, ptr, tbody, imgs,iac="",idc="",sortarr=[], sortord=[], sotmp=[];
  2467. if(ts.p.shrinkToFit===true && ts.p.forceFit===true) {
  2468. for (i=ts.p.colModel.length-1;i>=0;i--){
  2469. if(!ts.p.colModel[i].hidden) {
  2470. ts.p.colModel[i].resizable=false;
  2471. break;
  2472. }
  2473. }
  2474. }
  2475. if(ts.p.viewsortcols[1] === 'horizontal') {iac=" ui-i-asc";idc=" ui-i-desc";}
  2476. tdc = isMSIE ? "class='ui-th-div-ie'" :"";
  2477. 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>";
  2478. 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>";
  2479. if(ts.p.multiSort) {
  2480. sortarr = ts.p.sortname.split(",");
  2481. for (i=0; i<sortarr.length; i++) {
  2482. sotmp = $.trim(sortarr[i]).split(" ");
  2483. sortarr[i] = $.trim(sotmp[0]);
  2484. sortord[i] = sotmp[1] ? $.trim(sotmp[1]) : ts.p.sortorder || "asc";
  2485. }
  2486. }
  2487. for(i=0;i<this.p.colNames.length;i++){
  2488. var tooltip = ts.p.headertitles ? (" title=\""+$.jgrid.stripHtml(ts.p.colNames[i])+"\"") :"";
  2489. thead += "<th id='"+ts.p.id+"_"+ts.p.colModel[i].name+"' role='columnheader' class='ui-state-default ui-th-column ui-th-"+dir+"'"+ tooltip+">";
  2490. idn = ts.p.colModel[i].index || ts.p.colModel[i].name;
  2491. thead += "<div id='jqgh_"+ts.p.id+"_"+ts.p.colModel[i].name+"' "+tdc+">"+ts.p.colNames[i];
  2492. if(!ts.p.colModel[i].width) { ts.p.colModel[i].width = 150; }
  2493. else { ts.p.colModel[i].width = parseInt(ts.p.colModel[i].width,10); }
  2494. if(typeof ts.p.colModel[i].title !== "boolean") { ts.p.colModel[i].title = true; }
  2495. ts.p.colModel[i].lso = "";
  2496. if (idn === ts.p.sortname) {
  2497. ts.p.lastsort = i;
  2498. }
  2499. if(ts.p.multiSort) {
  2500. sotmp = $.inArray(idn,sortarr);
  2501. if( sotmp !== -1 ) {
  2502. ts.p.colModel[i].lso = sortord[sotmp];
  2503. }
  2504. }
  2505. thead += imgs+"</div></th>";
  2506. }
  2507. thead += "</tr></thead>";
  2508. imgs = null;
  2509. $(this).append(thead);
  2510. $("thead tr:first th",this).hover(function(){$(this).addClass('ui-state-hover');},function(){$(this).removeClass('ui-state-hover');});
  2511. if(this.p.multiselect) {
  2512. var emp=[], chk;
  2513. $('#cb_'+$.jgrid.jqID(ts.p.id),this).bind('click',function(){
  2514. ts.p.selarrrow = [];
  2515. var froz = ts.p.frozenColumns === true ? ts.p.id + "_frozen" : "";
  2516. if (this.checked) {
  2517. $(ts.rows).each(function(i) {
  2518. if (i>0) {
  2519. if(!$(this).hasClass("ui-subgrid") && !$(this).hasClass("jqgroup") && !$(this).hasClass('ui-state-disabled')){
  2520. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id) )[ts.p.useProp ? 'prop': 'attr']("checked",true);
  2521. $(this).addClass("ui-state-highlight").attr("aria-selected","true");
  2522. ts.p.selarrrow.push(this.id);
  2523. ts.p.selrow = this.id;
  2524. if(froz) {
  2525. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id), ts.grid.fbDiv )[ts.p.useProp ? 'prop': 'attr']("checked",true);
  2526. $("#"+$.jgrid.jqID(this.id), ts.grid.fbDiv).addClass("ui-state-highlight");
  2527. }
  2528. }
  2529. }
  2530. });
  2531. chk=true;
  2532. emp=[];
  2533. }
  2534. else {
  2535. $(ts.rows).each(function(i) {
  2536. if(i>0) {
  2537. if(!$(this).hasClass("ui-subgrid") && !$(this).hasClass('ui-state-disabled')){
  2538. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id) )[ts.p.useProp ? 'prop': 'attr']("checked", false);
  2539. $(this).removeClass("ui-state-highlight").attr("aria-selected","false");
  2540. emp.push(this.id);
  2541. if(froz) {
  2542. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id), ts.grid.fbDiv )[ts.p.useProp ? 'prop': 'attr']("checked",false);
  2543. $("#"+$.jgrid.jqID(this.id), ts.grid.fbDiv).removeClass("ui-state-highlight");
  2544. }
  2545. }
  2546. }
  2547. });
  2548. ts.p.selrow = null;
  2549. chk=false;
  2550. }
  2551. $(ts).triggerHandler("jqGridSelectAll", [chk ? ts.p.selarrrow : emp, chk]);
  2552. if($.isFunction(ts.p.onSelectAll)) {ts.p.onSelectAll.call(ts, chk ? ts.p.selarrrow : emp,chk);}
  2553. });
  2554. }
  2555. if(ts.p.autowidth===true) {
  2556. var pw = $(eg).innerWidth();
  2557. ts.p.width = pw > 0? pw: 'nw';
  2558. }
  2559. setColWidth();
  2560. $(eg).css("width",grid.width+"px").append("<div class='ui-jqgrid-resize-mark' id='rs_m"+ts.p.id+"'>&#160;</div>");
  2561. $(gv).css("width",grid.width+"px");
  2562. thead = $("thead:first",ts).get(0);
  2563. var tfoot = "";
  2564. 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+"'>"; }
  2565. var thr = $("tr:first",thead),
  2566. firstr = "<tr class='jqgfirstrow' role='row' style='height:auto'>";
  2567. ts.p.disableClick=false;
  2568. $("th",thr).each(function ( j ) {
  2569. w = ts.p.colModel[j].width;
  2570. if(ts.p.colModel[j].resizable === undefined) {ts.p.colModel[j].resizable = true;}
  2571. if(ts.p.colModel[j].resizable){
  2572. res = document.createElement("span");
  2573. $(res).html("&#160;").addClass('ui-jqgrid-resize ui-jqgrid-resize-'+dir)
  2574. .css("cursor","col-resize");
  2575. $(this).addClass(ts.p.resizeclass);
  2576. } else {
  2577. res = "";
  2578. }
  2579. $(this).css("width",w+"px").prepend(res);
  2580. res = null;
  2581. var hdcol = "";
  2582. if( ts.p.colModel[j].hidden ) {
  2583. $(this).css("display","none");
  2584. hdcol = "display:none;";
  2585. }
  2586. firstr += "<td role='gridcell' style='height:0px;width:"+w+"px;"+hdcol+"'></td>";
  2587. grid.headers[j] = { width: w, el: this };
  2588. sort = ts.p.colModel[j].sortable;
  2589. if( typeof sort !== 'boolean') {ts.p.colModel[j].sortable = true; sort=true;}
  2590. var nm = ts.p.colModel[j].name;
  2591. if( !(nm === 'cb' || nm==='subgrid' || nm==='rn') ) {
  2592. if(ts.p.viewsortcols[2]){
  2593. $(">div",this).addClass('ui-jqgrid-sortable');
  2594. }
  2595. }
  2596. if(sort) {
  2597. if(ts.p.multiSort) {
  2598. if(ts.p.viewsortcols[0]) {
  2599. $("div span.s-ico",this).show();
  2600. if(ts.p.colModel[j].lso){
  2601. $("div span.ui-icon-"+ts.p.colModel[j].lso,this).removeClass("ui-state-disabled");
  2602. }
  2603. } else if( ts.p.colModel[j].lso) {
  2604. $("div span.s-ico",this).show();
  2605. $("div span.ui-icon-"+ts.p.colModel[j].lso,this).removeClass("ui-state-disabled");
  2606. }
  2607. } else {
  2608. 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");}}
  2609. else if( j === ts.p.lastsort) {$("div span.s-ico",this).show();$("div span.ui-icon-"+ts.p.sortorder,this).removeClass("ui-state-disabled");}
  2610. }
  2611. }
  2612. if(ts.p.footerrow) { tfoot += "<td role='gridcell' "+formatCol(j,0,'', null, '', false)+">&#160;</td>"; }
  2613. }).mousedown(function(e) {
  2614. if ($(e.target).closest("th>span.ui-jqgrid-resize").length !== 1) { return; }
  2615. var ci = getColumnHeaderIndex(this);
  2616. if(ts.p.forceFit===true) {ts.p.nv= nextVisible(ci);}
  2617. grid.dragStart(ci, e, getOffset(ci));
  2618. return false;
  2619. }).click(function(e) {
  2620. if (ts.p.disableClick) {
  2621. ts.p.disableClick = false;
  2622. return false;
  2623. }
  2624. var s = "th>div.ui-jqgrid-sortable",r,d;
  2625. if (!ts.p.viewsortcols[2]) { s = "th>div>span>span.ui-grid-ico-sort"; }
  2626. var t = $(e.target).closest(s);
  2627. if (t.length !== 1) { return; }
  2628. var ci;
  2629. if(ts.p.frozenColumns) {
  2630. var tid = $(this)[0].id.substring( ts.p.id.length + 1 );
  2631. $(ts.p.colModel).each(function(i){
  2632. if (this.name === tid) {
  2633. ci = i;return false;
  2634. }
  2635. });
  2636. } else {
  2637. ci = getColumnHeaderIndex(this);
  2638. }
  2639. if (!ts.p.viewsortcols[2]) { r=true;d=t.attr("sort"); }
  2640. if(ci != null){
  2641. sortData( $('div',this)[0].id, ci, r, d, this);
  2642. }
  2643. return false;
  2644. });
  2645. if (ts.p.sortable && $.fn.sortable) {
  2646. try {
  2647. $(ts).jqGrid("sortableColumns", thr);
  2648. } catch (e){}
  2649. }
  2650. if(ts.p.footerrow) { tfoot += "</tr></tbody></table>"; }
  2651. firstr += "</tr>";
  2652. tbody = document.createElement("tbody");
  2653. this.appendChild(tbody);
  2654. $(this).addClass('ui-jqgrid-btable').append(firstr);
  2655. firstr = null;
  2656. 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),
  2657. hg = (ts.p.caption && ts.p.hiddengrid===true) ? true : false,
  2658. hb = $("<div class='ui-jqgrid-hbox" + (dir==="rtl" ? "-rtl" : "" )+"'></div>");
  2659. thead = null;
  2660. grid.hDiv = document.createElement("div");
  2661. $(grid.hDiv)
  2662. .css({ width: grid.width+"px"})
  2663. .addClass("ui-state-default ui-jqgrid-hdiv")
  2664. .append(hb);
  2665. $(hb).append(hTable);
  2666. hTable = null;
  2667. if(hg) { $(grid.hDiv).hide(); }
  2668. if(ts.p.pager){
  2669. // TBD -- escape ts.p.pager here?
  2670. if(typeof ts.p.pager === "string") {if(ts.p.pager.substr(0,1) !== "#") { ts.p.pager = "#"+ts.p.pager;} }
  2671. else { ts.p.pager = "#"+ $(ts.p.pager).attr("id");}
  2672. $(ts.p.pager).css({width: grid.width+"px"}).addClass('ui-state-default ui-jqgrid-pager ui-corner-bottom').appendTo(eg);
  2673. if(hg) {$(ts.p.pager).hide();}
  2674. setPager(ts.p.pager,'');
  2675. }
  2676. if( ts.p.cellEdit === false && ts.p.hoverrows === true) {
  2677. $(ts).bind('mouseover',function(e) {
  2678. ptr = $(e.target).closest("tr.jqgrow");
  2679. if($(ptr).attr("class") !== "ui-subgrid") {
  2680. $(ptr).addClass("ui-state-hover");
  2681. }
  2682. }).bind('mouseout',function(e) {
  2683. ptr = $(e.target).closest("tr.jqgrow");
  2684. $(ptr).removeClass("ui-state-hover");
  2685. });
  2686. }
  2687. var ri,ci, tdHtml;
  2688. $(ts).before(grid.hDiv).click(function(e) {
  2689. td = e.target;
  2690. ptr = $(td,ts.rows).closest("tr.jqgrow");
  2691. 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 ) {
  2692. return this;
  2693. }
  2694. var scb = $(td).hasClass("cbox"),
  2695. cSel = $(ts).triggerHandler("jqGridBeforeSelectRow", [ptr[0].id, e]);
  2696. cSel = (cSel === false || cSel === 'stop') ? false : true;
  2697. if(cSel && $.isFunction(ts.p.beforeSelectRow)) { cSel = ts.p.beforeSelectRow.call(ts,ptr[0].id, e); }
  2698. if (td.tagName === 'A' || ((td.tagName === 'INPUT' || td.tagName === 'TEXTAREA' || td.tagName === 'OPTION' || td.tagName === 'SELECT' ) && !scb) ) { return; }
  2699. if(cSel === true) {
  2700. ri = ptr[0].id;
  2701. ci = $.jgrid.getCellIndex(td);
  2702. tdHtml = $(td).closest("td,th").html();
  2703. $(ts).triggerHandler("jqGridCellSelect", [ri,ci,tdHtml,e]);
  2704. if($.isFunction(ts.p.onCellSelect)) {
  2705. ts.p.onCellSelect.call(ts,ri,ci,tdHtml,e);
  2706. }
  2707. if(ts.p.cellEdit === true) {
  2708. if(ts.p.multiselect && scb){
  2709. $(ts).jqGrid("setSelection", ri ,true,e);
  2710. } else {
  2711. ri = ptr[0].rowIndex;
  2712. try {$(ts).jqGrid("editCell",ri,ci,true);} catch (_) {}
  2713. }
  2714. } else if ( !ts.p.multikey ) {
  2715. if(ts.p.multiselect && ts.p.multiboxonly) {
  2716. if(scb){$(ts).jqGrid("setSelection",ri,true,e);}
  2717. else {
  2718. var frz = ts.p.frozenColumns ? ts.p.id+"_frozen" : "";
  2719. $(ts.p.selarrrow).each(function(i,n){
  2720. var trid = $(ts).jqGrid('getGridRowById',n);
  2721. $( trid ).removeClass("ui-state-highlight");
  2722. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(n))[ts.p.useProp ? 'prop': 'attr']("checked", false);
  2723. if(frz) {
  2724. $("#"+$.jgrid.jqID(n), "#"+$.jgrid.jqID(frz)).removeClass("ui-state-highlight");
  2725. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(n), "#"+$.jgrid.jqID(frz))[ts.p.useProp ? 'prop': 'attr']("checked", false);
  2726. }
  2727. });
  2728. ts.p.selarrrow = [];
  2729. $(ts).jqGrid("setSelection",ri,true,e);
  2730. }
  2731. } else {
  2732. $(ts).jqGrid("setSelection",ri,true,e);
  2733. }
  2734. } else {
  2735. if(e[ts.p.multikey]) {
  2736. $(ts).jqGrid("setSelection",ri,true,e);
  2737. } else if(ts.p.multiselect && scb) {
  2738. scb = $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+ri).is(":checked");
  2739. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+ri)[ts.p.useProp ? 'prop' : 'attr']("checked", scb);
  2740. }
  2741. }
  2742. }
  2743. }).bind('reloadGrid', function(e,opts) {
  2744. if(ts.p.treeGrid ===true) { ts.p.datatype = ts.p.treedatatype;}
  2745. if (opts && opts.current) {
  2746. ts.grid.selectionPreserver(ts);
  2747. }
  2748. if(ts.p.datatype==="local"){ $(ts).jqGrid("resetSelection"); if(ts.p.data.length) { refreshIndex();} }
  2749. else if(!ts.p.treeGrid) {
  2750. ts.p.selrow=null;
  2751. if(ts.p.multiselect) {ts.p.selarrrow =[];setHeadCheckBox(false);}
  2752. ts.p.savedRow = [];
  2753. }
  2754. if(ts.p.scroll) {emptyRows.call(ts, true, false);}
  2755. if (opts && opts.page) {
  2756. var page = opts.page;
  2757. if (page > ts.p.lastpage) { page = ts.p.lastpage; }
  2758. if (page < 1) { page = 1; }
  2759. ts.p.page = page;
  2760. if (ts.grid.prevRowHeight) {
  2761. ts.grid.bDiv.scrollTop = (page - 1) * ts.grid.prevRowHeight * ts.p.rowNum;
  2762. } else {
  2763. ts.grid.bDiv.scrollTop = 0;
  2764. }
  2765. }
  2766. if (ts.grid.prevRowHeight && ts.p.scroll) {
  2767. delete ts.p.lastpage;
  2768. ts.grid.populateVisible();
  2769. } else {
  2770. ts.grid.populate();
  2771. }
  2772. if(ts.p._inlinenav===true) {$(ts).jqGrid('showAddEditButtons');}
  2773. return false;
  2774. })
  2775. .dblclick(function(e) {
  2776. td = e.target;
  2777. ptr = $(td,ts.rows).closest("tr.jqgrow");
  2778. if($(ptr).length === 0 ){return;}
  2779. ri = ptr[0].rowIndex;
  2780. ci = $.jgrid.getCellIndex(td);
  2781. $(ts).triggerHandler("jqGridDblClickRow", [$(ptr).attr("id"),ri,ci,e]);
  2782. if ($.isFunction(ts.p.ondblClickRow)) { ts.p.ondblClickRow.call(ts,$(ptr).attr("id"),ri,ci, e); }
  2783. })
  2784. .bind('contextmenu', function(e) {
  2785. td = e.target;
  2786. ptr = $(td,ts.rows).closest("tr.jqgrow");
  2787. if($(ptr).length === 0 ){return;}
  2788. if(!ts.p.multiselect) { $(ts).jqGrid("setSelection",ptr[0].id,true,e); }
  2789. ri = ptr[0].rowIndex;
  2790. ci = $.jgrid.getCellIndex(td);
  2791. $(ts).triggerHandler("jqGridRightClickRow", [$(ptr).attr("id"),ri,ci,e]);
  2792. if ($.isFunction(ts.p.onRightClickRow)) { ts.p.onRightClickRow.call(ts,$(ptr).attr("id"),ri,ci, e); }
  2793. });
  2794. grid.bDiv = document.createElement("div");
  2795. if(isMSIE) { if(String(ts.p.height).toLowerCase() === "auto") { ts.p.height = "100%"; } }
  2796. $(grid.bDiv)
  2797. .append($('<div style="position:relative;'+(isMSIE && $.jgrid.msiever() < 8 ? "height:0.01%;" : "")+'"></div>').append('<div></div>').append(this))
  2798. .addClass("ui-jqgrid-bdiv")
  2799. .css({ height: ts.p.height+(isNaN(ts.p.height)?"":"px"), width: (grid.width)+"px"})
  2800. .scroll(grid.scrollGrid);
  2801. $("table:first",grid.bDiv).css({width:ts.p.tblwidth+"px"});
  2802. if( !$.support.tbody ) { //IE
  2803. if( $("tbody",this).length === 2 ) { $("tbody:gt(0)",this).remove();}
  2804. }
  2805. if(ts.p.multikey){
  2806. if( $.jgrid.msie) {
  2807. $(grid.bDiv).bind("selectstart",function(){return false;});
  2808. } else {
  2809. $(grid.bDiv).bind("mousedown",function(){return false;});
  2810. }
  2811. }
  2812. if(hg) {$(grid.bDiv).hide();}
  2813. grid.cDiv = document.createElement("div");
  2814. var arf = ts.p.hidegrid===true ? $("<a role='link' class='ui-jqgrid-titlebar-close ui-corner-all HeaderButton' />").hover(
  2815. function(){ arf.addClass('ui-state-hover');},
  2816. function() {arf.removeClass('ui-state-hover');})
  2817. .append("<span class='ui-icon ui-icon-circle-triangle-n'></span>").css((dir==="rtl"?"left":"right"),"0px") : "";
  2818. $(grid.cDiv).append(arf).append("<span class='ui-jqgrid-title'>"+ts.p.caption+"</span>")
  2819. .addClass("ui-jqgrid-titlebar ui-jqgrid-caption"+(dir==="rtl" ? "-rtl" :"" )+" ui-widget-header ui-corner-top ui-helper-clearfix");
  2820. $(grid.cDiv).insertBefore(grid.hDiv);
  2821. if( ts.p.toolbar[0] ) {
  2822. grid.uDiv = document.createElement("div");
  2823. if(ts.p.toolbar[1] === "top") {$(grid.uDiv).insertBefore(grid.hDiv);}
  2824. else if (ts.p.toolbar[1]==="bottom" ) {$(grid.uDiv).insertAfter(grid.hDiv);}
  2825. if(ts.p.toolbar[1]==="both") {
  2826. grid.ubDiv = document.createElement("div");
  2827. $(grid.uDiv).addClass("ui-userdata ui-state-default").attr("id","t_"+this.id).insertBefore(grid.hDiv);
  2828. $(grid.ubDiv).addClass("ui-userdata ui-state-default").attr("id","tb_"+this.id).insertAfter(grid.hDiv);
  2829. if(hg) {$(grid.ubDiv).hide();}
  2830. } else {
  2831. $(grid.uDiv).width(grid.width).addClass("ui-userdata ui-state-default").attr("id","t_"+this.id);
  2832. }
  2833. if(hg) {$(grid.uDiv).hide();}
  2834. }
  2835. if(ts.p.toppager) {
  2836. ts.p.toppager = $.jgrid.jqID(ts.p.id)+"_toppager";
  2837. grid.topDiv = $("<div id='"+ts.p.toppager+"'></div>")[0];
  2838. ts.p.toppager = "#"+ts.p.toppager;
  2839. $(grid.topDiv).addClass('ui-state-default ui-jqgrid-toppager').width(grid.width).insertBefore(grid.hDiv);
  2840. setPager(ts.p.toppager,'_t');
  2841. }
  2842. if(ts.p.footerrow) {
  2843. grid.sDiv = $("<div class='ui-jqgrid-sdiv'></div>")[0];
  2844. hb = $("<div class='ui-jqgrid-hbox"+(dir==="rtl"?"-rtl":"")+"'></div>");
  2845. $(grid.sDiv).append(hb).width(grid.width).insertAfter(grid.hDiv);
  2846. $(hb).append(tfoot);
  2847. grid.footers = $(".ui-jqgrid-ftable",grid.sDiv)[0].rows[0].cells;
  2848. if(ts.p.rownumbers) { grid.footers[0].className = 'ui-state-default jqgrid-rownum'; }
  2849. if(hg) {$(grid.sDiv).hide();}
  2850. }
  2851. hb = null;
  2852. if(ts.p.caption) {
  2853. var tdt = ts.p.datatype;
  2854. if(ts.p.hidegrid===true) {
  2855. $(".ui-jqgrid-titlebar-close",grid.cDiv).click( function(e){
  2856. var onHdCl = $.isFunction(ts.p.onHeaderClick),
  2857. elems = ".ui-jqgrid-bdiv, .ui-jqgrid-hdiv, .ui-jqgrid-pager, .ui-jqgrid-sdiv",
  2858. counter, self = this;
  2859. if(ts.p.toolbar[0]===true) {
  2860. if( ts.p.toolbar[1]==='both') {
  2861. elems += ', #' + $(grid.ubDiv).attr('id');
  2862. }
  2863. elems += ', #' + $(grid.uDiv).attr('id');
  2864. }
  2865. counter = $(elems,"#gview_"+$.jgrid.jqID(ts.p.id)).length;
  2866. if(ts.p.gridstate === 'visible') {
  2867. $(elems,"#gbox_"+$.jgrid.jqID(ts.p.id)).slideUp("fast", function() {
  2868. counter--;
  2869. if (counter === 0) {
  2870. $("span",self).removeClass("ui-icon-circle-triangle-n").addClass("ui-icon-circle-triangle-s");
  2871. ts.p.gridstate = 'hidden';
  2872. if($("#gbox_"+$.jgrid.jqID(ts.p.id)).hasClass("ui-resizable")) { $(".ui-resizable-handle","#gbox_"+$.jgrid.jqID(ts.p.id)).hide(); }
  2873. $(ts).triggerHandler("jqGridHeaderClick", [ts.p.gridstate,e]);
  2874. if(onHdCl) {if(!hg) {ts.p.onHeaderClick.call(ts,ts.p.gridstate,e);}}
  2875. }
  2876. });
  2877. } else if(ts.p.gridstate === 'hidden'){
  2878. $(elems,"#gbox_"+$.jgrid.jqID(ts.p.id)).slideDown("fast", function() {
  2879. counter--;
  2880. if (counter === 0) {
  2881. $("span",self).removeClass("ui-icon-circle-triangle-s").addClass("ui-icon-circle-triangle-n");
  2882. if(hg) {ts.p.datatype = tdt;populate();hg=false;}
  2883. ts.p.gridstate = 'visible';
  2884. if($("#gbox_"+$.jgrid.jqID(ts.p.id)).hasClass("ui-resizable")) { $(".ui-resizable-handle","#gbox_"+$.jgrid.jqID(ts.p.id)).show(); }
  2885. $(ts).triggerHandler("jqGridHeaderClick", [ts.p.gridstate,e]);
  2886. if(onHdCl) {if(!hg) {ts.p.onHeaderClick.call(ts,ts.p.gridstate,e);}}
  2887. }
  2888. });
  2889. }
  2890. return false;
  2891. });
  2892. if(hg) {ts.p.datatype="local"; $(".ui-jqgrid-titlebar-close",grid.cDiv).trigger("click");}
  2893. }
  2894. } else {$(grid.cDiv).hide();}
  2895. $(grid.hDiv).after(grid.bDiv)
  2896. .mousemove(function (e) {
  2897. if(grid.resizing){grid.dragMove(e);return false;}
  2898. });
  2899. $(".ui-jqgrid-labels",grid.hDiv).bind("selectstart", function () { return false; });
  2900. $(document).bind( "mouseup.jqGrid" + ts.p.id, function () {
  2901. if(grid.resizing) { grid.dragEnd(); return false;}
  2902. return true;
  2903. });
  2904. ts.formatCol = formatCol;
  2905. ts.sortData = sortData;
  2906. ts.updatepager = updatepager;
  2907. ts.refreshIndex = refreshIndex;
  2908. ts.setHeadCheckBox = setHeadCheckBox;
  2909. ts.constructTr = constructTr;
  2910. ts.formatter = function ( rowId, cellval , colpos, rwdat, act){return formatter(rowId, cellval , colpos, rwdat, act);};
  2911. $.extend(grid,{populate : populate, emptyRows: emptyRows, beginReq: beginReq, endReq: endReq});
  2912. this.grid = grid;
  2913. ts.addXmlData = function(d) {addXmlData(d,ts.grid.bDiv);};
  2914. ts.addJSONData = function(d) {addJSONData(d,ts.grid.bDiv);};
  2915. this.grid.cols = this.rows[0].cells;
  2916. $(ts).triggerHandler("jqGridInitGrid");
  2917. if ($.isFunction( ts.p.onInitGrid )) { ts.p.onInitGrid.call(ts); }
  2918. populate();ts.p.hiddengrid=false;
  2919. });
  2920. };
  2921. $.jgrid.extend({
  2922. getGridParam : function(pName) {
  2923. var $t = this[0];
  2924. if (!$t || !$t.grid) {return;}
  2925. if (!pName) { return $t.p; }
  2926. return $t.p[pName] !== undefined ? $t.p[pName] : null;
  2927. },
  2928. setGridParam : function (newParams){
  2929. return this.each(function(){
  2930. if (this.grid && typeof newParams === 'object') {$.extend(true,this.p,newParams);}
  2931. });
  2932. },
  2933. getGridRowById: function ( rowid ) {
  2934. var row;
  2935. this.each( function(){
  2936. try {
  2937. //row = this.rows.namedItem( rowid );
  2938. var i = this.rows.length;
  2939. while(i--) {
  2940. if( rowid.toString() === this.rows[i].id) {
  2941. row = this.rows[i];
  2942. break;
  2943. }
  2944. }
  2945. } catch ( e ) {
  2946. row = $(this.grid.bDiv).find( "#" + $.jgrid.jqID( rowid ));
  2947. }
  2948. });
  2949. return row;
  2950. },
  2951. getDataIDs : function () {
  2952. var ids=[], i=0, len, j=0;
  2953. this.each(function(){
  2954. len = this.rows.length;
  2955. if(len && len>0){
  2956. while(i<len) {
  2957. if($(this.rows[i]).hasClass('jqgrow')) {
  2958. ids[j] = this.rows[i].id;
  2959. j++;
  2960. }
  2961. i++;
  2962. }
  2963. }
  2964. });
  2965. return ids;
  2966. },
  2967. setSelection : function(selection,onsr, e) {
  2968. return this.each(function(){
  2969. var $t = this, stat,pt, ner, ia, tpsr, fid;
  2970. if(selection === undefined) { return; }
  2971. onsr = onsr === false ? false : true;
  2972. pt=$($t).jqGrid('getGridRowById', selection);
  2973. if(!pt || !pt.className || pt.className.indexOf( 'ui-state-disabled' ) > -1 ) { return; }
  2974. function scrGrid(iR){
  2975. var ch = $($t.grid.bDiv)[0].clientHeight,
  2976. st = $($t.grid.bDiv)[0].scrollTop,
  2977. rpos = $($t.rows[iR]).position().top,
  2978. rh = $t.rows[iR].clientHeight;
  2979. if(rpos+rh >= ch+st) { $($t.grid.bDiv)[0].scrollTop = rpos-(ch+st)+rh+st; }
  2980. else if(rpos < ch+st) {
  2981. if(rpos < st) {
  2982. $($t.grid.bDiv)[0].scrollTop = rpos;
  2983. }
  2984. }
  2985. }
  2986. if($t.p.scrollrows===true) {
  2987. ner = $($t).jqGrid('getGridRowById',selection).rowIndex;
  2988. if(ner >=0 ){
  2989. scrGrid(ner);
  2990. }
  2991. }
  2992. if($t.p.frozenColumns === true ) {
  2993. fid = $t.p.id+"_frozen";
  2994. }
  2995. if(!$t.p.multiselect) {
  2996. if(pt.className !== "ui-subgrid") {
  2997. if( $t.p.selrow !== pt.id) {
  2998. $( $($t).jqGrid('getGridRowById', $t.p.selrow) ).removeClass("ui-state-highlight").attr({"aria-selected":"false", "tabindex" : "-1"});
  2999. $(pt).addClass("ui-state-highlight").attr({"aria-selected":"true", "tabindex" : "0"});//.focus();
  3000. if(fid) {
  3001. $("#"+$.jgrid.jqID($t.p.selrow), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight");
  3002. $("#"+$.jgrid.jqID(selection), "#"+$.jgrid.jqID(fid)).addClass("ui-state-highlight");
  3003. }
  3004. stat = true;
  3005. } else {
  3006. stat = false;
  3007. }
  3008. $t.p.selrow = pt.id;
  3009. if( onsr ) {
  3010. $($t).triggerHandler("jqGridSelectRow", [pt.id, stat, e]);
  3011. if( $t.p.onSelectRow) { $t.p.onSelectRow.call($t, pt.id, stat, e); }
  3012. }
  3013. }
  3014. } else {
  3015. //unselect selectall checkbox when deselecting a specific row
  3016. $t.setHeadCheckBox( false );
  3017. $t.p.selrow = pt.id;
  3018. ia = $.inArray($t.p.selrow,$t.p.selarrrow);
  3019. if ( ia === -1 ){
  3020. if(pt.className !== "ui-subgrid") { $(pt).addClass("ui-state-highlight").attr("aria-selected","true");}
  3021. stat = true;
  3022. $t.p.selarrrow.push($t.p.selrow);
  3023. } else {
  3024. if(pt.className !== "ui-subgrid") { $(pt).removeClass("ui-state-highlight").attr("aria-selected","false");}
  3025. stat = false;
  3026. $t.p.selarrrow.splice(ia,1);
  3027. tpsr = $t.p.selarrrow[0];
  3028. $t.p.selrow = (tpsr === undefined) ? null : tpsr;
  3029. }
  3030. $("#jqg_"+$.jgrid.jqID($t.p.id)+"_"+$.jgrid.jqID(pt.id))[$t.p.useProp ? 'prop': 'attr']("checked",stat);
  3031. if(fid) {
  3032. if(ia === -1) {
  3033. $("#"+$.jgrid.jqID(selection), "#"+$.jgrid.jqID(fid)).addClass("ui-state-highlight");
  3034. } else {
  3035. $("#"+$.jgrid.jqID(selection), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight");
  3036. }
  3037. $("#jqg_"+$.jgrid.jqID($t.p.id)+"_"+$.jgrid.jqID(selection), "#"+$.jgrid.jqID(fid))[$t.p.useProp ? 'prop': 'attr']("checked",stat);
  3038. }
  3039. if( onsr ) {
  3040. $($t).triggerHandler("jqGridSelectRow", [pt.id, stat, e]);
  3041. if( $t.p.onSelectRow) { $t.p.onSelectRow.call($t, pt.id , stat, e); }
  3042. }
  3043. }
  3044. });
  3045. },
  3046. resetSelection : function( rowid ){
  3047. return this.each(function(){
  3048. var t = this, sr, fid;
  3049. if( t.p.frozenColumns === true ) {
  3050. fid = t.p.id+"_frozen";
  3051. }
  3052. if(rowid !== undefined ) {
  3053. sr = rowid === t.p.selrow ? t.p.selrow : rowid;
  3054. $("#"+$.jgrid.jqID(t.p.id)+" tbody:first tr#"+$.jgrid.jqID(sr)).removeClass("ui-state-highlight").attr("aria-selected","false");
  3055. if (fid) { $("#"+$.jgrid.jqID(sr), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight"); }
  3056. if(t.p.multiselect) {
  3057. $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(sr), "#"+$.jgrid.jqID(t.p.id))[t.p.useProp ? 'prop': 'attr']("checked",false);
  3058. if(fid) { $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(sr), "#"+$.jgrid.jqID(fid))[t.p.useProp ? 'prop': 'attr']("checked",false); }
  3059. t.setHeadCheckBox( false);
  3060. }
  3061. sr = null;
  3062. } else if(!t.p.multiselect) {
  3063. if(t.p.selrow) {
  3064. $("#"+$.jgrid.jqID(t.p.id)+" tbody:first tr#"+$.jgrid.jqID(t.p.selrow)).removeClass("ui-state-highlight").attr("aria-selected","false");
  3065. if(fid) { $("#"+$.jgrid.jqID(t.p.selrow), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight"); }
  3066. t.p.selrow = null;
  3067. }
  3068. } else {
  3069. $(t.p.selarrrow).each(function(i,n){
  3070. $( $(t).jqGrid('getGridRowById',n) ).removeClass("ui-state-highlight").attr("aria-selected","false");
  3071. $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(n))[t.p.useProp ? 'prop': 'attr']("checked",false);
  3072. if(fid) {
  3073. $("#"+$.jgrid.jqID(n), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight");
  3074. $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(n), "#"+$.jgrid.jqID(fid))[t.p.useProp ? 'prop': 'attr']("checked",false);
  3075. }
  3076. });
  3077. t.setHeadCheckBox( false );
  3078. t.p.selarrrow = [];
  3079. t.p.selrow = null;
  3080. }
  3081. if(t.p.cellEdit === true) {
  3082. if(parseInt(t.p.iCol,10)>=0 && parseInt(t.p.iRow,10)>=0) {
  3083. $("td:eq("+t.p.iCol+")",t.rows[t.p.iRow]).removeClass("edit-cell ui-state-highlight");
  3084. $(t.rows[t.p.iRow]).removeClass("selected-row ui-state-hover");
  3085. }
  3086. }
  3087. t.p.savedRow = [];
  3088. });
  3089. },
  3090. getRowData : function( rowid ) {
  3091. var res = {}, resall, getall=false, len, j=0;
  3092. this.each(function(){
  3093. var $t = this,nm,ind;
  3094. if(rowid === undefined) {
  3095. getall = true;
  3096. resall = [];
  3097. len = $t.rows.length;
  3098. } else {
  3099. ind = $($t).jqGrid('getGridRowById', rowid);
  3100. if(!ind) { return res; }
  3101. len = 2;
  3102. }
  3103. while(j<len){
  3104. if(getall) { ind = $t.rows[j]; }
  3105. if( $(ind).hasClass('jqgrow') ) {
  3106. $('td[role="gridcell"]',ind).each( function(i) {
  3107. nm = $t.p.colModel[i].name;
  3108. if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn') {
  3109. if($t.p.treeGrid===true && nm === $t.p.ExpandColumn) {
  3110. res[nm] = $.jgrid.htmlDecode($("span:first",this).html());
  3111. } else {
  3112. try {
  3113. res[nm] = $.unformat.call($t,this,{rowId:ind.id, colModel:$t.p.colModel[i]},i);
  3114. } catch (e){
  3115. res[nm] = $.jgrid.htmlDecode($(this).html());
  3116. }
  3117. }
  3118. }
  3119. });
  3120. if(getall) { resall.push(res); res={}; }
  3121. }
  3122. j++;
  3123. }
  3124. });
  3125. return resall || res;
  3126. },
  3127. delRowData : function(rowid) {
  3128. var success = false, rowInd, ia;
  3129. this.each(function() {
  3130. var $t = this;
  3131. rowInd = $($t).jqGrid('getGridRowById', rowid);
  3132. if(!rowInd) {return false;}
  3133. $(rowInd).remove();
  3134. $t.p.records--;
  3135. $t.p.reccount--;
  3136. $t.updatepager(true,false);
  3137. success=true;
  3138. if($t.p.multiselect) {
  3139. ia = $.inArray(rowid,$t.p.selarrrow);
  3140. if(ia !== -1) { $t.p.selarrrow.splice(ia,1);}
  3141. }
  3142. if ($t.p.multiselect && $t.p.selarrrow.length > 0) {
  3143. $t.p.selrow = $t.p.selarrrow[$t.p.selarrrow.length-1];
  3144. } else {
  3145. $t.p.selrow = null;
  3146. }
  3147. if($t.p.datatype === 'local') {
  3148. var id = $.jgrid.stripPref($t.p.idPrefix, rowid),
  3149. pos = $t.p._index[id];
  3150. if(pos !== undefined) {
  3151. $t.p.data.splice(pos,1);
  3152. $t.refreshIndex();
  3153. }
  3154. }
  3155. if( $t.p.altRows === true && success ) {
  3156. var cn = $t.p.altclass;
  3157. $($t.rows).each(function(i){
  3158. if(i % 2 === 1) { $(this).addClass(cn); }
  3159. else { $(this).removeClass(cn); }
  3160. });
  3161. }
  3162. });
  3163. return success;
  3164. },
  3165. setRowData : function(rowid, data, cssp) {
  3166. var nm, success=true, title;
  3167. this.each(function(){
  3168. if(!this.grid) {return false;}
  3169. var t = this, vl, ind, cp = typeof cssp, lcdata={};
  3170. ind = $(this).jqGrid('getGridRowById', rowid);
  3171. if(!ind) { return false; }
  3172. if( data ) {
  3173. try {
  3174. $(this.p.colModel).each(function(i){
  3175. nm = this.name;
  3176. var dval =$.jgrid.getAccessor(data,nm);
  3177. if( dval !== undefined) {
  3178. lcdata[nm] = this.formatter && typeof this.formatter === 'string' && this.formatter === 'date' ? $.unformat.date.call(t,dval,this) : dval;
  3179. vl = t.formatter( rowid, dval, i, data, 'edit');
  3180. title = this.title ? {"title":$.jgrid.stripHtml(vl)} : {};
  3181. if(t.p.treeGrid===true && nm === t.p.ExpandColumn) {
  3182. $("td[role='gridcell']:eq("+i+") > span:first",ind).html(vl).attr(title);
  3183. } else {
  3184. $("td[role='gridcell']:eq("+i+")",ind).html(vl).attr(title);
  3185. }
  3186. }
  3187. });
  3188. if(t.p.datatype === 'local') {
  3189. var id = $.jgrid.stripPref(t.p.idPrefix, rowid),
  3190. pos = t.p._index[id], key;
  3191. if(t.p.treeGrid) {
  3192. for(key in t.p.treeReader){
  3193. if(t.p.treeReader.hasOwnProperty(key)) {
  3194. delete lcdata[t.p.treeReader[key]];
  3195. }
  3196. }
  3197. }
  3198. if(pos !== undefined) {
  3199. t.p.data[pos] = $.extend(true, t.p.data[pos], lcdata);
  3200. }
  3201. lcdata = null;
  3202. }
  3203. } catch (e) {
  3204. success = false;
  3205. }
  3206. }
  3207. if(success) {
  3208. if(cp === 'string') {$(ind).addClass(cssp);} else if(cssp !== null && cp === 'object') {$(ind).css(cssp);}
  3209. $(t).triggerHandler("jqGridAfterGridComplete");
  3210. }
  3211. });
  3212. return success;
  3213. },
  3214. addRowData : function(rowid,rdata,pos,src) {
  3215. if(!pos) {pos = "last";}
  3216. var success = false, nm, row, gi, si, ni,sind, i, v, prp="", aradd, cnm, cn, data, cm, id;
  3217. if(rdata) {
  3218. if($.isArray(rdata)) {
  3219. aradd=true;
  3220. pos = "last";
  3221. cnm = rowid;
  3222. } else {
  3223. rdata = [rdata];
  3224. aradd = false;
  3225. }
  3226. this.each(function() {
  3227. var t = this, datalen = rdata.length;
  3228. ni = t.p.rownumbers===true ? 1 :0;
  3229. gi = t.p.multiselect ===true ? 1 :0;
  3230. si = t.p.subGrid===true ? 1 :0;
  3231. if(!aradd) {
  3232. if(rowid !== undefined) { rowid = String(rowid);}
  3233. else {
  3234. rowid = $.jgrid.randId();
  3235. if(t.p.keyIndex !== false) {
  3236. cnm = t.p.colModel[t.p.keyIndex+gi+si+ni].name;
  3237. if(rdata[0][cnm] !== undefined) { rowid = rdata[0][cnm]; }
  3238. }
  3239. }
  3240. }
  3241. cn = t.p.altclass;
  3242. var k = 0, cna ="", lcdata = {},
  3243. air = $.isFunction(t.p.afterInsertRow) ? true : false;
  3244. while(k < datalen) {
  3245. data = rdata[k];
  3246. row=[];
  3247. if(aradd) {
  3248. try {
  3249. rowid = data[cnm];
  3250. if(rowid===undefined) {
  3251. rowid = $.jgrid.randId();
  3252. }
  3253. }
  3254. catch (e) {rowid = $.jgrid.randId();}
  3255. cna = t.p.altRows === true ? (t.rows.length-1)%2 === 0 ? cn : "" : "";
  3256. }
  3257. id = rowid;
  3258. rowid = t.p.idPrefix + rowid;
  3259. if(ni){
  3260. prp = t.formatCol(0,1,'',null,rowid, true);
  3261. row[row.length] = "<td role=\"gridcell\" class=\"ui-state-default jqgrid-rownum\" "+prp+">0</td>";
  3262. }
  3263. if(gi) {
  3264. v = "<input role=\"checkbox\" type=\"checkbox\""+" id=\"jqg_"+t.p.id+"_"+rowid+"\" class=\"cbox\"/>";
  3265. prp = t.formatCol(ni,1,'', null, rowid, true);
  3266. row[row.length] = "<td role=\"gridcell\" "+prp+">"+v+"</td>";
  3267. }
  3268. if(si) {
  3269. row[row.length] = $(t).jqGrid("addSubGridCell",gi+ni,1);
  3270. }
  3271. for(i = gi+si+ni; i < t.p.colModel.length;i++){
  3272. cm = t.p.colModel[i];
  3273. nm = cm.name;
  3274. lcdata[nm] = data[nm];
  3275. v = t.formatter( rowid, $.jgrid.getAccessor(data,nm), i, data );
  3276. prp = t.formatCol(i,1,v, data, rowid, lcdata);
  3277. row[row.length] = "<td role=\"gridcell\" "+prp+">"+v+"</td>";
  3278. }
  3279. row.unshift( t.constructTr(rowid, false, cna, lcdata, data, false ) );
  3280. row[row.length] = "</tr>";
  3281. if(t.rows.length === 0){
  3282. $("table:first",t.grid.bDiv).append(row.join(''));
  3283. } else {
  3284. switch (pos) {
  3285. case 'last':
  3286. $(t.rows[t.rows.length-1]).after(row.join(''));
  3287. sind = t.rows.length-1;
  3288. break;
  3289. case 'first':
  3290. $(t.rows[0]).after(row.join(''));
  3291. sind = 1;
  3292. break;
  3293. case 'after':
  3294. sind = $(t).jqGrid('getGridRowById', src);
  3295. if (sind) {
  3296. if($(t.rows[sind.rowIndex+1]).hasClass("ui-subgrid")) { $(t.rows[sind.rowIndex+1]).after(row); }
  3297. else { $(sind).after(row.join('')); }
  3298. sind=sind.rowIndex + 1;
  3299. }
  3300. break;
  3301. case 'before':
  3302. sind = $(t).jqGrid('getGridRowById', src);
  3303. if(sind) {
  3304. $(sind).before(row.join(''));
  3305. sind=sind.rowIndex - 1;
  3306. }
  3307. break;
  3308. }
  3309. }
  3310. if(t.p.subGrid===true) {
  3311. $(t).jqGrid("addSubGrid",gi+ni, sind);
  3312. }
  3313. t.p.records++;
  3314. t.p.reccount++;
  3315. $(t).triggerHandler("jqGridAfterInsertRow", [rowid,data,data]);
  3316. if(air) { t.p.afterInsertRow.call(t,rowid,data,data); }
  3317. k++;
  3318. if(t.p.datatype === 'local') {
  3319. lcdata[t.p.localReader.id] = id;
  3320. t.p._index[id] = t.p.data.length;
  3321. t.p.data.push(lcdata);
  3322. lcdata = {};
  3323. }
  3324. }
  3325. if( t.p.altRows === true && !aradd) {
  3326. if (pos === "last") {
  3327. if ((t.rows.length-1)%2 === 1) {$(t.rows[t.rows.length-1]).addClass(cn);}
  3328. } else {
  3329. $(t.rows).each(function(i){
  3330. if(i % 2 ===1) { $(this).addClass(cn); }
  3331. else { $(this).removeClass(cn); }
  3332. });
  3333. }
  3334. }
  3335. t.updatepager(true,true);
  3336. success = true;
  3337. });
  3338. }
  3339. return success;
  3340. },
  3341. footerData : function(action,data, format) {
  3342. var nm, success=false, res={}, title;
  3343. function isEmpty(obj) {
  3344. var i;
  3345. for(i in obj) {
  3346. if (obj.hasOwnProperty(i)) { return false; }
  3347. }
  3348. return true;
  3349. }
  3350. if(action == undefined) { action = "get"; }
  3351. if(typeof format !== "boolean") { format = true; }
  3352. action = action.toLowerCase();
  3353. this.each(function(){
  3354. var t = this, vl;
  3355. if(!t.grid || !t.p.footerrow) {return false;}
  3356. if(action === "set") { if(isEmpty(data)) { return false; } }
  3357. success=true;
  3358. $(this.p.colModel).each(function(i){
  3359. nm = this.name;
  3360. if(action === "set") {
  3361. if( data[nm] !== undefined) {
  3362. vl = format ? t.formatter( "", data[nm], i, data, 'edit') : data[nm];
  3363. title = this.title ? {"title":$.jgrid.stripHtml(vl)} : {};
  3364. $("tr.footrow td:eq("+i+")",t.grid.sDiv).html(vl).attr(title);
  3365. success = true;
  3366. }
  3367. } else if(action === "get") {
  3368. res[nm] = $("tr.footrow td:eq("+i+")",t.grid.sDiv).html();
  3369. }
  3370. });
  3371. });
  3372. return action === "get" ? res : success;
  3373. },
  3374. showHideCol : function(colname,show) {
  3375. return this.each(function() {
  3376. var $t = this, fndh=false, brd=$.jgrid.cell_width ? 0: $t.p.cellLayout, cw;
  3377. if (!$t.grid ) {return;}
  3378. if( typeof colname === 'string') {colname=[colname];}
  3379. show = show !== "none" ? "" : "none";
  3380. var sw = show === "" ? true :false,
  3381. gh = $t.p.groupHeader && (typeof $t.p.groupHeader === 'object' || $.isFunction($t.p.groupHeader) );
  3382. if(gh) { $($t).jqGrid('destroyGroupHeader', false); }
  3383. $(this.p.colModel).each(function(i) {
  3384. if ($.inArray(this.name,colname) !== -1 && this.hidden === sw) {
  3385. if($t.p.frozenColumns === true && this.frozen === true) {
  3386. return true;
  3387. }
  3388. $("tr[role=rowheader]",$t.grid.hDiv).each(function(){
  3389. $(this.cells[i]).css("display", show);
  3390. });
  3391. $($t.rows).each(function(){
  3392. if (!$(this).hasClass("jqgroup")) {
  3393. $(this.cells[i]).css("display", show);
  3394. }
  3395. });
  3396. if($t.p.footerrow) { $("tr.footrow td:eq("+i+")", $t.grid.sDiv).css("display", show); }
  3397. cw = parseInt(this.width,10);
  3398. if(show === "none") {
  3399. $t.p.tblwidth -= cw+brd;
  3400. } else {
  3401. $t.p.tblwidth += cw+brd;
  3402. }
  3403. this.hidden = !sw;
  3404. fndh=true;
  3405. $($t).triggerHandler("jqGridShowHideCol", [sw,this.name,i]);
  3406. }
  3407. });
  3408. if(fndh===true) {
  3409. if($t.p.shrinkToFit === true && !isNaN($t.p.height)) { $t.p.tblwidth += parseInt($t.p.scrollOffset,10);}
  3410. $($t).jqGrid("setGridWidth",$t.p.shrinkToFit === true ? $t.p.tblwidth : $t.p.width );
  3411. }
  3412. if( gh ) {
  3413. $($t).jqGrid('setGroupHeaders',$t.p.groupHeader);
  3414. }
  3415. });
  3416. },
  3417. hideCol : function (colname) {
  3418. return this.each(function(){$(this).jqGrid("showHideCol",colname,"none");});
  3419. },
  3420. showCol : function(colname) {
  3421. return this.each(function(){$(this).jqGrid("showHideCol",colname,"");});
  3422. },
  3423. remapColumns : function(permutation, updateCells, keepHeader)
  3424. {
  3425. function resortArray(a) {
  3426. var ac;
  3427. if (a.length) {
  3428. ac = $.makeArray(a);
  3429. } else {
  3430. ac = $.extend({}, a);
  3431. }
  3432. $.each(permutation, function(i) {
  3433. a[i] = ac[this];
  3434. });
  3435. }
  3436. var ts = this.get(0);
  3437. function resortRows(parent, clobj) {
  3438. $(">tr"+(clobj||""), parent).each(function() {
  3439. var row = this;
  3440. var elems = $.makeArray(row.cells);
  3441. $.each(permutation, function() {
  3442. var e = elems[this];
  3443. if (e) {
  3444. row.appendChild(e);
  3445. }
  3446. });
  3447. });
  3448. }
  3449. resortArray(ts.p.colModel);
  3450. resortArray(ts.p.colNames);
  3451. resortArray(ts.grid.headers);
  3452. resortRows($("thead:first", ts.grid.hDiv), keepHeader && ":not(.ui-jqgrid-labels)");
  3453. if (updateCells) {
  3454. resortRows($("#"+$.jgrid.jqID(ts.p.id)+" tbody:first"), ".jqgfirstrow, tr.jqgrow, tr.jqfoot");
  3455. }
  3456. if (ts.p.footerrow) {
  3457. resortRows($("tbody:first", ts.grid.sDiv));
  3458. }
  3459. if (ts.p.remapColumns) {
  3460. if (!ts.p.remapColumns.length){
  3461. ts.p.remapColumns = $.makeArray(permutation);
  3462. } else {
  3463. resortArray(ts.p.remapColumns);
  3464. }
  3465. }
  3466. ts.p.lastsort = $.inArray(ts.p.lastsort, permutation);
  3467. if(ts.p.treeGrid) { ts.p.expColInd = $.inArray(ts.p.expColInd, permutation); }
  3468. $(ts).triggerHandler("jqGridRemapColumns", [permutation, updateCells, keepHeader]);
  3469. },
  3470. setGridWidth : function(nwidth, shrink) {
  3471. return this.each(function(){
  3472. if (!this.grid ) {return;}
  3473. var $t = this, cw,
  3474. initwidth = 0, brd=$.jgrid.cell_width ? 0: $t.p.cellLayout, lvc, vc=0, hs=false, scw=$t.p.scrollOffset, aw, gw=0, cr;
  3475. if(typeof shrink !== 'boolean') {
  3476. shrink=$t.p.shrinkToFit;
  3477. }
  3478. if(isNaN(nwidth)) {return;}
  3479. nwidth = parseInt(nwidth,10);
  3480. $t.grid.width = $t.p.width = nwidth;
  3481. $("#gbox_"+$.jgrid.jqID($t.p.id)).css("width",nwidth+"px");
  3482. $("#gview_"+$.jgrid.jqID($t.p.id)).css("width",nwidth+"px");
  3483. $($t.grid.bDiv).css("width",nwidth+"px");
  3484. $($t.grid.hDiv).css("width",nwidth+"px");
  3485. if($t.p.pager ) {$($t.p.pager).css("width",nwidth+"px");}
  3486. if($t.p.toppager ) {$($t.p.toppager).css("width",nwidth+"px");}
  3487. if($t.p.toolbar[0] === true){
  3488. $($t.grid.uDiv).css("width",nwidth+"px");
  3489. if($t.p.toolbar[1]==="both") {$($t.grid.ubDiv).css("width",nwidth+"px");}
  3490. }
  3491. if($t.p.footerrow) { $($t.grid.sDiv).css("width",nwidth+"px"); }
  3492. if(shrink ===false && $t.p.forceFit === true) {$t.p.forceFit=false;}
  3493. if(shrink===true) {
  3494. $.each($t.p.colModel, function() {
  3495. if(this.hidden===false){
  3496. cw = this.widthOrg;
  3497. initwidth += cw+brd;
  3498. if(this.fixed) {
  3499. gw += cw+brd;
  3500. } else {
  3501. vc++;
  3502. }
  3503. }
  3504. });
  3505. if(vc === 0) { return; }
  3506. $t.p.tblwidth = initwidth;
  3507. aw = nwidth-brd*vc-gw;
  3508. if(!isNaN($t.p.height)) {
  3509. if($($t.grid.bDiv)[0].clientHeight < $($t.grid.bDiv)[0].scrollHeight || $t.rows.length === 1){
  3510. hs = true;
  3511. aw -= scw;
  3512. }
  3513. }
  3514. initwidth =0;
  3515. var cle = $t.grid.cols.length >0;
  3516. $.each($t.p.colModel, function(i) {
  3517. if(this.hidden === false && !this.fixed){
  3518. cw = this.widthOrg;
  3519. cw = Math.round(aw*cw/($t.p.tblwidth-brd*vc-gw));
  3520. if (cw < 0) { return; }
  3521. this.width =cw;
  3522. initwidth += cw;
  3523. $t.grid.headers[i].width=cw;
  3524. $t.grid.headers[i].el.style.width=cw+"px";
  3525. if($t.p.footerrow) { $t.grid.footers[i].style.width = cw+"px"; }
  3526. if(cle) { $t.grid.cols[i].style.width = cw+"px"; }
  3527. lvc = i;
  3528. }
  3529. });
  3530. if (!lvc) { return; }
  3531. cr =0;
  3532. if (hs) {
  3533. if(nwidth-gw-(initwidth+brd*vc) !== scw){
  3534. cr = nwidth-gw-(initwidth+brd*vc)-scw;
  3535. }
  3536. } else if( Math.abs(nwidth-gw-(initwidth+brd*vc)) !== 1) {
  3537. cr = nwidth-gw-(initwidth+brd*vc);
  3538. }
  3539. $t.p.colModel[lvc].width += cr;
  3540. $t.p.tblwidth = initwidth+cr+brd*vc+gw;
  3541. if($t.p.tblwidth > nwidth) {
  3542. var delta = $t.p.tblwidth - parseInt(nwidth,10);
  3543. $t.p.tblwidth = nwidth;
  3544. cw = $t.p.colModel[lvc].width = $t.p.colModel[lvc].width-delta;
  3545. } else {
  3546. cw= $t.p.colModel[lvc].width;
  3547. }
  3548. $t.grid.headers[lvc].width = cw;
  3549. $t.grid.headers[lvc].el.style.width=cw+"px";
  3550. if(cle) { $t.grid.cols[lvc].style.width = cw+"px"; }
  3551. if($t.p.footerrow) {
  3552. $t.grid.footers[lvc].style.width = cw+"px";
  3553. }
  3554. }
  3555. if($t.p.tblwidth) {
  3556. $('table:first',$t.grid.bDiv).css("width",$t.p.tblwidth+"px");
  3557. $('table:first',$t.grid.hDiv).css("width",$t.p.tblwidth+"px");
  3558. $t.grid.hDiv.scrollLeft = $t.grid.bDiv.scrollLeft;
  3559. if($t.p.footerrow) {
  3560. $('table:first',$t.grid.sDiv).css("width",$t.p.tblwidth+"px");
  3561. }
  3562. }
  3563. });
  3564. },
  3565. setGridHeight : function (nh) {
  3566. return this.each(function (){
  3567. var $t = this;
  3568. if(!$t.grid) {return;}
  3569. var bDiv = $($t.grid.bDiv);
  3570. bDiv.css({height: nh+(isNaN(nh)?"":"px")});
  3571. if($t.p.frozenColumns === true){
  3572. //follow the original set height to use 16, better scrollbar width detection
  3573. $('#'+$.jgrid.jqID($t.p.id)+"_frozen").parent().height(bDiv.height() - 16);
  3574. }
  3575. $t.p.height = nh;
  3576. if ($t.p.scroll) { $t.grid.populateVisible(); }
  3577. });
  3578. },
  3579. setCaption : function (newcap){
  3580. return this.each(function(){
  3581. this.p.caption=newcap;
  3582. $("span.ui-jqgrid-title, span.ui-jqgrid-title-rtl",this.grid.cDiv).html(newcap);
  3583. $(this.grid.cDiv).show();
  3584. });
  3585. },
  3586. setLabel : function(colname, nData, prop, attrp ){
  3587. return this.each(function(){
  3588. var $t = this, pos=-1;
  3589. if(!$t.grid) {return;}
  3590. if(colname !== undefined) {
  3591. $($t.p.colModel).each(function(i){
  3592. if (this.name === colname) {
  3593. pos = i;return false;
  3594. }
  3595. });
  3596. } else { return; }
  3597. if(pos>=0) {
  3598. var thecol = $("tr.ui-jqgrid-labels th:eq("+pos+")",$t.grid.hDiv);
  3599. if (nData){
  3600. var ico = $(".s-ico",thecol);
  3601. $("[id^=jqgh_]",thecol).empty().html(nData).append(ico);
  3602. $t.p.colNames[pos] = nData;
  3603. }
  3604. if (prop) {
  3605. if(typeof prop === 'string') {$(thecol).addClass(prop);} else {$(thecol).css(prop);}
  3606. }
  3607. if(typeof attrp === 'object') {$(thecol).attr(attrp);}
  3608. }
  3609. });
  3610. },
  3611. setCell : function(rowid,colname,nData,cssp,attrp, forceupd) {
  3612. return this.each(function(){
  3613. var $t = this, pos =-1,v, title;
  3614. if(!$t.grid) {return;}
  3615. if(isNaN(colname)) {
  3616. $($t.p.colModel).each(function(i){
  3617. if (this.name === colname) {
  3618. pos = i;return false;
  3619. }
  3620. });
  3621. } else {pos = parseInt(colname,10);}
  3622. if(pos>=0) {
  3623. var ind = $($t).jqGrid('getGridRowById', rowid);
  3624. if (ind){
  3625. var tcell = $("td:eq("+pos+")",ind);
  3626. if(nData !== "" || forceupd === true) {
  3627. v = $t.formatter(rowid, nData, pos,ind,'edit');
  3628. title = $t.p.colModel[pos].title ? {"title":$.jgrid.stripHtml(v)} : {};
  3629. if($t.p.treeGrid && $(".tree-wrap",$(tcell)).length>0) {
  3630. $("span",$(tcell)).html(v).attr(title);
  3631. } else {
  3632. $(tcell).html(v).attr(title);
  3633. }
  3634. if($t.p.datatype === "local") {
  3635. var cm = $t.p.colModel[pos], index;
  3636. nData = cm.formatter && typeof cm.formatter === 'string' && cm.formatter === 'date' ? $.unformat.date.call($t,nData,cm) : nData;
  3637. index = $t.p._index[$.jgrid.stripPref($t.p.idPrefix, rowid)];
  3638. if(index !== undefined) {
  3639. $t.p.data[index][cm.name] = nData;
  3640. }
  3641. }
  3642. }
  3643. if(typeof cssp === 'string'){
  3644. $(tcell).addClass(cssp);
  3645. } else if(cssp) {
  3646. $(tcell).css(cssp);
  3647. }
  3648. if(typeof attrp === 'object') {$(tcell).attr(attrp);}
  3649. }
  3650. }
  3651. });
  3652. },
  3653. getCell : function(rowid,col) {
  3654. var ret = false;
  3655. this.each(function(){
  3656. var $t=this, pos=-1;
  3657. if(!$t.grid) {return;}
  3658. if(isNaN(col)) {
  3659. $($t.p.colModel).each(function(i){
  3660. if (this.name === col) {
  3661. pos = i;return false;
  3662. }
  3663. });
  3664. } else {pos = parseInt(col,10);}
  3665. if(pos>=0) {
  3666. var ind = $($t).jqGrid('getGridRowById', rowid);
  3667. if(ind) {
  3668. try {
  3669. ret = $.unformat.call($t,$("td:eq("+pos+")",ind),{rowId:ind.id, colModel:$t.p.colModel[pos]},pos);
  3670. } catch (e){
  3671. ret = $.jgrid.htmlDecode($("td:eq("+pos+")",ind).html());
  3672. }
  3673. }
  3674. }
  3675. });
  3676. return ret;
  3677. },
  3678. getCol : function (col, obj, mathopr) {
  3679. var ret = [], val, sum=0, min, max, v;
  3680. obj = typeof obj !== 'boolean' ? false : obj;
  3681. if(mathopr === undefined) { mathopr = false; }
  3682. this.each(function(){
  3683. var $t=this, pos=-1;
  3684. if(!$t.grid) {return;}
  3685. if(isNaN(col)) {
  3686. $($t.p.colModel).each(function(i){
  3687. if (this.name === col) {
  3688. pos = i;return false;
  3689. }
  3690. });
  3691. } else {pos = parseInt(col,10);}
  3692. if(pos>=0) {
  3693. var ln = $t.rows.length, i =0, dlen=0;
  3694. if (ln && ln>0){
  3695. while(i<ln){
  3696. if($($t.rows[i]).hasClass('jqgrow')) {
  3697. try {
  3698. val = $.unformat.call($t,$($t.rows[i].cells[pos]),{rowId:$t.rows[i].id, colModel:$t.p.colModel[pos]},pos);
  3699. } catch (e) {
  3700. val = $.jgrid.htmlDecode($t.rows[i].cells[pos].innerHTML);
  3701. }
  3702. if(mathopr) {
  3703. v = parseFloat(val);
  3704. if(!isNaN(v)) {
  3705. sum += v;
  3706. if (max === undefined) {max = min = v;}
  3707. min = Math.min(min, v);
  3708. max = Math.max(max, v);
  3709. dlen++;
  3710. }
  3711. }
  3712. else if(obj) { ret.push( {id:$t.rows[i].id,value:val} ); }
  3713. else { ret.push( val ); }
  3714. }
  3715. i++;
  3716. }
  3717. if(mathopr) {
  3718. switch(mathopr.toLowerCase()){
  3719. case 'sum': ret =sum; break;
  3720. case 'avg': ret = sum/dlen; break;
  3721. case 'count': ret = (ln-1); break;
  3722. case 'min': ret = min; break;
  3723. case 'max': ret = max; break;
  3724. }
  3725. }
  3726. }
  3727. }
  3728. });
  3729. return ret;
  3730. },
  3731. clearGridData : function(clearfooter) {
  3732. return this.each(function(){
  3733. var $t = this;
  3734. if(!$t.grid) {return;}
  3735. if(typeof clearfooter !== 'boolean') { clearfooter = false; }
  3736. if($t.p.deepempty) {$("#"+$.jgrid.jqID($t.p.id)+" tbody:first tr:gt(0)").remove();}
  3737. else {
  3738. var trf = $("#"+$.jgrid.jqID($t.p.id)+" tbody:first tr:first")[0];
  3739. $("#"+$.jgrid.jqID($t.p.id)+" tbody:first").empty().append(trf);
  3740. }
  3741. if($t.p.footerrow && clearfooter) { $(".ui-jqgrid-ftable td",$t.grid.sDiv).html("&#160;"); }
  3742. $t.p.selrow = null; $t.p.selarrrow= []; $t.p.savedRow = [];
  3743. $t.p.records = 0;$t.p.page=1;$t.p.lastpage=0;$t.p.reccount=0;
  3744. $t.p.data = []; $t.p._index = {};
  3745. $t.updatepager(true,false);
  3746. });
  3747. },
  3748. getInd : function(rowid,rc){
  3749. var ret =false,rw;
  3750. this.each(function(){
  3751. rw = $(this).jqGrid('getGridRowById', rowid);
  3752. if(rw) {
  3753. ret = rc===true ? rw: rw.rowIndex;
  3754. }
  3755. });
  3756. return ret;
  3757. },
  3758. bindKeys : function( settings ){
  3759. var o = $.extend({
  3760. onEnter: null,
  3761. onSpace: null,
  3762. onLeftKey: null,
  3763. onRightKey: null,
  3764. scrollingRows : true
  3765. },settings || {});
  3766. return this.each(function(){
  3767. var $t = this;
  3768. if( !$('body').is('[role]') ){$('body').attr('role','application');}
  3769. $t.p.scrollrows = o.scrollingRows;
  3770. $($t).keydown(function(event){
  3771. var target = $($t).find('tr[tabindex=0]')[0], id, r, mind,
  3772. expanded = $t.p.treeReader.expanded_field;
  3773. //check for arrow keys
  3774. if(target) {
  3775. mind = $t.p._index[$.jgrid.stripPref($t.p.idPrefix, target.id)];
  3776. if(event.keyCode === 37 || event.keyCode === 38 || event.keyCode === 39 || event.keyCode === 40){
  3777. // up key
  3778. if(event.keyCode === 38 ){
  3779. r = target.previousSibling;
  3780. id = "";
  3781. if(r) {
  3782. if($(r).is(":hidden")) {
  3783. while(r) {
  3784. r = r.previousSibling;
  3785. if(!$(r).is(":hidden") && $(r).hasClass('jqgrow')) {id = r.id;break;}
  3786. }
  3787. } else {
  3788. id = r.id;
  3789. }
  3790. }
  3791. $($t).jqGrid('setSelection', id, true, event);
  3792. event.preventDefault();
  3793. }
  3794. //if key is down arrow
  3795. if(event.keyCode === 40){
  3796. r = target.nextSibling;
  3797. id ="";
  3798. if(r) {
  3799. if($(r).is(":hidden")) {
  3800. while(r) {
  3801. r = r.nextSibling;
  3802. if(!$(r).is(":hidden") && $(r).hasClass('jqgrow') ) {id = r.id;break;}
  3803. }
  3804. } else {
  3805. id = r.id;
  3806. }
  3807. }
  3808. $($t).jqGrid('setSelection', id, true, event);
  3809. event.preventDefault();
  3810. }
  3811. // left
  3812. if(event.keyCode === 37 ){
  3813. if($t.p.treeGrid && $t.p.data[mind][expanded]) {
  3814. $(target).find("div.treeclick").trigger('click');
  3815. }
  3816. $($t).triggerHandler("jqGridKeyLeft", [$t.p.selrow]);
  3817. if($.isFunction(o.onLeftKey)) {
  3818. o.onLeftKey.call($t, $t.p.selrow);
  3819. }
  3820. }
  3821. // right
  3822. if(event.keyCode === 39 ){
  3823. if($t.p.treeGrid && !$t.p.data[mind][expanded]) {
  3824. $(target).find("div.treeclick").trigger('click');
  3825. }
  3826. $($t).triggerHandler("jqGridKeyRight", [$t.p.selrow]);
  3827. if($.isFunction(o.onRightKey)) {
  3828. o.onRightKey.call($t, $t.p.selrow);
  3829. }
  3830. }
  3831. }
  3832. //check if enter was pressed on a grid or treegrid node
  3833. else if( event.keyCode === 13 ){
  3834. $($t).triggerHandler("jqGridKeyEnter", [$t.p.selrow]);
  3835. if($.isFunction(o.onEnter)) {
  3836. o.onEnter.call($t, $t.p.selrow);
  3837. }
  3838. } else if(event.keyCode === 32) {
  3839. $($t).triggerHandler("jqGridKeySpace", [$t.p.selrow]);
  3840. if($.isFunction(o.onSpace)) {
  3841. o.onSpace.call($t, $t.p.selrow);
  3842. }
  3843. }
  3844. }
  3845. });
  3846. });
  3847. },
  3848. unbindKeys : function(){
  3849. return this.each(function(){
  3850. $(this).unbind('keydown');
  3851. });
  3852. },
  3853. getLocalRow : function (rowid) {
  3854. var ret = false, ind;
  3855. this.each(function(){
  3856. if(rowid !== undefined) {
  3857. ind = this.p._index[$.jgrid.stripPref(this.p.idPrefix, rowid)];
  3858. if(ind >= 0 ) {
  3859. ret = this.p.data[ind];
  3860. }
  3861. }
  3862. });
  3863. return ret;
  3864. }
  3865. });
  3866. })(jQuery);
  3867. /*jshint eqeqeq:false */
  3868. /*global jQuery */
  3869. (function($){
  3870. /**
  3871. * jqGrid extension for custom methods
  3872. * Tony Tomov tony@trirand.com
  3873. * http://trirand.com/blog/
  3874. *
  3875. * Wildraid wildraid@mail.ru
  3876. * Oleg Kiriljuk oleg.kiriljuk@ok-soft-gmbh.com
  3877. * Dual licensed under the MIT and GPL licenses:
  3878. * http://www.opensource.org/licenses/mit-license.php
  3879. * http://www.gnu.org/licenses/gpl-2.0.html
  3880. **/
  3881. "use strict";
  3882. $.jgrid.extend({
  3883. getColProp : function(colname){
  3884. var ret ={}, $t = this[0];
  3885. if ( !$t.grid ) { return false; }
  3886. var cM = $t.p.colModel, i;
  3887. for ( i=0;i<cM.length;i++ ) {
  3888. if ( cM[i].name === colname ) {
  3889. ret = cM[i];
  3890. break;
  3891. }
  3892. }
  3893. return ret;
  3894. },
  3895. setColProp : function(colname, obj){
  3896. //do not set width will not work
  3897. return this.each(function(){
  3898. if ( this.grid ) {
  3899. if ( obj ) {
  3900. var cM = this.p.colModel, i;
  3901. for ( i=0;i<cM.length;i++ ) {
  3902. if ( cM[i].name === colname ) {
  3903. $.extend(true, this.p.colModel[i],obj);
  3904. break;
  3905. }
  3906. }
  3907. }
  3908. }
  3909. });
  3910. },
  3911. sortGrid : function(colname,reload, sor){
  3912. return this.each(function(){
  3913. var $t=this,idx=-1,i, sobj=false;
  3914. if ( !$t.grid ) { return;}
  3915. if ( !colname ) { colname = $t.p.sortname; }
  3916. for ( i=0;i<$t.p.colModel.length;i++ ) {
  3917. if ( $t.p.colModel[i].index === colname || $t.p.colModel[i].name === colname ) {
  3918. idx = i;
  3919. if($t.p.frozenColumns === true && $t.p.colModel[i].frozen === true) {
  3920. sobj = $t.grid.fhDiv.find("#" + $t.p.id + "_" + colname);
  3921. }
  3922. break;
  3923. }
  3924. }
  3925. if ( idx !== -1 ){
  3926. var sort = $t.p.colModel[idx].sortable;
  3927. if(!sobj) {
  3928. sobj = $t.grid.headers[idx].el;
  3929. }
  3930. if ( typeof sort !== 'boolean' ) { sort = true; }
  3931. if ( typeof reload !=='boolean' ) { reload = false; }
  3932. if ( sort ) { $t.sortData("jqgh_"+$t.p.id+"_" + colname, idx, reload, sor, sobj); }
  3933. }
  3934. });
  3935. },
  3936. clearBeforeUnload : function () {
  3937. return this.each(function(){
  3938. var grid = this.grid;
  3939. if ($.isFunction(grid.emptyRows)) {
  3940. grid.emptyRows.call(this, true, true); // this work quick enough and reduce the size of memory leaks if we have someone
  3941. }
  3942. $(document).unbind("mouseup.jqGrid" + this.p.id );
  3943. $(grid.hDiv).unbind("mousemove"); // TODO add namespace
  3944. $(this).unbind();
  3945. grid.dragEnd = null;
  3946. grid.dragMove = null;
  3947. grid.dragStart = null;
  3948. grid.emptyRows = null;
  3949. grid.populate = null;
  3950. grid.populateVisible = null;
  3951. grid.scrollGrid = null;
  3952. grid.selectionPreserver = null;
  3953. grid.bDiv = null;
  3954. grid.cDiv = null;
  3955. grid.hDiv = null;
  3956. grid.cols = null;
  3957. var i, l = grid.headers.length;
  3958. for (i = 0; i < l; i++) {
  3959. grid.headers[i].el = null;
  3960. }
  3961. this.formatCol = null;
  3962. this.sortData = null;
  3963. this.updatepager = null;
  3964. this.refreshIndex = null;
  3965. this.setHeadCheckBox = null;
  3966. this.constructTr = null;
  3967. this.formatter = null;
  3968. this.addXmlData = null;
  3969. this.addJSONData = null;
  3970. this.grid = null;
  3971. });
  3972. },
  3973. GridDestroy : function () {
  3974. return this.each(function(){
  3975. if ( this.grid ) {
  3976. if ( this.p.pager ) { // if not part of grid
  3977. $(this.p.pager).remove();
  3978. }
  3979. try {
  3980. $(this).jqGrid('clearBeforeUnload');
  3981. $("#gbox_"+$.jgrid.jqID(this.id)).remove();
  3982. } catch (_) {}
  3983. }
  3984. });
  3985. },
  3986. GridUnload : function(){
  3987. return this.each(function(){
  3988. if ( !this.grid ) {return;}
  3989. var defgrid = {id: $(this).attr('id'),cl: $(this).attr('class')};
  3990. if (this.p.pager) {
  3991. $(this.p.pager).empty().removeClass("ui-state-default ui-jqgrid-pager ui-corner-bottom");
  3992. }
  3993. var newtable = document.createElement('table');
  3994. $(newtable).attr({id:defgrid.id});
  3995. newtable.className = defgrid.cl;
  3996. var gid = $.jgrid.jqID(this.id);
  3997. $(newtable).removeClass("ui-jqgrid-btable");
  3998. if( $(this.p.pager).parents("#gbox_"+gid).length === 1 ) {
  3999. $(newtable).insertBefore("#gbox_"+gid).show();
  4000. $(this.p.pager).insertBefore("#gbox_"+gid);
  4001. } else {
  4002. $(newtable).insertBefore("#gbox_"+gid).show();
  4003. }
  4004. $(this).jqGrid('clearBeforeUnload');
  4005. $("#gbox_"+gid).remove();
  4006. });
  4007. },
  4008. setGridState : function(state) {
  4009. return this.each(function(){
  4010. if ( !this.grid ) {return;}
  4011. var $t = this;
  4012. if(state === 'hidden'){
  4013. $(".ui-jqgrid-bdiv, .ui-jqgrid-hdiv","#gview_"+$.jgrid.jqID($t.p.id)).slideUp("fast");
  4014. if($t.p.pager) {$($t.p.pager).slideUp("fast");}
  4015. if($t.p.toppager) {$($t.p.toppager).slideUp("fast");}
  4016. if($t.p.toolbar[0]===true) {
  4017. if( $t.p.toolbar[1] === 'both') {
  4018. $($t.grid.ubDiv).slideUp("fast");
  4019. }
  4020. $($t.grid.uDiv).slideUp("fast");
  4021. }
  4022. if($t.p.footerrow) { $(".ui-jqgrid-sdiv","#gbox_"+$.jgrid.jqID($t.p.id)).slideUp("fast"); }
  4023. $(".ui-jqgrid-titlebar-close span",$t.grid.cDiv).removeClass("ui-icon-circle-triangle-n").addClass("ui-icon-circle-triangle-s");
  4024. $t.p.gridstate = 'hidden';
  4025. } else if(state === 'visible') {
  4026. $(".ui-jqgrid-hdiv, .ui-jqgrid-bdiv","#gview_"+$.jgrid.jqID($t.p.id)).slideDown("fast");
  4027. if($t.p.pager) {$($t.p.pager).slideDown("fast");}
  4028. if($t.p.toppager) {$($t.p.toppager).slideDown("fast");}
  4029. if($t.p.toolbar[0]===true) {
  4030. if( $t.p.toolbar[1] === 'both') {
  4031. $($t.grid.ubDiv).slideDown("fast");
  4032. }
  4033. $($t.grid.uDiv).slideDown("fast");
  4034. }
  4035. if($t.p.footerrow) { $(".ui-jqgrid-sdiv","#gbox_"+$.jgrid.jqID($t.p.id)).slideDown("fast"); }
  4036. $(".ui-jqgrid-titlebar-close span",$t.grid.cDiv).removeClass("ui-icon-circle-triangle-s").addClass("ui-icon-circle-triangle-n");
  4037. $t.p.gridstate = 'visible';
  4038. }
  4039. });
  4040. },
  4041. filterToolbar : function(p){
  4042. p = $.extend({
  4043. autosearch: true,
  4044. searchOnEnter : true,
  4045. beforeSearch: null,
  4046. afterSearch: null,
  4047. beforeClear: null,
  4048. afterClear: null,
  4049. searchurl : '',
  4050. stringResult: false,
  4051. groupOp: 'AND',
  4052. defaultSearch : "bw",
  4053. searchOperators : false,
  4054. resetIcon : "x",
  4055. operands : { "eq" :"==", "ne":"!","lt":"<","le":"<=","gt":">","ge":">=","bw":"^","bn":"!^","in":"=","ni":"!=","ew":"|","en":"!@","cn":"~","nc":"!~","nu":"#","nn":"!#"}
  4056. }, $.jgrid.search , p || {});
  4057. return this.each(function(){
  4058. var $t = this;
  4059. if(this.ftoolbar) { return; }
  4060. var triggerToolbar = function() {
  4061. var sdata={}, j=0, v, nm, sopt={},so;
  4062. $.each($t.p.colModel,function(){
  4063. var $elem = $("#gs_"+$.jgrid.jqID(this.name), (this.frozen===true && $t.p.frozenColumns === true) ? $t.grid.fhDiv : $t.grid.hDiv);
  4064. nm = this.index || this.name;
  4065. if(p.searchOperators ) {
  4066. so = $elem.parent().prev().children("a").attr("soper") || p.defaultSearch;
  4067. } else {
  4068. so = (this.searchoptions && this.searchoptions.sopt) ? this.searchoptions.sopt[0] : this.stype==='select'? 'eq' : p.defaultSearch;
  4069. }
  4070. v = this.stype === "custom" && $.isFunction(this.searchoptions.custom_value) && $elem.length > 0 && $elem[0].nodeName.toUpperCase() === "SPAN" ?
  4071. this.searchoptions.custom_value.call($t, $elem.children(".customelement:first"), "get") :
  4072. $elem.val();
  4073. if(v || so==="nu" || so==="nn") {
  4074. sdata[nm] = v;
  4075. sopt[nm] = so;
  4076. j++;
  4077. } else {
  4078. try {
  4079. delete $t.p.postData[nm];
  4080. } catch (z) {}
  4081. }
  4082. });
  4083. var sd = j>0 ? true : false;
  4084. if(p.stringResult === true || $t.p.datatype === "local") {
  4085. var ruleGroup = "{\"groupOp\":\"" + p.groupOp + "\",\"rules\":[";
  4086. var gi=0;
  4087. $.each(sdata,function(i,n){
  4088. if (gi > 0) {ruleGroup += ",";}
  4089. ruleGroup += "{\"field\":\"" + i + "\",";
  4090. ruleGroup += "\"op\":\"" + sopt[i] + "\",";
  4091. n+="";
  4092. ruleGroup += "\"data\":\"" + n.replace(/\\/g,'\\\\').replace(/\"/g,'\\"') + "\"}";
  4093. gi++;
  4094. });
  4095. ruleGroup += "]}";
  4096. $.extend($t.p.postData,{filters:ruleGroup});
  4097. $.each(['searchField', 'searchString', 'searchOper'], function(i, n){
  4098. if($t.p.postData.hasOwnProperty(n)) { delete $t.p.postData[n];}
  4099. });
  4100. } else {
  4101. $.extend($t.p.postData,sdata);
  4102. }
  4103. var saveurl;
  4104. if($t.p.searchurl) {
  4105. saveurl = $t.p.url;
  4106. $($t).jqGrid("setGridParam",{url:$t.p.searchurl});
  4107. }
  4108. var bsr = $($t).triggerHandler("jqGridToolbarBeforeSearch") === 'stop' ? true : false;
  4109. if(!bsr && $.isFunction(p.beforeSearch)){bsr = p.beforeSearch.call($t);}
  4110. if(!bsr) { $($t).jqGrid("setGridParam",{search:sd}).trigger("reloadGrid",[{page:1}]); }
  4111. if(saveurl) {$($t).jqGrid("setGridParam",{url:saveurl});}
  4112. $($t).triggerHandler("jqGridToolbarAfterSearch");
  4113. if($.isFunction(p.afterSearch)){p.afterSearch.call($t);}
  4114. },
  4115. clearToolbar = function(trigger){
  4116. var sdata={}, j=0, nm;
  4117. trigger = (typeof trigger !== 'boolean') ? true : trigger;
  4118. $.each($t.p.colModel,function(){
  4119. var v, $elem = $("#gs_"+$.jgrid.jqID(this.name),(this.frozen===true && $t.p.frozenColumns === true) ? $t.grid.fhDiv : $t.grid.hDiv);
  4120. if(this.searchoptions && this.searchoptions.defaultValue !== undefined) { v = this.searchoptions.defaultValue; }
  4121. nm = this.index || this.name;
  4122. switch (this.stype) {
  4123. case 'select' :
  4124. $elem.find("option").each(function (i){
  4125. if(i===0) { this.selected = true; }
  4126. if ($(this).val() === v) {
  4127. this.selected = true;
  4128. return false;
  4129. }
  4130. });
  4131. if ( v !== undefined ) {
  4132. // post the key and not the text
  4133. sdata[nm] = v;
  4134. j++;
  4135. } else {
  4136. try {
  4137. delete $t.p.postData[nm];
  4138. } catch(e) {}
  4139. }
  4140. break;
  4141. case 'text':
  4142. $elem.val(v || "");
  4143. if(v !== undefined) {
  4144. sdata[nm] = v;
  4145. j++;
  4146. } else {
  4147. try {
  4148. delete $t.p.postData[nm];
  4149. } catch (y){}
  4150. }
  4151. break;
  4152. case 'custom':
  4153. if ($.isFunction(this.searchoptions.custom_value) && $elem.length > 0 && $elem[0].nodeName.toUpperCase() === "SPAN") {
  4154. this.searchoptions.custom_value.call($t, $elem.children(".customelement:first"), "set", v || "");
  4155. }
  4156. break;
  4157. }
  4158. });
  4159. var sd = j>0 ? true : false;
  4160. $t.p.resetsearch = true;
  4161. if(p.stringResult === true || $t.p.datatype === "local") {
  4162. var ruleGroup = "{\"groupOp\":\"" + p.groupOp + "\",\"rules\":[";
  4163. var gi=0;
  4164. $.each(sdata,function(i,n){
  4165. if (gi > 0) {ruleGroup += ",";}
  4166. ruleGroup += "{\"field\":\"" + i + "\",";
  4167. ruleGroup += "\"op\":\"" + "eq" + "\",";
  4168. n+="";
  4169. ruleGroup += "\"data\":\"" + n.replace(/\\/g,'\\\\').replace(/\"/g,'\\"') + "\"}";
  4170. gi++;
  4171. });
  4172. ruleGroup += "]}";
  4173. $.extend($t.p.postData,{filters:ruleGroup});
  4174. $.each(['searchField', 'searchString', 'searchOper'], function(i, n){
  4175. if($t.p.postData.hasOwnProperty(n)) { delete $t.p.postData[n];}
  4176. });
  4177. } else {
  4178. $.extend($t.p.postData,sdata);
  4179. }
  4180. var saveurl;
  4181. if($t.p.searchurl) {
  4182. saveurl = $t.p.url;
  4183. $($t).jqGrid("setGridParam",{url:$t.p.searchurl});
  4184. }
  4185. var bcv = $($t).triggerHandler("jqGridToolbarBeforeClear") === 'stop' ? true : false;
  4186. if(!bcv && $.isFunction(p.beforeClear)){bcv = p.beforeClear.call($t);}
  4187. if(!bcv) {
  4188. if(trigger) {
  4189. $($t).jqGrid("setGridParam",{search:sd}).trigger("reloadGrid",[{page:1}]);
  4190. }
  4191. }
  4192. if(saveurl) {$($t).jqGrid("setGridParam",{url:saveurl});}
  4193. $($t).triggerHandler("jqGridToolbarAfterClear");
  4194. if($.isFunction(p.afterClear)){p.afterClear();}
  4195. },
  4196. toggleToolbar = function(){
  4197. var trow = $("tr.ui-search-toolbar",$t.grid.hDiv),
  4198. trow2 = $t.p.frozenColumns === true ? $("tr.ui-search-toolbar",$t.grid.fhDiv) : false;
  4199. if(trow.css("display") === 'none') {
  4200. trow.show();
  4201. if(trow2) {
  4202. trow2.show();
  4203. }
  4204. } else {
  4205. trow.hide();
  4206. if(trow2) {
  4207. trow2.hide();
  4208. }
  4209. }
  4210. },
  4211. buildRuleMenu = function( elem, left, top ){
  4212. $("#sopt_menu").remove();
  4213. left=parseInt(left,10);
  4214. top=parseInt(top,10) + 18;
  4215. var fs = $('.ui-jqgrid-view').css('font-size') || '11px';
  4216. var str = '<ul id="sopt_menu" class="ui-search-menu" role="menu" tabindex="0" style="font-size:'+fs+';left:'+left+'px;top:'+top+'px;">',
  4217. selected = $(elem).attr("soper"), selclass,
  4218. aoprs = [], ina;
  4219. var i=0, nm =$(elem).attr("colname"),len = $t.p.colModel.length;
  4220. while(i<len) {
  4221. if($t.p.colModel[i].name === nm) {
  4222. break;
  4223. }
  4224. i++;
  4225. }
  4226. var cm = $t.p.colModel[i], options = $.extend({}, cm.searchoptions);
  4227. if(!options.sopt) {
  4228. options.sopt = [];
  4229. options.sopt[0]= cm.stype==='select' ? 'eq' : p.defaultSearch;
  4230. }
  4231. $.each(p.odata, function() { aoprs.push(this.oper); });
  4232. for ( i = 0 ; i < options.sopt.length; i++) {
  4233. ina = $.inArray(options.sopt[i],aoprs);
  4234. if(ina !== -1) {
  4235. selclass = selected === p.odata[ina].oper ? "ui-state-highlight" : "";
  4236. str += '<li class="ui-menu-item '+selclass+'" role="presentation"><a class="ui-corner-all g-menu-item" tabindex="0" role="menuitem" value="'+p.odata[ina].oper+'" oper="'+p.operands[p.odata[ina].oper]+'"><table cellspacing="0" cellpadding="0" border="0"><tr><td width="25px">'+p.operands[p.odata[ina].oper]+'</td><td>'+ p.odata[ina].text+'</td></tr></table></a></li>';
  4237. }
  4238. }
  4239. str += "</ul>";
  4240. $('body').append(str);
  4241. $("#sopt_menu").addClass("ui-menu ui-widget ui-widget-content ui-corner-all");
  4242. $("#sopt_menu > li > a").hover(
  4243. function(){ $(this).addClass("ui-state-hover"); },
  4244. function(){ $(this).removeClass("ui-state-hover"); }
  4245. ).click(function( e ){
  4246. var v = $(this).attr("value"),
  4247. oper = $(this).attr("oper");
  4248. $($t).triggerHandler("jqGridToolbarSelectOper", [v, oper, elem]);
  4249. $("#sopt_menu").hide();
  4250. $(elem).text(oper).attr("soper",v);
  4251. if(p.autosearch===true){
  4252. var inpelm = $(elem).parent().next().children()[0];
  4253. if( $(inpelm).val() || v==="nu" || v ==="nn") {
  4254. triggerToolbar();
  4255. }
  4256. }
  4257. });
  4258. };
  4259. // create the row
  4260. var tr = $("<tr class='ui-search-toolbar' role='rowheader'></tr>");
  4261. var timeoutHnd;
  4262. $.each($t.p.colModel,function(ci){
  4263. var cm=this, soptions, surl, self, select = "", sot="=", so, i,
  4264. th = $("<th role='columnheader' class='ui-state-default ui-th-column ui-th-"+$t.p.direction+"'></th>"),
  4265. thd = $("<div style='position:relative;height:100%;padding-right:0.3em;padding-left:0.3em;'></div>"),
  4266. stbl = $("<table class='ui-search-table' cellspacing='0'><tr><td class='ui-search-oper'></td><td class='ui-search-input'></td><td class='ui-search-clear'></td></tr></table>");
  4267. if(this.hidden===true) { $(th).css("display","none");}
  4268. this.search = this.search === false ? false : true;
  4269. if(this.stype === undefined) {this.stype='text';}
  4270. soptions = $.extend({},this.searchoptions || {});
  4271. if(this.search){
  4272. if(p.searchOperators) {
  4273. so = (soptions.sopt) ? soptions.sopt[0] : cm.stype==='select' ? 'eq' : p.defaultSearch;
  4274. for(i = 0;i<p.odata.length;i++) {
  4275. if(p.odata[i].oper === so) {
  4276. sot = p.operands[so] || "";
  4277. break;
  4278. }
  4279. }
  4280. var st = soptions.searchtitle != null ? soptions.searchtitle : p.operandTitle;
  4281. select = "<a title='"+st+"' style='padding-right: 0.5em;' soper='"+so+"' class='soptclass' colname='"+this.name+"'>"+sot+"</a>";
  4282. }
  4283. $("td:eq(0)",stbl).attr("colindex",ci).append(select);
  4284. if(soptions.clearSearch === undefined) {
  4285. soptions.clearSearch = true;
  4286. }
  4287. if(soptions.clearSearch) {
  4288. var csv = p.resetTitle || 'Clear Search Value';
  4289. $("td:eq(2)",stbl).append("<a title='"+csv+"' style='padding-right: 0.3em;padding-left: 0.3em;' class='clearsearchclass'>"+p.resetIcon+"</a>");
  4290. } else {
  4291. $("td:eq(2)", stbl).hide();
  4292. }
  4293. switch (this.stype)
  4294. {
  4295. case "select":
  4296. surl = this.surl || soptions.dataUrl;
  4297. if(surl) {
  4298. // data returned should have already constructed html select
  4299. // primitive jQuery load
  4300. self = thd;
  4301. $(self).append(stbl);
  4302. $.ajax($.extend({
  4303. url: surl,
  4304. dataType: "html",
  4305. success: function(res) {
  4306. if(soptions.buildSelect !== undefined) {
  4307. var d = soptions.buildSelect(res);
  4308. if (d) {
  4309. $("td:eq(1)",stbl).append(d);
  4310. }
  4311. } else {
  4312. $("td:eq(1)",stbl).append(res);
  4313. }
  4314. if(soptions.defaultValue !== undefined) { $("select",self).val(soptions.defaultValue); }
  4315. $("select",self).attr({name:cm.index || cm.name, id: "gs_"+cm.name});
  4316. if(soptions.attr) {$("select",self).attr(soptions.attr);}
  4317. $("select",self).css({width: "100%"});
  4318. // preserve autoserch
  4319. $.jgrid.bindEv.call($t, $("select",self)[0], soptions);
  4320. if(p.autosearch===true){
  4321. $("select",self).change(function(){
  4322. triggerToolbar();
  4323. return false;
  4324. });
  4325. }
  4326. res=null;
  4327. }
  4328. }, $.jgrid.ajaxOptions, $t.p.ajaxSelectOptions || {} ));
  4329. } else {
  4330. var oSv, sep, delim;
  4331. if(cm.searchoptions) {
  4332. oSv = cm.searchoptions.value === undefined ? "" : cm.searchoptions.value;
  4333. sep = cm.searchoptions.separator === undefined ? ":" : cm.searchoptions.separator;
  4334. delim = cm.searchoptions.delimiter === undefined ? ";" : cm.searchoptions.delimiter;
  4335. } else if(cm.editoptions) {
  4336. oSv = cm.editoptions.value === undefined ? "" : cm.editoptions.value;
  4337. sep = cm.editoptions.separator === undefined ? ":" : cm.editoptions.separator;
  4338. delim = cm.editoptions.delimiter === undefined ? ";" : cm.editoptions.delimiter;
  4339. }
  4340. if (oSv) {
  4341. var elem = document.createElement("select");
  4342. elem.style.width = "100%";
  4343. $(elem).attr({name:cm.index || cm.name, id: "gs_"+cm.name});
  4344. var sv, ov, key, k;
  4345. if(typeof oSv === "string") {
  4346. so = oSv.split(delim);
  4347. for(k=0; k<so.length;k++){
  4348. sv = so[k].split(sep);
  4349. ov = document.createElement("option");
  4350. ov.value = sv[0]; ov.innerHTML = sv[1];
  4351. elem.appendChild(ov);
  4352. }
  4353. } else if(typeof oSv === "object" ) {
  4354. for (key in oSv) {
  4355. if(oSv.hasOwnProperty(key)) {
  4356. ov = document.createElement("option");
  4357. ov.value = key; ov.innerHTML = oSv[key];
  4358. elem.appendChild(ov);
  4359. }
  4360. }
  4361. }
  4362. if(soptions.defaultValue !== undefined) { $(elem).val(soptions.defaultValue); }
  4363. if(soptions.attr) {$(elem).attr(soptions.attr);}
  4364. $(thd).append(stbl);
  4365. $.jgrid.bindEv.call($t, elem , soptions);
  4366. $("td:eq(1)",stbl).append( elem );
  4367. if(p.autosearch===true){
  4368. $(elem).change(function(){
  4369. triggerToolbar();
  4370. return false;
  4371. });
  4372. }
  4373. }
  4374. }
  4375. break;
  4376. case "text":
  4377. var df = soptions.defaultValue !== undefined ? soptions.defaultValue: "";
  4378. $("td:eq(1)",stbl).append("<input type='text' style='width:100%;padding:0px;' name='"+(cm.index || cm.name)+"' id='gs_"+cm.name+"' value='"+df+"'/>");
  4379. $(thd).append(stbl);
  4380. if(soptions.attr) {$("input",thd).attr(soptions.attr);}
  4381. $.jgrid.bindEv.call($t, $("input",thd)[0], soptions);
  4382. if(p.autosearch===true){
  4383. if(p.searchOnEnter) {
  4384. $("input",thd).keypress(function(e){
  4385. var key = e.charCode || e.keyCode || 0;
  4386. if(key === 13){
  4387. triggerToolbar();
  4388. return false;
  4389. }
  4390. return this;
  4391. });
  4392. } else {
  4393. $("input",thd).keydown(function(e){
  4394. var key = e.which;
  4395. switch (key) {
  4396. case 13:
  4397. return false;
  4398. case 9 :
  4399. case 16:
  4400. case 37:
  4401. case 38:
  4402. case 39:
  4403. case 40:
  4404. case 27:
  4405. break;
  4406. default :
  4407. if(timeoutHnd) { clearTimeout(timeoutHnd); }
  4408. timeoutHnd = setTimeout(function(){triggerToolbar();},500);
  4409. }
  4410. });
  4411. }
  4412. }
  4413. break;
  4414. case "custom":
  4415. $("td:eq(1)",stbl).append("<span style='width:95%;padding:0px;' name='"+(cm.index || cm.name)+"' id='gs_"+cm.name+"'/>");
  4416. $(thd).append(stbl);
  4417. try {
  4418. if($.isFunction(soptions.custom_element)) {
  4419. var celm = soptions.custom_element.call($t,soptions.defaultValue !== undefined ? soptions.defaultValue: "",soptions);
  4420. if(celm) {
  4421. celm = $(celm).addClass("customelement");
  4422. $(thd).find(">span").append(celm);
  4423. } else {
  4424. throw "e2";
  4425. }
  4426. } else {
  4427. throw "e1";
  4428. }
  4429. } catch (e) {
  4430. if (e === "e1") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_element' "+$.jgrid.edit.msg.nodefined,$.jgrid.edit.bClose);}
  4431. if (e === "e2") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_element' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose);}
  4432. else { $.jgrid.info_dialog($.jgrid.errors.errcap,typeof e==="string"?e:e.message,$.jgrid.edit.bClose); }
  4433. }
  4434. break;
  4435. }
  4436. }
  4437. $(th).append(thd);
  4438. $(tr).append(th);
  4439. if(!p.searchOperators) {
  4440. $("td:eq(0)",stbl).hide();
  4441. }
  4442. });
  4443. $("table thead",$t.grid.hDiv).append(tr);
  4444. if(p.searchOperators) {
  4445. $(".soptclass",tr).click(function(e){
  4446. var offset = $(this).offset(),
  4447. left = ( offset.left ),
  4448. top = ( offset.top);
  4449. buildRuleMenu(this, left, top );
  4450. e.stopPropagation();
  4451. });
  4452. $("body").on('click', function(e){
  4453. if(e.target.className !== "soptclass") {
  4454. $("#sopt_menu").hide();
  4455. }
  4456. });
  4457. }
  4458. $(".clearsearchclass",tr).click(function(e){
  4459. var ptr = $(this).parents("tr:first"),
  4460. coli = parseInt($("td.ui-search-oper", ptr).attr('colindex'),10),
  4461. sval = $.extend({},$t.p.colModel[coli].searchoptions || {}),
  4462. dval = sval.defaultValue ? sval.defaultValue : "";
  4463. if($t.p.colModel[coli].stype === "select") {
  4464. if(dval) {
  4465. $("td.ui-search-input select", ptr).val( dval );
  4466. } else {
  4467. $("td.ui-search-input select", ptr)[0].selectedIndex = 0;
  4468. }
  4469. } else {
  4470. $("td.ui-search-input input", ptr).val( dval );
  4471. }
  4472. // ToDo custom search type
  4473. if(p.autosearch===true){
  4474. triggerToolbar();
  4475. }
  4476. });
  4477. this.ftoolbar = true;
  4478. this.triggerToolbar = triggerToolbar;
  4479. this.clearToolbar = clearToolbar;
  4480. this.toggleToolbar = toggleToolbar;
  4481. });
  4482. },
  4483. destroyFilterToolbar: function () {
  4484. return this.each(function () {
  4485. if (!this.ftoolbar) {
  4486. return;
  4487. }
  4488. this.triggerToolbar = null;
  4489. this.clearToolbar = null;
  4490. this.toggleToolbar = null;
  4491. this.ftoolbar = false;
  4492. $(this.grid.hDiv).find("table thead tr.ui-search-toolbar").remove();
  4493. });
  4494. },
  4495. destroyGroupHeader : function(nullHeader)
  4496. {
  4497. if(nullHeader === undefined) {
  4498. nullHeader = true;
  4499. }
  4500. return this.each(function()
  4501. {
  4502. var $t = this, $tr, i, l, headers, $th, $resizing, grid = $t.grid,
  4503. thead = $("table.ui-jqgrid-htable thead", grid.hDiv), cm = $t.p.colModel, hc;
  4504. if(!grid) { return; }
  4505. $(this).unbind('.setGroupHeaders');
  4506. $tr = $("<tr>", {role: "rowheader"}).addClass("ui-jqgrid-labels");
  4507. headers = grid.headers;
  4508. for (i = 0, l = headers.length; i < l; i++) {
  4509. hc = cm[i].hidden ? "none" : "";
  4510. $th = $(headers[i].el)
  4511. .width(headers[i].width)
  4512. .css('display',hc);
  4513. try {
  4514. $th.removeAttr("rowSpan");
  4515. } catch (rs) {
  4516. //IE 6/7
  4517. $th.attr("rowSpan",1);
  4518. }
  4519. $tr.append($th);
  4520. $resizing = $th.children("span.ui-jqgrid-resize");
  4521. if ($resizing.length>0) {// resizable column
  4522. $resizing[0].style.height = "";
  4523. }
  4524. $th.children("div")[0].style.top = "";
  4525. }
  4526. $(thead).children('tr.ui-jqgrid-labels').remove();
  4527. $(thead).prepend($tr);
  4528. if(nullHeader === true) {
  4529. $($t).jqGrid('setGridParam',{ 'groupHeader': null});
  4530. }
  4531. });
  4532. },
  4533. setGroupHeaders : function ( o ) {
  4534. o = $.extend({
  4535. useColSpanStyle : false,
  4536. groupHeaders: []
  4537. },o || {});
  4538. return this.each(function(){
  4539. this.p.groupHeader = o;
  4540. var ts = this,
  4541. i, cmi, skip = 0, $tr, $colHeader, th, $th, thStyle,
  4542. iCol,
  4543. cghi,
  4544. //startColumnName,
  4545. numberOfColumns,
  4546. titleText,
  4547. cVisibleColumns,
  4548. colModel = ts.p.colModel,
  4549. cml = colModel.length,
  4550. ths = ts.grid.headers,
  4551. $htable = $("table.ui-jqgrid-htable", ts.grid.hDiv),
  4552. $trLabels = $htable.children("thead").children("tr.ui-jqgrid-labels:last").addClass("jqg-second-row-header"),
  4553. $thead = $htable.children("thead"),
  4554. $theadInTable,
  4555. $firstHeaderRow = $htable.find(".jqg-first-row-header");
  4556. if($firstHeaderRow[0] === undefined) {
  4557. $firstHeaderRow = $('<tr>', {role: "row", "aria-hidden": "true"}).addClass("jqg-first-row-header").css("height", "auto");
  4558. } else {
  4559. $firstHeaderRow.empty();
  4560. }
  4561. var $firstRow,
  4562. inColumnHeader = function (text, columnHeaders) {
  4563. var length = columnHeaders.length, i;
  4564. for (i = 0; i < length; i++) {
  4565. if (columnHeaders[i].startColumnName === text) {
  4566. return i;
  4567. }
  4568. }
  4569. return -1;
  4570. };
  4571. $(ts).prepend($thead);
  4572. $tr = $('<tr>', {role: "rowheader"}).addClass("ui-jqgrid-labels jqg-third-row-header");
  4573. for (i = 0; i < cml; i++) {
  4574. th = ths[i].el;
  4575. $th = $(th);
  4576. cmi = colModel[i];
  4577. // build the next cell for the first header row
  4578. thStyle = { height: '0px', width: ths[i].width + 'px', display: (cmi.hidden ? 'none' : '')};
  4579. $("<th>", {role: 'gridcell'}).css(thStyle).addClass("ui-first-th-"+ts.p.direction).appendTo($firstHeaderRow);
  4580. th.style.width = ""; // remove unneeded style
  4581. iCol = inColumnHeader(cmi.name, o.groupHeaders);
  4582. if (iCol >= 0) {
  4583. cghi = o.groupHeaders[iCol];
  4584. numberOfColumns = cghi.numberOfColumns;
  4585. titleText = cghi.titleText;
  4586. // caclulate the number of visible columns from the next numberOfColumns columns
  4587. for (cVisibleColumns = 0, iCol = 0; iCol < numberOfColumns && (i + iCol < cml); iCol++) {
  4588. if (!colModel[i + iCol].hidden) {
  4589. cVisibleColumns++;
  4590. }
  4591. }
  4592. // The next numberOfColumns headers will be moved in the next row
  4593. // in the current row will be placed the new column header with the titleText.
  4594. // The text will be over the cVisibleColumns columns
  4595. $colHeader = $('<th>').attr({role: "columnheader"})
  4596. .addClass("ui-state-default ui-th-column-header ui-th-"+ts.p.direction)
  4597. .css({'height':'22px', 'border-top': '0 none'})
  4598. .html(titleText);
  4599. if(cVisibleColumns > 0) {
  4600. $colHeader.attr("colspan", String(cVisibleColumns));
  4601. }
  4602. if (ts.p.headertitles) {
  4603. $colHeader.attr("title", $colHeader.text());
  4604. }
  4605. // hide if not a visible cols
  4606. if( cVisibleColumns === 0) {
  4607. $colHeader.hide();
  4608. }
  4609. $th.before($colHeader); // insert new column header before the current
  4610. $tr.append(th); // move the current header in the next row
  4611. // set the coumter of headers which will be moved in the next row
  4612. skip = numberOfColumns - 1;
  4613. } else {
  4614. if (skip === 0) {
  4615. if (o.useColSpanStyle) {
  4616. // expand the header height to two rows
  4617. $th.attr("rowspan", "2");
  4618. } else {
  4619. $('<th>', {role: "columnheader"})
  4620. .addClass("ui-state-default ui-th-column-header ui-th-"+ts.p.direction)
  4621. .css({"display": cmi.hidden ? 'none' : '', 'border-top': '0 none'})
  4622. .insertBefore($th);
  4623. $tr.append(th);
  4624. }
  4625. } else {
  4626. // move the header to the next row
  4627. //$th.css({"padding-top": "2px", height: "19px"});
  4628. $tr.append(th);
  4629. skip--;
  4630. }
  4631. }
  4632. }
  4633. $theadInTable = $(ts).children("thead");
  4634. $theadInTable.prepend($firstHeaderRow);
  4635. $tr.insertAfter($trLabels);
  4636. $htable.append($theadInTable);
  4637. if (o.useColSpanStyle) {
  4638. // Increase the height of resizing span of visible headers
  4639. $htable.find("span.ui-jqgrid-resize").each(function () {
  4640. var $parent = $(this).parent();
  4641. if ($parent.is(":visible")) {
  4642. this.style.cssText = 'height: ' + $parent.height() + 'px !important; cursor: col-resize;';
  4643. }
  4644. });
  4645. // Set position of the sortable div (the main lable)
  4646. // with the column header text to the middle of the cell.
  4647. // One should not do this for hidden headers.
  4648. $htable.find("div.ui-jqgrid-sortable").each(function () {
  4649. var $ts = $(this), $parent = $ts.parent();
  4650. if ($parent.is(":visible") && $parent.is(":has(span.ui-jqgrid-resize)")) {
  4651. $ts.css('top', ($parent.height() - $ts.outerHeight()) / 2 + 'px');
  4652. }
  4653. });
  4654. }
  4655. $firstRow = $theadInTable.find("tr.jqg-first-row-header");
  4656. $(ts).bind('jqGridResizeStop.setGroupHeaders', function (e, nw, idx) {
  4657. $firstRow.find('th').eq(idx).width(nw);
  4658. });
  4659. });
  4660. },
  4661. setFrozenColumns : function () {
  4662. return this.each(function() {
  4663. if ( !this.grid ) {return;}
  4664. var $t = this, cm = $t.p.colModel,i=0, len = cm.length, maxfrozen = -1, frozen= false;
  4665. // TODO treeGrid and grouping Support
  4666. if($t.p.subGrid === true || $t.p.treeGrid === true || $t.p.cellEdit === true || $t.p.sortable || $t.p.scroll )
  4667. {
  4668. return;
  4669. }
  4670. if($t.p.rownumbers) { i++; }
  4671. if($t.p.multiselect) { i++; }
  4672. // get the max index of frozen col
  4673. while(i<len)
  4674. {
  4675. // from left, no breaking frozen
  4676. if(cm[i].frozen === true)
  4677. {
  4678. frozen = true;
  4679. maxfrozen = i;
  4680. } else {
  4681. break;
  4682. }
  4683. i++;
  4684. }
  4685. if( maxfrozen>=0 && frozen) {
  4686. var top = $t.p.caption ? $($t.grid.cDiv).outerHeight() : 0,
  4687. hth = $(".ui-jqgrid-htable","#gview_"+$.jgrid.jqID($t.p.id)).height();
  4688. //headers
  4689. if($t.p.toppager) {
  4690. top = top + $($t.grid.topDiv).outerHeight();
  4691. }
  4692. if($t.p.toolbar[0] === true) {
  4693. if($t.p.toolbar[1] !== "bottom") {
  4694. top = top + $($t.grid.uDiv).outerHeight();
  4695. }
  4696. }
  4697. $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>');
  4698. $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>');
  4699. $("#gview_"+$.jgrid.jqID($t.p.id)).append($t.grid.fhDiv);
  4700. var htbl = $(".ui-jqgrid-htable","#gview_"+$.jgrid.jqID($t.p.id)).clone(true);
  4701. // groupheader support - only if useColSpanstyle is false
  4702. if($t.p.groupHeader) {
  4703. $("tr.jqg-first-row-header, tr.jqg-third-row-header", htbl).each(function(){
  4704. $("th:gt("+maxfrozen+")",this).remove();
  4705. });
  4706. var swapfroz = -1, fdel = -1, cs, rs;
  4707. $("tr.jqg-second-row-header th", htbl).each(function(){
  4708. cs= parseInt($(this).attr("colspan"),10);
  4709. rs= parseInt($(this).attr("rowspan"),10);
  4710. if(rs) {
  4711. swapfroz++;
  4712. fdel++;
  4713. }
  4714. if(cs) {
  4715. swapfroz = swapfroz+cs;
  4716. fdel++;
  4717. }
  4718. if(swapfroz === maxfrozen) {
  4719. return false;
  4720. }
  4721. });
  4722. if(swapfroz !== maxfrozen) {
  4723. fdel = maxfrozen;
  4724. }
  4725. $("tr.jqg-second-row-header", htbl).each(function(){
  4726. $("th:gt("+fdel+")",this).remove();
  4727. });
  4728. } else {
  4729. $("tr",htbl).each(function(){
  4730. $("th:gt("+maxfrozen+")",this).remove();
  4731. });
  4732. }
  4733. $(htbl).width(1);
  4734. // resizing stuff
  4735. $($t.grid.fhDiv).append(htbl)
  4736. .mousemove(function (e) {
  4737. if($t.grid.resizing){ $t.grid.dragMove(e);return false; }
  4738. });
  4739. $($t).bind('jqGridResizeStop.setFrozenColumns', function (e, w, index) {
  4740. var rhth = $(".ui-jqgrid-htable",$t.grid.fhDiv);
  4741. $("th:eq("+index+")",rhth).width( w );
  4742. var btd = $(".ui-jqgrid-btable",$t.grid.fbDiv);
  4743. $("tr:first td:eq("+index+")",btd).width( w );
  4744. });
  4745. // sorting stuff
  4746. $($t).bind('jqGridSortCol.setFrozenColumns', function (e, index, idxcol) {
  4747. 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);
  4748. $("span.ui-grid-ico-sort",previousSelectedTh).addClass('ui-state-disabled');
  4749. $(previousSelectedTh).attr("aria-selected","false");
  4750. $("span.ui-icon-"+$t.p.sortorder,newSelectedTh).removeClass('ui-state-disabled');
  4751. $(newSelectedTh).attr("aria-selected","true");
  4752. if(!$t.p.viewsortcols[0]) {
  4753. if($t.p.lastsort !== idxcol) {
  4754. $("span.s-ico",previousSelectedTh).hide();
  4755. $("span.s-ico",newSelectedTh).show();
  4756. }
  4757. }
  4758. });
  4759. // data stuff
  4760. //TODO support for setRowData
  4761. $("#gview_"+$.jgrid.jqID($t.p.id)).append($t.grid.fbDiv);
  4762. $($t.grid.bDiv).scroll(function () {
  4763. $($t.grid.fbDiv).scrollTop($(this).scrollTop());
  4764. });
  4765. if($t.p.hoverrows === true) {
  4766. $("#"+$.jgrid.jqID($t.p.id)).unbind('mouseover').unbind('mouseout');
  4767. }
  4768. $($t).bind('jqGridAfterGridComplete.setFrozenColumns', function () {
  4769. $("#"+$.jgrid.jqID($t.p.id)+"_frozen").remove();
  4770. $($t.grid.fbDiv).height($($t.grid.bDiv).height()-16);
  4771. var btbl = $("#"+$.jgrid.jqID($t.p.id)).clone(true);
  4772. $("tr[role=row]",btbl).each(function(){
  4773. $("td[role=gridcell]:gt("+maxfrozen+")",this).remove();
  4774. });
  4775. $(btbl).width(1).attr("id",$t.p.id+"_frozen");
  4776. $($t.grid.fbDiv).append(btbl);
  4777. if($t.p.hoverrows === true) {
  4778. $("tr.jqgrow", btbl).hover(
  4779. function(){ $(this).addClass("ui-state-hover"); $("#"+$.jgrid.jqID(this.id), "#"+$.jgrid.jqID($t.p.id)).addClass("ui-state-hover"); },
  4780. function(){ $(this).removeClass("ui-state-hover"); $("#"+$.jgrid.jqID(this.id), "#"+$.jgrid.jqID($t.p.id)).removeClass("ui-state-hover"); }
  4781. );
  4782. $("tr.jqgrow", "#"+$.jgrid.jqID($t.p.id)).hover(
  4783. function(){ $(this).addClass("ui-state-hover"); $("#"+$.jgrid.jqID(this.id), "#"+$.jgrid.jqID($t.p.id)+"_frozen").addClass("ui-state-hover");},
  4784. function(){ $(this).removeClass("ui-state-hover"); $("#"+$.jgrid.jqID(this.id), "#"+$.jgrid.jqID($t.p.id)+"_frozen").removeClass("ui-state-hover"); }
  4785. );
  4786. }
  4787. btbl=null;
  4788. });
  4789. if(!$t.grid.hDiv.loading) {
  4790. $($t).triggerHandler("jqGridAfterGridComplete");
  4791. }
  4792. $t.p.frozenColumns = true;
  4793. }
  4794. });
  4795. },
  4796. destroyFrozenColumns : function() {
  4797. return this.each(function() {
  4798. if ( !this.grid ) {return;}
  4799. if(this.p.frozenColumns === true) {
  4800. var $t = this;
  4801. $($t.grid.fhDiv).remove();
  4802. $($t.grid.fbDiv).remove();
  4803. $t.grid.fhDiv = null; $t.grid.fbDiv=null;
  4804. $(this).unbind('.setFrozenColumns');
  4805. if($t.p.hoverrows === true) {
  4806. var ptr;
  4807. $("#"+$.jgrid.jqID($t.p.id)).bind('mouseover',function(e) {
  4808. ptr = $(e.target).closest("tr.jqgrow");
  4809. if($(ptr).attr("class") !== "ui-subgrid") {
  4810. $(ptr).addClass("ui-state-hover");
  4811. }
  4812. }).bind('mouseout',function(e) {
  4813. ptr = $(e.target).closest("tr.jqgrow");
  4814. $(ptr).removeClass("ui-state-hover");
  4815. });
  4816. }
  4817. this.p.frozenColumns = false;
  4818. }
  4819. });
  4820. }
  4821. });
  4822. })(jQuery);
  4823. /*
  4824. * jqModal - Minimalist Modaling with jQuery
  4825. * (http://dev.iceburg.net/jquery/jqmodal/)
  4826. *
  4827. * Copyright (c) 2007,2008 Brice Burgess <bhb@iceburg.net>
  4828. * Dual licensed under the MIT and GPL licenses:
  4829. * http://www.opensource.org/licenses/mit-license.php
  4830. * http://www.gnu.org/licenses/gpl.html
  4831. *
  4832. * $Version: 07/06/2008 +r13
  4833. */
  4834. (function($) {
  4835. $.fn.jqm=function(o){
  4836. var p={
  4837. overlay: 50,
  4838. closeoverlay : true,
  4839. overlayClass: 'jqmOverlay',
  4840. closeClass: 'jqmClose',
  4841. trigger: '.jqModal',
  4842. ajax: F,
  4843. ajaxText: '',
  4844. target: F,
  4845. modal: F,
  4846. toTop: F,
  4847. onShow: F,
  4848. onHide: F,
  4849. onLoad: F
  4850. };
  4851. return this.each(function(){if(this._jqm)return H[this._jqm].c=$.extend({},H[this._jqm].c,o);s++;this._jqm=s;
  4852. H[s]={c:$.extend(p,$.jqm.params,o),a:F,w:$(this).addClass('jqmID'+s),s:s};
  4853. if(p.trigger)$(this).jqmAddTrigger(p.trigger);
  4854. });};
  4855. $.fn.jqmAddClose=function(e){return hs(this,e,'jqmHide');};
  4856. $.fn.jqmAddTrigger=function(e){return hs(this,e,'jqmShow');};
  4857. $.fn.jqmShow=function(t){return this.each(function(){$.jqm.open(this._jqm,t);});};
  4858. $.fn.jqmHide=function(t){return this.each(function(){$.jqm.close(this._jqm,t)});};
  4859. $.jqm = {
  4860. hash:{},
  4861. 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);
  4862. if(c.modal) {if(!A[0])setTimeout(function(){L('bind');},1);A.push(s);}
  4863. else if(c.overlay > 0) {if(c.closeoverlay) h.w.jqmAddClose(o);}
  4864. else o=F;
  4865. h.o=(o)?o.addClass(c.overlayClass).prependTo('body'):F;
  4866. 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;
  4867. 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);});}
  4868. else if(cc)h.w.jqmAddClose($(cc,h.w));
  4869. if(c.toTop&&h.o)h.w.before('<span id="jqmP'+h.w[0]._jqm+'"></span>').insertAfter(h.o);
  4870. (c.onShow)?c.onShow(h):h.w.show();e(h);return F;
  4871. },
  4872. close:function(s){var h=H[s];if(!h.a)return F;h.a=F;
  4873. if(A[0]){A.pop();if(!A[0])L('unbind');}
  4874. if(h.c.toTop&&h.o)$('#jqmP'+h.w[0]._jqm).after(h.w).remove();
  4875. if(h.c.onHide)h.c.onHide(h);else{h.w.hide();if(h.o)h.o.remove();} return F;
  4876. },
  4877. params:{}};
  4878. var s=0,H=$.jqm.hash,A=[],F=false,
  4879. e=function(h){f(h);},
  4880. f=function(h){try{$(':input:visible',h.w)[0].focus();}catch(_){}},
  4881. L=function(t){$(document)[t]("keypress",m)[t]("keydown",m)[t]("mousedown",m);},
  4882. m=function(e){var h=H[A[A.length-1]],r=(!$(e.target).parents('.jqmID'+h.s)[0]);if(r){$('.jqmID'+h.s).each(function(){var $self=$(this),offset=$self.offset();if(offset.top<=e.pageY && e.pageY<=offset.top+$self.height() && offset.left<=e.pageX && e.pageX<=offset.left+$self.width()){r=false;return false;}});f(h);}return !r;},
  4883. hs=function(w,t,c){return w.each(function(){var s=this._jqm;$(t).each(function() {
  4884. 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);});});};
  4885. })(jQuery);/*
  4886. * jqDnR - Minimalistic Drag'n'Resize for jQuery.
  4887. *
  4888. * Copyright (c) 2007 Brice Burgess <bhb@iceburg.net>, http://www.iceburg.net
  4889. * Licensed under the MIT License:
  4890. * http://www.opensource.org/licenses/mit-license.php
  4891. *
  4892. * $Version: 2007.08.19 +r2
  4893. */
  4894. (function($){
  4895. $.fn.jqDrag=function(h){return i(this,h,'d');};
  4896. $.fn.jqResize=function(h,ar){return i(this,h,'r',ar);};
  4897. $.jqDnR={
  4898. dnr:{},
  4899. e:0,
  4900. drag:function(v){
  4901. if(M.k == 'd'){E.css({left:M.X+v.pageX-M.pX,top:M.Y+v.pageY-M.pY});}
  4902. else {
  4903. E.css({width:Math.max(v.pageX-M.pX+M.W,0),height:Math.max(v.pageY-M.pY+M.H,0)});
  4904. if(M1){E1.css({width:Math.max(v.pageX-M1.pX+M1.W,0),height:Math.max(v.pageY-M1.pY+M1.H,0)});}
  4905. }
  4906. return false;
  4907. },
  4908. stop:function(){
  4909. //E.css('opacity',M.o);
  4910. $(document).unbind('mousemove',J.drag).unbind('mouseup',J.stop);
  4911. }
  4912. };
  4913. var J=$.jqDnR,M=J.dnr,E=J.e,E1,M1,
  4914. i=function(e,h,k,aR){
  4915. return e.each(function(){
  4916. h=(h)?$(h,e):e;
  4917. h.bind('mousedown',{e:e,k:k},function(v){
  4918. var d=v.data,p={};E=d.e;E1 = aR ? $(aR) : false;
  4919. // attempt utilization of dimensions plugin to fix IE issues
  4920. if(E.css('position') != 'relative'){try{E.position(p);}catch(e){}}
  4921. M={
  4922. X:p.left||f('left')||0,
  4923. Y:p.top||f('top')||0,
  4924. W:f('width')||E[0].scrollWidth||0,
  4925. H:f('height')||E[0].scrollHeight||0,
  4926. pX:v.pageX,
  4927. pY:v.pageY,
  4928. k:d.k
  4929. //o:E.css('opacity')
  4930. };
  4931. // also resize
  4932. if(E1 && d.k != 'd'){
  4933. M1={
  4934. X:p.left||f1('left')||0,
  4935. Y:p.top||f1('top')||0,
  4936. W:E1[0].offsetWidth||f1('width')||0,
  4937. H:E1[0].offsetHeight||f1('height')||0,
  4938. pX:v.pageX,
  4939. pY:v.pageY,
  4940. k:d.k
  4941. };
  4942. } else {M1 = false;}
  4943. //E.css({opacity:0.8});
  4944. if($("input.hasDatepicker",E[0])[0]) {
  4945. try {$("input.hasDatepicker",E[0]).datepicker('hide');}catch (dpe){}
  4946. }
  4947. $(document).mousemove($.jqDnR.drag).mouseup($.jqDnR.stop);
  4948. return false;
  4949. });
  4950. });
  4951. },
  4952. f=function(k){return parseInt(E.css(k),10)||false;},
  4953. f1=function(k){return parseInt(E1.css(k),10)||false;};
  4954. })(jQuery);/*
  4955. The below work is licensed under Creative Commons GNU LGPL License.
  4956. Original work:
  4957. License: http://creativecommons.org/licenses/LGPL/2.1/
  4958. Author: Stefan Goessner/2006
  4959. Web: http://goessner.net/
  4960. Modifications made:
  4961. Version: 0.9-p5
  4962. Description: Restructured code, JSLint validated (no strict whitespaces),
  4963. added handling of empty arrays, empty strings, and int/floats values.
  4964. Author: Michael Schøler/2008-01-29
  4965. Web: http://michael.hinnerup.net/blog/2008/01/26/converting-json-to-xml-and-xml-to-json/
  4966. Description: json2xml added support to convert functions as CDATA
  4967. so it will be easy to write characters that cause some problems when convert
  4968. Author: Tony Tomov
  4969. */
  4970. /*global alert */
  4971. var xmlJsonClass = {
  4972. // Param "xml": Element or document DOM node.
  4973. // Param "tab": Tab or indent string for pretty output formatting omit or use empty string "" to supress.
  4974. // Returns: JSON string
  4975. xml2json: function(xml, tab) {
  4976. if (xml.nodeType === 9) {
  4977. // document node
  4978. xml = xml.documentElement;
  4979. }
  4980. var nws = this.removeWhite(xml);
  4981. var obj = this.toObj(nws);
  4982. var json = this.toJson(obj, xml.nodeName, "\t");
  4983. return "{\n" + tab + (tab ? json.replace(/\t/g, tab) : json.replace(/\t|\n/g, "")) + "\n}";
  4984. },
  4985. // Param "o": JavaScript object
  4986. // Param "tab": tab or indent string for pretty output formatting omit or use empty string "" to supress.
  4987. // Returns: XML string
  4988. json2xml: function(o, tab) {
  4989. var toXml = function(v, name, ind) {
  4990. var xml = "";
  4991. var i, n;
  4992. if (v instanceof Array) {
  4993. if (v.length === 0) {
  4994. xml += ind + "<"+name+">__EMPTY_ARRAY_</"+name+">\n";
  4995. }
  4996. else {
  4997. for (i = 0, n = v.length; i < n; i += 1) {
  4998. var sXml = ind + toXml(v[i], name, ind+"\t") + "\n";
  4999. xml += sXml;
  5000. }
  5001. }
  5002. }
  5003. else if (typeof(v) === "object") {
  5004. var hasChild = false;
  5005. xml += ind + "<" + name;
  5006. var m;
  5007. for (m in v) if (v.hasOwnProperty(m)) {
  5008. if (m.charAt(0) === "@") {
  5009. xml += " " + m.substr(1) + "=\"" + v[m].toString() + "\"";
  5010. }
  5011. else {
  5012. hasChild = true;
  5013. }
  5014. }
  5015. xml += hasChild ? ">" : "/>";
  5016. if (hasChild) {
  5017. for (m in v) if (v.hasOwnProperty(m)) {
  5018. if (m === "#text") {
  5019. xml += v[m];
  5020. }
  5021. else if (m === "#cdata") {
  5022. xml += "<![CDATA[" + v[m] + "]]>";
  5023. }
  5024. else if (m.charAt(0) !== "@") {
  5025. xml += toXml(v[m], m, ind+"\t");
  5026. }
  5027. }
  5028. xml += (xml.charAt(xml.length - 1) === "\n" ? ind : "") + "</" + name + ">";
  5029. }
  5030. }
  5031. else if (typeof(v) === "function") {
  5032. xml += ind + "<" + name + ">" + "<![CDATA[" + v + "]]>" + "</" + name + ">";
  5033. }
  5034. else {
  5035. if (v === undefined ) { v = ""; }
  5036. if (v.toString() === "\"\"" || v.toString().length === 0) {
  5037. xml += ind + "<" + name + ">__EMPTY_STRING_</" + name + ">";
  5038. }
  5039. else {
  5040. xml += ind + "<" + name + ">" + v.toString() + "</" + name + ">";
  5041. }
  5042. }
  5043. return xml;
  5044. };
  5045. var xml = "";
  5046. var m;
  5047. for (m in o) if (o.hasOwnProperty(m)) {
  5048. xml += toXml(o[m], m, "");
  5049. }
  5050. return tab ? xml.replace(/\t/g, tab) : xml.replace(/\t|\n/g, "");
  5051. },
  5052. // Internal methods
  5053. toObj: function(xml) {
  5054. var o = {};
  5055. var FuncTest = /function/i;
  5056. if (xml.nodeType === 1) {
  5057. // element node ..
  5058. if (xml.attributes.length) {
  5059. // element with attributes ..
  5060. var i;
  5061. for (i = 0; i < xml.attributes.length; i += 1) {
  5062. o["@" + xml.attributes[i].nodeName] = (xml.attributes[i].nodeValue || "").toString();
  5063. }
  5064. }
  5065. if (xml.firstChild) {
  5066. // element has child nodes ..
  5067. var textChild = 0, cdataChild = 0, hasElementChild = false;
  5068. var n;
  5069. for (n = xml.firstChild; n; n = n.nextSibling) {
  5070. if (n.nodeType === 1) {
  5071. hasElementChild = true;
  5072. }
  5073. else if (n.nodeType === 3 && n.nodeValue.match(/[^ \f\n\r\t\v]/)) {
  5074. // non-whitespace text
  5075. textChild += 1;
  5076. }
  5077. else if (n.nodeType === 4) {
  5078. // cdata section node
  5079. cdataChild += 1;
  5080. }
  5081. }
  5082. if (hasElementChild) {
  5083. if (textChild < 2 && cdataChild < 2) {
  5084. // structured element with evtl. a single text or/and cdata node ..
  5085. this.removeWhite(xml);
  5086. for (n = xml.firstChild; n; n = n.nextSibling) {
  5087. if (n.nodeType === 3) {
  5088. // text node
  5089. o["#text"] = this.escape(n.nodeValue);
  5090. }
  5091. else if (n.nodeType === 4) {
  5092. // cdata node
  5093. if (FuncTest.test(n.nodeValue)) {
  5094. o[n.nodeName] = [o[n.nodeName], n.nodeValue];
  5095. } else {
  5096. o["#cdata"] = this.escape(n.nodeValue);
  5097. }
  5098. }
  5099. else if (o[n.nodeName]) {
  5100. // multiple occurence of element ..
  5101. if (o[n.nodeName] instanceof Array) {
  5102. o[n.nodeName][o[n.nodeName].length] = this.toObj(n);
  5103. }
  5104. else {
  5105. o[n.nodeName] = [o[n.nodeName], this.toObj(n)];
  5106. }
  5107. }
  5108. else {
  5109. // first occurence of element ..
  5110. o[n.nodeName] = this.toObj(n);
  5111. }
  5112. }
  5113. }
  5114. else {
  5115. // mixed content
  5116. if (!xml.attributes.length) {
  5117. o = this.escape(this.innerXml(xml));
  5118. }
  5119. else {
  5120. o["#text"] = this.escape(this.innerXml(xml));
  5121. }
  5122. }
  5123. }
  5124. else if (textChild) {
  5125. // pure text
  5126. if (!xml.attributes.length) {
  5127. o = this.escape(this.innerXml(xml));
  5128. if (o === "__EMPTY_ARRAY_") {
  5129. o = "[]";
  5130. } else if (o === "__EMPTY_STRING_") {
  5131. o = "";
  5132. }
  5133. }
  5134. else {
  5135. o["#text"] = this.escape(this.innerXml(xml));
  5136. }
  5137. }
  5138. else if (cdataChild) {
  5139. // cdata
  5140. if (cdataChild > 1) {
  5141. o = this.escape(this.innerXml(xml));
  5142. }
  5143. else {
  5144. for (n = xml.firstChild; n; n = n.nextSibling) {
  5145. if(FuncTest.test(xml.firstChild.nodeValue)) {
  5146. o = xml.firstChild.nodeValue;
  5147. break;
  5148. } else {
  5149. o["#cdata"] = this.escape(n.nodeValue);
  5150. }
  5151. }
  5152. }
  5153. }
  5154. }
  5155. if (!xml.attributes.length && !xml.firstChild) {
  5156. o = null;
  5157. }
  5158. }
  5159. else if (xml.nodeType === 9) {
  5160. // document.node
  5161. o = this.toObj(xml.documentElement);
  5162. }
  5163. else {
  5164. alert("unhandled node type: " + xml.nodeType);
  5165. }
  5166. return o;
  5167. },
  5168. toJson: function(o, name, ind, wellform) {
  5169. if(wellform === undefined) wellform = true;
  5170. var json = name ? ("\"" + name + "\"") : "", tab = "\t", newline = "\n";
  5171. if(!wellform) {
  5172. tab= ""; newline= "";
  5173. }
  5174. if (o === "[]") {
  5175. json += (name ? ":[]" : "[]");
  5176. }
  5177. else if (o instanceof Array) {
  5178. var n, i, ar=[];
  5179. for (i = 0, n = o.length; i < n; i += 1) {
  5180. ar[i] = this.toJson(o[i], "", ind + tab, wellform);
  5181. }
  5182. json += (name ? ":[" : "[") + (ar.length > 1 ? (newline + ind + tab + ar.join(","+newline + ind + tab) + newline + ind) : ar.join("")) + "]";
  5183. }
  5184. else if (o === null) {
  5185. json += (name && ":") + "null";
  5186. }
  5187. else if (typeof(o) === "object") {
  5188. var arr = [], m;
  5189. for (m in o) {
  5190. if (o.hasOwnProperty(m)) {
  5191. arr[arr.length] = this.toJson(o[m], m, ind + tab, wellform);
  5192. }
  5193. }
  5194. json += (name ? ":{" : "{") + (arr.length > 1 ? (newline + ind + tab + arr.join(","+newline + ind + tab) + newline + ind) : arr.join("")) + "}";
  5195. }
  5196. else if (typeof(o) === "string") {
  5197. /*
  5198. var objRegExp = /(^-?\d+\.?\d*$)/;
  5199. var FuncTest = /function/i;
  5200. var os = o.toString();
  5201. if (objRegExp.test(os) || FuncTest.test(os) || os==="false" || os==="true") {
  5202. // int or float
  5203. json += (name && ":") + "\"" +os + "\"";
  5204. }
  5205. else {
  5206. */
  5207. json += (name && ":") + "\"" + o.replace(/\\/g,'\\\\').replace(/\"/g,'\\"') + "\"";
  5208. //}
  5209. }
  5210. else {
  5211. json += (name && ":") + o.toString();
  5212. }
  5213. return json;
  5214. },
  5215. innerXml: function(node) {
  5216. var s = "";
  5217. if ("innerHTML" in node) {
  5218. s = node.innerHTML;
  5219. }
  5220. else {
  5221. var asXml = function(n) {
  5222. var s = "", i;
  5223. if (n.nodeType === 1) {
  5224. s += "<" + n.nodeName;
  5225. for (i = 0; i < n.attributes.length; i += 1) {
  5226. s += " " + n.attributes[i].nodeName + "=\"" + (n.attributes[i].nodeValue || "").toString() + "\"";
  5227. }
  5228. if (n.firstChild) {
  5229. s += ">";
  5230. for (var c = n.firstChild; c; c = c.nextSibling) {
  5231. s += asXml(c);
  5232. }
  5233. s += "</" + n.nodeName + ">";
  5234. }
  5235. else {
  5236. s += "/>";
  5237. }
  5238. }
  5239. else if (n.nodeType === 3) {
  5240. s += n.nodeValue;
  5241. }
  5242. else if (n.nodeType === 4) {
  5243. s += "<![CDATA[" + n.nodeValue + "]]>";
  5244. }
  5245. return s;
  5246. };
  5247. for (var c = node.firstChild; c; c = c.nextSibling) {
  5248. s += asXml(c);
  5249. }
  5250. }
  5251. return s;
  5252. },
  5253. escape: function(txt) {
  5254. return txt.replace(/[\\]/g, "\\\\").replace(/[\"]/g, '\\"').replace(/[\n]/g, '\\n').replace(/[\r]/g, '\\r');
  5255. },
  5256. removeWhite: function(e) {
  5257. e.normalize();
  5258. var n;
  5259. for (n = e.firstChild; n; ) {
  5260. if (n.nodeType === 3) {
  5261. // text node
  5262. if (!n.nodeValue.match(/[^ \f\n\r\t\v]/)) {
  5263. // pure whitespace text node
  5264. var nxt = n.nextSibling;
  5265. e.removeChild(n);
  5266. n = nxt;
  5267. }
  5268. else {
  5269. n = n.nextSibling;
  5270. }
  5271. }
  5272. else if (n.nodeType === 1) {
  5273. // element node
  5274. this.removeWhite(n);
  5275. n = n.nextSibling;
  5276. }
  5277. else {
  5278. // any other node
  5279. n = n.nextSibling;
  5280. }
  5281. }
  5282. return e;
  5283. }
  5284. };/*
  5285. **
  5286. * formatter for values but most of the values if for jqGrid
  5287. * Some of this was inspired and based on how YUI does the table datagrid but in jQuery fashion
  5288. * we are trying to keep it as light as possible
  5289. * Joshua Burnett josh@9ci.com
  5290. * http://www.greenbill.com
  5291. *
  5292. * Changes from Tony Tomov tony@trirand.com
  5293. * Dual licensed under the MIT and GPL licenses:
  5294. * http://www.opensource.org/licenses/mit-license.php
  5295. * http://www.gnu.org/licenses/gpl-2.0.html
  5296. *
  5297. **/
  5298. /*jshint eqeqeq:false */
  5299. /*global jQuery */
  5300. (function($) {
  5301. "use strict";
  5302. $.fmatter = {};
  5303. //opts can be id:row id for the row, rowdata:the data for the row, colmodel:the column model for this column
  5304. //example {id:1234,}
  5305. $.extend($.fmatter,{
  5306. isBoolean : function(o) {
  5307. return typeof o === 'boolean';
  5308. },
  5309. isObject : function(o) {
  5310. return (o && (typeof o === 'object' || $.isFunction(o))) || false;
  5311. },
  5312. isString : function(o) {
  5313. return typeof o === 'string';
  5314. },
  5315. isNumber : function(o) {
  5316. return typeof o === 'number' && isFinite(o);
  5317. },
  5318. isValue : function (o) {
  5319. return (this.isObject(o) || this.isString(o) || this.isNumber(o) || this.isBoolean(o));
  5320. },
  5321. isEmpty : function(o) {
  5322. if(!this.isString(o) && this.isValue(o)) {
  5323. return false;
  5324. }
  5325. if (!this.isValue(o)){
  5326. return true;
  5327. }
  5328. o = $.trim(o).replace(/\&nbsp\;/ig,'').replace(/\&#160\;/ig,'');
  5329. return o==="";
  5330. }
  5331. });
  5332. $.fn.fmatter = function(formatType, cellval, opts, rwd, act) {
  5333. // build main options before element iteration
  5334. var v=cellval;
  5335. opts = $.extend({}, $.jgrid.formatter, opts);
  5336. try {
  5337. v = $.fn.fmatter[formatType].call(this, cellval, opts, rwd, act);
  5338. } catch(fe){}
  5339. return v;
  5340. };
  5341. $.fmatter.util = {
  5342. // Taken from YAHOO utils
  5343. NumberFormat : function(nData,opts) {
  5344. if(!$.fmatter.isNumber(nData)) {
  5345. nData *= 1;
  5346. }
  5347. if($.fmatter.isNumber(nData)) {
  5348. var bNegative = (nData < 0);
  5349. var sOutput = String(nData);
  5350. var sDecimalSeparator = opts.decimalSeparator || ".";
  5351. var nDotIndex;
  5352. if($.fmatter.isNumber(opts.decimalPlaces)) {
  5353. // Round to the correct decimal place
  5354. var nDecimalPlaces = opts.decimalPlaces;
  5355. var nDecimal = Math.pow(10, nDecimalPlaces);
  5356. sOutput = String(Math.round(nData*nDecimal)/nDecimal);
  5357. nDotIndex = sOutput.lastIndexOf(".");
  5358. if(nDecimalPlaces > 0) {
  5359. // Add the decimal separator
  5360. if(nDotIndex < 0) {
  5361. sOutput += sDecimalSeparator;
  5362. nDotIndex = sOutput.length-1;
  5363. }
  5364. // Replace the "."
  5365. else if(sDecimalSeparator !== "."){
  5366. sOutput = sOutput.replace(".",sDecimalSeparator);
  5367. }
  5368. // Add missing zeros
  5369. while((sOutput.length - 1 - nDotIndex) < nDecimalPlaces) {
  5370. sOutput += "0";
  5371. }
  5372. }
  5373. }
  5374. if(opts.thousandsSeparator) {
  5375. var sThousandsSeparator = opts.thousandsSeparator;
  5376. nDotIndex = sOutput.lastIndexOf(sDecimalSeparator);
  5377. nDotIndex = (nDotIndex > -1) ? nDotIndex : sOutput.length;
  5378. var sNewOutput = sOutput.substring(nDotIndex);
  5379. var nCount = -1, i;
  5380. for (i=nDotIndex; i>0; i--) {
  5381. nCount++;
  5382. if ((nCount%3 === 0) && (i !== nDotIndex) && (!bNegative || (i > 1))) {
  5383. sNewOutput = sThousandsSeparator + sNewOutput;
  5384. }
  5385. sNewOutput = sOutput.charAt(i-1) + sNewOutput;
  5386. }
  5387. sOutput = sNewOutput;
  5388. }
  5389. // Prepend prefix
  5390. sOutput = (opts.prefix) ? opts.prefix + sOutput : sOutput;
  5391. // Append suffix
  5392. sOutput = (opts.suffix) ? sOutput + opts.suffix : sOutput;
  5393. return sOutput;
  5394. }
  5395. return nData;
  5396. }
  5397. };
  5398. $.fn.fmatter.defaultFormat = function(cellval, opts) {
  5399. return ($.fmatter.isValue(cellval) && cellval!=="" ) ? cellval : opts.defaultValue || "&#160;";
  5400. };
  5401. $.fn.fmatter.email = function(cellval, opts) {
  5402. if(!$.fmatter.isEmpty(cellval)) {
  5403. return "<a href=\"mailto:" + cellval + "\">" + cellval + "</a>";
  5404. }
  5405. return $.fn.fmatter.defaultFormat(cellval,opts );
  5406. };
  5407. $.fn.fmatter.checkbox =function(cval, opts) {
  5408. var op = $.extend({},opts.checkbox), ds;
  5409. if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
  5410. op = $.extend({},op,opts.colModel.formatoptions);
  5411. }
  5412. if(op.disabled===true) {ds = "disabled=\"disabled\"";} else {ds="";}
  5413. if($.fmatter.isEmpty(cval) || cval === undefined ) {cval = $.fn.fmatter.defaultFormat(cval,op);}
  5414. cval=String(cval);
  5415. cval=(cval+"").toLowerCase();
  5416. var bchk = cval.search(/(false|f|0|no|n|off|undefined)/i)<0 ? " checked='checked' " : "";
  5417. return "<input type=\"checkbox\" " + bchk + " value=\""+ cval+"\" offval=\"no\" "+ds+ "/>";
  5418. };
  5419. $.fn.fmatter.link = function(cellval, opts) {
  5420. var op = {target:opts.target};
  5421. var target = "";
  5422. if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
  5423. op = $.extend({},op,opts.colModel.formatoptions);
  5424. }
  5425. if(op.target) {target = 'target=' + op.target;}
  5426. if(!$.fmatter.isEmpty(cellval)) {
  5427. return "<a "+target+" href=\"" + cellval + "\">" + cellval + "</a>";
  5428. }
  5429. return $.fn.fmatter.defaultFormat(cellval,opts);
  5430. };
  5431. $.fn.fmatter.showlink = function(cellval, opts) {
  5432. var op = {baseLinkUrl: opts.baseLinkUrl,showAction:opts.showAction, addParam: opts.addParam || "", target: opts.target, idName: opts.idName},
  5433. target = "", idUrl;
  5434. if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
  5435. op = $.extend({},op,opts.colModel.formatoptions);
  5436. }
  5437. if(op.target) {target = 'target=' + op.target;}
  5438. idUrl = op.baseLinkUrl+op.showAction + '?'+ op.idName+'='+opts.rowId+op.addParam;
  5439. if($.fmatter.isString(cellval) || $.fmatter.isNumber(cellval)) { //add this one even if its blank string
  5440. return "<a "+target+" href=\"" + idUrl + "\">" + cellval + "</a>";
  5441. }
  5442. return $.fn.fmatter.defaultFormat(cellval,opts);
  5443. };
  5444. $.fn.fmatter.integer = function(cellval, opts) {
  5445. var op = $.extend({},opts.integer);
  5446. if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
  5447. op = $.extend({},op,opts.colModel.formatoptions);
  5448. }
  5449. if($.fmatter.isEmpty(cellval)) {
  5450. return op.defaultValue;
  5451. }
  5452. return $.fmatter.util.NumberFormat(cellval,op);
  5453. };
  5454. $.fn.fmatter.number = function (cellval, opts) {
  5455. var op = $.extend({},opts.number);
  5456. if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
  5457. op = $.extend({},op,opts.colModel.formatoptions);
  5458. }
  5459. if($.fmatter.isEmpty(cellval)) {
  5460. return op.defaultValue;
  5461. }
  5462. return $.fmatter.util.NumberFormat(cellval,op);
  5463. };
  5464. $.fn.fmatter.currency = function (cellval, opts) {
  5465. var op = $.extend({},opts.currency);
  5466. if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
  5467. op = $.extend({},op,opts.colModel.formatoptions);
  5468. }
  5469. if($.fmatter.isEmpty(cellval)) {
  5470. return op.defaultValue;
  5471. }
  5472. return $.fmatter.util.NumberFormat(cellval,op);
  5473. };
  5474. $.fn.fmatter.date = function (cellval, opts, rwd, act) {
  5475. var op = $.extend({},opts.date);
  5476. if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
  5477. op = $.extend({},op,opts.colModel.formatoptions);
  5478. }
  5479. if(!op.reformatAfterEdit && act === 'edit'){
  5480. return $.fn.fmatter.defaultFormat(cellval, opts);
  5481. }
  5482. if(!$.fmatter.isEmpty(cellval)) {
  5483. return $.jgrid.parseDate(op.srcformat,cellval,op.newformat,op);
  5484. }
  5485. return $.fn.fmatter.defaultFormat(cellval, opts);
  5486. };
  5487. $.fn.fmatter.select = function (cellval,opts) {
  5488. // jqGrid specific
  5489. cellval = String(cellval);
  5490. var oSelect = false, ret=[], sep, delim;
  5491. if(opts.colModel.formatoptions !== undefined){
  5492. oSelect= opts.colModel.formatoptions.value;
  5493. sep = opts.colModel.formatoptions.separator === undefined ? ":" : opts.colModel.formatoptions.separator;
  5494. delim = opts.colModel.formatoptions.delimiter === undefined ? ";" : opts.colModel.formatoptions.delimiter;
  5495. } else if(opts.colModel.editoptions !== undefined){
  5496. oSelect= opts.colModel.editoptions.value;
  5497. sep = opts.colModel.editoptions.separator === undefined ? ":" : opts.colModel.editoptions.separator;
  5498. delim = opts.colModel.editoptions.delimiter === undefined ? ";" : opts.colModel.editoptions.delimiter;
  5499. }
  5500. if (oSelect) {
  5501. var msl = opts.colModel.editoptions.multiple === true ? true : false,
  5502. scell = [], sv;
  5503. if(msl) {scell = cellval.split(",");scell = $.map(scell,function(n){return $.trim(n);});}
  5504. if ($.fmatter.isString(oSelect)) {
  5505. // mybe here we can use some caching with care ????
  5506. var so = oSelect.split(delim), j=0, i;
  5507. for(i=0; i<so.length;i++){
  5508. sv = so[i].split(sep);
  5509. if(sv.length > 2 ) {
  5510. sv[1] = $.map(sv,function(n,i){if(i>0) {return n;}}).join(sep);
  5511. }
  5512. if(msl) {
  5513. if($.inArray(sv[0],scell)>-1) {
  5514. ret[j] = sv[1];
  5515. j++;
  5516. }
  5517. } else if($.trim(sv[0]) === $.trim(cellval)) {
  5518. ret[0] = sv[1];
  5519. break;
  5520. }
  5521. }
  5522. } else if($.fmatter.isObject(oSelect)) {
  5523. // this is quicker
  5524. if(msl) {
  5525. ret = $.map(scell, function(n){
  5526. return oSelect[n];
  5527. });
  5528. } else {
  5529. ret[0] = oSelect[cellval] || "";
  5530. }
  5531. }
  5532. }
  5533. cellval = ret.join(", ");
  5534. return cellval === "" ? $.fn.fmatter.defaultFormat(cellval,opts) : cellval;
  5535. };
  5536. $.fn.fmatter.rowactions = function(act) {
  5537. var $tr = $(this).closest("tr.jqgrow"),
  5538. rid = $tr.attr("id"),
  5539. $id = $(this).closest("table.ui-jqgrid-btable").attr('id').replace(/_frozen([^_]*)$/,'$1'),
  5540. $grid = $("#"+$id),
  5541. $t = $grid[0],
  5542. p = $t.p,
  5543. cm = p.colModel[$.jgrid.getCellIndex(this)],
  5544. $actionsDiv = cm.frozen ? $("tr#"+rid+" td:eq("+$.jgrid.getCellIndex(this)+") > div",$grid) :$(this).parent(),
  5545. op = {
  5546. extraparam: {}
  5547. },
  5548. saverow = function(rowid, res) {
  5549. if($.isFunction(op.afterSave)) { op.afterSave.call($t, rowid, res); }
  5550. $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show();
  5551. $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide();
  5552. },
  5553. restorerow = function(rowid) {
  5554. if($.isFunction(op.afterRestore)) { op.afterRestore.call($t, rowid); }
  5555. $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show();
  5556. $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide();
  5557. };
  5558. if (cm.formatoptions !== undefined) {
  5559. op = $.extend(op,cm.formatoptions);
  5560. }
  5561. if (p.editOptions !== undefined) {
  5562. op.editOptions = p.editOptions;
  5563. }
  5564. if (p.delOptions !== undefined) {
  5565. op.delOptions = p.delOptions;
  5566. }
  5567. if ($tr.hasClass("jqgrid-new-row")){
  5568. op.extraparam[p.prmNames.oper] = p.prmNames.addoper;
  5569. }
  5570. var actop = {
  5571. keys: op.keys,
  5572. oneditfunc: op.onEdit,
  5573. successfunc: op.onSuccess,
  5574. url: op.url,
  5575. extraparam: op.extraparam,
  5576. aftersavefunc: saverow,
  5577. errorfunc: op.onError,
  5578. afterrestorefunc: restorerow,
  5579. restoreAfterError: op.restoreAfterError,
  5580. mtype: op.mtype
  5581. };
  5582. switch(act)
  5583. {
  5584. case 'edit':
  5585. $grid.jqGrid('editRow', rid, actop);
  5586. $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").hide();
  5587. $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").show();
  5588. $grid.triggerHandler("jqGridAfterGridComplete");
  5589. break;
  5590. case 'save':
  5591. if ($grid.jqGrid('saveRow', rid, actop)) {
  5592. $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show();
  5593. $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide();
  5594. $grid.triggerHandler("jqGridAfterGridComplete");
  5595. }
  5596. break;
  5597. case 'cancel' :
  5598. $grid.jqGrid('restoreRow', rid, restorerow);
  5599. $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show();
  5600. $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide();
  5601. $grid.triggerHandler("jqGridAfterGridComplete");
  5602. break;
  5603. case 'del':
  5604. $grid.jqGrid('delGridRow', rid, op.delOptions);
  5605. break;
  5606. case 'formedit':
  5607. $grid.jqGrid('setSelection', rid);
  5608. $grid.jqGrid('editGridRow', rid, op.editOptions);
  5609. break;
  5610. }
  5611. };
  5612. $.fn.fmatter.actions = function(cellval,opts) {
  5613. var op={keys:false, editbutton:true, delbutton:true, editformbutton: false},
  5614. rowid=opts.rowId, str="",ocl;
  5615. if(opts.colModel.formatoptions !== undefined) {
  5616. op = $.extend(op,opts.colModel.formatoptions);
  5617. }
  5618. if(rowid === undefined || $.fmatter.isEmpty(rowid)) {return "";}
  5619. if(op.editformbutton){
  5620. ocl = "id='jEditButton_"+rowid+"' onclick=jQuery.fn.fmatter.rowactions.call(this,'formedit'); onmouseover=jQuery(this).addClass('ui-state-hover'); onmouseout=jQuery(this).removeClass('ui-state-hover'); ";
  5621. 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>";
  5622. } else if(op.editbutton){
  5623. ocl = "id='jEditButton_"+rowid+"' onclick=jQuery.fn.fmatter.rowactions.call(this,'edit'); onmouseover=jQuery(this).addClass('ui-state-hover'); onmouseout=jQuery(this).removeClass('ui-state-hover') ";
  5624. 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>";
  5625. }
  5626. if(op.delbutton) {
  5627. ocl = "id='jDeleteButton_"+rowid+"' onclick=jQuery.fn.fmatter.rowactions.call(this,'del'); onmouseover=jQuery(this).addClass('ui-state-hover'); onmouseout=jQuery(this).removeClass('ui-state-hover'); ";
  5628. 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>";
  5629. }
  5630. ocl = "id='jSaveButton_"+rowid+"' onclick=jQuery.fn.fmatter.rowactions.call(this,'save'); onmouseover=jQuery(this).addClass('ui-state-hover'); onmouseout=jQuery(this).removeClass('ui-state-hover'); ";
  5631. 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>";
  5632. ocl = "id='jCancelButton_"+rowid+"' onclick=jQuery.fn.fmatter.rowactions.call(this,'cancel'); onmouseover=jQuery(this).addClass('ui-state-hover'); onmouseout=jQuery(this).removeClass('ui-state-hover'); ";
  5633. 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>";
  5634. return "<div style='margin-left:8px;'>" + str + "</div>";
  5635. };
  5636. $.unformat = function (cellval,options,pos,cnt) {
  5637. // specific for jqGrid only
  5638. var ret, formatType = options.colModel.formatter,
  5639. op =options.colModel.formatoptions || {}, sep,
  5640. re = /([\.\*\_\'\(\)\{\}\+\?\\])/g,
  5641. unformatFunc = options.colModel.unformat||($.fn.fmatter[formatType] && $.fn.fmatter[formatType].unformat);
  5642. if(unformatFunc !== undefined && $.isFunction(unformatFunc) ) {
  5643. ret = unformatFunc.call(this, $(cellval).text(), options, cellval);
  5644. } else if(formatType !== undefined && $.fmatter.isString(formatType) ) {
  5645. var opts = $.jgrid.formatter || {}, stripTag;
  5646. switch(formatType) {
  5647. case 'integer' :
  5648. op = $.extend({},opts.integer,op);
  5649. sep = op.thousandsSeparator.replace(re,"\\$1");
  5650. stripTag = new RegExp(sep, "g");
  5651. ret = $(cellval).text().replace(stripTag,'');
  5652. break;
  5653. case 'number' :
  5654. op = $.extend({},opts.number,op);
  5655. sep = op.thousandsSeparator.replace(re,"\\$1");
  5656. stripTag = new RegExp(sep, "g");
  5657. ret = $(cellval).text().replace(stripTag,"").replace(op.decimalSeparator,'.');
  5658. break;
  5659. case 'currency':
  5660. op = $.extend({},opts.currency,op);
  5661. sep = op.thousandsSeparator.replace(re,"\\$1");
  5662. stripTag = new RegExp(sep, "g");
  5663. ret = $(cellval).text();
  5664. if (op.prefix && op.prefix.length) {
  5665. ret = ret.substr(op.prefix.length);
  5666. }
  5667. if (op.suffix && op.suffix.length) {
  5668. ret = ret.substr(0, ret.length - op.suffix.length);
  5669. }
  5670. ret = ret.replace(stripTag,'').replace(op.decimalSeparator,'.');
  5671. break;
  5672. case 'checkbox':
  5673. var cbv = (options.colModel.editoptions) ? options.colModel.editoptions.value.split(":") : ["Yes","No"];
  5674. ret = $('input',cellval).is(":checked") ? cbv[0] : cbv[1];
  5675. break;
  5676. case 'select' :
  5677. ret = $.unformat.select(cellval,options,pos,cnt);
  5678. break;
  5679. case 'actions':
  5680. return "";
  5681. default:
  5682. ret= $(cellval).text();
  5683. }
  5684. }
  5685. return ret !== undefined ? ret : cnt===true ? $(cellval).text() : $.jgrid.htmlDecode($(cellval).html());
  5686. };
  5687. $.unformat.select = function (cellval,options,pos,cnt) {
  5688. // Spacial case when we have local data and perform a sort
  5689. // cnt is set to true only in sortDataArray
  5690. var ret = [];
  5691. var cell = $(cellval).text();
  5692. if(cnt===true) {return cell;}
  5693. var op = $.extend({}, options.colModel.formatoptions !== undefined ? options.colModel.formatoptions: options.colModel.editoptions),
  5694. sep = op.separator === undefined ? ":" : op.separator,
  5695. delim = op.delimiter === undefined ? ";" : op.delimiter;
  5696. if(op.value){
  5697. var oSelect = op.value,
  5698. msl = op.multiple === true ? true : false,
  5699. scell = [], sv;
  5700. if(msl) {scell = cell.split(",");scell = $.map(scell,function(n){return $.trim(n);});}
  5701. if ($.fmatter.isString(oSelect)) {
  5702. var so = oSelect.split(delim), j=0, i;
  5703. for(i=0; i<so.length;i++){
  5704. sv = so[i].split(sep);
  5705. if(sv.length > 2 ) {
  5706. sv[1] = $.map(sv,function(n,i){if(i>0) {return n;}}).join(sep);
  5707. }
  5708. if(msl) {
  5709. if($.inArray(sv[1],scell)>-1) {
  5710. ret[j] = sv[0];
  5711. j++;
  5712. }
  5713. } else if($.trim(sv[1]) === $.trim(cell)) {
  5714. ret[0] = sv[0];
  5715. break;
  5716. }
  5717. }
  5718. } else if($.fmatter.isObject(oSelect) || $.isArray(oSelect) ){
  5719. if(!msl) {scell[0] = cell;}
  5720. ret = $.map(scell, function(n){
  5721. var rv;
  5722. $.each(oSelect, function(i,val){
  5723. if (val === n) {
  5724. rv = i;
  5725. return false;
  5726. }
  5727. });
  5728. if( rv !== undefined ) {return rv;}
  5729. });
  5730. }
  5731. return ret.join(", ");
  5732. }
  5733. return cell || "";
  5734. };
  5735. $.unformat.date = function (cellval, opts) {
  5736. var op = $.jgrid.formatter.date || {};
  5737. if(opts.formatoptions !== undefined) {
  5738. op = $.extend({},op,opts.formatoptions);
  5739. }
  5740. if(!$.fmatter.isEmpty(cellval)) {
  5741. return $.jgrid.parseDate(op.newformat,cellval,op.srcformat,op);
  5742. }
  5743. return $.fn.fmatter.defaultFormat(cellval, opts);
  5744. };
  5745. })(jQuery);
  5746. /*jshint eqeqeq:false */
  5747. /*global jQuery */
  5748. (function($){
  5749. /*
  5750. * jqGrid common function
  5751. * Tony Tomov tony@trirand.com
  5752. * http://trirand.com/blog/
  5753. * Dual licensed under the MIT and GPL licenses:
  5754. * http://www.opensource.org/licenses/mit-license.php
  5755. * http://www.gnu.org/licenses/gpl-2.0.html
  5756. */
  5757. "use strict";
  5758. $.extend($.jgrid,{
  5759. // Modal functions
  5760. showModal : function(h) {
  5761. h.w.show();
  5762. },
  5763. closeModal : function(h) {
  5764. h.w.hide().attr("aria-hidden","true");
  5765. if(h.o) {h.o.remove();}
  5766. },
  5767. hideModal : function (selector,o) {
  5768. o = $.extend({jqm : true, gb :''}, o || {});
  5769. if(o.onClose) {
  5770. 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);
  5771. if (typeof oncret === 'boolean' && !oncret ) { return; }
  5772. }
  5773. if ($.fn.jqm && o.jqm === true) {
  5774. $(selector).attr("aria-hidden","true").jqmHide();
  5775. } else {
  5776. if(o.gb !== '') {
  5777. try {$(".jqgrid-overlay:first",o.gb).hide();} catch (e){}
  5778. }
  5779. $(selector).hide().attr("aria-hidden","true");
  5780. }
  5781. },
  5782. //Helper functions
  5783. findPos : function(obj) {
  5784. var curleft = 0, curtop = 0;
  5785. if (obj.offsetParent) {
  5786. do {
  5787. curleft += obj.offsetLeft;
  5788. curtop += obj.offsetTop;
  5789. } while (obj = obj.offsetParent);
  5790. //do not change obj == obj.offsetParent
  5791. }
  5792. return [curleft,curtop];
  5793. },
  5794. createModal : function(aIDs, content, p, insertSelector, posSelector, appendsel, css) {
  5795. p = $.extend(true, {}, $.jgrid.jqModal || {}, p);
  5796. var mw = document.createElement('div'), rtlsup, self = this;
  5797. css = $.extend({}, css || {});
  5798. rtlsup = $(p.gbox).attr("dir") === "rtl" ? true : false;
  5799. mw.className= "ui-widget ui-widget-content ui-corner-all ui-jqdialog";
  5800. mw.id = aIDs.themodal;
  5801. var mh = document.createElement('div');
  5802. mh.className = "ui-jqdialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix";
  5803. mh.id = aIDs.modalhead;
  5804. $(mh).append("<span class='ui-jqdialog-title'>"+p.caption+"</span>");
  5805. var ahr= $("<a class='ui-jqdialog-titlebar-close ui-corner-all'></a>")
  5806. .hover(function(){ahr.addClass('ui-state-hover');},
  5807. function(){ahr.removeClass('ui-state-hover');})
  5808. .append("<span class='ui-icon ui-icon-closethick'></span>");
  5809. $(mh).append(ahr);
  5810. if(rtlsup) {
  5811. mw.dir = "rtl";
  5812. $(".ui-jqdialog-title",mh).css("float","right");
  5813. $(".ui-jqdialog-titlebar-close",mh).css("left",0.3+"em");
  5814. } else {
  5815. mw.dir = "ltr";
  5816. $(".ui-jqdialog-title",mh).css("float","left");
  5817. $(".ui-jqdialog-titlebar-close",mh).css("right",0.3+"em");
  5818. }
  5819. var mc = document.createElement('div');
  5820. $(mc).addClass("ui-jqdialog-content ui-widget-content").attr("id",aIDs.modalcontent);
  5821. $(mc).append(content);
  5822. mw.appendChild(mc);
  5823. $(mw).prepend(mh);
  5824. if(appendsel===true) { $('body').append(mw); } //append as first child in body -for alert dialog
  5825. else if (typeof appendsel === "string") {
  5826. $(appendsel).append(mw);
  5827. } else {$(mw).insertBefore(insertSelector);}
  5828. $(mw).css(css);
  5829. if(p.jqModal === undefined) {p.jqModal = true;} // internal use
  5830. var coord = {};
  5831. if ( $.fn.jqm && p.jqModal === true) {
  5832. if(p.left ===0 && p.top===0 && p.overlay) {
  5833. var pos = [];
  5834. pos = $.jgrid.findPos(posSelector);
  5835. p.left = pos[0] + 4;
  5836. p.top = pos[1] + 4;
  5837. }
  5838. coord.top = p.top+"px";
  5839. coord.left = p.left;
  5840. } else if(p.left !==0 || p.top!==0) {
  5841. coord.left = p.left;
  5842. coord.top = p.top+"px";
  5843. }
  5844. $("a.ui-jqdialog-titlebar-close",mh).click(function(){
  5845. var oncm = $("#"+$.jgrid.jqID(aIDs.themodal)).data("onClose") || p.onClose;
  5846. var gboxclose = $("#"+$.jgrid.jqID(aIDs.themodal)).data("gbox") || p.gbox;
  5847. self.hideModal("#"+$.jgrid.jqID(aIDs.themodal),{gb:gboxclose,jqm:p.jqModal,onClose:oncm});
  5848. return false;
  5849. });
  5850. if (p.width === 0 || !p.width) {p.width = 300;}
  5851. if(p.height === 0 || !p.height) {p.height =200;}
  5852. if(!p.zIndex) {
  5853. var parentZ = $(insertSelector).parents("*[role=dialog]").filter(':first').css("z-index");
  5854. if(parentZ) {
  5855. p.zIndex = parseInt(parentZ,10)+2;
  5856. } else {
  5857. p.zIndex = 950;
  5858. }
  5859. }
  5860. var rtlt = 0;
  5861. if( rtlsup && coord.left && !appendsel) {
  5862. rtlt = $(p.gbox).width()- (!isNaN(p.width) ? parseInt(p.width,10) :0) - 8; // to do
  5863. // just in case
  5864. coord.left = parseInt(coord.left,10) + parseInt(rtlt,10);
  5865. }
  5866. if(coord.left) { coord.left += "px"; }
  5867. $(mw).css($.extend({
  5868. width: isNaN(p.width) ? "auto": p.width+"px",
  5869. height:isNaN(p.height) ? "auto" : p.height + "px",
  5870. zIndex:p.zIndex,
  5871. overflow: 'hidden'
  5872. },coord))
  5873. .attr({tabIndex: "-1","role":"dialog","aria-labelledby":aIDs.modalhead,"aria-hidden":"true"});
  5874. if(p.drag === undefined) { p.drag=true;}
  5875. if(p.resize === undefined) {p.resize=true;}
  5876. if (p.drag) {
  5877. $(mh).css('cursor','move');
  5878. if($.fn.jqDrag) {
  5879. $(mw).jqDrag(mh);
  5880. } else {
  5881. try {
  5882. $(mw).draggable({handle: $("#"+$.jgrid.jqID(mh.id))});
  5883. } catch (e) {}
  5884. }
  5885. }
  5886. if(p.resize) {
  5887. if($.fn.jqResize) {
  5888. $(mw).append("<div class='jqResize ui-resizable-handle ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se'></div>");
  5889. $("#"+$.jgrid.jqID(aIDs.themodal)).jqResize(".jqResize",aIDs.scrollelm ? "#"+$.jgrid.jqID(aIDs.scrollelm) : false);
  5890. } else {
  5891. try {
  5892. $(mw).resizable({handles: 'se, sw',alsoResize: aIDs.scrollelm ? "#"+$.jgrid.jqID(aIDs.scrollelm) : false});
  5893. } catch (r) {}
  5894. }
  5895. }
  5896. if(p.closeOnEscape === true){
  5897. $(mw).keydown( function( e ) {
  5898. if( e.which == 27 ) {
  5899. var cone = $("#"+$.jgrid.jqID(aIDs.themodal)).data("onClose") || p.onClose;
  5900. self.hideModal("#"+$.jgrid.jqID(aIDs.themodal),{gb:p.gbox,jqm:p.jqModal,onClose: cone});
  5901. }
  5902. });
  5903. }
  5904. },
  5905. viewModal : function (selector,o){
  5906. o = $.extend({
  5907. toTop: true,
  5908. overlay: 10,
  5909. modal: false,
  5910. overlayClass : 'ui-widget-overlay',
  5911. onShow: $.jgrid.showModal,
  5912. onHide: $.jgrid.closeModal,
  5913. gbox: '',
  5914. jqm : true,
  5915. jqM : true
  5916. }, o || {});
  5917. if ($.fn.jqm && o.jqm === true) {
  5918. if(o.jqM) { $(selector).attr("aria-hidden","false").jqm(o).jqmShow(); }
  5919. else {$(selector).attr("aria-hidden","false").jqmShow();}
  5920. } else {
  5921. if(o.gbox !== '') {
  5922. $(".jqgrid-overlay:first",o.gbox).show();
  5923. $(selector).data("gbox",o.gbox);
  5924. }
  5925. $(selector).show().attr("aria-hidden","false");
  5926. try{$(':input:visible',selector)[0].focus();}catch(_){}
  5927. }
  5928. },
  5929. info_dialog : function(caption, content,c_b, modalopt) {
  5930. var mopt = {
  5931. width:290,
  5932. height:'auto',
  5933. dataheight: 'auto',
  5934. drag: true,
  5935. resize: false,
  5936. left:250,
  5937. top:170,
  5938. zIndex : 1000,
  5939. jqModal : true,
  5940. modal : false,
  5941. closeOnEscape : true,
  5942. align: 'center',
  5943. buttonalign : 'center',
  5944. buttons : []
  5945. // {text:'textbutt', id:"buttid", onClick : function(){...}}
  5946. // 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...
  5947. };
  5948. $.extend(true, mopt, $.jgrid.jqModal || {}, {caption:"<b>"+caption+"</b>"}, modalopt || {});
  5949. var jm = mopt.jqModal, self = this;
  5950. if($.fn.jqm && !jm) { jm = false; }
  5951. // in case there is no jqModal
  5952. var buttstr ="", i;
  5953. if(mopt.buttons.length > 0) {
  5954. for(i=0;i<mopt.buttons.length;i++) {
  5955. if(mopt.buttons[i].id === undefined) { mopt.buttons[i].id = "info_button_"+i; }
  5956. buttstr += "<a id='"+mopt.buttons[i].id+"' class='fm-button ui-state-default ui-corner-all'>"+mopt.buttons[i].text+"</a>";
  5957. }
  5958. }
  5959. var dh = isNaN(mopt.dataheight) ? mopt.dataheight : mopt.dataheight+"px",
  5960. cn = "text-align:"+mopt.align+";";
  5961. var cnt = "<div id='info_id'>";
  5962. cnt += "<div id='infocnt' style='margin:0px;padding-bottom:1em;width:100%;overflow:auto;position:relative;height:"+dh+";"+cn+"'>"+content+"</div>";
  5963. 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 id='closedialog' class='fm-button ui-state-default ui-corner-all'>"+c_b+"</a>"+buttstr+"</div>" :
  5964. 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>" : "";
  5965. cnt += "</div>";
  5966. try {
  5967. if($("#info_dialog").attr("aria-hidden") === "false") {
  5968. $.jgrid.hideModal("#info_dialog",{jqm:jm});
  5969. }
  5970. $("#info_dialog").remove();
  5971. } catch (e){}
  5972. $.jgrid.createModal({
  5973. themodal:'info_dialog',
  5974. modalhead:'info_head',
  5975. modalcontent:'info_content',
  5976. scrollelm: 'infocnt'},
  5977. cnt,
  5978. mopt,
  5979. '','',true
  5980. );
  5981. // attach onclick after inserting into the dom
  5982. if(buttstr) {
  5983. $.each(mopt.buttons,function(i){
  5984. $("#"+$.jgrid.jqID(this.id),"#info_id").bind('click',function(){mopt.buttons[i].onClick.call($("#info_dialog")); return false;});
  5985. });
  5986. }
  5987. $("#closedialog", "#info_id").click(function(){
  5988. self.hideModal("#info_dialog",{
  5989. jqm:jm,
  5990. onClose: $("#info_dialog").data("onClose") || mopt.onClose,
  5991. gb: $("#info_dialog").data("gbox") || mopt.gbox
  5992. });
  5993. return false;
  5994. });
  5995. $(".fm-button","#info_dialog").hover(
  5996. function(){$(this).addClass('ui-state-hover');},
  5997. function(){$(this).removeClass('ui-state-hover');}
  5998. );
  5999. if($.isFunction(mopt.beforeOpen) ) { mopt.beforeOpen(); }
  6000. $.jgrid.viewModal("#info_dialog",{
  6001. onHide: function(h) {
  6002. h.w.hide().remove();
  6003. if(h.o) { h.o.remove(); }
  6004. },
  6005. modal :mopt.modal,
  6006. jqm:jm
  6007. });
  6008. if($.isFunction(mopt.afterOpen) ) { mopt.afterOpen(); }
  6009. try{ $("#info_dialog").focus();} catch (m){}
  6010. },
  6011. bindEv: function (el, opt) {
  6012. var $t = this;
  6013. if($.isFunction(opt.dataInit)) {
  6014. opt.dataInit.call($t,el,opt);
  6015. }
  6016. if(opt.dataEvents) {
  6017. $.each(opt.dataEvents, function() {
  6018. if (this.data !== undefined) {
  6019. $(el).bind(this.type, this.data, this.fn);
  6020. } else {
  6021. $(el).bind(this.type, this.fn);
  6022. }
  6023. });
  6024. }
  6025. },
  6026. // Form Functions
  6027. createEl : function(eltype,options,vl,autowidth, ajaxso) {
  6028. var elem = "", $t = this;
  6029. function setAttributes(elm, atr, exl ) {
  6030. var exclude = ['dataInit','dataEvents','dataUrl', 'buildSelect','sopt', 'searchhidden', 'defaultValue', 'attr', 'custom_element', 'custom_value'];
  6031. if(exl !== undefined && $.isArray(exl)) {
  6032. $.merge(exclude, exl);
  6033. }
  6034. $.each(atr, function(key, value){
  6035. if($.inArray(key, exclude) === -1) {
  6036. $(elm).attr(key,value);
  6037. }
  6038. });
  6039. if(!atr.hasOwnProperty('id')) {
  6040. $(elm).attr('id', $.jgrid.randId());
  6041. }
  6042. }
  6043. switch (eltype)
  6044. {
  6045. case "textarea" :
  6046. elem = document.createElement("textarea");
  6047. if(autowidth) {
  6048. if(!options.cols) { $(elem).css({width:"98%"});}
  6049. } else if (!options.cols) { options.cols = 20; }
  6050. if(!options.rows) { options.rows = 2; }
  6051. if(vl==='&nbsp;' || vl==='&#160;' || (vl.length===1 && vl.charCodeAt(0)===160)) {vl="";}
  6052. elem.value = vl;
  6053. setAttributes(elem, options);
  6054. $(elem).attr({"role":"textbox","multiline":"true"});
  6055. break;
  6056. case "checkbox" : //what code for simple checkbox
  6057. elem = document.createElement("input");
  6058. elem.type = "checkbox";
  6059. if( !options.value ) {
  6060. var vl1 = (vl+"").toLowerCase();
  6061. if(vl1.search(/(false|f|0|no|n|off|undefined)/i)<0 && vl1!=="") {
  6062. elem.checked=true;
  6063. elem.defaultChecked=true;
  6064. elem.value = vl;
  6065. } else {
  6066. elem.value = "on";
  6067. }
  6068. $(elem).attr("offval","off");
  6069. } else {
  6070. var cbval = options.value.split(":");
  6071. if(vl === cbval[0]) {
  6072. elem.checked=true;
  6073. elem.defaultChecked=true;
  6074. }
  6075. elem.value = cbval[0];
  6076. $(elem).attr("offval",cbval[1]);
  6077. }
  6078. setAttributes(elem, options, ['value']);
  6079. $(elem).attr("role","checkbox");
  6080. break;
  6081. case "select" :
  6082. elem = document.createElement("select");
  6083. elem.setAttribute("role","select");
  6084. var msl, ovm = [];
  6085. if(options.multiple===true) {
  6086. msl = true;
  6087. elem.multiple="multiple";
  6088. $(elem).attr("aria-multiselectable","true");
  6089. } else { msl = false; }
  6090. if(options.dataUrl !== undefined) {
  6091. var rowid = options.name ? String(options.id).substring(0, String(options.id).length - String(options.name).length - 1) : String(options.id),
  6092. postData = options.postData || ajaxso.postData;
  6093. if ($t.p && $t.p.idPrefix) {
  6094. rowid = $.jgrid.stripPref($t.p.idPrefix, rowid);
  6095. }
  6096. $.ajax($.extend({
  6097. url: $.isFunction(options.dataUrl) ? options.dataUrl.call($t, rowid, vl, String(options.name)) : options.dataUrl,
  6098. type : "GET",
  6099. dataType: "html",
  6100. data: $.isFunction(postData) ? postData.call($t, rowid, vl, String(options.name)) : postData,
  6101. context: {elem:elem, options:options, vl:vl},
  6102. success: function(data){
  6103. var ovm = [], elem = this.elem, vl = this.vl,
  6104. options = $.extend({},this.options),
  6105. msl = options.multiple===true,
  6106. a = $.isFunction(options.buildSelect) ? options.buildSelect.call($t,data) : data;
  6107. if(typeof a === 'string') {
  6108. a = $( $.trim( a ) ).html();
  6109. }
  6110. if(a) {
  6111. $(elem).append(a);
  6112. setAttributes(elem, options, postData ? ['postData'] : undefined );
  6113. if(options.size === undefined) { options.size = msl ? 3 : 1;}
  6114. if(msl) {
  6115. ovm = vl.split(",");
  6116. ovm = $.map(ovm,function(n){return $.trim(n);});
  6117. } else {
  6118. ovm[0] = $.trim(vl);
  6119. }
  6120. //$(elem).attr(options);
  6121. setTimeout(function(){
  6122. $("option",elem).each(function(i){
  6123. //if(i===0) { this.selected = ""; }
  6124. // fix IE8/IE7 problem with selecting of the first item on multiple=true
  6125. if (i === 0 && elem.multiple) { this.selected = false; }
  6126. $(this).attr("role","option");
  6127. if($.inArray($.trim($(this).text()),ovm) > -1 || $.inArray($.trim($(this).val()),ovm) > -1 ) {
  6128. this.selected= "selected";
  6129. }
  6130. });
  6131. },0);
  6132. }
  6133. }
  6134. },ajaxso || {}));
  6135. } else if(options.value) {
  6136. var i;
  6137. if(options.size === undefined) {
  6138. options.size = msl ? 3 : 1;
  6139. }
  6140. if(msl) {
  6141. ovm = vl.split(",");
  6142. ovm = $.map(ovm,function(n){return $.trim(n);});
  6143. }
  6144. if(typeof options.value === 'function') { options.value = options.value(); }
  6145. var so,sv, ov,
  6146. sep = options.separator === undefined ? ":" : options.separator,
  6147. delim = options.delimiter === undefined ? ";" : options.delimiter;
  6148. if(typeof options.value === 'string') {
  6149. so = options.value.split(delim);
  6150. for(i=0; i<so.length;i++){
  6151. sv = so[i].split(sep);
  6152. if(sv.length > 2 ) {
  6153. sv[1] = $.map(sv,function(n,ii){if(ii>0) { return n;} }).join(sep);
  6154. }
  6155. ov = document.createElement("option");
  6156. ov.setAttribute("role","option");
  6157. ov.value = sv[0]; ov.innerHTML = sv[1];
  6158. elem.appendChild(ov);
  6159. if (!msl && ($.trim(sv[0]) === $.trim(vl) || $.trim(sv[1]) === $.trim(vl))) { ov.selected ="selected"; }
  6160. if (msl && ($.inArray($.trim(sv[1]), ovm)>-1 || $.inArray($.trim(sv[0]), ovm)>-1)) {ov.selected ="selected";}
  6161. }
  6162. } else if (typeof options.value === 'object') {
  6163. var oSv = options.value, key;
  6164. for (key in oSv) {
  6165. if (oSv.hasOwnProperty(key ) ){
  6166. ov = document.createElement("option");
  6167. ov.setAttribute("role","option");
  6168. ov.value = key; ov.innerHTML = oSv[key];
  6169. elem.appendChild(ov);
  6170. if (!msl && ( $.trim(key) === $.trim(vl) || $.trim(oSv[key]) === $.trim(vl)) ) { ov.selected ="selected"; }
  6171. if (msl && ($.inArray($.trim(oSv[key]),ovm)>-1 || $.inArray($.trim(key),ovm)>-1)) { ov.selected ="selected"; }
  6172. }
  6173. }
  6174. }
  6175. setAttributes(elem, options, ['value']);
  6176. }
  6177. break;
  6178. case "text" :
  6179. case "password" :
  6180. case "button" :
  6181. var role;
  6182. if(eltype==="button") { role = "button"; }
  6183. else { role = "textbox"; }
  6184. elem = document.createElement("input");
  6185. elem.type = eltype;
  6186. elem.value = vl;
  6187. setAttributes(elem, options);
  6188. if(eltype !== "button"){
  6189. if(autowidth) {
  6190. if(!options.size) { $(elem).css({width:"98%"}); }
  6191. } else if (!options.size) { options.size = 20; }
  6192. }
  6193. $(elem).attr("role",role);
  6194. break;
  6195. case "image" :
  6196. case "file" :
  6197. elem = document.createElement("input");
  6198. elem.type = eltype;
  6199. setAttributes(elem, options);
  6200. break;
  6201. case "custom" :
  6202. elem = document.createElement("span");
  6203. try {
  6204. if($.isFunction(options.custom_element)) {
  6205. var celm = options.custom_element.call($t,vl,options);
  6206. if(celm) {
  6207. celm = $(celm).addClass("customelement").attr({id:options.id,name:options.name});
  6208. $(elem).empty().append(celm);
  6209. } else {
  6210. throw "e2";
  6211. }
  6212. } else {
  6213. throw "e1";
  6214. }
  6215. } catch (e) {
  6216. if (e==="e1") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_element' "+$.jgrid.edit.msg.nodefined, $.jgrid.edit.bClose);}
  6217. if (e==="e2") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_element' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose);}
  6218. else { $.jgrid.info_dialog($.jgrid.errors.errcap,typeof e==="string"?e:e.message,$.jgrid.edit.bClose); }
  6219. }
  6220. break;
  6221. }
  6222. return elem;
  6223. },
  6224. // Date Validation Javascript
  6225. checkDate : function (format, date) {
  6226. var daysInFebruary = function(year){
  6227. // February has 29 days in any year evenly divisible by four,
  6228. // EXCEPT for centurial years which are not also divisible by 400.
  6229. return (((year % 4 === 0) && ( year % 100 !== 0 || (year % 400 === 0))) ? 29 : 28 );
  6230. },
  6231. tsp = {}, sep;
  6232. format = format.toLowerCase();
  6233. //we search for /,-,. for the date separator
  6234. if(format.indexOf("/") !== -1) {
  6235. sep = "/";
  6236. } else if(format.indexOf("-") !== -1) {
  6237. sep = "-";
  6238. } else if(format.indexOf(".") !== -1) {
  6239. sep = ".";
  6240. } else {
  6241. sep = "/";
  6242. }
  6243. format = format.split(sep);
  6244. date = date.split(sep);
  6245. if (date.length !== 3) { return false; }
  6246. var j=-1,yln, dln=-1, mln=-1, i;
  6247. for(i=0;i<format.length;i++){
  6248. var dv = isNaN(date[i]) ? 0 : parseInt(date[i],10);
  6249. tsp[format[i]] = dv;
  6250. yln = format[i];
  6251. if(yln.indexOf("y") !== -1) { j=i; }
  6252. if(yln.indexOf("m") !== -1) { mln=i; }
  6253. if(yln.indexOf("d") !== -1) { dln=i; }
  6254. }
  6255. if (format[j] === "y" || format[j] === "yyyy") {
  6256. yln=4;
  6257. } else if(format[j] ==="yy"){
  6258. yln = 2;
  6259. } else {
  6260. yln = -1;
  6261. }
  6262. var daysInMonth = [0,31,29,31,30,31,30,31,31,30,31,30,31],
  6263. strDate;
  6264. if (j === -1) {
  6265. return false;
  6266. }
  6267. strDate = tsp[format[j]].toString();
  6268. if(yln === 2 && strDate.length === 1) {yln = 1;}
  6269. if (strDate.length !== yln || (tsp[format[j]]===0 && date[j]!=="00")){
  6270. return false;
  6271. }
  6272. if(mln === -1) {
  6273. return false;
  6274. }
  6275. strDate = tsp[format[mln]].toString();
  6276. if (strDate.length<1 || tsp[format[mln]]<1 || tsp[format[mln]]>12){
  6277. return false;
  6278. }
  6279. if(dln === -1) {
  6280. return false;
  6281. }
  6282. strDate = tsp[format[dln]].toString();
  6283. 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]]]){
  6284. return false;
  6285. }
  6286. return true;
  6287. },
  6288. isEmpty : function(val)
  6289. {
  6290. if (val.match(/^\s+$/) || val === "") {
  6291. return true;
  6292. }
  6293. return false;
  6294. },
  6295. checkTime : function(time){
  6296. // checks only hh:ss (and optional am/pm)
  6297. var re = /^(\d{1,2}):(\d{2})([apAP][Mm])?$/,regs;
  6298. if(!$.jgrid.isEmpty(time))
  6299. {
  6300. regs = time.match(re);
  6301. if(regs) {
  6302. if(regs[3]) {
  6303. if(regs[1] < 1 || regs[1] > 12) { return false; }
  6304. } else {
  6305. if(regs[1] > 23) { return false; }
  6306. }
  6307. if(regs[2] > 59) {
  6308. return false;
  6309. }
  6310. } else {
  6311. return false;
  6312. }
  6313. }
  6314. return true;
  6315. },
  6316. checkValues : function(val, valref, customobject, nam) {
  6317. var edtrul,i, nm, dft, len, g = this, cm = g.p.colModel;
  6318. if(customobject === undefined) {
  6319. if(typeof valref==='string'){
  6320. for( i =0, len=cm.length;i<len; i++){
  6321. if(cm[i].name===valref) {
  6322. edtrul = cm[i].editrules;
  6323. valref = i;
  6324. if(cm[i].formoptions != null) { nm = cm[i].formoptions.label; }
  6325. break;
  6326. }
  6327. }
  6328. } else if(valref >=0) {
  6329. edtrul = cm[valref].editrules;
  6330. }
  6331. } else {
  6332. edtrul = customobject;
  6333. nm = nam===undefined ? "_" : nam;
  6334. }
  6335. if(edtrul) {
  6336. if(!nm) { nm = g.p.colNames != null ? g.p.colNames[valref] : cm[valref].label; }
  6337. if(edtrul.required === true) {
  6338. if( $.jgrid.isEmpty(val) ) { return [false,nm+": "+$.jgrid.edit.msg.required,""]; }
  6339. }
  6340. // force required
  6341. var rqfield = edtrul.required === false ? false : true;
  6342. if(edtrul.number === true) {
  6343. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  6344. if(isNaN(val)) { return [false,nm+": "+$.jgrid.edit.msg.number,""]; }
  6345. }
  6346. }
  6347. if(edtrul.minValue !== undefined && !isNaN(edtrul.minValue)) {
  6348. if (parseFloat(val) < parseFloat(edtrul.minValue) ) { return [false,nm+": "+$.jgrid.edit.msg.minValue+" "+edtrul.minValue,""];}
  6349. }
  6350. if(edtrul.maxValue !== undefined && !isNaN(edtrul.maxValue)) {
  6351. if (parseFloat(val) > parseFloat(edtrul.maxValue) ) { return [false,nm+": "+$.jgrid.edit.msg.maxValue+" "+edtrul.maxValue,""];}
  6352. }
  6353. var filter;
  6354. if(edtrul.email === true) {
  6355. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  6356. // taken from $ Validate plugin
  6357. 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;
  6358. if(!filter.test(val)) {return [false,nm+": "+$.jgrid.edit.msg.email,""];}
  6359. }
  6360. }
  6361. if(edtrul.integer === true) {
  6362. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  6363. if(isNaN(val)) { return [false,nm+": "+$.jgrid.edit.msg.integer,""]; }
  6364. if ((val % 1 !== 0) || (val.indexOf('.') !== -1)) { return [false,nm+": "+$.jgrid.edit.msg.integer,""];}
  6365. }
  6366. }
  6367. if(edtrul.date === true) {
  6368. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  6369. if(cm[valref].formatoptions && cm[valref].formatoptions.newformat) {
  6370. dft = cm[valref].formatoptions.newformat;
  6371. if( $.jgrid.formatter.date.masks.hasOwnProperty(dft) ) {
  6372. dft = $.jgrid.formatter.date.masks[dft];
  6373. }
  6374. } else {
  6375. dft = cm[valref].datefmt || "Y-m-d";
  6376. }
  6377. if(!$.jgrid.checkDate (dft, val)) { return [false,nm+": "+$.jgrid.edit.msg.date+" - "+dft,""]; }
  6378. }
  6379. }
  6380. if(edtrul.time === true) {
  6381. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  6382. if(!$.jgrid.checkTime (val)) { return [false,nm+": "+$.jgrid.edit.msg.date+" - hh:mm (am/pm)",""]; }
  6383. }
  6384. }
  6385. if(edtrul.url === true) {
  6386. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  6387. filter = /^(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
  6388. if(!filter.test(val)) {return [false,nm+": "+$.jgrid.edit.msg.url,""];}
  6389. }
  6390. }
  6391. if(edtrul.custom === true) {
  6392. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  6393. if($.isFunction(edtrul.custom_func)) {
  6394. var ret = edtrul.custom_func.call(g,val,nm,valref);
  6395. return $.isArray(ret) ? ret : [false,$.jgrid.edit.msg.customarray,""];
  6396. }
  6397. return [false,$.jgrid.edit.msg.customfcheck,""];
  6398. }
  6399. }
  6400. }
  6401. return [true,"",""];
  6402. }
  6403. });
  6404. })(jQuery);
  6405. /*
  6406. * jqFilter jQuery jqGrid filter addon.
  6407. * Copyright (c) 2011, Tony Tomov, tony@trirand.com
  6408. * Dual licensed under the MIT and GPL licenses
  6409. * http://www.opensource.org/licenses/mit-license.php
  6410. * http://www.gnu.org/licenses/gpl-2.0.html
  6411. *
  6412. * The work is inspired from this Stefan Pirvu
  6413. * http://www.codeproject.com/KB/scripting/json-filtering.aspx
  6414. *
  6415. * The filter uses JSON entities to hold filter rules and groups. Here is an example of a filter:
  6416. { "groupOp": "AND",
  6417. "groups" : [
  6418. { "groupOp": "OR",
  6419. "rules": [
  6420. { "field": "name", "op": "eq", "data": "England" },
  6421. { "field": "id", "op": "le", "data": "5"}
  6422. ]
  6423. }
  6424. ],
  6425. "rules": [
  6426. { "field": "name", "op": "eq", "data": "Romania" },
  6427. { "field": "id", "op": "le", "data": "1"}
  6428. ]
  6429. }
  6430. */
  6431. /*jshint eqeqeq:false, eqnull:true, devel:true */
  6432. /*global jQuery */
  6433. (function ($) {
  6434. "use strict";
  6435. $.fn.jqFilter = function( arg ) {
  6436. if (typeof arg === 'string') {
  6437. var fn = $.fn.jqFilter[arg];
  6438. if (!fn) {
  6439. throw ("jqFilter - No such method: " + arg);
  6440. }
  6441. var args = $.makeArray(arguments).slice(1);
  6442. return fn.apply(this,args);
  6443. }
  6444. var p = $.extend(true,{
  6445. filter: null,
  6446. columns: [],
  6447. onChange : null,
  6448. afterRedraw : null,
  6449. checkValues : null,
  6450. error: false,
  6451. errmsg : "",
  6452. errorcheck : true,
  6453. showQuery : true,
  6454. sopt : null,
  6455. ops : [],
  6456. operands : null,
  6457. numopts : ['eq','ne', 'lt', 'le', 'gt', 'ge', 'nu', 'nn', 'in', 'ni'],
  6458. stropts : ['eq', 'ne', 'bw', 'bn', 'ew', 'en', 'cn', 'nc', 'nu', 'nn', 'in', 'ni'],
  6459. strarr : ['text', 'string', 'blob'],
  6460. groupOps : [{ op: "AND", text: "AND" }, { op: "OR", text: "OR" }],
  6461. groupButton : true,
  6462. ruleButtons : true,
  6463. direction : "ltr"
  6464. }, $.jgrid.filter, arg || {});
  6465. return this.each( function() {
  6466. if (this.filter) {return;}
  6467. this.p = p;
  6468. // setup filter in case if they is not defined
  6469. if (this.p.filter === null || this.p.filter === undefined) {
  6470. this.p.filter = {
  6471. groupOp: this.p.groupOps[0].op,
  6472. rules: [],
  6473. groups: []
  6474. };
  6475. }
  6476. var i, len = this.p.columns.length, cl,
  6477. isIE = /msie/i.test(navigator.userAgent) && !window.opera;
  6478. // translating the options
  6479. this.p.initFilter = $.extend(true,{},this.p.filter);
  6480. // set default values for the columns if they are not set
  6481. if( !len ) {return;}
  6482. for(i=0; i < len; i++) {
  6483. cl = this.p.columns[i];
  6484. if( cl.stype ) {
  6485. // grid compatibility
  6486. cl.inputtype = cl.stype;
  6487. } else if(!cl.inputtype) {
  6488. cl.inputtype = 'text';
  6489. }
  6490. if( cl.sorttype ) {
  6491. // grid compatibility
  6492. cl.searchtype = cl.sorttype;
  6493. } else if (!cl.searchtype) {
  6494. cl.searchtype = 'string';
  6495. }
  6496. if(cl.hidden === undefined) {
  6497. // jqGrid compatibility
  6498. cl.hidden = false;
  6499. }
  6500. if(!cl.label) {
  6501. cl.label = cl.name;
  6502. }
  6503. if(cl.index) {
  6504. cl.name = cl.index;
  6505. }
  6506. if(!cl.hasOwnProperty('searchoptions')) {
  6507. cl.searchoptions = {};
  6508. }
  6509. if(!cl.hasOwnProperty('searchrules')) {
  6510. cl.searchrules = {};
  6511. }
  6512. }
  6513. if(this.p.showQuery) {
  6514. $(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>");
  6515. }
  6516. var getGrid = function () {
  6517. return $("#" + $.jgrid.jqID(p.id))[0] || null;
  6518. };
  6519. /*
  6520. *Perform checking.
  6521. *
  6522. */
  6523. var checkData = function(val, colModelItem) {
  6524. var ret = [true,""], $t = getGrid();
  6525. if($.isFunction(colModelItem.searchrules)) {
  6526. ret = colModelItem.searchrules.call($t, val, colModelItem);
  6527. } else if($.jgrid && $.jgrid.checkValues) {
  6528. try {
  6529. ret = $.jgrid.checkValues.call($t, val, -1, colModelItem.searchrules, colModelItem.label);
  6530. } catch (e) {}
  6531. }
  6532. if(ret && ret.length && ret[0] === false) {
  6533. p.error = !ret[0];
  6534. p.errmsg = ret[1];
  6535. }
  6536. };
  6537. /* moving to common
  6538. randId = function() {
  6539. return Math.floor(Math.random()*10000).toString();
  6540. };
  6541. */
  6542. this.onchange = function ( ){
  6543. // clear any error
  6544. this.p.error = false;
  6545. this.p.errmsg="";
  6546. return $.isFunction(this.p.onChange) ? this.p.onChange.call( this, this.p ) : false;
  6547. };
  6548. /*
  6549. * Redraw the filter every time when new field is added/deleted
  6550. * and field is changed
  6551. */
  6552. this.reDraw = function() {
  6553. $("table.group:first",this).remove();
  6554. var t = this.createTableForGroup(p.filter, null);
  6555. $(this).append(t);
  6556. if($.isFunction(this.p.afterRedraw) ) {
  6557. this.p.afterRedraw.call(this, this.p);
  6558. }
  6559. };
  6560. /*
  6561. * Creates a grouping data for the filter
  6562. * @param group - object
  6563. * @param parentgroup - object
  6564. */
  6565. this.createTableForGroup = function(group, parentgroup) {
  6566. var that = this, i;
  6567. // this table will hold all the group (tables) and rules (rows)
  6568. var table = $("<table class='group ui-widget ui-widget-content' style='border:0px none;'><tbody></tbody></table>"),
  6569. // create error message row
  6570. align = "left";
  6571. if(this.p.direction === "rtl") {
  6572. align = "right";
  6573. table.attr("dir","rtl");
  6574. }
  6575. if(parentgroup === null) {
  6576. table.append("<tr class='error' style='display:none;'><th colspan='5' class='ui-state-error' align='"+align+"'></th></tr>");
  6577. }
  6578. var tr = $("<tr></tr>");
  6579. table.append(tr);
  6580. // this header will hold the group operator type and group action buttons for
  6581. // creating subgroup "+ {}", creating rule "+" or deleting the group "-"
  6582. var th = $("<th colspan='5' align='"+align+"'></th>");
  6583. tr.append(th);
  6584. if(this.p.ruleButtons === true) {
  6585. // dropdown for: choosing group operator type
  6586. var groupOpSelect = $("<select class='opsel'></select>");
  6587. th.append(groupOpSelect);
  6588. // populate dropdown with all posible group operators: or, and
  6589. var str= "", selected;
  6590. for (i = 0; i < p.groupOps.length; i++) {
  6591. selected = group.groupOp === that.p.groupOps[i].op ? " selected='selected'" :"";
  6592. str += "<option value='"+that.p.groupOps[i].op+"'" + selected+">"+that.p.groupOps[i].text+"</option>";
  6593. }
  6594. groupOpSelect
  6595. .append(str)
  6596. .bind('change',function() {
  6597. group.groupOp = $(groupOpSelect).val();
  6598. that.onchange(); // signals that the filter has changed
  6599. });
  6600. }
  6601. // button for adding a new subgroup
  6602. var inputAddSubgroup ="<span></span>";
  6603. if(this.p.groupButton) {
  6604. inputAddSubgroup = $("<input type='button' value='+ {}' title='Add subgroup' class='add-group'/>");
  6605. inputAddSubgroup.bind('click',function() {
  6606. if (group.groups === undefined ) {
  6607. group.groups = [];
  6608. }
  6609. group.groups.push({
  6610. groupOp: p.groupOps[0].op,
  6611. rules: [],
  6612. groups: []
  6613. }); // adding a new group
  6614. that.reDraw(); // the html has changed, force reDraw
  6615. that.onchange(); // signals that the filter has changed
  6616. return false;
  6617. });
  6618. }
  6619. th.append(inputAddSubgroup);
  6620. if(this.p.ruleButtons === true) {
  6621. // button for adding a new rule
  6622. var inputAddRule = $("<input type='button' value='+' title='Add rule' class='add-rule ui-add'/>"), cm;
  6623. inputAddRule.bind('click',function() {
  6624. //if(!group) { group = {};}
  6625. if (group.rules === undefined) {
  6626. group.rules = [];
  6627. }
  6628. for (i = 0; i < that.p.columns.length; i++) {
  6629. // but show only serchable and serchhidden = true fields
  6630. var searchable = (that.p.columns[i].search === undefined) ? true: that.p.columns[i].search,
  6631. hidden = (that.p.columns[i].hidden === true),
  6632. ignoreHiding = (that.p.columns[i].searchoptions.searchhidden === true);
  6633. if ((ignoreHiding && searchable) || (searchable && !hidden)) {
  6634. cm = that.p.columns[i];
  6635. break;
  6636. }
  6637. }
  6638. var opr;
  6639. if( cm.searchoptions.sopt ) {opr = cm.searchoptions.sopt;}
  6640. else if(that.p.sopt) { opr= that.p.sopt; }
  6641. else if ( $.inArray(cm.searchtype, that.p.strarr) !== -1 ) {opr = that.p.stropts;}
  6642. else {opr = that.p.numopts;}
  6643. group.rules.push({
  6644. field: cm.name,
  6645. op: opr[0],
  6646. data: ""
  6647. }); // adding a new rule
  6648. that.reDraw(); // the html has changed, force reDraw
  6649. // for the moment no change have been made to the rule, so
  6650. // this will not trigger onchange event
  6651. return false;
  6652. });
  6653. th.append(inputAddRule);
  6654. }
  6655. // button for delete the group
  6656. if (parentgroup !== null) { // ignore the first group
  6657. var inputDeleteGroup = $("<input type='button' value='-' title='Delete group' class='delete-group'/>");
  6658. th.append(inputDeleteGroup);
  6659. inputDeleteGroup.bind('click',function() {
  6660. // remove group from parent
  6661. for (i = 0; i < parentgroup.groups.length; i++) {
  6662. if (parentgroup.groups[i] === group) {
  6663. parentgroup.groups.splice(i, 1);
  6664. break;
  6665. }
  6666. }
  6667. that.reDraw(); // the html has changed, force reDraw
  6668. that.onchange(); // signals that the filter has changed
  6669. return false;
  6670. });
  6671. }
  6672. // append subgroup rows
  6673. if (group.groups !== undefined) {
  6674. for (i = 0; i < group.groups.length; i++) {
  6675. var trHolderForSubgroup = $("<tr></tr>");
  6676. table.append(trHolderForSubgroup);
  6677. var tdFirstHolderForSubgroup = $("<td class='first'></td>");
  6678. trHolderForSubgroup.append(tdFirstHolderForSubgroup);
  6679. var tdMainHolderForSubgroup = $("<td colspan='4'></td>");
  6680. tdMainHolderForSubgroup.append(this.createTableForGroup(group.groups[i], group));
  6681. trHolderForSubgroup.append(tdMainHolderForSubgroup);
  6682. }
  6683. }
  6684. if(group.groupOp === undefined) {
  6685. group.groupOp = that.p.groupOps[0].op;
  6686. }
  6687. // append rules rows
  6688. if (group.rules !== undefined) {
  6689. for (i = 0; i < group.rules.length; i++) {
  6690. table.append(
  6691. this.createTableRowForRule(group.rules[i], group)
  6692. );
  6693. }
  6694. }
  6695. return table;
  6696. };
  6697. /*
  6698. * Create the rule data for the filter
  6699. */
  6700. this.createTableRowForRule = function(rule, group ) {
  6701. // save current entity in a variable so that it could
  6702. // be referenced in anonimous method calls
  6703. var that=this, $t = getGrid(), tr = $("<tr></tr>"),
  6704. //document.createElement("tr"),
  6705. // first column used for padding
  6706. //tdFirstHolderForRule = document.createElement("td"),
  6707. i, op, trpar, cm, str="", selected;
  6708. //tdFirstHolderForRule.setAttribute("class", "first");
  6709. tr.append("<td class='first'></td>");
  6710. // create field container
  6711. var ruleFieldTd = $("<td class='columns'></td>");
  6712. tr.append(ruleFieldTd);
  6713. // dropdown for: choosing field
  6714. var ruleFieldSelect = $("<select></select>"), ina, aoprs = [];
  6715. ruleFieldTd.append(ruleFieldSelect);
  6716. ruleFieldSelect.bind('change',function() {
  6717. rule.field = $(ruleFieldSelect).val();
  6718. trpar = $(this).parents("tr:first");
  6719. for (i=0;i<that.p.columns.length;i++) {
  6720. if(that.p.columns[i].name === rule.field) {
  6721. cm = that.p.columns[i];
  6722. break;
  6723. }
  6724. }
  6725. if(!cm) {return;}
  6726. cm.searchoptions.id = $.jgrid.randId();
  6727. if(isIE && cm.inputtype === "text") {
  6728. if(!cm.searchoptions.size) {
  6729. cm.searchoptions.size = 10;
  6730. }
  6731. }
  6732. var elm = $.jgrid.createEl.call($t, cm.inputtype,cm.searchoptions, "", true, that.p.ajaxSelectOptions || {}, true);
  6733. $(elm).addClass("input-elm");
  6734. //that.createElement(rule, "");
  6735. if( cm.searchoptions.sopt ) {op = cm.searchoptions.sopt;}
  6736. else if(that.p.sopt) { op= that.p.sopt; }
  6737. else if ($.inArray(cm.searchtype, that.p.strarr) !== -1) {op = that.p.stropts;}
  6738. else {op = that.p.numopts;}
  6739. // operators
  6740. var s ="", so = 0;
  6741. aoprs = [];
  6742. $.each(that.p.ops, function() { aoprs.push(this.oper); });
  6743. for ( i = 0 ; i < op.length; i++) {
  6744. ina = $.inArray(op[i],aoprs);
  6745. if(ina !== -1) {
  6746. if(so===0) {
  6747. rule.op = that.p.ops[ina].oper;
  6748. }
  6749. s += "<option value='"+that.p.ops[ina].oper+"'>"+that.p.ops[ina].text+"</option>";
  6750. so++;
  6751. }
  6752. }
  6753. $(".selectopts",trpar).empty().append( s );
  6754. $(".selectopts",trpar)[0].selectedIndex = 0;
  6755. if( $.jgrid.msie && $.jgrid.msiever() < 9) {
  6756. var sw = parseInt($("select.selectopts",trpar)[0].offsetWidth, 10) + 1;
  6757. $(".selectopts",trpar).width( sw );
  6758. $(".selectopts",trpar).css("width","auto");
  6759. }
  6760. // data
  6761. $(".data",trpar).empty().append( elm );
  6762. $.jgrid.bindEv.call($t, elm, cm.searchoptions);
  6763. $(".input-elm",trpar).bind('change',function( e ) {
  6764. var elem = e.target;
  6765. rule.data = elem.nodeName.toUpperCase() === "SPAN" && cm.searchoptions && $.isFunction(cm.searchoptions.custom_value) ?
  6766. cm.searchoptions.custom_value.call($t, $(elem).children(".customelement:first"), 'get') : elem.value;
  6767. that.onchange(); // signals that the filter has changed
  6768. });
  6769. setTimeout(function(){ //IE, Opera, Chrome
  6770. rule.data = $(elm).val();
  6771. that.onchange(); // signals that the filter has changed
  6772. }, 0);
  6773. });
  6774. // populate drop down with user provided column definitions
  6775. var j=0;
  6776. for (i = 0; i < that.p.columns.length; i++) {
  6777. // but show only serchable and serchhidden = true fields
  6778. var searchable = (that.p.columns[i].search === undefined) ? true: that.p.columns[i].search,
  6779. hidden = (that.p.columns[i].hidden === true),
  6780. ignoreHiding = (that.p.columns[i].searchoptions.searchhidden === true);
  6781. if ((ignoreHiding && searchable) || (searchable && !hidden)) {
  6782. selected = "";
  6783. if(rule.field === that.p.columns[i].name) {
  6784. selected = " selected='selected'";
  6785. j=i;
  6786. }
  6787. str += "<option value='"+that.p.columns[i].name+"'" +selected+">"+that.p.columns[i].label+"</option>";
  6788. }
  6789. }
  6790. ruleFieldSelect.append( str );
  6791. // create operator container
  6792. var ruleOperatorTd = $("<td class='operators'></td>");
  6793. tr.append(ruleOperatorTd);
  6794. cm = p.columns[j];
  6795. // create it here so it can be referentiated in the onchange event
  6796. //var RD = that.createElement(rule, rule.data);
  6797. cm.searchoptions.id = $.jgrid.randId();
  6798. if(isIE && cm.inputtype === "text") {
  6799. if(!cm.searchoptions.size) {
  6800. cm.searchoptions.size = 10;
  6801. }
  6802. }
  6803. var ruleDataInput = $.jgrid.createEl.call($t, cm.inputtype,cm.searchoptions, rule.data, true, that.p.ajaxSelectOptions || {}, true);
  6804. if(rule.op === 'nu' || rule.op === 'nn') {
  6805. $(ruleDataInput).attr('readonly','true');
  6806. $(ruleDataInput).attr('disabled','true');
  6807. } //retain the state of disabled text fields in case of null ops
  6808. // dropdown for: choosing operator
  6809. var ruleOperatorSelect = $("<select class='selectopts'></select>");
  6810. ruleOperatorTd.append(ruleOperatorSelect);
  6811. ruleOperatorSelect.bind('change',function() {
  6812. rule.op = $(ruleOperatorSelect).val();
  6813. trpar = $(this).parents("tr:first");
  6814. var rd = $(".input-elm",trpar)[0];
  6815. if (rule.op === "nu" || rule.op === "nn") { // disable for operator "is null" and "is not null"
  6816. rule.data = "";
  6817. if(rd.tagName.toUpperCase() !== 'SELECT') rd.value = "";
  6818. rd.setAttribute("readonly", "true");
  6819. rd.setAttribute("disabled", "true");
  6820. } else {
  6821. if(rd.tagName.toUpperCase() === 'SELECT') rule.data = rd.value;
  6822. rd.removeAttribute("readonly");
  6823. rd.removeAttribute("disabled");
  6824. }
  6825. that.onchange(); // signals that the filter has changed
  6826. });
  6827. // populate drop down with all available operators
  6828. if( cm.searchoptions.sopt ) {op = cm.searchoptions.sopt;}
  6829. else if(that.p.sopt) { op= that.p.sopt; }
  6830. else if ($.inArray(cm.searchtype, that.p.strarr) !== -1) {op = that.p.stropts;}
  6831. else {op = that.p.numopts;}
  6832. str="";
  6833. $.each(that.p.ops, function() { aoprs.push(this.oper); });
  6834. for ( i = 0; i < op.length; i++) {
  6835. ina = $.inArray(op[i],aoprs);
  6836. if(ina !== -1) {
  6837. selected = rule.op === that.p.ops[ina].oper ? " selected='selected'" : "";
  6838. str += "<option value='"+that.p.ops[ina].oper+"'"+selected+">"+that.p.ops[ina].text+"</option>";
  6839. }
  6840. }
  6841. ruleOperatorSelect.append( str );
  6842. // create data container
  6843. var ruleDataTd = $("<td class='data'></td>");
  6844. tr.append(ruleDataTd);
  6845. // textbox for: data
  6846. // is created previously
  6847. //ruleDataInput.setAttribute("type", "text");
  6848. ruleDataTd.append(ruleDataInput);
  6849. $.jgrid.bindEv.call($t, ruleDataInput, cm.searchoptions);
  6850. $(ruleDataInput)
  6851. .addClass("input-elm")
  6852. .bind('change', function() {
  6853. rule.data = cm.inputtype === 'custom' ? cm.searchoptions.custom_value.call($t, $(this).children(".customelement:first"),'get') : $(this).val();
  6854. that.onchange(); // signals that the filter has changed
  6855. });
  6856. // create action container
  6857. var ruleDeleteTd = $("<td></td>");
  6858. tr.append(ruleDeleteTd);
  6859. // create button for: delete rule
  6860. if(this.p.ruleButtons === true) {
  6861. var ruleDeleteInput = $("<input type='button' value='-' title='Delete rule' class='delete-rule ui-del'/>");
  6862. ruleDeleteTd.append(ruleDeleteInput);
  6863. //$(ruleDeleteInput).html("").height(20).width(30).button({icons: { primary: "ui-icon-minus", text:false}});
  6864. ruleDeleteInput.bind('click',function() {
  6865. // remove rule from group
  6866. for (i = 0; i < group.rules.length; i++) {
  6867. if (group.rules[i] === rule) {
  6868. group.rules.splice(i, 1);
  6869. break;
  6870. }
  6871. }
  6872. that.reDraw(); // the html has changed, force reDraw
  6873. that.onchange(); // signals that the filter has changed
  6874. return false;
  6875. });
  6876. }
  6877. return tr;
  6878. };
  6879. this.getStringForGroup = function(group) {
  6880. var s = "(", index;
  6881. if (group.groups !== undefined) {
  6882. for (index = 0; index < group.groups.length; index++) {
  6883. if (s.length > 1) {
  6884. s += " " + group.groupOp + " ";
  6885. }
  6886. try {
  6887. s += this.getStringForGroup(group.groups[index]);
  6888. } catch (eg) {alert(eg);}
  6889. }
  6890. }
  6891. if (group.rules !== undefined) {
  6892. try{
  6893. for (index = 0; index < group.rules.length; index++) {
  6894. if (s.length > 1) {
  6895. s += " " + group.groupOp + " ";
  6896. }
  6897. s += this.getStringForRule(group.rules[index]);
  6898. }
  6899. } catch (e) {alert(e);}
  6900. }
  6901. s += ")";
  6902. if (s === "()") {
  6903. return ""; // ignore groups that don't have rules
  6904. }
  6905. return s;
  6906. };
  6907. this.getStringForRule = function(rule) {
  6908. var opUF = "",opC="", i, cm, ret, val,
  6909. numtypes = ['int', 'integer', 'float', 'number', 'currency']; // jqGrid
  6910. for (i = 0; i < this.p.ops.length; i++) {
  6911. if (this.p.ops[i].oper === rule.op) {
  6912. opUF = this.p.operands.hasOwnProperty(rule.op) ? this.p.operands[rule.op] : "";
  6913. opC = this.p.ops[i].oper;
  6914. break;
  6915. }
  6916. }
  6917. for (i=0; i<this.p.columns.length; i++) {
  6918. if(this.p.columns[i].name === rule.field) {
  6919. cm = this.p.columns[i];
  6920. break;
  6921. }
  6922. }
  6923. if (cm == undefined) { return ""; }
  6924. val = rule.data;
  6925. if(opC === 'bw' || opC === 'bn') { val = val+"%"; }
  6926. if(opC === 'ew' || opC === 'en') { val = "%"+val; }
  6927. if(opC === 'cn' || opC === 'nc') { val = "%"+val+"%"; }
  6928. if(opC === 'in' || opC === 'ni') { val = " ("+val+")"; }
  6929. if(p.errorcheck) { checkData(rule.data, cm); }
  6930. if($.inArray(cm.searchtype, numtypes) !== -1 || opC === 'nn' || opC === 'nu') { ret = rule.field + " " + opUF + " " + val; }
  6931. else { ret = rule.field + " " + opUF + " \"" + val + "\""; }
  6932. return ret;
  6933. };
  6934. this.resetFilter = function () {
  6935. this.p.filter = $.extend(true,{},this.p.initFilter);
  6936. this.reDraw();
  6937. this.onchange();
  6938. };
  6939. this.hideError = function() {
  6940. $("th.ui-state-error", this).html("");
  6941. $("tr.error", this).hide();
  6942. };
  6943. this.showError = function() {
  6944. $("th.ui-state-error", this).html(this.p.errmsg);
  6945. $("tr.error", this).show();
  6946. };
  6947. this.toUserFriendlyString = function() {
  6948. return this.getStringForGroup(p.filter);
  6949. };
  6950. this.toString = function() {
  6951. // this will obtain a string that can be used to match an item.
  6952. var that = this;
  6953. function getStringRule(rule) {
  6954. if(that.p.errorcheck) {
  6955. var i, cm;
  6956. for (i=0; i<that.p.columns.length; i++) {
  6957. if(that.p.columns[i].name === rule.field) {
  6958. cm = that.p.columns[i];
  6959. break;
  6960. }
  6961. }
  6962. if(cm) {checkData(rule.data, cm);}
  6963. }
  6964. return rule.op + "(item." + rule.field + ",'" + rule.data + "')";
  6965. }
  6966. function getStringForGroup(group) {
  6967. var s = "(", index;
  6968. if (group.groups !== undefined) {
  6969. for (index = 0; index < group.groups.length; index++) {
  6970. if (s.length > 1) {
  6971. if (group.groupOp === "OR") {
  6972. s += " || ";
  6973. }
  6974. else {
  6975. s += " && ";
  6976. }
  6977. }
  6978. s += getStringForGroup(group.groups[index]);
  6979. }
  6980. }
  6981. if (group.rules !== undefined) {
  6982. for (index = 0; index < group.rules.length; index++) {
  6983. if (s.length > 1) {
  6984. if (group.groupOp === "OR") {
  6985. s += " || ";
  6986. }
  6987. else {
  6988. s += " && ";
  6989. }
  6990. }
  6991. s += getStringRule(group.rules[index]);
  6992. }
  6993. }
  6994. s += ")";
  6995. if (s === "()") {
  6996. return ""; // ignore groups that don't have rules
  6997. }
  6998. return s;
  6999. }
  7000. return getStringForGroup(this.p.filter);
  7001. };
  7002. // Here we init the filter
  7003. this.reDraw();
  7004. if(this.p.showQuery) {
  7005. this.onchange();
  7006. }
  7007. // mark is as created so that it will not be created twice on this element
  7008. this.filter = true;
  7009. });
  7010. };
  7011. $.extend($.fn.jqFilter,{
  7012. /*
  7013. * Return SQL like string. Can be used directly
  7014. */
  7015. toSQLString : function()
  7016. {
  7017. var s ="";
  7018. this.each(function(){
  7019. s = this.toUserFriendlyString();
  7020. });
  7021. return s;
  7022. },
  7023. /*
  7024. * Return filter data as object.
  7025. */
  7026. filterData : function()
  7027. {
  7028. var s;
  7029. this.each(function(){
  7030. s = this.p.filter;
  7031. });
  7032. return s;
  7033. },
  7034. getParameter : function (param) {
  7035. if(param !== undefined) {
  7036. if (this.p.hasOwnProperty(param) ) {
  7037. return this.p[param];
  7038. }
  7039. }
  7040. return this.p;
  7041. },
  7042. resetFilter: function() {
  7043. return this.each(function(){
  7044. this.resetFilter();
  7045. });
  7046. },
  7047. addFilter: function (pfilter) {
  7048. if (typeof pfilter === "string") {
  7049. pfilter = $.jgrid.parse( pfilter );
  7050. }
  7051. this.each(function(){
  7052. this.p.filter = pfilter;
  7053. this.reDraw();
  7054. this.onchange();
  7055. });
  7056. }
  7057. });
  7058. })(jQuery);
  7059. /*jshint eqeqeq:false, eqnull:true, devel:true */
  7060. /*global xmlJsonClass, jQuery */
  7061. (function($){
  7062. /**
  7063. * jqGrid extension for form editing Grid Data
  7064. * Tony Tomov tony@trirand.com
  7065. * http://trirand.com/blog/
  7066. * Dual licensed under the MIT and GPL licenses:
  7067. * http://www.opensource.org/licenses/mit-license.php
  7068. * http://www.gnu.org/licenses/gpl-2.0.html
  7069. **/
  7070. "use strict";
  7071. var rp_ge = {};
  7072. $.jgrid.extend({
  7073. searchGrid : function (p) {
  7074. p = $.extend(true, {
  7075. recreateFilter: false,
  7076. drag: true,
  7077. sField:'searchField',
  7078. sValue:'searchString',
  7079. sOper: 'searchOper',
  7080. sFilter: 'filters',
  7081. loadDefaults: true, // this options activates loading of default filters from grid's postData for Multipe Search only.
  7082. beforeShowSearch: null,
  7083. afterShowSearch : null,
  7084. onInitializeSearch: null,
  7085. afterRedraw : null,
  7086. afterChange: null,
  7087. closeAfterSearch : false,
  7088. closeAfterReset: false,
  7089. closeOnEscape : false,
  7090. searchOnEnter : false,
  7091. multipleSearch : false,
  7092. multipleGroup : false,
  7093. //cloneSearchRowOnAdd: true,
  7094. top : 0,
  7095. left: 0,
  7096. jqModal : true,
  7097. modal: false,
  7098. resize : true,
  7099. width: 450,
  7100. height: 'auto',
  7101. dataheight: 'auto',
  7102. showQuery: false,
  7103. errorcheck : true,
  7104. sopt: null,
  7105. stringResult: undefined,
  7106. onClose : null,
  7107. onSearch : null,
  7108. onReset : null,
  7109. toTop : true,
  7110. overlay : 30,
  7111. columns : [],
  7112. tmplNames : null,
  7113. tmplFilters : null,
  7114. tmplLabel : ' Template: ',
  7115. showOnLoad: false,
  7116. layer: null,
  7117. operands : { "eq" :"=", "ne":"<>","lt":"<","le":"<=","gt":">","ge":">=","bw":"LIKE","bn":"NOT LIKE","in":"IN","ni":"NOT IN","ew":"LIKE","en":"NOT LIKE","cn":"LIKE","nc":"NOT LIKE","nu":"IS NULL","nn":"ISNOT NULL"}
  7118. }, $.jgrid.search, p || {});
  7119. return this.each(function() {
  7120. var $t = this;
  7121. if(!$t.grid) {return;}
  7122. var fid = "fbox_"+$t.p.id,
  7123. showFrm = true,
  7124. mustReload = true,
  7125. IDs = {themodal:'searchmod'+fid,modalhead:'searchhd'+fid,modalcontent:'searchcnt'+fid, scrollelm : fid},
  7126. defaultFilters = $t.p.postData[p.sFilter];
  7127. if(typeof defaultFilters === "string") {
  7128. defaultFilters = $.jgrid.parse( defaultFilters );
  7129. }
  7130. if(p.recreateFilter === true) {
  7131. $("#"+$.jgrid.jqID(IDs.themodal)).remove();
  7132. }
  7133. function showFilter(_filter) {
  7134. showFrm = $($t).triggerHandler("jqGridFilterBeforeShow", [_filter]);
  7135. if(showFrm === undefined) {
  7136. showFrm = true;
  7137. }
  7138. if(showFrm && $.isFunction(p.beforeShowSearch)) {
  7139. showFrm = p.beforeShowSearch.call($t,_filter);
  7140. }
  7141. if(showFrm) {
  7142. $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{gbox:"#gbox_"+$.jgrid.jqID(fid),jqm:p.jqModal, modal:p.modal, overlay: p.overlay, toTop: p.toTop});
  7143. $($t).triggerHandler("jqGridFilterAfterShow", [_filter]);
  7144. if($.isFunction(p.afterShowSearch)) {
  7145. p.afterShowSearch.call($t, _filter);
  7146. }
  7147. }
  7148. }
  7149. if ( $("#"+$.jgrid.jqID(IDs.themodal))[0] !== undefined ) {
  7150. showFilter($("#fbox_"+$.jgrid.jqID(+$t.p.id)));
  7151. } else {
  7152. var fil = $("<div><div id='"+fid+"' class='searchFilter' style='overflow:auto'></div></div>").insertBefore("#gview_"+$.jgrid.jqID($t.p.id)),
  7153. align = "left", butleft ="";
  7154. if($t.p.direction === "rtl") {
  7155. align = "right";
  7156. butleft = " style='text-align:left'";
  7157. fil.attr("dir","rtl");
  7158. }
  7159. var columns = $.extend([],$t.p.colModel),
  7160. bS ="<a 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>",
  7161. bC ="<a 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>",
  7162. bQ = "", tmpl="", colnm, found = false, bt, cmi=-1;
  7163. if(p.showQuery) {
  7164. bQ ="<a 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>";
  7165. }
  7166. if(!p.columns.length) {
  7167. $.each(columns, function(i,n){
  7168. if(!n.label) {
  7169. n.label = $t.p.colNames[i];
  7170. }
  7171. // find first searchable column and set it if no default filter
  7172. if(!found) {
  7173. var searchable = (n.search === undefined) ? true: n.search ,
  7174. hidden = (n.hidden === true),
  7175. ignoreHiding = (n.searchoptions && n.searchoptions.searchhidden === true);
  7176. if ((ignoreHiding && searchable) || (searchable && !hidden)) {
  7177. found = true;
  7178. colnm = n.index || n.name;
  7179. cmi =i;
  7180. }
  7181. }
  7182. });
  7183. } else {
  7184. columns = p.columns;
  7185. cmi = 0;
  7186. colnm = columns[0].index || columns[0].name;
  7187. }
  7188. // old behaviour
  7189. if( (!defaultFilters && colnm) || p.multipleSearch === false ) {
  7190. var cmop = "eq";
  7191. if(cmi >=0 && columns[cmi].searchoptions && columns[cmi].searchoptions.sopt) {
  7192. cmop = columns[cmi].searchoptions.sopt[0];
  7193. } else if(p.sopt && p.sopt.length) {
  7194. cmop = p.sopt[0];
  7195. }
  7196. defaultFilters = {groupOp: "AND", rules: [{field: colnm, op: cmop, data: ""}]};
  7197. }
  7198. found = false;
  7199. if(p.tmplNames && p.tmplNames.length) {
  7200. found = true;
  7201. tmpl = p.tmplLabel;
  7202. tmpl += "<select class='ui-template'>";
  7203. tmpl += "<option value='default'>Default</option>";
  7204. $.each(p.tmplNames, function(i,n){
  7205. tmpl += "<option value='"+i+"'>"+n+"</option>";
  7206. });
  7207. tmpl += "</select>";
  7208. }
  7209. 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>";
  7210. fid = $.jgrid.jqID( fid);
  7211. $("#"+fid).jqFilter({
  7212. columns : columns,
  7213. filter: p.loadDefaults ? defaultFilters : null,
  7214. showQuery: p.showQuery,
  7215. errorcheck : p.errorcheck,
  7216. sopt: p.sopt,
  7217. groupButton : p.multipleGroup,
  7218. ruleButtons : p.multipleSearch,
  7219. afterRedraw : p.afterRedraw,
  7220. ops : p.odata,
  7221. operands : p.operands,
  7222. ajaxSelectOptions: $t.p.ajaxSelectOptions,
  7223. groupOps: p.groupOps,
  7224. onChange : function() {
  7225. if(this.p.showQuery) {
  7226. $('.query',this).html(this.toUserFriendlyString());
  7227. }
  7228. if ($.isFunction(p.afterChange)) {
  7229. p.afterChange.call($t, $("#"+fid), p);
  7230. }
  7231. },
  7232. direction : $t.p.direction,
  7233. id: $t.p.id
  7234. });
  7235. fil.append( bt );
  7236. if(found && p.tmplFilters && p.tmplFilters.length) {
  7237. $(".ui-template", fil).bind('change', function(){
  7238. var curtempl = $(this).val();
  7239. if(curtempl==="default") {
  7240. $("#"+fid).jqFilter('addFilter', defaultFilters);
  7241. } else {
  7242. $("#"+fid).jqFilter('addFilter', p.tmplFilters[parseInt(curtempl,10)]);
  7243. }
  7244. return false;
  7245. });
  7246. }
  7247. if(p.multipleGroup === true) {p.multipleSearch = true;}
  7248. $($t).triggerHandler("jqGridFilterInitialize", [$("#"+fid)]);
  7249. if($.isFunction(p.onInitializeSearch) ) {
  7250. p.onInitializeSearch.call($t, $("#"+fid));
  7251. }
  7252. p.gbox = "#gbox_"+fid;
  7253. if (p.layer) {
  7254. $.jgrid.createModal(IDs ,fil,p,"#gview_"+$.jgrid.jqID($t.p.id),$("#gbox_"+$.jgrid.jqID($t.p.id))[0], "#"+$.jgrid.jqID(p.layer), {position: "relative"});
  7255. } else {
  7256. $.jgrid.createModal(IDs ,fil,p,"#gview_"+$.jgrid.jqID($t.p.id),$("#gbox_"+$.jgrid.jqID($t.p.id))[0]);
  7257. }
  7258. if (p.searchOnEnter || p.closeOnEscape) {
  7259. $("#"+$.jgrid.jqID(IDs.themodal)).keydown(function (e) {
  7260. var $target = $(e.target);
  7261. if (p.searchOnEnter && e.which === 13 && // 13 === $.ui.keyCode.ENTER
  7262. !$target.hasClass('add-group') && !$target.hasClass('add-rule') &&
  7263. !$target.hasClass('delete-group') && !$target.hasClass('delete-rule') &&
  7264. (!$target.hasClass("fm-button") || !$target.is("[id$=_query]"))) {
  7265. $("#"+fid+"_search").click();
  7266. return false;
  7267. }
  7268. if (p.closeOnEscape && e.which === 27) { // 27 === $.ui.keyCode.ESCAPE
  7269. $("#"+$.jgrid.jqID(IDs.modalhead)).find(".ui-jqdialog-titlebar-close").click();
  7270. return false;
  7271. }
  7272. });
  7273. }
  7274. if(bQ) {
  7275. $("#"+fid+"_query").bind('click', function(){
  7276. $(".queryresult", fil).toggle();
  7277. return false;
  7278. });
  7279. }
  7280. if (p.stringResult===undefined) {
  7281. // to provide backward compatibility, inferring stringResult value from multipleSearch
  7282. p.stringResult = p.multipleSearch;
  7283. }
  7284. $("#"+fid+"_search").bind('click', function(){
  7285. var fl = $("#"+fid), sdata={}, res, filters;
  7286. fl.find(".input-elm:focus").change();
  7287. filters = fl.jqFilter('filterData');
  7288. if(p.errorcheck) {
  7289. fl[0].hideError();
  7290. if(!p.showQuery) {fl.jqFilter('toSQLString');}
  7291. if(fl[0].p.error) {
  7292. fl[0].showError();
  7293. return false;
  7294. }
  7295. }
  7296. if(p.stringResult) {
  7297. try {
  7298. // xmlJsonClass or JSON.stringify
  7299. res = xmlJsonClass.toJson(filters, '', '', false);
  7300. } catch (e) {
  7301. try {
  7302. res = JSON.stringify(filters);
  7303. } catch (e2) { }
  7304. }
  7305. if(typeof res==="string") {
  7306. sdata[p.sFilter] = res;
  7307. $.each([p.sField,p.sValue, p.sOper], function() {sdata[this] = "";});
  7308. }
  7309. } else {
  7310. if(p.multipleSearch) {
  7311. sdata[p.sFilter] = filters;
  7312. $.each([p.sField,p.sValue, p.sOper], function() {sdata[this] = "";});
  7313. } else {
  7314. sdata[p.sField] = filters.rules[0].field;
  7315. sdata[p.sValue] = filters.rules[0].data;
  7316. sdata[p.sOper] = filters.rules[0].op;
  7317. sdata[p.sFilter] = "";
  7318. }
  7319. }
  7320. $t.p.search = true;
  7321. $.extend($t.p.postData,sdata);
  7322. mustReload = $($t).triggerHandler("jqGridFilterSearch");
  7323. if( mustReload === undefined) {
  7324. mustReload = true;
  7325. }
  7326. if(mustReload && $.isFunction(p.onSearch) ) {
  7327. mustReload = p.onSearch.call($t, $t.p.filters);
  7328. }
  7329. if (mustReload !== false) {
  7330. $($t).trigger("reloadGrid",[{page:1}]);
  7331. }
  7332. if(p.closeAfterSearch) {
  7333. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:p.jqModal,onClose: p.onClose});
  7334. }
  7335. return false;
  7336. });
  7337. $("#"+fid+"_reset").bind('click', function(){
  7338. var sdata={},
  7339. fl = $("#"+fid);
  7340. $t.p.search = false;
  7341. $t.p.resetsearch = true;
  7342. if(p.multipleSearch===false) {
  7343. sdata[p.sField] = sdata[p.sValue] = sdata[p.sOper] = "";
  7344. } else {
  7345. sdata[p.sFilter] = "";
  7346. }
  7347. fl[0].resetFilter();
  7348. if(found) {
  7349. $(".ui-template", fil).val("default");
  7350. }
  7351. $.extend($t.p.postData,sdata);
  7352. mustReload = $($t).triggerHandler("jqGridFilterReset");
  7353. if(mustReload === undefined) {
  7354. mustReload = true;
  7355. }
  7356. if(mustReload && $.isFunction(p.onReset) ) {
  7357. mustReload = p.onReset.call($t);
  7358. }
  7359. if(mustReload !== false) {
  7360. $($t).trigger("reloadGrid",[{page:1}]);
  7361. }
  7362. if (p.closeAfterReset) {
  7363. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:p.jqModal,onClose: p.onClose});
  7364. }
  7365. return false;
  7366. });
  7367. showFilter($("#"+fid));
  7368. $(".fm-button:not(.ui-state-disabled)",fil).hover(
  7369. function(){$(this).addClass('ui-state-hover');},
  7370. function(){$(this).removeClass('ui-state-hover');}
  7371. );
  7372. }
  7373. });
  7374. },
  7375. editGridRow : function(rowid, p){
  7376. p = $.extend(true, {
  7377. top : 0,
  7378. left: 0,
  7379. width: 300,
  7380. datawidth: 'auto',
  7381. height: 'auto',
  7382. dataheight: 'auto',
  7383. modal: false,
  7384. overlay : 30,
  7385. drag: true,
  7386. resize: true,
  7387. url: null,
  7388. mtype : "POST",
  7389. clearAfterAdd :true,
  7390. closeAfterEdit : false,
  7391. reloadAfterSubmit : true,
  7392. onInitializeForm: null,
  7393. beforeInitData: null,
  7394. beforeShowForm: null,
  7395. afterShowForm: null,
  7396. beforeSubmit: null,
  7397. afterSubmit: null,
  7398. onclickSubmit: null,
  7399. afterComplete: null,
  7400. onclickPgButtons : null,
  7401. afterclickPgButtons: null,
  7402. editData : {},
  7403. recreateForm : false,
  7404. jqModal : true,
  7405. closeOnEscape : false,
  7406. addedrow : "first",
  7407. topinfo : '',
  7408. bottominfo: '',
  7409. saveicon : [],
  7410. closeicon : [],
  7411. savekey: [false,13],
  7412. navkeys: [false,38,40],
  7413. checkOnSubmit : false,
  7414. checkOnUpdate : false,
  7415. _savedData : {},
  7416. processing : false,
  7417. onClose : null,
  7418. ajaxEditOptions : {},
  7419. serializeEditData : null,
  7420. viewPagerButtons : true,
  7421. overlayClass : 'ui-widget-overlay'
  7422. }, $.jgrid.edit, p || {});
  7423. rp_ge[$(this)[0].p.id] = p;
  7424. return this.each(function(){
  7425. var $t = this;
  7426. if (!$t.grid || !rowid) {return;}
  7427. var gID = $t.p.id,
  7428. frmgr = "FrmGrid_"+gID, frmtborg = "TblGrid_"+gID, frmtb = "#"+$.jgrid.jqID(frmtborg),
  7429. IDs = {themodal:'editmod'+gID,modalhead:'edithd'+gID,modalcontent:'editcnt'+gID, scrollelm : frmgr},
  7430. onBeforeShow = $.isFunction(rp_ge[$t.p.id].beforeShowForm) ? rp_ge[$t.p.id].beforeShowForm : false,
  7431. onAfterShow = $.isFunction(rp_ge[$t.p.id].afterShowForm) ? rp_ge[$t.p.id].afterShowForm : false,
  7432. onBeforeInit = $.isFunction(rp_ge[$t.p.id].beforeInitData) ? rp_ge[$t.p.id].beforeInitData : false,
  7433. onInitializeForm = $.isFunction(rp_ge[$t.p.id].onInitializeForm) ? rp_ge[$t.p.id].onInitializeForm : false,
  7434. showFrm = true,
  7435. maxCols = 1, maxRows=0, postdata, diff, frmoper;
  7436. frmgr = $.jgrid.jqID(frmgr);
  7437. if (rowid === "new") {
  7438. rowid = "_empty";
  7439. frmoper = "add";
  7440. p.caption=rp_ge[$t.p.id].addCaption;
  7441. } else {
  7442. p.caption=rp_ge[$t.p.id].editCaption;
  7443. frmoper = "edit";
  7444. }
  7445. if(!p.recreateForm) {
  7446. if( $($t).data("formProp") ) {
  7447. $.extend(rp_ge[$(this)[0].p.id], $($t).data("formProp"));
  7448. }
  7449. }
  7450. var closeovrl = true;
  7451. if(p.checkOnUpdate && p.jqModal && !p.modal) {
  7452. closeovrl = false;
  7453. }
  7454. function getFormData(){
  7455. $(frmtb+" > tbody > tr > td > .FormElement").each(function() {
  7456. var celm = $(".customelement", this);
  7457. if (celm.length) {
  7458. var elem = celm[0], nm = $(elem).attr('name');
  7459. $.each($t.p.colModel, function(){
  7460. if(this.name === nm && this.editoptions && $.isFunction(this.editoptions.custom_value)) {
  7461. try {
  7462. postdata[nm] = this.editoptions.custom_value.call($t, $("#"+$.jgrid.jqID(nm),frmtb),'get');
  7463. if (postdata[nm] === undefined) {throw "e1";}
  7464. } catch (e) {
  7465. if (e==="e1") {$.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose);}
  7466. else {$.jgrid.info_dialog($.jgrid.errors.errcap,e.message,$.jgrid.edit.bClose);}
  7467. }
  7468. return true;
  7469. }
  7470. });
  7471. } else {
  7472. switch ($(this).get(0).type) {
  7473. case "checkbox":
  7474. if($(this).is(":checked")) {
  7475. postdata[this.name]= $(this).val();
  7476. }else {
  7477. var ofv = $(this).attr("offval");
  7478. postdata[this.name]= ofv;
  7479. }
  7480. break;
  7481. case "select-one":
  7482. postdata[this.name]= $("option:selected",this).val();
  7483. break;
  7484. case "select-multiple":
  7485. postdata[this.name]= $(this).val();
  7486. if(postdata[this.name]) {postdata[this.name] = postdata[this.name].join(",");}
  7487. else {postdata[this.name] ="";}
  7488. var selectedText = [];
  7489. $("option:selected",this).each(
  7490. function(i,selected){
  7491. selectedText[i] = $(selected).text();
  7492. }
  7493. );
  7494. break;
  7495. case "password":
  7496. case "text":
  7497. case "textarea":
  7498. case "button":
  7499. postdata[this.name] = $(this).val();
  7500. break;
  7501. }
  7502. if($t.p.autoencode) {postdata[this.name] = $.jgrid.htmlEncode(postdata[this.name]);}
  7503. }
  7504. });
  7505. return true;
  7506. }
  7507. function createData(rowid,obj,tb,maxcols){
  7508. var nm, hc,trdata, cnt=0,tmp, dc,elc, retpos=[], ind=false,
  7509. tdtmpl = "<td class='CaptionTD'>&#160;</td><td class='DataTD'>&#160;</td>", tmpl="", i; //*2
  7510. for (i =1; i<=maxcols;i++) {
  7511. tmpl += tdtmpl;
  7512. }
  7513. if(rowid !== '_empty') {
  7514. ind = $(obj).jqGrid("getInd",rowid);
  7515. }
  7516. $(obj.p.colModel).each( function(i) {
  7517. nm = this.name;
  7518. // hidden fields are included in the form
  7519. if(this.editrules && this.editrules.edithidden === true) {
  7520. hc = false;
  7521. } else {
  7522. hc = this.hidden === true ? true : false;
  7523. }
  7524. dc = hc ? "style='display:none'" : "";
  7525. if ( nm !== 'cb' && nm !== 'subgrid' && this.editable===true && nm !== 'rn') {
  7526. if(ind === false) {
  7527. tmp = "";
  7528. } else {
  7529. if(nm === obj.p.ExpandColumn && obj.p.treeGrid === true) {
  7530. tmp = $("td[role='gridcell']:eq("+i+")",obj.rows[ind]).text();
  7531. } else {
  7532. try {
  7533. tmp = $.unformat.call(obj, $("td[role='gridcell']:eq("+i+")",obj.rows[ind]),{rowId:rowid, colModel:this},i);
  7534. } catch (_) {
  7535. tmp = (this.edittype && this.edittype === "textarea") ? $("td[role='gridcell']:eq("+i+")",obj.rows[ind]).text() : $("td[role='gridcell']:eq("+i+")",obj.rows[ind]).html();
  7536. }
  7537. if(!tmp || tmp === "&nbsp;" || tmp === "&#160;" || (tmp.length===1 && tmp.charCodeAt(0)===160) ) {tmp='';}
  7538. }
  7539. }
  7540. var opt = $.extend({}, this.editoptions || {} ,{id:nm,name:nm}),
  7541. frmopt = $.extend({}, {elmprefix:'',elmsuffix:'',rowabove:false,rowcontent:''}, this.formoptions || {}),
  7542. rp = parseInt(frmopt.rowpos,10) || cnt+1,
  7543. cp = parseInt((parseInt(frmopt.colpos,10) || 1)*2,10);
  7544. if(rowid === "_empty" && opt.defaultValue ) {
  7545. tmp = $.isFunction(opt.defaultValue) ? opt.defaultValue.call($t) : opt.defaultValue;
  7546. }
  7547. if(!this.edittype) {this.edittype = "text";}
  7548. if($t.p.autoencode) {tmp = $.jgrid.htmlDecode(tmp);}
  7549. elc = $.jgrid.createEl.call($t,this.edittype,opt,tmp,false,$.extend({},$.jgrid.ajaxOptions,obj.p.ajaxSelectOptions || {}));
  7550. //if(tmp === "" && this.edittype == "checkbox") {tmp = $(elc).attr("offval");}
  7551. //if(tmp === "" && this.edittype == "select") {tmp = $("option:eq(0)",elc).text();}
  7552. if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {rp_ge[$t.p.id]._savedData[nm] = tmp;}
  7553. $(elc).addClass("FormElement");
  7554. if( $.inArray(this.edittype, ['text','textarea','password','select']) > -1) {
  7555. $(elc).addClass("ui-widget-content ui-corner-all");
  7556. }
  7557. trdata = $(tb).find("tr[rowpos="+rp+"]");
  7558. if(frmopt.rowabove) {
  7559. var newdata = $("<tr><td class='contentinfo' colspan='"+(maxcols*2)+"'>"+frmopt.rowcontent+"</td></tr>");
  7560. $(tb).append(newdata);
  7561. newdata[0].rp = rp;
  7562. }
  7563. if ( trdata.length===0 ) {
  7564. trdata = $("<tr "+dc+" rowpos='"+rp+"'></tr>").addClass("FormData").attr("id","tr_"+nm);
  7565. $(trdata).append(tmpl);
  7566. $(tb).append(trdata);
  7567. trdata[0].rp = rp;
  7568. }
  7569. $("td:eq("+(cp-2)+")",trdata[0]).html(frmopt.label === undefined ? obj.p.colNames[i]: frmopt.label);
  7570. $("td:eq("+(cp-1)+")",trdata[0]).append(frmopt.elmprefix).append(elc).append(frmopt.elmsuffix);
  7571. if(this.edittype==='custom' && $.isFunction(opt.custom_value) ) {
  7572. opt.custom_value.call($t, $("#"+nm,"#"+frmgr),'set',tmp);
  7573. }
  7574. $.jgrid.bindEv.call($t, elc, opt);
  7575. retpos[cnt] = i;
  7576. cnt++;
  7577. }
  7578. });
  7579. if( cnt > 0) {
  7580. 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>");
  7581. idrow[0].rp = cnt+999;
  7582. $(tb).append(idrow);
  7583. if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {rp_ge[$t.p.id]._savedData[obj.p.id+"_id"] = rowid;}
  7584. }
  7585. return retpos;
  7586. }
  7587. function fillData(rowid,obj,fmid){
  7588. var nm,cnt=0,tmp, fld,opt,vl,vlc;
  7589. 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;}
  7590. var cm = obj.p.colModel;
  7591. if(rowid === '_empty') {
  7592. $(cm).each(function(){
  7593. nm = this.name;
  7594. opt = $.extend({}, this.editoptions || {} );
  7595. fld = $("#"+$.jgrid.jqID(nm),"#"+fmid);
  7596. if(fld && fld.length && fld[0] !== null) {
  7597. vl = "";
  7598. if(this.edittype === 'custom' && $.isFunction(opt.custom_value)) {
  7599. opt.custom_value.call($t, $("#"+nm,"#"+fmid),'set',vl);
  7600. } else if(opt.defaultValue ) {
  7601. vl = $.isFunction(opt.defaultValue) ? opt.defaultValue.call($t) : opt.defaultValue;
  7602. if(fld[0].type==='checkbox') {
  7603. vlc = vl.toLowerCase();
  7604. if(vlc.search(/(false|f|0|no|n|off|undefined)/i)<0 && vlc!=="") {
  7605. fld[0].checked = true;
  7606. fld[0].defaultChecked = true;
  7607. fld[0].value = vl;
  7608. } else {
  7609. fld[0].checked = false;
  7610. fld[0].defaultChecked = false;
  7611. }
  7612. } else {fld.val(vl);}
  7613. } else {
  7614. if( fld[0].type==='checkbox' ) {
  7615. fld[0].checked = false;
  7616. fld[0].defaultChecked = false;
  7617. vl = $(fld).attr("offval");
  7618. } else if (fld[0].type && fld[0].type.substr(0,6)==='select') {
  7619. fld[0].selectedIndex = 0;
  7620. } else {
  7621. fld.val(vl);
  7622. }
  7623. }
  7624. if(rp_ge[$t.p.id].checkOnSubmit===true || rp_ge[$t.p.id].checkOnUpdate) {rp_ge[$t.p.id]._savedData[nm] = vl;}
  7625. }
  7626. });
  7627. $("#id_g","#"+fmid).val(rowid);
  7628. return;
  7629. }
  7630. var tre = $(obj).jqGrid("getInd",rowid,true);
  7631. if(!tre) {return;}
  7632. $('td[role="gridcell"]',tre).each( function(i) {
  7633. nm = cm[i].name;
  7634. // hidden fields are included in the form
  7635. if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn' && cm[i].editable===true) {
  7636. if(nm === obj.p.ExpandColumn && obj.p.treeGrid === true) {
  7637. tmp = $(this).text();
  7638. } else {
  7639. try {
  7640. tmp = $.unformat.call(obj, $(this),{rowId:rowid, colModel:cm[i]},i);
  7641. } catch (_) {
  7642. tmp = cm[i].edittype==="textarea" ? $(this).text() : $(this).html();
  7643. }
  7644. }
  7645. if($t.p.autoencode) {tmp = $.jgrid.htmlDecode(tmp);}
  7646. if(rp_ge[$t.p.id].checkOnSubmit===true || rp_ge[$t.p.id].checkOnUpdate) {rp_ge[$t.p.id]._savedData[nm] = tmp;}
  7647. nm = $.jgrid.jqID(nm);
  7648. switch (cm[i].edittype) {
  7649. case "password":
  7650. case "text":
  7651. case "button" :
  7652. case "image":
  7653. case "textarea":
  7654. if(tmp === "&nbsp;" || tmp === "&#160;" || (tmp.length===1 && tmp.charCodeAt(0)===160) ) {tmp='';}
  7655. $("#"+nm,"#"+fmid).val(tmp);
  7656. break;
  7657. case "select":
  7658. var opv = tmp.split(",");
  7659. opv = $.map(opv,function(n){return $.trim(n);});
  7660. $("#"+nm+" option","#"+fmid).each(function(){
  7661. if (!cm[i].editoptions.multiple && ($.trim(tmp) === $.trim($(this).text()) || opv[0] === $.trim($(this).text()) || opv[0] === $.trim($(this).val())) ){
  7662. this.selected= true;
  7663. } else if (cm[i].editoptions.multiple){
  7664. if( $.inArray($.trim($(this).text()), opv ) > -1 || $.inArray($.trim($(this).val()), opv ) > -1 ){
  7665. this.selected = true;
  7666. }else{
  7667. this.selected = false;
  7668. }
  7669. } else {
  7670. this.selected = false;
  7671. }
  7672. });
  7673. break;
  7674. case "checkbox":
  7675. tmp = String(tmp);
  7676. if(cm[i].editoptions && cm[i].editoptions.value) {
  7677. var cb = cm[i].editoptions.value.split(":");
  7678. if(cb[0] === tmp) {
  7679. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']({"checked":true, "defaultChecked" : true});
  7680. } else {
  7681. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']({"checked":false, "defaultChecked" : false});
  7682. }
  7683. } else {
  7684. tmp = tmp.toLowerCase();
  7685. if(tmp.search(/(false|f|0|no|n|off|undefined)/i)<0 && tmp!=="") {
  7686. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("checked",true);
  7687. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("defaultChecked",true); //ie
  7688. } else {
  7689. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("checked", false);
  7690. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("defaultChecked", false); //ie
  7691. }
  7692. }
  7693. break;
  7694. case 'custom' :
  7695. try {
  7696. if(cm[i].editoptions && $.isFunction(cm[i].editoptions.custom_value)) {
  7697. cm[i].editoptions.custom_value.call($t, $("#"+nm,"#"+fmid),'set',tmp);
  7698. } else {throw "e1";}
  7699. } catch (e) {
  7700. if (e==="e1") {$.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.nodefined,$.jgrid.edit.bClose);}
  7701. else {$.jgrid.info_dialog($.jgrid.errors.errcap,e.message,$.jgrid.edit.bClose);}
  7702. }
  7703. break;
  7704. }
  7705. cnt++;
  7706. }
  7707. });
  7708. if(cnt>0) {$("#id_g",frmtb).val(rowid);}
  7709. }
  7710. function setNulls() {
  7711. $.each($t.p.colModel, function(i,n){
  7712. if(n.editoptions && n.editoptions.NullIfEmpty === true) {
  7713. if(postdata.hasOwnProperty(n.name) && postdata[n.name] === "") {
  7714. postdata[n.name] = 'null';
  7715. }
  7716. }
  7717. });
  7718. }
  7719. function postIt() {
  7720. var copydata, ret=[true,"",""], onCS = {}, opers = $t.p.prmNames, idname, oper, key, selr, i;
  7721. var retvals = $($t).triggerHandler("jqGridAddEditBeforeCheckValues", [$("#"+frmgr), frmoper]);
  7722. if(retvals && typeof retvals === 'object') {postdata = retvals;}
  7723. if($.isFunction(rp_ge[$t.p.id].beforeCheckValues)) {
  7724. retvals = rp_ge[$t.p.id].beforeCheckValues.call($t, postdata,$("#"+frmgr),frmoper);
  7725. if(retvals && typeof retvals === 'object') {postdata = retvals;}
  7726. }
  7727. for( key in postdata ){
  7728. if(postdata.hasOwnProperty(key)) {
  7729. ret = $.jgrid.checkValues.call($t,postdata[key],key);
  7730. if(ret[0] === false) {break;}
  7731. }
  7732. }
  7733. setNulls();
  7734. if(ret[0]) {
  7735. onCS = $($t).triggerHandler("jqGridAddEditClickSubmit", [rp_ge[$t.p.id], postdata, frmoper]);
  7736. if( onCS === undefined && $.isFunction( rp_ge[$t.p.id].onclickSubmit)) {
  7737. onCS = rp_ge[$t.p.id].onclickSubmit.call($t, rp_ge[$t.p.id], postdata, frmoper) || {};
  7738. }
  7739. ret = $($t).triggerHandler("jqGridAddEditBeforeSubmit", [postdata, $("#"+frmgr), frmoper]);
  7740. if(ret === undefined) {
  7741. ret = [true,"",""];
  7742. }
  7743. if( ret[0] && $.isFunction(rp_ge[$t.p.id].beforeSubmit)) {
  7744. ret = rp_ge[$t.p.id].beforeSubmit.call($t,postdata,$("#"+frmgr), frmoper);
  7745. }
  7746. }
  7747. if(ret[0] && !rp_ge[$t.p.id].processing) {
  7748. rp_ge[$t.p.id].processing = true;
  7749. $("#sData", frmtb+"_2").addClass('ui-state-active');
  7750. oper = opers.oper;
  7751. idname = opers.id;
  7752. // we add to pos data array the action - the name is oper
  7753. postdata[oper] = ($.trim(postdata[$t.p.id+"_id"]) === "_empty") ? opers.addoper : opers.editoper;
  7754. if(postdata[oper] !== opers.addoper) {
  7755. postdata[idname] = postdata[$t.p.id+"_id"];
  7756. } else {
  7757. // check to see if we have allredy this field in the form and if yes lieve it
  7758. if( postdata[idname] === undefined ) {postdata[idname] = postdata[$t.p.id+"_id"];}
  7759. }
  7760. delete postdata[$t.p.id+"_id"];
  7761. postdata = $.extend(postdata,rp_ge[$t.p.id].editData,onCS);
  7762. if($t.p.treeGrid === true) {
  7763. if(postdata[oper] === opers.addoper) {
  7764. selr = $($t).jqGrid("getGridParam", 'selrow');
  7765. var tr_par_id = $t.p.treeGridModel === 'adjacency' ? $t.p.treeReader.parent_id_field : 'parent_id';
  7766. postdata[tr_par_id] = selr;
  7767. }
  7768. for(i in $t.p.treeReader){
  7769. if($t.p.treeReader.hasOwnProperty(i)) {
  7770. var itm = $t.p.treeReader[i];
  7771. if(postdata.hasOwnProperty(itm)) {
  7772. if(postdata[oper] === opers.addoper && i === 'parent_id_field') {continue;}
  7773. delete postdata[itm];
  7774. }
  7775. }
  7776. }
  7777. }
  7778. postdata[idname] = $.jgrid.stripPref($t.p.idPrefix, postdata[idname]);
  7779. var ajaxOptions = $.extend({
  7780. url: rp_ge[$t.p.id].url || $($t).jqGrid('getGridParam','editurl'),
  7781. type: rp_ge[$t.p.id].mtype,
  7782. data: $.isFunction(rp_ge[$t.p.id].serializeEditData) ? rp_ge[$t.p.id].serializeEditData.call($t,postdata) : postdata,
  7783. complete:function(data,status){
  7784. var key;
  7785. postdata[idname] = $t.p.idPrefix + postdata[idname];
  7786. if(data.status >= 300 && data.status !== 304) {
  7787. ret[0] = false;
  7788. ret[1] = $($t).triggerHandler("jqGridAddEditErrorTextFormat", [data, frmoper]);
  7789. if ($.isFunction(rp_ge[$t.p.id].errorTextFormat)) {
  7790. ret[1] = rp_ge[$t.p.id].errorTextFormat.call($t, data, frmoper);
  7791. } else {
  7792. ret[1] = status + " Status: '" + data.statusText + "'. Error code: " + data.status;
  7793. }
  7794. } else {
  7795. // data is posted successful
  7796. // execute aftersubmit with the returned data from server
  7797. ret = $($t).triggerHandler("jqGridAddEditAfterSubmit", [data, postdata, frmoper]);
  7798. if(ret === undefined) {
  7799. ret = [true,"",""];
  7800. }
  7801. if( ret[0] && $.isFunction(rp_ge[$t.p.id].afterSubmit) ) {
  7802. ret = rp_ge[$t.p.id].afterSubmit.call($t, data,postdata, frmoper);
  7803. }
  7804. }
  7805. if(ret[0] === false) {
  7806. $("#FormError>td",frmtb).html(ret[1]);
  7807. $("#FormError",frmtb).show();
  7808. } else {
  7809. if($t.p.autoencode) {
  7810. $.each(postdata,function(n,v){
  7811. postdata[n] = $.jgrid.htmlDecode(v);
  7812. });
  7813. }
  7814. //rp_ge[$t.p.id].reloadAfterSubmit = rp_ge[$t.p.id].reloadAfterSubmit && $t.p.datatype != "local";
  7815. // the action is add
  7816. if(postdata[oper] === opers.addoper ) {
  7817. //id processing
  7818. // user not set the id ret[2]
  7819. if(!ret[2]) {ret[2] = $.jgrid.randId();}
  7820. postdata[idname] = ret[2];
  7821. if(rp_ge[$t.p.id].reloadAfterSubmit) {
  7822. $($t).trigger("reloadGrid");
  7823. } else {
  7824. if($t.p.treeGrid === true){
  7825. $($t).jqGrid("addChildNode",ret[2],selr,postdata );
  7826. } else {
  7827. $($t).jqGrid("addRowData",ret[2],postdata,p.addedrow);
  7828. }
  7829. }
  7830. if(rp_ge[$t.p.id].closeAfterAdd) {
  7831. if($t.p.treeGrid !== true){
  7832. $($t).jqGrid("setSelection",ret[2]);
  7833. }
  7834. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose});
  7835. } else if (rp_ge[$t.p.id].clearAfterAdd) {
  7836. fillData("_empty",$t,frmgr);
  7837. }
  7838. } else {
  7839. // the action is update
  7840. if(rp_ge[$t.p.id].reloadAfterSubmit) {
  7841. $($t).trigger("reloadGrid");
  7842. if( !rp_ge[$t.p.id].closeAfterEdit ) {setTimeout(function(){$($t).jqGrid("setSelection",postdata[idname]);},1000);}
  7843. } else {
  7844. if($t.p.treeGrid === true) {
  7845. $($t).jqGrid("setTreeRow", postdata[idname],postdata);
  7846. } else {
  7847. $($t).jqGrid("setRowData", postdata[idname],postdata);
  7848. }
  7849. }
  7850. 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});}
  7851. }
  7852. if($.isFunction(rp_ge[$t.p.id].afterComplete)) {
  7853. copydata = data;
  7854. setTimeout(function(){
  7855. $($t).triggerHandler("jqGridAddEditAfterComplete", [copydata, postdata, $("#"+frmgr), frmoper]);
  7856. rp_ge[$t.p.id].afterComplete.call($t, copydata, postdata, $("#"+frmgr), frmoper);
  7857. copydata=null;
  7858. },500);
  7859. }
  7860. if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {
  7861. $("#"+frmgr).data("disabled",false);
  7862. if(rp_ge[$t.p.id]._savedData[$t.p.id+"_id"] !== "_empty"){
  7863. for(key in rp_ge[$t.p.id]._savedData) {
  7864. if(rp_ge[$t.p.id]._savedData.hasOwnProperty(key) && postdata[key]) {
  7865. rp_ge[$t.p.id]._savedData[key] = postdata[key];
  7866. }
  7867. }
  7868. }
  7869. }
  7870. }
  7871. rp_ge[$t.p.id].processing=false;
  7872. $("#sData", frmtb+"_2").removeClass('ui-state-active');
  7873. try{$(':input:visible',"#"+frmgr)[0].focus();} catch (e){}
  7874. }
  7875. }, $.jgrid.ajaxOptions, rp_ge[$t.p.id].ajaxEditOptions );
  7876. if (!ajaxOptions.url && !rp_ge[$t.p.id].useDataProxy) {
  7877. if ($.isFunction($t.p.dataProxy)) {
  7878. rp_ge[$t.p.id].useDataProxy = true;
  7879. } else {
  7880. ret[0]=false;ret[1] += " "+$.jgrid.errors.nourl;
  7881. }
  7882. }
  7883. if (ret[0]) {
  7884. if (rp_ge[$t.p.id].useDataProxy) {
  7885. var dpret = $t.p.dataProxy.call($t, ajaxOptions, "set_"+$t.p.id);
  7886. if(dpret === undefined) {
  7887. dpret = [true, ""];
  7888. }
  7889. if(dpret[0] === false ) {
  7890. ret[0] = false;
  7891. ret[1] = dpret[1] || "Error deleting the selected row!" ;
  7892. } else {
  7893. if(ajaxOptions.data.oper === opers.addoper && rp_ge[$t.p.id].closeAfterAdd ) {
  7894. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});
  7895. }
  7896. if(ajaxOptions.data.oper === opers.editoper && rp_ge[$t.p.id].closeAfterEdit ) {
  7897. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});
  7898. }
  7899. }
  7900. } else {
  7901. $.ajax(ajaxOptions);
  7902. }
  7903. }
  7904. }
  7905. if(ret[0] === false) {
  7906. $("#FormError>td",frmtb).html(ret[1]);
  7907. $("#FormError",frmtb).show();
  7908. // return;
  7909. }
  7910. }
  7911. function compareData(nObj, oObj ) {
  7912. var ret = false,key;
  7913. for (key in nObj) {
  7914. if(nObj.hasOwnProperty(key) && nObj[key] != oObj[key]) {
  7915. ret = true;
  7916. break;
  7917. }
  7918. }
  7919. return ret;
  7920. }
  7921. function checkUpdates () {
  7922. var stat = true;
  7923. $("#FormError",frmtb).hide();
  7924. if(rp_ge[$t.p.id].checkOnUpdate) {
  7925. postdata = {};
  7926. getFormData();
  7927. diff = compareData(postdata,rp_ge[$t.p.id]._savedData);
  7928. if(diff) {
  7929. $("#"+frmgr).data("disabled",true);
  7930. $(".confirm","#"+IDs.themodal).show();
  7931. stat = false;
  7932. }
  7933. }
  7934. return stat;
  7935. }
  7936. function restoreInline()
  7937. {
  7938. var i;
  7939. if (rowid !== "_empty" && $t.p.savedRow !== undefined && $t.p.savedRow.length > 0 && $.isFunction($.fn.jqGrid.restoreRow)) {
  7940. for (i=0;i<$t.p.savedRow.length;i++) {
  7941. if ($t.p.savedRow[i].id == rowid) {
  7942. $($t).jqGrid('restoreRow',rowid);
  7943. break;
  7944. }
  7945. }
  7946. }
  7947. }
  7948. function updateNav(cr, posarr){
  7949. var totr = posarr[1].length-1;
  7950. if (cr===0) {
  7951. $("#pData",frmtb+"_2").addClass('ui-state-disabled');
  7952. } else if( posarr[1][cr-1] !== undefined && $("#"+$.jgrid.jqID(posarr[1][cr-1])).hasClass('ui-state-disabled')) {
  7953. $("#pData",frmtb+"_2").addClass('ui-state-disabled');
  7954. } else {
  7955. $("#pData",frmtb+"_2").removeClass('ui-state-disabled');
  7956. }
  7957. if (cr===totr) {
  7958. $("#nData",frmtb+"_2").addClass('ui-state-disabled');
  7959. } else if( posarr[1][cr+1] !== undefined && $("#"+$.jgrid.jqID(posarr[1][cr+1])).hasClass('ui-state-disabled')) {
  7960. $("#nData",frmtb+"_2").addClass('ui-state-disabled');
  7961. } else {
  7962. $("#nData",frmtb+"_2").removeClass('ui-state-disabled');
  7963. }
  7964. }
  7965. function getCurrPos() {
  7966. var rowsInGrid = $($t).jqGrid("getDataIDs"),
  7967. selrow = $("#id_g",frmtb).val(),
  7968. pos = $.inArray(selrow,rowsInGrid);
  7969. return [pos,rowsInGrid];
  7970. }
  7971. var dh = isNaN(rp_ge[$(this)[0].p.id].dataheight) ? rp_ge[$(this)[0].p.id].dataheight : rp_ge[$(this)[0].p.id].dataheight+"px",
  7972. dw = isNaN(rp_ge[$(this)[0].p.id].datawidth) ? rp_ge[$(this)[0].p.id].datawidth : rp_ge[$(this)[0].p.id].datawidth+"px",
  7973. frm = $("<form name='FormPost' id='"+frmgr+"' class='FormGrid' onSubmit='return false;' style='width:"+dw+";overflow:auto;position:relative;height:"+dh+";'></form>").data("disabled",false),
  7974. tbl = $("<table id='"+frmtborg+"' class='EditTable' cellspacing='0' cellpadding='0' border='0'><tbody></tbody></table>");
  7975. showFrm = $($t).triggerHandler("jqGridAddEditBeforeInitData", [$("#"+frmgr), frmoper]);
  7976. if(showFrm === undefined) {
  7977. showFrm = true;
  7978. }
  7979. if(showFrm && onBeforeInit) {
  7980. showFrm = onBeforeInit.call($t,$("#"+frmgr),frmoper);
  7981. }
  7982. if(showFrm === false) {return;}
  7983. restoreInline();
  7984. $($t.p.colModel).each( function() {
  7985. var fmto = this.formoptions;
  7986. maxCols = Math.max(maxCols, fmto ? fmto.colpos || 0 : 0 );
  7987. maxRows = Math.max(maxRows, fmto ? fmto.rowpos || 0 : 0 );
  7988. });
  7989. $(frm).append(tbl);
  7990. var flr = $("<tr id='FormError' style='display:none'><td class='ui-state-error' colspan='"+(maxCols*2)+"'></td></tr>");
  7991. flr[0].rp = 0;
  7992. $(tbl).append(flr);
  7993. //topinfo
  7994. flr = $("<tr style='display:none' class='tinfo'><td class='topinfo' colspan='"+(maxCols*2)+"'>"+rp_ge[$t.p.id].topinfo+"</td></tr>");
  7995. flr[0].rp = 0;
  7996. $(tbl).append(flr);
  7997. // set the id.
  7998. // use carefull only to change here colproperties.
  7999. // create data
  8000. var rtlb = $t.p.direction === "rtl" ? true :false,
  8001. bp = rtlb ? "nData" : "pData",
  8002. bn = rtlb ? "pData" : "nData";
  8003. createData(rowid,$t,tbl,maxCols);
  8004. // buttons at footer
  8005. var bP = "<a id='"+bp+"' class='fm-button ui-state-default ui-corner-left'><span class='ui-icon ui-icon-triangle-1-w'></span></a>",
  8006. bN = "<a id='"+bn+"' class='fm-button ui-state-default ui-corner-right'><span class='ui-icon ui-icon-triangle-1-e'></span></a>",
  8007. bS ="<a id='sData' class='fm-button ui-state-default ui-corner-all'>"+p.bSubmit+"</a>",
  8008. bC ="<a id='cData' class='fm-button ui-state-default ui-corner-all'>"+p.bCancel+"</a>";
  8009. 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>";
  8010. bt += "<tr style='display:none' class='binfo'><td class='bottominfo' colspan='2'>"+rp_ge[$t.p.id].bottominfo+"</td></tr>";
  8011. bt += "</tbody></table>";
  8012. if(maxRows > 0) {
  8013. var sd=[];
  8014. $.each($(tbl)[0].rows,function(i,r){
  8015. sd[i] = r;
  8016. });
  8017. sd.sort(function(a,b){
  8018. if(a.rp > b.rp) {return 1;}
  8019. if(a.rp < b.rp) {return -1;}
  8020. return 0;
  8021. });
  8022. $.each(sd, function(index, row) {
  8023. $('tbody',tbl).append(row);
  8024. });
  8025. }
  8026. p.gbox = "#gbox_"+$.jgrid.jqID(gID);
  8027. var cle = false;
  8028. if(p.closeOnEscape===true){
  8029. p.closeOnEscape = false;
  8030. cle = true;
  8031. }
  8032. var tms = $("<div></div>").append(frm).append(bt);
  8033. $.jgrid.createModal(IDs,tms, rp_ge[$(this)[0].p.id] ,"#gview_"+$.jgrid.jqID($t.p.id),$("#gbox_"+$.jgrid.jqID($t.p.id))[0]);
  8034. if(rtlb) {
  8035. $("#pData, #nData",frmtb+"_2").css("float","right");
  8036. $(".EditButton",frmtb+"_2").css("text-align","left");
  8037. }
  8038. if(rp_ge[$t.p.id].topinfo) {$(".tinfo",frmtb).show();}
  8039. if(rp_ge[$t.p.id].bottominfo) {$(".binfo",frmtb+"_2").show();}
  8040. tms = null;bt=null;
  8041. $("#"+$.jgrid.jqID(IDs.themodal)).keydown( function( e ) {
  8042. var wkey = e.target;
  8043. if ($("#"+frmgr).data("disabled")===true ) {return false;}//??
  8044. if(rp_ge[$t.p.id].savekey[0] === true && e.which === rp_ge[$t.p.id].savekey[1]) { // save
  8045. if(wkey.tagName !== "TEXTAREA") {
  8046. $("#sData", frmtb+"_2").trigger("click");
  8047. return false;
  8048. }
  8049. }
  8050. if(e.which === 27) {
  8051. if(!checkUpdates()) {return false;}
  8052. if(cle) {$.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:p.gbox,jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});}
  8053. return false;
  8054. }
  8055. if(rp_ge[$t.p.id].navkeys[0]===true) {
  8056. if($("#id_g",frmtb).val() === "_empty") {return true;}
  8057. if(e.which === rp_ge[$t.p.id].navkeys[1]){ //up
  8058. $("#pData", frmtb+"_2").trigger("click");
  8059. return false;
  8060. }
  8061. if(e.which === rp_ge[$t.p.id].navkeys[2]){ //down
  8062. $("#nData", frmtb+"_2").trigger("click");
  8063. return false;
  8064. }
  8065. }
  8066. });
  8067. if(p.checkOnUpdate) {
  8068. $("a.ui-jqdialog-titlebar-close span","#"+$.jgrid.jqID(IDs.themodal)).removeClass("jqmClose");
  8069. $("a.ui-jqdialog-titlebar-close","#"+$.jgrid.jqID(IDs.themodal)).unbind("click")
  8070. .click(function(){
  8071. if(!checkUpdates()) {return false;}
  8072. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose});
  8073. return false;
  8074. });
  8075. }
  8076. p.saveicon = $.extend([true,"left","ui-icon-disk"],p.saveicon);
  8077. p.closeicon = $.extend([true,"left","ui-icon-close"],p.closeicon);
  8078. // beforeinitdata after creation of the form
  8079. if(p.saveicon[0]===true) {
  8080. $("#sData",frmtb+"_2").addClass(p.saveicon[1] === "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  8081. .append("<span class='ui-icon "+p.saveicon[2]+"'></span>");
  8082. }
  8083. if(p.closeicon[0]===true) {
  8084. $("#cData",frmtb+"_2").addClass(p.closeicon[1] === "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  8085. .append("<span class='ui-icon "+p.closeicon[2]+"'></span>");
  8086. }
  8087. if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {
  8088. bS ="<a id='sNew' class='fm-button ui-state-default ui-corner-all' style='z-index:1002'>"+p.bYes+"</a>";
  8089. bN ="<a id='nNew' class='fm-button ui-state-default ui-corner-all' style='z-index:1002'>"+p.bNo+"</a>";
  8090. bC ="<a id='cNew' class='fm-button ui-state-default ui-corner-all' style='z-index:1002'>"+p.bExit+"</a>";
  8091. var zI = p.zIndex || 999;zI ++;
  8092. $("<div class='"+ p.overlayClass+" jqgrid-overlay confirm' style='z-index:"+zI+";display:none;'>&#160;"+"</div><div class='confirm ui-widget-content ui-jqconfirm' style='z-index:"+(zI+1)+"'>"+p.saveData+"<br/><br/>"+bS+bN+bC+"</div>").insertAfter("#"+frmgr);
  8093. $("#sNew","#"+$.jgrid.jqID(IDs.themodal)).click(function(){
  8094. postIt();
  8095. $("#"+frmgr).data("disabled",false);
  8096. $(".confirm","#"+$.jgrid.jqID(IDs.themodal)).hide();
  8097. return false;
  8098. });
  8099. $("#nNew","#"+$.jgrid.jqID(IDs.themodal)).click(function(){
  8100. $(".confirm","#"+$.jgrid.jqID(IDs.themodal)).hide();
  8101. $("#"+frmgr).data("disabled",false);
  8102. setTimeout(function(){$(":input:visible","#"+frmgr)[0].focus();},0);
  8103. return false;
  8104. });
  8105. $("#cNew","#"+$.jgrid.jqID(IDs.themodal)).click(function(){
  8106. $(".confirm","#"+$.jgrid.jqID(IDs.themodal)).hide();
  8107. $("#"+frmgr).data("disabled",false);
  8108. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose});
  8109. return false;
  8110. });
  8111. }
  8112. // here initform - only once
  8113. $($t).triggerHandler("jqGridAddEditInitializeForm", [$("#"+frmgr), frmoper]);
  8114. if(onInitializeForm) {onInitializeForm.call($t,$("#"+frmgr), frmoper);}
  8115. if(rowid==="_empty" || !rp_ge[$t.p.id].viewPagerButtons) {$("#pData,#nData",frmtb+"_2").hide();} else {$("#pData,#nData",frmtb+"_2").show();}
  8116. $($t).triggerHandler("jqGridAddEditBeforeShowForm", [$("#"+frmgr), frmoper]);
  8117. if(onBeforeShow) { onBeforeShow.call($t, $("#"+frmgr), frmoper);}
  8118. $("#"+$.jgrid.jqID(IDs.themodal)).data("onClose",rp_ge[$t.p.id].onClose);
  8119. $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{
  8120. gbox:"#gbox_"+$.jgrid.jqID(gID),
  8121. jqm:p.jqModal,
  8122. overlay: p.overlay,
  8123. modal:p.modal,
  8124. overlayClass: p.overlayClass,
  8125. onHide : function(h) {
  8126. $($t).data("formProp", {
  8127. top:parseFloat($(h.w).css("top")),
  8128. left : parseFloat($(h.w).css("left")),
  8129. width : $(h.w).width(),
  8130. height : $(h.w).height(),
  8131. dataheight : $("#"+frmgr).height(),
  8132. datawidth: $("#"+frmgr).width()
  8133. });
  8134. h.w.remove();
  8135. if(h.o) {h.o.remove();}
  8136. }
  8137. });
  8138. if(!closeovrl) {
  8139. $("." + $.jgrid.jqID(p.overlayClass)).click(function(){
  8140. if(!checkUpdates()) {return false;}
  8141. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});
  8142. return false;
  8143. });
  8144. }
  8145. $(".fm-button","#"+$.jgrid.jqID(IDs.themodal)).hover(
  8146. function(){$(this).addClass('ui-state-hover');},
  8147. function(){$(this).removeClass('ui-state-hover');}
  8148. );
  8149. $("#sData", frmtb+"_2").click(function(){
  8150. postdata = {};
  8151. $("#FormError",frmtb).hide();
  8152. // all depend on ret array
  8153. //ret[0] - succes
  8154. //ret[1] - msg if not succes
  8155. //ret[2] - the id that will be set if reload after submit false
  8156. getFormData();
  8157. if(postdata[$t.p.id+"_id"] === "_empty") {postIt();}
  8158. else if(p.checkOnSubmit===true ) {
  8159. diff = compareData(postdata,rp_ge[$t.p.id]._savedData);
  8160. if(diff) {
  8161. $("#"+frmgr).data("disabled",true);
  8162. $(".confirm","#"+$.jgrid.jqID(IDs.themodal)).show();
  8163. } else {
  8164. postIt();
  8165. }
  8166. } else {
  8167. postIt();
  8168. }
  8169. return false;
  8170. });
  8171. $("#cData", frmtb+"_2").click(function(){
  8172. if(!checkUpdates()) {return false;}
  8173. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose});
  8174. return false;
  8175. });
  8176. $("#nData", frmtb+"_2").click(function(){
  8177. if(!checkUpdates()) {return false;}
  8178. $("#FormError",frmtb).hide();
  8179. var npos = getCurrPos();
  8180. npos[0] = parseInt(npos[0],10);
  8181. if(npos[0] !== -1 && npos[1][npos[0]+1]) {
  8182. $($t).triggerHandler("jqGridAddEditClickPgButtons", ['next',$("#"+frmgr),npos[1][npos[0]]]);
  8183. var nposret;
  8184. if($.isFunction(p.onclickPgButtons)) {
  8185. nposret = p.onclickPgButtons.call($t, 'next',$("#"+frmgr),npos[1][npos[0]]);
  8186. if( nposret !== undefined && nposret === false ) {return false;}
  8187. }
  8188. if( $("#"+$.jgrid.jqID(npos[1][npos[0]+1])).hasClass('ui-state-disabled')) {return false;}
  8189. fillData(npos[1][npos[0]+1],$t,frmgr);
  8190. $($t).jqGrid("setSelection",npos[1][npos[0]+1]);
  8191. $($t).triggerHandler("jqGridAddEditAfterClickPgButtons", ['next',$("#"+frmgr),npos[1][npos[0]]]);
  8192. if($.isFunction(p.afterclickPgButtons)) {
  8193. p.afterclickPgButtons.call($t, 'next',$("#"+frmgr),npos[1][npos[0]+1]);
  8194. }
  8195. updateNav(npos[0]+1,npos);
  8196. }
  8197. return false;
  8198. });
  8199. $("#pData", frmtb+"_2").click(function(){
  8200. if(!checkUpdates()) {return false;}
  8201. $("#FormError",frmtb).hide();
  8202. var ppos = getCurrPos();
  8203. if(ppos[0] !== -1 && ppos[1][ppos[0]-1]) {
  8204. $($t).triggerHandler("jqGridAddEditClickPgButtons", ['prev',$("#"+frmgr),ppos[1][ppos[0]]]);
  8205. var pposret;
  8206. if($.isFunction(p.onclickPgButtons)) {
  8207. pposret = p.onclickPgButtons.call($t, 'prev',$("#"+frmgr),ppos[1][ppos[0]]);
  8208. if( pposret !== undefined && pposret === false ) {return false;}
  8209. }
  8210. if( $("#"+$.jgrid.jqID(ppos[1][ppos[0]-1])).hasClass('ui-state-disabled')) {return false;}
  8211. fillData(ppos[1][ppos[0]-1],$t,frmgr);
  8212. $($t).jqGrid("setSelection",ppos[1][ppos[0]-1]);
  8213. $($t).triggerHandler("jqGridAddEditAfterClickPgButtons", ['prev',$("#"+frmgr),ppos[1][ppos[0]]]);
  8214. if($.isFunction(p.afterclickPgButtons)) {
  8215. p.afterclickPgButtons.call($t, 'prev',$("#"+frmgr),ppos[1][ppos[0]-1]);
  8216. }
  8217. updateNav(ppos[0]-1,ppos);
  8218. }
  8219. return false;
  8220. });
  8221. $($t).triggerHandler("jqGridAddEditAfterShowForm", [$("#"+frmgr), frmoper]);
  8222. if(onAfterShow) { onAfterShow.call($t, $("#"+frmgr), frmoper); }
  8223. var posInit =getCurrPos();
  8224. updateNav(posInit[0],posInit);
  8225. });
  8226. },
  8227. viewGridRow : function(rowid, p){
  8228. p = $.extend(true, {
  8229. top : 0,
  8230. left: 0,
  8231. width: 0,
  8232. datawidth: 'auto',
  8233. height: 'auto',
  8234. dataheight: 'auto',
  8235. modal: false,
  8236. overlay: 30,
  8237. drag: true,
  8238. resize: true,
  8239. jqModal: true,
  8240. closeOnEscape : false,
  8241. labelswidth: '30%',
  8242. closeicon: [],
  8243. navkeys: [false,38,40],
  8244. onClose: null,
  8245. beforeShowForm : null,
  8246. beforeInitData : null,
  8247. viewPagerButtons : true,
  8248. recreateForm : false
  8249. }, $.jgrid.view, p || {});
  8250. rp_ge[$(this)[0].p.id] = p;
  8251. return this.each(function(){
  8252. var $t = this;
  8253. if (!$t.grid || !rowid) {return;}
  8254. var gID = $t.p.id,
  8255. frmgr = "ViewGrid_"+$.jgrid.jqID( gID ), frmtb = "ViewTbl_" + $.jgrid.jqID( gID ),
  8256. frmgr_id = "ViewGrid_"+gID, frmtb_id = "ViewTbl_"+gID,
  8257. IDs = {themodal:'viewmod'+gID,modalhead:'viewhd'+gID,modalcontent:'viewcnt'+gID, scrollelm : frmgr},
  8258. onBeforeInit = $.isFunction(rp_ge[$t.p.id].beforeInitData) ? rp_ge[$t.p.id].beforeInitData : false,
  8259. showFrm = true,
  8260. maxCols = 1, maxRows=0;
  8261. if(!p.recreateForm) {
  8262. if( $($t).data("viewProp") ) {
  8263. $.extend(rp_ge[$(this)[0].p.id], $($t).data("viewProp"));
  8264. }
  8265. }
  8266. function focusaref(){ //Sfari 3 issues
  8267. if(rp_ge[$t.p.id].closeOnEscape===true || rp_ge[$t.p.id].navkeys[0]===true) {
  8268. setTimeout(function(){$(".ui-jqdialog-titlebar-close","#"+$.jgrid.jqID(IDs.modalhead)).focus();},0);
  8269. }
  8270. }
  8271. function createData(rowid,obj,tb,maxcols){
  8272. var nm, hc,trdata, cnt=0,tmp, dc, retpos=[], ind=false, i,
  8273. 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="",
  8274. tdtmpl2 = "<td class='CaptionTD form-view-label ui-widget-content'>&#160;</td><td class='DataTD form-view-data ui-widget-content'>&#160;</td>",
  8275. fmtnum = ['integer','number','currency'],max1 =0, max2=0 ,maxw,setme, viewfld;
  8276. for (i=1;i<=maxcols;i++) {
  8277. tmpl += i === 1 ? tdtmpl : tdtmpl2;
  8278. }
  8279. // find max number align rigth with property formatter
  8280. $(obj.p.colModel).each( function() {
  8281. if(this.editrules && this.editrules.edithidden === true) {
  8282. hc = false;
  8283. } else {
  8284. hc = this.hidden === true ? true : false;
  8285. }
  8286. if(!hc && this.align==='right') {
  8287. if(this.formatter && $.inArray(this.formatter,fmtnum) !== -1 ) {
  8288. max1 = Math.max(max1,parseInt(this.width,10));
  8289. } else {
  8290. max2 = Math.max(max2,parseInt(this.width,10));
  8291. }
  8292. }
  8293. });
  8294. maxw = max1 !==0 ? max1 : max2 !==0 ? max2 : 0;
  8295. ind = $(obj).jqGrid("getInd",rowid);
  8296. $(obj.p.colModel).each( function(i) {
  8297. nm = this.name;
  8298. setme = false;
  8299. // hidden fields are included in the form
  8300. if(this.editrules && this.editrules.edithidden === true) {
  8301. hc = false;
  8302. } else {
  8303. hc = this.hidden === true ? true : false;
  8304. }
  8305. dc = hc ? "style='display:none'" : "";
  8306. viewfld = (typeof this.viewable !== 'boolean') ? true : this.viewable;
  8307. if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn' && viewfld) {
  8308. if(ind === false) {
  8309. tmp = "";
  8310. } else {
  8311. if(nm === obj.p.ExpandColumn && obj.p.treeGrid === true) {
  8312. tmp = $("td:eq("+i+")",obj.rows[ind]).text();
  8313. } else {
  8314. tmp = $("td:eq("+i+")",obj.rows[ind]).html();
  8315. }
  8316. }
  8317. setme = this.align === 'right' && maxw !==0 ? true : false;
  8318. var frmopt = $.extend({},{rowabove:false,rowcontent:''}, this.formoptions || {}),
  8319. rp = parseInt(frmopt.rowpos,10) || cnt+1,
  8320. cp = parseInt((parseInt(frmopt.colpos,10) || 1)*2,10);
  8321. if(frmopt.rowabove) {
  8322. var newdata = $("<tr><td class='contentinfo' colspan='"+(maxcols*2)+"'>"+frmopt.rowcontent+"</td></tr>");
  8323. $(tb).append(newdata);
  8324. newdata[0].rp = rp;
  8325. }
  8326. trdata = $(tb).find("tr[rowpos="+rp+"]");
  8327. if ( trdata.length===0 ) {
  8328. trdata = $("<tr "+dc+" rowpos='"+rp+"'></tr>").addClass("FormData").attr("id","trv_"+nm);
  8329. $(trdata).append(tmpl);
  8330. $(tb).append(trdata);
  8331. trdata[0].rp = rp;
  8332. }
  8333. $("td:eq("+(cp-2)+")",trdata[0]).html('<b>'+ (frmopt.label === undefined ? obj.p.colNames[i]: frmopt.label)+'</b>');
  8334. $("td:eq("+(cp-1)+")",trdata[0]).append("<span>"+tmp+"</span>").attr("id","v_"+nm);
  8335. if(setme){
  8336. $("td:eq("+(cp-1)+") span",trdata[0]).css({'text-align':'right',width:maxw+"px"});
  8337. }
  8338. retpos[cnt] = i;
  8339. cnt++;
  8340. }
  8341. });
  8342. if( cnt > 0) {
  8343. 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>");
  8344. idrow[0].rp = cnt+99;
  8345. $(tb).append(idrow);
  8346. }
  8347. return retpos;
  8348. }
  8349. function fillData(rowid,obj){
  8350. var nm, hc,cnt=0,tmp,trv;
  8351. trv = $(obj).jqGrid("getInd",rowid,true);
  8352. if(!trv) {return;}
  8353. $('td',trv).each( function(i) {
  8354. nm = obj.p.colModel[i].name;
  8355. // hidden fields are included in the form
  8356. if(obj.p.colModel[i].editrules && obj.p.colModel[i].editrules.edithidden === true) {
  8357. hc = false;
  8358. } else {
  8359. hc = obj.p.colModel[i].hidden === true ? true : false;
  8360. }
  8361. if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn') {
  8362. if(nm === obj.p.ExpandColumn && obj.p.treeGrid === true) {
  8363. tmp = $(this).text();
  8364. } else {
  8365. tmp = $(this).html();
  8366. }
  8367. nm = $.jgrid.jqID("v_"+nm);
  8368. $("#"+nm+" span","#"+frmtb).html(tmp);
  8369. if (hc) {$("#"+nm,"#"+frmtb).parents("tr:first").hide();}
  8370. cnt++;
  8371. }
  8372. });
  8373. if(cnt>0) {$("#id_g","#"+frmtb).val(rowid);}
  8374. }
  8375. function updateNav(cr,posarr){
  8376. var totr = posarr[1].length-1;
  8377. if (cr===0) {
  8378. $("#pData","#"+frmtb+"_2").addClass('ui-state-disabled');
  8379. } else if( posarr[1][cr-1] !== undefined && $("#"+$.jgrid.jqID(posarr[1][cr-1])).hasClass('ui-state-disabled')) {
  8380. $("#pData",frmtb+"_2").addClass('ui-state-disabled');
  8381. } else {
  8382. $("#pData","#"+frmtb+"_2").removeClass('ui-state-disabled');
  8383. }
  8384. if (cr===totr) {
  8385. $("#nData","#"+frmtb+"_2").addClass('ui-state-disabled');
  8386. } else if( posarr[1][cr+1] !== undefined && $("#"+$.jgrid.jqID(posarr[1][cr+1])).hasClass('ui-state-disabled')) {
  8387. $("#nData",frmtb+"_2").addClass('ui-state-disabled');
  8388. } else {
  8389. $("#nData","#"+frmtb+"_2").removeClass('ui-state-disabled');
  8390. }
  8391. }
  8392. function getCurrPos() {
  8393. var rowsInGrid = $($t).jqGrid("getDataIDs"),
  8394. selrow = $("#id_g","#"+frmtb).val(),
  8395. pos = $.inArray(selrow,rowsInGrid);
  8396. return [pos,rowsInGrid];
  8397. }
  8398. var dh = isNaN(rp_ge[$(this)[0].p.id].dataheight) ? rp_ge[$(this)[0].p.id].dataheight : rp_ge[$(this)[0].p.id].dataheight+"px",
  8399. dw = isNaN(rp_ge[$(this)[0].p.id].datawidth) ? rp_ge[$(this)[0].p.id].datawidth : rp_ge[$(this)[0].p.id].datawidth+"px",
  8400. frm = $("<form name='FormPost' id='"+frmgr_id+"' class='FormGrid' style='width:"+dw+";overflow:auto;position:relative;height:"+dh+";'></form>"),
  8401. tbl =$("<table id='"+frmtb_id+"' class='EditTable' cellspacing='1' cellpadding='2' border='0' style='table-layout:fixed'><tbody></tbody></table>");
  8402. if(onBeforeInit) {
  8403. showFrm = onBeforeInit.call($t,$("#"+frmgr));
  8404. if(showFrm === undefined) {
  8405. showFrm = true;
  8406. }
  8407. }
  8408. if(showFrm === false) {return;}
  8409. $($t.p.colModel).each( function() {
  8410. var fmto = this.formoptions;
  8411. maxCols = Math.max(maxCols, fmto ? fmto.colpos || 0 : 0 );
  8412. maxRows = Math.max(maxRows, fmto ? fmto.rowpos || 0 : 0 );
  8413. });
  8414. // set the id.
  8415. $(frm).append(tbl);
  8416. createData(rowid, $t, tbl, maxCols);
  8417. var rtlb = $t.p.direction === "rtl" ? true :false,
  8418. bp = rtlb ? "nData" : "pData",
  8419. bn = rtlb ? "pData" : "nData",
  8420. // buttons at footer
  8421. bP = "<a id='"+bp+"' class='fm-button ui-state-default ui-corner-left'><span class='ui-icon ui-icon-triangle-1-w'></span></a>",
  8422. bN = "<a id='"+bn+"' class='fm-button ui-state-default ui-corner-right'><span class='ui-icon ui-icon-triangle-1-e'></span></a>",
  8423. bC ="<a id='cData' class='fm-button ui-state-default ui-corner-all'>"+p.bClose+"</a>";
  8424. if(maxRows > 0) {
  8425. var sd=[];
  8426. $.each($(tbl)[0].rows,function(i,r){
  8427. sd[i] = r;
  8428. });
  8429. sd.sort(function(a,b){
  8430. if(a.rp > b.rp) {return 1;}
  8431. if(a.rp < b.rp) {return -1;}
  8432. return 0;
  8433. });
  8434. $.each(sd, function(index, row) {
  8435. $('tbody',tbl).append(row);
  8436. });
  8437. }
  8438. p.gbox = "#gbox_"+$.jgrid.jqID(gID);
  8439. var bt = $("<div></div>").append(frm).append("<table border='0' class='EditTable' id='"+frmtb+"_2'><tbody><tr id='Act_Buttons'><td class='navButton' width='"+p.labelswidth+"'>"+(rtlb ? bN+bP : bP+bN)+"</td><td class='EditButton'>"+bC+"</td></tr></tbody></table>");
  8440. $.jgrid.createModal(IDs,bt,p,"#gview_"+$.jgrid.jqID($t.p.id),$("#gview_"+$.jgrid.jqID($t.p.id))[0]);
  8441. if(rtlb) {
  8442. $("#pData, #nData","#"+frmtb+"_2").css("float","right");
  8443. $(".EditButton","#"+frmtb+"_2").css("text-align","left");
  8444. }
  8445. if(!p.viewPagerButtons) {$("#pData, #nData","#"+frmtb+"_2").hide();}
  8446. bt = null;
  8447. $("#"+IDs.themodal).keydown( function( e ) {
  8448. if(e.which === 27) {
  8449. if(rp_ge[$t.p.id].closeOnEscape) {$.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:p.gbox,jqm:p.jqModal, onClose: p.onClose});}
  8450. return false;
  8451. }
  8452. if(p.navkeys[0]===true) {
  8453. if(e.which === p.navkeys[1]){ //up
  8454. $("#pData", "#"+frmtb+"_2").trigger("click");
  8455. return false;
  8456. }
  8457. if(e.which === p.navkeys[2]){ //down
  8458. $("#nData", "#"+frmtb+"_2").trigger("click");
  8459. return false;
  8460. }
  8461. }
  8462. });
  8463. p.closeicon = $.extend([true,"left","ui-icon-close"],p.closeicon);
  8464. if(p.closeicon[0]===true) {
  8465. $("#cData","#"+frmtb+"_2").addClass(p.closeicon[1] === "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  8466. .append("<span class='ui-icon "+p.closeicon[2]+"'></span>");
  8467. }
  8468. if($.isFunction(p.beforeShowForm)) {p.beforeShowForm.call($t,$("#"+frmgr));}
  8469. $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{
  8470. gbox:"#gbox_"+$.jgrid.jqID(gID),
  8471. jqm:p.jqModal,
  8472. overlay: p.overlay,
  8473. modal:p.modal,
  8474. onHide : function(h) {
  8475. $($t).data("viewProp", {
  8476. top:parseFloat($(h.w).css("top")),
  8477. left : parseFloat($(h.w).css("left")),
  8478. width : $(h.w).width(),
  8479. height : $(h.w).height(),
  8480. dataheight : $("#"+frmgr).height(),
  8481. datawidth: $("#"+frmgr).width()
  8482. });
  8483. h.w.remove();
  8484. if(h.o) {h.o.remove();}
  8485. }
  8486. });
  8487. $(".fm-button:not(.ui-state-disabled)","#"+frmtb+"_2").hover(
  8488. function(){$(this).addClass('ui-state-hover');},
  8489. function(){$(this).removeClass('ui-state-hover');}
  8490. );
  8491. focusaref();
  8492. $("#cData", "#"+frmtb+"_2").click(function(){
  8493. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: p.onClose});
  8494. return false;
  8495. });
  8496. $("#nData", "#"+frmtb+"_2").click(function(){
  8497. $("#FormError","#"+frmtb).hide();
  8498. var npos = getCurrPos();
  8499. npos[0] = parseInt(npos[0],10);
  8500. if(npos[0] !== -1 && npos[1][npos[0]+1]) {
  8501. if($.isFunction(p.onclickPgButtons)) {
  8502. p.onclickPgButtons.call($t,'next',$("#"+frmgr),npos[1][npos[0]]);
  8503. }
  8504. fillData(npos[1][npos[0]+1],$t);
  8505. $($t).jqGrid("setSelection",npos[1][npos[0]+1]);
  8506. if($.isFunction(p.afterclickPgButtons)) {
  8507. p.afterclickPgButtons.call($t,'next',$("#"+frmgr),npos[1][npos[0]+1]);
  8508. }
  8509. updateNav(npos[0]+1,npos);
  8510. }
  8511. focusaref();
  8512. return false;
  8513. });
  8514. $("#pData", "#"+frmtb+"_2").click(function(){
  8515. $("#FormError","#"+frmtb).hide();
  8516. var ppos = getCurrPos();
  8517. if(ppos[0] !== -1 && ppos[1][ppos[0]-1]) {
  8518. if($.isFunction(p.onclickPgButtons)) {
  8519. p.onclickPgButtons.call($t,'prev',$("#"+frmgr),ppos[1][ppos[0]]);
  8520. }
  8521. fillData(ppos[1][ppos[0]-1],$t);
  8522. $($t).jqGrid("setSelection",ppos[1][ppos[0]-1]);
  8523. if($.isFunction(p.afterclickPgButtons)) {
  8524. p.afterclickPgButtons.call($t,'prev',$("#"+frmgr),ppos[1][ppos[0]-1]);
  8525. }
  8526. updateNav(ppos[0]-1,ppos);
  8527. }
  8528. focusaref();
  8529. return false;
  8530. });
  8531. var posInit =getCurrPos();
  8532. updateNav(posInit[0],posInit);
  8533. });
  8534. },
  8535. delGridRow : function(rowids,p) {
  8536. p = $.extend(true, {
  8537. top : 0,
  8538. left: 0,
  8539. width: 240,
  8540. height: 'auto',
  8541. dataheight : 'auto',
  8542. modal: false,
  8543. overlay: 30,
  8544. drag: true,
  8545. resize: true,
  8546. url : '',
  8547. mtype : "POST",
  8548. reloadAfterSubmit: true,
  8549. beforeShowForm: null,
  8550. beforeInitData : null,
  8551. afterShowForm: null,
  8552. beforeSubmit: null,
  8553. onclickSubmit: null,
  8554. afterSubmit: null,
  8555. jqModal : true,
  8556. closeOnEscape : false,
  8557. delData: {},
  8558. delicon : [],
  8559. cancelicon : [],
  8560. onClose : null,
  8561. ajaxDelOptions : {},
  8562. processing : false,
  8563. serializeDelData : null,
  8564. useDataProxy : false
  8565. }, $.jgrid.del, p ||{});
  8566. rp_ge[$(this)[0].p.id] = p;
  8567. return this.each(function(){
  8568. var $t = this;
  8569. if (!$t.grid ) {return;}
  8570. if(!rowids) {return;}
  8571. var onBeforeShow = $.isFunction( rp_ge[$t.p.id].beforeShowForm ),
  8572. onAfterShow = $.isFunction( rp_ge[$t.p.id].afterShowForm ),
  8573. onBeforeInit = $.isFunction(rp_ge[$t.p.id].beforeInitData) ? rp_ge[$t.p.id].beforeInitData : false,
  8574. gID = $t.p.id, onCS = {},
  8575. showFrm = true,
  8576. dtbl = "DelTbl_"+$.jgrid.jqID(gID),postd, idname, opers, oper,
  8577. dtbl_id = "DelTbl_" + gID,
  8578. IDs = {themodal:'delmod'+gID,modalhead:'delhd'+gID,modalcontent:'delcnt'+gID, scrollelm: dtbl};
  8579. if ($.isArray(rowids)) {rowids = rowids.join();}
  8580. if ( $("#"+$.jgrid.jqID(IDs.themodal))[0] !== undefined ) {
  8581. if(onBeforeInit) {
  8582. showFrm = onBeforeInit.call($t,$("#"+dtbl));
  8583. if(showFrm === undefined) {
  8584. showFrm = true;
  8585. }
  8586. }
  8587. if(showFrm === false) {return;}
  8588. $("#DelData>td","#"+dtbl).text(rowids);
  8589. $("#DelError","#"+dtbl).hide();
  8590. if( rp_ge[$t.p.id].processing === true) {
  8591. rp_ge[$t.p.id].processing=false;
  8592. $("#dData", "#"+dtbl).removeClass('ui-state-active');
  8593. }
  8594. if(onBeforeShow) {rp_ge[$t.p.id].beforeShowForm.call($t,$("#"+dtbl));}
  8595. $.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});
  8596. if(onAfterShow) {rp_ge[$t.p.id].afterShowForm.call($t,$("#"+dtbl));}
  8597. } else {
  8598. var dh = isNaN(rp_ge[$t.p.id].dataheight) ? rp_ge[$t.p.id].dataheight : rp_ge[$t.p.id].dataheight+"px",
  8599. dw = isNaN(p.datawidth) ? p.datawidth : p.datawidth+"px",
  8600. tbl = "<div id='"+dtbl_id+"' class='formdata' style='width:"+dw+";overflow:auto;position:relative;height:"+dh+";'>";
  8601. tbl += "<table class='DelTable'><tbody>";
  8602. // error data
  8603. tbl += "<tr id='DelError' style='display:none'><td class='ui-state-error'></td></tr>";
  8604. tbl += "<tr id='DelData' style='display:none'><td >"+rowids+"</td></tr>";
  8605. tbl += "<tr><td class=\"delmsg\" style=\"white-space:pre;\">"+rp_ge[$t.p.id].msg+"</td></tr><tr><td >&#160;</td></tr>";
  8606. // buttons at footer
  8607. tbl += "</tbody></table></div>";
  8608. var bS = "<a id='dData' class='fm-button ui-state-default ui-corner-all'>"+p.bSubmit+"</a>",
  8609. bC = "<a id='eData' class='fm-button ui-state-default ui-corner-all'>"+p.bCancel+"</a>";
  8610. 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>";
  8611. p.gbox = "#gbox_"+$.jgrid.jqID(gID);
  8612. $.jgrid.createModal(IDs,tbl,p,"#gview_"+$.jgrid.jqID($t.p.id),$("#gview_"+$.jgrid.jqID($t.p.id))[0]);
  8613. if(onBeforeInit) {
  8614. showFrm = onBeforeInit.call($t,$("#"+dtbl));
  8615. if(showFrm === undefined) {
  8616. showFrm = true;
  8617. }
  8618. }
  8619. if(showFrm === false) {return;}
  8620. $(".fm-button","#"+dtbl+"_2").hover(
  8621. function(){$(this).addClass('ui-state-hover');},
  8622. function(){$(this).removeClass('ui-state-hover');}
  8623. );
  8624. p.delicon = $.extend([true,"left","ui-icon-scissors"],rp_ge[$t.p.id].delicon);
  8625. p.cancelicon = $.extend([true,"left","ui-icon-cancel"],rp_ge[$t.p.id].cancelicon);
  8626. if(p.delicon[0]===true) {
  8627. $("#dData","#"+dtbl+"_2").addClass(p.delicon[1] === "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  8628. .append("<span class='ui-icon "+p.delicon[2]+"'></span>");
  8629. }
  8630. if(p.cancelicon[0]===true) {
  8631. $("#eData","#"+dtbl+"_2").addClass(p.cancelicon[1] === "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  8632. .append("<span class='ui-icon "+p.cancelicon[2]+"'></span>");
  8633. }
  8634. $("#dData","#"+dtbl+"_2").click(function(){
  8635. var ret=[true,""], pk,
  8636. postdata = $("#DelData>td","#"+dtbl).text(); //the pair is name=val1,val2,...
  8637. onCS = {};
  8638. if( $.isFunction( rp_ge[$t.p.id].onclickSubmit ) ) {onCS = rp_ge[$t.p.id].onclickSubmit.call($t,rp_ge[$t.p.id], postdata) || {};}
  8639. if( $.isFunction( rp_ge[$t.p.id].beforeSubmit ) ) {ret = rp_ge[$t.p.id].beforeSubmit.call($t,postdata);}
  8640. if(ret[0] && !rp_ge[$t.p.id].processing) {
  8641. rp_ge[$t.p.id].processing = true;
  8642. opers = $t.p.prmNames;
  8643. postd = $.extend({},rp_ge[$t.p.id].delData, onCS);
  8644. oper = opers.oper;
  8645. postd[oper] = opers.deloper;
  8646. idname = opers.id;
  8647. postdata = String(postdata).split(",");
  8648. if(!postdata.length) { return false; }
  8649. for(pk in postdata) {
  8650. if(postdata.hasOwnProperty(pk)) {
  8651. postdata[pk] = $.jgrid.stripPref($t.p.idPrefix, postdata[pk]);
  8652. }
  8653. }
  8654. postd[idname] = postdata.join();
  8655. $(this).addClass('ui-state-active');
  8656. var ajaxOptions = $.extend({
  8657. url: rp_ge[$t.p.id].url || $($t).jqGrid('getGridParam','editurl'),
  8658. type: rp_ge[$t.p.id].mtype,
  8659. data: $.isFunction(rp_ge[$t.p.id].serializeDelData) ? rp_ge[$t.p.id].serializeDelData.call($t,postd) : postd,
  8660. complete:function(data,status){
  8661. var i;
  8662. if(data.status >= 300 && data.status !== 304) {
  8663. ret[0] = false;
  8664. if ($.isFunction(rp_ge[$t.p.id].errorTextFormat)) {
  8665. ret[1] = rp_ge[$t.p.id].errorTextFormat.call($t,data);
  8666. } else {
  8667. ret[1] = status + " Status: '" + data.statusText + "'. Error code: " + data.status;
  8668. }
  8669. } else {
  8670. // data is posted successful
  8671. // execute aftersubmit with the returned data from server
  8672. if( $.isFunction( rp_ge[$t.p.id].afterSubmit ) ) {
  8673. ret = rp_ge[$t.p.id].afterSubmit.call($t,data,postd);
  8674. }
  8675. }
  8676. if(ret[0] === false) {
  8677. $("#DelError>td","#"+dtbl).html(ret[1]);
  8678. $("#DelError","#"+dtbl).show();
  8679. } else {
  8680. if(rp_ge[$t.p.id].reloadAfterSubmit && $t.p.datatype !== "local") {
  8681. $($t).trigger("reloadGrid");
  8682. } else {
  8683. if($t.p.treeGrid===true){
  8684. try {$($t).jqGrid("delTreeNode",$t.p.idPrefix+postdata[0]);} catch(e){}
  8685. } else {
  8686. for(i=0;i<postdata.length;i++) {
  8687. $($t).jqGrid("delRowData",$t.p.idPrefix+ postdata[i]);
  8688. }
  8689. }
  8690. $t.p.selrow = null;
  8691. $t.p.selarrrow = [];
  8692. }
  8693. if($.isFunction(rp_ge[$t.p.id].afterComplete)) {
  8694. setTimeout(function(){rp_ge[$t.p.id].afterComplete.call($t,data,postdata);},500);
  8695. }
  8696. }
  8697. rp_ge[$t.p.id].processing=false;
  8698. $("#dData", "#"+dtbl+"_2").removeClass('ui-state-active');
  8699. if(ret[0]) {$.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});}
  8700. }
  8701. }, $.jgrid.ajaxOptions, rp_ge[$t.p.id].ajaxDelOptions);
  8702. if (!ajaxOptions.url && !rp_ge[$t.p.id].useDataProxy) {
  8703. if ($.isFunction($t.p.dataProxy)) {
  8704. rp_ge[$t.p.id].useDataProxy = true;
  8705. } else {
  8706. ret[0]=false;ret[1] += " "+$.jgrid.errors.nourl;
  8707. }
  8708. }
  8709. if (ret[0]) {
  8710. if (rp_ge[$t.p.id].useDataProxy) {
  8711. var dpret = $t.p.dataProxy.call($t, ajaxOptions, "del_"+$t.p.id);
  8712. if(dpret === undefined) {
  8713. dpret = [true, ""];
  8714. }
  8715. if(dpret[0] === false ) {
  8716. ret[0] = false;
  8717. ret[1] = dpret[1] || "Error deleting the selected row!" ;
  8718. } else {
  8719. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});
  8720. }
  8721. }
  8722. else {$.ajax(ajaxOptions);}
  8723. }
  8724. }
  8725. if(ret[0] === false) {
  8726. $("#DelError>td","#"+dtbl).html(ret[1]);
  8727. $("#DelError","#"+dtbl).show();
  8728. }
  8729. return false;
  8730. });
  8731. $("#eData", "#"+dtbl+"_2").click(function(){
  8732. $.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});
  8733. return false;
  8734. });
  8735. if(onBeforeShow) {rp_ge[$t.p.id].beforeShowForm.call($t,$("#"+dtbl));}
  8736. $.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});
  8737. if(onAfterShow) {rp_ge[$t.p.id].afterShowForm.call($t,$("#"+dtbl));}
  8738. }
  8739. if(rp_ge[$t.p.id].closeOnEscape===true) {
  8740. setTimeout(function(){$(".ui-jqdialog-titlebar-close","#"+$.jgrid.jqID(IDs.modalhead)).focus();},0);
  8741. }
  8742. });
  8743. },
  8744. navGrid : function (elem, o, pEdit,pAdd,pDel,pSearch, pView) {
  8745. o = $.extend({
  8746. edit: true,
  8747. editicon: "ui-icon-pencil",
  8748. add: true,
  8749. addicon:"ui-icon-plus",
  8750. del: true,
  8751. delicon:"ui-icon-trash",
  8752. search: true,
  8753. searchicon:"ui-icon-search",
  8754. refresh: true,
  8755. refreshicon:"ui-icon-refresh",
  8756. refreshstate: 'firstpage',
  8757. view: false,
  8758. viewicon : "ui-icon-document",
  8759. position : "left",
  8760. closeOnEscape : true,
  8761. beforeRefresh : null,
  8762. afterRefresh : null,
  8763. cloneToTop : false,
  8764. alertwidth : 200,
  8765. alertheight : 'auto',
  8766. alerttop: null,
  8767. alertleft: null,
  8768. alertzIndex : null
  8769. }, $.jgrid.nav, o ||{});
  8770. return this.each(function() {
  8771. if(this.nav) {return;}
  8772. var alertIDs = {themodal: 'alertmod_' + this.p.id, modalhead: 'alerthd_' + this.p.id,modalcontent: 'alertcnt_' + this.p.id},
  8773. $t = this, twd, tdw;
  8774. if(!$t.grid || typeof elem !== 'string') {return;}
  8775. if ($("#"+alertIDs.themodal)[0] === undefined) {
  8776. if(!o.alerttop && !o.alertleft) {
  8777. if (window.innerWidth !== undefined) {
  8778. o.alertleft = window.innerWidth;
  8779. o.alerttop = window.innerHeight;
  8780. } else if (document.documentElement !== undefined && document.documentElement.clientWidth !== undefined && document.documentElement.clientWidth !== 0) {
  8781. o.alertleft = document.documentElement.clientWidth;
  8782. o.alerttop = document.documentElement.clientHeight;
  8783. } else {
  8784. o.alertleft=1024;
  8785. o.alerttop=768;
  8786. }
  8787. o.alertleft = o.alertleft/2 - parseInt(o.alertwidth,10)/2;
  8788. o.alerttop = o.alerttop/2-25;
  8789. }
  8790. $.jgrid.createModal(alertIDs,
  8791. "<div>"+o.alerttext+"</div><span tabindex='0'><span tabindex='-1' id='jqg_alrt'></span></span>",
  8792. {
  8793. gbox:"#gbox_"+$.jgrid.jqID($t.p.id),
  8794. jqModal:true,
  8795. drag:true,
  8796. resize:true,
  8797. caption:o.alertcap,
  8798. top:o.alerttop,
  8799. left:o.alertleft,
  8800. width:o.alertwidth,
  8801. height: o.alertheight,
  8802. closeOnEscape:o.closeOnEscape,
  8803. zIndex: o.alertzIndex
  8804. },
  8805. "#gview_"+$.jgrid.jqID($t.p.id),
  8806. $("#gbox_"+$.jgrid.jqID($t.p.id))[0],
  8807. true
  8808. );
  8809. }
  8810. var clone = 1, i,
  8811. onHoverIn = function () {
  8812. if (!$(this).hasClass('ui-state-disabled')) {
  8813. $(this).addClass("ui-state-hover");
  8814. }
  8815. },
  8816. onHoverOut = function () {
  8817. $(this).removeClass("ui-state-hover");
  8818. };
  8819. if(o.cloneToTop && $t.p.toppager) {clone = 2;}
  8820. for(i = 0; i<clone; i++) {
  8821. var tbd,
  8822. navtbl = $("<table cellspacing='0' cellpadding='0' border='0' class='ui-pg-table navtable' style='float:left;table-layout:auto;'><tbody><tr></tr></tbody></table>"),
  8823. sep = "<td class='ui-pg-button ui-state-disabled' style='width:4px;'><span class='ui-separator'></span></td>",
  8824. pgid, elemids;
  8825. if(i===0) {
  8826. pgid = elem;
  8827. elemids = $t.p.id;
  8828. if(pgid === $t.p.toppager) {
  8829. elemids += "_top";
  8830. clone = 1;
  8831. }
  8832. } else {
  8833. pgid = $t.p.toppager;
  8834. elemids = $t.p.id+"_top";
  8835. }
  8836. if($t.p.direction === "rtl") {$(navtbl).attr("dir","rtl").css("float","right");}
  8837. if (o.add) {
  8838. pAdd = pAdd || {};
  8839. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  8840. $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.addicon+"'></span>"+o.addtext+"</div>");
  8841. $("tr",navtbl).append(tbd);
  8842. $(tbd,navtbl)
  8843. .attr({"title":o.addtitle || "",id : pAdd.id || "add_"+elemids})
  8844. .click(function(){
  8845. if (!$(this).hasClass('ui-state-disabled')) {
  8846. if ($.isFunction( o.addfunc )) {
  8847. o.addfunc.call($t);
  8848. } else {
  8849. $($t).jqGrid("editGridRow","new",pAdd);
  8850. }
  8851. }
  8852. return false;
  8853. }).hover(onHoverIn, onHoverOut);
  8854. tbd = null;
  8855. }
  8856. if (o.edit) {
  8857. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  8858. pEdit = pEdit || {};
  8859. $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.editicon+"'></span>"+o.edittext+"</div>");
  8860. $("tr",navtbl).append(tbd);
  8861. $(tbd,navtbl)
  8862. .attr({"title":o.edittitle || "",id: pEdit.id || "edit_"+elemids})
  8863. .click(function(){
  8864. if (!$(this).hasClass('ui-state-disabled')) {
  8865. var sr = $t.p.selrow;
  8866. if (sr) {
  8867. if($.isFunction( o.editfunc ) ) {
  8868. o.editfunc.call($t, sr);
  8869. } else {
  8870. $($t).jqGrid("editGridRow",sr,pEdit);
  8871. }
  8872. } else {
  8873. $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:true});
  8874. $("#jqg_alrt").focus();
  8875. }
  8876. }
  8877. return false;
  8878. }).hover(onHoverIn, onHoverOut);
  8879. tbd = null;
  8880. }
  8881. if (o.view) {
  8882. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  8883. pView = pView || {};
  8884. $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.viewicon+"'></span>"+o.viewtext+"</div>");
  8885. $("tr",navtbl).append(tbd);
  8886. $(tbd,navtbl)
  8887. .attr({"title":o.viewtitle || "",id: pView.id || "view_"+elemids})
  8888. .click(function(){
  8889. if (!$(this).hasClass('ui-state-disabled')) {
  8890. var sr = $t.p.selrow;
  8891. if (sr) {
  8892. if($.isFunction( o.viewfunc ) ) {
  8893. o.viewfunc.call($t, sr);
  8894. } else {
  8895. $($t).jqGrid("viewGridRow",sr,pView);
  8896. }
  8897. } else {
  8898. $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:true});
  8899. $("#jqg_alrt").focus();
  8900. }
  8901. }
  8902. return false;
  8903. }).hover(onHoverIn, onHoverOut);
  8904. tbd = null;
  8905. }
  8906. if (o.del) {
  8907. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  8908. pDel = pDel || {};
  8909. $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.delicon+"'></span>"+o.deltext+"</div>");
  8910. $("tr",navtbl).append(tbd);
  8911. $(tbd,navtbl)
  8912. .attr({"title":o.deltitle || "",id: pDel.id || "del_"+elemids})
  8913. .click(function(){
  8914. if (!$(this).hasClass('ui-state-disabled')) {
  8915. var dr;
  8916. if($t.p.multiselect) {
  8917. dr = $t.p.selarrrow;
  8918. if(dr.length===0) {dr = null;}
  8919. } else {
  8920. dr = $t.p.selrow;
  8921. }
  8922. if(dr){
  8923. if($.isFunction( o.delfunc )){
  8924. o.delfunc.call($t, dr);
  8925. }else{
  8926. $($t).jqGrid("delGridRow",dr,pDel);
  8927. }
  8928. } else {
  8929. $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:true});$("#jqg_alrt").focus();
  8930. }
  8931. }
  8932. return false;
  8933. }).hover(onHoverIn, onHoverOut);
  8934. tbd = null;
  8935. }
  8936. if(o.add || o.edit || o.del || o.view) {$("tr",navtbl).append(sep);}
  8937. if (o.search) {
  8938. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  8939. pSearch = pSearch || {};
  8940. $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.searchicon+"'></span>"+o.searchtext+"</div>");
  8941. $("tr",navtbl).append(tbd);
  8942. $(tbd,navtbl)
  8943. .attr({"title":o.searchtitle || "",id:pSearch.id || "search_"+elemids})
  8944. .click(function(){
  8945. if (!$(this).hasClass('ui-state-disabled')) {
  8946. if($.isFunction( o.searchfunc )) {
  8947. o.searchfunc.call($t, pSearch);
  8948. } else {
  8949. $($t).jqGrid("searchGrid",pSearch);
  8950. }
  8951. }
  8952. return false;
  8953. }).hover(onHoverIn, onHoverOut);
  8954. if (pSearch.showOnLoad && pSearch.showOnLoad === true) {
  8955. $(tbd,navtbl).click();
  8956. }
  8957. tbd = null;
  8958. }
  8959. if (o.refresh) {
  8960. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  8961. $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.refreshicon+"'></span>"+o.refreshtext+"</div>");
  8962. $("tr",navtbl).append(tbd);
  8963. $(tbd,navtbl)
  8964. .attr({"title":o.refreshtitle || "",id: "refresh_"+elemids})
  8965. .click(function(){
  8966. if (!$(this).hasClass('ui-state-disabled')) {
  8967. if($.isFunction(o.beforeRefresh)) {o.beforeRefresh.call($t);}
  8968. $t.p.search = false;
  8969. $t.p.resetsearch = true;
  8970. try {
  8971. var gID = $t.p.id;
  8972. $t.p.postData.filters ="";
  8973. try {
  8974. $("#fbox_"+$.jgrid.jqID(gID)).jqFilter('resetFilter');
  8975. } catch(ef) {}
  8976. if($.isFunction($t.clearToolbar)) {$t.clearToolbar.call($t,false);}
  8977. } catch (e) {}
  8978. switch (o.refreshstate) {
  8979. case 'firstpage':
  8980. $($t).trigger("reloadGrid", [{page:1}]);
  8981. break;
  8982. case 'current':
  8983. $($t).trigger("reloadGrid", [{current:true}]);
  8984. break;
  8985. }
  8986. if($.isFunction(o.afterRefresh)) {o.afterRefresh.call($t);}
  8987. }
  8988. return false;
  8989. }).hover(onHoverIn, onHoverOut);
  8990. tbd = null;
  8991. }
  8992. tdw = $(".ui-jqgrid").css("font-size") || "11px";
  8993. $('body').append("<div id='testpg2' class='ui-jqgrid ui-widget ui-widget-content' style='font-size:"+tdw+";visibility:hidden;' ></div>");
  8994. twd = $(navtbl).clone().appendTo("#testpg2").width();
  8995. $("#testpg2").remove();
  8996. $(pgid+"_"+o.position,pgid).append(navtbl);
  8997. if($t.p._nvtd) {
  8998. if(twd > $t.p._nvtd[0] ) {
  8999. $(pgid+"_"+o.position,pgid).width(twd);
  9000. $t.p._nvtd[0] = twd;
  9001. }
  9002. $t.p._nvtd[1] = twd;
  9003. }
  9004. tdw =null;twd=null;navtbl =null;
  9005. this.nav = true;
  9006. }
  9007. });
  9008. },
  9009. navButtonAdd : function (elem, p) {
  9010. p = $.extend({
  9011. caption : "newButton",
  9012. title: '',
  9013. buttonicon : 'ui-icon-newwin',
  9014. onClickButton: null,
  9015. position : "last",
  9016. cursor : 'pointer'
  9017. }, p ||{});
  9018. return this.each(function() {
  9019. if( !this.grid) {return;}
  9020. if( typeof elem === "string" && elem.indexOf("#") !== 0) {elem = "#"+$.jgrid.jqID(elem);}
  9021. var findnav = $(".navtable",elem)[0], $t = this;
  9022. if (findnav) {
  9023. if( p.id && $("#"+$.jgrid.jqID(p.id), findnav)[0] !== undefined ) {return;}
  9024. var tbd = $("<td></td>");
  9025. if(p.buttonicon.toString().toUpperCase() === "NONE") {
  9026. $(tbd).addClass('ui-pg-button ui-corner-all').append("<div class='ui-pg-div'>"+p.caption+"</div>");
  9027. } else {
  9028. $(tbd).addClass('ui-pg-button ui-corner-all').append("<div class='ui-pg-div'><span class='ui-icon "+p.buttonicon+"'></span>"+p.caption+"</div>");
  9029. }
  9030. if(p.id) {$(tbd).attr("id",p.id);}
  9031. if(p.position==='first'){
  9032. if(findnav.rows[0].cells.length ===0 ) {
  9033. $("tr",findnav).append(tbd);
  9034. } else {
  9035. $("tr td:eq(0)",findnav).before(tbd);
  9036. }
  9037. } else {
  9038. $("tr",findnav).append(tbd);
  9039. }
  9040. $(tbd,findnav)
  9041. .attr("title",p.title || "")
  9042. .click(function(e){
  9043. if (!$(this).hasClass('ui-state-disabled')) {
  9044. if ($.isFunction(p.onClickButton) ) {p.onClickButton.call($t,e);}
  9045. }
  9046. return false;
  9047. })
  9048. .hover(
  9049. function () {
  9050. if (!$(this).hasClass('ui-state-disabled')) {
  9051. $(this).addClass('ui-state-hover');
  9052. }
  9053. },
  9054. function () {$(this).removeClass("ui-state-hover");}
  9055. );
  9056. }
  9057. });
  9058. },
  9059. navSeparatorAdd:function (elem,p) {
  9060. p = $.extend({
  9061. sepclass : "ui-separator",
  9062. sepcontent: '',
  9063. position : "last"
  9064. }, p ||{});
  9065. return this.each(function() {
  9066. if( !this.grid) {return;}
  9067. if( typeof elem === "string" && elem.indexOf("#") !== 0) {elem = "#"+$.jgrid.jqID(elem);}
  9068. var findnav = $(".navtable",elem)[0];
  9069. if(findnav) {
  9070. var sep = "<td class='ui-pg-button ui-state-disabled' style='width:4px;'><span class='"+p.sepclass+"'></span>"+p.sepcontent+"</td>";
  9071. if (p.position === 'first') {
  9072. if (findnav.rows[0].cells.length === 0) {
  9073. $("tr", findnav).append(sep);
  9074. } else {
  9075. $("tr td:eq(0)", findnav).before(sep);
  9076. }
  9077. } else {
  9078. $("tr", findnav).append(sep);
  9079. }
  9080. }
  9081. });
  9082. },
  9083. GridToForm : function( rowid, formid ) {
  9084. return this.each(function(){
  9085. var $t = this, i;
  9086. if (!$t.grid) {return;}
  9087. var rowdata = $($t).jqGrid("getRowData",rowid);
  9088. if (rowdata) {
  9089. for(i in rowdata) {
  9090. if(rowdata.hasOwnProperty(i)) {
  9091. if ( $("[name="+$.jgrid.jqID(i)+"]",formid).is("input:radio") || $("[name="+$.jgrid.jqID(i)+"]",formid).is("input:checkbox")) {
  9092. $("[name="+$.jgrid.jqID(i)+"]",formid).each( function() {
  9093. if( $(this).val() == rowdata[i] ) {
  9094. $(this)[$t.p.useProp ? 'prop': 'attr']("checked",true);
  9095. } else {
  9096. $(this)[$t.p.useProp ? 'prop': 'attr']("checked", false);
  9097. }
  9098. });
  9099. } else {
  9100. // this is very slow on big table and form.
  9101. $("[name="+$.jgrid.jqID(i)+"]",formid).val(rowdata[i]);
  9102. }
  9103. }
  9104. }
  9105. }
  9106. });
  9107. },
  9108. FormToGrid : function(rowid, formid, mode, position){
  9109. return this.each(function() {
  9110. var $t = this;
  9111. if(!$t.grid) {return;}
  9112. if(!mode) {mode = 'set';}
  9113. if(!position) {position = 'first';}
  9114. var fields = $(formid).serializeArray();
  9115. var griddata = {};
  9116. $.each(fields, function(i, field){
  9117. griddata[field.name] = field.value;
  9118. });
  9119. if(mode==='add') {$($t).jqGrid("addRowData",rowid,griddata, position);}
  9120. else if(mode==='set') {$($t).jqGrid("setRowData",rowid,griddata);}
  9121. });
  9122. }
  9123. });
  9124. })(jQuery);
  9125. /*jshint eqeqeq:false, eqnull:true, devel:true */
  9126. /*global jQuery */
  9127. (function($){
  9128. /**
  9129. * jqGrid extension for manipulating Grid Data
  9130. * Tony Tomov tony@trirand.com
  9131. * http://trirand.com/blog/
  9132. * Dual licensed under the MIT and GPL licenses:
  9133. * http://www.opensource.org/licenses/mit-license.php
  9134. * http://www.gnu.org/licenses/gpl-2.0.html
  9135. **/
  9136. "use strict";
  9137. $.jgrid.inlineEdit = $.jgrid.inlineEdit || {};
  9138. $.jgrid.extend({
  9139. //Editing
  9140. editRow : function(rowid,keys,oneditfunc,successfunc, url, extraparam, aftersavefunc,errorfunc, afterrestorefunc) {
  9141. // Compatible mode old versions
  9142. var o={}, args = $.makeArray(arguments).slice(1);
  9143. if( $.type(args[0]) === "object" ) {
  9144. o = args[0];
  9145. } else {
  9146. if (keys !== undefined) { o.keys = keys; }
  9147. if ($.isFunction(oneditfunc)) { o.oneditfunc = oneditfunc; }
  9148. if ($.isFunction(successfunc)) { o.successfunc = successfunc; }
  9149. if (url !== undefined) { o.url = url; }
  9150. if (extraparam !== undefined) { o.extraparam = extraparam; }
  9151. if ($.isFunction(aftersavefunc)) { o.aftersavefunc = aftersavefunc; }
  9152. if ($.isFunction(errorfunc)) { o.errorfunc = errorfunc; }
  9153. if ($.isFunction(afterrestorefunc)) { o.afterrestorefunc = afterrestorefunc; }
  9154. // last two not as param, but as object (sorry)
  9155. //if (restoreAfterError !== undefined) { o.restoreAfterError = restoreAfterError; }
  9156. //if (mtype !== undefined) { o.mtype = mtype || "POST"; }
  9157. }
  9158. o = $.extend(true, {
  9159. keys : false,
  9160. oneditfunc: null,
  9161. successfunc: null,
  9162. url: null,
  9163. extraparam: {},
  9164. aftersavefunc: null,
  9165. errorfunc: null,
  9166. afterrestorefunc: null,
  9167. restoreAfterError: true,
  9168. mtype: "POST"
  9169. }, $.jgrid.inlineEdit, o );
  9170. // End compatible
  9171. return this.each(function(){
  9172. var $t = this, nm, tmp, editable, cnt=0, focus=null, svr={}, ind,cm, bfer;
  9173. if (!$t.grid ) { return; }
  9174. ind = $($t).jqGrid("getInd",rowid,true);
  9175. if( ind === false ) {return;}
  9176. bfer = $.isFunction( o.beforeEditRow ) ? o.beforeEditRow.call($t,o, rowid) : undefined;
  9177. if( bfer === undefined ) {
  9178. bfer = true;
  9179. }
  9180. if(!bfer) { return; }
  9181. editable = $(ind).attr("editable") || "0";
  9182. if (editable === "0" && !$(ind).hasClass("not-editable-row")) {
  9183. cm = $t.p.colModel;
  9184. $('td[role="gridcell"]',ind).each( function(i) {
  9185. nm = cm[i].name;
  9186. var treeg = $t.p.treeGrid===true && nm === $t.p.ExpandColumn;
  9187. if(treeg) { tmp = $("span:first",this).html();}
  9188. else {
  9189. try {
  9190. tmp = $.unformat.call($t,this,{rowId:rowid, colModel:cm[i]},i);
  9191. } catch (_) {
  9192. tmp = ( cm[i].edittype && cm[i].edittype === 'textarea' ) ? $(this).text() : $(this).html();
  9193. }
  9194. }
  9195. if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn') {
  9196. if($t.p.autoencode) { tmp = $.jgrid.htmlDecode(tmp); }
  9197. svr[nm]=tmp;
  9198. if(cm[i].editable===true) {
  9199. if(focus===null) { focus = i; }
  9200. if (treeg) { $("span:first",this).html(""); }
  9201. else { $(this).html(""); }
  9202. var opt = $.extend({},cm[i].editoptions || {},{id:rowid+"_"+nm,name:nm});
  9203. if(!cm[i].edittype) { cm[i].edittype = "text"; }
  9204. if(tmp === "&nbsp;" || tmp === "&#160;" || (tmp.length===1 && tmp.charCodeAt(0)===160) ) {tmp='';}
  9205. var elc = $.jgrid.createEl.call($t,cm[i].edittype,opt,tmp,true,$.extend({},$.jgrid.ajaxOptions,$t.p.ajaxSelectOptions || {}));
  9206. $(elc).addClass("editable");
  9207. if(treeg) { $("span:first",this).append(elc); }
  9208. else { $(this).append(elc); }
  9209. $.jgrid.bindEv.call($t, elc, opt);
  9210. //Again IE
  9211. if(cm[i].edittype === "select" && cm[i].editoptions!==undefined && cm[i].editoptions.multiple===true && cm[i].editoptions.dataUrl===undefined && $.jgrid.msie) {
  9212. $(elc).width($(elc).width());
  9213. }
  9214. cnt++;
  9215. }
  9216. }
  9217. });
  9218. if(cnt > 0) {
  9219. svr.id = rowid; $t.p.savedRow.push(svr);
  9220. $(ind).attr("editable","1");
  9221. setTimeout(function(){$("td:eq("+focus+") input",ind).focus();},0);
  9222. if(o.keys===true) {
  9223. $(ind).bind("keydown",function(e) {
  9224. if (e.keyCode === 27) {
  9225. $($t).jqGrid("restoreRow",rowid, o.afterrestorefunc);
  9226. if($t.p._inlinenav) {
  9227. try {
  9228. $($t).jqGrid('showAddEditButtons');
  9229. } catch (eer1) {}
  9230. }
  9231. return false;
  9232. }
  9233. if (e.keyCode === 13) {
  9234. var ta = e.target;
  9235. if(ta.tagName === 'TEXTAREA') { return true; }
  9236. if( $($t).jqGrid("saveRow", rowid, o ) ) {
  9237. if($t.p._inlinenav) {
  9238. try {
  9239. $($t).jqGrid('showAddEditButtons');
  9240. } catch (eer2) {}
  9241. }
  9242. }
  9243. return false;
  9244. }
  9245. });
  9246. }
  9247. $($t).triggerHandler("jqGridInlineEditRow", [rowid, o]);
  9248. if( $.isFunction(o.oneditfunc)) { o.oneditfunc.call($t, rowid); }
  9249. }
  9250. }
  9251. });
  9252. },
  9253. saveRow : function(rowid, successfunc, url, extraparam, aftersavefunc,errorfunc, afterrestorefunc) {
  9254. // Compatible mode old versions
  9255. var args = $.makeArray(arguments).slice(1), o = {};
  9256. if( $.type(args[0]) === "object" ) {
  9257. o = args[0];
  9258. } else {
  9259. if ($.isFunction(successfunc)) { o.successfunc = successfunc; }
  9260. if (url !== undefined) { o.url = url; }
  9261. if (extraparam !== undefined) { o.extraparam = extraparam; }
  9262. if ($.isFunction(aftersavefunc)) { o.aftersavefunc = aftersavefunc; }
  9263. if ($.isFunction(errorfunc)) { o.errorfunc = errorfunc; }
  9264. if ($.isFunction(afterrestorefunc)) { o.afterrestorefunc = afterrestorefunc; }
  9265. }
  9266. o = $.extend(true, {
  9267. successfunc: null,
  9268. url: null,
  9269. extraparam: {},
  9270. aftersavefunc: null,
  9271. errorfunc: null,
  9272. afterrestorefunc: null,
  9273. restoreAfterError: true,
  9274. mtype: "POST"
  9275. }, $.jgrid.inlineEdit, o );
  9276. // End compatible
  9277. var success = false;
  9278. var $t = this[0], nm, tmp={}, tmp2={}, tmp3= {}, editable, fr, cv, ind;
  9279. if (!$t.grid ) { return success; }
  9280. ind = $($t).jqGrid("getInd",rowid,true);
  9281. if(ind === false) {return success;}
  9282. var bfsr = $.isFunction( o.beforeSaveRow ) ? o.beforeSaveRow.call($t,o, rowid) : undefined;
  9283. if( bfsr === undefined ) {
  9284. bfsr = true;
  9285. }
  9286. if(!bfsr) { return; }
  9287. editable = $(ind).attr("editable");
  9288. o.url = o.url || $t.p.editurl;
  9289. if (editable==="1") {
  9290. var cm;
  9291. $('td[role="gridcell"]',ind).each(function(i) {
  9292. cm = $t.p.colModel[i];
  9293. nm = cm.name;
  9294. if ( nm !== 'cb' && nm !== 'subgrid' && cm.editable===true && nm !== 'rn' && !$(this).hasClass('not-editable-cell')) {
  9295. switch (cm.edittype) {
  9296. case "checkbox":
  9297. var cbv = ["Yes","No"];
  9298. if(cm.editoptions ) {
  9299. cbv = cm.editoptions.value.split(":");
  9300. }
  9301. tmp[nm]= $("input",this).is(":checked") ? cbv[0] : cbv[1];
  9302. break;
  9303. case 'text':
  9304. case 'password':
  9305. case 'textarea':
  9306. case "button" :
  9307. tmp[nm]=$("input, textarea",this).val();
  9308. break;
  9309. case 'select':
  9310. if(!cm.editoptions.multiple) {
  9311. tmp[nm] = $("select option:selected",this).val();
  9312. tmp2[nm] = $("select option:selected", this).text();
  9313. } else {
  9314. var sel = $("select",this), selectedText = [];
  9315. tmp[nm] = $(sel).val();
  9316. if(tmp[nm]) { tmp[nm]= tmp[nm].join(","); } else { tmp[nm] =""; }
  9317. $("select option:selected",this).each(
  9318. function(i,selected){
  9319. selectedText[i] = $(selected).text();
  9320. }
  9321. );
  9322. tmp2[nm] = selectedText.join(",");
  9323. }
  9324. if(cm.formatter && cm.formatter === 'select') { tmp2={}; }
  9325. break;
  9326. case 'custom' :
  9327. try {
  9328. if(cm.editoptions && $.isFunction(cm.editoptions.custom_value)) {
  9329. tmp[nm] = cm.editoptions.custom_value.call($t, $(".customelement",this),'get');
  9330. if (tmp[nm] === undefined) { throw "e2"; }
  9331. } else { throw "e1"; }
  9332. } catch (e) {
  9333. if (e==="e1") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.nodefined,$.jgrid.edit.bClose); }
  9334. if (e==="e2") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose); }
  9335. else { $.jgrid.info_dialog($.jgrid.errors.errcap,e.message,$.jgrid.edit.bClose); }
  9336. }
  9337. break;
  9338. }
  9339. cv = $.jgrid.checkValues.call($t,tmp[nm],i);
  9340. if(cv[0] === false) {
  9341. return false;
  9342. }
  9343. if($t.p.autoencode) { tmp[nm] = $.jgrid.htmlEncode(tmp[nm]); }
  9344. if(o.url !== 'clientArray' && cm.editoptions && cm.editoptions.NullIfEmpty === true) {
  9345. if(tmp[nm] === "") {
  9346. tmp3[nm] = 'null';
  9347. }
  9348. }
  9349. }
  9350. });
  9351. if (cv[0] === false){
  9352. try {
  9353. var tr = $($t).jqGrid('getGridRowById', rowid), positions = $.jgrid.findPos(tr);
  9354. $.jgrid.info_dialog($.jgrid.errors.errcap,cv[1],$.jgrid.edit.bClose,{left:positions[0],top:positions[1]+$(tr).outerHeight()});
  9355. } catch (e) {
  9356. alert(cv[1]);
  9357. }
  9358. return success;
  9359. }
  9360. var idname, opers = $t.p.prmNames, oldRowId = rowid;
  9361. if ($t.p.keyIndex === false) {
  9362. idname = opers.id;
  9363. } else {
  9364. idname = $t.p.colModel[$t.p.keyIndex +
  9365. ($t.p.rownumbers === true ? 1 : 0) +
  9366. ($t.p.multiselect === true ? 1 : 0) +
  9367. ($t.p.subGrid === true ? 1 : 0)].name;
  9368. }
  9369. if(tmp) {
  9370. tmp[opers.oper] = opers.editoper;
  9371. if (tmp[idname] === undefined || tmp[idname]==="") {
  9372. tmp[idname] = rowid;
  9373. } else if (ind.id !== $t.p.idPrefix + tmp[idname]) {
  9374. // rename rowid
  9375. var oldid = $.jgrid.stripPref($t.p.idPrefix, rowid);
  9376. if ($t.p._index[oldid] !== undefined) {
  9377. $t.p._index[tmp[idname]] = $t.p._index[oldid];
  9378. delete $t.p._index[oldid];
  9379. }
  9380. rowid = $t.p.idPrefix + tmp[idname];
  9381. $(ind).attr("id", rowid);
  9382. if ($t.p.selrow === oldRowId) {
  9383. $t.p.selrow = rowid;
  9384. }
  9385. if ($.isArray($t.p.selarrrow)) {
  9386. var i = $.inArray(oldRowId, $t.p.selarrrow);
  9387. if (i>=0) {
  9388. $t.p.selarrrow[i] = rowid;
  9389. }
  9390. }
  9391. if ($t.p.multiselect) {
  9392. var newCboxId = "jqg_" + $t.p.id + "_" + rowid;
  9393. $("input.cbox",ind)
  9394. .attr("id", newCboxId)
  9395. .attr("name", newCboxId);
  9396. }
  9397. // TODO: to test the case of frozen columns
  9398. }
  9399. if($t.p.inlineData === undefined) { $t.p.inlineData ={}; }
  9400. tmp = $.extend({},tmp,$t.p.inlineData,o.extraparam);
  9401. }
  9402. if (o.url === 'clientArray') {
  9403. tmp = $.extend({},tmp, tmp2);
  9404. if($t.p.autoencode) {
  9405. $.each(tmp,function(n,v){
  9406. tmp[n] = $.jgrid.htmlDecode(v);
  9407. });
  9408. }
  9409. var k, resp = $($t).jqGrid("setRowData",rowid,tmp);
  9410. $(ind).attr("editable","0");
  9411. for(k=0;k<$t.p.savedRow.length;k++) {
  9412. if( String($t.p.savedRow[k].id) === String(oldRowId)) {fr = k; break;}
  9413. }
  9414. if(fr >= 0) { $t.p.savedRow.splice(fr,1); }
  9415. $($t).triggerHandler("jqGridInlineAfterSaveRow", [rowid, resp, tmp, o]);
  9416. if( $.isFunction(o.aftersavefunc) ) { o.aftersavefunc.call($t, rowid,resp, o); }
  9417. success = true;
  9418. $(ind).removeClass("jqgrid-new-row").unbind("keydown");
  9419. } else {
  9420. $("#lui_"+$.jgrid.jqID($t.p.id)).show();
  9421. tmp3 = $.extend({},tmp,tmp3);
  9422. tmp3[idname] = $.jgrid.stripPref($t.p.idPrefix, tmp3[idname]);
  9423. $.ajax($.extend({
  9424. url:o.url,
  9425. data: $.isFunction($t.p.serializeRowData) ? $t.p.serializeRowData.call($t, tmp3) : tmp3,
  9426. type: o.mtype,
  9427. async : false, //?!?
  9428. complete: function(res,stat){
  9429. $("#lui_"+$.jgrid.jqID($t.p.id)).hide();
  9430. if (stat === "success"){
  9431. var ret = true, sucret, k;
  9432. sucret = $($t).triggerHandler("jqGridInlineSuccessSaveRow", [res, rowid, o]);
  9433. if (!$.isArray(sucret)) {sucret = [true, tmp];}
  9434. if (sucret[0] && $.isFunction(o.successfunc)) {sucret = o.successfunc.call($t, res);}
  9435. if($.isArray(sucret)) {
  9436. // expect array - status, data, rowid
  9437. ret = sucret[0];
  9438. tmp = sucret[1] || tmp;
  9439. } else {
  9440. ret = sucret;
  9441. }
  9442. if (ret===true) {
  9443. if($t.p.autoencode) {
  9444. $.each(tmp,function(n,v){
  9445. tmp[n] = $.jgrid.htmlDecode(v);
  9446. });
  9447. }
  9448. tmp = $.extend({},tmp, tmp2);
  9449. $($t).jqGrid("setRowData",rowid,tmp);
  9450. $(ind).attr("editable","0");
  9451. for(k=0;k<$t.p.savedRow.length;k++) {
  9452. if( String($t.p.savedRow[k].id) === String(rowid)) {fr = k; break;}
  9453. }
  9454. if(fr >= 0) { $t.p.savedRow.splice(fr,1); }
  9455. $($t).triggerHandler("jqGridInlineAfterSaveRow", [rowid, res, tmp, o]);
  9456. if( $.isFunction(o.aftersavefunc) ) { o.aftersavefunc.call($t, rowid,res); }
  9457. success = true;
  9458. $(ind).removeClass("jqgrid-new-row").unbind("keydown");
  9459. } else {
  9460. $($t).triggerHandler("jqGridInlineErrorSaveRow", [rowid, res, stat, null, o]);
  9461. if($.isFunction(o.errorfunc) ) {
  9462. o.errorfunc.call($t, rowid, res, stat, null);
  9463. }
  9464. if(o.restoreAfterError === true) {
  9465. $($t).jqGrid("restoreRow",rowid, o.afterrestorefunc);
  9466. }
  9467. }
  9468. }
  9469. },
  9470. error:function(res,stat,err){
  9471. $("#lui_"+$.jgrid.jqID($t.p.id)).hide();
  9472. $($t).triggerHandler("jqGridInlineErrorSaveRow", [rowid, res, stat, err, o]);
  9473. if($.isFunction(o.errorfunc) ) {
  9474. o.errorfunc.call($t, rowid, res, stat, err);
  9475. } else {
  9476. var rT = res.responseText || res.statusText;
  9477. try {
  9478. $.jgrid.info_dialog($.jgrid.errors.errcap,'<div class="ui-state-error">'+ rT +'</div>', $.jgrid.edit.bClose,{buttonalign:'right'});
  9479. } catch(e) {
  9480. alert(rT);
  9481. }
  9482. }
  9483. if(o.restoreAfterError === true) {
  9484. $($t).jqGrid("restoreRow",rowid, o.afterrestorefunc);
  9485. }
  9486. }
  9487. }, $.jgrid.ajaxOptions, $t.p.ajaxRowOptions || {}));
  9488. }
  9489. }
  9490. return success;
  9491. },
  9492. restoreRow : function(rowid, afterrestorefunc) {
  9493. // Compatible mode old versions
  9494. var args = $.makeArray(arguments).slice(1), o={};
  9495. if( $.type(args[0]) === "object" ) {
  9496. o = args[0];
  9497. } else {
  9498. if ($.isFunction(afterrestorefunc)) { o.afterrestorefunc = afterrestorefunc; }
  9499. }
  9500. o = $.extend(true, {}, $.jgrid.inlineEdit, o );
  9501. // End compatible
  9502. return this.each(function(){
  9503. var $t= this, fr=-1, ind, ares={}, k;
  9504. if (!$t.grid ) { return; }
  9505. ind = $($t).jqGrid("getInd",rowid,true);
  9506. if(ind === false) {return;}
  9507. var bfcr = $.isFunction( o.beforeCancelRow ) ? o.beforeCancelRow.call($t, o, sr) : undefined;
  9508. if( bfcr === undefined ) {
  9509. bfcr = true;
  9510. }
  9511. if(!bfcr) { return; }
  9512. for(k=0;k<$t.p.savedRow.length;k++) {
  9513. if( String($t.p.savedRow[k].id) === String(rowid)) {fr = k; break;}
  9514. }
  9515. if(fr >= 0) {
  9516. if($.isFunction($.fn.datepicker)) {
  9517. try {
  9518. $("input.hasDatepicker","#"+$.jgrid.jqID(ind.id)).datepicker('hide');
  9519. } catch (e) {}
  9520. }
  9521. $.each($t.p.colModel, function(){
  9522. if(this.editable === true && $t.p.savedRow[fr].hasOwnProperty(this.name)) {
  9523. ares[this.name] = $t.p.savedRow[fr][this.name];
  9524. }
  9525. });
  9526. $($t).jqGrid("setRowData",rowid,ares);
  9527. $(ind).attr("editable","0").unbind("keydown");
  9528. $t.p.savedRow.splice(fr,1);
  9529. if($("#"+$.jgrid.jqID(rowid), "#"+$.jgrid.jqID($t.p.id)).hasClass("jqgrid-new-row")){
  9530. setTimeout(function(){
  9531. $($t).jqGrid("delRowData",rowid);
  9532. $($t).jqGrid('showAddEditButtons');
  9533. },0);
  9534. }
  9535. }
  9536. $($t).triggerHandler("jqGridInlineAfterRestoreRow", [rowid]);
  9537. if ($.isFunction(o.afterrestorefunc))
  9538. {
  9539. o.afterrestorefunc.call($t, rowid);
  9540. }
  9541. });
  9542. },
  9543. addRow : function ( p ) {
  9544. p = $.extend(true, {
  9545. rowID : null,
  9546. initdata : {},
  9547. position :"first",
  9548. useDefValues : true,
  9549. useFormatter : false,
  9550. addRowParams : {extraparam:{}}
  9551. },p || {});
  9552. return this.each(function(){
  9553. if (!this.grid ) { return; }
  9554. var $t = this;
  9555. var bfar = $.isFunction( p.beforeAddRow ) ? p.beforeAddRow.call($t,p.addRowParams) : undefined;
  9556. if( bfar === undefined ) {
  9557. bfar = true;
  9558. }
  9559. if(!bfar) { return; }
  9560. p.rowID = $.isFunction(p.rowID) ? p.rowID.call($t, p) : ( (p.rowID != null) ? p.rowID : $.jgrid.randId());
  9561. if(p.useDefValues === true) {
  9562. $($t.p.colModel).each(function(){
  9563. if( this.editoptions && this.editoptions.defaultValue ) {
  9564. var opt = this.editoptions.defaultValue,
  9565. tmp = $.isFunction(opt) ? opt.call($t) : opt;
  9566. p.initdata[this.name] = tmp;
  9567. }
  9568. });
  9569. }
  9570. $($t).jqGrid('addRowData', p.rowID, p.initdata, p.position);
  9571. p.rowID = $t.p.idPrefix + p.rowID;
  9572. $("#"+$.jgrid.jqID(p.rowID), "#"+$.jgrid.jqID($t.p.id)).addClass("jqgrid-new-row");
  9573. if(p.useFormatter) {
  9574. $("#"+$.jgrid.jqID(p.rowID)+" .ui-inline-edit", "#"+$.jgrid.jqID($t.p.id)).click();
  9575. } else {
  9576. var opers = $t.p.prmNames,
  9577. oper = opers.oper;
  9578. p.addRowParams.extraparam[oper] = opers.addoper;
  9579. $($t).jqGrid('editRow', p.rowID, p.addRowParams);
  9580. $($t).jqGrid('setSelection', p.rowID);
  9581. }
  9582. });
  9583. },
  9584. inlineNav : function (elem, o) {
  9585. o = $.extend(true,{
  9586. edit: true,
  9587. editicon: "ui-icon-pencil",
  9588. add: true,
  9589. addicon:"ui-icon-plus",
  9590. save: true,
  9591. saveicon:"ui-icon-disk",
  9592. cancel: true,
  9593. cancelicon:"ui-icon-cancel",
  9594. addParams : {addRowParams: {extraparam: {}}},
  9595. editParams : {},
  9596. restoreAfterSelect : true
  9597. }, $.jgrid.nav, o ||{});
  9598. return this.each(function(){
  9599. if (!this.grid ) { return; }
  9600. var $t = this, onSelect, gID = $.jgrid.jqID($t.p.id);
  9601. $t.p._inlinenav = true;
  9602. // detect the formatactions column
  9603. if(o.addParams.useFormatter === true) {
  9604. var cm = $t.p.colModel,i;
  9605. for (i = 0; i<cm.length; i++) {
  9606. if(cm[i].formatter && cm[i].formatter === "actions" ) {
  9607. if(cm[i].formatoptions) {
  9608. var defaults = {
  9609. keys:false,
  9610. onEdit : null,
  9611. onSuccess: null,
  9612. afterSave:null,
  9613. onError: null,
  9614. afterRestore: null,
  9615. extraparam: {},
  9616. url: null
  9617. },
  9618. ap = $.extend( defaults, cm[i].formatoptions );
  9619. o.addParams.addRowParams = {
  9620. "keys" : ap.keys,
  9621. "oneditfunc" : ap.onEdit,
  9622. "successfunc" : ap.onSuccess,
  9623. "url" : ap.url,
  9624. "extraparam" : ap.extraparam,
  9625. "aftersavefunc" : ap.afterSave,
  9626. "errorfunc": ap.onError,
  9627. "afterrestorefunc" : ap.afterRestore
  9628. };
  9629. }
  9630. break;
  9631. }
  9632. }
  9633. }
  9634. if(o.add) {
  9635. $($t).jqGrid('navButtonAdd', elem,{
  9636. caption : o.addtext,
  9637. title : o.addtitle,
  9638. buttonicon : o.addicon,
  9639. id : $t.p.id+"_iladd",
  9640. onClickButton : function () {
  9641. $($t).jqGrid('addRow', o.addParams);
  9642. if(!o.addParams.useFormatter) {
  9643. $("#"+gID+"_ilsave").removeClass('ui-state-disabled');
  9644. $("#"+gID+"_ilcancel").removeClass('ui-state-disabled');
  9645. $("#"+gID+"_iladd").addClass('ui-state-disabled');
  9646. $("#"+gID+"_iledit").addClass('ui-state-disabled');
  9647. }
  9648. }
  9649. });
  9650. }
  9651. if(o.edit) {
  9652. $($t).jqGrid('navButtonAdd', elem,{
  9653. caption : o.edittext,
  9654. title : o.edittitle,
  9655. buttonicon : o.editicon,
  9656. id : $t.p.id+"_iledit",
  9657. onClickButton : function () {
  9658. var sr = $($t).jqGrid('getGridParam','selrow');
  9659. if(sr) {
  9660. $($t).jqGrid('editRow', sr, o.editParams);
  9661. $("#"+gID+"_ilsave").removeClass('ui-state-disabled');
  9662. $("#"+gID+"_ilcancel").removeClass('ui-state-disabled');
  9663. $("#"+gID+"_iladd").addClass('ui-state-disabled');
  9664. $("#"+gID+"_iledit").addClass('ui-state-disabled');
  9665. } else {
  9666. $.jgrid.viewModal("#alertmod",{gbox:"#gbox_"+gID,jqm:true});$("#jqg_alrt").focus();
  9667. }
  9668. }
  9669. });
  9670. }
  9671. if(o.save) {
  9672. $($t).jqGrid('navButtonAdd', elem,{
  9673. caption : o.savetext || '',
  9674. title : o.savetitle || 'Save row',
  9675. buttonicon : o.saveicon,
  9676. id : $t.p.id+"_ilsave",
  9677. onClickButton : function () {
  9678. var sr = $t.p.savedRow[0].id;
  9679. if(sr) {
  9680. var opers = $t.p.prmNames,
  9681. oper = opers.oper, tmpParams = o.editParams;
  9682. if($("#"+$.jgrid.jqID(sr), "#"+gID ).hasClass("jqgrid-new-row")) {
  9683. o.addParams.addRowParams.extraparam[oper] = opers.addoper;
  9684. tmpParams = o.addParams.addRowParams;
  9685. } else {
  9686. if(!o.editParams.extraparam) {
  9687. o.editParams.extraparam = {};
  9688. }
  9689. o.editParams.extraparam[oper] = opers.editoper;
  9690. }
  9691. if( $($t).jqGrid('saveRow', sr, tmpParams) ) {
  9692. $($t).jqGrid('showAddEditButtons');
  9693. }
  9694. } else {
  9695. $.jgrid.viewModal("#alertmod",{gbox:"#gbox_"+gID,jqm:true});$("#jqg_alrt").focus();
  9696. }
  9697. }
  9698. });
  9699. $("#"+gID+"_ilsave").addClass('ui-state-disabled');
  9700. }
  9701. if(o.cancel) {
  9702. $($t).jqGrid('navButtonAdd', elem,{
  9703. caption : o.canceltext || '',
  9704. title : o.canceltitle || 'Cancel row editing',
  9705. buttonicon : o.cancelicon,
  9706. id : $t.p.id+"_ilcancel",
  9707. onClickButton : function () {
  9708. var sr = $t.p.savedRow[0].id, cancelPrm = o.editParams;
  9709. if(sr) {
  9710. if($("#"+$.jgrid.jqID(sr), "#"+gID ).hasClass("jqgrid-new-row")) {
  9711. cancelPrm = o.addParams.addRowParams;
  9712. }
  9713. $($t).jqGrid('restoreRow', sr, cancelPrm);
  9714. $($t).jqGrid('showAddEditButtons');
  9715. } else {
  9716. $.jgrid.viewModal("#alertmod",{gbox:"#gbox_"+gID,jqm:true});$("#jqg_alrt").focus();
  9717. }
  9718. }
  9719. });
  9720. $("#"+gID+"_ilcancel").addClass('ui-state-disabled');
  9721. }
  9722. if(o.restoreAfterSelect === true) {
  9723. if($.isFunction($t.p.beforeSelectRow)) {
  9724. onSelect = $t.p.beforeSelectRow;
  9725. } else {
  9726. onSelect = false;
  9727. }
  9728. $t.p.beforeSelectRow = function(id, stat) {
  9729. var ret = true;
  9730. if($t.p.savedRow.length > 0 && $t.p._inlinenav===true && ( id !== $t.p.selrow && $t.p.selrow !==null) ) {
  9731. if($t.p.selrow === o.addParams.rowID ) {
  9732. $($t).jqGrid('delRowData', $t.p.selrow);
  9733. } else {
  9734. $($t).jqGrid('restoreRow', $t.p.selrow, o.editParams);
  9735. }
  9736. $($t).jqGrid('showAddEditButtons');
  9737. }
  9738. if(onSelect) {
  9739. ret = onSelect.call($t, id, stat);
  9740. }
  9741. return ret;
  9742. };
  9743. }
  9744. });
  9745. },
  9746. showAddEditButtons : function() {
  9747. return this.each(function(){
  9748. if (!this.grid ) { return; }
  9749. var gID = $.jgrid.jqID(this.p.id);
  9750. $("#"+gID+"_ilsave").addClass('ui-state-disabled');
  9751. $("#"+gID+"_ilcancel").addClass('ui-state-disabled');
  9752. $("#"+gID+"_iladd").removeClass('ui-state-disabled');
  9753. $("#"+gID+"_iledit").removeClass('ui-state-disabled');
  9754. });
  9755. }
  9756. //end inline edit
  9757. });
  9758. })(jQuery);
  9759. /*jshint eqeqeq:false */
  9760. /*global jQuery */
  9761. (function($){
  9762. /*
  9763. **
  9764. * jqGrid extension for cellediting Grid Data
  9765. * Tony Tomov tony@trirand.com
  9766. * http://trirand.com/blog/
  9767. * Dual licensed under the MIT and GPL licenses:
  9768. * http://www.opensource.org/licenses/mit-license.php
  9769. * http://www.gnu.org/licenses/gpl-2.0.html
  9770. **/
  9771. /**
  9772. * all events and options here are aded anonynous and not in the base grid
  9773. * since the array is to big. Here is the order of execution.
  9774. * From this point we use jQuery isFunction
  9775. * formatCell
  9776. * beforeEditCell,
  9777. * onSelectCell (used only for noneditable cels)
  9778. * afterEditCell,
  9779. * beforeSaveCell, (called before validation of values if any)
  9780. * beforeSubmitCell (if cellsubmit remote (ajax))
  9781. * afterSubmitCell(if cellsubmit remote (ajax)),
  9782. * afterSaveCell,
  9783. * errorCell,
  9784. * serializeCellData - new
  9785. * Options
  9786. * cellsubmit (remote,clientArray) (added in grid options)
  9787. * cellurl
  9788. * ajaxCellOptions
  9789. * */
  9790. "use strict";
  9791. $.jgrid.extend({
  9792. editCell : function (iRow,iCol, ed){
  9793. return this.each(function (){
  9794. var $t = this, nm, tmp,cc, cm;
  9795. if (!$t.grid || $t.p.cellEdit !== true) {return;}
  9796. iCol = parseInt(iCol,10);
  9797. // select the row that can be used for other methods
  9798. $t.p.selrow = $t.rows[iRow].id;
  9799. if (!$t.p.knv) {$($t).jqGrid("GridNav");}
  9800. // check to see if we have already edited cell
  9801. if ($t.p.savedRow.length>0) {
  9802. // prevent second click on that field and enable selects
  9803. if (ed===true ) {
  9804. if(iRow == $t.p.iRow && iCol == $t.p.iCol){
  9805. return;
  9806. }
  9807. }
  9808. // save the cell
  9809. $($t).jqGrid("saveCell",$t.p.savedRow[0].id,$t.p.savedRow[0].ic);
  9810. } else {
  9811. window.setTimeout(function () { $("#"+$.jgrid.jqID($t.p.knv)).attr("tabindex","-1").focus();},0);
  9812. }
  9813. cm = $t.p.colModel[iCol];
  9814. nm = cm.name;
  9815. if (nm==='subgrid' || nm==='cb' || nm==='rn') {return;}
  9816. cc = $("td:eq("+iCol+")",$t.rows[iRow]);
  9817. if (cm.editable===true && ed===true && !cc.hasClass("not-editable-cell")) {
  9818. if(parseInt($t.p.iCol,10)>=0 && parseInt($t.p.iRow,10)>=0) {
  9819. $("td:eq("+$t.p.iCol+")",$t.rows[$t.p.iRow]).removeClass("edit-cell ui-state-highlight");
  9820. $($t.rows[$t.p.iRow]).removeClass("selected-row ui-state-hover");
  9821. }
  9822. $(cc).addClass("edit-cell ui-state-highlight");
  9823. $($t.rows[iRow]).addClass("selected-row ui-state-hover");
  9824. try {
  9825. tmp = $.unformat.call($t,cc,{rowId: $t.rows[iRow].id, colModel:cm},iCol);
  9826. } catch (_) {
  9827. tmp = ( cm.edittype && cm.edittype === 'textarea' ) ? $(cc).text() : $(cc).html();
  9828. }
  9829. if($t.p.autoencode) { tmp = $.jgrid.htmlDecode(tmp); }
  9830. if (!cm.edittype) {cm.edittype = "text";}
  9831. $t.p.savedRow.push({id:iRow,ic:iCol,name:nm,v:tmp});
  9832. if(tmp === "&nbsp;" || tmp === "&#160;" || (tmp.length===1 && tmp.charCodeAt(0)===160) ) {tmp='';}
  9833. if($.isFunction($t.p.formatCell)) {
  9834. var tmp2 = $t.p.formatCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
  9835. if(tmp2 !== undefined ) {tmp = tmp2;}
  9836. }
  9837. $($t).triggerHandler("jqGridBeforeEditCell", [$t.rows[iRow].id, nm, tmp, iRow, iCol]);
  9838. if ($.isFunction($t.p.beforeEditCell)) {
  9839. $t.p.beforeEditCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
  9840. }
  9841. var opt = $.extend({}, cm.editoptions || {} ,{id:iRow+"_"+nm,name:nm});
  9842. var elc = $.jgrid.createEl.call($t,cm.edittype,opt,tmp,true,$.extend({},$.jgrid.ajaxOptions,$t.p.ajaxSelectOptions || {}));
  9843. $(cc).html("").append(elc).attr("tabindex","0");
  9844. $.jgrid.bindEv.call($t, elc, opt);
  9845. window.setTimeout(function () { $(elc).focus();},0);
  9846. $("input, select, textarea",cc).bind("keydown",function(e) {
  9847. if (e.keyCode === 27) {
  9848. if($("input.hasDatepicker",cc).length >0) {
  9849. if( $(".ui-datepicker").is(":hidden") ) { $($t).jqGrid("restoreCell",iRow,iCol); }
  9850. else { $("input.hasDatepicker",cc).datepicker('hide'); }
  9851. } else {
  9852. $($t).jqGrid("restoreCell",iRow,iCol);
  9853. }
  9854. } //ESC
  9855. if (e.keyCode === 13) {
  9856. $($t).jqGrid("saveCell",iRow,iCol);
  9857. // Prevent default action
  9858. return false;
  9859. } //Enter
  9860. if (e.keyCode === 9) {
  9861. if(!$t.grid.hDiv.loading ) {
  9862. if (e.shiftKey) {$($t).jqGrid("prevCell",iRow,iCol);} //Shift TAb
  9863. else {$($t).jqGrid("nextCell",iRow,iCol);} //Tab
  9864. } else {
  9865. return false;
  9866. }
  9867. }
  9868. e.stopPropagation();
  9869. });
  9870. $($t).triggerHandler("jqGridAfterEditCell", [$t.rows[iRow].id, nm, tmp, iRow, iCol]);
  9871. if ($.isFunction($t.p.afterEditCell)) {
  9872. $t.p.afterEditCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
  9873. }
  9874. } else {
  9875. if (parseInt($t.p.iCol,10)>=0 && parseInt($t.p.iRow,10)>=0) {
  9876. $("td:eq("+$t.p.iCol+")",$t.rows[$t.p.iRow]).removeClass("edit-cell ui-state-highlight");
  9877. $($t.rows[$t.p.iRow]).removeClass("selected-row ui-state-hover");
  9878. }
  9879. cc.addClass("edit-cell ui-state-highlight");
  9880. $($t.rows[iRow]).addClass("selected-row ui-state-hover");
  9881. tmp = cc.html().replace(/\&#160\;/ig,'');
  9882. $($t).triggerHandler("jqGridSelectCell", [$t.rows[iRow].id, nm, tmp, iRow, iCol]);
  9883. if ($.isFunction($t.p.onSelectCell)) {
  9884. $t.p.onSelectCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
  9885. }
  9886. }
  9887. $t.p.iCol = iCol; $t.p.iRow = iRow;
  9888. });
  9889. },
  9890. saveCell : function (iRow, iCol){
  9891. return this.each(function(){
  9892. var $t= this, fr;
  9893. if (!$t.grid || $t.p.cellEdit !== true) {return;}
  9894. if ( $t.p.savedRow.length >= 1) {fr = 0;} else {fr=null;}
  9895. if(fr !== null) {
  9896. var cc = $("td:eq("+iCol+")",$t.rows[iRow]),v,v2,
  9897. cm = $t.p.colModel[iCol], nm = cm.name, nmjq = $.jgrid.jqID(nm) ;
  9898. switch (cm.edittype) {
  9899. case "select":
  9900. if(!cm.editoptions.multiple) {
  9901. v = $("#"+iRow+"_"+nmjq+" option:selected",$t.rows[iRow]).val();
  9902. v2 = $("#"+iRow+"_"+nmjq+" option:selected",$t.rows[iRow]).text();
  9903. } else {
  9904. var sel = $("#"+iRow+"_"+nmjq,$t.rows[iRow]), selectedText = [];
  9905. v = $(sel).val();
  9906. if(v) { v.join(",");} else { v=""; }
  9907. $("option:selected",sel).each(
  9908. function(i,selected){
  9909. selectedText[i] = $(selected).text();
  9910. }
  9911. );
  9912. v2 = selectedText.join(",");
  9913. }
  9914. if(cm.formatter) { v2 = v; }
  9915. break;
  9916. case "checkbox":
  9917. var cbv = ["Yes","No"];
  9918. if(cm.editoptions){
  9919. cbv = cm.editoptions.value.split(":");
  9920. }
  9921. v = $("#"+iRow+"_"+nmjq,$t.rows[iRow]).is(":checked") ? cbv[0] : cbv[1];
  9922. v2=v;
  9923. break;
  9924. case "password":
  9925. case "text":
  9926. case "textarea":
  9927. case "button" :
  9928. v = $("#"+iRow+"_"+nmjq,$t.rows[iRow]).val();
  9929. v2=v;
  9930. break;
  9931. case 'custom' :
  9932. try {
  9933. if(cm.editoptions && $.isFunction(cm.editoptions.custom_value)) {
  9934. v = cm.editoptions.custom_value.call($t, $(".customelement",cc),'get');
  9935. if (v===undefined) { throw "e2";} else { v2=v; }
  9936. } else { throw "e1"; }
  9937. } catch (e) {
  9938. if (e==="e1") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.nodefined,$.jgrid.edit.bClose); }
  9939. if (e==="e2") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose); }
  9940. else {$.jgrid.info_dialog($.jgrid.errors.errcap,e.message,$.jgrid.edit.bClose); }
  9941. }
  9942. break;
  9943. }
  9944. // The common approach is if nothing changed do not do anything
  9945. if (v2 !== $t.p.savedRow[fr].v){
  9946. var vvv = $($t).triggerHandler("jqGridBeforeSaveCell", [$t.rows[iRow].id, nm, v, iRow, iCol]);
  9947. if (vvv) {v = vvv; v2=vvv;}
  9948. if ($.isFunction($t.p.beforeSaveCell)) {
  9949. var vv = $t.p.beforeSaveCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
  9950. if (vv) {v = vv; v2=vv;}
  9951. }
  9952. var cv = $.jgrid.checkValues.call($t,v,iCol);
  9953. if(cv[0] === true) {
  9954. var addpost = $($t).triggerHandler("jqGridBeforeSubmitCell", [$t.rows[iRow].id, nm, v, iRow, iCol]) || {};
  9955. if ($.isFunction($t.p.beforeSubmitCell)) {
  9956. addpost = $t.p.beforeSubmitCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
  9957. if (!addpost) {addpost={};}
  9958. }
  9959. if( $("input.hasDatepicker",cc).length >0) { $("input.hasDatepicker",cc).datepicker('hide'); }
  9960. if ($t.p.cellsubmit === 'remote') {
  9961. if ($t.p.cellurl) {
  9962. var postdata = {};
  9963. if($t.p.autoencode) { v = $.jgrid.htmlEncode(v); }
  9964. postdata[nm] = v;
  9965. var idname,oper, opers;
  9966. opers = $t.p.prmNames;
  9967. idname = opers.id;
  9968. oper = opers.oper;
  9969. postdata[idname] = $.jgrid.stripPref($t.p.idPrefix, $t.rows[iRow].id);
  9970. postdata[oper] = opers.editoper;
  9971. postdata = $.extend(addpost,postdata);
  9972. $("#lui_"+$.jgrid.jqID($t.p.id)).show();
  9973. $t.grid.hDiv.loading = true;
  9974. $.ajax( $.extend( {
  9975. url: $t.p.cellurl,
  9976. data :$.isFunction($t.p.serializeCellData) ? $t.p.serializeCellData.call($t, postdata) : postdata,
  9977. type: "POST",
  9978. complete: function (result, stat) {
  9979. $("#lui_"+$t.p.id).hide();
  9980. $t.grid.hDiv.loading = false;
  9981. if (stat === 'success') {
  9982. var ret = $($t).triggerHandler("jqGridAfterSubmitCell", [$t, result, postdata.id, nm, v, iRow, iCol]) || [true, ''];
  9983. if (ret[0] === true && $.isFunction($t.p.afterSubmitCell)) {
  9984. ret = $t.p.afterSubmitCell.call($t, result,postdata.id,nm,v,iRow,iCol);
  9985. }
  9986. if(ret[0] === true){
  9987. $(cc).empty();
  9988. $($t).jqGrid("setCell",$t.rows[iRow].id, iCol, v2, false, false, true);
  9989. $(cc).addClass("dirty-cell");
  9990. $($t.rows[iRow]).addClass("edited");
  9991. $($t).triggerHandler("jqGridAfterSaveCell", [$t.rows[iRow].id, nm, v, iRow, iCol]);
  9992. if ($.isFunction($t.p.afterSaveCell)) {
  9993. $t.p.afterSaveCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
  9994. }
  9995. $t.p.savedRow.splice(0,1);
  9996. } else {
  9997. $.jgrid.info_dialog($.jgrid.errors.errcap,ret[1],$.jgrid.edit.bClose);
  9998. $($t).jqGrid("restoreCell",iRow,iCol);
  9999. }
  10000. }
  10001. },
  10002. error:function(res,stat,err) {
  10003. $("#lui_"+$.jgrid.jqID($t.p.id)).hide();
  10004. $t.grid.hDiv.loading = false;
  10005. $($t).triggerHandler("jqGridErrorCell", [res, stat, err]);
  10006. if ($.isFunction($t.p.errorCell)) {
  10007. $t.p.errorCell.call($t, res,stat,err);
  10008. $($t).jqGrid("restoreCell",iRow,iCol);
  10009. } else {
  10010. $.jgrid.info_dialog($.jgrid.errors.errcap,res.status+" : "+res.statusText+"<br/>"+stat,$.jgrid.edit.bClose);
  10011. $($t).jqGrid("restoreCell",iRow,iCol);
  10012. }
  10013. }
  10014. }, $.jgrid.ajaxOptions, $t.p.ajaxCellOptions || {}));
  10015. } else {
  10016. try {
  10017. $.jgrid.info_dialog($.jgrid.errors.errcap,$.jgrid.errors.nourl,$.jgrid.edit.bClose);
  10018. $($t).jqGrid("restoreCell",iRow,iCol);
  10019. } catch (e) {}
  10020. }
  10021. }
  10022. if ($t.p.cellsubmit === 'clientArray') {
  10023. $(cc).empty();
  10024. $($t).jqGrid("setCell",$t.rows[iRow].id,iCol, v2, false, false, true);
  10025. $(cc).addClass("dirty-cell");
  10026. $($t.rows[iRow]).addClass("edited");
  10027. $($t).triggerHandler("jqGridAfterSaveCell", [$t.rows[iRow].id, nm, v, iRow, iCol]);
  10028. if ($.isFunction($t.p.afterSaveCell)) {
  10029. $t.p.afterSaveCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
  10030. }
  10031. $t.p.savedRow.splice(0,1);
  10032. }
  10033. } else {
  10034. try {
  10035. window.setTimeout(function(){$.jgrid.info_dialog($.jgrid.errors.errcap,v+" "+cv[1],$.jgrid.edit.bClose);},100);
  10036. $($t).jqGrid("restoreCell",iRow,iCol);
  10037. } catch (e) {}
  10038. }
  10039. } else {
  10040. $($t).jqGrid("restoreCell",iRow,iCol);
  10041. }
  10042. }
  10043. window.setTimeout(function () { $("#"+$.jgrid.jqID($t.p.knv)).attr("tabindex","-1").focus();},0);
  10044. });
  10045. },
  10046. restoreCell : function(iRow, iCol) {
  10047. return this.each(function(){
  10048. var $t= this, fr;
  10049. if (!$t.grid || $t.p.cellEdit !== true ) {return;}
  10050. if ( $t.p.savedRow.length >= 1) {fr = 0;} else {fr=null;}
  10051. if(fr !== null) {
  10052. var cc = $("td:eq("+iCol+")",$t.rows[iRow]);
  10053. // datepicker fix
  10054. if($.isFunction($.fn.datepicker)) {
  10055. try {
  10056. $("input.hasDatepicker",cc).datepicker('hide');
  10057. } catch (e) {}
  10058. }
  10059. $(cc).empty().attr("tabindex","-1");
  10060. $($t).jqGrid("setCell",$t.rows[iRow].id, iCol, $t.p.savedRow[fr].v, false, false, true);
  10061. $($t).triggerHandler("jqGridAfterRestoreCell", [$t.rows[iRow].id, $t.p.savedRow[fr].v, iRow, iCol]);
  10062. if ($.isFunction($t.p.afterRestoreCell)) {
  10063. $t.p.afterRestoreCell.call($t, $t.rows[iRow].id, $t.p.savedRow[fr].v, iRow, iCol);
  10064. }
  10065. $t.p.savedRow.splice(0,1);
  10066. }
  10067. window.setTimeout(function () { $("#"+$t.p.knv).attr("tabindex","-1").focus();},0);
  10068. });
  10069. },
  10070. nextCell : function (iRow,iCol) {
  10071. return this.each(function (){
  10072. var $t = this, nCol=false, i;
  10073. if (!$t.grid || $t.p.cellEdit !== true) {return;}
  10074. // try to find next editable cell
  10075. for (i=iCol+1; i<$t.p.colModel.length; i++) {
  10076. if ( $t.p.colModel[i].editable ===true) {
  10077. nCol = i; break;
  10078. }
  10079. }
  10080. if(nCol !== false) {
  10081. $($t).jqGrid("editCell",iRow,nCol,true);
  10082. } else {
  10083. if ($t.p.savedRow.length >0) {
  10084. $($t).jqGrid("saveCell",iRow,iCol);
  10085. }
  10086. }
  10087. });
  10088. },
  10089. prevCell : function (iRow,iCol) {
  10090. return this.each(function (){
  10091. var $t = this, nCol=false, i;
  10092. if (!$t.grid || $t.p.cellEdit !== true) {return;}
  10093. // try to find next editable cell
  10094. for (i=iCol-1; i>=0; i--) {
  10095. if ( $t.p.colModel[i].editable ===true) {
  10096. nCol = i; break;
  10097. }
  10098. }
  10099. if(nCol !== false) {
  10100. $($t).jqGrid("editCell",iRow,nCol,true);
  10101. } else {
  10102. if ($t.p.savedRow.length >0) {
  10103. $($t).jqGrid("saveCell",iRow,iCol);
  10104. }
  10105. }
  10106. });
  10107. },
  10108. GridNav : function() {
  10109. return this.each(function () {
  10110. var $t = this;
  10111. if (!$t.grid || $t.p.cellEdit !== true ) {return;}
  10112. // trick to process keydown on non input elements
  10113. $t.p.knv = $t.p.id + "_kn";
  10114. var selection = $("<div style='position:fixed;top:0px;width:1px;height:1px;' tabindex='0'><div tabindex='-1' style='width:1px;height:1px;' id='"+$t.p.knv+"'></div></div>"),
  10115. i, kdir;
  10116. function scrollGrid(iR, iC, tp){
  10117. if (tp.substr(0,1)==='v') {
  10118. var ch = $($t.grid.bDiv)[0].clientHeight,
  10119. st = $($t.grid.bDiv)[0].scrollTop,
  10120. nROT = $t.rows[iR].offsetTop+$t.rows[iR].clientHeight,
  10121. pROT = $t.rows[iR].offsetTop;
  10122. if(tp === 'vd') {
  10123. if(nROT >= ch) {
  10124. $($t.grid.bDiv)[0].scrollTop = $($t.grid.bDiv)[0].scrollTop + $t.rows[iR].clientHeight;
  10125. }
  10126. }
  10127. if(tp === 'vu'){
  10128. if (pROT < st ) {
  10129. $($t.grid.bDiv)[0].scrollTop = $($t.grid.bDiv)[0].scrollTop - $t.rows[iR].clientHeight;
  10130. }
  10131. }
  10132. }
  10133. if(tp==='h') {
  10134. var cw = $($t.grid.bDiv)[0].clientWidth,
  10135. sl = $($t.grid.bDiv)[0].scrollLeft,
  10136. nCOL = $t.rows[iR].cells[iC].offsetLeft+$t.rows[iR].cells[iC].clientWidth,
  10137. pCOL = $t.rows[iR].cells[iC].offsetLeft;
  10138. if(nCOL >= cw+parseInt(sl,10)) {
  10139. $($t.grid.bDiv)[0].scrollLeft = $($t.grid.bDiv)[0].scrollLeft + $t.rows[iR].cells[iC].clientWidth;
  10140. } else if (pCOL < sl) {
  10141. $($t.grid.bDiv)[0].scrollLeft = $($t.grid.bDiv)[0].scrollLeft - $t.rows[iR].cells[iC].clientWidth;
  10142. }
  10143. }
  10144. }
  10145. function findNextVisible(iC,act){
  10146. var ind, i;
  10147. if(act === 'lft') {
  10148. ind = iC+1;
  10149. for (i=iC;i>=0;i--){
  10150. if ($t.p.colModel[i].hidden !== true) {
  10151. ind = i;
  10152. break;
  10153. }
  10154. }
  10155. }
  10156. if(act === 'rgt') {
  10157. ind = iC-1;
  10158. for (i=iC; i<$t.p.colModel.length;i++){
  10159. if ($t.p.colModel[i].hidden !== true) {
  10160. ind = i;
  10161. break;
  10162. }
  10163. }
  10164. }
  10165. return ind;
  10166. }
  10167. $(selection).insertBefore($t.grid.cDiv);
  10168. $("#"+$t.p.knv)
  10169. .focus()
  10170. .keydown(function (e){
  10171. kdir = e.keyCode;
  10172. if($t.p.direction === "rtl") {
  10173. if(kdir===37) { kdir = 39;}
  10174. else if (kdir===39) { kdir = 37; }
  10175. }
  10176. switch (kdir) {
  10177. case 38:
  10178. if ($t.p.iRow-1 >0 ) {
  10179. scrollGrid($t.p.iRow-1,$t.p.iCol,'vu');
  10180. $($t).jqGrid("editCell",$t.p.iRow-1,$t.p.iCol,false);
  10181. }
  10182. break;
  10183. case 40 :
  10184. if ($t.p.iRow+1 <= $t.rows.length-1) {
  10185. scrollGrid($t.p.iRow+1,$t.p.iCol,'vd');
  10186. $($t).jqGrid("editCell",$t.p.iRow+1,$t.p.iCol,false);
  10187. }
  10188. break;
  10189. case 37 :
  10190. if ($t.p.iCol -1 >= 0) {
  10191. i = findNextVisible($t.p.iCol-1,'lft');
  10192. scrollGrid($t.p.iRow, i,'h');
  10193. $($t).jqGrid("editCell",$t.p.iRow, i,false);
  10194. }
  10195. break;
  10196. case 39 :
  10197. if ($t.p.iCol +1 <= $t.p.colModel.length-1) {
  10198. i = findNextVisible($t.p.iCol+1,'rgt');
  10199. scrollGrid($t.p.iRow,i,'h');
  10200. $($t).jqGrid("editCell",$t.p.iRow,i,false);
  10201. }
  10202. break;
  10203. case 13:
  10204. if (parseInt($t.p.iCol,10)>=0 && parseInt($t.p.iRow,10)>=0) {
  10205. $($t).jqGrid("editCell",$t.p.iRow,$t.p.iCol,true);
  10206. }
  10207. break;
  10208. default :
  10209. return true;
  10210. }
  10211. return false;
  10212. });
  10213. });
  10214. },
  10215. getChangedCells : function (mthd) {
  10216. var ret=[];
  10217. if (!mthd) {mthd='all';}
  10218. this.each(function(){
  10219. var $t= this,nm;
  10220. if (!$t.grid || $t.p.cellEdit !== true ) {return;}
  10221. $($t.rows).each(function(j){
  10222. var res = {};
  10223. if ($(this).hasClass("edited")) {
  10224. $('td',this).each( function(i) {
  10225. nm = $t.p.colModel[i].name;
  10226. if ( nm !== 'cb' && nm !== 'subgrid') {
  10227. if (mthd==='dirty') {
  10228. if ($(this).hasClass('dirty-cell')) {
  10229. try {
  10230. res[nm] = $.unformat.call($t,this,{rowId:$t.rows[j].id, colModel:$t.p.colModel[i]},i);
  10231. } catch (e){
  10232. res[nm] = $.jgrid.htmlDecode($(this).html());
  10233. }
  10234. }
  10235. } else {
  10236. try {
  10237. res[nm] = $.unformat.call($t,this,{rowId:$t.rows[j].id,colModel:$t.p.colModel[i]},i);
  10238. } catch (e) {
  10239. res[nm] = $.jgrid.htmlDecode($(this).html());
  10240. }
  10241. }
  10242. }
  10243. });
  10244. res.id = this.id;
  10245. ret.push(res);
  10246. }
  10247. });
  10248. });
  10249. return ret;
  10250. }
  10251. /// end cell editing
  10252. });
  10253. })(jQuery);
  10254. /*jshint eqeqeq:false */
  10255. /*global jQuery */
  10256. (function($){
  10257. /**
  10258. * jqGrid extension for SubGrid Data
  10259. * Tony Tomov tony@trirand.com
  10260. * http://trirand.com/blog/
  10261. * Dual licensed under the MIT and GPL licenses:
  10262. * http://www.opensource.org/licenses/mit-license.php
  10263. * http://www.gnu.org/licenses/gpl-2.0.html
  10264. **/
  10265. "use strict";
  10266. $.jgrid.extend({
  10267. setSubGrid : function () {
  10268. return this.each(function (){
  10269. var $t = this, cm, i,
  10270. suboptions = {
  10271. plusicon : "ui-icon-plus",
  10272. minusicon : "ui-icon-minus",
  10273. openicon: "ui-icon-carat-1-sw",
  10274. expandOnLoad: false,
  10275. delayOnLoad : 50,
  10276. selectOnExpand : false,
  10277. selectOnCollapse : false,
  10278. reloadOnExpand : true
  10279. };
  10280. $t.p.subGridOptions = $.extend(suboptions, $t.p.subGridOptions || {});
  10281. $t.p.colNames.unshift("");
  10282. $t.p.colModel.unshift({name:'subgrid',width: $.jgrid.cell_width ? $t.p.subGridWidth+$t.p.cellLayout : $t.p.subGridWidth,sortable: false,resizable:false,hidedlg:true,search:false,fixed:true});
  10283. cm = $t.p.subGridModel;
  10284. if(cm[0]) {
  10285. cm[0].align = $.extend([],cm[0].align || []);
  10286. for(i=0;i<cm[0].name.length;i++) { cm[0].align[i] = cm[0].align[i] || 'left';}
  10287. }
  10288. });
  10289. },
  10290. addSubGridCell :function (pos,iRow) {
  10291. var prp='',ic,sid;
  10292. this.each(function(){
  10293. prp = this.formatCol(pos,iRow);
  10294. sid= this.p.id;
  10295. ic = this.p.subGridOptions.plusicon;
  10296. });
  10297. return "<td role=\"gridcell\" aria-describedby=\""+sid+"_subgrid\" class=\"ui-sgcollapsed sgcollapsed\" "+prp+"><a style='cursor:pointer;'><span class='ui-icon "+ic+"'></span></a></td>";
  10298. },
  10299. addSubGrid : function( pos, sind ) {
  10300. return this.each(function(){
  10301. var ts = this;
  10302. if (!ts.grid ) { return; }
  10303. //-------------------------
  10304. var subGridCell = function(trdiv,cell,pos)
  10305. {
  10306. var tddiv = $("<td align='"+ts.p.subGridModel[0].align[pos]+"'></td>").html(cell);
  10307. $(trdiv).append(tddiv);
  10308. };
  10309. var subGridXml = function(sjxml, sbid){
  10310. var tddiv, i, sgmap,
  10311. dummy = $("<table cellspacing='0' cellpadding='0' border='0'><tbody></tbody></table>"),
  10312. trdiv = $("<tr></tr>");
  10313. for (i = 0; i<ts.p.subGridModel[0].name.length; i++) {
  10314. tddiv = $("<th class='ui-state-default ui-th-subgrid ui-th-column ui-th-"+ts.p.direction+"'></th>");
  10315. $(tddiv).html(ts.p.subGridModel[0].name[i]);
  10316. $(tddiv).width( ts.p.subGridModel[0].width[i]);
  10317. $(trdiv).append(tddiv);
  10318. }
  10319. $(dummy).append(trdiv);
  10320. if (sjxml){
  10321. sgmap = ts.p.xmlReader.subgrid;
  10322. $(sgmap.root+" "+sgmap.row, sjxml).each( function(){
  10323. trdiv = $("<tr class='ui-widget-content ui-subtblcell'></tr>");
  10324. if(sgmap.repeatitems === true) {
  10325. $(sgmap.cell,this).each( function(i) {
  10326. subGridCell(trdiv, $(this).text() || '&#160;',i);
  10327. });
  10328. } else {
  10329. var f = ts.p.subGridModel[0].mapping || ts.p.subGridModel[0].name;
  10330. if (f) {
  10331. for (i=0;i<f.length;i++) {
  10332. subGridCell(trdiv, $(f[i],this).text() || '&#160;',i);
  10333. }
  10334. }
  10335. }
  10336. $(dummy).append(trdiv);
  10337. });
  10338. }
  10339. var pID = $("table:first",ts.grid.bDiv).attr("id")+"_";
  10340. $("#"+$.jgrid.jqID(pID+sbid)).append(dummy);
  10341. ts.grid.hDiv.loading = false;
  10342. $("#load_"+$.jgrid.jqID(ts.p.id)).hide();
  10343. return false;
  10344. };
  10345. var subGridJson = function(sjxml, sbid){
  10346. var tddiv,result,i,cur, sgmap,j,
  10347. dummy = $("<table cellspacing='0' cellpadding='0' border='0'><tbody></tbody></table>"),
  10348. trdiv = $("<tr></tr>");
  10349. for (i = 0; i<ts.p.subGridModel[0].name.length; i++) {
  10350. tddiv = $("<th class='ui-state-default ui-th-subgrid ui-th-column ui-th-"+ts.p.direction+"'></th>");
  10351. $(tddiv).html(ts.p.subGridModel[0].name[i]);
  10352. $(tddiv).width( ts.p.subGridModel[0].width[i]);
  10353. $(trdiv).append(tddiv);
  10354. }
  10355. $(dummy).append(trdiv);
  10356. if (sjxml){
  10357. sgmap = ts.p.jsonReader.subgrid;
  10358. result = $.jgrid.getAccessor(sjxml, sgmap.root);
  10359. if ( result !== undefined ) {
  10360. for (i=0;i<result.length;i++) {
  10361. cur = result[i];
  10362. trdiv = $("<tr class='ui-widget-content ui-subtblcell'></tr>");
  10363. if(sgmap.repeatitems === true) {
  10364. if(sgmap.cell) { cur=cur[sgmap.cell]; }
  10365. for (j=0;j<cur.length;j++) {
  10366. subGridCell(trdiv, cur[j] || '&#160;',j);
  10367. }
  10368. } else {
  10369. var f = ts.p.subGridModel[0].mapping || ts.p.subGridModel[0].name;
  10370. if(f.length) {
  10371. for (j=0;j<f.length;j++) {
  10372. subGridCell(trdiv, cur[f[j]] || '&#160;',j);
  10373. }
  10374. }
  10375. }
  10376. $(dummy).append(trdiv);
  10377. }
  10378. }
  10379. }
  10380. var pID = $("table:first",ts.grid.bDiv).attr("id")+"_";
  10381. $("#"+$.jgrid.jqID(pID+sbid)).append(dummy);
  10382. ts.grid.hDiv.loading = false;
  10383. $("#load_"+$.jgrid.jqID(ts.p.id)).hide();
  10384. return false;
  10385. };
  10386. var populatesubgrid = function( rd )
  10387. {
  10388. var sid,dp, i, j;
  10389. sid = $(rd).attr("id");
  10390. dp = {nd_: (new Date().getTime())};
  10391. dp[ts.p.prmNames.subgridid]=sid;
  10392. if(!ts.p.subGridModel[0]) { return false; }
  10393. if(ts.p.subGridModel[0].params) {
  10394. for(j=0; j < ts.p.subGridModel[0].params.length; j++) {
  10395. for(i=0; i<ts.p.colModel.length; i++) {
  10396. if(ts.p.colModel[i].name === ts.p.subGridModel[0].params[j]) {
  10397. dp[ts.p.colModel[i].name]= $("td:eq("+i+")",rd).text().replace(/\&#160\;/ig,'');
  10398. }
  10399. }
  10400. }
  10401. }
  10402. if(!ts.grid.hDiv.loading) {
  10403. ts.grid.hDiv.loading = true;
  10404. $("#load_"+$.jgrid.jqID(ts.p.id)).show();
  10405. if(!ts.p.subgridtype) { ts.p.subgridtype = ts.p.datatype; }
  10406. if($.isFunction(ts.p.subgridtype)) {
  10407. ts.p.subgridtype.call(ts, dp);
  10408. } else {
  10409. ts.p.subgridtype = ts.p.subgridtype.toLowerCase();
  10410. }
  10411. switch(ts.p.subgridtype) {
  10412. case "xml":
  10413. case "json":
  10414. $.ajax($.extend({
  10415. type:ts.p.mtype,
  10416. url: ts.p.subGridUrl,
  10417. dataType:ts.p.subgridtype,
  10418. data: $.isFunction(ts.p.serializeSubGridData)? ts.p.serializeSubGridData.call(ts, dp) : dp,
  10419. complete: function(sxml) {
  10420. if(ts.p.subgridtype === "xml") {
  10421. subGridXml(sxml.responseXML, sid);
  10422. } else {
  10423. subGridJson($.jgrid.parse(sxml.responseText),sid);
  10424. }
  10425. sxml=null;
  10426. }
  10427. }, $.jgrid.ajaxOptions, ts.p.ajaxSubgridOptions || {}));
  10428. break;
  10429. }
  10430. }
  10431. return false;
  10432. };
  10433. var _id, pID,atd, nhc=0, bfsc, r;
  10434. $.each(ts.p.colModel,function(){
  10435. if(this.hidden === true || this.name === 'rn' || this.name === 'cb') {
  10436. nhc++;
  10437. }
  10438. });
  10439. var len = ts.rows.length, i=1;
  10440. if( sind !== undefined && sind > 0) {
  10441. i = sind;
  10442. len = sind+1;
  10443. }
  10444. while(i < len) {
  10445. if($(ts.rows[i]).hasClass('jqgrow')) {
  10446. $(ts.rows[i].cells[pos]).bind('click', function() {
  10447. var tr = $(this).parent("tr")[0];
  10448. r = tr.nextSibling;
  10449. if($(this).hasClass("sgcollapsed")) {
  10450. pID = ts.p.id;
  10451. _id = tr.id;
  10452. if(ts.p.subGridOptions.reloadOnExpand === true || ( ts.p.subGridOptions.reloadOnExpand === false && !$(r).hasClass('ui-subgrid') ) ) {
  10453. atd = pos >=1 ? "<td colspan='"+pos+"'>&#160;</td>":"";
  10454. bfsc = $(ts).triggerHandler("jqGridSubGridBeforeExpand", [pID + "_" + _id, _id]);
  10455. bfsc = (bfsc === false || bfsc === 'stop') ? false : true;
  10456. if(bfsc && $.isFunction(ts.p.subGridBeforeExpand)) {
  10457. bfsc = ts.p.subGridBeforeExpand.call(ts, pID+"_"+_id,_id);
  10458. }
  10459. if(bfsc === false) {return false;}
  10460. $(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>" );
  10461. $(ts).triggerHandler("jqGridSubGridRowExpanded", [pID + "_" + _id, _id]);
  10462. if( $.isFunction(ts.p.subGridRowExpanded)) {
  10463. ts.p.subGridRowExpanded.call(ts, pID+"_"+ _id,_id);
  10464. } else {
  10465. populatesubgrid(tr);
  10466. }
  10467. } else {
  10468. $(r).show();
  10469. }
  10470. $(this).html("<a style='cursor:pointer;'><span class='ui-icon "+ts.p.subGridOptions.minusicon+"'></span></a>").removeClass("sgcollapsed").addClass("sgexpanded");
  10471. if(ts.p.subGridOptions.selectOnExpand) {
  10472. $(ts).jqGrid('setSelection',_id);
  10473. }
  10474. } else if($(this).hasClass("sgexpanded")) {
  10475. bfsc = $(ts).triggerHandler("jqGridSubGridRowColapsed", [pID + "_" + _id, _id]);
  10476. bfsc = (bfsc === false || bfsc === 'stop') ? false : true;
  10477. _id = tr.id;
  10478. if( bfsc && $.isFunction(ts.p.subGridRowColapsed)) {
  10479. bfsc = ts.p.subGridRowColapsed.call(ts, pID+"_"+_id,_id );
  10480. }
  10481. if(bfsc===false) {return false;}
  10482. if(ts.p.subGridOptions.reloadOnExpand === true) {
  10483. $(r).remove(".ui-subgrid");
  10484. } else if($(r).hasClass('ui-subgrid')) { // incase of dynamic deleting
  10485. $(r).hide();
  10486. }
  10487. $(this).html("<a style='cursor:pointer;'><span class='ui-icon "+ts.p.subGridOptions.plusicon+"'></span></a>").removeClass("sgexpanded").addClass("sgcollapsed");
  10488. if(ts.p.subGridOptions.selectOnCollapse) {
  10489. $(ts).jqGrid('setSelection',_id);
  10490. }
  10491. }
  10492. return false;
  10493. });
  10494. }
  10495. i++;
  10496. }
  10497. if(ts.p.subGridOptions.expandOnLoad === true) {
  10498. $(ts.rows).filter('.jqgrow').each(function(index,row){
  10499. $(row.cells[0]).click();
  10500. });
  10501. }
  10502. ts.subGridXml = function(xml,sid) {subGridXml(xml,sid);};
  10503. ts.subGridJson = function(json,sid) {subGridJson(json,sid);};
  10504. });
  10505. },
  10506. expandSubGridRow : function(rowid) {
  10507. return this.each(function () {
  10508. var $t = this;
  10509. if(!$t.grid && !rowid) {return;}
  10510. if($t.p.subGrid===true) {
  10511. var rc = $(this).jqGrid("getInd",rowid,true);
  10512. if(rc) {
  10513. var sgc = $("td.sgcollapsed",rc)[0];
  10514. if(sgc) {
  10515. $(sgc).trigger("click");
  10516. }
  10517. }
  10518. }
  10519. });
  10520. },
  10521. collapseSubGridRow : function(rowid) {
  10522. return this.each(function () {
  10523. var $t = this;
  10524. if(!$t.grid && !rowid) {return;}
  10525. if($t.p.subGrid===true) {
  10526. var rc = $(this).jqGrid("getInd",rowid,true);
  10527. if(rc) {
  10528. var sgc = $("td.sgexpanded",rc)[0];
  10529. if(sgc) {
  10530. $(sgc).trigger("click");
  10531. }
  10532. }
  10533. }
  10534. });
  10535. },
  10536. toggleSubGridRow : function(rowid) {
  10537. return this.each(function () {
  10538. var $t = this;
  10539. if(!$t.grid && !rowid) {return;}
  10540. if($t.p.subGrid===true) {
  10541. var rc = $(this).jqGrid("getInd",rowid,true);
  10542. if(rc) {
  10543. var sgc = $("td.sgcollapsed",rc)[0];
  10544. if(sgc) {
  10545. $(sgc).trigger("click");
  10546. } else {
  10547. sgc = $("td.sgexpanded",rc)[0];
  10548. if(sgc) {
  10549. $(sgc).trigger("click");
  10550. }
  10551. }
  10552. }
  10553. }
  10554. });
  10555. }
  10556. });
  10557. })(jQuery);
  10558. /**
  10559. * jqGrid extension - Tree Grid
  10560. * Tony Tomov tony@trirand.com
  10561. * http://trirand.com/blog/
  10562. * Dual licensed under the MIT and GPL licenses:
  10563. * http://www.opensource.org/licenses/mit-license.php
  10564. * http://www.gnu.org/licenses/gpl.html
  10565. **/
  10566. /*jshint eqeqeq:false */
  10567. /*global jQuery */
  10568. (function($) {
  10569. "use strict";
  10570. $.jgrid.extend({
  10571. setTreeNode : function(i, len){
  10572. return this.each(function(){
  10573. var $t = this;
  10574. if( !$t.grid || !$t.p.treeGrid ) {return;}
  10575. var expCol = $t.p.expColInd,
  10576. expanded = $t.p.treeReader.expanded_field,
  10577. isLeaf = $t.p.treeReader.leaf_field,
  10578. level = $t.p.treeReader.level_field,
  10579. icon = $t.p.treeReader.icon_field,
  10580. loaded = $t.p.treeReader.loaded, lft, rgt, curLevel, ident,lftpos, twrap,
  10581. ldat, lf;
  10582. while(i<len) {
  10583. var ind = $.jgrid.stripPref($t.p.idPrefix, $t.rows[i].id), dind = $t.p._index[ind], expan;
  10584. ldat = $t.p.data[dind];
  10585. //$t.rows[i].level = ldat[level];
  10586. if($t.p.treeGridModel === 'nested') {
  10587. if(!ldat[isLeaf]) {
  10588. lft = parseInt(ldat[$t.p.treeReader.left_field],10);
  10589. rgt = parseInt(ldat[$t.p.treeReader.right_field],10);
  10590. // NS Model
  10591. ldat[isLeaf] = (rgt === lft+1) ? 'true' : 'false';
  10592. $t.rows[i].cells[$t.p._treeleafpos].innerHTML = ldat[isLeaf];
  10593. }
  10594. }
  10595. //else {
  10596. //row.parent_id = rd[$t.p.treeReader.parent_id_field];
  10597. //}
  10598. curLevel = parseInt(ldat[level],10);
  10599. if($t.p.tree_root_level === 0) {
  10600. ident = curLevel+1;
  10601. lftpos = curLevel;
  10602. } else {
  10603. ident = curLevel;
  10604. lftpos = curLevel -1;
  10605. }
  10606. twrap = "<div class='tree-wrap tree-wrap-"+$t.p.direction+"' style='width:"+(ident*18)+"px;'>";
  10607. twrap += "<div style='"+($t.p.direction==="rtl" ? "right:" : "left:")+(lftpos*18)+"px;' class='ui-icon ";
  10608. if(ldat[loaded] !== undefined) {
  10609. if(ldat[loaded]==="true" || ldat[loaded]===true) {
  10610. ldat[loaded] = true;
  10611. } else {
  10612. ldat[loaded] = false;
  10613. }
  10614. }
  10615. if(ldat[isLeaf] === "true" || ldat[isLeaf] === true) {
  10616. twrap += ((ldat[icon] !== undefined && ldat[icon] !== "") ? ldat[icon] : $t.p.treeIcons.leaf)+" tree-leaf treeclick";
  10617. ldat[isLeaf] = true;
  10618. lf="leaf";
  10619. } else {
  10620. ldat[isLeaf] = false;
  10621. lf="";
  10622. }
  10623. ldat[expanded] = ((ldat[expanded] === "true" || ldat[expanded] === true) ? true : false) && (ldat[loaded] || ldat[loaded] === undefined);
  10624. if(ldat[expanded] === false) {
  10625. twrap += ((ldat[isLeaf] === true) ? "'" : $t.p.treeIcons.plus+" tree-plus treeclick'");
  10626. } else {
  10627. twrap += ((ldat[isLeaf] === true) ? "'" : $t.p.treeIcons.minus+" tree-minus treeclick'");
  10628. }
  10629. twrap += "></div></div>";
  10630. $($t.rows[i].cells[expCol]).wrapInner("<span class='cell-wrapper"+lf+"'></span>").prepend(twrap);
  10631. if(curLevel !== parseInt($t.p.tree_root_level,10)) {
  10632. var pn = $($t).jqGrid('getNodeParent',ldat);
  10633. expan = pn && pn.hasOwnProperty(expanded) ? pn[expanded] : true;
  10634. if( !expan ){
  10635. $($t.rows[i]).css("display","none");
  10636. }
  10637. }
  10638. $($t.rows[i].cells[expCol])
  10639. .find("div.treeclick")
  10640. .bind("click",function(e){
  10641. var target = e.target || e.srcElement,
  10642. ind2 =$.jgrid.stripPref($t.p.idPrefix,$(target,$t.rows).closest("tr.jqgrow")[0].id),
  10643. pos = $t.p._index[ind2];
  10644. if(!$t.p.data[pos][isLeaf]){
  10645. if($t.p.data[pos][expanded]){
  10646. $($t).jqGrid("collapseRow",$t.p.data[pos]);
  10647. $($t).jqGrid("collapseNode",$t.p.data[pos]);
  10648. } else {
  10649. $($t).jqGrid("expandRow",$t.p.data[pos]);
  10650. $($t).jqGrid("expandNode",$t.p.data[pos]);
  10651. }
  10652. }
  10653. return false;
  10654. });
  10655. if($t.p.ExpandColClick === true) {
  10656. $($t.rows[i].cells[expCol])
  10657. .find("span.cell-wrapper")
  10658. .css("cursor","pointer")
  10659. .bind("click",function(e) {
  10660. var target = e.target || e.srcElement,
  10661. ind2 =$.jgrid.stripPref($t.p.idPrefix,$(target,$t.rows).closest("tr.jqgrow")[0].id),
  10662. pos = $t.p._index[ind2];
  10663. if(!$t.p.data[pos][isLeaf]){
  10664. if($t.p.data[pos][expanded]){
  10665. $($t).jqGrid("collapseRow",$t.p.data[pos]);
  10666. $($t).jqGrid("collapseNode",$t.p.data[pos]);
  10667. } else {
  10668. $($t).jqGrid("expandRow",$t.p.data[pos]);
  10669. $($t).jqGrid("expandNode",$t.p.data[pos]);
  10670. }
  10671. }
  10672. $($t).jqGrid("setSelection",ind2);
  10673. return false;
  10674. });
  10675. }
  10676. i++;
  10677. }
  10678. });
  10679. },
  10680. setTreeGrid : function() {
  10681. return this.each(function (){
  10682. var $t = this, i=0, pico, ecol = false, nm, key, tkey, dupcols=[];
  10683. if(!$t.p.treeGrid) {return;}
  10684. if(!$t.p.treedatatype ) {$.extend($t.p,{treedatatype: $t.p.datatype});}
  10685. $t.p.subGrid = false;$t.p.altRows =false;
  10686. $t.p.pgbuttons = false;$t.p.pginput = false;
  10687. $t.p.gridview = true;
  10688. if($t.p.rowTotal === null ) { $t.p.rowNum = 10000; }
  10689. $t.p.multiselect = false;$t.p.rowList = [];
  10690. $t.p.expColInd = 0;
  10691. pico = 'ui-icon-triangle-1-' + ($t.p.direction==="rtl" ? 'w' : 'e');
  10692. $t.p.treeIcons = $.extend({plus:pico,minus:'ui-icon-triangle-1-s',leaf:'ui-icon-radio-off'},$t.p.treeIcons || {});
  10693. if($t.p.treeGridModel === 'nested') {
  10694. $t.p.treeReader = $.extend({
  10695. level_field: "level",
  10696. left_field:"lft",
  10697. right_field: "rgt",
  10698. leaf_field: "isLeaf",
  10699. expanded_field: "expanded",
  10700. loaded: "loaded",
  10701. icon_field: "icon"
  10702. },$t.p.treeReader);
  10703. } else if($t.p.treeGridModel === 'adjacency') {
  10704. $t.p.treeReader = $.extend({
  10705. level_field: "level",
  10706. parent_id_field: "parent",
  10707. leaf_field: "isLeaf",
  10708. expanded_field: "expanded",
  10709. loaded: "loaded",
  10710. icon_field: "icon"
  10711. },$t.p.treeReader );
  10712. }
  10713. for ( key in $t.p.colModel){
  10714. if($t.p.colModel.hasOwnProperty(key)) {
  10715. nm = $t.p.colModel[key].name;
  10716. if( nm === $t.p.ExpandColumn && !ecol ) {
  10717. ecol = true;
  10718. $t.p.expColInd = i;
  10719. }
  10720. i++;
  10721. //
  10722. for(tkey in $t.p.treeReader) {
  10723. if($t.p.treeReader.hasOwnProperty(tkey) && $t.p.treeReader[tkey] === nm) {
  10724. dupcols.push(nm);
  10725. }
  10726. }
  10727. }
  10728. }
  10729. $.each($t.p.treeReader,function(j,n){
  10730. if(n && $.inArray(n, dupcols) === -1){
  10731. if(j==='leaf_field') { $t.p._treeleafpos= i; }
  10732. i++;
  10733. $t.p.colNames.push(n);
  10734. $t.p.colModel.push({name:n,width:1,hidden:true,sortable:false,resizable:false,hidedlg:true,editable:true,search:false});
  10735. }
  10736. });
  10737. });
  10738. },
  10739. expandRow: function (record){
  10740. this.each(function(){
  10741. var $t = this;
  10742. if(!$t.grid || !$t.p.treeGrid) {return;}
  10743. var childern = $($t).jqGrid("getNodeChildren",record),
  10744. //if ($($t).jqGrid("isVisibleNode",record)) {
  10745. expanded = $t.p.treeReader.expanded_field;
  10746. $(childern).each(function(){
  10747. var id = $t.p.idPrefix + $.jgrid.getAccessor(this,$t.p.localReader.id);
  10748. $($($t).jqGrid('getGridRowById', id)).css("display","");
  10749. if(this[expanded]) {
  10750. $($t).jqGrid("expandRow",this);
  10751. }
  10752. });
  10753. //}
  10754. });
  10755. },
  10756. collapseRow : function (record) {
  10757. this.each(function(){
  10758. var $t = this;
  10759. if(!$t.grid || !$t.p.treeGrid) {return;}
  10760. var childern = $($t).jqGrid("getNodeChildren",record),
  10761. expanded = $t.p.treeReader.expanded_field;
  10762. $(childern).each(function(){
  10763. var id = $t.p.idPrefix + $.jgrid.getAccessor(this,$t.p.localReader.id);
  10764. $($($t).jqGrid('getGridRowById', id)).css("display","none");
  10765. if(this[expanded]){
  10766. $($t).jqGrid("collapseRow",this);
  10767. }
  10768. });
  10769. });
  10770. },
  10771. // NS ,adjacency models
  10772. getRootNodes : function() {
  10773. var result = [];
  10774. this.each(function(){
  10775. var $t = this;
  10776. if(!$t.grid || !$t.p.treeGrid) {return;}
  10777. switch ($t.p.treeGridModel) {
  10778. case 'nested' :
  10779. var level = $t.p.treeReader.level_field;
  10780. $($t.p.data).each(function(){
  10781. if(parseInt(this[level],10) === parseInt($t.p.tree_root_level,10)) {
  10782. result.push(this);
  10783. }
  10784. });
  10785. break;
  10786. case 'adjacency' :
  10787. var parent_id = $t.p.treeReader.parent_id_field;
  10788. $($t.p.data).each(function(){
  10789. if(this[parent_id] === null || String(this[parent_id]).toLowerCase() === "null") {
  10790. result.push(this);
  10791. }
  10792. });
  10793. break;
  10794. }
  10795. });
  10796. return result;
  10797. },
  10798. getNodeDepth : function(rc) {
  10799. var ret = null;
  10800. this.each(function(){
  10801. if(!this.grid || !this.p.treeGrid) {return;}
  10802. var $t = this;
  10803. switch ($t.p.treeGridModel) {
  10804. case 'nested' :
  10805. var level = $t.p.treeReader.level_field;
  10806. ret = parseInt(rc[level],10) - parseInt($t.p.tree_root_level,10);
  10807. break;
  10808. case 'adjacency' :
  10809. ret = $($t).jqGrid("getNodeAncestors",rc).length;
  10810. break;
  10811. }
  10812. });
  10813. return ret;
  10814. },
  10815. getNodeParent : function(rc) {
  10816. var result = null;
  10817. this.each(function(){
  10818. var $t = this;
  10819. if(!$t.grid || !$t.p.treeGrid) {return;}
  10820. switch ($t.p.treeGridModel) {
  10821. case 'nested' :
  10822. var lftc = $t.p.treeReader.left_field,
  10823. rgtc = $t.p.treeReader.right_field,
  10824. levelc = $t.p.treeReader.level_field,
  10825. lft = parseInt(rc[lftc],10), rgt = parseInt(rc[rgtc],10), level = parseInt(rc[levelc],10);
  10826. $(this.p.data).each(function(){
  10827. if(parseInt(this[levelc],10) === level-1 && parseInt(this[lftc],10) < lft && parseInt(this[rgtc],10) > rgt) {
  10828. result = this;
  10829. return false;
  10830. }
  10831. });
  10832. break;
  10833. case 'adjacency' :
  10834. var parent_id = $t.p.treeReader.parent_id_field,
  10835. dtid = $t.p.localReader.id;
  10836. $(this.p.data).each(function(){
  10837. if(this[dtid] === $.jgrid.stripPref($t.p.idPrefix, rc[parent_id]) ) {
  10838. result = this;
  10839. return false;
  10840. }
  10841. });
  10842. break;
  10843. }
  10844. });
  10845. return result;
  10846. },
  10847. getNodeChildren : function(rc) {
  10848. var result = [];
  10849. this.each(function(){
  10850. var $t = this;
  10851. if(!$t.grid || !$t.p.treeGrid) {return;}
  10852. switch ($t.p.treeGridModel) {
  10853. case 'nested' :
  10854. var lftc = $t.p.treeReader.left_field,
  10855. rgtc = $t.p.treeReader.right_field,
  10856. levelc = $t.p.treeReader.level_field,
  10857. lft = parseInt(rc[lftc],10), rgt = parseInt(rc[rgtc],10), level = parseInt(rc[levelc],10);
  10858. $(this.p.data).each(function(){
  10859. if(parseInt(this[levelc],10) === level+1 && parseInt(this[lftc],10) > lft && parseInt(this[rgtc],10) < rgt) {
  10860. result.push(this);
  10861. }
  10862. });
  10863. break;
  10864. case 'adjacency' :
  10865. var parent_id = $t.p.treeReader.parent_id_field,
  10866. dtid = $t.p.localReader.id;
  10867. $(this.p.data).each(function(){
  10868. if(this[parent_id] == $.jgrid.stripPref($t.p.idPrefix, rc[dtid])) {
  10869. result.push(this);
  10870. }
  10871. });
  10872. break;
  10873. }
  10874. });
  10875. return result;
  10876. },
  10877. getFullTreeNode : function(rc) {
  10878. var result = [];
  10879. this.each(function(){
  10880. var $t = this, len;
  10881. if(!$t.grid || !$t.p.treeGrid) {return;}
  10882. switch ($t.p.treeGridModel) {
  10883. case 'nested' :
  10884. var lftc = $t.p.treeReader.left_field,
  10885. rgtc = $t.p.treeReader.right_field,
  10886. levelc = $t.p.treeReader.level_field,
  10887. lft = parseInt(rc[lftc],10), rgt = parseInt(rc[rgtc],10), level = parseInt(rc[levelc],10);
  10888. $(this.p.data).each(function(){
  10889. if(parseInt(this[levelc],10) >= level && parseInt(this[lftc],10) >= lft && parseInt(this[lftc],10) <= rgt) {
  10890. result.push(this);
  10891. }
  10892. });
  10893. break;
  10894. case 'adjacency' :
  10895. if(rc) {
  10896. result.push(rc);
  10897. var parent_id = $t.p.treeReader.parent_id_field,
  10898. dtid = $t.p.localReader.id;
  10899. $(this.p.data).each(function(i){
  10900. len = result.length;
  10901. for (i = 0; i < len; i++) {
  10902. if ($.jgrid.stripPref($t.p.idPrefix, result[i][dtid]) === this[parent_id]) {
  10903. result.push(this);
  10904. break;
  10905. }
  10906. }
  10907. });
  10908. }
  10909. break;
  10910. }
  10911. });
  10912. return result;
  10913. },
  10914. // End NS, adjacency Model
  10915. getNodeAncestors : function(rc) {
  10916. var ancestors = [];
  10917. this.each(function(){
  10918. if(!this.grid || !this.p.treeGrid) {return;}
  10919. var parent = $(this).jqGrid("getNodeParent",rc);
  10920. while (parent) {
  10921. ancestors.push(parent);
  10922. parent = $(this).jqGrid("getNodeParent",parent);
  10923. }
  10924. });
  10925. return ancestors;
  10926. },
  10927. isVisibleNode : function(rc) {
  10928. var result = true;
  10929. this.each(function(){
  10930. var $t = this;
  10931. if(!$t.grid || !$t.p.treeGrid) {return;}
  10932. var ancestors = $($t).jqGrid("getNodeAncestors",rc),
  10933. expanded = $t.p.treeReader.expanded_field;
  10934. $(ancestors).each(function(){
  10935. result = result && this[expanded];
  10936. if(!result) {return false;}
  10937. });
  10938. });
  10939. return result;
  10940. },
  10941. isNodeLoaded : function(rc) {
  10942. var result;
  10943. this.each(function(){
  10944. var $t = this;
  10945. if(!$t.grid || !$t.p.treeGrid) {return;}
  10946. var isLeaf = $t.p.treeReader.leaf_field,
  10947. loaded = $t.p.treeReader.loaded;
  10948. if(rc !== undefined ) {
  10949. if(rc[loaded] !== undefined) {
  10950. result = rc[loaded];
  10951. } else if( rc[isLeaf] || $($t).jqGrid("getNodeChildren",rc).length > 0){
  10952. result = true;
  10953. } else {
  10954. result = false;
  10955. }
  10956. } else {
  10957. result = false;
  10958. }
  10959. });
  10960. return result;
  10961. },
  10962. expandNode : function(rc) {
  10963. return this.each(function(){
  10964. if(!this.grid || !this.p.treeGrid) {return;}
  10965. var expanded = this.p.treeReader.expanded_field,
  10966. parent = this.p.treeReader.parent_id_field,
  10967. loaded = this.p.treeReader.loaded,
  10968. level = this.p.treeReader.level_field,
  10969. lft = this.p.treeReader.left_field,
  10970. rgt = this.p.treeReader.right_field;
  10971. if(!rc[expanded]) {
  10972. var id = $.jgrid.getAccessor(rc,this.p.localReader.id);
  10973. var rc1 = $("#" + this.p.idPrefix + $.jgrid.jqID(id),this.grid.bDiv)[0];
  10974. var position = this.p._index[id];
  10975. if( $(this).jqGrid("isNodeLoaded",this.p.data[position]) ) {
  10976. rc[expanded] = true;
  10977. $("div.treeclick",rc1).removeClass(this.p.treeIcons.plus+" tree-plus").addClass(this.p.treeIcons.minus+" tree-minus");
  10978. } else if (!this.grid.hDiv.loading) {
  10979. rc[expanded] = true;
  10980. $("div.treeclick",rc1).removeClass(this.p.treeIcons.plus+" tree-plus").addClass(this.p.treeIcons.minus+" tree-minus");
  10981. this.p.treeANode = rc1.rowIndex;
  10982. this.p.datatype = this.p.treedatatype;
  10983. if(this.p.treeGridModel === 'nested') {
  10984. $(this).jqGrid("setGridParam",{postData:{nodeid:id,n_left:rc[lft],n_right:rc[rgt],n_level:rc[level]}});
  10985. } else {
  10986. $(this).jqGrid("setGridParam",{postData:{nodeid:id,parentid:rc[parent],n_level:rc[level]}} );
  10987. }
  10988. $(this).trigger("reloadGrid");
  10989. rc[loaded] = true;
  10990. if(this.p.treeGridModel === 'nested') {
  10991. $(this).jqGrid("setGridParam",{postData:{nodeid:'',n_left:'',n_right:'',n_level:''}});
  10992. } else {
  10993. $(this).jqGrid("setGridParam",{postData:{nodeid:'',parentid:'',n_level:''}});
  10994. }
  10995. }
  10996. }
  10997. });
  10998. },
  10999. collapseNode : function(rc) {
  11000. return this.each(function(){
  11001. if(!this.grid || !this.p.treeGrid) {return;}
  11002. var expanded = this.p.treeReader.expanded_field;
  11003. if(rc[expanded]) {
  11004. rc[expanded] = false;
  11005. var id = $.jgrid.getAccessor(rc,this.p.localReader.id);
  11006. var rc1 = $("#" + this.p.idPrefix + $.jgrid.jqID(id),this.grid.bDiv)[0];
  11007. $("div.treeclick",rc1).removeClass(this.p.treeIcons.minus+" tree-minus").addClass(this.p.treeIcons.plus+" tree-plus");
  11008. }
  11009. });
  11010. },
  11011. SortTree : function( sortname, newDir, st, datefmt) {
  11012. return this.each(function(){
  11013. if(!this.grid || !this.p.treeGrid) {return;}
  11014. var i, len,
  11015. rec, records = [], $t = this, query, roots,
  11016. rt = $(this).jqGrid("getRootNodes");
  11017. // Sorting roots
  11018. query = $.jgrid.from(rt);
  11019. query.orderBy(sortname,newDir,st, datefmt);
  11020. roots = query.select();
  11021. // Sorting children
  11022. for (i = 0, len = roots.length; i < len; i++) {
  11023. rec = roots[i];
  11024. records.push(rec);
  11025. $(this).jqGrid("collectChildrenSortTree",records, rec, sortname, newDir,st, datefmt);
  11026. }
  11027. $.each(records, function(index) {
  11028. var id = $.jgrid.getAccessor(this,$t.p.localReader.id);
  11029. $('#'+$.jgrid.jqID($t.p.id)+ ' tbody tr:eq('+index+')').after($('tr#'+$.jgrid.jqID(id),$t.grid.bDiv));
  11030. });
  11031. query = null;roots=null;records=null;
  11032. });
  11033. },
  11034. collectChildrenSortTree : function(records, rec, sortname, newDir,st, datefmt) {
  11035. return this.each(function(){
  11036. if(!this.grid || !this.p.treeGrid) {return;}
  11037. var i, len,
  11038. child, ch, query, children;
  11039. ch = $(this).jqGrid("getNodeChildren",rec);
  11040. query = $.jgrid.from(ch);
  11041. query.orderBy(sortname, newDir, st, datefmt);
  11042. children = query.select();
  11043. for (i = 0, len = children.length; i < len; i++) {
  11044. child = children[i];
  11045. records.push(child);
  11046. $(this).jqGrid("collectChildrenSortTree",records, child, sortname, newDir, st, datefmt);
  11047. }
  11048. });
  11049. },
  11050. // experimental
  11051. setTreeRow : function(rowid, data) {
  11052. var success=false;
  11053. this.each(function(){
  11054. var t = this;
  11055. if(!t.grid || !t.p.treeGrid) {return;}
  11056. success = $(t).jqGrid("setRowData",rowid,data);
  11057. });
  11058. return success;
  11059. },
  11060. delTreeNode : function (rowid) {
  11061. return this.each(function () {
  11062. var $t = this, rid = $t.p.localReader.id, i,
  11063. left = $t.p.treeReader.left_field,
  11064. right = $t.p.treeReader.right_field, myright, width, res, key;
  11065. if(!$t.grid || !$t.p.treeGrid) {return;}
  11066. var rc = $t.p._index[rowid];
  11067. if (rc !== undefined) {
  11068. // nested
  11069. myright = parseInt($t.p.data[rc][right],10);
  11070. width = myright - parseInt($t.p.data[rc][left],10) + 1;
  11071. var dr = $($t).jqGrid("getFullTreeNode",$t.p.data[rc]);
  11072. if(dr.length>0){
  11073. for (i=0;i<dr.length;i++){
  11074. $($t).jqGrid("delRowData",dr[i][rid]);
  11075. }
  11076. }
  11077. if( $t.p.treeGridModel === "nested") {
  11078. // ToDo - update grid data
  11079. res = $.jgrid.from($t.p.data)
  11080. .greater(left,myright,{stype:'integer'})
  11081. .select();
  11082. if(res.length) {
  11083. for( key in res) {
  11084. if(res.hasOwnProperty(key)) {
  11085. res[key][left] = parseInt(res[key][left],10) - width ;
  11086. }
  11087. }
  11088. }
  11089. res = $.jgrid.from($t.p.data)
  11090. .greater(right,myright,{stype:'integer'})
  11091. .select();
  11092. if(res.length) {
  11093. for( key in res) {
  11094. if(res.hasOwnProperty(key)) {
  11095. res[key][right] = parseInt(res[key][right],10) - width ;
  11096. }
  11097. }
  11098. }
  11099. }
  11100. }
  11101. });
  11102. },
  11103. addChildNode : function( nodeid, parentid, data, expandData ) {
  11104. //return this.each(function(){
  11105. var $t = this[0];
  11106. if(data) {
  11107. // we suppose tha the id is autoincremet and
  11108. var expanded = $t.p.treeReader.expanded_field,
  11109. isLeaf = $t.p.treeReader.leaf_field,
  11110. level = $t.p.treeReader.level_field,
  11111. //icon = $t.p.treeReader.icon_field,
  11112. parent = $t.p.treeReader.parent_id_field,
  11113. left = $t.p.treeReader.left_field,
  11114. right = $t.p.treeReader.right_field,
  11115. loaded = $t.p.treeReader.loaded,
  11116. method, parentindex, parentdata, parentlevel, i, len, max=0, rowind = parentid, leaf, maxright;
  11117. if(expandData===undefined) {expandData = false;}
  11118. if ( nodeid === undefined || nodeid === null ) {
  11119. i = $t.p.data.length-1;
  11120. if( i>= 0 ) {
  11121. while(i>=0){max = Math.max(max, parseInt($t.p.data[i][$t.p.localReader.id],10)); i--;}
  11122. }
  11123. nodeid = max+1;
  11124. }
  11125. var prow = $($t).jqGrid('getInd', parentid);
  11126. leaf = false;
  11127. // if not a parent we assume root
  11128. if ( parentid === undefined || parentid === null || parentid==="") {
  11129. parentid = null;
  11130. rowind = null;
  11131. method = 'last';
  11132. parentlevel = $t.p.tree_root_level;
  11133. i = $t.p.data.length+1;
  11134. } else {
  11135. method = 'after';
  11136. parentindex = $t.p._index[parentid];
  11137. parentdata = $t.p.data[parentindex];
  11138. parentid = parentdata[$t.p.localReader.id];
  11139. parentlevel = parseInt(parentdata[level],10)+1;
  11140. var childs = $($t).jqGrid('getFullTreeNode', parentdata);
  11141. // if there are child nodes get the last index of it
  11142. if(childs.length) {
  11143. i = childs[childs.length-1][$t.p.localReader.id];
  11144. rowind = i;
  11145. i = $($t).jqGrid('getInd',rowind)+1;
  11146. } else {
  11147. i = $($t).jqGrid('getInd', parentid)+1;
  11148. }
  11149. // if the node is leaf
  11150. if(parentdata[isLeaf]) {
  11151. leaf = true;
  11152. parentdata[expanded] = true;
  11153. //var prow = $($t).jqGrid('getInd', parentid);
  11154. $($t.rows[prow])
  11155. .find("span.cell-wrapperleaf").removeClass("cell-wrapperleaf").addClass("cell-wrapper")
  11156. .end()
  11157. .find("div.tree-leaf").removeClass($t.p.treeIcons.leaf+" tree-leaf").addClass($t.p.treeIcons.minus+" tree-minus");
  11158. $t.p.data[parentindex][isLeaf] = false;
  11159. parentdata[loaded] = true;
  11160. }
  11161. }
  11162. len = i+1;
  11163. if( data[expanded]===undefined) {data[expanded]= false;}
  11164. if( data[loaded]===undefined ) { data[loaded] = false;}
  11165. data[level] = parentlevel;
  11166. if( data[isLeaf]===undefined) {data[isLeaf]= true;}
  11167. if( $t.p.treeGridModel === "adjacency") {
  11168. data[parent] = parentid;
  11169. }
  11170. if( $t.p.treeGridModel === "nested") {
  11171. // this method requiere more attention
  11172. var query, res, key;
  11173. //maxright = parseInt(maxright,10);
  11174. // ToDo - update grid data
  11175. if(parentid !== null) {
  11176. maxright = parseInt(parentdata[right],10);
  11177. query = $.jgrid.from($t.p.data);
  11178. query = query.greaterOrEquals(right,maxright,{stype:'integer'});
  11179. res = query.select();
  11180. if(res.length) {
  11181. for( key in res) {
  11182. if(res.hasOwnProperty(key)) {
  11183. res[key][left] = res[key][left] > maxright ? parseInt(res[key][left],10) +2 : res[key][left];
  11184. res[key][right] = res[key][right] >= maxright ? parseInt(res[key][right],10) +2 : res[key][right];
  11185. }
  11186. }
  11187. }
  11188. data[left] = maxright;
  11189. data[right]= maxright+1;
  11190. } else {
  11191. maxright = parseInt( $($t).jqGrid('getCol', right, false, 'max'), 10);
  11192. res = $.jgrid.from($t.p.data)
  11193. .greater(left,maxright,{stype:'integer'})
  11194. .select();
  11195. if(res.length) {
  11196. for( key in res) {
  11197. if(res.hasOwnProperty(key)) {
  11198. res[key][left] = parseInt(res[key][left],10) +2 ;
  11199. }
  11200. }
  11201. }
  11202. res = $.jgrid.from($t.p.data)
  11203. .greater(right,maxright,{stype:'integer'})
  11204. .select();
  11205. if(res.length) {
  11206. for( key in res) {
  11207. if(res.hasOwnProperty(key)) {
  11208. res[key][right] = parseInt(res[key][right],10) +2 ;
  11209. }
  11210. }
  11211. }
  11212. data[left] = maxright+1;
  11213. data[right] = maxright + 2;
  11214. }
  11215. }
  11216. if( parentid === null || $($t).jqGrid("isNodeLoaded",parentdata) || leaf ) {
  11217. $($t).jqGrid('addRowData', nodeid, data, method, rowind);
  11218. $($t).jqGrid('setTreeNode', i, len);
  11219. }
  11220. if(parentdata && !parentdata[expanded] && expandData) {
  11221. $($t.rows[prow])
  11222. .find("div.treeclick")
  11223. .click();
  11224. }
  11225. }
  11226. //});
  11227. }
  11228. });
  11229. })(jQuery);
  11230. /*jshint eqeqeq:false, eqnull:true */
  11231. /*global jQuery */
  11232. // Grouping module
  11233. (function($){
  11234. "use strict";
  11235. $.extend($.jgrid,{
  11236. template : function(format){ //jqgformat
  11237. var args = $.makeArray(arguments).slice(1), j, al = args.length;
  11238. if(format==null) { format = ""; }
  11239. return format.replace(/\{([\w\-]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g, function(m,i){
  11240. if(!isNaN(parseInt(i,10))) {
  11241. return args[parseInt(i,10)];
  11242. }
  11243. for(j=0; j < al;j++) {
  11244. if($.isArray(args[j])) {
  11245. var nmarr = args[ j ],
  11246. k = nmarr.length;
  11247. while(k--) {
  11248. if(i===nmarr[k].nm) {
  11249. return nmarr[k].v;
  11250. }
  11251. }
  11252. }
  11253. }
  11254. });
  11255. }
  11256. });
  11257. $.jgrid.extend({
  11258. groupingSetup : function () {
  11259. return this.each(function (){
  11260. var $t = this, i, j, cml, cm = $t.p.colModel, grp = $t.p.groupingView;
  11261. if(grp !== null && ( (typeof grp === 'object') || $.isFunction(grp) ) ) {
  11262. if(!grp.groupField.length) {
  11263. $t.p.grouping = false;
  11264. } else {
  11265. if (grp.visibiltyOnNextGrouping === undefined) {
  11266. grp.visibiltyOnNextGrouping = [];
  11267. }
  11268. grp.lastvalues=[];
  11269. if(!grp._locgr) {
  11270. grp.groups =[];
  11271. }
  11272. grp.counters =[];
  11273. for(i=0;i<grp.groupField.length;i++) {
  11274. if(!grp.groupOrder[i]) {
  11275. grp.groupOrder[i] = 'asc';
  11276. }
  11277. if(!grp.groupText[i]) {
  11278. grp.groupText[i] = '{0}';
  11279. }
  11280. if( typeof grp.groupColumnShow[i] !== 'boolean') {
  11281. grp.groupColumnShow[i] = true;
  11282. }
  11283. if( typeof grp.groupSummary[i] !== 'boolean') {
  11284. grp.groupSummary[i] = false;
  11285. }
  11286. if( !grp.groupSummaryPos[i]) {
  11287. grp.groupSummaryPos[i] = 'footer';
  11288. }
  11289. if(grp.groupColumnShow[i] === true) {
  11290. grp.visibiltyOnNextGrouping[i] = true;
  11291. $($t).jqGrid('showCol',grp.groupField[i]);
  11292. } else {
  11293. grp.visibiltyOnNextGrouping[i] = $("#"+$.jgrid.jqID($t.p.id+"_"+grp.groupField[i])).is(":visible");
  11294. $($t).jqGrid('hideCol',grp.groupField[i]);
  11295. }
  11296. }
  11297. grp.summary =[];
  11298. if(grp.hideFirstGroupCol) {
  11299. grp.formatDisplayField[0] = function (v) { return v;};
  11300. }
  11301. for(j=0, cml = cm.length; j < cml; j++) {
  11302. if(grp.hideFirstGroupCol) {
  11303. if(!cm[j].hidden && grp.groupField[0] === cm[j].name) {
  11304. cm[j].formatter = function(){return '';};
  11305. }
  11306. }
  11307. if(cm[j].summaryType ) {
  11308. if(cm[j].summaryDivider) {
  11309. grp.summary.push({nm:cm[j].name,st:cm[j].summaryType, v: '', sd:cm[j].summaryDivider, vd:'', sr: cm[j].summaryRound, srt: cm[j].summaryRoundType || 'round'});
  11310. } else {
  11311. grp.summary.push({nm:cm[j].name,st:cm[j].summaryType, v: '', sr: cm[j].summaryRound, srt: cm[j].summaryRoundType || 'round'});
  11312. }
  11313. }
  11314. }
  11315. }
  11316. } else {
  11317. $t.p.grouping = false;
  11318. }
  11319. });
  11320. },
  11321. groupingPrepare : function ( record, irow ) {
  11322. this.each(function(){
  11323. var grp = this.p.groupingView, $t= this, i,
  11324. grlen = grp.groupField.length,
  11325. fieldName,
  11326. v,
  11327. displayName,
  11328. displayValue,
  11329. changed = 0;
  11330. for(i=0;i<grlen;i++) {
  11331. fieldName = grp.groupField[i];
  11332. displayName = grp.displayField[i];
  11333. v = record[fieldName];
  11334. displayValue = displayName == null ? null : record[displayName];
  11335. if( displayValue == null ) {
  11336. displayValue = v;
  11337. }
  11338. if( v !== undefined ) {
  11339. if(irow === 0 ) {
  11340. // First record always starts a new group
  11341. grp.groups.push({idx:i,dataIndex:fieldName,value:v, displayValue: displayValue, startRow: irow, cnt:1, summary : [] } );
  11342. grp.lastvalues[i] = v;
  11343. grp.counters[i] = {cnt:1, pos:grp.groups.length-1, summary: $.extend(true,[],grp.summary)};
  11344. $.each(grp.counters[i].summary,function() {
  11345. if ($.isFunction(this.st)) {
  11346. this.v = this.st.call($t, this.v, this.nm, record);
  11347. } else {
  11348. this.v = $($t).jqGrid('groupingCalculations.handler',this.st, this.v, this.nm, this.sr, this.srt, record);
  11349. if(this.st.toLowerCase() === 'avg' && this.sd) {
  11350. this.vd = $($t).jqGrid('groupingCalculations.handler',this.st, this.vd, this.sd, this.sr, this.srt, record);
  11351. }
  11352. }
  11353. });
  11354. grp.groups[grp.counters[i].pos].summary = grp.counters[i].summary;
  11355. } else {
  11356. if (typeof v !== "object" && ($.isArray(grp.isInTheSameGroup) && $.isFunction(grp.isInTheSameGroup[i]) ? ! grp.isInTheSameGroup[i].call($t, grp.lastvalues[i], v, i, grp): grp.lastvalues[i] !== v)) {
  11357. // This record is not in same group as previous one
  11358. grp.groups.push({idx:i,dataIndex:fieldName,value:v, displayValue: displayValue, startRow: irow, cnt:1, summary : [] } );
  11359. grp.lastvalues[i] = v;
  11360. changed = 1;
  11361. grp.counters[i] = {cnt:1, pos:grp.groups.length-1, summary: $.extend(true,[],grp.summary)};
  11362. $.each(grp.counters[i].summary,function() {
  11363. if ($.isFunction(this.st)) {
  11364. this.v = this.st.call($t, this.v, this.nm, record);
  11365. } else {
  11366. this.v = $($t).jqGrid('groupingCalculations.handler',this.st, this.v, this.nm, this.sr, this.srt, record);
  11367. if(this.st.toLowerCase() === 'avg' && this.sd) {
  11368. this.vd = $($t).jqGrid('groupingCalculations.handler',this.st, this.vd, this.sd, this.sr, this.srt, record);
  11369. }
  11370. }
  11371. });
  11372. grp.groups[grp.counters[i].pos].summary = grp.counters[i].summary;
  11373. } else {
  11374. if (changed === 1) {
  11375. // This group has changed because an earlier group changed.
  11376. grp.groups.push({idx:i,dataIndex:fieldName,value:v, displayValue: displayValue, startRow: irow, cnt:1, summary : [] } );
  11377. grp.lastvalues[i] = v;
  11378. grp.counters[i] = {cnt:1, pos:grp.groups.length-1, summary: $.extend(true,[],grp.summary)};
  11379. $.each(grp.counters[i].summary,function() {
  11380. if ($.isFunction(this.st)) {
  11381. this.v = this.st.call($t, this.v, this.nm, record);
  11382. } else {
  11383. this.v = $($t).jqGrid('groupingCalculations.handler',this.st, this.v, this.nm, this.sr, this.srt, record);
  11384. if(this.st.toLowerCase() === 'avg' && this.sd) {
  11385. this.vd = $($t).jqGrid('groupingCalculations.handler',this.st, this.vd, this.sd, this.sr, this.srt, record);
  11386. }
  11387. }
  11388. });
  11389. grp.groups[grp.counters[i].pos].summary = grp.counters[i].summary;
  11390. } else {
  11391. grp.counters[i].cnt += 1;
  11392. grp.groups[grp.counters[i].pos].cnt = grp.counters[i].cnt;
  11393. $.each(grp.counters[i].summary,function() {
  11394. if ($.isFunction(this.st)) {
  11395. this.v = this.st.call($t, this.v, this.nm, record);
  11396. } else {
  11397. this.v = $($t).jqGrid('groupingCalculations.handler',this.st, this.v, this.nm, this.sr, this.srt, record);
  11398. if(this.st.toLowerCase() === 'avg' && this.sd) {
  11399. this.vd = $($t).jqGrid('groupingCalculations.handler',this.st, this.vd, this.sd, this.sr, this.srt, record);
  11400. }
  11401. }
  11402. });
  11403. grp.groups[grp.counters[i].pos].summary = grp.counters[i].summary;
  11404. }
  11405. }
  11406. }
  11407. }
  11408. }
  11409. //gdata.push( rData );
  11410. });
  11411. return this;
  11412. },
  11413. groupingToggle : function(hid){
  11414. this.each(function(){
  11415. var $t = this,
  11416. grp = $t.p.groupingView,
  11417. strpos = hid.split('_'),
  11418. num = parseInt(strpos[strpos.length-2], 10);
  11419. strpos.splice(strpos.length-2,2);
  11420. var uid = strpos.join("_"),
  11421. minus = grp.minusicon,
  11422. plus = grp.plusicon,
  11423. tar = $("#"+$.jgrid.jqID(hid)),
  11424. r = tar.length ? tar[0].nextSibling : null,
  11425. tarspan = $("#"+$.jgrid.jqID(hid)+" span."+"tree-wrap-"+$t.p.direction),
  11426. getGroupingLevelFromClass = function (className) {
  11427. var nums = $.map(className.split(" "), function (item) {
  11428. if (item.substring(0, uid.length + 1) === uid + "_") {
  11429. return parseInt(item.substring(uid.length + 1), 10);
  11430. }
  11431. });
  11432. return nums.length > 0 ? nums[0] : undefined;
  11433. },
  11434. itemGroupingLevel,
  11435. showData,
  11436. collapsed = false,
  11437. frz = $t.p.frozenColumns ? $t.p.id+"_frozen" : false,
  11438. tar2 = frz ? $("#"+$.jgrid.jqID(hid), "#"+$.jgrid.jqID(frz) ) : false,
  11439. r2 = (tar2 && tar2.length) ? tar2[0].nextSibling : null;
  11440. if( tarspan.hasClass(minus) ) {
  11441. if(grp.showSummaryOnHide) {
  11442. if(r){
  11443. while(r) {
  11444. if($(r).hasClass('jqfoot') ) {
  11445. var lv = parseInt($(r).attr("jqfootlevel"),10);
  11446. if( lv <= num) {
  11447. break;
  11448. }
  11449. }
  11450. $(r).hide();
  11451. r = r.nextSibling;
  11452. if(frz) {
  11453. $(r2).hide();
  11454. r2 = r2.nextSibling;
  11455. }
  11456. }
  11457. }
  11458. } else {
  11459. if(r){
  11460. while(r) {
  11461. itemGroupingLevel = getGroupingLevelFromClass(r.className);
  11462. if (itemGroupingLevel !== undefined && itemGroupingLevel <= num) {
  11463. break;
  11464. }
  11465. $(r).hide();
  11466. r = r.nextSibling;
  11467. if(frz) {
  11468. $(r2).hide();
  11469. r2 = r2.nextSibling;
  11470. }
  11471. }
  11472. }
  11473. }
  11474. tarspan.removeClass(minus).addClass(plus);
  11475. collapsed = true;
  11476. } else {
  11477. if(r){
  11478. showData = undefined;
  11479. while(r) {
  11480. itemGroupingLevel = getGroupingLevelFromClass(r.className);
  11481. if (showData === undefined) {
  11482. showData = itemGroupingLevel === undefined; // if the first row after the opening group is data row then show the data rows
  11483. }
  11484. if (itemGroupingLevel !== undefined) {
  11485. if (itemGroupingLevel <= num) {
  11486. break;// next item of the same lever are found
  11487. }
  11488. if (itemGroupingLevel === num + 1) {
  11489. $(r).show().find(">td>span."+"tree-wrap-"+$t.p.direction).removeClass(minus).addClass(plus);
  11490. if(frz) {
  11491. $(r2).show().find(">td>span."+"tree-wrap-"+$t.p.direction).removeClass(minus).addClass(plus);
  11492. }
  11493. }
  11494. } else if (showData) {
  11495. $(r).show();
  11496. if(frz) {
  11497. $(r2).show();
  11498. }
  11499. }
  11500. r = r.nextSibling;
  11501. if(frz) {
  11502. r2 = r2.nextSibling;
  11503. }
  11504. }
  11505. }
  11506. tarspan.removeClass(plus).addClass(minus);
  11507. }
  11508. $($t).triggerHandler("jqGridGroupingClickGroup", [hid , collapsed]);
  11509. if( $.isFunction($t.p.onClickGroup)) { $t.p.onClickGroup.call($t, hid , collapsed); }
  11510. });
  11511. return false;
  11512. },
  11513. groupingRender : function (grdata, colspans, page, rn ) {
  11514. return this.each(function(){
  11515. var $t = this,
  11516. grp = $t.p.groupingView,
  11517. str = "", icon = "", hid, clid, pmrtl = grp.groupCollapse ? grp.plusicon : grp.minusicon, gv, cp=[], len =grp.groupField.length;
  11518. pmrtl += " tree-wrap-"+$t.p.direction;
  11519. $.each($t.p.colModel, function (i,n){
  11520. var ii;
  11521. for(ii=0;ii<len;ii++) {
  11522. if(grp.groupField[ii] === n.name ) {
  11523. cp[ii] = i;
  11524. break;
  11525. }
  11526. }
  11527. });
  11528. var toEnd = 0;
  11529. function findGroupIdx( ind , offset, grp) {
  11530. var ret = false, i;
  11531. if(offset===0) {
  11532. ret = grp[ind];
  11533. } else {
  11534. var id = grp[ind].idx;
  11535. if(id===0) {
  11536. ret = grp[ind];
  11537. } else {
  11538. for(i=ind;i >= 0; i--) {
  11539. if(grp[i].idx === id-offset) {
  11540. ret = grp[i];
  11541. break;
  11542. }
  11543. }
  11544. }
  11545. }
  11546. return ret;
  11547. }
  11548. function buildSummaryTd(i, ik, grp, foffset) {
  11549. var fdata = findGroupIdx(i, ik, grp),
  11550. cm = $t.p.colModel,
  11551. vv, grlen = fdata.cnt, str="", k;
  11552. for(k=foffset; k<colspans;k++) {
  11553. var tmpdata = "<td "+$t.formatCol(k,1,'')+">&#160;</td>",
  11554. tplfld = "{0}";
  11555. $.each(fdata.summary,function(){
  11556. if(this.nm === cm[k].name) {
  11557. if(cm[k].summaryTpl) {
  11558. tplfld = cm[k].summaryTpl;
  11559. }
  11560. if(typeof this.st === 'string' && this.st.toLowerCase() === 'avg') {
  11561. if(this.sd && this.vd) {
  11562. this.v = (this.v/this.vd);
  11563. } else if(this.v && grlen > 0) {
  11564. this.v = (this.v/grlen);
  11565. }
  11566. }
  11567. try {
  11568. this.groupCount = fdata.cnt;
  11569. this.groupIndex = fdata.dataIndex;
  11570. this.groupValue = fdata.value;
  11571. vv = $t.formatter('', this.v, k, this);
  11572. } catch (ef) {
  11573. vv = this.v;
  11574. }
  11575. tmpdata= "<td "+$t.formatCol(k,1,'')+">"+$.jgrid.format(tplfld,vv)+ "</td>";
  11576. return false;
  11577. }
  11578. });
  11579. str += tmpdata;
  11580. }
  11581. return str;
  11582. }
  11583. var sumreverse = $.makeArray(grp.groupSummary);
  11584. sumreverse.reverse();
  11585. $.each(grp.groups,function(i,n){
  11586. if(grp._locgr) {
  11587. if( !(n.startRow +n.cnt > (page-1)*rn && n.startRow < page*rn)) {
  11588. return true;
  11589. }
  11590. }
  11591. toEnd++;
  11592. clid = $t.p.id+"ghead_"+n.idx;
  11593. hid = clid+"_"+i;
  11594. icon = "<span style='cursor:pointer;' class='ui-icon "+pmrtl+"' onclick=\"jQuery('#"+$.jgrid.jqID($t.p.id)+"').jqGrid('groupingToggle','"+hid+"');return false;\"></span>";
  11595. try {
  11596. if ($.isArray(grp.formatDisplayField) && $.isFunction(grp.formatDisplayField[n.idx])) {
  11597. n.displayValue = grp.formatDisplayField[n.idx].call($t, n.displayValue, n.value, $t.p.colModel[cp[n.idx]], n.idx, grp);
  11598. gv = n.displayValue;
  11599. } else {
  11600. gv = $t.formatter(hid, n.displayValue, cp[n.idx], n.value );
  11601. }
  11602. } catch (egv) {
  11603. gv = n.displayValue;
  11604. }
  11605. if(grp.groupSummaryPos[n.idx] === 'header') {
  11606. str += "<tr id=\""+hid+"\"" +(grp.groupCollapse && n.idx>0 ? " style=\"display:none;\" " : " ") + "role=\"row\" class= \"ui-widget-content jqgroup ui-row-"+$t.p.direction+" "+clid+"\"><td style=\"padding-left:"+(n.idx * 12) + "px;"+"\">"+icon+$.jgrid.template(grp.groupText[n.idx], gv, n.cnt, n.summary)+"</td>";
  11607. str += buildSummaryTd(i, n.idx-1, grp.groups, 1);
  11608. str += "</tr>";
  11609. } else {
  11610. str += "<tr id=\""+hid+"\"" +(grp.groupCollapse && n.idx>0 ? " style=\"display:none;\" " : " ") + "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>";
  11611. }
  11612. var leaf = len-1 === n.idx;
  11613. if( leaf ) {
  11614. var gg = grp.groups[i+1], kk, ik, offset = 0, sgr = n.startRow,
  11615. end = gg !== undefined ? grp.groups[i+1].startRow : grdata.length;
  11616. if(grp._locgr) {
  11617. offset = (page-1)*rn;
  11618. if(offset > n.startRow) {
  11619. sgr = offset;
  11620. }
  11621. }
  11622. for(kk=sgr;kk<end;kk++) {
  11623. if(!grdata[kk - offset]) { break; }
  11624. str += grdata[kk - offset].join('');
  11625. }
  11626. if(grp.groupSummaryPos[n.idx] !== 'header') {
  11627. var jj;
  11628. if (gg !== undefined) {
  11629. for (jj = 0; jj < grp.groupField.length; jj++) {
  11630. if (gg.dataIndex === grp.groupField[jj]) {
  11631. break;
  11632. }
  11633. }
  11634. toEnd = grp.groupField.length - jj;
  11635. }
  11636. for (ik = 0; ik < toEnd; ik++) {
  11637. if(!sumreverse[ik]) { continue; }
  11638. var hhdr = "";
  11639. if(grp.groupCollapse && !grp.showSummaryOnHide) {
  11640. hhdr = " style=\"display:none;\"";
  11641. }
  11642. str += "<tr"+hhdr+" jqfootlevel=\""+(n.idx-ik)+"\" role=\"row\" class=\"ui-widget-content jqfoot ui-row-"+$t.p.direction+"\">";
  11643. str += buildSummaryTd(i, ik, grp.groups, 0);
  11644. str += "</tr>";
  11645. }
  11646. toEnd = jj;
  11647. }
  11648. }
  11649. });
  11650. $("#"+$.jgrid.jqID($t.p.id)+" tbody:first").append(str);
  11651. // free up memory
  11652. str = null;
  11653. });
  11654. },
  11655. groupingGroupBy : function (name, options ) {
  11656. return this.each(function(){
  11657. var $t = this;
  11658. if(typeof name === "string") {
  11659. name = [name];
  11660. }
  11661. var grp = $t.p.groupingView;
  11662. $t.p.grouping = true;
  11663. //Set default, in case visibilityOnNextGrouping is undefined
  11664. if (grp.visibiltyOnNextGrouping === undefined) {
  11665. grp.visibiltyOnNextGrouping = [];
  11666. }
  11667. var i;
  11668. // show previous hidden groups if they are hidden and weren't removed yet
  11669. for(i=0;i<grp.groupField.length;i++) {
  11670. if(!grp.groupColumnShow[i] && grp.visibiltyOnNextGrouping[i]) {
  11671. $($t).jqGrid('showCol',grp.groupField[i]);
  11672. }
  11673. }
  11674. // set visibility status of current group columns on next grouping
  11675. for(i=0;i<name.length;i++) {
  11676. grp.visibiltyOnNextGrouping[i] = $("#"+$.jgrid.jqID($t.p.id)+"_"+$.jgrid.jqID(name[i])).is(":visible");
  11677. }
  11678. $t.p.groupingView = $.extend($t.p.groupingView, options || {});
  11679. grp.groupField = name;
  11680. $($t).trigger("reloadGrid");
  11681. });
  11682. },
  11683. groupingRemove : function (current) {
  11684. return this.each(function(){
  11685. var $t = this;
  11686. if(current === undefined) {
  11687. current = true;
  11688. }
  11689. $t.p.grouping = false;
  11690. if(current===true) {
  11691. var grp = $t.p.groupingView, i;
  11692. // show previous hidden groups if they are hidden and weren't removed yet
  11693. for(i=0;i<grp.groupField.length;i++) {
  11694. if (!grp.groupColumnShow[i] && grp.visibiltyOnNextGrouping[i]) {
  11695. $($t).jqGrid('showCol', grp.groupField);
  11696. }
  11697. }
  11698. $("tr.jqgroup, tr.jqfoot","#"+$.jgrid.jqID($t.p.id)+" tbody:first").remove();
  11699. $("tr.jqgrow:hidden","#"+$.jgrid.jqID($t.p.id)+" tbody:first").show();
  11700. } else {
  11701. $($t).trigger("reloadGrid");
  11702. }
  11703. });
  11704. },
  11705. groupingCalculations : {
  11706. handler: function(fn, v, field, round, roundType, rc) {
  11707. var funcs = {
  11708. sum: function() {
  11709. return parseFloat(v||0) + parseFloat((rc[field]||0));
  11710. },
  11711. min: function() {
  11712. if(v==="") {
  11713. return parseFloat(rc[field]||0);
  11714. }
  11715. return Math.min(parseFloat(v),parseFloat(rc[field]||0));
  11716. },
  11717. max: function() {
  11718. if(v==="") {
  11719. return parseFloat(rc[field]||0);
  11720. }
  11721. return Math.max(parseFloat(v),parseFloat(rc[field]||0));
  11722. },
  11723. count: function() {
  11724. if(v==="") {v=0;}
  11725. if(rc.hasOwnProperty(field)) {
  11726. return v+1;
  11727. }
  11728. return 0;
  11729. },
  11730. avg: function() {
  11731. // the same as sum, but at end we divide it
  11732. // so use sum instead of duplicating the code (?)
  11733. return funcs.sum();
  11734. }
  11735. };
  11736. if(!funcs[fn]) {
  11737. throw ("jqGrid Grouping No such method: " + fn);
  11738. }
  11739. var res = funcs[fn]();
  11740. if (round != null) {
  11741. if (roundType === 'fixed') {
  11742. res = res.toFixed(round);
  11743. } else {
  11744. var mul = Math.pow(10, round);
  11745. res = Math.round(res * mul) / mul;
  11746. }
  11747. }
  11748. return res;
  11749. }
  11750. }
  11751. });
  11752. })(jQuery);
  11753. /*jshint eqeqeq:false, eqnull:true, devel:true */
  11754. /*global jQuery, xmlJsonClass */
  11755. (function($){
  11756. /*
  11757. * jqGrid extension for constructing Grid Data from external file
  11758. * Tony Tomov tony@trirand.com
  11759. * http://trirand.com/blog/
  11760. * Dual licensed under the MIT and GPL licenses:
  11761. * http://www.opensource.org/licenses/mit-license.php
  11762. * http://www.gnu.org/licenses/gpl-2.0.html
  11763. **/
  11764. "use strict";
  11765. $.jgrid.extend({
  11766. jqGridImport : function(o) {
  11767. o = $.extend({
  11768. imptype : "xml", // xml, json, xmlstring, jsonstring
  11769. impstring: "",
  11770. impurl: "",
  11771. mtype: "GET",
  11772. impData : {},
  11773. xmlGrid :{
  11774. config : "roots>grid",
  11775. data: "roots>rows"
  11776. },
  11777. jsonGrid :{
  11778. config : "grid",
  11779. data: "data"
  11780. },
  11781. ajaxOptions :{}
  11782. }, o || {});
  11783. return this.each(function(){
  11784. var $t = this;
  11785. var xmlConvert = function (xml,o) {
  11786. var cnfg = $(o.xmlGrid.config,xml)[0];
  11787. var xmldata = $(o.xmlGrid.data,xml)[0], jstr, jstr1, key;
  11788. if(xmlJsonClass.xml2json && $.jgrid.parse) {
  11789. jstr = xmlJsonClass.xml2json(cnfg," ");
  11790. jstr = $.jgrid.parse(jstr);
  11791. for(key in jstr) {
  11792. if(jstr.hasOwnProperty(key)) {
  11793. jstr1=jstr[key];
  11794. }
  11795. }
  11796. if(xmldata) {
  11797. // save the datatype
  11798. var svdatatype = jstr.grid.datatype;
  11799. jstr.grid.datatype = 'xmlstring';
  11800. jstr.grid.datastr = xml;
  11801. $($t).jqGrid( jstr1 ).jqGrid("setGridParam",{datatype:svdatatype});
  11802. } else {
  11803. $($t).jqGrid( jstr1 );
  11804. }
  11805. jstr = null;jstr1=null;
  11806. } else {
  11807. alert("xml2json or parse are not present");
  11808. }
  11809. };
  11810. var jsonConvert = function (jsonstr,o){
  11811. if (jsonstr && typeof jsonstr === 'string') {
  11812. var _jsonparse = false;
  11813. if($.jgrid.useJSON) {
  11814. $.jgrid.useJSON = false;
  11815. _jsonparse = true;
  11816. }
  11817. var json = $.jgrid.parse(jsonstr);
  11818. if(_jsonparse) { $.jgrid.useJSON = true; }
  11819. var gprm = json[o.jsonGrid.config];
  11820. var jdata = json[o.jsonGrid.data];
  11821. if(jdata) {
  11822. var svdatatype = gprm.datatype;
  11823. gprm.datatype = 'jsonstring';
  11824. gprm.datastr = jdata;
  11825. $($t).jqGrid( gprm ).jqGrid("setGridParam",{datatype:svdatatype});
  11826. } else {
  11827. $($t).jqGrid( gprm );
  11828. }
  11829. }
  11830. };
  11831. switch (o.imptype){
  11832. case 'xml':
  11833. $.ajax($.extend({
  11834. url:o.impurl,
  11835. type:o.mtype,
  11836. data: o.impData,
  11837. dataType:"xml",
  11838. complete: function(xml,stat) {
  11839. if(stat === 'success') {
  11840. xmlConvert(xml.responseXML,o);
  11841. $($t).triggerHandler("jqGridImportComplete", [xml, o]);
  11842. if($.isFunction(o.importComplete)) {
  11843. o.importComplete(xml);
  11844. }
  11845. }
  11846. xml=null;
  11847. }
  11848. }, o.ajaxOptions));
  11849. break;
  11850. case 'xmlstring' :
  11851. // we need to make just the conversion and use the same code as xml
  11852. if(o.impstring && typeof o.impstring === 'string') {
  11853. var xmld = $.parseXML(o.impstring);
  11854. if(xmld) {
  11855. xmlConvert(xmld,o);
  11856. $($t).triggerHandler("jqGridImportComplete", [xmld, o]);
  11857. if($.isFunction(o.importComplete)) {
  11858. o.importComplete(xmld);
  11859. }
  11860. o.impstring = null;
  11861. }
  11862. xmld = null;
  11863. }
  11864. break;
  11865. case 'json':
  11866. $.ajax($.extend({
  11867. url:o.impurl,
  11868. type:o.mtype,
  11869. data: o.impData,
  11870. dataType:"json",
  11871. complete: function(json) {
  11872. try {
  11873. jsonConvert(json.responseText,o );
  11874. $($t).triggerHandler("jqGridImportComplete", [json, o]);
  11875. if($.isFunction(o.importComplete)) {
  11876. o.importComplete(json);
  11877. }
  11878. } catch (ee){}
  11879. json=null;
  11880. }
  11881. }, o.ajaxOptions ));
  11882. break;
  11883. case 'jsonstring' :
  11884. if(o.impstring && typeof o.impstring === 'string') {
  11885. jsonConvert(o.impstring,o );
  11886. $($t).triggerHandler("jqGridImportComplete", [o.impstring, o]);
  11887. if($.isFunction(o.importComplete)) {
  11888. o.importComplete(o.impstring);
  11889. }
  11890. o.impstring = null;
  11891. }
  11892. break;
  11893. }
  11894. });
  11895. },
  11896. jqGridExport : function(o) {
  11897. o = $.extend({
  11898. exptype : "xmlstring",
  11899. root: "grid",
  11900. ident: "\t"
  11901. }, o || {});
  11902. var ret = null;
  11903. this.each(function () {
  11904. if(!this.grid) { return;}
  11905. var key, gprm = $.extend(true, {},$(this).jqGrid("getGridParam"));
  11906. // we need to check for:
  11907. // 1.multiselect, 2.subgrid 3. treegrid and remove the unneded columns from colNames
  11908. if(gprm.rownumbers) {
  11909. gprm.colNames.splice(0,1);
  11910. gprm.colModel.splice(0,1);
  11911. }
  11912. if(gprm.multiselect) {
  11913. gprm.colNames.splice(0,1);
  11914. gprm.colModel.splice(0,1);
  11915. }
  11916. if(gprm.subGrid) {
  11917. gprm.colNames.splice(0,1);
  11918. gprm.colModel.splice(0,1);
  11919. }
  11920. gprm.knv = null;
  11921. if(gprm.treeGrid) {
  11922. for (key in gprm.treeReader) {
  11923. if(gprm.treeReader.hasOwnProperty(key)) {
  11924. gprm.colNames.splice(gprm.colNames.length-1);
  11925. gprm.colModel.splice(gprm.colModel.length-1);
  11926. }
  11927. }
  11928. }
  11929. switch (o.exptype) {
  11930. case 'xmlstring' :
  11931. ret = "<"+o.root+">"+xmlJsonClass.json2xml(gprm,o.ident)+"</"+o.root+">";
  11932. break;
  11933. case 'jsonstring' :
  11934. ret = "{"+ xmlJsonClass.toJson(gprm,o.root,o.ident,false)+"}";
  11935. if(gprm.postData.filters !== undefined) {
  11936. ret=ret.replace(/filters":"/,'filters":');
  11937. ret=ret.replace(/}]}"/,'}]}');
  11938. }
  11939. break;
  11940. }
  11941. });
  11942. return ret;
  11943. },
  11944. excelExport : function(o) {
  11945. o = $.extend({
  11946. exptype : "remote",
  11947. url : null,
  11948. oper: "oper",
  11949. tag: "excel",
  11950. exportOptions : {}
  11951. }, o || {});
  11952. return this.each(function(){
  11953. if(!this.grid) { return;}
  11954. var url;
  11955. if(o.exptype === "remote") {
  11956. var pdata = $.extend({},this.p.postData);
  11957. pdata[o.oper] = o.tag;
  11958. var params = jQuery.param(pdata);
  11959. if(o.url.indexOf("?") !== -1) { url = o.url+"&"+params; }
  11960. else { url = o.url+"?"+params; }
  11961. window.location = url;
  11962. }
  11963. });
  11964. }
  11965. });
  11966. })(jQuery);
  11967. /*jshint evil:true, eqeqeq:false, eqnull:true, devel:true */
  11968. /*global jQuery */
  11969. (function($){
  11970. /*
  11971. **
  11972. * jqGrid addons using jQuery UI
  11973. * Author: Mark Williams
  11974. * Dual licensed under the MIT and GPL licenses:
  11975. * http://www.opensource.org/licenses/mit-license.php
  11976. * http://www.gnu.org/licenses/gpl-2.0.html
  11977. * depends on jQuery UI
  11978. **/
  11979. "use strict";
  11980. if ($.jgrid.msie && $.jgrid.msiever()===8) {
  11981. $.expr[":"].hidden = function(elem) {
  11982. return elem.offsetWidth === 0 || elem.offsetHeight === 0 ||
  11983. elem.style.display === "none";
  11984. };
  11985. }
  11986. // requiere load multiselect before grid
  11987. $.jgrid._multiselect = false;
  11988. if($.ui) {
  11989. if ($.ui.multiselect ) {
  11990. if($.ui.multiselect.prototype._setSelected) {
  11991. var setSelected = $.ui.multiselect.prototype._setSelected;
  11992. $.ui.multiselect.prototype._setSelected = function(item,selected) {
  11993. var ret = setSelected.call(this,item,selected);
  11994. if (selected && this.selectedList) {
  11995. var elt = this.element;
  11996. this.selectedList.find('li').each(function() {
  11997. if ($(this).data('optionLink')) {
  11998. $(this).data('optionLink').remove().appendTo(elt);
  11999. }
  12000. });
  12001. }
  12002. return ret;
  12003. };
  12004. }
  12005. if($.ui.multiselect.prototype.destroy) {
  12006. $.ui.multiselect.prototype.destroy = function() {
  12007. this.element.show();
  12008. this.container.remove();
  12009. if ($.Widget === undefined) {
  12010. $.widget.prototype.destroy.apply(this, arguments);
  12011. } else {
  12012. $.Widget.prototype.destroy.apply(this, arguments);
  12013. }
  12014. };
  12015. }
  12016. $.jgrid._multiselect = true;
  12017. }
  12018. }
  12019. $.jgrid.extend({
  12020. sortableColumns : function (tblrow)
  12021. {
  12022. return this.each(function (){
  12023. var ts = this, tid= $.jgrid.jqID( ts.p.id );
  12024. function start() {ts.p.disableClick = true;}
  12025. var sortable_opts = {
  12026. "tolerance" : "pointer",
  12027. "axis" : "x",
  12028. "scrollSensitivity": "1",
  12029. "items": '>th:not(:has(#jqgh_'+tid+'_cb'+',#jqgh_'+tid+'_rn'+',#jqgh_'+tid+'_subgrid),:hidden)',
  12030. "placeholder": {
  12031. element: function(item) {
  12032. var el = $(document.createElement(item[0].nodeName))
  12033. .addClass(item[0].className+" ui-sortable-placeholder ui-state-highlight")
  12034. .removeClass("ui-sortable-helper")[0];
  12035. return el;
  12036. },
  12037. update: function(self, p) {
  12038. p.height(self.currentItem.innerHeight() - parseInt(self.currentItem.css('paddingTop')||0, 10) - parseInt(self.currentItem.css('paddingBottom')||0, 10));
  12039. p.width(self.currentItem.innerWidth() - parseInt(self.currentItem.css('paddingLeft')||0, 10) - parseInt(self.currentItem.css('paddingRight')||0, 10));
  12040. }
  12041. },
  12042. "update": function(event, ui) {
  12043. var p = $(ui.item).parent(),
  12044. th = $(">th", p),
  12045. colModel = ts.p.colModel,
  12046. cmMap = {}, tid= ts.p.id+"_";
  12047. $.each(colModel, function(i) { cmMap[this.name]=i; });
  12048. var permutation = [];
  12049. th.each(function() {
  12050. var id = $(">div", this).get(0).id.replace(/^jqgh_/, "").replace(tid,"");
  12051. if (cmMap.hasOwnProperty(id)) {
  12052. permutation.push(cmMap[id]);
  12053. }
  12054. });
  12055. $(ts).jqGrid("remapColumns",permutation, true, true);
  12056. if ($.isFunction(ts.p.sortable.update)) {
  12057. ts.p.sortable.update(permutation);
  12058. }
  12059. setTimeout(function(){ts.p.disableClick=false;}, 50);
  12060. }
  12061. };
  12062. if (ts.p.sortable.options) {
  12063. $.extend(sortable_opts, ts.p.sortable.options);
  12064. } else if ($.isFunction(ts.p.sortable)) {
  12065. ts.p.sortable = { "update" : ts.p.sortable };
  12066. }
  12067. if (sortable_opts.start) {
  12068. var s = sortable_opts.start;
  12069. sortable_opts.start = function(e,ui) {
  12070. start();
  12071. s.call(this,e,ui);
  12072. };
  12073. } else {
  12074. sortable_opts.start = start;
  12075. }
  12076. if (ts.p.sortable.exclude) {
  12077. sortable_opts.items += ":not("+ts.p.sortable.exclude+")";
  12078. }
  12079. tblrow.sortable(sortable_opts).data("sortable").floating = true;
  12080. });
  12081. },
  12082. columnChooser : function(opts) {
  12083. var self = this;
  12084. if($("#colchooser_"+$.jgrid.jqID(self[0].p.id)).length ) { return; }
  12085. var selector = $('<div id="colchooser_'+self[0].p.id+'" style="position:relative;overflow:hidden"><div><select multiple="multiple"></select></div></div>');
  12086. var select = $('select', selector);
  12087. function insert(perm,i,v) {
  12088. if(i>=0){
  12089. var a = perm.slice();
  12090. var b = a.splice(i,Math.max(perm.length-i,i));
  12091. if(i>perm.length) { i = perm.length; }
  12092. a[i] = v;
  12093. return a.concat(b);
  12094. }
  12095. }
  12096. opts = $.extend({
  12097. "width" : 420,
  12098. "height" : 240,
  12099. "classname" : null,
  12100. "done" : function(perm) { if (perm) { self.jqGrid("remapColumns", perm, true); } },
  12101. /* msel is either the name of a ui widget class that
  12102. extends a multiselect, or a function that supports
  12103. creating a multiselect object (with no argument,
  12104. or when passed an object), and destroying it (when
  12105. passed the string "destroy"). */
  12106. "msel" : "multiselect",
  12107. /* "msel_opts" : {}, */
  12108. /* dlog is either the name of a ui widget class that
  12109. behaves in a dialog-like way, or a function, that
  12110. supports creating a dialog (when passed dlog_opts)
  12111. or destroying a dialog (when passed the string
  12112. "destroy")
  12113. */
  12114. "dlog" : "dialog",
  12115. "dialog_opts" : {
  12116. "minWidth": 470
  12117. },
  12118. /* dlog_opts is either an option object to be passed
  12119. to "dlog", or (more likely) a function that creates
  12120. the options object.
  12121. The default produces a suitable options object for
  12122. ui.dialog */
  12123. "dlog_opts" : function(opts) {
  12124. var buttons = {};
  12125. buttons[opts.bSubmit] = function() {
  12126. opts.apply_perm();
  12127. opts.cleanup(false);
  12128. };
  12129. buttons[opts.bCancel] = function() {
  12130. opts.cleanup(true);
  12131. };
  12132. return $.extend(true, {
  12133. "buttons": buttons,
  12134. "close": function() {
  12135. opts.cleanup(true);
  12136. },
  12137. "modal" : opts.modal || false,
  12138. "resizable": opts.resizable || true,
  12139. "width": opts.width+20
  12140. }, opts.dialog_opts || {});
  12141. },
  12142. /* Function to get the permutation array, and pass it to the
  12143. "done" function */
  12144. "apply_perm" : function() {
  12145. $('option',select).each(function() {
  12146. if (this.selected) {
  12147. self.jqGrid("showCol", colModel[this.value].name);
  12148. } else {
  12149. self.jqGrid("hideCol", colModel[this.value].name);
  12150. }
  12151. });
  12152. var perm = [];
  12153. //fixedCols.slice(0);
  12154. $('option:selected',select).each(function() { perm.push(parseInt(this.value,10)); });
  12155. $.each(perm, function() { delete colMap[colModel[parseInt(this,10)].name]; });
  12156. $.each(colMap, function() {
  12157. var ti = parseInt(this,10);
  12158. perm = insert(perm,ti,ti);
  12159. });
  12160. if (opts.done) {
  12161. opts.done.call(self, perm);
  12162. }
  12163. },
  12164. /* Function to cleanup the dialog, and select. Also calls the
  12165. done function with no permutation (to indicate that the
  12166. columnChooser was aborted */
  12167. "cleanup" : function(calldone) {
  12168. call(opts.dlog, selector, 'destroy');
  12169. call(opts.msel, select, 'destroy');
  12170. selector.remove();
  12171. if (calldone && opts.done) {
  12172. opts.done.call(self);
  12173. }
  12174. },
  12175. "msel_opts" : {}
  12176. }, $.jgrid.col, opts || {});
  12177. if($.ui) {
  12178. if ($.ui.multiselect ) {
  12179. if(opts.msel === "multiselect") {
  12180. if(!$.jgrid._multiselect) {
  12181. // should be in language file
  12182. alert("Multiselect plugin loaded after jqGrid. Please load the plugin before the jqGrid!");
  12183. return;
  12184. }
  12185. opts.msel_opts = $.extend($.ui.multiselect.defaults,opts.msel_opts);
  12186. }
  12187. }
  12188. }
  12189. if (opts.caption) {
  12190. selector.attr("title", opts.caption);
  12191. }
  12192. if (opts.classname) {
  12193. selector.addClass(opts.classname);
  12194. select.addClass(opts.classname);
  12195. }
  12196. if (opts.width) {
  12197. $(">div",selector).css({"width": opts.width,"margin":"0 auto"});
  12198. select.css("width", opts.width);
  12199. }
  12200. if (opts.height) {
  12201. $(">div",selector).css("height", opts.height);
  12202. select.css("height", opts.height - 10);
  12203. }
  12204. var colModel = self.jqGrid("getGridParam", "colModel");
  12205. var colNames = self.jqGrid("getGridParam", "colNames");
  12206. var colMap = {}, fixedCols = [];
  12207. select.empty();
  12208. $.each(colModel, function(i) {
  12209. colMap[this.name] = i;
  12210. if (this.hidedlg) {
  12211. if (!this.hidden) {
  12212. fixedCols.push(i);
  12213. }
  12214. return;
  12215. }
  12216. select.append("<option value='"+i+"' "+
  12217. (this.hidden?"":"selected='selected'")+">"+$.jgrid.stripHtml(colNames[i])+"</option>");
  12218. });
  12219. function call(fn, obj) {
  12220. if (!fn) { return; }
  12221. if (typeof fn === 'string') {
  12222. if ($.fn[fn]) {
  12223. $.fn[fn].apply(obj, $.makeArray(arguments).slice(2));
  12224. }
  12225. } else if ($.isFunction(fn)) {
  12226. fn.apply(obj, $.makeArray(arguments).slice(2));
  12227. }
  12228. }
  12229. var dopts = $.isFunction(opts.dlog_opts) ? opts.dlog_opts.call(self, opts) : opts.dlog_opts;
  12230. call(opts.dlog, selector, dopts);
  12231. var mopts = $.isFunction(opts.msel_opts) ? opts.msel_opts.call(self, opts) : opts.msel_opts;
  12232. call(opts.msel, select, mopts);
  12233. },
  12234. sortableRows : function (opts) {
  12235. // Can accept all sortable options and events
  12236. return this.each(function(){
  12237. var $t = this;
  12238. if(!$t.grid) { return; }
  12239. // Currently we disable a treeGrid sortable
  12240. if($t.p.treeGrid) { return; }
  12241. if($.fn.sortable) {
  12242. opts = $.extend({
  12243. "cursor":"move",
  12244. "axis" : "y",
  12245. "items": ".jqgrow"
  12246. },
  12247. opts || {});
  12248. if(opts.start && $.isFunction(opts.start)) {
  12249. opts._start_ = opts.start;
  12250. delete opts.start;
  12251. } else {opts._start_=false;}
  12252. if(opts.update && $.isFunction(opts.update)) {
  12253. opts._update_ = opts.update;
  12254. delete opts.update;
  12255. } else {opts._update_ = false;}
  12256. opts.start = function(ev,ui) {
  12257. $(ui.item).css("border-width","0");
  12258. $("td",ui.item).each(function(i){
  12259. this.style.width = $t.grid.cols[i].style.width;
  12260. });
  12261. if($t.p.subGrid) {
  12262. var subgid = $(ui.item).attr("id");
  12263. try {
  12264. $($t).jqGrid('collapseSubGridRow',subgid);
  12265. } catch (e) {}
  12266. }
  12267. if(opts._start_) {
  12268. opts._start_.apply(this,[ev,ui]);
  12269. }
  12270. };
  12271. opts.update = function (ev,ui) {
  12272. $(ui.item).css("border-width","");
  12273. if($t.p.rownumbers === true) {
  12274. $("td.jqgrid-rownum",$t.rows).each(function( i ){
  12275. $(this).html( i+1+(parseInt($t.p.page,10)-1)*parseInt($t.p.rowNum,10) );
  12276. });
  12277. }
  12278. if(opts._update_) {
  12279. opts._update_.apply(this,[ev,ui]);
  12280. }
  12281. };
  12282. $("tbody:first",$t).sortable(opts);
  12283. $("tbody:first",$t).disableSelection();
  12284. }
  12285. });
  12286. },
  12287. gridDnD : function(opts) {
  12288. return this.each(function(){
  12289. var $t = this, i, cn;
  12290. if(!$t.grid) { return; }
  12291. // Currently we disable a treeGrid drag and drop
  12292. if($t.p.treeGrid) { return; }
  12293. if(!$.fn.draggable || !$.fn.droppable) { return; }
  12294. function updateDnD ()
  12295. {
  12296. var datadnd = $.data($t,"dnd");
  12297. $("tr.jqgrow:not(.ui-draggable)",$t).draggable($.isFunction(datadnd.drag) ? datadnd.drag.call($($t),datadnd) : datadnd.drag);
  12298. }
  12299. var appender = "<table id='jqgrid_dnd' class='ui-jqgrid-dnd'></table>";
  12300. if($("#jqgrid_dnd")[0] === undefined) {
  12301. $('body').append(appender);
  12302. }
  12303. if(typeof opts === 'string' && opts === 'updateDnD' && $t.p.jqgdnd===true) {
  12304. updateDnD();
  12305. return;
  12306. }
  12307. opts = $.extend({
  12308. "drag" : function (opts) {
  12309. return $.extend({
  12310. start : function (ev, ui) {
  12311. var i, subgid;
  12312. // if we are in subgrid mode try to collapse the node
  12313. if($t.p.subGrid) {
  12314. subgid = $(ui.helper).attr("id");
  12315. try {
  12316. $($t).jqGrid('collapseSubGridRow',subgid);
  12317. } catch (e) {}
  12318. }
  12319. // hack
  12320. // drag and drop does not insert tr in table, when the table has no rows
  12321. // we try to insert new empty row on the target(s)
  12322. for (i=0;i<$.data($t,"dnd").connectWith.length;i++){
  12323. if($($.data($t,"dnd").connectWith[i]).jqGrid('getGridParam','reccount') === 0 ){
  12324. $($.data($t,"dnd").connectWith[i]).jqGrid('addRowData','jqg_empty_row',{});
  12325. }
  12326. }
  12327. ui.helper.addClass("ui-state-highlight");
  12328. $("td",ui.helper).each(function(i) {
  12329. this.style.width = $t.grid.headers[i].width+"px";
  12330. });
  12331. if(opts.onstart && $.isFunction(opts.onstart) ) { opts.onstart.call($($t),ev,ui); }
  12332. },
  12333. stop :function(ev,ui) {
  12334. var i, ids;
  12335. if(ui.helper.dropped && !opts.dragcopy) {
  12336. ids = $(ui.helper).attr("id");
  12337. if(ids === undefined) { ids = $(this).attr("id"); }
  12338. $($t).jqGrid('delRowData',ids );
  12339. }
  12340. // if we have a empty row inserted from start event try to delete it
  12341. for (i=0;i<$.data($t,"dnd").connectWith.length;i++){
  12342. $($.data($t,"dnd").connectWith[i]).jqGrid('delRowData','jqg_empty_row');
  12343. }
  12344. if(opts.onstop && $.isFunction(opts.onstop) ) { opts.onstop.call($($t),ev,ui); }
  12345. }
  12346. },opts.drag_opts || {});
  12347. },
  12348. "drop" : function (opts) {
  12349. return $.extend({
  12350. accept: function(d) {
  12351. if (!$(d).hasClass('jqgrow')) { return d;}
  12352. var tid = $(d).closest("table.ui-jqgrid-btable");
  12353. if(tid.length > 0 && $.data(tid[0],"dnd") !== undefined) {
  12354. var cn = $.data(tid[0],"dnd").connectWith;
  12355. return $.inArray('#'+$.jgrid.jqID(this.id),cn) !== -1 ? true : false;
  12356. }
  12357. return false;
  12358. },
  12359. drop: function(ev, ui) {
  12360. if (!$(ui.draggable).hasClass('jqgrow')) { return; }
  12361. var accept = $(ui.draggable).attr("id");
  12362. var getdata = ui.draggable.parent().parent().jqGrid('getRowData',accept);
  12363. if(!opts.dropbyname) {
  12364. var j =0, tmpdata = {}, nm, key;
  12365. var dropmodel = $("#"+$.jgrid.jqID(this.id)).jqGrid('getGridParam','colModel');
  12366. try {
  12367. for (key in getdata) {
  12368. if (getdata.hasOwnProperty(key)) {
  12369. nm = dropmodel[j].name;
  12370. if( !(nm === 'cb' || nm === 'rn' || nm === 'subgrid' )) {
  12371. if(getdata.hasOwnProperty(key) && dropmodel[j]) {
  12372. tmpdata[nm] = getdata[key];
  12373. }
  12374. }
  12375. j++;
  12376. }
  12377. }
  12378. getdata = tmpdata;
  12379. } catch (e) {}
  12380. }
  12381. ui.helper.dropped = true;
  12382. if(opts.beforedrop && $.isFunction(opts.beforedrop) ) {
  12383. //parameters to this callback - event, element, data to be inserted, sender, reciever
  12384. // should return object which will be inserted into the reciever
  12385. var datatoinsert = opts.beforedrop.call(this,ev,ui,getdata,$('#'+$.jgrid.jqID($t.p.id)),$(this));
  12386. if (datatoinsert !== undefined && datatoinsert !== null && typeof datatoinsert === "object") { getdata = datatoinsert; }
  12387. }
  12388. if(ui.helper.dropped) {
  12389. var grid;
  12390. if(opts.autoid) {
  12391. if($.isFunction(opts.autoid)) {
  12392. grid = opts.autoid.call(this,getdata);
  12393. } else {
  12394. grid = Math.ceil(Math.random()*1000);
  12395. grid = opts.autoidprefix+grid;
  12396. }
  12397. }
  12398. // NULL is interpreted as undefined while null as object
  12399. $("#"+$.jgrid.jqID(this.id)).jqGrid('addRowData',grid,getdata,opts.droppos);
  12400. }
  12401. if(opts.ondrop && $.isFunction(opts.ondrop) ) { opts.ondrop.call(this,ev,ui, getdata); }
  12402. }}, opts.drop_opts || {});
  12403. },
  12404. "onstart" : null,
  12405. "onstop" : null,
  12406. "beforedrop": null,
  12407. "ondrop" : null,
  12408. "drop_opts" : {
  12409. "activeClass": "ui-state-active",
  12410. "hoverClass": "ui-state-hover"
  12411. },
  12412. "drag_opts" : {
  12413. "revert": "invalid",
  12414. "helper": "clone",
  12415. "cursor": "move",
  12416. "appendTo" : "#jqgrid_dnd",
  12417. "zIndex": 5000
  12418. },
  12419. "dragcopy": false,
  12420. "dropbyname" : false,
  12421. "droppos" : "first",
  12422. "autoid" : true,
  12423. "autoidprefix" : "dnd_"
  12424. }, opts || {});
  12425. if(!opts.connectWith) { return; }
  12426. opts.connectWith = opts.connectWith.split(",");
  12427. opts.connectWith = $.map(opts.connectWith,function(n){return $.trim(n);});
  12428. $.data($t,"dnd",opts);
  12429. if($t.p.reccount !== 0 && !$t.p.jqgdnd) {
  12430. updateDnD();
  12431. }
  12432. $t.p.jqgdnd = true;
  12433. for (i=0;i<opts.connectWith.length;i++){
  12434. cn =opts.connectWith[i];
  12435. $(cn).droppable($.isFunction(opts.drop) ? opts.drop.call($($t),opts) : opts.drop);
  12436. }
  12437. });
  12438. },
  12439. gridResize : function(opts) {
  12440. return this.each(function(){
  12441. var $t = this, gID = $.jgrid.jqID($t.p.id);
  12442. if(!$t.grid || !$.fn.resizable) { return; }
  12443. opts = $.extend({}, opts || {});
  12444. if(opts.alsoResize ) {
  12445. opts._alsoResize_ = opts.alsoResize;
  12446. delete opts.alsoResize;
  12447. } else {
  12448. opts._alsoResize_ = false;
  12449. }
  12450. if(opts.stop && $.isFunction(opts.stop)) {
  12451. opts._stop_ = opts.stop;
  12452. delete opts.stop;
  12453. } else {
  12454. opts._stop_ = false;
  12455. }
  12456. opts.stop = function (ev, ui) {
  12457. $($t).jqGrid('setGridParam',{height:$("#gview_"+gID+" .ui-jqgrid-bdiv").height()});
  12458. $($t).jqGrid('setGridWidth',ui.size.width,opts.shrinkToFit);
  12459. if(opts._stop_) { opts._stop_.call($t,ev,ui); }
  12460. };
  12461. if(opts._alsoResize_) {
  12462. var optstest = "{\'#gview_"+gID+" .ui-jqgrid-bdiv\':true,'" +opts._alsoResize_+"':true}";
  12463. opts.alsoResize = eval('('+optstest+')'); // the only way that I found to do this
  12464. } else {
  12465. opts.alsoResize = $(".ui-jqgrid-bdiv","#gview_"+gID);
  12466. }
  12467. delete opts._alsoResize_;
  12468. $("#gbox_"+gID).resizable(opts);
  12469. });
  12470. }
  12471. });
  12472. })(jQuery);
  12473. /*
  12474. Transform a table to a jqGrid.
  12475. Peter Romianowski <peter.romianowski@optivo.de>
  12476. If the first column of the table contains checkboxes or
  12477. radiobuttons then the jqGrid is made selectable.
  12478. */
  12479. // Addition - selector can be a class or id
  12480. function tableToGrid(selector, options) {
  12481. jQuery(selector).each(function() {
  12482. if(this.grid) {return;} //Adedd from Tony Tomov
  12483. // This is a small "hack" to make the width of the jqGrid 100%
  12484. jQuery(this).width("99%");
  12485. var w = jQuery(this).width();
  12486. // Text whether we have single or multi select
  12487. var inputCheckbox = jQuery('tr td:first-child input[type=checkbox]:first', jQuery(this));
  12488. var inputRadio = jQuery('tr td:first-child input[type=radio]:first', jQuery(this));
  12489. var selectMultiple = inputCheckbox.length > 0;
  12490. var selectSingle = !selectMultiple && inputRadio.length > 0;
  12491. var selectable = selectMultiple || selectSingle;
  12492. //var inputName = inputCheckbox.attr("name") || inputRadio.attr("name");
  12493. // Build up the columnModel and the data
  12494. var colModel = [];
  12495. var colNames = [];
  12496. jQuery('th', jQuery(this)).each(function() {
  12497. if (colModel.length === 0 && selectable) {
  12498. colModel.push({
  12499. name: '__selection__',
  12500. index: '__selection__',
  12501. width: 0,
  12502. hidden: true
  12503. });
  12504. colNames.push('__selection__');
  12505. } else {
  12506. colModel.push({
  12507. name: jQuery(this).attr("id") || jQuery.trim(jQuery.jgrid.stripHtml(jQuery(this).html())).split(' ').join('_'),
  12508. index: jQuery(this).attr("id") || jQuery.trim(jQuery.jgrid.stripHtml(jQuery(this).html())).split(' ').join('_'),
  12509. width: jQuery(this).width() || 150
  12510. });
  12511. colNames.push(jQuery(this).html());
  12512. }
  12513. });
  12514. var data = [];
  12515. var rowIds = [];
  12516. var rowChecked = [];
  12517. jQuery('tbody > tr', jQuery(this)).each(function() {
  12518. var row = {};
  12519. var rowPos = 0;
  12520. jQuery('td', jQuery(this)).each(function() {
  12521. if (rowPos === 0 && selectable) {
  12522. var input = jQuery('input', jQuery(this));
  12523. var rowId = input.attr("value");
  12524. rowIds.push(rowId || data.length);
  12525. if (input.is(":checked")) {
  12526. rowChecked.push(rowId);
  12527. }
  12528. row[colModel[rowPos].name] = input.attr("value");
  12529. } else {
  12530. row[colModel[rowPos].name] = jQuery(this).html();
  12531. }
  12532. rowPos++;
  12533. });
  12534. if(rowPos >0) { data.push(row); }
  12535. });
  12536. // Clear the original HTML table
  12537. jQuery(this).empty();
  12538. // Mark it as jqGrid
  12539. jQuery(this).addClass("scroll");
  12540. jQuery(this).jqGrid(jQuery.extend({
  12541. datatype: "local",
  12542. width: w,
  12543. colNames: colNames,
  12544. colModel: colModel,
  12545. multiselect: selectMultiple
  12546. //inputName: inputName,
  12547. //inputValueCol: imputName != null ? "__selection__" : null
  12548. }, options || {}));
  12549. // Add data
  12550. var a;
  12551. for (a = 0; a < data.length; a++) {
  12552. var id = null;
  12553. if (rowIds.length > 0) {
  12554. id = rowIds[a];
  12555. if (id && id.replace) {
  12556. // We have to do this since the value of a checkbox
  12557. // or radio button can be anything
  12558. id = encodeURIComponent(id).replace(/[.\-%]/g, "_");
  12559. }
  12560. }
  12561. if (id === null) {
  12562. id = a + 1;
  12563. }
  12564. jQuery(this).jqGrid("addRowData",id, data[a]);
  12565. }
  12566. // Set the selection
  12567. for (a = 0; a < rowChecked.length; a++) {
  12568. jQuery(this).jqGrid("setSelection",rowChecked[a]);
  12569. }
  12570. });
  12571. };
  12572. /*jshint eqeqeq:false */
  12573. /*global jQuery */
  12574. (function($){
  12575. /**
  12576. * jqGrid pivot functions
  12577. * Tony Tomov tony@trirand.com
  12578. * http://trirand.com/blog/
  12579. * Dual licensed under the MIT and GPL licenses:
  12580. * http://www.opensource.org/licenses/mit-license.php
  12581. * http://www.gnu.org/licenses/gpl-2.0.html
  12582. */
  12583. "use strict";
  12584. // To optimize the search we need custom array filter
  12585. // This code is taken from
  12586. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter
  12587. function _pivotfilter (fn, context) {
  12588. var i,
  12589. value,
  12590. result = [],
  12591. length;
  12592. if (!this || typeof fn !== 'function' || (fn instanceof RegExp)) {
  12593. throw new TypeError();
  12594. }
  12595. length = this.length;
  12596. for (i = 0; i < length; i++) {
  12597. if (this.hasOwnProperty(i)) {
  12598. value = this[i];
  12599. if (fn.call(context, value, i, this)) {
  12600. result.push(value);
  12601. // We need break in order to cancel loop
  12602. // in case the row is found
  12603. break;
  12604. }
  12605. }
  12606. }
  12607. return result;
  12608. }
  12609. $.assocArraySize = function(obj) {
  12610. // http://stackoverflow.com/a/6700/11236
  12611. var size = 0, key;
  12612. for (key in obj) {
  12613. if (obj.hasOwnProperty(key)) {
  12614. size++;
  12615. }
  12616. }
  12617. return size;
  12618. };
  12619. $.jgrid.extend({
  12620. pivotSetup : function( data, options ){
  12621. // data should come in json format
  12622. // The function return the new colModel and the transformed data
  12623. // again with group setup options which then will be passed to the grid
  12624. var columns =[],
  12625. pivotrows =[],
  12626. summaries = [],
  12627. member=[],
  12628. groupOptions = {
  12629. grouping : true,
  12630. groupingView : {
  12631. groupField : [],
  12632. groupSummary: [],
  12633. groupSummaryPos:[]
  12634. }
  12635. },
  12636. headers = [],
  12637. o = $.extend ( {
  12638. rowTotals : false,
  12639. rowTotalsText : 'Total',
  12640. // summary columns
  12641. colTotals : false,
  12642. groupSummary : true,
  12643. groupSummaryPos : 'header',
  12644. frozenStaticCols : false
  12645. }, options || {});
  12646. this.each(function(){
  12647. var
  12648. row,
  12649. rowindex,
  12650. i,
  12651. rowlen = data.length,
  12652. xlen, ylen, aggrlen,
  12653. tmp,
  12654. newObj,
  12655. r=0;
  12656. // utility funcs
  12657. /*
  12658. * Filter the data to a given criteria. Return the firt occurance
  12659. */
  12660. function find(ar, fun, extra) {
  12661. var res;
  12662. res = _pivotfilter.call(ar, fun, extra);
  12663. return res.length > 0 ? res[0] : null;
  12664. }
  12665. /*
  12666. * Check if the grouped row column exist (See find)
  12667. * If the row is not find in pivot rows retun null,
  12668. * otherviese the column
  12669. */
  12670. function findGroup(item, index) {
  12671. var j = 0, ret = true, i;
  12672. for(i in item) {
  12673. if(item[i] != this[j]) {
  12674. ret = false;
  12675. break;
  12676. }
  12677. j++;
  12678. if(j>=this.length) {
  12679. break;
  12680. }
  12681. }
  12682. if(ret) {
  12683. rowindex = index;
  12684. }
  12685. return ret;
  12686. }
  12687. /*
  12688. * Perform calculations of the pivot values.
  12689. */
  12690. function calculation(oper, v, field, rc) {
  12691. var ret;
  12692. switch (oper) {
  12693. case "sum" :
  12694. ret = parseFloat(v||0) + parseFloat((rc[field]||0));
  12695. break;
  12696. case "count" :
  12697. if(v==="" || v == null) {
  12698. v=0;
  12699. }
  12700. if(rc.hasOwnProperty(field)) {
  12701. ret = v+1;
  12702. } else {
  12703. ret = 0;
  12704. }
  12705. break;
  12706. case "min" :
  12707. if(v==="" || v == null) {
  12708. ret = parseFloat(rc[field]||0);
  12709. } else {
  12710. ret =Math.min(parseFloat(v),parseFloat(rc[field]||0));
  12711. }
  12712. break;
  12713. case "max" :
  12714. if(v==="" || v == null) {
  12715. ret = parseFloat(rc[field]||0);
  12716. } else {
  12717. ret = Math.max(parseFloat(v),parseFloat(rc[field]||0));
  12718. }
  12719. break;
  12720. }
  12721. return ret;
  12722. }
  12723. /*
  12724. * The function agragates the values of the pivot grid.
  12725. * Return the current row with pivot summary values
  12726. */
  12727. function agregateFunc ( row, aggr, value, curr) {
  12728. // default is sum
  12729. var arrln = aggr.length, i, label, j, jv;
  12730. if($.isArray(value)) {
  12731. jv = value.length;
  12732. } else {
  12733. jv = 1;
  12734. }
  12735. member = [];
  12736. member.root = 0;
  12737. for(j=0;j<jv;j++) {
  12738. var tmpmember = [], vl;
  12739. for(i=0; i < arrln; i++) {
  12740. if(value == null) {
  12741. label = $.trim(aggr[i].member)+"_"+aggr[i].aggregator;
  12742. vl = label;
  12743. } else {
  12744. vl = value[j].replace(/\s+/g, '');
  12745. try {
  12746. label = (arrln === 1 ? vl : vl+"_"+aggr[i].aggregator+"_"+i);
  12747. } catch(e) {}
  12748. }
  12749. curr[label] = tmpmember[label] = calculation( aggr[i].aggregator, curr[label], aggr[i].member, row);
  12750. }
  12751. member[vl] = tmpmember;
  12752. }
  12753. return curr;
  12754. }
  12755. // Making the row totals without to add in yDimension
  12756. if(o.rowTotals && o.yDimension.length > 0) {
  12757. var dn = o.yDimension[0].dataName;
  12758. o.yDimension.splice(0,0,{dataName:dn});
  12759. o.yDimension[0].converter = function(){ return '_r_Totals'; };
  12760. }
  12761. // build initial columns (colModel) from xDimension
  12762. xlen = $.isArray(o.xDimension) ? o.xDimension.length : 0;
  12763. ylen = o.yDimension.length;
  12764. aggrlen = $.isArray(o.aggregates) ? o.aggregates.length : 0;
  12765. if(xlen === 0 || aggrlen === 0) {
  12766. throw("xDimension or aggregates optiona are not set!");
  12767. }
  12768. var colc;
  12769. for(i = 0; i< xlen; i++) {
  12770. colc = {name:o.xDimension[i].dataName, frozen: o.frozenStaticCols};
  12771. colc = $.extend(true, colc, o.xDimension[i]);
  12772. columns.push( colc );
  12773. }
  12774. var groupfields = xlen - 1, tree={};
  12775. //tree = { text: 'root', leaf: false, children: [] };
  12776. //loop over alll the source data
  12777. while( r < rowlen ) {
  12778. row = data[r];
  12779. var xValue = [];
  12780. var yValue = [];
  12781. tmp = {};
  12782. i = 0;
  12783. // build the data from xDimension
  12784. do {
  12785. xValue[i] = $.trim(row[o.xDimension[i].dataName]);
  12786. tmp[o.xDimension[i].dataName] = xValue[i];
  12787. i++;
  12788. } while( i < xlen );
  12789. var k = 0;
  12790. rowindex = -1;
  12791. // check to see if the row is in our new pivotrow set
  12792. newObj = find(pivotrows, findGroup, xValue);
  12793. if(!newObj) {
  12794. // if the row is not in our set
  12795. k = 0;
  12796. // if yDimension is set
  12797. if(ylen>=1) {
  12798. // build the cols set in yDimension
  12799. for(k=0;k<ylen;k++) {
  12800. yValue[k] = $.trim(row[o.yDimension[k].dataName]);
  12801. // Check to see if we have user defined conditions
  12802. if(o.yDimension[k].converter && $.isFunction(o.yDimension[k].converter)) {
  12803. yValue[k] = o.yDimension[k].converter.call(this, yValue[k], xValue, yValue);
  12804. }
  12805. }
  12806. // make the colums based on aggregates definition
  12807. // and return the members for late calculation
  12808. tmp = agregateFunc( row, o.aggregates, yValue, tmp );
  12809. } else if( ylen === 0 ) {
  12810. // if not set use direct the aggregates
  12811. tmp = agregateFunc( row, o.aggregates, null, tmp );
  12812. }
  12813. // add the result in pivot rows
  12814. pivotrows.push( tmp );
  12815. } else {
  12816. // the pivot exists
  12817. if( rowindex >= 0) {
  12818. k = 0;
  12819. // make the recalculations
  12820. if(ylen>=1) {
  12821. for(k=0;k<ylen;k++) {
  12822. yValue[k] = $.trim(row[o.yDimension[k].dataName]);
  12823. if(o.yDimension[k].converter && $.isFunction(o.yDimension[k].converter)) {
  12824. yValue[k] = o.yDimension[k].converter.call(this, yValue[k], xValue, yValue);
  12825. }
  12826. }
  12827. newObj = agregateFunc( row, o.aggregates, yValue, newObj );
  12828. } else if( ylen === 0 ) {
  12829. newObj = agregateFunc( row, o.aggregates, null, newObj );
  12830. }
  12831. // update the row
  12832. pivotrows[rowindex] = newObj;
  12833. }
  12834. }
  12835. var kj=0, current = null,existing = null, kk;
  12836. // Build a JSON tree from the member (see aggregateFunc)
  12837. // to make later the columns
  12838. //
  12839. for (kk in member) {
  12840. if(kj === 0) {
  12841. if (!tree.children||tree.children === undefined){
  12842. tree = { text: kk, level : 0, children: [] };
  12843. }
  12844. current = tree.children;
  12845. } else {
  12846. existing = null;
  12847. for (i=0; i < current.length; i++) {
  12848. if (current[i].text === kk) {
  12849. //current[i].fields=member[kk];
  12850. existing = current[i];
  12851. break;
  12852. }
  12853. }
  12854. if (existing) {
  12855. current = existing.children;
  12856. } else {
  12857. current.push({ children: [], text: kk, level: kj, fields: member[kk] });
  12858. current = current[current.length - 1].children;
  12859. }
  12860. }
  12861. kj++;
  12862. }
  12863. r++;
  12864. }
  12865. var lastval=[], initColLen = columns.length, swaplen = initColLen;
  12866. if(ylen>0) {
  12867. headers[ylen-1] = { useColSpanStyle: false, groupHeaders: []};
  12868. }
  12869. /*
  12870. * Recursive function which uses the tree to build the
  12871. * columns from the pivot values and set the group Headers
  12872. */
  12873. function list(items) {
  12874. var l, j, key, k, col;
  12875. for (key in items) { // iterate
  12876. if (items.hasOwnProperty(key)) {
  12877. // write amount of spaces according to level
  12878. // and write name and newline
  12879. if(typeof items[key] !== "object") {
  12880. // If not a object build the header of the appropriate level
  12881. if( key === 'level') {
  12882. if(lastval[items.level] === undefined) {
  12883. lastval[items.level] ='';
  12884. if(items.level>0 && items.text !== '_r_Totals') {
  12885. headers[items.level-1] = {
  12886. useColSpanStyle: false,
  12887. groupHeaders: []
  12888. };
  12889. }
  12890. }
  12891. if(lastval[items.level] !== items.text && items.children.length && items.text !== '_r_Totals') {
  12892. if(items.level>0) {
  12893. headers[items.level-1].groupHeaders.push({
  12894. titleText: items.text
  12895. });
  12896. var collen = headers[items.level-1].groupHeaders.length,
  12897. colpos = collen === 1 ? swaplen : initColLen+(collen-1)*aggrlen;
  12898. headers[items.level-1].groupHeaders[collen-1].startColumnName = columns[colpos].name;
  12899. headers[items.level-1].groupHeaders[collen-1].numberOfColumns = columns.length - colpos;
  12900. initColLen = columns.length;
  12901. }
  12902. }
  12903. lastval[items.level] = items.text;
  12904. }
  12905. // This is in case when the member contain more than one summary item
  12906. if(items.level === ylen && key==='level' && ylen >0) {
  12907. if( aggrlen > 1){
  12908. var ll=1;
  12909. for( l in items.fields) {
  12910. if(ll===1) {
  12911. headers[ylen-1].groupHeaders.push({startColumnName: l, numberOfColumns: 1, titleText: items.text});
  12912. }
  12913. ll++;
  12914. }
  12915. headers[ylen-1].groupHeaders[headers[ylen-1].groupHeaders.length-1].numberOfColumns = ll-1;
  12916. } else {
  12917. headers.splice(ylen-1,1);
  12918. }
  12919. }
  12920. }
  12921. // if object, call recursively
  12922. if (items[key] != null && typeof items[key] === "object") {
  12923. list(items[key]);
  12924. }
  12925. // Finally build the coulumns
  12926. if( key === 'level') {
  12927. if(items.level >0){
  12928. j=0;
  12929. for(l in items.fields) {
  12930. col = {};
  12931. for(k in o.aggregates[j]) {
  12932. if(o.aggregates[j].hasOwnProperty(k)) {
  12933. switch( k ) {
  12934. case 'member':
  12935. case 'label':
  12936. case 'aggregator':
  12937. break;
  12938. default:
  12939. col[k] = o.aggregates[j][k];
  12940. }
  12941. }
  12942. }
  12943. if(aggrlen>1) {
  12944. col.name = l;
  12945. col.label = o.aggregates[j].label || l;
  12946. } else {
  12947. col.name = items.text;
  12948. col.label = items.text==='_r_Totals' ? o.rowTotalsText : items.text;
  12949. }
  12950. columns.push (col);
  12951. j++;
  12952. }
  12953. }
  12954. }
  12955. }
  12956. }
  12957. }
  12958. list(tree, 0);
  12959. var nm;
  12960. // loop again trougth the pivot rows in order to build grand total
  12961. if(o.colTotals) {
  12962. var plen = pivotrows.length;
  12963. while(plen--) {
  12964. for(i=xlen;i<columns.length;i++) {
  12965. nm = columns[i].name;
  12966. if(!summaries[nm]) {
  12967. summaries[nm] = parseFloat(pivotrows[plen][nm] || 0);
  12968. } else {
  12969. summaries[nm] += parseFloat(pivotrows[plen][nm] || 0);
  12970. }
  12971. }
  12972. }
  12973. }
  12974. // based on xDimension levels build grouping
  12975. if( groupfields > 0) {
  12976. for(i=0;i<groupfields;i++) {
  12977. groupOptions.groupingView.groupField[i] = columns[i].name;
  12978. groupOptions.groupingView.groupSummary[i] = o.groupSummary;
  12979. groupOptions.groupingView.groupSummaryPos[i] = o.groupSummaryPos;
  12980. }
  12981. } else {
  12982. // no grouping is needed
  12983. groupOptions.grouping = false;
  12984. }
  12985. groupOptions.sortname = columns[groupfields].name;
  12986. groupOptions.groupingView.hideFirstGroupCol = true;
  12987. });
  12988. // return the final result.
  12989. return { "colModel" : columns, "rows": pivotrows, "groupOptions" : groupOptions, "groupHeaders" : headers, summary : summaries };
  12990. },
  12991. jqPivot : function( data, pivotOpt, gridOpt, ajaxOpt) {
  12992. return this.each(function(){
  12993. var $t = this;
  12994. function pivot( data) {
  12995. var pivotGrid = jQuery($t).jqGrid('pivotSetup',data, pivotOpt),
  12996. footerrow = $.assocArraySize(pivotGrid.summary) > 0 ? true : false,
  12997. query= $.jgrid.from(pivotGrid.rows), i;
  12998. for(i=0; i< pivotGrid.groupOptions.groupingView.groupField.length; i++) {
  12999. query.orderBy(pivotGrid.groupOptions.groupingView.groupField[i], "a", 'text', '');
  13000. }
  13001. jQuery($t).jqGrid($.extend({
  13002. datastr: $.extend(query.select(),footerrow ? {userdata:pivotGrid.summary} : {}),
  13003. datatype: "jsonstring",
  13004. footerrow : footerrow,
  13005. userDataOnFooter: footerrow,
  13006. colModel: pivotGrid.colModel,
  13007. viewrecords: true,
  13008. sortname: pivotOpt.xDimension[0].dataName // ?????
  13009. }, gridOpt || {}, pivotGrid.groupOptions));
  13010. var gHead = pivotGrid.groupHeaders;
  13011. if(gHead.length) {
  13012. for( i = 0;i < gHead.length ; i++) {
  13013. if(gHead[i] && gHead[i].groupHeaders.length) {
  13014. jQuery($t).jqGrid('setGroupHeaders',gHead[i]);
  13015. }
  13016. }
  13017. }
  13018. if(pivotOpt.frozenStaticCols) {
  13019. jQuery($t).jqGrid("setFrozenColumns");
  13020. }
  13021. }
  13022. if(typeof data === "string") {
  13023. $.ajax($.extend({
  13024. url : data,
  13025. dataType: 'json',
  13026. success : function(response) {
  13027. pivot($.jgrid.getAccessor(response, ajaxOpt && ajaxOpt.reader ? ajaxOpt.reader: 'rows') );
  13028. }
  13029. }, ajaxOpt || {}) );
  13030. } else {
  13031. pivot( data );
  13032. }
  13033. });
  13034. }
  13035. });
  13036. })(jQuery);