jqGrid.js 486 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345
  1. // ==ClosureCompiler==
  2. // @compilation_level SIMPLE_OPTIMIZATIONS
  3. /**
  4. * http://blog.mn886.net/jqGrid/
  5. * @license jqGrid 4.6.0 - jQuery Grid
  6. * Copyright (c) 2008, Tony Tomov, tony@trirand.com
  7. * Dual licensed under the MIT and GPL licenses
  8. * http://www.opensource.org/licenses/mit-license.php
  9. * http://www.gnu.org/licenses/gpl-2.0.html
  10. * Date: 2014-02-20
  11. */
  12. //jsHint options
  13. /*jshint evil:true, eqeqeq:false, eqnull:true, devel:true */
  14. /*global jQuery */
  15. (function ($) {
  16. "use strict";
  17. $.jgrid = $.jgrid || {};
  18. $.extend($.jgrid,{
  19. version : "4.6.0",
  20. htmlDecode : function(value){
  21. if(value && (value===' ' || value===' ' || (value.length===1 && value.charCodeAt(0)===160))) { return "";}
  22. return !value ? value : String(value).replace(/&gt;/g, ">").replace(/&lt;/g, "<").replace(/&quot;/g, '"').replace(/&amp;/g, "&");
  23. },
  24. htmlEncode : function (value){
  25. return !value ? value : String(value).replace(/&/g, "&amp;").replace(/\"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
  26. },
  27. format : function(format){ //jqgformat
  28. var args = $.makeArray(arguments).slice(1);
  29. if(format==null) { format = ""; }
  30. return format.replace(/\{(\d+)\}/g, function(m, i){
  31. return args[i];
  32. });
  33. },
  34. msie : navigator.appName === 'Microsoft Internet Explorer',
  35. msiever : function () {
  36. var rv = -1;
  37. var ua = navigator.userAgent;
  38. var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
  39. if (re.exec(ua) != null) {
  40. rv = parseFloat( RegExp.$1 );
  41. }
  42. return rv;
  43. },
  44. getCellIndex : function (cell) {
  45. var c = $(cell);
  46. if (c.is('tr')) { return -1; }
  47. c = (!c.is('td') && !c.is('th') ? c.closest("td,th") : c)[0];
  48. if ($.jgrid.msie) { return $.inArray(c, c.parentNode.cells); }
  49. return c.cellIndex;
  50. },
  51. stripHtml : function(v) {
  52. v = String(v);
  53. var regexp = /<("[^"]*"|'[^']*'|[^'">])*>/gi;
  54. if (v) {
  55. v = v.replace(regexp,"");
  56. return (v && v !== '&nbsp;' && v !== '&#160;') ? v.replace(/\"/g,"'") : "";
  57. }
  58. return v;
  59. },
  60. stripPref : function (pref, id) {
  61. var obj = $.type( pref );
  62. if( obj === "string" || obj === "number") {
  63. pref = String(pref);
  64. id = pref !== "" ? String(id).replace(String(pref), "") : id;
  65. }
  66. return id;
  67. },
  68. parse : function(jsonString) {
  69. var js = jsonString;
  70. if (js.substr(0,9) === "while(1);") { js = js.substr(9); }
  71. if (js.substr(0,2) === "/*") { js = js.substr(2,js.length-4); }
  72. if(!js) { js = "{}"; }
  73. return ($.jgrid.useJSON===true && typeof JSON === 'object' && typeof JSON.parse === 'function') ?
  74. JSON.parse(js) :
  75. eval('(' + js + ')');
  76. },
  77. parseDate : function(format, date, newformat, opts) {
  78. var token = /\\.|[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]/g,
  79. timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
  80. timezoneClip = /[^-+\dA-Z]/g,
  81. msDateRegExp = new RegExp("^\/Date\\((([-+])?[0-9]+)(([-+])([0-9]{2})([0-9]{2}))?\\)\/$"),
  82. msMatch = ((typeof date === 'string') ? date.match(msDateRegExp): null),
  83. pad = function (value, length) {
  84. value = String(value);
  85. length = parseInt(length,10) || 2;
  86. while (value.length < length) { value = '0' + value; }
  87. return value;
  88. },
  89. ts = {m : 1, d : 1, y : 1970, h : 0, i : 0, s : 0, u:0},
  90. timestamp=0, dM, k,hl,
  91. h12to24 = function(ampm, h){
  92. if (ampm === 0){ if (h === 12) { h = 0;} }
  93. else { if (h !== 12) { h += 12; } }
  94. return h;
  95. };
  96. if(opts === undefined) {
  97. opts = $.jgrid.formatter.date;
  98. }
  99. // old lang files
  100. if(opts.parseRe === undefined ) {
  101. opts.parseRe = /[#%\\\/:_;.,\t\s-]/;
  102. }
  103. if( opts.masks.hasOwnProperty(format) ) { format = opts.masks[format]; }
  104. if(date && date != null) {
  105. if( !isNaN( date - 0 ) && String(format).toLowerCase() === "u") {
  106. //Unix timestamp
  107. timestamp = new Date( parseFloat(date)*1000 );
  108. } else if(date.constructor === Date) {
  109. timestamp = date;
  110. // Microsoft date format support
  111. } else if( msMatch !== null ) {
  112. timestamp = new Date(parseInt(msMatch[1], 10));
  113. if (msMatch[3]) {
  114. var offset = Number(msMatch[5]) * 60 + Number(msMatch[6]);
  115. offset *= ((msMatch[4] === '-') ? 1 : -1);
  116. offset -= timestamp.getTimezoneOffset();
  117. timestamp.setTime(Number(Number(timestamp) + (offset * 60 * 1000)));
  118. }
  119. } else {
  120. var offset = 0;
  121. //Support ISO8601Long that have Z at the end to indicate UTC timezone
  122. if(opts.srcformat === 'ISO8601Long' && date.charAt(date.length - 1) === 'Z') {
  123. offset -= (new Date()).getTimezoneOffset();
  124. }
  125. date = String(date).replace(/\T/g,"#").replace(/\t/,"%").split(opts.parseRe);
  126. format = format.replace(/\T/g,"#").replace(/\t/,"%").split(opts.parseRe);
  127. // parsing for month names
  128. for(k=0,hl=format.length;k<hl;k++){
  129. if(format[k] === 'M') {
  130. dM = $.inArray(date[k],opts.monthNames);
  131. if(dM !== -1 && dM < 12){date[k] = dM+1; ts.m = date[k];}
  132. }
  133. if(format[k] === 'F') {
  134. dM = $.inArray(date[k],opts.monthNames,12);
  135. if(dM !== -1 && dM > 11){date[k] = dM+1-12; ts.m = date[k];}
  136. }
  137. if(format[k] === 'a') {
  138. dM = $.inArray(date[k],opts.AmPm);
  139. if(dM !== -1 && dM < 2 && date[k] === opts.AmPm[dM]){
  140. date[k] = dM;
  141. ts.h = h12to24(date[k], ts.h);
  142. }
  143. }
  144. if(format[k] === 'A') {
  145. dM = $.inArray(date[k],opts.AmPm);
  146. if(dM !== -1 && dM > 1 && date[k] === opts.AmPm[dM]){
  147. date[k] = dM-2;
  148. ts.h = h12to24(date[k], ts.h);
  149. }
  150. }
  151. if (format[k] === 'g') {
  152. ts.h = parseInt(date[k], 10);
  153. }
  154. if(date[k] !== undefined) {
  155. ts[format[k].toLowerCase()] = parseInt(date[k],10);
  156. }
  157. }
  158. if(ts.f) {ts.m = ts.f;}
  159. if( ts.m === 0 && ts.y === 0 && ts.d === 0) {
  160. return "&#160;" ;
  161. }
  162. ts.m = parseInt(ts.m,10)-1;
  163. var ty = ts.y;
  164. if (ty >= 70 && ty <= 99) {ts.y = 1900+ts.y;}
  165. else if (ty >=0 && ty <=69) {ts.y= 2000+ts.y;}
  166. timestamp = new Date(ts.y, ts.m, ts.d, ts.h, ts.i, ts.s, ts.u);
  167. //Apply offset to show date as local time.
  168. if(offset > 0) {
  169. timestamp.setTime(Number(Number(timestamp) + (offset * 60 * 1000)));
  170. }
  171. }
  172. } else {
  173. timestamp = new Date(ts.y, ts.m, ts.d, ts.h, ts.i, ts.s, ts.u);
  174. }
  175. if( newformat === undefined ) {
  176. return timestamp;
  177. }
  178. if( opts.masks.hasOwnProperty(newformat) ) {
  179. newformat = opts.masks[newformat];
  180. } else if ( !newformat ) {
  181. newformat = 'Y-m-d';
  182. }
  183. var
  184. G = timestamp.getHours(),
  185. i = timestamp.getMinutes(),
  186. j = timestamp.getDate(),
  187. n = timestamp.getMonth() + 1,
  188. o = timestamp.getTimezoneOffset(),
  189. s = timestamp.getSeconds(),
  190. u = timestamp.getMilliseconds(),
  191. w = timestamp.getDay(),
  192. Y = timestamp.getFullYear(),
  193. N = (w + 6) % 7 + 1,
  194. z = (new Date(Y, n - 1, j) - new Date(Y, 0, 1)) / 86400000,
  195. flags = {
  196. // Day
  197. d: pad(j),
  198. D: opts.dayNames[w],
  199. j: j,
  200. l: opts.dayNames[w + 7],
  201. N: N,
  202. S: opts.S(j),
  203. //j < 11 || j > 13 ? ['st', 'nd', 'rd', 'th'][Math.min((j - 1) % 10, 3)] : 'th',
  204. w: w,
  205. z: z,
  206. // Week
  207. 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),
  208. // Month
  209. F: opts.monthNames[n - 1 + 12],
  210. m: pad(n),
  211. M: opts.monthNames[n - 1],
  212. n: n,
  213. t: '?',
  214. // Year
  215. L: '?',
  216. o: '?',
  217. Y: Y,
  218. y: String(Y).substring(2),
  219. // Time
  220. a: G < 12 ? opts.AmPm[0] : opts.AmPm[1],
  221. A: G < 12 ? opts.AmPm[2] : opts.AmPm[3],
  222. B: '?',
  223. g: G % 12 || 12,
  224. G: G,
  225. h: pad(G % 12 || 12),
  226. H: pad(G),
  227. i: pad(i),
  228. s: pad(s),
  229. u: u,
  230. // Timezone
  231. e: '?',
  232. I: '?',
  233. O: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
  234. P: '?',
  235. T: (String(timestamp).match(timezone) || [""]).pop().replace(timezoneClip, ""),
  236. Z: '?',
  237. // Full Date/Time
  238. c: '?',
  239. r: '?',
  240. U: Math.floor(timestamp / 1000)
  241. };
  242. return newformat.replace(token, function ($0) {
  243. return flags.hasOwnProperty($0) ? flags[$0] : $0.substring(1);
  244. });
  245. },
  246. jqID : function(sid){
  247. return String(sid).replace(/[!"#$%&'()*+,.\/:; <=>?@\[\\\]\^`{|}~]/g,"\\$&");
  248. },
  249. guid : 1,
  250. uidPref: 'jqg',
  251. randId : function( prefix ) {
  252. return (prefix || $.jgrid.uidPref) + ($.jgrid.guid++);
  253. },
  254. getAccessor : function(obj, expr) {
  255. var ret,p,prm = [], i;
  256. if( typeof expr === 'function') { return expr(obj); }
  257. ret = obj[expr];
  258. if(ret===undefined) {
  259. try {
  260. if ( typeof expr === 'string' ) {
  261. prm = expr.split('.');
  262. }
  263. i = prm.length;
  264. if( i ) {
  265. ret = obj;
  266. while (ret && i--) {
  267. p = prm.shift();
  268. ret = ret[p];
  269. }
  270. }
  271. } catch (e) {}
  272. }
  273. return ret;
  274. },
  275. getXmlData: function (obj, expr, returnObj) {
  276. var ret, m = typeof expr === 'string' ? expr.match(/^(.*)\[(\w+)\]$/) : null;
  277. if (typeof expr === 'function') { return expr(obj); }
  278. if (m && m[2]) {
  279. // m[2] is the attribute selector
  280. // m[1] is an optional element selector
  281. // examples: "[id]", "rows[page]"
  282. return m[1] ? $(m[1], obj).attr(m[2]) : $(obj).attr(m[2]);
  283. }
  284. ret = $(expr, obj);
  285. if (returnObj) { return ret; }
  286. //$(expr, obj).filter(':last'); // we use ':last' to be more compatible with old version of jqGrid
  287. return ret.length > 0 ? $(ret).text() : undefined;
  288. },
  289. cellWidth : function () {
  290. 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>"),
  291. testCell = $testDiv.appendTo("body")
  292. .find("td")
  293. .width();
  294. $testDiv.remove();
  295. return Math.abs(testCell-5) > 0.1;
  296. },
  297. cell_width : true,
  298. ajaxOptions: {},
  299. from : function(source){
  300. // Original Author Hugo Bonacci
  301. // License MIT http://jlinq.codeplex.com/license
  302. var QueryObject=function(d,q){
  303. if(typeof d==="string"){
  304. d=$.data(d);
  305. }
  306. var self=this,
  307. _data=d,
  308. _usecase=true,
  309. _trim=false,
  310. _query=q,
  311. _stripNum = /[\$,%]/g,
  312. _lastCommand=null,
  313. _lastField=null,
  314. _orDepth=0,
  315. _negate=false,
  316. _queuedOperator="",
  317. _sorting=[],
  318. _useProperties=true;
  319. if(typeof d==="object"&&d.push) {
  320. if(d.length>0){
  321. if(typeof d[0]!=="object"){
  322. _useProperties=false;
  323. }else{
  324. _useProperties=true;
  325. }
  326. }
  327. }else{
  328. throw "data provides is not an array";
  329. }
  330. this._hasData=function(){
  331. return _data===null?false:_data.length===0?false:true;
  332. };
  333. this._getStr=function(s){
  334. var phrase=[];
  335. if(_trim){
  336. phrase.push("jQuery.trim(");
  337. }
  338. phrase.push("String("+s+")");
  339. if(_trim){
  340. phrase.push(")");
  341. }
  342. if(!_usecase){
  343. phrase.push(".toLowerCase()");
  344. }
  345. return phrase.join("");
  346. };
  347. this._strComp=function(val){
  348. if(typeof val==="string"){
  349. return".toString()";
  350. }
  351. return"";
  352. };
  353. this._group=function(f,u){
  354. return({field:f.toString(),unique:u,items:[]});
  355. };
  356. this._toStr=function(phrase){
  357. if(_trim){
  358. phrase=$.trim(phrase);
  359. }
  360. phrase=phrase.toString().replace(/\\/g,'\\\\').replace(/\"/g,'\\"');
  361. return _usecase ? phrase : phrase.toLowerCase();
  362. };
  363. this._funcLoop=function(func){
  364. var results=[];
  365. $.each(_data,function(i,v){
  366. results.push(func(v));
  367. });
  368. return results;
  369. };
  370. this._append=function(s){
  371. var i;
  372. if(_query===null){
  373. _query="";
  374. } else {
  375. _query+=_queuedOperator === "" ? " && " :_queuedOperator;
  376. }
  377. for (i=0;i<_orDepth;i++){
  378. _query+="(";
  379. }
  380. if(_negate){
  381. _query+="!";
  382. }
  383. _query+="("+s+")";
  384. _negate=false;
  385. _queuedOperator="";
  386. _orDepth=0;
  387. };
  388. this._setCommand=function(f,c){
  389. _lastCommand=f;
  390. _lastField=c;
  391. };
  392. this._resetNegate=function(){
  393. _negate=false;
  394. };
  395. this._repeatCommand=function(f,v){
  396. if(_lastCommand===null){
  397. return self;
  398. }
  399. if(f!==null&&v!==null){
  400. return _lastCommand(f,v);
  401. }
  402. if(_lastField===null){
  403. return _lastCommand(f);
  404. }
  405. if(!_useProperties){
  406. return _lastCommand(f);
  407. }
  408. return _lastCommand(_lastField,f);
  409. };
  410. this._equals=function(a,b){
  411. return(self._compare(a,b,1)===0);
  412. };
  413. this._compare=function(a,b,d){
  414. var toString = Object.prototype.toString;
  415. if( d === undefined) { d = 1; }
  416. if(a===undefined) { a = null; }
  417. if(b===undefined) { b = null; }
  418. if(a===null && b===null){
  419. return 0;
  420. }
  421. if(a===null&&b!==null){
  422. return 1;
  423. }
  424. if(a!==null&&b===null){
  425. return -1;
  426. }
  427. if (toString.call(a) === '[object Date]' && toString.call(b) === '[object Date]') {
  428. if (a < b) { return -d; }
  429. if (a > b) { return d; }
  430. return 0;
  431. }
  432. if(!_usecase && typeof a !== "number" && typeof b !== "number" ) {
  433. a=String(a);
  434. b=String(b);
  435. }
  436. if(a<b){return -d;}
  437. if(a>b){return d;}
  438. return 0;
  439. };
  440. this._performSort=function(){
  441. if(_sorting.length===0){return;}
  442. _data=self._doSort(_data,0);
  443. };
  444. this._doSort=function(d,q){
  445. var by=_sorting[q].by,
  446. dir=_sorting[q].dir,
  447. type = _sorting[q].type,
  448. dfmt = _sorting[q].datefmt,
  449. sfunc = _sorting[q].sfunc;
  450. if(q===_sorting.length-1){
  451. return self._getOrder(d, by, dir, type, dfmt, sfunc);
  452. }
  453. q++;
  454. var values=self._getGroup(d,by,dir,type,dfmt), results=[], i, j, sorted;
  455. for(i=0;i<values.length;i++){
  456. sorted=self._doSort(values[i].items,q);
  457. for(j=0;j<sorted.length;j++){
  458. results.push(sorted[j]);
  459. }
  460. }
  461. return results;
  462. };
  463. this._getOrder=function(data,by,dir,type, dfmt, sfunc){
  464. var sortData=[],_sortData=[], newDir = dir==="a" ? 1 : -1, i,ab,j,
  465. findSortKey;
  466. if(type === undefined ) { type = "text"; }
  467. if (type === 'float' || type=== 'number' || type=== 'currency' || type=== 'numeric') {
  468. findSortKey = function($cell) {
  469. var key = parseFloat( String($cell).replace(_stripNum, ''));
  470. return isNaN(key) ? Number.NEGATIVE_INFINITY : key;
  471. };
  472. } else if (type==='int' || type==='integer') {
  473. findSortKey = function($cell) {
  474. return $cell ? parseFloat(String($cell).replace(_stripNum, '')) : Number.NEGATIVE_INFINITY;
  475. };
  476. } else if(type === 'date' || type === 'datetime') {
  477. findSortKey = function($cell) {
  478. return $.jgrid.parseDate(dfmt,$cell).getTime();
  479. };
  480. } else if($.isFunction(type)) {
  481. findSortKey = type;
  482. } else {
  483. findSortKey = function($cell) {
  484. $cell = $cell ? $.trim(String($cell)) : "";
  485. return _usecase ? $cell : $cell.toLowerCase();
  486. };
  487. }
  488. $.each(data,function(i,v){
  489. ab = by!=="" ? $.jgrid.getAccessor(v,by) : v;
  490. if(ab === undefined) { ab = ""; }
  491. ab = findSortKey(ab, v);
  492. _sortData.push({ 'vSort': ab,'index':i});
  493. });
  494. if($.isFunction(sfunc)) {
  495. _sortData.sort(function(a,b){
  496. a = a.vSort;
  497. b = b.vSort;
  498. return sfunc.call(this,a,b,newDir);
  499. });
  500. } else {
  501. _sortData.sort(function(a,b){
  502. a = a.vSort;
  503. b = b.vSort;
  504. return self._compare(a,b,newDir);
  505. });
  506. }
  507. j=0;
  508. var nrec= data.length;
  509. // overhead, but we do not change the original data.
  510. while(j<nrec) {
  511. i = _sortData[j].index;
  512. sortData.push(data[i]);
  513. j++;
  514. }
  515. return sortData;
  516. };
  517. this._getGroup=function(data,by,dir,type, dfmt){
  518. var results=[],
  519. group=null,
  520. last=null, val;
  521. $.each(self._getOrder(data,by,dir,type, dfmt),function(i,v){
  522. val = $.jgrid.getAccessor(v, by);
  523. if(val == null) { val = ""; }
  524. if(!self._equals(last,val)){
  525. last=val;
  526. if(group !== null){
  527. results.push(group);
  528. }
  529. group=self._group(by,val);
  530. }
  531. group.items.push(v);
  532. });
  533. if(group !== null){
  534. results.push(group);
  535. }
  536. return results;
  537. };
  538. this.ignoreCase=function(){
  539. _usecase=false;
  540. return self;
  541. };
  542. this.useCase=function(){
  543. _usecase=true;
  544. return self;
  545. };
  546. this.trim=function(){
  547. _trim=true;
  548. return self;
  549. };
  550. this.noTrim=function(){
  551. _trim=false;
  552. return self;
  553. };
  554. this.execute=function(){
  555. var match=_query, results=[];
  556. if(match === null){
  557. return self;
  558. }
  559. $.each(_data,function(){
  560. if(eval(match)){results.push(this);}
  561. });
  562. _data=results;
  563. return self;
  564. };
  565. this.data=function(){
  566. return _data;
  567. };
  568. this.select=function(f){
  569. self._performSort();
  570. if(!self._hasData()){ return[]; }
  571. self.execute();
  572. if($.isFunction(f)){
  573. var results=[];
  574. $.each(_data,function(i,v){
  575. results.push(f(v));
  576. });
  577. return results;
  578. }
  579. return _data;
  580. };
  581. this.hasMatch=function(){
  582. if(!self._hasData()) { return false; }
  583. self.execute();
  584. return _data.length>0;
  585. };
  586. this.andNot=function(f,v,x){
  587. _negate=!_negate;
  588. return self.and(f,v,x);
  589. };
  590. this.orNot=function(f,v,x){
  591. _negate=!_negate;
  592. return self.or(f,v,x);
  593. };
  594. this.not=function(f,v,x){
  595. return self.andNot(f,v,x);
  596. };
  597. this.and=function(f,v,x){
  598. _queuedOperator=" && ";
  599. if(f===undefined){
  600. return self;
  601. }
  602. return self._repeatCommand(f,v,x);
  603. };
  604. this.or=function(f,v,x){
  605. _queuedOperator=" || ";
  606. if(f===undefined) { return self; }
  607. return self._repeatCommand(f,v,x);
  608. };
  609. this.orBegin=function(){
  610. _orDepth++;
  611. return self;
  612. };
  613. this.orEnd=function(){
  614. if (_query !== null){
  615. _query+=")";
  616. }
  617. return self;
  618. };
  619. this.isNot=function(f){
  620. _negate=!_negate;
  621. return self.is(f);
  622. };
  623. this.is=function(f){
  624. self._append('this.'+f);
  625. self._resetNegate();
  626. return self;
  627. };
  628. this._compareValues=function(func,f,v,how,t){
  629. var fld;
  630. if(_useProperties){
  631. fld='jQuery.jgrid.getAccessor(this,\''+f+'\')';
  632. }else{
  633. fld='this';
  634. }
  635. if(v===undefined) { v = null; }
  636. //var val=v===null?f:v,
  637. var val =v,
  638. swst = t.stype === undefined ? "text" : t.stype;
  639. if(v !== null) {
  640. switch(swst) {
  641. case 'int':
  642. case 'integer':
  643. val = (isNaN(Number(val)) || val==="") ? '0' : val; // To be fixed with more inteligent code
  644. fld = 'parseInt('+fld+',10)';
  645. val = 'parseInt('+val+',10)';
  646. break;
  647. case 'float':
  648. case 'number':
  649. case 'numeric':
  650. val = String(val).replace(_stripNum, '');
  651. val = (isNaN(Number(val)) || val==="") ? '0' : val; // To be fixed with more inteligent code
  652. fld = 'parseFloat('+fld+')';
  653. val = 'parseFloat('+val+')';
  654. break;
  655. case 'date':
  656. case 'datetime':
  657. val = String($.jgrid.parseDate(t.newfmt || 'Y-m-d',val).getTime());
  658. fld = 'jQuery.jgrid.parseDate("'+t.srcfmt+'",'+fld+').getTime()';
  659. break;
  660. default :
  661. fld=self._getStr(fld);
  662. val=self._getStr('"'+self._toStr(val)+'"');
  663. }
  664. }
  665. self._append(fld+' '+how+' '+val);
  666. self._setCommand(func,f);
  667. self._resetNegate();
  668. return self;
  669. };
  670. this.equals=function(f,v,t){
  671. return self._compareValues(self.equals,f,v,"==",t);
  672. };
  673. this.notEquals=function(f,v,t){
  674. return self._compareValues(self.equals,f,v,"!==",t);
  675. };
  676. this.isNull = function(f,v,t){
  677. return self._compareValues(self.equals,f,null,"===",t);
  678. };
  679. this.greater=function(f,v,t){
  680. return self._compareValues(self.greater,f,v,">",t);
  681. };
  682. this.less=function(f,v,t){
  683. return self._compareValues(self.less,f,v,"<",t);
  684. };
  685. this.greaterOrEquals=function(f,v,t){
  686. return self._compareValues(self.greaterOrEquals,f,v,">=",t);
  687. };
  688. this.lessOrEquals=function(f,v,t){
  689. return self._compareValues(self.lessOrEquals,f,v,"<=",t);
  690. };
  691. this.startsWith=function(f,v){
  692. var val = (v==null) ? f: v,
  693. length=_trim ? $.trim(val.toString()).length : val.toString().length;
  694. if(_useProperties){
  695. self._append(self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.substr(0,'+length+') == '+self._getStr('"'+self._toStr(v)+'"'));
  696. }else{
  697. if (v!=null) { length=_trim?$.trim(v.toString()).length:v.toString().length; }
  698. self._append(self._getStr('this')+'.substr(0,'+length+') == '+self._getStr('"'+self._toStr(f)+'"'));
  699. }
  700. self._setCommand(self.startsWith,f);
  701. self._resetNegate();
  702. return self;
  703. };
  704. this.endsWith=function(f,v){
  705. var val = (v==null) ? f: v,
  706. length=_trim ? $.trim(val.toString()).length:val.toString().length;
  707. if(_useProperties){
  708. self._append(self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.substr('+self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.length-'+length+','+length+') == "'+self._toStr(v)+'"');
  709. } else {
  710. self._append(self._getStr('this')+'.substr('+self._getStr('this')+'.length-"'+self._toStr(f)+'".length,"'+self._toStr(f)+'".length) == "'+self._toStr(f)+'"');
  711. }
  712. self._setCommand(self.endsWith,f);self._resetNegate();
  713. return self;
  714. };
  715. this.contains=function(f,v){
  716. if(_useProperties){
  717. self._append(self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.indexOf("'+self._toStr(v)+'",0) > -1');
  718. }else{
  719. self._append(self._getStr('this')+'.indexOf("'+self._toStr(f)+'",0) > -1');
  720. }
  721. self._setCommand(self.contains,f);
  722. self._resetNegate();
  723. return self;
  724. };
  725. this.groupBy=function(by,dir,type, datefmt){
  726. if(!self._hasData()){
  727. return null;
  728. }
  729. return self._getGroup(_data,by,dir,type, datefmt);
  730. };
  731. this.orderBy=function(by,dir,stype, dfmt, sfunc){
  732. dir = dir == null ? "a" :$.trim(dir.toString().toLowerCase());
  733. if(stype == null) { stype = "text"; }
  734. if(dfmt == null) { dfmt = "Y-m-d"; }
  735. if(sfunc == null) { sfunc = false; }
  736. if(dir==="desc"||dir==="descending"){dir="d";}
  737. if(dir==="asc"||dir==="ascending"){dir="a";}
  738. _sorting.push({by:by,dir:dir,type:stype, datefmt: dfmt, sfunc: sfunc});
  739. return self;
  740. };
  741. return self;
  742. };
  743. return new QueryObject(source,null);
  744. },
  745. getMethod: function (name) {
  746. return this.getAccessor($.fn.jqGrid, name);
  747. },
  748. extend : function(methods) {
  749. $.extend($.fn.jqGrid,methods);
  750. if (!this.no_legacy_api) {
  751. $.fn.extend(methods);
  752. }
  753. }
  754. });
  755. $.fn.jqGrid = function( pin ) {
  756. if (typeof pin === 'string') {
  757. var fn = $.jgrid.getMethod(pin);
  758. if (!fn) {
  759. throw ("jqGrid - No such method: " + pin);
  760. }
  761. var args = $.makeArray(arguments).slice(1);
  762. return fn.apply(this,args);
  763. }
  764. return this.each( function() {
  765. if(this.grid) {return;}
  766. var listId=pin.confid;
  767. //alert(JSON.stringify(pin) );
  768. var p = $.extend(true,{
  769. url: "",
  770. height: 150,
  771. page: 1,
  772. rowNum: 20,//一页显示多少条
  773. rowTotal : null,
  774. records: 0,
  775. pager: "",
  776. pgbuttons: true,
  777. pginput: true,
  778. colModel: [],
  779. rowList:[5,10,20,50,100],
  780. colNames: [],
  781. sortorder: "asc",
  782. sortname: "",
  783. datatype: "json",
  784. mtype: "GET",
  785. altRows: false,
  786. selarrrow: [],
  787. savedRow: [],
  788. shrinkToFit: true,
  789. xmlReader: {},
  790. jsonReader : {
  791. root: "rows", // json中代表实际模型数据的入口
  792. page: "page", // json中代表当前页码的数据
  793. total: "totalPage", // json中代表页码总数的数据
  794. records: "records", // json中代表数据行总数的数据
  795. id:pin.primaryId,
  796. subs:"subs",
  797. repeatitems: true // 如果设为false,则jqGrid在解析json时,会根据name来搜索对应的数据元素(即可以json中元素可以不按顺序);而所使用的name是来自于colModel中的name设定。
  798. },
  799. subGrid: false,
  800. subGridModel :[],
  801. reccount: 0,
  802. lastpage: 0,
  803. lastsort: 0,
  804. selrow: null,
  805. beforeSelectRow: null,
  806. onSelectRow:function(rowid, status) {
  807. if(ts.p.multiselect){
  808. //如果选中,则判断数组中如果没有的话加入数组
  809. var ia = $.inArray(rowid,ts.p.checkArray);
  810. if (status) { // 每一次取消选中时,将该行id添加到SelectList中
  811. if(ia<0){
  812. ts.p.checkArray.push(rowid);
  813. //同步选择项到数据库
  814. if(ts.p.mutldb){
  815. setCheckBoxDb(ts.p.mutldbId,rowid,true);
  816. }
  817. }
  818. } else {
  819. if(ia>-1){
  820. ts.p.checkArray.splice(ia,1);
  821. //同步选择项到数据库
  822. if(ts.p.mutldb){
  823. setCheckBoxDb(ts.p.mutldbId,rowid,false);
  824. }
  825. }
  826. }
  827. ts.p.selarrrow=ts.p.checkArray;
  828. }
  829. callEvent(listId+"_onSelectRow");},
  830. onSortCol: null,
  831. ondblClickRow:function(id) {
  832. var rowData = $("#"+listId).jqGrid("getRowData", id);
  833. // colModel
  834. $("#"+listId).jqGrid('editRow',id,{
  835. keys : true, //这里按[enter]保存
  836. url: "jq/save.action",
  837. mtype : "POST",
  838. restoreAfterError: true,
  839. extraparam: {
  840. "ware.id": rowData.id,
  841. "ware.warename": $("#"+id+"_name").val(),
  842. "ware.createDate": $("#"+id+"_date").val(),
  843. "ware.number": $("#"+id+"_amount").val(),
  844. "ware.valid": $("#"+id+"_type").val()
  845. },
  846. oneditfunc: function(rowid){
  847. //alert("oneditfunc");
  848. },
  849. succesfunc: function(response){
  850. alert("save success");
  851. return true;
  852. },
  853. errorfunc: function(rowid, res){
  854. //alert(rowid);
  855. }
  856. });
  857. callEvent(listId+"_ondblClickRow");}, // 定义事件 ,
  858. onRightClickRow: null,
  859. onPaging: null,
  860. onSelectAll:function(rowIds,status) {
  861. if(ts.p.multiselect){
  862. //如果是选择的选中,则把当页所有条目加上
  863. if(status){
  864. for(var i=0;i<rowIds.length;i++){
  865. var ia = $.inArray(rowIds[i],ts.p.checkArray);
  866. if(ia<0){
  867. ts.p.checkArray.push(rowIds[i]);
  868. }
  869. }
  870. //后台,同步选择项到数据库
  871. if(ts.p.mutldb){
  872. new Service({
  873. serviceId:"mutlSelectService",
  874. method:"addBatch",
  875. parameters:{TABLE_NAME:"fw_mutl_select",ID:ts.p.mutldbId,VALUES:rowIds}
  876. }).sentAjax('同步选择项到数据库',function(data){
  877. });
  878. }
  879. }else{
  880. //checkArray数组中把当页的全删除
  881. for(var i=0;i<rowIds.length;i++){
  882. var ia = $.inArray(rowIds[i],ts.p.checkArray);
  883. if(ia>-1){
  884. ts.p.checkArray.splice(ia,1);
  885. }
  886. }
  887. //后台,同步选择项到数据库
  888. if(ts.p.mutldb){
  889. new Service({
  890. serviceId:"mutlSelectService",
  891. method:"delBatch",
  892. parameters:{TABLE_NAME:"fw_mutl_select",ID:opts.mutldbId,VALUES:rowIds}
  893. }).sentAjax('同步选择项到数据库',function(data){
  894. });
  895. }
  896. }
  897. ts.p.selarrrow=ts.p.checkArray;
  898. }
  899. callEvent(listId+"_onSelectAll");},
  900. onInitGrid : function() {
  901. iniDicts(ts.p);
  902. if(ts.p.multiselect){
  903. if(ts.p.checkArray==undefined){
  904. ts.p.checkArray=[];
  905. }
  906. if(ts.p.mutldb){
  907. new Service().appendQuery({
  908. configId:'FW_CONFIG.FW_MUTL_SELECT_SEQ'
  909. }).sentAjax('获取跨页全选同步到数据库表的唯一ID',function(data){
  910. ts.p.mutldbId = data[0][0];
  911. },null,false);
  912. }
  913. }
  914. callEvent(listId+"_onInitGrid");},
  915. loadComplete: function() {
  916. callEvent(listId+"_loadComplete");},
  917. gridComplete: function() {
  918. if(ts.p.multiselect){
  919. var rowIds = $("#"+listId).jqGrid('getDataIDs');
  920. if(ts.p.checkArray.length>0){
  921. var checkArray=ts.p.checkArray;
  922. var checkboxes = $("tbody :checkbox","#"+listId);
  923. checkboxes.each(function(){
  924. for(var j=0;j<checkArray.length;j++){
  925. var checkID="jqg_"+listId+"_"+checkArray[j];
  926. if(checkID==this.id ){
  927. this.checked = true;
  928. break;
  929. }
  930. }
  931. });
  932. }
  933. ts.p.selarrrow=ts.p.checkArray;
  934. if($("#"+ts.p.configId).data('_allChecked')){
  935. $("#cb_"+ts.p.configId).attr("checked",true);;
  936. }
  937. }
  938. //合计列放在subs
  939. $("#"+listId).footerData('set', ts.p.subs[0]);
  940. callEvent(listId+"_gridComplete");},//当表格所有数据都加载完成而且其他的处理也都完成时触发此事件,排序,翻页同样也会触发此事件
  941. loadError: null,
  942. loadBeforeSend: null,
  943. afterInsertRow: null,
  944. beforeRequest: null,
  945. beforeProcessing : null,
  946. onHeaderClick: null,
  947. viewrecords: true,//是否要显示总记录数
  948. loadonce:false, //一次加载全部数据到客户端,由客户端进行排序。
  949. multiselect: false,//定义是否可以多选
  950. multikey: false,//只有在multiselect设置为ture时起作用,定义使用那个key来做多选。shiftKey,altKey,ctrlKey
  951. editurl: 'clientArray',
  952. search: false,
  953. caption: "",
  954. hidegrid: true,
  955. hiddengrid: false,
  956. postData: {},
  957. userData: {},
  958. treeGrid : false,
  959. treeGridModel : 'nested',
  960. treeReader : {},
  961. treeANode : -1,
  962. ExpandColumn: null,
  963. tree_root_level : 0,
  964. //当参数为null时不会被发到服务器端
  965. prmNames: {page:"page",rows:"rows", sort: "sidx",order: "sord", search:"_search", nd:"nd", id:"id",oper:"operate",editoper:"edit",addoper:"add",deloper:"del", subgridid:"id", npage: null, totalrows:"totalrows"},
  966. forceFit : false,
  967. gridstate : "visible",
  968. cellEdit: false,
  969. cellsubmit: "remote",
  970. nv:0,
  971. loadui: "enable",
  972. toolbar: [false,""],
  973. scroll: false,
  974. multiboxonly : false,//(参数值:true:表示手动点击复选框才会勾选,false:表示选中这一行任意列,则自动勾选),
  975. deselectAfterSort : true,
  976. scrollrows : false,
  977. autowidth: false,
  978. scrollOffset :18,
  979. cellLayout: 5,
  980. subGridWidth: 20,
  981. multiselectWidth: 20,
  982. gridview: false,
  983. rownumWidth: 25,
  984. rownumbers : true,//是否显示序号列 true显示,false不显示
  985. pagerpos: 'center',
  986. recordpos: 'right',
  987. footerrow : false,//分页上添加一行,用于显示统计信息
  988. userDataOnFooter : false,
  989. hoverrows : true,
  990. altclass : 'ui-priority-secondary',
  991. viewsortcols : [false,'vertical',true],
  992. resizeclass : '',
  993. autoencode : false,
  994. remapColumns : [],
  995. ajaxGridOptions :{},
  996. direction : "ltr",
  997. toppager: false,
  998. headertitles: false,
  999. scrollTimeout: 40,
  1000. data : [],
  1001. _index : {},
  1002. grouping : false,
  1003. 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},
  1004. ignoreCase : false,
  1005. cmTemplate : {},
  1006. idPrefix : "",
  1007. multiSort : false,
  1008. minColWidth : 33,
  1009. recordtext : "记录 第{0} 到 {1} 行 | 总记录数 {2}",//显示记录数的格式
  1010. emptyrecords : "无数据",//空记录时的提示信息
  1011. pgtext : "第几页 {0} 总页数 {1}"//页数显示格式
  1012. }, $.jgrid.defaults, pin || {});
  1013. var ts= this, grid={
  1014. headers:[],
  1015. cols:[],
  1016. footers: [],
  1017. dragStart: function(i,x,y) {
  1018. var gridLeftPos = $(this.bDiv).offset().left;
  1019. this.resizing = { idx: i, startX: x.clientX, sOL : x.clientX - gridLeftPos };
  1020. this.hDiv.style.cursor = "col-resize";
  1021. this.curGbox = $("#rs_m"+$.jgrid.jqID(p.id),"#gbox_"+$.jgrid.jqID(p.id));
  1022. this.curGbox.css({display:"block",left:x.clientX-gridLeftPos,top:y[1],height:y[2]});
  1023. $(ts).triggerHandler("jqGridResizeStart", [x, i]);
  1024. if($.isFunction(p.resizeStart)) { p.resizeStart.call(ts,x,i); }
  1025. document.onselectstart=function(){return false;};
  1026. },
  1027. dragMove: function(x) {
  1028. if(this.resizing) {
  1029. var diff = x.clientX-this.resizing.startX,
  1030. h = this.headers[this.resizing.idx],
  1031. newWidth = p.direction === "ltr" ? h.width + diff : h.width - diff, hn, nWn;
  1032. if(newWidth > 33) {
  1033. this.curGbox.css({left:this.resizing.sOL+diff});
  1034. if(p.forceFit===true ){
  1035. hn = this.headers[this.resizing.idx+p.nv];
  1036. nWn = p.direction === "ltr" ? hn.width - diff : hn.width + diff;
  1037. if(nWn > p.minColWidth ) {
  1038. h.newWidth = newWidth;
  1039. hn.newWidth = nWn;
  1040. }
  1041. } else {
  1042. this.newWidth = p.direction === "ltr" ? p.tblwidth+diff : p.tblwidth-diff;
  1043. h.newWidth = newWidth;
  1044. }
  1045. }
  1046. }
  1047. },
  1048. dragEnd: function() {
  1049. this.hDiv.style.cursor = "default";
  1050. if(this.resizing) {
  1051. var idx = this.resizing.idx,
  1052. nw = this.headers[idx].newWidth || this.headers[idx].width;
  1053. nw = parseInt(nw,10);
  1054. this.resizing = false;
  1055. $("#rs_m"+$.jgrid.jqID(p.id)).css("display","none");
  1056. p.colModel[idx].width = nw;
  1057. this.headers[idx].width = nw;
  1058. this.headers[idx].el.style.width = nw + "px";
  1059. this.cols[idx].style.width = nw+"px";
  1060. if(this.footers.length>0) {this.footers[idx].style.width = nw+"px";}
  1061. if(p.forceFit===true){
  1062. nw = this.headers[idx+p.nv].newWidth || this.headers[idx+p.nv].width;
  1063. this.headers[idx+p.nv].width = nw;
  1064. this.headers[idx+p.nv].el.style.width = nw + "px";
  1065. this.cols[idx+p.nv].style.width = nw+"px";
  1066. if(this.footers.length>0) {this.footers[idx+p.nv].style.width = nw+"px";}
  1067. p.colModel[idx+p.nv].width = nw;
  1068. } else {
  1069. p.tblwidth = this.newWidth || p.tblwidth;
  1070. $('table:first',this.bDiv).css("width",p.tblwidth+"px");
  1071. $('table:first',this.hDiv).css("width",p.tblwidth+"px");
  1072. this.hDiv.scrollLeft = this.bDiv.scrollLeft;
  1073. if(p.footerrow) {
  1074. $('table:first',this.sDiv).css("width",p.tblwidth+"px");
  1075. this.sDiv.scrollLeft = this.bDiv.scrollLeft;
  1076. }
  1077. }
  1078. $(ts).triggerHandler("jqGridResizeStop", [nw, idx]);
  1079. if($.isFunction(p.resizeStop)) { p.resizeStop.call(ts,nw,idx); }
  1080. }
  1081. this.curGbox = null;
  1082. document.onselectstart=function(){return true;};
  1083. },
  1084. populateVisible: function() {
  1085. if (grid.timer) { clearTimeout(grid.timer); }
  1086. grid.timer = null;
  1087. var dh = $(grid.bDiv).height();
  1088. if (!dh) { return; }
  1089. var table = $("table:first", grid.bDiv);
  1090. var rows, rh;
  1091. if(table[0].rows.length) {
  1092. try {
  1093. rows = table[0].rows[1];
  1094. rh = rows ? $(rows).outerHeight() || grid.prevRowHeight : grid.prevRowHeight;
  1095. } catch (pv) {
  1096. rh = grid.prevRowHeight;
  1097. }
  1098. }
  1099. if (!rh) { return; }
  1100. grid.prevRowHeight = rh;
  1101. var rn = p.rowNum;
  1102. var scrollTop = grid.scrollTop = grid.bDiv.scrollTop;
  1103. var ttop = Math.round(table.position().top) - scrollTop;
  1104. var tbot = ttop + table.height();
  1105. var div = rh * rn;
  1106. var page, npage, empty;
  1107. if ( tbot < dh && ttop <= 0 &&
  1108. (p.lastpage===undefined||(parseInt((tbot + scrollTop + div - 1) / div,10) || 0) <= p.lastpage))
  1109. {
  1110. npage = parseInt((dh - tbot + div - 1) / div,10) || 1;
  1111. if (tbot >= 0 || npage < 2 || p.scroll === true) {
  1112. page = ( Math.round((tbot + scrollTop) / div) || 0) + 1;
  1113. ttop = -1;
  1114. } else {
  1115. ttop = 1;
  1116. }
  1117. }
  1118. if (ttop > 0) {
  1119. page = ( parseInt(scrollTop / div,10) || 0 ) + 1;
  1120. npage = (parseInt((scrollTop + dh) / div,10) || 0) + 2 - page;
  1121. empty = true;
  1122. }
  1123. if (npage) {
  1124. if (p.lastpage && (page > p.lastpage || p.lastpage===1 || (page === p.page && page===p.lastpage)) ) {
  1125. return;
  1126. }
  1127. if (grid.hDiv.loading) {
  1128. grid.timer = setTimeout(grid.populateVisible, p.scrollTimeout);
  1129. } else {
  1130. p.page = page;
  1131. if (empty) {
  1132. grid.selectionPreserver(table[0]);
  1133. grid.emptyRows.call(table[0], false, false);
  1134. }
  1135. grid.populate(npage);
  1136. }
  1137. }
  1138. },
  1139. scrollGrid: function( e ) {
  1140. if(p.scroll) {
  1141. var scrollTop = grid.bDiv.scrollTop;
  1142. if(grid.scrollTop === undefined) { grid.scrollTop = 0; }
  1143. if (scrollTop !== grid.scrollTop) {
  1144. grid.scrollTop = scrollTop;
  1145. if (grid.timer) { clearTimeout(grid.timer); }
  1146. grid.timer = setTimeout(grid.populateVisible, p.scrollTimeout);
  1147. }
  1148. }
  1149. grid.hDiv.scrollLeft = grid.bDiv.scrollLeft;
  1150. if(p.footerrow) {
  1151. grid.sDiv.scrollLeft = grid.bDiv.scrollLeft;
  1152. }
  1153. if( e ) { e.stopPropagation(); }
  1154. },
  1155. selectionPreserver : function(ts) {
  1156. var p = ts.p,
  1157. sr = p.selrow, sra = p.selarrrow ? $.makeArray(p.selarrrow) : null,
  1158. left = ts.grid.bDiv.scrollLeft,
  1159. restoreSelection = function() {
  1160. var i;
  1161. p.selrow = null;
  1162. p.selarrrow = [];
  1163. if(p.multiselect && sra && sra.length>0) {
  1164. for(i=0;i<sra.length;i++){
  1165. if (sra[i] !== sr) {
  1166. $(ts).jqGrid("setSelection",sra[i],false, null);
  1167. }
  1168. }
  1169. }
  1170. if (sr) {
  1171. $(ts).jqGrid("setSelection",sr,false,null);
  1172. }
  1173. ts.grid.bDiv.scrollLeft = left;
  1174. $(ts).unbind('.selectionPreserver', restoreSelection);
  1175. };
  1176. $(ts).bind('jqGridGridComplete.selectionPreserver', restoreSelection);
  1177. }
  1178. };
  1179. if(this.tagName.toUpperCase() !== 'TABLE' || this.id == null) {
  1180. alert("Element is not a table or has no id!");
  1181. return;
  1182. }
  1183. if(document.documentMode !== undefined ) { // IE only
  1184. if(document.documentMode <= 5) {
  1185. alert("Grid can not be used in this ('quirks') mode!");
  1186. return;
  1187. }
  1188. }
  1189. $(this).empty().attr("tabindex","0");
  1190. this.p = p ;
  1191. this.p.useProp = !!$.fn.prop;
  1192. var i, dir;
  1193. if(this.p.colNames.length === 0) {
  1194. for (i=0;i<this.p.colModel.length;i++){
  1195. this.p.colNames[i] = this.p.colModel[i].label || this.p.colModel[i].name;
  1196. }
  1197. }
  1198. if( this.p.colNames.length !== this.p.colModel.length ) {
  1199. alert($.jgrid.errors.model);
  1200. return;
  1201. }
  1202. var gv = $("<div class='ui-jqgrid-view'></div>"),
  1203. isMSIE = $.jgrid.msie;
  1204. ts.p.direction = $.trim(ts.p.direction.toLowerCase());
  1205. if($.inArray(ts.p.direction,["ltr","rtl"]) === -1) { ts.p.direction = "ltr"; }
  1206. dir = ts.p.direction;
  1207. $(gv).insertBefore(this);
  1208. $(this).removeClass("scroll").appendTo(gv);
  1209. var eg = $("<div class='ui-jqgrid ui-widget ui-widget-content ui-corner-all'></div>");
  1210. $(eg).attr({"id" : "gbox_"+this.id,"dir":dir}).insertBefore(gv);
  1211. $(gv).attr("id","gview_"+this.id).appendTo(eg);
  1212. $("<div class='ui-widget-overlay jqgrid-overlay' id='lui_"+this.id+"'></div>").insertBefore(gv);
  1213. $("<div class='loading ui-state-default ui-state-active' id='load_"+this.id+"'>"+this.p.loadtext+"</div>").insertBefore(gv);
  1214. $(this).attr({cellspacing:"0",cellpadding:"0",border:"0","role":"grid","aria-multiselectable":!!this.p.multiselect,"aria-labelledby":"gbox_"+this.id});
  1215. var sortkeys = ["shiftKey","altKey","ctrlKey"],
  1216. intNum = function(val,defval) {
  1217. val = parseInt(val,10);
  1218. if (isNaN(val)) { return defval || 0;}
  1219. return val;
  1220. },
  1221. formatCol = function (pos, rowInd, tv, rawObject, rowId, rdata){
  1222. var cm = ts.p.colModel[pos],
  1223. ral = cm.align, result="style=\"", clas = cm.classes, nm = cm.name, celp, acp=[];
  1224. if(ral) { result += "text-align:"+ral+";"; }
  1225. if(cm.hidden===true) { result += "display:none;"; }
  1226. if(rowInd===0) {
  1227. result += "width: "+grid.headers[pos].width+"px;";
  1228. } else if (cm.cellattr && $.isFunction(cm.cellattr))
  1229. {
  1230. celp = cm.cellattr.call(ts, rowId, tv, rawObject, cm, rdata);
  1231. if(celp && typeof celp === "string") {
  1232. celp = celp.replace(/style/i,'style').replace(/title/i,'title');
  1233. if(celp.indexOf('title') > -1) { cm.title=false;}
  1234. if(celp.indexOf('class') > -1) { clas = undefined;}
  1235. acp = celp.replace('-style','-sti').split(/style/);
  1236. if(acp.length === 2 ) {
  1237. acp[1] = $.trim(acp[1].replace('-sti','-style').replace("=",""));
  1238. if(acp[1].indexOf("'") === 0 || acp[1].indexOf('"') === 0) {
  1239. acp[1] = acp[1].substring(1);
  1240. }
  1241. result += acp[1].replace(/'/gi,'"');
  1242. } else {
  1243. result += "\"";
  1244. }
  1245. }
  1246. }
  1247. if(!acp.length) { acp[0] = ""; result += "\"";}
  1248. result += (clas !== undefined ? (" class=\""+clas+"\"") :"") + ((cm.title && tv) ? (" title=\""+$.jgrid.stripHtml(tv)+"\"") :"");
  1249. result += " aria-describedby=\""+ts.p.id+"_"+nm+"\"";
  1250. return result + acp[0];
  1251. },
  1252. cellVal = function (val) {
  1253. return val == null || val === "" ? "&#160;" : (ts.p.autoencode ? $.jgrid.htmlEncode(val) : String(val));
  1254. },
  1255. formatter = function (rowId, cellval , colpos, rwdat, _act){
  1256. var cm = ts.p.colModel[colpos],v;
  1257. if(cm.formatter !== undefined) {
  1258. rowId = String(ts.p.idPrefix) !== "" ? $.jgrid.stripPref(ts.p.idPrefix, rowId) : rowId;
  1259. var opts= {rowId: rowId, colModel:cm, gid:ts.p.id, pos:colpos };
  1260. if($.isFunction( cm.formatter ) ) {
  1261. v = cm.formatter.call(ts,cellval,opts,rwdat,_act);
  1262. } else if($.fmatter){
  1263. //alert(cellval+"---bbq");
  1264. v = $.fn.fmatter.call(ts,cm.formatter,cellval,opts,rwdat,_act);
  1265. } else {
  1266. v = cellVal(cellval);
  1267. }
  1268. } else {
  1269. v = cellVal(cellval);
  1270. }
  1271. return v;
  1272. },
  1273. addCell = function(rowId,cell,pos,irow, srvr, rdata) {
  1274. var v,prp;
  1275. v = formatter(rowId,cell,pos,srvr,'add');
  1276. prp = formatCol( pos,irow, v, srvr, rowId, rdata);
  1277. return "<td role=\"gridcell\" "+prp+">"+v+"</td>";
  1278. },
  1279. addMulti = function(rowid,pos,irow,checked){
  1280. var v = "<input role=\"checkbox\" type=\"checkbox\""+" id=\"jqg_"+ts.p.id+"_"+rowid+"\" class=\"cbox\" name=\"jqg_"+ts.p.id+"_"+rowid+"\"" + (checked ? "checked=\"checked\"" : "")+"/>",
  1281. prp = formatCol( pos,irow,'',null, rowid, true);
  1282. return "<td role=\"gridcell\" "+prp+">"+v+"</td>";
  1283. },
  1284. addRowNum = function (pos,irow,pG,rN) {
  1285. var v = (parseInt(pG,10)-1)*parseInt(rN,10)+1+irow,
  1286. prp = formatCol( pos,irow,v, null, irow, true);
  1287. return "<td role=\"gridcell\" class=\"ui-state-default jqgrid-rownum\" "+prp+">"+v+"</td>";
  1288. },
  1289. reader = function (datatype) {
  1290. var field, f=[], j=0, i;
  1291. for(i =0; i<ts.p.colModel.length; i++){
  1292. field = ts.p.colModel[i];
  1293. if (field.name !== 'cb' && field.name !=='subgrid' && field.name !=='rn') {
  1294. f[j]= datatype === "local" ?
  1295. field.name :
  1296. ( (datatype==="xml" || datatype === "xmlstring") ? field.xmlmap || field.name : field.jsonmap || field.name );
  1297. if(ts.p.keyName !== false && field.key===true ) {
  1298. ts.p.keyName = f[j];
  1299. }
  1300. j++;
  1301. }
  1302. }
  1303. return f;
  1304. },
  1305. orderedCols = function (offset) {
  1306. var order = ts.p.remapColumns;
  1307. if (!order || !order.length) {
  1308. order = $.map(ts.p.colModel, function(v,i) { return i; });
  1309. }
  1310. if (offset) {
  1311. order = $.map(order, function(v) { return v<offset?null:v-offset; });
  1312. }
  1313. return order;
  1314. },
  1315. emptyRows = function (scroll, locdata) {
  1316. var firstrow;
  1317. if (this.p.deepempty) {
  1318. $(this.rows).slice(1).remove();
  1319. } else {
  1320. firstrow = this.rows.length > 0 ? this.rows[0] : null;
  1321. $(this.firstChild).empty().append(firstrow);
  1322. }
  1323. if (scroll && this.p.scroll) {
  1324. $(this.grid.bDiv.firstChild).css({height: "auto"});
  1325. $(this.grid.bDiv.firstChild.firstChild).css({height: 0, display: "none"});
  1326. if (this.grid.bDiv.scrollTop !== 0) {
  1327. this.grid.bDiv.scrollTop = 0;
  1328. }
  1329. }
  1330. if(locdata === true && this.p.treeGrid) {
  1331. this.p.data = []; this.p._index = {};
  1332. }
  1333. },
  1334. refreshIndex = function() {
  1335. var datalen = ts.p.data.length, idname, i, val;
  1336. if(ts.p.keyName === false || ts.p.loadonce === true) {
  1337. idname = ts.p.localReader.id;
  1338. } else {
  1339. idname = ts.p.keyName;
  1340. }
  1341. for(i =0;i < datalen; i++) {
  1342. val = $.jgrid.getAccessor(ts.p.data[i],idname);
  1343. if (val === undefined) { val=String(i+1); }
  1344. ts.p._index[val] = i;
  1345. }
  1346. },
  1347. constructTr = function(id, hide, altClass, rd, cur, selected) {
  1348. var tabindex = '-1', restAttr = '', attrName, style = hide ? 'display:none;' : '',
  1349. classes = 'ui-widget-content jqgrow ui-row-' + ts.p.direction + (altClass ? ' ' + altClass : '') + (selected ? ' ui-state-highlight' : ''),
  1350. rowAttrObj = $(ts).triggerHandler("jqGridRowAttr", [rd, cur, id]);
  1351. if( typeof rowAttrObj !== "object" ) {
  1352. rowAttrObj = $.isFunction(ts.p.rowattr) ? ts.p.rowattr.call(ts, rd, cur, id) :{};
  1353. }
  1354. if(!$.isEmptyObject( rowAttrObj )) {
  1355. if (rowAttrObj.hasOwnProperty("id")) {
  1356. id = rowAttrObj.id;
  1357. delete rowAttrObj.id;
  1358. }
  1359. if (rowAttrObj.hasOwnProperty("tabindex")) {
  1360. tabindex = rowAttrObj.tabindex;
  1361. delete rowAttrObj.tabindex;
  1362. }
  1363. if (rowAttrObj.hasOwnProperty("style")) {
  1364. style += rowAttrObj.style;
  1365. delete rowAttrObj.style;
  1366. }
  1367. if (rowAttrObj.hasOwnProperty("class")) {
  1368. classes += ' ' + rowAttrObj['class'];
  1369. delete rowAttrObj['class'];
  1370. }
  1371. // dot't allow to change role attribute
  1372. try { delete rowAttrObj.role; } catch(ra){}
  1373. for (attrName in rowAttrObj) {
  1374. if (rowAttrObj.hasOwnProperty(attrName)) {
  1375. restAttr += ' ' + attrName + '=' + rowAttrObj[attrName];
  1376. }
  1377. }
  1378. }
  1379. return '<tr role="row" id="' + id + '" tabindex="' + tabindex + '" class="' + classes + '"' +
  1380. (style === '' ? '' : ' style="' + style + '"') + restAttr + '>';
  1381. },
  1382. addXmlData = function (xml,t, rcnt, more, adjust) {
  1383. var startReq = new Date(),
  1384. locdata = (ts.p.datatype !== "local" && ts.p.loadonce) || ts.p.datatype === "xmlstring",
  1385. xmlid = "_id_", xmlRd = ts.p.xmlReader,
  1386. frd = ts.p.datatype === "local" ? "local" : "xml";
  1387. if(locdata) {
  1388. ts.p.data = [];
  1389. ts.p._index = {};
  1390. ts.p.localReader.id = xmlid;
  1391. }
  1392. ts.p.reccount = 0;
  1393. if($.isXMLDoc(xml)) {
  1394. if(ts.p.treeANode===-1 && !ts.p.scroll) {
  1395. emptyRows.call(ts, false, true);
  1396. rcnt=1;
  1397. } else { rcnt = rcnt > 1 ? rcnt :1; }
  1398. } else { return; }
  1399. 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;
  1400. if(ts.p.subGrid===true) {
  1401. si = 1;
  1402. addSubGridCell = $.jgrid.getMethod("addSubGridCell");
  1403. }
  1404. if(!xmlRd.repeatitems) {f = reader(frd);}
  1405. if( ts.p.keyName===false) {
  1406. idn = $.isFunction( xmlRd.id ) ? xmlRd.id.call(ts, xml) : xmlRd.id;
  1407. } else {
  1408. idn = ts.p.keyName;
  1409. }
  1410. if( String(idn).indexOf("[") === -1 ) {
  1411. if (f.length) {
  1412. getId = function( trow, k) {return $(idn,trow).text() || k;};
  1413. } else {
  1414. getId = function( trow, k) {return $(xmlRd.cell,trow).eq(idn).text() || k;};
  1415. }
  1416. }
  1417. else {
  1418. getId = function( trow, k) {return trow.getAttribute(idn.replace(/[\[\]]/g,"")) || k;};
  1419. }
  1420. ts.p.userData = {};
  1421. ts.p.page = intNum($.jgrid.getXmlData(xml, xmlRd.page), ts.p.page);
  1422. ts.p.lastpage = intNum($.jgrid.getXmlData(xml, xmlRd.total), 1);
  1423. ts.p.records = intNum($.jgrid.getXmlData(xml, xmlRd.records));
  1424. if($.isFunction(xmlRd.userdata)) {
  1425. ts.p.userData = xmlRd.userdata.call(ts, xml) || {};
  1426. } else {
  1427. $.jgrid.getXmlData(xml, xmlRd.userdata, true).each(function() {ts.p.userData[this.getAttribute("name")]= $(this).text();});
  1428. }
  1429. var gxml = $.jgrid.getXmlData( xml, xmlRd.root, true);
  1430. gxml = $.jgrid.getXmlData( gxml, xmlRd.row, true);
  1431. if (!gxml) { gxml = []; }
  1432. var gl = gxml.length, j=0, grpdata=[], rn = parseInt(ts.p.rowNum,10), br=ts.p.scroll?$.jgrid.randId():1, altr;
  1433. if (gl > 0 && ts.p.page <= 0) { ts.p.page = 1; }
  1434. if(gxml && gl){
  1435. if (adjust) { rn *= adjust+1; }
  1436. var afterInsRow = $.isFunction(ts.p.afterInsertRow), hiderow=false, groupingPrepare;
  1437. if(ts.p.grouping) {
  1438. hiderow = ts.p.groupingView.groupCollapse === true;
  1439. groupingPrepare = $.jgrid.getMethod("groupingPrepare");
  1440. }
  1441. while (j<gl) {
  1442. xmlr = gxml[j];
  1443. rid = getId(xmlr,br+j);
  1444. rid = ts.p.idPrefix + rid;
  1445. altr = rcnt === 0 ? 0 : rcnt+1;
  1446. cn1 = (altr+j)%2 === 1 ? cn : '';
  1447. var iStartTrTag = rowData.length;
  1448. rowData.push("");
  1449. if( ni ) {
  1450. rowData.push( addRowNum(0,j,ts.p.page,ts.p.rowNum) );
  1451. }
  1452. if( gi ) {
  1453. rowData.push( addMulti(rid,ni,j, false) );
  1454. }
  1455. if( si ) {
  1456. rowData.push( addSubGridCell.call(self,gi+ni,j+rcnt) );
  1457. }
  1458. if(xmlRd.repeatitems){
  1459. if (!F) { F=orderedCols(gi+si+ni); }
  1460. var cells = $.jgrid.getXmlData( xmlr, xmlRd.cell, true);
  1461. $.each(F, function (k) {
  1462. var cell = cells[this];
  1463. if (!cell) { return false; }
  1464. v = cell.textContent || cell.text;
  1465. rd[ts.p.colModel[k+gi+si+ni].name] = v;
  1466. rowData.push( addCell(rid,v,k+gi+si+ni,j+rcnt,xmlr, rd) );
  1467. });
  1468. } else {
  1469. for(i = 0; i < f.length;i++) {
  1470. v = $.jgrid.getXmlData( xmlr, f[i]);
  1471. rd[ts.p.colModel[i+gi+si+ni].name] = v;
  1472. rowData.push( addCell(rid, v, i+gi+si+ni, j+rcnt, xmlr, rd) );
  1473. }
  1474. }
  1475. rowData[iStartTrTag] = constructTr(rid, hiderow, cn1, rd, xmlr, false);
  1476. rowData.push("</tr>");
  1477. if(ts.p.grouping) {
  1478. grpdata.push( rowData );
  1479. if(!ts.p.groupingView._locgr) {
  1480. groupingPrepare.call(self, rd, j );
  1481. }
  1482. rowData = [];
  1483. }
  1484. if(locdata || ts.p.treeGrid === true) {
  1485. rd[xmlid] = $.jgrid.stripPref(ts.p.idPrefix, rid);
  1486. ts.p.data.push(rd);
  1487. ts.p._index[rd[xmlid]] = ts.p.data.length-1;
  1488. }
  1489. if(ts.p.gridview === false ) {
  1490. $("tbody:first",t).append(rowData.join(''));
  1491. self.triggerHandler("jqGridAfterInsertRow", [rid, rd, xmlr]);
  1492. if(afterInsRow) {ts.p.afterInsertRow.call(ts,rid,rd,xmlr);}
  1493. rowData=[];
  1494. }
  1495. rd={};
  1496. ir++;
  1497. j++;
  1498. if(ir===rn) {break;}
  1499. }
  1500. }
  1501. if(ts.p.gridview === true) {
  1502. fpos = ts.p.treeANode > -1 ? ts.p.treeANode: 0;
  1503. if(ts.p.grouping) {
  1504. if(!locdata) {
  1505. self.jqGrid('groupingRender',grpdata,ts.p.colModel.length, ts.p.page, rn);
  1506. grpdata = null;
  1507. }
  1508. } else if(ts.p.treeGrid === true && fpos > 0) {
  1509. $(ts.rows[fpos]).after(rowData.join(''));
  1510. } else {
  1511. $("tbody:first",t).append(rowData.join(''));
  1512. }
  1513. }
  1514. if(ts.p.subGrid === true ) {
  1515. try {self.jqGrid("addSubGrid",gi+ni);} catch (_){}
  1516. }
  1517. ts.p.totaltime = new Date() - startReq;
  1518. if(ir>0) { if(ts.p.records===0) { ts.p.records=gl;} }
  1519. rowData =null;
  1520. if( ts.p.treeGrid === true) {
  1521. try {self.jqGrid("setTreeNode", fpos+1, ir+fpos+1);} catch (e) {}
  1522. }
  1523. if(!ts.p.treeGrid && !ts.p.scroll) {ts.grid.bDiv.scrollTop = 0;}
  1524. ts.p.reccount=ir;
  1525. ts.p.treeANode = -1;
  1526. if(ts.p.userDataOnFooter) { self.jqGrid("footerData","set",ts.p.userData,true); }
  1527. if(locdata) {
  1528. ts.p.records = gl;
  1529. ts.p.lastpage = Math.ceil(gl/ rn);
  1530. }
  1531. if (!more) { ts.updatepager(false,true); }
  1532. if(locdata) {
  1533. while (ir<gl) {
  1534. xmlr = gxml[ir];
  1535. rid = getId(xmlr,ir+br);
  1536. rid = ts.p.idPrefix + rid;
  1537. if(xmlRd.repeatitems){
  1538. if (!F) { F=orderedCols(gi+si+ni); }
  1539. var cells2 = $.jgrid.getXmlData( xmlr, xmlRd.cell, true);
  1540. $.each(F, function (k) {
  1541. var cell = cells2[this];
  1542. if (!cell) { return false; }
  1543. v = cell.textContent || cell.text;
  1544. rd[ts.p.colModel[k+gi+si+ni].name] = v;
  1545. });
  1546. } else {
  1547. for(i = 0; i < f.length;i++) {
  1548. v = $.jgrid.getXmlData( xmlr, f[i]);
  1549. rd[ts.p.colModel[i+gi+si+ni].name] = v;
  1550. }
  1551. }
  1552. rd[xmlid] = $.jgrid.stripPref(ts.p.idPrefix, rid);
  1553. if(ts.p.grouping) {
  1554. groupingPrepare.call(self, rd, ir );
  1555. }
  1556. ts.p.data.push(rd);
  1557. ts.p._index[rd[xmlid]] = ts.p.data.length-1;
  1558. rd = {};
  1559. ir++;
  1560. }
  1561. if(ts.p.grouping) {
  1562. ts.p.groupingView._locgr = true;
  1563. self.jqGrid('groupingRender', grpdata, ts.p.colModel.length, ts.p.page, rn);
  1564. grpdata = null;
  1565. }
  1566. }
  1567. },
  1568. addJSONData = function(data,t, rcnt, more, adjust) {
  1569. var startReq = new Date();
  1570. if(data) {
  1571. if(ts.p.treeANode === -1 && !ts.p.scroll) {
  1572. emptyRows.call(ts, false, true);
  1573. rcnt=1;
  1574. } else { rcnt = rcnt > 1 ? rcnt :1; }
  1575. } else { return; }
  1576. var dReader, locid = "_id_", frd,
  1577. locdata = (ts.p.datatype !== "local" && ts.p.loadonce) || ts.p.datatype === "jsonstring";
  1578. if(locdata) { ts.p.data = []; ts.p._index = {}; ts.p.localReader.id = locid;}
  1579. ts.p.reccount = 0;
  1580. if(ts.p.datatype === "local") {
  1581. dReader = ts.p.localReader;
  1582. frd= 'local';
  1583. } else {
  1584. dReader = ts.p.jsonReader;
  1585. frd='json';
  1586. }
  1587. 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;
  1588. ts.p.page = intNum($.jgrid.getAccessor(data,dReader.page), ts.p.page);
  1589. ts.p.lastpage = intNum($.jgrid.getAccessor(data,dReader.total), 1);
  1590. ts.p.records = intNum($.jgrid.getAccessor(data,dReader.records));
  1591. ts.p.userData = $.jgrid.getAccessor(data,dReader.userdata) || {};
  1592. ts.p.subs= $.jgrid.getAccessor(data,dReader.subs) || {};
  1593. if(si) {
  1594. addSubGridCell = $.jgrid.getMethod("addSubGridCell");
  1595. }
  1596. if( ts.p.keyName===false ) {
  1597. idn = $.isFunction(dReader.id) ? dReader.id.call(ts, data) : dReader.id;
  1598. } else {
  1599. idn = ts.p.keyName;
  1600. }
  1601. drows = $.jgrid.getAccessor(data,dReader.root);
  1602. if (drows == null && $.isArray(data)) { drows = data; }
  1603. if (!drows) { drows = []; }
  1604. len = drows.length; i=0;
  1605. if (len > 0 && ts.p.page <= 0) { ts.p.page = 1; }
  1606. var rn = parseInt(ts.p.rowNum,10),br=ts.p.scroll?$.jgrid.randId():1, altr, selected=false, selr;
  1607. if (adjust) { rn *= adjust+1; }
  1608. if(ts.p.datatype === "local" && !ts.p.deselectAfterSort) {
  1609. selected = true;
  1610. }
  1611. var afterInsRow = $.isFunction(ts.p.afterInsertRow), grpdata=[],hiderow=false, groupingPrepare;
  1612. if(ts.p.grouping) {
  1613. hiderow = ts.p.groupingView.groupCollapse === true;
  1614. groupingPrepare = $.jgrid.getMethod("groupingPrepare");
  1615. }
  1616. while (i<len) {
  1617. cur = drows[i];
  1618. idr = $.jgrid.getAccessor(cur,idn);
  1619. if(idr === undefined) {
  1620. if (typeof idn === "number" && ts.p.colModel[idn+gi+si+ni] != null) {
  1621. // reread id by name
  1622. idr = $.jgrid.getAccessor(cur,ts.p.colModel[idn+gi+si+ni].name);
  1623. }
  1624. if(idr === undefined) {
  1625. idr = br+i;
  1626. if(f.length===0){
  1627. if(dReader.cell){
  1628. var ccur = $.jgrid.getAccessor(cur,dReader.cell) || cur;
  1629. idr = ccur != null && ccur[idn] !== undefined ? ccur[idn] : idr;
  1630. ccur=null;
  1631. }
  1632. }
  1633. }
  1634. }
  1635. idr = ts.p.idPrefix + idr;
  1636. altr = rcnt === 1 ? 0 : rcnt;
  1637. cn1 = (altr+i)%2 === 1 ? cn : '';
  1638. if( selected) {
  1639. if( ts.p.multiselect) {
  1640. selr = ($.inArray(idr, ts.p.selarrrow) !== -1);
  1641. } else {
  1642. selr = (idr === ts.p.selrow);
  1643. }
  1644. }
  1645. var iStartTrTag = rowData.length;
  1646. rowData.push("");
  1647. if( ni ) {
  1648. rowData.push( addRowNum(0,i,ts.p.page,ts.p.rowNum) );
  1649. }
  1650. if( gi ){
  1651. rowData.push( addMulti(idr,ni,i,selr) );
  1652. }
  1653. if( si ) {
  1654. rowData.push( addSubGridCell.call(self,gi+ni,i+rcnt) );
  1655. }
  1656. rowReader=objectReader;
  1657. if (dReader.repeatitems) {
  1658. if(dReader.cell) {cur = $.jgrid.getAccessor(cur,dReader.cell) || cur;}
  1659. if ($.isArray(cur)) { rowReader=arrayReader; }
  1660. }
  1661. for (j=0;j<rowReader.length;j++) {
  1662. v = $.jgrid.getAccessor(cur,rowReader[j]);
  1663. rd[ts.p.colModel[j+gi+si+ni].name] = v;
  1664. rowData.push( addCell(idr,v,j+gi+si+ni,i+rcnt,cur, rd) );
  1665. }
  1666. rowData[iStartTrTag] = constructTr(idr, hiderow, cn1, rd, cur, selr);
  1667. rowData.push( "</tr>" );
  1668. if(ts.p.grouping) {
  1669. grpdata.push( rowData );
  1670. if(!ts.p.groupingView._locgr) {
  1671. groupingPrepare.call(self, rd, i);
  1672. }
  1673. rowData = [];
  1674. }
  1675. if(locdata || ts.p.treeGrid===true) {
  1676. rd[locid] = $.jgrid.stripPref(ts.p.idPrefix, idr);
  1677. ts.p.data.push(rd);
  1678. ts.p._index[rd[locid]] = ts.p.data.length-1;
  1679. }
  1680. if(ts.p.gridview === false ) {
  1681. $("#"+$.jgrid.jqID(ts.p.id)+" tbody:first").append(rowData.join(''));
  1682. self.triggerHandler("jqGridAfterInsertRow", [idr, rd, cur]);
  1683. if(afterInsRow) {ts.p.afterInsertRow.call(ts,idr,rd,cur);}
  1684. rowData=[];//ari=0;
  1685. }
  1686. rd={};
  1687. ir++;
  1688. i++;
  1689. if(ir===rn) { break; }
  1690. }
  1691. if(ts.p.gridview === true ) {
  1692. fpos = ts.p.treeANode > -1 ? ts.p.treeANode: 0;
  1693. if(ts.p.grouping) {
  1694. if(!locdata) {
  1695. self.jqGrid('groupingRender', grpdata, ts.p.colModel.length, ts.p.page, rn);
  1696. grpdata = null;
  1697. }
  1698. } else if(ts.p.treeGrid === true && fpos > 0) {
  1699. $(ts.rows[fpos]).after(rowData.join(''));
  1700. } else {
  1701. $("#"+$.jgrid.jqID(ts.p.id)+" tbody:first").append(rowData.join(''));
  1702. }
  1703. }
  1704. if(ts.p.subGrid === true ) {
  1705. try { self.jqGrid("addSubGrid",gi+ni);} catch (_){}
  1706. }
  1707. ts.p.totaltime = new Date() - startReq;
  1708. if(ir>0) {
  1709. if(ts.p.records===0) { ts.p.records=len; }
  1710. }
  1711. rowData = null;
  1712. if( ts.p.treeGrid === true) {
  1713. try {self.jqGrid("setTreeNode", fpos+1, ir+fpos+1);} catch (e) {}
  1714. }
  1715. if(!ts.p.treeGrid && !ts.p.scroll) {ts.grid.bDiv.scrollTop = 0;}
  1716. ts.p.reccount=ir;
  1717. ts.p.treeANode = -1;
  1718. if(ts.p.userDataOnFooter) { self.jqGrid("footerData","set",ts.p.userData,true); }
  1719. if(locdata) {
  1720. ts.p.records = len;
  1721. ts.p.lastpage = Math.ceil(len/ rn);
  1722. }
  1723. if (!more) { ts.updatepager(false,true); }
  1724. if(locdata) {
  1725. while (ir<len && drows[ir]) {
  1726. cur = drows[ir];
  1727. idr = $.jgrid.getAccessor(cur,idn);
  1728. if(idr === undefined) {
  1729. if (typeof idn === "number" && ts.p.colModel[idn+gi+si+ni] != null) {
  1730. // reread id by name
  1731. idr = $.jgrid.getAccessor(cur,ts.p.colModel[idn+gi+si+ni].name);
  1732. }
  1733. if(idr === undefined) {
  1734. idr = br+ir;
  1735. if(f.length===0){
  1736. if(dReader.cell){
  1737. var ccur2 = $.jgrid.getAccessor(cur,dReader.cell) || cur;
  1738. idr = ccur2 != null && ccur2[idn] !== undefined ? ccur2[idn] : idr;
  1739. ccur2=null;
  1740. }
  1741. }
  1742. }
  1743. }
  1744. if(cur) {
  1745. idr = ts.p.idPrefix + idr;
  1746. rowReader=objectReader;
  1747. if (dReader.repeatitems) {
  1748. if(dReader.cell) {cur = $.jgrid.getAccessor(cur,dReader.cell) || cur;}
  1749. if ($.isArray(cur)) { rowReader=arrayReader; }
  1750. }
  1751. for (j=0;j<rowReader.length;j++) {
  1752. rd[ts.p.colModel[j+gi+si+ni].name] = $.jgrid.getAccessor(cur,rowReader[j]);
  1753. }
  1754. rd[locid] = $.jgrid.stripPref(ts.p.idPrefix, idr);
  1755. if(ts.p.grouping) {
  1756. groupingPrepare.call(self, rd, ir );
  1757. }
  1758. ts.p.data.push(rd);
  1759. ts.p._index[rd[locid]] = ts.p.data.length-1;
  1760. rd = {};
  1761. }
  1762. ir++;
  1763. }
  1764. if(ts.p.grouping) {
  1765. ts.p.groupingView._locgr = true;
  1766. self.jqGrid('groupingRender', grpdata, ts.p.colModel.length, ts.p.page, rn);
  1767. grpdata = null;
  1768. }
  1769. }
  1770. },
  1771. addLocalData = function() {
  1772. var st = ts.p.multiSort ? [] : "", sto=[], fndsort=false, cmtypes={}, grtypes=[], grindexes=[], srcformat, sorttype, newformat;
  1773. if(!$.isArray(ts.p.data)) {
  1774. return;
  1775. }
  1776. var grpview = ts.p.grouping ? ts.p.groupingView : false, lengrp, gin;
  1777. $.each(ts.p.colModel,function(){
  1778. sorttype = this.sorttype || "text";
  1779. if(sorttype === "date" || sorttype === "datetime") {
  1780. if(this.formatter && typeof this.formatter === 'string' && this.formatter === 'date') {
  1781. if(this.formatoptions && this.formatoptions.srcformat) {
  1782. srcformat = this.formatoptions.srcformat;
  1783. } else {
  1784. srcformat = $.jgrid.formatter.date.srcformat;
  1785. }
  1786. if(this.formatoptions && this.formatoptions.newformat) {
  1787. newformat = this.formatoptions.newformat;
  1788. } else {
  1789. newformat = $.jgrid.formatter.date.newformat;
  1790. }
  1791. } else {
  1792. srcformat = newformat = this.datefmt || "Y-m-d";
  1793. }
  1794. cmtypes[this.name] = {"stype": sorttype, "srcfmt": srcformat,"newfmt":newformat, "sfunc": this.sortfunc || null};
  1795. } else {
  1796. cmtypes[this.name] = {"stype": sorttype, "srcfmt":'',"newfmt":'', "sfunc": this.sortfunc || null};
  1797. }
  1798. if(ts.p.grouping ) {
  1799. for(gin =0, lengrp = grpview.groupField.length; gin< lengrp; gin++) {
  1800. if( this.name === grpview.groupField[gin]) {
  1801. var grindex = this.name;
  1802. if (this.index) {
  1803. grindex = this.index;
  1804. }
  1805. grtypes[gin] = cmtypes[grindex];
  1806. grindexes[gin]= grindex;
  1807. }
  1808. }
  1809. }
  1810. if(ts.p.multiSort) {
  1811. if(this.lso) {
  1812. st.push(this.name);
  1813. var tmplso= this.lso.split("-");
  1814. sto.push( tmplso[tmplso.length-1] );
  1815. }
  1816. } else {
  1817. if(!fndsort && (this.index === ts.p.sortname || this.name === ts.p.sortname)){
  1818. st = this.name; // ???
  1819. fndsort = true;
  1820. }
  1821. }
  1822. });
  1823. if(ts.p.treeGrid) {
  1824. $(ts).jqGrid("SortTree", st, ts.p.sortorder, cmtypes[st].stype || 'text', cmtypes[st].srcfmt || '');
  1825. return;
  1826. }
  1827. var compareFnMap = {
  1828. 'eq':function(queryObj) {return queryObj.equals;},
  1829. 'ne':function(queryObj) {return queryObj.notEquals;},
  1830. 'lt':function(queryObj) {return queryObj.less;},
  1831. 'le':function(queryObj) {return queryObj.lessOrEquals;},
  1832. 'gt':function(queryObj) {return queryObj.greater;},
  1833. 'ge':function(queryObj) {return queryObj.greaterOrEquals;},
  1834. 'cn':function(queryObj) {return queryObj.contains;},
  1835. 'nc':function(queryObj,op) {return op === "OR" ? queryObj.orNot().contains : queryObj.andNot().contains;},
  1836. 'bw':function(queryObj) {return queryObj.startsWith;},
  1837. 'bn':function(queryObj,op) {return op === "OR" ? queryObj.orNot().startsWith : queryObj.andNot().startsWith;},
  1838. 'en':function(queryObj,op) {return op === "OR" ? queryObj.orNot().endsWith : queryObj.andNot().endsWith;},
  1839. 'ew':function(queryObj) {return queryObj.endsWith;},
  1840. 'ni':function(queryObj,op) {return op === "OR" ? queryObj.orNot().equals : queryObj.andNot().equals;},
  1841. 'in':function(queryObj) {return queryObj.equals;},
  1842. 'nu':function(queryObj) {return queryObj.isNull;},
  1843. 'nn':function(queryObj,op) {return op === "OR" ? queryObj.orNot().isNull : queryObj.andNot().isNull;}
  1844. },
  1845. query = $.jgrid.from(ts.p.data);
  1846. if (ts.p.ignoreCase) { query = query.ignoreCase(); }
  1847. function tojLinq ( group ) {
  1848. var s = 0, index, gor, ror, opr, rule;
  1849. if (group.groups != null) {
  1850. gor = group.groups.length && group.groupOp.toString().toUpperCase() === "OR";
  1851. if (gor) {
  1852. query.orBegin();
  1853. }
  1854. for (index = 0; index < group.groups.length; index++) {
  1855. if (s > 0 && gor) {
  1856. query.or();
  1857. }
  1858. try {
  1859. tojLinq(group.groups[index]);
  1860. } catch (e) {alert(e);}
  1861. s++;
  1862. }
  1863. if (gor) {
  1864. query.orEnd();
  1865. }
  1866. }
  1867. if (group.rules != null) {
  1868. //if(s>0) {
  1869. // var result = query.select();
  1870. // query = $.jgrid.from( result);
  1871. // if (ts.p.ignoreCase) { query = query.ignoreCase(); }
  1872. //}
  1873. try{
  1874. ror = group.rules.length && group.groupOp.toString().toUpperCase() === "OR";
  1875. if (ror) {
  1876. query.orBegin();
  1877. }
  1878. for (index = 0; index < group.rules.length; index++) {
  1879. rule = group.rules[index];
  1880. opr = group.groupOp.toString().toUpperCase();
  1881. if (compareFnMap[rule.op] && rule.field ) {
  1882. if(s > 0 && opr && opr === "OR") {
  1883. query = query.or();
  1884. }
  1885. query = compareFnMap[rule.op](query, opr)(rule.field, rule.data, cmtypes[rule.field]);
  1886. }
  1887. s++;
  1888. }
  1889. if (ror) {
  1890. query.orEnd();
  1891. }
  1892. } catch (g) {alert(g);}
  1893. }
  1894. }
  1895. if (ts.p.search === true) {
  1896. var srules = ts.p.postData.filters;
  1897. if(srules) {
  1898. if(typeof srules === "string") { srules = $.jgrid.parse(srules);}
  1899. tojLinq( srules );
  1900. } else {
  1901. try {
  1902. query = compareFnMap[ts.p.postData.searchOper](query)(ts.p.postData.searchField, ts.p.postData.searchString,cmtypes[ts.p.postData.searchField]);
  1903. } catch (se){}
  1904. }
  1905. }
  1906. if(ts.p.grouping) {
  1907. for(gin=0; gin<lengrp;gin++) {
  1908. query.orderBy(grindexes[gin],grpview.groupOrder[gin],grtypes[gin].stype, grtypes[gin].srcfmt);
  1909. }
  1910. }
  1911. if(ts.p.multiSort) {
  1912. $.each(st,function(i){
  1913. query.orderBy(this, sto[i], cmtypes[this].stype, cmtypes[this].srcfmt, cmtypes[this].sfunc);
  1914. });
  1915. } else {
  1916. if (st && ts.p.sortorder && fndsort) {
  1917. if(ts.p.sortorder.toUpperCase() === "DESC") {
  1918. query.orderBy(ts.p.sortname, "d", cmtypes[st].stype, cmtypes[st].srcfmt, cmtypes[st].sfunc);
  1919. } else {
  1920. query.orderBy(ts.p.sortname, "a", cmtypes[st].stype, cmtypes[st].srcfmt, cmtypes[st].sfunc);
  1921. }
  1922. }
  1923. }
  1924. var queryResults = query.select(),
  1925. recordsperpage = parseInt(ts.p.rowNum,10),
  1926. total = queryResults.length,
  1927. page = parseInt(ts.p.page,10),
  1928. totalpages = Math.ceil(total / recordsperpage),
  1929. retresult = {};
  1930. if((ts.p.search || ts.p.resetsearch) && ts.p.grouping && ts.p.groupingView._locgr) {
  1931. ts.p.groupingView.groups =[];
  1932. var j, grPrepare = $.jgrid.getMethod("groupingPrepare"), key, udc;
  1933. if(ts.p.footerrow && ts.p.userDataOnFooter) {
  1934. for (key in ts.p.userData) {
  1935. if(ts.p.userData.hasOwnProperty(key)) {
  1936. ts.p.userData[key] = 0;
  1937. }
  1938. }
  1939. udc = true;
  1940. }
  1941. for(j=0; j<total; j++) {
  1942. if(udc) {
  1943. for(key in ts.p.userData){
  1944. ts.p.userData[key] += parseFloat(queryResults[j][key] || 0);
  1945. }
  1946. }
  1947. grPrepare.call($(ts),queryResults[j],j, recordsperpage );
  1948. }
  1949. }
  1950. queryResults = queryResults.slice( (page-1)*recordsperpage , page*recordsperpage );
  1951. query = null;
  1952. cmtypes = null;
  1953. retresult[ts.p.localReader.total] = totalpages;
  1954. retresult[ts.p.localReader.page] = page;
  1955. retresult[ts.p.localReader.records] = total;
  1956. retresult[ts.p.localReader.root] = queryResults;
  1957. retresult[ts.p.localReader.userdata] = ts.p.userData;
  1958. queryResults = null;
  1959. return retresult;
  1960. },
  1961. updatepager = function(rn, dnd) {
  1962. var cp, last, base, from,to,tot,fmt, pgboxes = "", sppg,
  1963. tspg = ts.p.pager ? "_"+$.jgrid.jqID(ts.p.pager.substr(1)) : "",
  1964. tspg_t = ts.p.toppager ? "_"+ts.p.toppager.substr(1) : "";
  1965. base = parseInt(ts.p.page,10)-1;
  1966. if(base < 0) { base = 0; }
  1967. base = base*parseInt(ts.p.rowNum,10);
  1968. to = base + ts.p.reccount;
  1969. if (ts.p.scroll) {
  1970. var rows = $("tbody:first > tr:gt(0)", ts.grid.bDiv);
  1971. base = to - rows.length;
  1972. ts.p.reccount = rows.length;
  1973. var rh = rows.outerHeight() || ts.grid.prevRowHeight;
  1974. if (rh) {
  1975. var top = base * rh;
  1976. var height = parseInt(ts.p.records,10) * rh;
  1977. $(">div:first",ts.grid.bDiv).css({height : height}).children("div:first").css({height:top,display:top?"":"none"});
  1978. if (ts.grid.bDiv.scrollTop == 0 && ts.p.page > 1) {
  1979. ts.grid.bDiv.scrollTop = ts.p.rowNum * (ts.p.page - 1) * rh;
  1980. }
  1981. }
  1982. ts.grid.bDiv.scrollLeft = ts.grid.hDiv.scrollLeft;
  1983. }
  1984. pgboxes = ts.p.pager || "";
  1985. pgboxes += ts.p.toppager ? (pgboxes ? "," + ts.p.toppager : ts.p.toppager) : "";
  1986. if(pgboxes) {
  1987. fmt = $.jgrid.formatter.integer || {};
  1988. cp = intNum(ts.p.page);
  1989. last = intNum(ts.p.lastpage);
  1990. $(".selbox",pgboxes)[ this.p.useProp ? 'prop' : 'attr' ]("disabled",false);
  1991. if(ts.p.pginput===true) {
  1992. $('.ui-pg-input',pgboxes).val(ts.p.page);
  1993. sppg = ts.p.toppager ? '#sp_1'+tspg+",#sp_1"+tspg_t : '#sp_1'+tspg;
  1994. $(sppg).html($.fmatter ? $.fmatter.util.NumberFormat(ts.p.lastpage,fmt):ts.p.lastpage);
  1995. }
  1996. if (ts.p.viewrecords){
  1997. if(ts.p.reccount === 0) {
  1998. $(".ui-paging-info",pgboxes).html(ts.p.emptyrecords);
  1999. } else {
  2000. from = base+1;
  2001. tot=ts.p.records;
  2002. if($.fmatter) {
  2003. from = $.fmatter.util.NumberFormat(from,fmt);
  2004. to = $.fmatter.util.NumberFormat(to,fmt);
  2005. tot = $.fmatter.util.NumberFormat(tot,fmt);
  2006. }
  2007. $(".ui-paging-info",pgboxes).html($.jgrid.format(ts.p.recordtext,from,to,tot));
  2008. }
  2009. }
  2010. if(ts.p.pgbuttons===true) {
  2011. if(cp<=0) {cp = last = 0;}
  2012. if(cp===1 || cp === 0) {
  2013. $("#first"+tspg+", #prev"+tspg).addClass('ui-state-disabled').removeClass('ui-state-hover');
  2014. if(ts.p.toppager) { $("#first_t"+tspg_t+", #prev_t"+tspg_t).addClass('ui-state-disabled').removeClass('ui-state-hover'); }
  2015. } else {
  2016. $("#first"+tspg+", #prev"+tspg).removeClass('ui-state-disabled');
  2017. if(ts.p.toppager) { $("#first_t"+tspg_t+", #prev_t"+tspg_t).removeClass('ui-state-disabled'); }
  2018. }
  2019. if(cp===last || cp === 0) {
  2020. $("#next"+tspg+", #last"+tspg).addClass('ui-state-disabled').removeClass('ui-state-hover');
  2021. if(ts.p.toppager) { $("#next_t"+tspg_t+", #last_t"+tspg_t).addClass('ui-state-disabled').removeClass('ui-state-hover'); }
  2022. } else {
  2023. $("#next"+tspg+", #last"+tspg).removeClass('ui-state-disabled');
  2024. if(ts.p.toppager) { $("#next_t"+tspg_t+", #last_t"+tspg_t).removeClass('ui-state-disabled'); }
  2025. }
  2026. }
  2027. }
  2028. if(rn===true && ts.p.rownumbers === true) {
  2029. $(">td.jqgrid-rownum",ts.rows).each(function(i){
  2030. $(this).html(base+1+i);
  2031. });
  2032. }
  2033. if(dnd && ts.p.jqgdnd) { $(ts).jqGrid('gridDnD','updateDnD');}
  2034. $(ts).triggerHandler("jqGridGridComplete");
  2035. if($.isFunction(ts.p.gridComplete)) {ts.p.gridComplete.call(ts);}
  2036. $(ts).triggerHandler("jqGridAfterGridComplete");
  2037. },
  2038. beginReq = function() {
  2039. ts.grid.hDiv.loading = true;
  2040. if(ts.p.hiddengrid) { return;}
  2041. switch(ts.p.loadui) {
  2042. case "disable":
  2043. break;
  2044. case "enable":
  2045. $("#load_"+$.jgrid.jqID(ts.p.id)).show();
  2046. break;
  2047. case "block":
  2048. $("#lui_"+$.jgrid.jqID(ts.p.id)).show();
  2049. $("#load_"+$.jgrid.jqID(ts.p.id)).show();
  2050. break;
  2051. }
  2052. },
  2053. endReq = function() {
  2054. ts.grid.hDiv.loading = false;
  2055. switch(ts.p.loadui) {
  2056. case "disable":
  2057. break;
  2058. case "enable":
  2059. $("#load_"+$.jgrid.jqID(ts.p.id)).hide();
  2060. break;
  2061. case "block":
  2062. $("#lui_"+$.jgrid.jqID(ts.p.id)).hide();
  2063. $("#load_"+$.jgrid.jqID(ts.p.id)).hide();
  2064. break;
  2065. }
  2066. },
  2067. populate = function (npage) {
  2068. if(!ts.grid.hDiv.loading) {
  2069. var pvis = ts.p.scroll && npage === false,
  2070. prm = {}, dt, dstr, pN=ts.p.prmNames;
  2071. if(ts.p.page <=0) { ts.p.page = Math.min(1,ts.p.lastpage); }
  2072. if(pN.search !== null) {prm[pN.search] = ts.p.search;} if(pN.nd !== null) {prm[pN.nd] = new Date().getTime();}
  2073. if(pN.rows !== null) {prm[pN.rows]= ts.p.rowNum;} if(pN.page !== null) {prm[pN.page]= ts.p.page;}
  2074. if(pN.sort !== null) {prm[pN.sort]= ts.p.sortname;} if(pN.order !== null) {prm[pN.order]= ts.p.sortorder;}
  2075. if(ts.p.rowTotal !== null && pN.totalrows !== null) { prm[pN.totalrows]= ts.p.rowTotal; }
  2076. var lcf = $.isFunction(ts.p.loadComplete), lc = lcf ? ts.p.loadComplete : null;
  2077. var adjust = 0;
  2078. npage = npage || 1;
  2079. if (npage > 1) {
  2080. if(pN.npage !== null) {
  2081. prm[pN.npage] = npage;
  2082. adjust = npage - 1;
  2083. npage = 1;
  2084. } else {
  2085. lc = function(req) {
  2086. ts.p.page++;
  2087. ts.grid.hDiv.loading = false;
  2088. if (lcf) {
  2089. ts.p.loadComplete.call(ts,req);
  2090. }
  2091. populate(npage-1);
  2092. };
  2093. }
  2094. } else if (pN.npage !== null) {
  2095. delete ts.p.postData[pN.npage];
  2096. }
  2097. if(ts.p.grouping) {
  2098. $(ts).jqGrid('groupingSetup');
  2099. var grp = ts.p.groupingView, gi, gs="";
  2100. for(gi=0;gi<grp.groupField.length;gi++) {
  2101. var index = grp.groupField[gi];
  2102. $.each(ts.p.colModel, function(cmIndex, cmValue) {
  2103. if (cmValue.name === index && cmValue.index){
  2104. index = cmValue.index;
  2105. }
  2106. } );
  2107. gs += index +" "+grp.groupOrder[gi]+", ";
  2108. }
  2109. prm[pN.sort] = gs + prm[pN.sort];
  2110. }
  2111. $.extend(ts.p.postData,prm);
  2112. var rcnt = !ts.p.scroll ? 1 : ts.rows.length-1;
  2113. var bfr = $(ts).triggerHandler("jqGridBeforeRequest");
  2114. if (bfr === false || bfr === 'stop') { return; }
  2115. if ($.isFunction(ts.p.datatype)) { ts.p.datatype.call(ts,ts.p.postData,"load_"+ts.p.id, rcnt, npage, adjust); return;}
  2116. if ($.isFunction(ts.p.beforeRequest)) {
  2117. bfr = ts.p.beforeRequest.call(ts);
  2118. if(bfr === undefined) { bfr = true; }
  2119. if ( bfr === false ) { return; }
  2120. }
  2121. dt = ts.p.datatype.toLowerCase();
  2122. switch(dt)
  2123. {
  2124. case "json":
  2125. case "jsonp":
  2126. case "xml":
  2127. case "script":
  2128. var whereCls = ts.p.whereCls;
  2129. //前台和但记录联合的查询wherestr
  2130. if(ts.p.postData.whereStr!=undefined){
  2131. whereCls=whereCls + " and " +ts.p.postData.whereStr;
  2132. }
  2133. if(_ENCRYPT_WHERE){
  2134. if(whereCls!=null&&whereCls!='null'&&whereCls!=''&&whereCls!='undefined'){
  2135. whereCls=stringToHex(encrypt(WHEREKEY,whereCls));
  2136. }
  2137. }
  2138. var dsId = ts.p.dsId;
  2139. var dynDictWhereCls = JSON.stringify(ts.p.dynDictWhereCls);
  2140. var pageNumber=ts.p.page;
  2141. var pageSize=ts.p.rowNum;
  2142. var rowstart = (pageNumber - 1) * pageSize + 1;
  2143. var param = {
  2144. 'confid' : ts.p.confid,
  2145. 'rowstart':rowstart,
  2146. 'dynDictWhereCls' : dynDictWhereCls,
  2147. 'dsId' : dsId,
  2148. 'pageSize':pageSize,
  2149. 'whereCls' : whereCls
  2150. };
  2151. var data=$.isFunction(ts.p.serializeGridData)? ts.p.serializeGridData.call(ts,ts.p.postData) : ts.p.postData;
  2152. // alert("-----1--------"+JSON.stringify(param) );
  2153. // alert("-----2--------"+JSON.stringify(data) );
  2154. // $.extend(true,data , param );
  2155. if(ts.p.postData.whereStr==undefined){
  2156. $.extend(true,param ,data );
  2157. }
  2158. // alert("-----3--------"+JSON.stringify(param));
  2159. $.ajax($.extend({
  2160. url:ts.p.url,
  2161. type:ts.p.mtype,
  2162. dataType: dt ,
  2163. //data: $.isFunction(ts.p.serializeGridData)? ts.p.serializeGridData.call(ts,ts.p.postData) : ts.p.postData,
  2164. data: param,
  2165. success:function(data,st, xhr) {
  2166. if ($.isFunction(ts.p.beforeProcessing)) {
  2167. if (ts.p.beforeProcessing.call(ts, data, st, xhr) === false) {
  2168. endReq();
  2169. return;
  2170. }
  2171. }
  2172. if(dt === "xml") { addXmlData(data,ts.grid.bDiv,rcnt,npage>1,adjust); }
  2173. else { addJSONData(data,ts.grid.bDiv,rcnt,npage>1,adjust); }
  2174. $(ts).triggerHandler("jqGridLoadComplete", [data]);
  2175. if(lc) { lc.call(ts,data); }
  2176. $(ts).triggerHandler("jqGridAfterLoadComplete", [data]);
  2177. if (pvis) { ts.grid.populateVisible(); }
  2178. if( ts.p.loadonce || ts.p.treeGrid) {ts.p.datatype = "local";}
  2179. ts.p.data=data;
  2180. data=null;
  2181. if (npage === 1) { endReq(); }
  2182. },
  2183. error:function(xhr,st,err){
  2184. if($.isFunction(ts.p.loadError)) { ts.p.loadError.call(ts,xhr,st,err); }
  2185. if (npage === 1) { endReq(); }
  2186. xhr=null;
  2187. },
  2188. beforeSend: function(xhr, settings ){
  2189. var gotoreq = true;
  2190. if($.isFunction(ts.p.loadBeforeSend)) {
  2191. gotoreq = ts.p.loadBeforeSend.call(ts,xhr, settings);
  2192. }
  2193. if(gotoreq === undefined) { gotoreq = true; }
  2194. if(gotoreq === false) {
  2195. return false;
  2196. }
  2197. beginReq();
  2198. }
  2199. },$.jgrid.ajaxOptions, ts.p.ajaxGridOptions));
  2200. break;
  2201. case "xmlstring":
  2202. beginReq();
  2203. dstr = typeof ts.p.datastr !== 'string' ? ts.p.datastr : $.parseXML(ts.p.datastr);
  2204. addXmlData(dstr,ts.grid.bDiv);
  2205. $(ts).triggerHandler("jqGridLoadComplete", [dstr]);
  2206. if(lcf) {ts.p.loadComplete.call(ts,dstr);}
  2207. $(ts).triggerHandler("jqGridAfterLoadComplete", [dstr]);
  2208. ts.p.datatype = "local";
  2209. ts.p.datastr = null;
  2210. endReq();
  2211. break;
  2212. case "jsonstring":
  2213. beginReq();
  2214. if(typeof ts.p.datastr === 'string') { dstr = $.jgrid.parse(ts.p.datastr); }
  2215. else { dstr = ts.p.datastr; }
  2216. addJSONData(dstr,ts.grid.bDiv);
  2217. $(ts).triggerHandler("jqGridLoadComplete", [dstr]);
  2218. if(lcf) {ts.p.loadComplete.call(ts,dstr);}
  2219. $(ts).triggerHandler("jqGridAfterLoadComplete", [dstr]);
  2220. ts.p.datatype = "local";
  2221. ts.p.datastr = null;
  2222. endReq();
  2223. break;
  2224. case "local":
  2225. case "clientside":
  2226. beginReq();
  2227. ts.p.datatype = "local";
  2228. var req = addLocalData();
  2229. addJSONData(req,ts.grid.bDiv,rcnt,npage>1,adjust);
  2230. $(ts).triggerHandler("jqGridLoadComplete", [req]);
  2231. if(lc) { lc.call(ts,req); }
  2232. $(ts).triggerHandler("jqGridAfterLoadComplete", [req]);
  2233. if (pvis) { ts.grid.populateVisible(); }
  2234. endReq();
  2235. break;
  2236. }
  2237. }
  2238. },
  2239. setHeadCheckBox = function ( checked ) {
  2240. $('#cb_'+$.jgrid.jqID(ts.p.id),ts.grid.hDiv)[ts.p.useProp ? 'prop': 'attr']("checked", checked);
  2241. var fid = ts.p.frozenColumns ? ts.p.id+"_frozen" : "";
  2242. if(fid) {
  2243. $('#cb_'+$.jgrid.jqID(ts.p.id),ts.grid.fhDiv)[ts.p.useProp ? 'prop': 'attr']("checked", checked);
  2244. }
  2245. },
  2246. setPager = function (pgid, tp){
  2247. // TBD - consider escaping pgid with pgid = $.jgrid.jqID(pgid);
  2248. var sep = "<td class='ui-pg-button ui-state-disabled' style='width:4px;'><span class='ui-separator'></span></td>",
  2249. pginp = "",
  2250. pgl="<table cellspacing='0' cellpadding='0' border='0' style='table-layout:auto;' class='ui-pg-table'><tbody><tr>",
  2251. str="", pgcnt, lft, cent, rgt, twd, tdw, i,
  2252. clearVals = function(onpaging){
  2253. var ret;
  2254. if ($.isFunction(ts.p.onPaging) ) { ret = ts.p.onPaging.call(ts,onpaging); }
  2255. if(ret==='stop') {return false;}
  2256. ts.p.selrow = null;
  2257. if(ts.p.multiselect) {ts.p.selarrrow =[]; setHeadCheckBox( false );}
  2258. ts.p.savedRow = [];
  2259. return true;
  2260. };
  2261. pgid = pgid.substr(1);
  2262. tp += "_" + pgid;
  2263. pgcnt = "pg_"+pgid;
  2264. lft = pgid+"_left"; cent = pgid+"_center"; rgt = pgid+"_right";
  2265. $("#"+$.jgrid.jqID(pgid) )
  2266. .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>")
  2267. .attr("dir","ltr"); //explicit setting
  2268. if(ts.p.rowList.length >0){
  2269. str = "<td dir='"+dir+"'>";
  2270. str +="<select class='ui-pg-selbox' role='listbox'>";
  2271. var strnm;
  2272. for(i=0;i<ts.p.rowList.length;i++){
  2273. strnm = ts.p.rowList[i].toString().split(":");
  2274. if(strnm.length === 1) {
  2275. strnm[1] = strnm[0];
  2276. }
  2277. str +="<option role=\"option\" value=\""+strnm[0]+"\""+(( intNum(ts.p.rowNum,0) === intNum(strnm[0],0))?" selected=\"selected\"":"")+">"+strnm[1]+"</option>";
  2278. }
  2279. str +="</select></td>";
  2280. }
  2281. if(dir==="rtl") { pgl += str; }
  2282. 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>";}
  2283. if(ts.p.pgbuttons===true) {
  2284. var po=["first"+tp,"prev"+tp, "next"+tp,"last"+tp]; if(dir==="rtl") { po.reverse(); }
  2285. pgl += "<td id='"+po[0]+"' class='ui-pg-button ui-corner-all'><span class='ui-icon ui-icon-seek-first'></span></td>";
  2286. pgl += "<td id='"+po[1]+"' class='ui-pg-button ui-corner-all'><span class='ui-icon ui-icon-seek-prev'></span></td>";
  2287. pgl += pginp !== "" ? sep+pginp+sep:"";
  2288. pgl += "<td id='"+po[2]+"' class='ui-pg-button ui-corner-all'><span class='ui-icon ui-icon-seek-next'></span></td>";
  2289. pgl += "<td id='"+po[3]+"' class='ui-pg-button ui-corner-all'><span class='ui-icon ui-icon-seek-end'></span></td>";
  2290. } else if (pginp !== "") { pgl += pginp; }
  2291. if(dir==="ltr") { pgl += str; }
  2292. pgl += "</tr></tbody></table>";
  2293. 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>");}
  2294. $("td#"+pgid+"_"+ts.p.pagerpos,"#"+pgcnt).append(pgl);
  2295. tdw = $(".ui-jqgrid").css("font-size") || "11px";
  2296. $(document.body).append("<div id='testpg' class='ui-jqgrid ui-widget ui-widget-content' style='font-size:"+tdw+";visibility:hidden;' ></div>");
  2297. twd = $(pgl).clone().appendTo("#testpg").width();
  2298. $("#testpg").remove();
  2299. if(twd > 0) {
  2300. if(pginp !== "") { twd += 50; } //should be param
  2301. $("td#"+pgid+"_"+ts.p.pagerpos,"#"+pgcnt).width(twd);
  2302. }
  2303. ts.p._nvtd = [];
  2304. ts.p._nvtd[0] = twd ? Math.floor((ts.p.width - twd)/2) : Math.floor(ts.p.width/3);
  2305. ts.p._nvtd[1] = 0;
  2306. pgl=null;
  2307. $('.ui-pg-selbox',"#"+pgcnt).bind('change',function() {
  2308. if(!clearVals('records')) { return false; }
  2309. ts.p.page = Math.round(ts.p.rowNum*(ts.p.page-1)/this.value-0.5)+1;
  2310. ts.p.rowNum = this.value;
  2311. if(ts.p.pager) { $('.ui-pg-selbox',ts.p.pager).val(this.value); }
  2312. if(ts.p.toppager) { $('.ui-pg-selbox',ts.p.toppager).val(this.value); }
  2313. populate();
  2314. return false;
  2315. });
  2316. if(ts.p.pgbuttons===true) {
  2317. $(".ui-pg-button","#"+pgcnt).hover(function(){
  2318. if($(this).hasClass('ui-state-disabled')) {
  2319. this.style.cursor='default';
  2320. } else {
  2321. $(this).addClass('ui-state-hover');
  2322. this.style.cursor='pointer';
  2323. }
  2324. },function() {
  2325. if(!$(this).hasClass('ui-state-disabled')) {
  2326. $(this).removeClass('ui-state-hover');
  2327. this.style.cursor= "default";
  2328. }
  2329. });
  2330. $("#first"+$.jgrid.jqID(tp)+", #prev"+$.jgrid.jqID(tp)+", #next"+$.jgrid.jqID(tp)+", #last"+$.jgrid.jqID(tp)).click( function() {
  2331. if ($(this).hasClass("ui-state-disabled")) {
  2332. return false;
  2333. }
  2334. var cp = intNum(ts.p.page,1),
  2335. last = intNum(ts.p.lastpage,1), selclick = false,
  2336. fp=true, pp=true, np=true,lp=true;
  2337. if(last ===0 || last===1) {fp=false;pp=false;np=false;lp=false; }
  2338. else if( last>1 && cp >=1) {
  2339. if( cp === 1) { fp=false; pp=false; }
  2340. //else if( cp>1 && cp <last){ }
  2341. else if( cp===last){ np=false;lp=false; }
  2342. } else if( last>1 && cp===0 ) { np=false;lp=false; cp=last-1;}
  2343. if(!clearVals(this.id)) { return false; }
  2344. if( this.id === 'first'+tp && fp ) { ts.p.page=1; selclick=true;}
  2345. if( this.id === 'prev'+tp && pp) { ts.p.page=(cp-1); selclick=true;}
  2346. if( this.id === 'next'+tp && np) { ts.p.page=(cp+1); selclick=true;}
  2347. if( this.id === 'last'+tp && lp) { ts.p.page=last; selclick=true;}
  2348. if(selclick) {
  2349. populate();
  2350. }
  2351. return false;
  2352. });
  2353. }
  2354. if(ts.p.pginput===true) {
  2355. $('input.ui-pg-input',"#"+pgcnt).keypress( function(e) {
  2356. var key = e.charCode || e.keyCode || 0;
  2357. if(key === 13) {
  2358. if(!clearVals('user')) { return false; }
  2359. $(this).val( intNum( $(this).val(), 1));
  2360. ts.p.page = ($(this).val()>0) ? $(this).val():ts.p.page;
  2361. populate();
  2362. return false;
  2363. }
  2364. return this;
  2365. });
  2366. }
  2367. },
  2368. multiSort = function(iCol, obj ) {
  2369. var splas, sort="", cm = ts.p.colModel, fs=false, ls,
  2370. selTh = ts.p.frozenColumns ? obj : ts.grid.headers[iCol].el, so="";
  2371. $("span.ui-grid-ico-sort",selTh).addClass('ui-state-disabled');
  2372. $(selTh).attr("aria-selected","false");
  2373. if(cm[iCol].lso) {
  2374. if(cm[iCol].lso==="asc") {
  2375. cm[iCol].lso += "-desc";
  2376. so = "desc";
  2377. } else if(cm[iCol].lso==="desc") {
  2378. cm[iCol].lso += "-asc";
  2379. so = "asc";
  2380. } else if(cm[iCol].lso==="asc-desc" || cm[iCol].lso==="desc-asc") {
  2381. cm[iCol].lso="";
  2382. }
  2383. } else {
  2384. cm[iCol].lso = so = cm[iCol].firstsortorder || 'asc';
  2385. }
  2386. if( so ) {
  2387. $("span.s-ico",selTh).show();
  2388. $("span.ui-icon-"+so,selTh).removeClass('ui-state-disabled');
  2389. $(selTh).attr("aria-selected","true");
  2390. } else {
  2391. if(!ts.p.viewsortcols[0]) {
  2392. $("span.s-ico",selTh).hide();
  2393. }
  2394. }
  2395. ts.p.sortorder = "";
  2396. $.each(cm, function(i){
  2397. if(this.lso) {
  2398. if(i>0 && fs) {
  2399. sort += ", ";
  2400. }
  2401. splas = this.lso.split("-");
  2402. sort += cm[i].index || cm[i].name;
  2403. sort += " "+splas[splas.length-1];
  2404. fs = true;
  2405. ts.p.sortorder = splas[splas.length-1];
  2406. }
  2407. });
  2408. ls = sort.lastIndexOf(ts.p.sortorder);
  2409. sort = sort.substring(0, ls);
  2410. ts.p.sortname = sort;
  2411. },
  2412. sortData = function (index, idxcol,reload,sor, obj){
  2413. if(!ts.p.colModel[idxcol].sortable) { return; }
  2414. if(ts.p.savedRow.length > 0) {return;}
  2415. if(!reload) {
  2416. if( ts.p.lastsort === idxcol ) {
  2417. if( ts.p.sortorder === 'asc') {
  2418. ts.p.sortorder = 'desc';
  2419. } else if(ts.p.sortorder === 'desc') { ts.p.sortorder = 'asc';}
  2420. } else { ts.p.sortorder = ts.p.colModel[idxcol].firstsortorder || 'asc'; }
  2421. ts.p.page = 1;
  2422. }
  2423. if(ts.p.multiSort) {
  2424. multiSort( idxcol, obj);
  2425. } else {
  2426. if(sor) {
  2427. if(ts.p.lastsort === idxcol && ts.p.sortorder === sor && !reload) { return; }
  2428. ts.p.sortorder = sor;
  2429. }
  2430. var previousSelectedTh = ts.grid.headers[ts.p.lastsort].el, newSelectedTh = ts.p.frozenColumns ? obj : ts.grid.headers[idxcol].el;
  2431. $("span.ui-grid-ico-sort",previousSelectedTh).addClass('ui-state-disabled');
  2432. $(previousSelectedTh).attr("aria-selected","false");
  2433. if(ts.p.frozenColumns) {
  2434. ts.grid.fhDiv.find("span.ui-grid-ico-sort").addClass('ui-state-disabled');
  2435. ts.grid.fhDiv.find("th").attr("aria-selected","false");
  2436. }
  2437. $("span.ui-icon-"+ts.p.sortorder,newSelectedTh).removeClass('ui-state-disabled');
  2438. $(newSelectedTh).attr("aria-selected","true");
  2439. if(!ts.p.viewsortcols[0]) {
  2440. if(ts.p.lastsort !== idxcol) {
  2441. if(ts.p.frozenColumns){
  2442. ts.grid.fhDiv.find("span.s-ico").hide();
  2443. }
  2444. $("span.s-ico",previousSelectedTh).hide();
  2445. $("span.s-ico",newSelectedTh).show();
  2446. }
  2447. }
  2448. index = index.substring(5 + ts.p.id.length + 1); // bad to be changed!?!
  2449. ts.p.sortname = ts.p.colModel[idxcol].index || index;
  2450. }
  2451. if ($(ts).triggerHandler("jqGridSortCol", [ts.p.sortname, idxcol, ts.p.sortorder]) === 'stop') {
  2452. ts.p.lastsort = idxcol;
  2453. return;
  2454. }
  2455. if($.isFunction(ts.p.onSortCol)) {if (ts.p.onSortCol.call(ts, ts.p.sortname, idxcol, ts.p.sortorder)==='stop') {ts.p.lastsort = idxcol; return;}}
  2456. if(ts.p.datatype === "local") {
  2457. if(ts.p.deselectAfterSort) {$(ts).jqGrid("resetSelection");}
  2458. } else {
  2459. ts.p.selrow = null;
  2460. if(ts.p.multiselect){setHeadCheckBox( false );}
  2461. ts.p.selarrrow =[];
  2462. ts.p.savedRow =[];
  2463. }
  2464. if(ts.p.scroll) {
  2465. var sscroll = ts.grid.bDiv.scrollLeft;
  2466. emptyRows.call(ts, true, false);
  2467. ts.grid.hDiv.scrollLeft = sscroll;
  2468. }
  2469. if(ts.p.subGrid && ts.p.datatype === 'local') {
  2470. $("td.sgexpanded","#"+$.jgrid.jqID(ts.p.id)).each(function(){
  2471. $(this).trigger("click");
  2472. });
  2473. }
  2474. //控件自带的去服务器访问排序
  2475. //populate();
  2476. //修改为当前页数据排序--start
  2477. var name = ts.p.sortname;
  2478. var order = (ts.p.sortorder === "asc" ? 1 : -1);
  2479. var data=ts.p.data;
  2480. var rcnt = !ts.p.scroll ? 1 : ts.rows.length-1;
  2481. var npage = 1;var adjust = 0;
  2482. data.rows.sort(function(r1, r2) {
  2483. var a1 = r1[name];
  2484. var b1 = r2[name];
  2485. if (a1 == null || $.trim(a1) == '') {
  2486. a1 = '';
  2487. }
  2488. if (b1 == null || $.trim(b1) == '') {
  2489. b1 = '';
  2490. }
  2491. //比较值是数字则进行数字排序
  2492. if(!isNaN(a1)&&!isNaN(b1)&&a1!=''&&b1!=''){
  2493. if(CFW.oComm.fnSub(a1,b1)==0)
  2494. return 0 ;
  2495. else
  2496. return (CFW.oComm.fnSub(a1,b1) > 0 ? 1 : -1)* order;
  2497. }else{ //比较值是字符进行字符排序(如果是数字和字符混排的列值,则排序方式是混合的)
  2498. if(a1==b1)
  2499. return 0 ;
  2500. else
  2501. return (a1 > b1 ? 1 : -1)* order;
  2502. }
  2503. });
  2504. addJSONData(data,ts.grid.bDiv,rcnt,npage>1,adjust);
  2505. //修改为当前页数据排序--end
  2506. ts.p.lastsort = idxcol;
  2507. if(ts.p.sortname !== index && idxcol) {ts.p.lastsort = idxcol;}
  2508. },
  2509. setColWidth = function () {
  2510. 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;
  2511. $.each(ts.p.colModel, function() {
  2512. if(this.hidden === undefined) {this.hidden=false;}
  2513. if(ts.p.grouping && ts.p.autowidth) {
  2514. var ind = $.inArray(this.name, ts.p.groupingView.groupField);
  2515. if(ind >= 0 && ts.p.groupingView.groupColumnShow.length > ind) {
  2516. this.hidden = !ts.p.groupingView.groupColumnShow[ind];
  2517. }
  2518. }
  2519. this.widthOrg = cw = intNum(this.width,0);
  2520. if(this.hidden===false){
  2521. initwidth += cw+brd;
  2522. if(this.fixed) {
  2523. gw += cw+brd;
  2524. } else {
  2525. vc++;
  2526. }
  2527. }
  2528. });
  2529. if(isNaN(ts.p.width)) {
  2530. ts.p.width = initwidth + ((ts.p.shrinkToFit ===false && !isNaN(ts.p.height)) ? scw : 0);
  2531. }
  2532. grid.width = ts.p.width;
  2533. ts.p.tblwidth = initwidth;
  2534. if(ts.p.shrinkToFit ===false && ts.p.forceFit === true) {ts.p.forceFit=false;}
  2535. if(ts.p.shrinkToFit===true && vc > 0) {
  2536. aw = grid.width-brd*vc-gw;
  2537. if(!isNaN(ts.p.height)) {
  2538. aw -= scw;
  2539. hs = true;
  2540. }
  2541. initwidth =0;
  2542. $.each(ts.p.colModel, function(i) {
  2543. if(this.hidden === false && !this.fixed){
  2544. cw = Math.round(aw*this.width/(ts.p.tblwidth-brd*vc-gw));
  2545. this.width =cw;
  2546. initwidth += cw;
  2547. lvc = i;
  2548. }
  2549. });
  2550. cr =0;
  2551. if (hs) {
  2552. if(grid.width-gw-(initwidth+brd*vc) !== scw){
  2553. cr = grid.width-gw-(initwidth+brd*vc)-scw;
  2554. }
  2555. } else if(!hs && Math.abs(grid.width-gw-(initwidth+brd*vc)) !== 1) {
  2556. cr = grid.width-gw-(initwidth+brd*vc);
  2557. }
  2558. ts.p.colModel[lvc].width += cr;
  2559. ts.p.tblwidth = initwidth+cr+brd*vc+gw;
  2560. if(ts.p.tblwidth > ts.p.width) {
  2561. ts.p.colModel[lvc].width -= (ts.p.tblwidth - parseInt(ts.p.width,10));
  2562. ts.p.tblwidth = ts.p.width;
  2563. }
  2564. }
  2565. },
  2566. nextVisible= function(iCol) {
  2567. var ret = iCol, j=iCol, i;
  2568. for (i = iCol+1;i<ts.p.colModel.length;i++){
  2569. if(ts.p.colModel[i].hidden !== true ) {
  2570. j=i; break;
  2571. }
  2572. }
  2573. return j-ret;
  2574. },
  2575. getOffset = function (iCol) {
  2576. var $th = $(ts.grid.headers[iCol].el), ret = [$th.position().left + $th.outerWidth()];
  2577. if(ts.p.direction==="rtl") { ret[0] = ts.p.width - ret[0]; }
  2578. ret[0] -= ts.grid.bDiv.scrollLeft;
  2579. ret.push($(ts.grid.hDiv).position().top);
  2580. ret.push($(ts.grid.bDiv).offset().top - $(ts.grid.hDiv).offset().top + $(ts.grid.bDiv).height());
  2581. return ret;
  2582. },
  2583. getColumnHeaderIndex = function (th) {
  2584. var i, headers = ts.grid.headers, ci = $.jgrid.getCellIndex(th);
  2585. for (i = 0; i < headers.length; i++) {
  2586. if (th === headers[i].el) {
  2587. ci = i;
  2588. break;
  2589. }
  2590. }
  2591. return ci;
  2592. };
  2593. this.p.id = this.id;
  2594. if ($.inArray(ts.p.multikey,sortkeys) === -1 ) {ts.p.multikey = false;}
  2595. ts.p.keyName=false;
  2596. for (i=0; i<ts.p.colModel.length;i++) {
  2597. ts.p.colModel[i] = $.extend(true, {}, ts.p.cmTemplate, ts.p.colModel[i].template || {}, ts.p.colModel[i]);
  2598. if (ts.p.keyName === false && ts.p.colModel[i].key===true) {
  2599. ts.p.keyName = ts.p.colModel[i].name;
  2600. }
  2601. }
  2602. ts.p.sortorder = ts.p.sortorder.toLowerCase();
  2603. $.jgrid.cell_width = $.jgrid.cellWidth();
  2604. if(ts.p.grouping===true) {
  2605. ts.p.scroll = false;
  2606. ts.p.rownumbers = false;
  2607. //ts.p.subGrid = false; expiremental
  2608. ts.p.treeGrid = false;
  2609. ts.p.gridview = true;
  2610. }
  2611. if(this.p.treeGrid === true) {
  2612. try { $(this).jqGrid("setTreeGrid");} catch (_) {}
  2613. if(ts.p.datatype !== "local") { ts.p.localReader = {id: "_id_"}; }
  2614. }
  2615. if(this.p.subGrid) {
  2616. try { $(ts).jqGrid("setSubGrid");} catch (s){}
  2617. }
  2618. if(this.p.multiselect) {
  2619. this.p.colNames.unshift("<input role='checkbox' id='cb_"+this.p.id+"' class='cbox' type='checkbox'/>");
  2620. 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});
  2621. }
  2622. if(this.p.rownumbers) {
  2623. this.p.colNames.unshift("");
  2624. this.p.colModel.unshift({name:'rn',width:ts.p.rownumWidth,sortable:false,resizable:false,hidedlg:true,search:false,align:'center',fixed:true});
  2625. }
  2626. ts.p.xmlReader = $.extend(true,{
  2627. root: "rows",
  2628. row: "row",
  2629. page: "rows>page",
  2630. total: "rows>total",
  2631. records : "rows>records",
  2632. repeatitems: true,
  2633. cell: "cell",
  2634. id: "[id]",
  2635. userdata: "userdata",
  2636. subgrid: {root:"rows", row: "row", repeatitems: true, cell:"cell"}
  2637. }, ts.p.xmlReader);
  2638. ts.p.jsonReader = $.extend(true,{
  2639. root: "rows",
  2640. page: "page",
  2641. total: "total",
  2642. records: "records",
  2643. repeatitems: true,
  2644. cell: "cell",
  2645. id: "id",
  2646. userdata: "userdata",
  2647. subgrid: {root:"rows", repeatitems: true, cell:"cell"}
  2648. },ts.p.jsonReader);
  2649. ts.p.localReader = $.extend(true,{
  2650. root: "rows",
  2651. page: "page",
  2652. total: "total",
  2653. records: "records",
  2654. repeatitems: false,
  2655. cell: "cell",
  2656. id: "id",
  2657. userdata: "userdata",
  2658. subgrid: {root:"rows", repeatitems: true, cell:"cell"}
  2659. },ts.p.localReader);
  2660. if(ts.p.scroll){
  2661. ts.p.pgbuttons = false; ts.p.pginput=false; ts.p.rowList=[];
  2662. }
  2663. if(ts.p.data.length) { refreshIndex(); }
  2664. var thead = "<thead><tr class='ui-jqgrid-labels' role='rowheader'>",
  2665. tdc, idn, w, res, sort,
  2666. td, ptr, tbody, imgs,iac="",idc="",sortarr=[], sortord=[], sotmp=[];
  2667. if(ts.p.shrinkToFit===true && ts.p.forceFit===true) {
  2668. for (i=ts.p.colModel.length-1;i>=0;i--){
  2669. if(!ts.p.colModel[i].hidden) {
  2670. ts.p.colModel[i].resizable=false;
  2671. break;
  2672. }
  2673. }
  2674. }
  2675. if(ts.p.viewsortcols[1] === 'horizontal') {iac=" ui-i-asc";idc=" ui-i-desc";}
  2676. tdc = isMSIE ? "class='ui-th-div-ie'" :"";
  2677. 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>";
  2678. 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>";
  2679. if(ts.p.multiSort) {
  2680. sortarr = ts.p.sortname.split(",");
  2681. for (i=0; i<sortarr.length; i++) {
  2682. sotmp = $.trim(sortarr[i]).split(" ");
  2683. sortarr[i] = $.trim(sotmp[0]);
  2684. sortord[i] = sotmp[1] ? $.trim(sotmp[1]) : ts.p.sortorder || "asc";
  2685. }
  2686. }
  2687. for(i=0;i<this.p.colNames.length;i++){
  2688. var tooltip = ts.p.headertitles ? (" title=\""+$.jgrid.stripHtml(ts.p.colNames[i])+"\"") :"";
  2689. thead += "<th id='"+ts.p.id+"_"+ts.p.colModel[i].name+"' role='columnheader' class='ui-state-default ui-th-column ui-th-"+dir+"'"+ tooltip+">";
  2690. idn = ts.p.colModel[i].index || ts.p.colModel[i].name;
  2691. thead += "<div id='jqgh_"+ts.p.id+"_"+ts.p.colModel[i].name+"' "+tdc+">"+ts.p.colNames[i];
  2692. if(!ts.p.colModel[i].width) { ts.p.colModel[i].width = 150; }
  2693. else { ts.p.colModel[i].width = parseInt(ts.p.colModel[i].width,10); }
  2694. if(typeof ts.p.colModel[i].title !== "boolean") { ts.p.colModel[i].title = true; }
  2695. ts.p.colModel[i].lso = "";
  2696. if (idn === ts.p.sortname) {
  2697. ts.p.lastsort = i;
  2698. }
  2699. if(ts.p.multiSort) {
  2700. sotmp = $.inArray(idn,sortarr);
  2701. if( sotmp !== -1 ) {
  2702. ts.p.colModel[i].lso = sortord[sotmp];
  2703. }
  2704. }
  2705. thead += imgs+"</div></th>";
  2706. }
  2707. thead += "</tr></thead>";
  2708. imgs = null;
  2709. $(this).append(thead);
  2710. $("thead tr:first th",this).hover(function(){$(this).addClass('ui-state-hover');},function(){$(this).removeClass('ui-state-hover');});
  2711. if(this.p.multiselect) {
  2712. var emp=[], chk;
  2713. $('#cb_'+$.jgrid.jqID(ts.p.id),this).bind('click',function(){
  2714. ts.p.selarrrow = [];
  2715. var froz = ts.p.frozenColumns === true ? ts.p.id + "_frozen" : "";
  2716. if (this.checked) {
  2717. $(ts.rows).each(function(i) {
  2718. if (i>0) {
  2719. if(!$(this).hasClass("ui-subgrid") && !$(this).hasClass("jqgroup") && !$(this).hasClass('ui-state-disabled')){
  2720. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id) )[ts.p.useProp ? 'prop': 'attr']("checked",true);
  2721. $(this).addClass("ui-state-highlight").attr("aria-selected","true");
  2722. ts.p.selarrrow.push(this.id);
  2723. ts.p.selrow = this.id;
  2724. if(froz) {
  2725. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id), ts.grid.fbDiv )[ts.p.useProp ? 'prop': 'attr']("checked",true);
  2726. $("#"+$.jgrid.jqID(this.id), ts.grid.fbDiv).addClass("ui-state-highlight");
  2727. }
  2728. }
  2729. }
  2730. });
  2731. chk=true;
  2732. emp=[];
  2733. }
  2734. else {
  2735. $(ts.rows).each(function(i) {
  2736. if(i>0) {
  2737. if(!$(this).hasClass("ui-subgrid") && !$(this).hasClass('ui-state-disabled')){
  2738. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id) )[ts.p.useProp ? 'prop': 'attr']("checked", false);
  2739. $(this).removeClass("ui-state-highlight").attr("aria-selected","false");
  2740. emp.push(this.id);
  2741. if(froz) {
  2742. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id), ts.grid.fbDiv )[ts.p.useProp ? 'prop': 'attr']("checked",false);
  2743. $("#"+$.jgrid.jqID(this.id), ts.grid.fbDiv).removeClass("ui-state-highlight");
  2744. }
  2745. }
  2746. }
  2747. });
  2748. ts.p.selrow = null;
  2749. chk=false;
  2750. }
  2751. $(ts).triggerHandler("jqGridSelectAll", [chk ? ts.p.selarrrow : emp, chk]);
  2752. if($.isFunction(ts.p.onSelectAll)) {ts.p.onSelectAll.call(ts, chk ? ts.p.selarrrow : emp,chk);}
  2753. });
  2754. }
  2755. if(ts.p.autowidth===true) {
  2756. var pw = $(eg).innerWidth();
  2757. ts.p.width = pw > 0? pw: 'nw';
  2758. }
  2759. setColWidth();
  2760. $(eg).css("width",grid.width+"px").append("<div class='ui-jqgrid-resize-mark' id='rs_m"+ts.p.id+"'>&#160;</div>");
  2761. $(gv).css("width",grid.width+"px");
  2762. thead = $("thead:first",ts).get(0);
  2763. var tfoot = "";
  2764. 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+"'>"; }
  2765. var thr = $("tr:first",thead),
  2766. firstr = "<tr class='jqgfirstrow' role='row' style='height:auto'>";
  2767. ts.p.disableClick=false;
  2768. $("th",thr).each(function ( j ) {
  2769. w = ts.p.colModel[j].width;
  2770. if(ts.p.colModel[j].resizable === undefined) {ts.p.colModel[j].resizable = true;}
  2771. if(ts.p.colModel[j].resizable){
  2772. res = document.createElement("span");
  2773. $(res).html("&#160;").addClass('ui-jqgrid-resize ui-jqgrid-resize-'+dir)
  2774. .css("cursor","col-resize");
  2775. $(this).addClass(ts.p.resizeclass);
  2776. } else {
  2777. res = "";
  2778. }
  2779. $(this).css("width",w+"px").prepend(res);
  2780. res = null;
  2781. var hdcol = "";
  2782. if( ts.p.colModel[j].hidden ) {
  2783. $(this).css("display","none");
  2784. hdcol = "display:none;";
  2785. }
  2786. firstr += "<td role='gridcell' style='height:0px;width:"+w+"px;"+hdcol+"'></td>";
  2787. grid.headers[j] = { width: w, el: this };
  2788. sort = ts.p.colModel[j].sortable;
  2789. if( typeof sort !== 'boolean') {ts.p.colModel[j].sortable = true; sort=true;}
  2790. var nm = ts.p.colModel[j].name;
  2791. if( !(nm === 'cb' || nm==='subgrid' || nm==='rn') ) {
  2792. if(ts.p.viewsortcols[2]){
  2793. $(">div",this).addClass('ui-jqgrid-sortable');
  2794. }
  2795. }
  2796. if(sort) {
  2797. if(ts.p.multiSort) {
  2798. if(ts.p.viewsortcols[0]) {
  2799. $("div span.s-ico",this).show();
  2800. if(ts.p.colModel[j].lso){
  2801. $("div span.ui-icon-"+ts.p.colModel[j].lso,this).removeClass("ui-state-disabled");
  2802. }
  2803. } else if( ts.p.colModel[j].lso) {
  2804. $("div span.s-ico",this).show();
  2805. $("div span.ui-icon-"+ts.p.colModel[j].lso,this).removeClass("ui-state-disabled");
  2806. }
  2807. } else {
  2808. 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");}}
  2809. else if( j === ts.p.lastsort) {$("div span.s-ico",this).show();$("div span.ui-icon-"+ts.p.sortorder,this).removeClass("ui-state-disabled");}
  2810. }
  2811. }
  2812. if(ts.p.footerrow) { tfoot += "<td role='gridcell' "+formatCol(j,0,'', null, '', false)+">&#160;</td>"; }
  2813. }).mousedown(function(e) {
  2814. if ($(e.target).closest("th>span.ui-jqgrid-resize").length !== 1) { return; }
  2815. var ci = getColumnHeaderIndex(this);
  2816. if(ts.p.forceFit===true) {ts.p.nv= nextVisible(ci);}
  2817. grid.dragStart(ci, e, getOffset(ci));
  2818. return false;
  2819. }).click(function(e) {
  2820. //排序
  2821. if (ts.p.disableClick) {
  2822. ts.p.disableClick = false;
  2823. return false;
  2824. }
  2825. var s = "th>div.ui-jqgrid-sortable",r,d;
  2826. if (!ts.p.viewsortcols[2]) { s = "th>div>span>span.ui-grid-ico-sort"; }
  2827. var t = $(e.target).closest(s);
  2828. if (t.length !== 1) { return; }
  2829. var ci;
  2830. if(ts.p.frozenColumns) {
  2831. var tid = $(this)[0].id.substring( ts.p.id.length + 1 );
  2832. $(ts.p.colModel).each(function(i){
  2833. if (this.name === tid) {
  2834. ci = i;return false;
  2835. }
  2836. });
  2837. } else {
  2838. ci = getColumnHeaderIndex(this);
  2839. }
  2840. if (!ts.p.viewsortcols[2]) { r=true;d=t.attr("sort"); }
  2841. if(ci != null){
  2842. //排序
  2843. sortData( $('div',this)[0].id, ci, r, d, this);
  2844. }
  2845. return false;
  2846. });
  2847. if (ts.p.sortable && $.fn.sortable) {
  2848. try {
  2849. $(ts).jqGrid("sortableColumns", thr);
  2850. } catch (e){}
  2851. }
  2852. if(ts.p.footerrow) { tfoot += "</tr></tbody></table>"; }
  2853. firstr += "</tr>";
  2854. tbody = document.createElement("tbody");
  2855. this.appendChild(tbody);
  2856. $(this).addClass('ui-jqgrid-btable').append(firstr);
  2857. firstr = null;
  2858. 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),
  2859. hg = (ts.p.caption && ts.p.hiddengrid===true) ? true : false,
  2860. hb = $("<div class='ui-jqgrid-hbox" + (dir==="rtl" ? "-rtl" : "" )+"'></div>");
  2861. thead = null;
  2862. grid.hDiv = document.createElement("div");
  2863. $(grid.hDiv)
  2864. .css({ width: grid.width+"px"})
  2865. .addClass("ui-state-default ui-jqgrid-hdiv")
  2866. .append(hb);
  2867. $(hb).append(hTable);
  2868. hTable = null;
  2869. if(hg) { $(grid.hDiv).hide(); }
  2870. if(ts.p.pager){
  2871. // TBD -- escape ts.p.pager here?
  2872. if(typeof ts.p.pager === "string") {if(ts.p.pager.substr(0,1) !== "#") { ts.p.pager = "#"+ts.p.pager;} }
  2873. else { ts.p.pager = "#"+ $(ts.p.pager).attr("id");}
  2874. $(ts.p.pager).css({width: grid.width+"px"}).addClass('ui-state-default ui-jqgrid-pager ui-corner-bottom').appendTo(eg);
  2875. if(hg) {$(ts.p.pager).hide();}
  2876. setPager(ts.p.pager,'');
  2877. }
  2878. if( ts.p.cellEdit === false && ts.p.hoverrows === true) {
  2879. $(ts).bind('mouseover',function(e) {
  2880. ptr = $(e.target).closest("tr.jqgrow");
  2881. if($(ptr).attr("class") !== "ui-subgrid") {
  2882. $(ptr).addClass("ui-state-hover");
  2883. }
  2884. }).bind('mouseout',function(e) {
  2885. ptr = $(e.target).closest("tr.jqgrow");
  2886. $(ptr).removeClass("ui-state-hover");
  2887. });
  2888. }
  2889. var ri,ci, tdHtml;
  2890. $(ts).before(grid.hDiv).click(function(e) {
  2891. td = e.target;
  2892. ptr = $(td,ts.rows).closest("tr.jqgrow");
  2893. 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 ) {
  2894. return this;
  2895. }
  2896. var scb = $(td).hasClass("cbox"),
  2897. cSel = $(ts).triggerHandler("jqGridBeforeSelectRow", [ptr[0].id, e]);
  2898. cSel = (cSel === false || cSel === 'stop') ? false : true;
  2899. if(cSel && $.isFunction(ts.p.beforeSelectRow)) { cSel = ts.p.beforeSelectRow.call(ts,ptr[0].id, e); }
  2900. if (td.tagName === 'A' || ((td.tagName === 'INPUT' || td.tagName === 'TEXTAREA' || td.tagName === 'OPTION' || td.tagName === 'SELECT' ) && !scb) ) { return; }
  2901. if(cSel === true) {
  2902. ri = ptr[0].id;
  2903. ci = $.jgrid.getCellIndex(td);
  2904. tdHtml = $(td).closest("td,th").html();
  2905. $(ts).triggerHandler("jqGridCellSelect", [ri,ci,tdHtml,e]);
  2906. if($.isFunction(ts.p.onCellSelect)) {
  2907. ts.p.onCellSelect.call(ts,ri,ci,tdHtml,e);
  2908. }
  2909. if(ts.p.cellEdit === true) {
  2910. if(ts.p.multiselect && scb){
  2911. $(ts).jqGrid("setSelection", ri ,true,e);
  2912. } else {
  2913. ri = ptr[0].rowIndex;
  2914. try {$(ts).jqGrid("editCell",ri,ci,true);} catch (_) {}
  2915. }
  2916. } else if ( !ts.p.multikey ) {
  2917. if(ts.p.multiselect && ts.p.multiboxonly) {
  2918. if(scb){$(ts).jqGrid("setSelection",ri,true,e);}
  2919. else {
  2920. var frz = ts.p.frozenColumns ? ts.p.id+"_frozen" : "";
  2921. $(ts.p.selarrrow).each(function(i,n){
  2922. var trid = $(ts).jqGrid('getGridRowById',n);
  2923. if(trid) { $( trid ).removeClass("ui-state-highlight"); }
  2924. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(n))[ts.p.useProp ? 'prop': 'attr']("checked", false);
  2925. if(frz) {
  2926. $("#"+$.jgrid.jqID(n), "#"+$.jgrid.jqID(frz)).removeClass("ui-state-highlight");
  2927. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(n), "#"+$.jgrid.jqID(frz))[ts.p.useProp ? 'prop': 'attr']("checked", false);
  2928. }
  2929. });
  2930. ts.p.selarrrow = [];
  2931. $(ts).jqGrid("setSelection",ri,true,e);
  2932. }
  2933. } else {
  2934. $(ts).jqGrid("setSelection",ri,true,e);
  2935. }
  2936. } else {
  2937. if(e[ts.p.multikey]) {
  2938. $(ts).jqGrid("setSelection",ri,true,e);
  2939. } else if(ts.p.multiselect && scb) {
  2940. scb = $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+ri).is(":checked");
  2941. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+ri)[ts.p.useProp ? 'prop' : 'attr']("checked", scb);
  2942. }
  2943. }
  2944. }
  2945. }).bind('reloadGrid', function(e,opts) {
  2946. if(ts.p.treeGrid ===true) { ts.p.datatype = ts.p.treedatatype;}
  2947. if (opts && opts.current) {
  2948. ts.grid.selectionPreserver(ts);
  2949. }
  2950. if(ts.p.datatype==="local"){ $(ts).jqGrid("resetSelection"); if(ts.p.data.length) { refreshIndex();} }
  2951. else if(!ts.p.treeGrid) {
  2952. ts.p.selrow=null;
  2953. if(ts.p.multiselect) {ts.p.selarrrow =[];setHeadCheckBox(false);}
  2954. ts.p.savedRow = [];
  2955. }
  2956. if(ts.p.scroll) {emptyRows.call(ts, true, false);}
  2957. if (opts && opts.page) {
  2958. var page = opts.page;
  2959. if (page > ts.p.lastpage) { page = ts.p.lastpage; }
  2960. if (page < 1) { page = 1; }
  2961. ts.p.page = page;
  2962. if (ts.grid.prevRowHeight) {
  2963. ts.grid.bDiv.scrollTop = (page - 1) * ts.grid.prevRowHeight * ts.p.rowNum;
  2964. } else {
  2965. ts.grid.bDiv.scrollTop = 0;
  2966. }
  2967. }
  2968. if (ts.grid.prevRowHeight && ts.p.scroll) {
  2969. delete ts.p.lastpage;
  2970. ts.grid.populateVisible();
  2971. } else {
  2972. ts.grid.populate();
  2973. }
  2974. if(ts.p._inlinenav===true) {$(ts).jqGrid('showAddEditButtons');}
  2975. return false;
  2976. })
  2977. .dblclick(function(e) {
  2978. td = e.target;
  2979. ptr = $(td,ts.rows).closest("tr.jqgrow");
  2980. if($(ptr).length === 0 ){return;}
  2981. ri = ptr[0].rowIndex;
  2982. ci = $.jgrid.getCellIndex(td);
  2983. $(ts).triggerHandler("jqGridDblClickRow", [$(ptr).attr("id"),ri,ci,e]);
  2984. if ($.isFunction(ts.p.ondblClickRow)) { ts.p.ondblClickRow.call(ts,$(ptr).attr("id"),ri,ci, e); }
  2985. })
  2986. .bind('contextmenu', function(e) {
  2987. td = e.target;
  2988. ptr = $(td,ts.rows).closest("tr.jqgrow");
  2989. if($(ptr).length === 0 ){return;}
  2990. if(!ts.p.multiselect) { $(ts).jqGrid("setSelection",ptr[0].id,true,e); }
  2991. ri = ptr[0].rowIndex;
  2992. ci = $.jgrid.getCellIndex(td);
  2993. $(ts).triggerHandler("jqGridRightClickRow", [$(ptr).attr("id"),ri,ci,e]);
  2994. if ($.isFunction(ts.p.onRightClickRow)) { ts.p.onRightClickRow.call(ts,$(ptr).attr("id"),ri,ci, e); }
  2995. });
  2996. grid.bDiv = document.createElement("div");
  2997. if(isMSIE) { if(String(ts.p.height).toLowerCase() === "auto") { ts.p.height = "100%"; } }
  2998. $(grid.bDiv)
  2999. .append($('<div style="position:relative;'+(isMSIE && $.jgrid.msiever() < 8 ? "height:0.01%;" : "")+'"></div>').append('<div></div>').append(this))
  3000. .addClass("ui-jqgrid-bdiv")
  3001. .css({ height: ts.p.height+(isNaN(ts.p.height)?"":"px"), width: (grid.width)+"px"})
  3002. .scroll(grid.scrollGrid);
  3003. $("table:first",grid.bDiv).css({width:ts.p.tblwidth+"px"});
  3004. if( !$.support.tbody ) { //IE
  3005. if( $("tbody",this).length === 2 ) { $("tbody:gt(0)",this).remove();}
  3006. }
  3007. if(ts.p.multikey){
  3008. if( $.jgrid.msie) {
  3009. $(grid.bDiv).bind("selectstart",function(){return false;});
  3010. } else {
  3011. $(grid.bDiv).bind("mousedown",function(){return false;});
  3012. }
  3013. }
  3014. if(hg) {$(grid.bDiv).hide();}
  3015. grid.cDiv = document.createElement("div");
  3016. var arf = ts.p.hidegrid===true ? $("<a role='link' class='ui-jqgrid-titlebar-close ui-corner-all HeaderButton' />").hover(
  3017. function(){ arf.addClass('ui-state-hover');},
  3018. function() {arf.removeClass('ui-state-hover');})
  3019. .append("<span class='ui-icon ui-icon-circle-triangle-n'></span>").css((dir==="rtl"?"left":"right"),"0px") : "";
  3020. $(grid.cDiv).append(arf).append("<span class='ui-jqgrid-title'>"+ts.p.caption+"</span>")
  3021. .addClass("ui-jqgrid-titlebar ui-jqgrid-caption"+(dir==="rtl" ? "-rtl" :"" )+" ui-widget-header ui-corner-top ui-helper-clearfix");
  3022. $(grid.cDiv).insertBefore(grid.hDiv);
  3023. if( ts.p.toolbar[0] ) {
  3024. grid.uDiv = document.createElement("div");
  3025. if(ts.p.toolbar[1] === "top") {$(grid.uDiv).insertBefore(grid.hDiv);}
  3026. else if (ts.p.toolbar[1]==="bottom" ) {$(grid.uDiv).insertAfter(grid.hDiv);}
  3027. if(ts.p.toolbar[1]==="both") {
  3028. grid.ubDiv = document.createElement("div");
  3029. $(grid.uDiv).addClass("ui-userdata ui-state-default").attr("id","t_"+this.id).insertBefore(grid.hDiv);
  3030. $(grid.ubDiv).addClass("ui-userdata ui-state-default").attr("id","tb_"+this.id).insertAfter(grid.hDiv);
  3031. if(hg) {$(grid.ubDiv).hide();}
  3032. } else {
  3033. $(grid.uDiv).width(grid.width).addClass("ui-userdata ui-state-default").attr("id","t_"+this.id);
  3034. }
  3035. if(hg) {$(grid.uDiv).hide();}
  3036. }
  3037. if(ts.p.toppager) {
  3038. ts.p.toppager = $.jgrid.jqID(ts.p.id)+"_toppager";
  3039. grid.topDiv = $("<div id='"+ts.p.toppager+"'></div>")[0];
  3040. ts.p.toppager = "#"+ts.p.toppager;
  3041. $(grid.topDiv).addClass('ui-state-default ui-jqgrid-toppager').width(grid.width).insertBefore(grid.hDiv);
  3042. setPager(ts.p.toppager,'_t');
  3043. }
  3044. if(ts.p.footerrow) {
  3045. grid.sDiv = $("<div class='ui-jqgrid-sdiv'></div>")[0];
  3046. hb = $("<div class='ui-jqgrid-hbox"+(dir==="rtl"?"-rtl":"")+"'></div>");
  3047. $(grid.sDiv).append(hb).width(grid.width).insertAfter(grid.hDiv);
  3048. $(hb).append(tfoot);
  3049. grid.footers = $(".ui-jqgrid-ftable",grid.sDiv)[0].rows[0].cells;
  3050. if(ts.p.rownumbers) { grid.footers[0].className = 'ui-state-default jqgrid-rownum'; }
  3051. if(hg) {$(grid.sDiv).hide();}
  3052. }
  3053. hb = null;
  3054. if(ts.p.caption) {
  3055. var tdt = ts.p.datatype;
  3056. if(ts.p.hidegrid===true) {
  3057. $(".ui-jqgrid-titlebar-close",grid.cDiv).click( function(e){
  3058. var onHdCl = $.isFunction(ts.p.onHeaderClick),
  3059. elems = ".ui-jqgrid-bdiv, .ui-jqgrid-hdiv, .ui-jqgrid-pager, .ui-jqgrid-sdiv",
  3060. counter, self = this;
  3061. if(ts.p.toolbar[0]===true) {
  3062. if( ts.p.toolbar[1]==='both') {
  3063. elems += ', #' + $(grid.ubDiv).attr('id');
  3064. }
  3065. elems += ', #' + $(grid.uDiv).attr('id');
  3066. }
  3067. counter = $(elems,"#gview_"+$.jgrid.jqID(ts.p.id)).length;
  3068. if(ts.p.gridstate === 'visible') {
  3069. $(elems,"#gbox_"+$.jgrid.jqID(ts.p.id)).slideUp("fast", function() {
  3070. counter--;
  3071. if (counter === 0) {
  3072. $("span",self).removeClass("ui-icon-circle-triangle-n").addClass("ui-icon-circle-triangle-s");
  3073. ts.p.gridstate = 'hidden';
  3074. if($("#gbox_"+$.jgrid.jqID(ts.p.id)).hasClass("ui-resizable")) { $(".ui-resizable-handle","#gbox_"+$.jgrid.jqID(ts.p.id)).hide(); }
  3075. $(ts).triggerHandler("jqGridHeaderClick", [ts.p.gridstate,e]);
  3076. if(onHdCl) {if(!hg) {ts.p.onHeaderClick.call(ts,ts.p.gridstate,e);}}
  3077. }
  3078. });
  3079. } else if(ts.p.gridstate === 'hidden'){
  3080. $(elems,"#gbox_"+$.jgrid.jqID(ts.p.id)).slideDown("fast", function() {
  3081. counter--;
  3082. if (counter === 0) {
  3083. $("span",self).removeClass("ui-icon-circle-triangle-s").addClass("ui-icon-circle-triangle-n");
  3084. if(hg) {ts.p.datatype = tdt;populate();hg=false;}
  3085. ts.p.gridstate = 'visible';
  3086. if($("#gbox_"+$.jgrid.jqID(ts.p.id)).hasClass("ui-resizable")) { $(".ui-resizable-handle","#gbox_"+$.jgrid.jqID(ts.p.id)).show(); }
  3087. $(ts).triggerHandler("jqGridHeaderClick", [ts.p.gridstate,e]);
  3088. if(onHdCl) {if(!hg) {ts.p.onHeaderClick.call(ts,ts.p.gridstate,e);}}
  3089. }
  3090. });
  3091. }
  3092. return false;
  3093. });
  3094. if(hg) {ts.p.datatype="local"; $(".ui-jqgrid-titlebar-close",grid.cDiv).trigger("click");}
  3095. }
  3096. } else {$(grid.cDiv).hide();}
  3097. $(grid.hDiv).after(grid.bDiv)
  3098. .mousemove(function (e) {
  3099. if(grid.resizing){grid.dragMove(e);return false;}
  3100. });
  3101. $(".ui-jqgrid-labels",grid.hDiv).bind("selectstart", function () { return false; });
  3102. $(document).bind( "mouseup.jqGrid" + ts.p.id, function () {
  3103. if(grid.resizing) { grid.dragEnd(); return false;}
  3104. return true;
  3105. });
  3106. ts.formatCol = formatCol;
  3107. ts.sortData = sortData;
  3108. ts.updatepager = updatepager;
  3109. ts.refreshIndex = refreshIndex;
  3110. ts.setHeadCheckBox = setHeadCheckBox;
  3111. ts.constructTr = constructTr;
  3112. ts.formatter = function ( rowId, cellval , colpos, rwdat, act){return formatter(rowId, cellval , colpos, rwdat, act);};
  3113. $.extend(grid,{populate : populate, emptyRows: emptyRows, beginReq: beginReq, endReq: endReq});
  3114. this.grid = grid;
  3115. ts.addXmlData = function(d) {addXmlData(d,ts.grid.bDiv);};
  3116. ts.addJSONData = function(d) {addJSONData(d,ts.grid.bDiv);};
  3117. this.grid.cols = this.rows[0].cells;
  3118. $(ts).triggerHandler("jqGridInitGrid");
  3119. if ($.isFunction( ts.p.onInitGrid )) { ts.p.onInitGrid.call(ts); }
  3120. populate();ts.p.hiddengrid=false;
  3121. });
  3122. };
  3123. $.jgrid.extend({
  3124. getGridParam : function(pName) {
  3125. var $t = this[0];
  3126. if (!$t || !$t.grid) {return;}
  3127. if (!pName) { return $t.p; }
  3128. return $t.p[pName] !== undefined ? $t.p[pName] : null;
  3129. },
  3130. setGridParam : function (newParams){
  3131. return this.each(function(){
  3132. if (this.grid && typeof newParams === 'object') {$.extend(true,this.p,newParams);}
  3133. });
  3134. },
  3135. getGridRowById: function ( rowid ) {
  3136. var row;
  3137. this.each( function(){
  3138. try {
  3139. //row = this.rows.namedItem( rowid );
  3140. var i = this.rows.length;
  3141. while(i--) {
  3142. if( rowid.toString() === this.rows[i].id) {
  3143. row = this.rows[i];
  3144. break;
  3145. }
  3146. }
  3147. } catch ( e ) {
  3148. row = $(this.grid.bDiv).find( "#" + $.jgrid.jqID( rowid ));
  3149. }
  3150. });
  3151. return row;
  3152. },
  3153. getDataIDs : function () {
  3154. var ids=[], i=0, len, j=0;
  3155. this.each(function(){
  3156. len = this.rows.length;
  3157. if(len && len>0){
  3158. while(i<len) {
  3159. if($(this.rows[i]).hasClass('jqgrow')) {
  3160. ids[j] = this.rows[i].id;
  3161. j++;
  3162. }
  3163. i++;
  3164. }
  3165. }
  3166. });
  3167. return ids;
  3168. },
  3169. setAllChecked : function (selected) {
  3170. return this.each(function(){
  3171. var $t = this;
  3172. $t.p.checkArray=selected;
  3173. $t.p.selarrrow=selected;
  3174. $("#"+$t.p.configId).data('_allChecked',true);
  3175. });
  3176. },
  3177. setSelection : function(selection,onsr, e) {
  3178. return this.each(function(){
  3179. var $t = this, stat,pt, ner, ia, tpsr, fid, csr;
  3180. if(selection === undefined) { return; }
  3181. onsr = onsr === false ? false : true;
  3182. pt=$($t).jqGrid('getGridRowById', selection);
  3183. if(!pt || !pt.className || pt.className.indexOf( 'ui-state-disabled' ) > -1 ) { return; }
  3184. function scrGrid(iR){
  3185. var ch = $($t.grid.bDiv)[0].clientHeight,
  3186. st = $($t.grid.bDiv)[0].scrollTop,
  3187. rpos = $($t.rows[iR]).position().top,
  3188. rh = $t.rows[iR].clientHeight;
  3189. if(rpos+rh >= ch+st) { $($t.grid.bDiv)[0].scrollTop = rpos-(ch+st)+rh+st; }
  3190. else if(rpos < ch+st) {
  3191. if(rpos < st) {
  3192. $($t.grid.bDiv)[0].scrollTop = rpos;
  3193. }
  3194. }
  3195. }
  3196. if($t.p.scrollrows===true) {
  3197. ner = $($t).jqGrid('getGridRowById',selection).rowIndex;
  3198. if(ner >=0 ){
  3199. scrGrid(ner);
  3200. }
  3201. }
  3202. if($t.p.frozenColumns === true ) {
  3203. fid = $t.p.id+"_frozen";
  3204. }
  3205. if(!$t.p.multiselect) {
  3206. if(pt.className !== "ui-subgrid") {
  3207. if( $t.p.selrow !== pt.id ) {
  3208. csr = $($t).jqGrid('getGridRowById', $t.p.selrow);
  3209. if( csr ) {
  3210. $( csr ).removeClass("ui-state-highlight").attr({"aria-selected":"false", "tabindex" : "-1"});
  3211. }
  3212. $(pt).addClass("ui-state-highlight").attr({"aria-selected":"true", "tabindex" : "0"});//.focus();
  3213. if(fid) {
  3214. $("#"+$.jgrid.jqID($t.p.selrow), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight");
  3215. $("#"+$.jgrid.jqID(selection), "#"+$.jgrid.jqID(fid)).addClass("ui-state-highlight");
  3216. }
  3217. stat = true;
  3218. } else {
  3219. stat = false;
  3220. }
  3221. $t.p.selrow = pt.id;
  3222. if( onsr ) {
  3223. $($t).triggerHandler("jqGridSelectRow", [pt.id, stat, e]);
  3224. if( $t.p.onSelectRow) { $t.p.onSelectRow.call($t, pt.id, stat, e); }
  3225. }
  3226. }
  3227. } else {
  3228. //unselect selectall checkbox when deselecting a specific row
  3229. $t.setHeadCheckBox( false );
  3230. $t.p.selrow = pt.id;
  3231. ia = $.inArray($t.p.selrow,$t.p.selarrrow);
  3232. if ( ia === -1 ){
  3233. if(pt.className !== "ui-subgrid") { $(pt).addClass("ui-state-highlight").attr("aria-selected","true");}
  3234. stat = true;
  3235. $t.p.selarrrow.push($t.p.selrow);
  3236. } else {
  3237. if(pt.className !== "ui-subgrid") { $(pt).removeClass("ui-state-highlight").attr("aria-selected","false");}
  3238. stat = false;
  3239. $t.p.selarrrow.splice(ia,1);
  3240. tpsr = $t.p.selarrrow[0];
  3241. $t.p.selrow = (tpsr === undefined) ? null : tpsr;
  3242. }
  3243. $("#jqg_"+$.jgrid.jqID($t.p.id)+"_"+$.jgrid.jqID(pt.id))[$t.p.useProp ? 'prop': 'attr']("checked",stat);
  3244. if(fid) {
  3245. if(ia === -1) {
  3246. $("#"+$.jgrid.jqID(selection), "#"+$.jgrid.jqID(fid)).addClass("ui-state-highlight");
  3247. } else {
  3248. $("#"+$.jgrid.jqID(selection), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight");
  3249. }
  3250. $("#jqg_"+$.jgrid.jqID($t.p.id)+"_"+$.jgrid.jqID(selection), "#"+$.jgrid.jqID(fid))[$t.p.useProp ? 'prop': 'attr']("checked",stat);
  3251. }
  3252. if( onsr ) {
  3253. $($t).triggerHandler("jqGridSelectRow", [pt.id, stat, e]);
  3254. if( $t.p.onSelectRow) { $t.p.onSelectRow.call($t, pt.id , stat, e); }
  3255. }
  3256. }
  3257. });
  3258. },
  3259. resetSelection : function( rowid ){
  3260. return this.each(function(){
  3261. var t = this, sr, fid;
  3262. if( t.p.frozenColumns === true ) {
  3263. fid = t.p.id+"_frozen";
  3264. }
  3265. if(rowid !== undefined ) {
  3266. sr = rowid === t.p.selrow ? t.p.selrow : rowid;
  3267. $("#"+$.jgrid.jqID(t.p.id)+" tbody:first tr#"+$.jgrid.jqID(sr)).removeClass("ui-state-highlight").attr("aria-selected","false");
  3268. if (fid) { $("#"+$.jgrid.jqID(sr), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight"); }
  3269. if(t.p.multiselect) {
  3270. $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(sr), "#"+$.jgrid.jqID(t.p.id))[t.p.useProp ? 'prop': 'attr']("checked",false);
  3271. if(fid) { $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(sr), "#"+$.jgrid.jqID(fid))[t.p.useProp ? 'prop': 'attr']("checked",false); }
  3272. t.setHeadCheckBox( false);
  3273. }
  3274. sr = null;
  3275. } else if(!t.p.multiselect) {
  3276. if(t.p.selrow) {
  3277. $("#"+$.jgrid.jqID(t.p.id)+" tbody:first tr#"+$.jgrid.jqID(t.p.selrow)).removeClass("ui-state-highlight").attr("aria-selected","false");
  3278. if(fid) { $("#"+$.jgrid.jqID(t.p.selrow), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight"); }
  3279. t.p.selrow = null;
  3280. }
  3281. } else {
  3282. $(t.p.selarrrow).each(function(i,n){
  3283. $( $(t).jqGrid('getGridRowById',n) ).removeClass("ui-state-highlight").attr("aria-selected","false");
  3284. $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(n))[t.p.useProp ? 'prop': 'attr']("checked",false);
  3285. if(fid) {
  3286. $("#"+$.jgrid.jqID(n), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight");
  3287. $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(n), "#"+$.jgrid.jqID(fid))[t.p.useProp ? 'prop': 'attr']("checked",false);
  3288. }
  3289. });
  3290. t.setHeadCheckBox( false );
  3291. t.p.selarrrow = [];
  3292. t.p.selrow = null;
  3293. }
  3294. if(t.p.cellEdit === true) {
  3295. if(parseInt(t.p.iCol,10)>=0 && parseInt(t.p.iRow,10)>=0) {
  3296. $("td:eq("+t.p.iCol+")",t.rows[t.p.iRow]).removeClass("edit-cell ui-state-highlight");
  3297. $(t.rows[t.p.iRow]).removeClass("selected-row ui-state-hover");
  3298. }
  3299. }
  3300. t.p.savedRow = [];
  3301. });
  3302. },
  3303. getEditRowData : function( rowid ) {
  3304. var res = {},res2 = {},res3 = {}, resall, getall=false, len, j=0;
  3305. this.each(function(){
  3306. var $t = this,nm,ind,cm;
  3307. if(rowid === undefined) {
  3308. getall = true;
  3309. resall = [];
  3310. len = $t.rows.length;
  3311. } else {
  3312. ind = $($t).jqGrid('getGridRowById', rowid);
  3313. if(!ind) { return res; }
  3314. len = 2;
  3315. }
  3316. while(j<len){
  3317. if(getall) { ind = $t.rows[j]; }
  3318. if( $(ind).hasClass('jqgrow') ) {
  3319. var editable = $(ind).attr("editable");
  3320. if(editable=="1"){//编辑模式下获取rowdata
  3321. $('TD',ind).each( function(i) {
  3322. cm = $t.p.colModel[i];
  3323. nm = cm.name;
  3324. if ( nm !== 'cb' && nm !== 'subgrid' && cm.editable===true && nm !== 'rn' && !$(this).hasClass('not-editable-cell')) {
  3325. switch (cm.edittype) {
  3326. case "checkbox":
  3327. var cbv = ["Yes","No"];
  3328. if(cm.editoptions ) {
  3329. cbv = cm.editoptions.value.split(":");
  3330. }
  3331. res[nm]= $("input",this).is(":checked") ? cbv[0] : cbv[1];
  3332. break;
  3333. case 'text':
  3334. case 'password':
  3335. case 'textarea':
  3336. case "button" :
  3337. res[nm]=$("input, textarea",this).val();
  3338. break;
  3339. case 'select':
  3340. if(!cm.editoptions.multiple) {
  3341. res[nm]=$("input",this).val();
  3342. } else {
  3343. res[nm]=$("input",this).val();
  3344. }
  3345. if(cm.formatter && cm.formatter === 'select') { res2={}; }
  3346. break;
  3347. case 'select2':
  3348. if(!cm.editoptions.multiple) {
  3349. res[nm] = $("select option:selected",this).val();
  3350. res2[nm] = $("select option:selected", this).text();
  3351. } else {
  3352. var sel = $("select",this), selectedText = [];
  3353. res[nm] = $(sel).val();
  3354. if(res[nm]) { res[nm]= res[nm].join(","); } else { res[nm] =""; }
  3355. $("select option:selected",this).each(
  3356. function(i,selected){
  3357. selectedText[i] = $(selected).text();
  3358. }
  3359. );
  3360. res2[nm] = selectedText.join(",");
  3361. }
  3362. if(cm.formatter && cm.formatter === 'select') { res2={}; }
  3363. break;
  3364. case 'custom' :
  3365. try {
  3366. if(cm.editoptions && $.isFunction(cm.editoptions.custom_value)) {
  3367. res[nm] = cm.editoptions.custom_value.call($t, $(".customelement",this),'get');
  3368. if (res[nm] === undefined) { throw "e2"; }
  3369. } else { throw "e1"; }
  3370. } catch (e) {
  3371. if (e==="e1") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.nodefined,$.jgrid.edit.bClose); }
  3372. if (e==="e2") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose); }
  3373. else { $.jgrid.info_dialog($.jgrid.errors.errcap,e.message,$.jgrid.edit.bClose); }
  3374. }
  3375. break;
  3376. }
  3377. // cv = $.jgrid.checkValues.call($t,res[nm],i);
  3378. // if(cv[0] === false) {
  3379. // return false;
  3380. // }
  3381. if($t.p.autoencode) { res[nm] = $.jgrid.htmlEncode(res[nm]); }
  3382. }else if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn'){
  3383. if($t.p.treeGrid===true && nm === $t.p.ExpandColumn) {
  3384. res[nm] = $.jgrid.htmlDecode($("span:first",this).html());
  3385. } else {
  3386. try {
  3387. res[nm] = $.unformat.call($t,this,{rowId:ind.id, colModel:$t.p.colModel[i]},i);
  3388. } catch (e){
  3389. res[nm] = $.jgrid.htmlDecode($(this).html());
  3390. }
  3391. }
  3392. }
  3393. });
  3394. }else{//
  3395. $('td[role="gridcell"]',ind).each( function(i) {
  3396. nm = $t.p.colModel[i].name;
  3397. if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn') {
  3398. if($t.p.treeGrid===true && nm === $t.p.ExpandColumn) {
  3399. res[nm] = $.jgrid.htmlDecode($("span:first",this).html());
  3400. } else {
  3401. try {
  3402. res[nm] = $.unformat.call($t,this,{rowId:ind.id, colModel:$t.p.colModel[i]},i);
  3403. } catch (e){
  3404. res[nm] = $.jgrid.htmlDecode($(this).html());
  3405. }
  3406. }
  3407. }
  3408. });
  3409. }
  3410. if(getall) { resall.push(res); res={}; }
  3411. }
  3412. j++;
  3413. }
  3414. });
  3415. return resall || res;
  3416. },
  3417. getRowData : function( rowid ) {
  3418. var res = {}, resall, getall=false, len, j=0;
  3419. this.each(function(){
  3420. var $t = this,nm,ind;
  3421. if(rowid === undefined) {
  3422. getall = true;
  3423. resall = [];
  3424. len = $t.rows.length;
  3425. } else {
  3426. ind = $($t).jqGrid('getGridRowById', rowid);
  3427. if(!ind) { return res; }
  3428. len = 2;
  3429. }
  3430. while(j<len){
  3431. if(getall) { ind = $t.rows[j]; }
  3432. if( $(ind).hasClass('jqgrow') ) {
  3433. $('td[role="gridcell"]',ind).each( function(i) {
  3434. nm = $t.p.colModel[i].name;
  3435. if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn') {
  3436. if($t.p.treeGrid===true && nm === $t.p.ExpandColumn) {
  3437. res[nm] = $.jgrid.htmlDecode($("span:first",this).html());
  3438. } else {
  3439. try {
  3440. res[nm] = $.unformat.call($t,this,{rowId:ind.id, colModel:$t.p.colModel[i]},i);
  3441. } catch (e){
  3442. res[nm] = $.jgrid.htmlDecode($(this).html());
  3443. }
  3444. }
  3445. }
  3446. });
  3447. if(getall) { resall.push(res); res={}; }
  3448. }
  3449. j++;
  3450. }
  3451. });
  3452. return resall || res;
  3453. },
  3454. delRowData : function(rowid) {
  3455. var success = false, rowInd, ia, nextRow;
  3456. this.each(function() {
  3457. var $t = this;
  3458. rowInd = $($t).jqGrid('getGridRowById', rowid);
  3459. if(!rowInd) {return false;}
  3460. if($t.p.subGrid) {
  3461. nextRow = $(rowInd).next();
  3462. if(nextRow.hasClass('ui-subgrid')) {
  3463. nextRow.remove();
  3464. }
  3465. }
  3466. $(rowInd).remove();
  3467. $t.p.records--;
  3468. $t.p.reccount--;
  3469. $t.updatepager(true,false);
  3470. success=true;
  3471. if($t.p.multiselect) {
  3472. ia = $.inArray(rowid,$t.p.selarrrow);
  3473. if(ia !== -1) { $t.p.selarrrow.splice(ia,1);}
  3474. }
  3475. if ($t.p.multiselect && $t.p.selarrrow.length > 0) {
  3476. $t.p.selrow = $t.p.selarrrow[$t.p.selarrrow.length-1];
  3477. } else {
  3478. $t.p.selrow = null;
  3479. }
  3480. if($t.p.datatype === 'local') {
  3481. var id = $.jgrid.stripPref($t.p.idPrefix, rowid),
  3482. pos = $t.p._index[id];
  3483. if(pos !== undefined) {
  3484. $t.p.data.splice(pos,1);
  3485. $t.refreshIndex();
  3486. }
  3487. }
  3488. if( $t.p.altRows === true && success ) {
  3489. var cn = $t.p.altclass;
  3490. $($t.rows).each(function(i){
  3491. if(i % 2 === 1) { $(this).addClass(cn); }
  3492. else { $(this).removeClass(cn); }
  3493. });
  3494. }
  3495. });
  3496. return success;
  3497. },
  3498. setRowData : function(rowid, data, cssp) {
  3499. var nm, success=true, title;
  3500. this.each(function(){
  3501. if(!this.grid) {return false;}
  3502. var t = this, vl, ind, cp = typeof cssp, lcdata={};
  3503. ind = $(this).jqGrid('getGridRowById', rowid);
  3504. if(!ind) { return false; }
  3505. if( data ) {
  3506. try {
  3507. $(this.p.colModel).each(function(i){
  3508. nm = this.name;
  3509. var dval =$.jgrid.getAccessor(data,nm);
  3510. if( dval !== undefined) {
  3511. lcdata[nm] = this.formatter && typeof this.formatter === 'string' && this.formatter === 'date' ? $.unformat.date.call(t,dval,this) : dval;
  3512. vl = t.formatter( rowid, dval, i, data, 'edit');
  3513. title = this.title ? {"title":$.jgrid.stripHtml(vl)} : {};
  3514. if(t.p.treeGrid===true && nm === t.p.ExpandColumn) {
  3515. $("td[role='gridcell']:eq("+i+") > span:first",ind).html(vl).attr(title);
  3516. } else {
  3517. $("td[role='gridcell']:eq("+i+")",ind).html(vl).attr(title);
  3518. }
  3519. }
  3520. });
  3521. if(t.p.datatype === 'local') {
  3522. var id = $.jgrid.stripPref(t.p.idPrefix, rowid),
  3523. pos = t.p._index[id], key;
  3524. if(t.p.treeGrid) {
  3525. for(key in t.p.treeReader){
  3526. if(t.p.treeReader.hasOwnProperty(key)) {
  3527. delete lcdata[t.p.treeReader[key]];
  3528. }
  3529. }
  3530. }
  3531. if(pos !== undefined) {
  3532. t.p.data[pos] = $.extend(true, t.p.data[pos], lcdata);
  3533. }
  3534. lcdata = null;
  3535. }
  3536. } catch (e) {
  3537. success = false;
  3538. }
  3539. }
  3540. if(success) {
  3541. if(cp === 'string') {$(ind).addClass(cssp);} else if(cssp !== null && cp === 'object') {$(ind).css(cssp);}
  3542. $(t).triggerHandler("jqGridAfterGridComplete");
  3543. }
  3544. });
  3545. return success;
  3546. },
  3547. addRowData : function(rowid,rdata,pos,src) {
  3548. if(!pos) {pos = "last";}
  3549. var success = false, nm, row, gi, si, ni,sind, i, v, prp="", aradd, cnm, cn, data, cm, id;
  3550. if(rdata) {
  3551. if($.isArray(rdata)) {
  3552. aradd=true;
  3553. pos = "last";
  3554. cnm = rowid;
  3555. } else {
  3556. rdata = [rdata];
  3557. aradd = false;
  3558. }
  3559. this.each(function() {
  3560. var t = this, datalen = rdata.length;
  3561. ni = t.p.rownumbers===true ? 1 :0;
  3562. gi = t.p.multiselect ===true ? 1 :0;
  3563. si = t.p.subGrid===true ? 1 :0;
  3564. if(!aradd) {
  3565. if(rowid !== undefined) { rowid = String(rowid);}
  3566. else {
  3567. rowid = "NEWDATA_"+$.jgrid.randId();
  3568. if(t.p.keyName !== false) {
  3569. cnm = t.p.keyName;
  3570. if(rdata[0][cnm] !== undefined) { rowid = rdata[0][cnm]; }
  3571. }
  3572. }
  3573. }
  3574. cn = t.p.altclass;
  3575. var k = 0, cna ="", lcdata = {},
  3576. air = $.isFunction(t.p.afterInsertRow) ? true : false;
  3577. while(k < datalen) {
  3578. data = rdata[k];
  3579. row=[];
  3580. if(aradd) {
  3581. try {
  3582. rowid = data[cnm];
  3583. if(rowid===undefined) {
  3584. rowid = $.jgrid.randId();
  3585. }
  3586. }
  3587. catch (e) {rowid = $.jgrid.randId();}
  3588. cna = t.p.altRows === true ? (t.rows.length-1)%2 === 0 ? cn : "" : "";
  3589. }
  3590. id = rowid;
  3591. rowid = t.p.idPrefix + rowid;
  3592. if(ni){
  3593. prp = t.formatCol(0,1,'',null,rowid, true);
  3594. row[row.length] = "<td role=\"gridcell\" class=\"ui-state-default jqgrid-rownum\" "+prp+">0</td>";
  3595. }
  3596. if(gi) {
  3597. v = "<input role=\"checkbox\" type=\"checkbox\""+" id=\"jqg_"+t.p.id+"_"+rowid+"\" class=\"cbox\"/>";
  3598. prp = t.formatCol(ni,1,'', null, rowid, true);
  3599. row[row.length] = "<td role=\"gridcell\" "+prp+">"+v+"</td>";
  3600. }
  3601. if(si) {
  3602. row[row.length] = $(t).jqGrid("addSubGridCell",gi+ni,1);
  3603. }
  3604. for(i = gi+si+ni; i < t.p.colModel.length;i++){
  3605. cm = t.p.colModel[i];
  3606. nm = cm.name;
  3607. lcdata[nm] = data[nm];
  3608. v = t.formatter( rowid, $.jgrid.getAccessor(data,nm), i, data );
  3609. prp = t.formatCol(i,1,v, data, rowid, lcdata);
  3610. row[row.length] = "<td role=\"gridcell\" "+prp+">"+v+"</td>";
  3611. }
  3612. row.unshift( t.constructTr(rowid, false, cna, lcdata, data, false ) );
  3613. row[row.length] = "</tr>";
  3614. if(t.rows.length === 0){
  3615. $("table:first",t.grid.bDiv).append(row.join(''));
  3616. } else {
  3617. switch (pos) {
  3618. case 'last':
  3619. $(t.rows[t.rows.length-1]).after(row.join(''));
  3620. sind = t.rows.length-1;
  3621. break;
  3622. case 'first':
  3623. $(t.rows[0]).after(row.join(''));
  3624. sind = 1;
  3625. break;
  3626. case 'after':
  3627. sind = $(t).jqGrid('getGridRowById', src);
  3628. if (sind) {
  3629. if($(t.rows[sind.rowIndex+1]).hasClass("ui-subgrid")) { $(t.rows[sind.rowIndex+1]).after(row); }
  3630. else { $(sind).after(row.join('')); }
  3631. sind=sind.rowIndex + 1;
  3632. }
  3633. break;
  3634. case 'before':
  3635. sind = $(t).jqGrid('getGridRowById', src);
  3636. if(sind) {
  3637. $(sind).before(row.join(''));
  3638. sind=sind.rowIndex - 1;
  3639. }
  3640. break;
  3641. }
  3642. }
  3643. if(t.p.subGrid===true) {
  3644. $(t).jqGrid("addSubGrid",gi+ni, sind);
  3645. }
  3646. t.p.records++;
  3647. t.p.reccount++;
  3648. $(t).triggerHandler("jqGridAfterInsertRow", [rowid,data,data]);
  3649. if(air) { t.p.afterInsertRow.call(t,rowid,data,data); }
  3650. k++;
  3651. if(t.p.datatype === 'local') {
  3652. lcdata[t.p.localReader.id] = id;
  3653. t.p._index[id] = t.p.data.length;
  3654. t.p.data.push(lcdata);
  3655. lcdata = {};
  3656. }
  3657. }
  3658. if( t.p.altRows === true && !aradd) {
  3659. if (pos === "last") {
  3660. if ((t.rows.length-1)%2 === 1) {$(t.rows[t.rows.length-1]).addClass(cn);}
  3661. } else {
  3662. $(t.rows).each(function(i){
  3663. if(i % 2 ===1) { $(this).addClass(cn); }
  3664. else { $(this).removeClass(cn); }
  3665. });
  3666. }
  3667. }
  3668. t.updatepager(true,true);
  3669. success = true;
  3670. });
  3671. }
  3672. return success;
  3673. },
  3674. footerData : function(action,data, format) {
  3675. var nm, success=false, res={}, title;
  3676. function isEmpty(obj) {
  3677. var i;
  3678. for(i in obj) {
  3679. if (obj.hasOwnProperty(i)) { return false; }
  3680. }
  3681. return true;
  3682. }
  3683. if(action == undefined) { action = "get"; }
  3684. if(typeof format !== "boolean") { format = true; }
  3685. action = action.toLowerCase();
  3686. this.each(function(){
  3687. var t = this, vl;
  3688. if(!t.grid || !t.p.footerrow) {return false;}
  3689. if(action === "set") { if(isEmpty(data)) { return false; } }
  3690. success=true;
  3691. $(this.p.colModel).each(function(i){
  3692. nm = this.name;
  3693. if(action === "set") {
  3694. if( data[nm] !== undefined) {
  3695. vl = format ? t.formatter( "", data[nm], i, data, 'edit') : data[nm];
  3696. title = this.title ? {"title":$.jgrid.stripHtml(vl)} : {};
  3697. $("tr.footrow td:eq("+i+")",t.grid.sDiv).html(vl).attr(title);
  3698. success = true;
  3699. }
  3700. } else if(action === "get") {
  3701. res[nm] = $("tr.footrow td:eq("+i+")",t.grid.sDiv).html();
  3702. }
  3703. });
  3704. });
  3705. return action === "get" ? res : success;
  3706. },
  3707. showHideCol : function(colname,show) {
  3708. return this.each(function() {
  3709. var $t = this, fndh=false, brd=$.jgrid.cell_width ? 0: $t.p.cellLayout, cw;
  3710. if (!$t.grid ) {return;}
  3711. if( typeof colname === 'string') {colname=[colname];}
  3712. show = show !== "none" ? "" : "none";
  3713. var sw = show === "" ? true :false,
  3714. gh = $t.p.groupHeader && (typeof $t.p.groupHeader === 'object' || $.isFunction($t.p.groupHeader) );
  3715. if(gh) { $($t).jqGrid('destroyGroupHeader', false); }
  3716. $(this.p.colModel).each(function(i) {
  3717. if ($.inArray(this.name,colname) !== -1 && this.hidden === sw) {
  3718. if($t.p.frozenColumns === true && this.frozen === true) {
  3719. return true;
  3720. }
  3721. $("tr[role=rowheader]",$t.grid.hDiv).each(function(){
  3722. $(this.cells[i]).css("display", show);
  3723. });
  3724. $($t.rows).each(function(){
  3725. if (!$(this).hasClass("jqgroup")) {
  3726. $(this.cells[i]).css("display", show);
  3727. }
  3728. });
  3729. if($t.p.footerrow) { $("tr.footrow td:eq("+i+")", $t.grid.sDiv).css("display", show); }
  3730. cw = parseInt(this.width,10);
  3731. if(show === "none") {
  3732. $t.p.tblwidth -= cw+brd;
  3733. } else {
  3734. $t.p.tblwidth += cw+brd;
  3735. }
  3736. this.hidden = !sw;
  3737. fndh=true;
  3738. $($t).triggerHandler("jqGridShowHideCol", [sw,this.name,i]);
  3739. }
  3740. });
  3741. if(fndh===true) {
  3742. if($t.p.shrinkToFit === true && !isNaN($t.p.height)) { $t.p.tblwidth += parseInt($t.p.scrollOffset,10);}
  3743. $($t).jqGrid("setGridWidth",$t.p.shrinkToFit === true ? $t.p.tblwidth : $t.p.width );
  3744. }
  3745. if( gh ) {
  3746. $($t).jqGrid('setGroupHeaders',$t.p.groupHeader);
  3747. }
  3748. });
  3749. },
  3750. hideCol : function (colname) {
  3751. return this.each(function(){$(this).jqGrid("showHideCol",colname,"none");});
  3752. },
  3753. showCol : function(colname) {
  3754. return this.each(function(){$(this).jqGrid("showHideCol",colname,"");});
  3755. },
  3756. remapColumns : function(permutation, updateCells, keepHeader)
  3757. {
  3758. function resortArray(a) {
  3759. var ac;
  3760. if (a.length) {
  3761. ac = $.makeArray(a);
  3762. } else {
  3763. ac = $.extend({}, a);
  3764. }
  3765. $.each(permutation, function(i) {
  3766. a[i] = ac[this];
  3767. });
  3768. }
  3769. var ts = this.get(0);
  3770. function resortRows(parent, clobj) {
  3771. $(">tr"+(clobj||""), parent).each(function() {
  3772. var row = this;
  3773. var elems = $.makeArray(row.cells);
  3774. $.each(permutation, function() {
  3775. var e = elems[this];
  3776. if (e) {
  3777. row.appendChild(e);
  3778. }
  3779. });
  3780. });
  3781. }
  3782. resortArray(ts.p.colModel);
  3783. resortArray(ts.p.colNames);
  3784. resortArray(ts.grid.headers);
  3785. resortRows($("thead:first", ts.grid.hDiv), keepHeader && ":not(.ui-jqgrid-labels)");
  3786. if (updateCells) {
  3787. resortRows($("#"+$.jgrid.jqID(ts.p.id)+" tbody:first"), ".jqgfirstrow, tr.jqgrow, tr.jqfoot");
  3788. }
  3789. if (ts.p.footerrow) {
  3790. resortRows($("tbody:first", ts.grid.sDiv));
  3791. }
  3792. if (ts.p.remapColumns) {
  3793. if (!ts.p.remapColumns.length){
  3794. ts.p.remapColumns = $.makeArray(permutation);
  3795. } else {
  3796. resortArray(ts.p.remapColumns);
  3797. }
  3798. }
  3799. ts.p.lastsort = $.inArray(ts.p.lastsort, permutation);
  3800. if(ts.p.treeGrid) { ts.p.expColInd = $.inArray(ts.p.expColInd, permutation); }
  3801. $(ts).triggerHandler("jqGridRemapColumns", [permutation, updateCells, keepHeader]);
  3802. },
  3803. setGridWidth : function(nwidth, shrink) {
  3804. return this.each(function(){
  3805. if (!this.grid ) {return;}
  3806. var $t = this, cw,
  3807. initwidth = 0, brd=$.jgrid.cell_width ? 0: $t.p.cellLayout, lvc, vc=0, hs=false, scw=$t.p.scrollOffset, aw, gw=0, cr;
  3808. if(typeof shrink !== 'boolean') {
  3809. shrink=$t.p.shrinkToFit;
  3810. }
  3811. if(isNaN(nwidth)) {return;}
  3812. nwidth = parseInt(nwidth,10);
  3813. $t.grid.width = $t.p.width = nwidth;
  3814. $("#gbox_"+$.jgrid.jqID($t.p.id)).css("width",nwidth+"px");
  3815. $("#gview_"+$.jgrid.jqID($t.p.id)).css("width",nwidth+"px");
  3816. $($t.grid.bDiv).css("width",nwidth+"px");
  3817. $($t.grid.hDiv).css("width",nwidth+"px");
  3818. if($t.p.pager ) {$($t.p.pager).css("width",nwidth+"px");}
  3819. if($t.p.toppager ) {$($t.p.toppager).css("width",nwidth+"px");}
  3820. if($t.p.toolbar[0] === true){
  3821. $($t.grid.uDiv).css("width",nwidth+"px");
  3822. if($t.p.toolbar[1]==="both") {$($t.grid.ubDiv).css("width",nwidth+"px");}
  3823. }
  3824. if($t.p.footerrow) { $($t.grid.sDiv).css("width",nwidth+"px"); }
  3825. if(shrink ===false && $t.p.forceFit === true) {$t.p.forceFit=false;}
  3826. if(shrink===true) {
  3827. $.each($t.p.colModel, function() {
  3828. if(this.hidden===false){
  3829. cw = this.widthOrg;
  3830. initwidth += cw+brd;
  3831. if(this.fixed) {
  3832. gw += cw+brd;
  3833. } else {
  3834. vc++;
  3835. }
  3836. }
  3837. });
  3838. if(vc === 0) { return; }
  3839. $t.p.tblwidth = initwidth;
  3840. aw = nwidth-brd*vc-gw;
  3841. if(!isNaN($t.p.height)) {
  3842. if($($t.grid.bDiv)[0].clientHeight < $($t.grid.bDiv)[0].scrollHeight || $t.rows.length === 1){
  3843. hs = true;
  3844. aw -= scw;
  3845. }
  3846. }
  3847. initwidth =0;
  3848. var cle = $t.grid.cols.length >0;
  3849. $.each($t.p.colModel, function(i) {
  3850. if(this.hidden === false && !this.fixed){
  3851. cw = this.widthOrg;
  3852. cw = Math.round(aw*cw/($t.p.tblwidth-brd*vc-gw));
  3853. if (cw < 0) { return; }
  3854. this.width =cw;
  3855. initwidth += cw;
  3856. $t.grid.headers[i].width=cw;
  3857. $t.grid.headers[i].el.style.width=cw+"px";
  3858. if($t.p.footerrow) { $t.grid.footers[i].style.width = cw+"px"; }
  3859. if(cle) { $t.grid.cols[i].style.width = cw+"px"; }
  3860. lvc = i;
  3861. }
  3862. });
  3863. if (!lvc) { return; }
  3864. cr =0;
  3865. if (hs) {
  3866. if(nwidth-gw-(initwidth+brd*vc) !== scw){
  3867. cr = nwidth-gw-(initwidth+brd*vc)-scw;
  3868. }
  3869. } else if( Math.abs(nwidth-gw-(initwidth+brd*vc)) !== 1) {
  3870. cr = nwidth-gw-(initwidth+brd*vc);
  3871. }
  3872. $t.p.colModel[lvc].width += cr;
  3873. $t.p.tblwidth = initwidth+cr+brd*vc+gw;
  3874. if($t.p.tblwidth > nwidth) {
  3875. var delta = $t.p.tblwidth - parseInt(nwidth,10);
  3876. $t.p.tblwidth = nwidth;
  3877. cw = $t.p.colModel[lvc].width = $t.p.colModel[lvc].width-delta;
  3878. } else {
  3879. cw= $t.p.colModel[lvc].width;
  3880. }
  3881. $t.grid.headers[lvc].width = cw;
  3882. $t.grid.headers[lvc].el.style.width=cw+"px";
  3883. if(cle) { $t.grid.cols[lvc].style.width = cw+"px"; }
  3884. if($t.p.footerrow) {
  3885. $t.grid.footers[lvc].style.width = cw+"px";
  3886. }
  3887. }
  3888. if($t.p.tblwidth) {
  3889. $('table:first',$t.grid.bDiv).css("width",$t.p.tblwidth+"px");
  3890. $('table:first',$t.grid.hDiv).css("width",$t.p.tblwidth+"px");
  3891. $t.grid.hDiv.scrollLeft = $t.grid.bDiv.scrollLeft;
  3892. if($t.p.footerrow) {
  3893. $('table:first',$t.grid.sDiv).css("width",$t.p.tblwidth+"px");
  3894. }
  3895. }
  3896. });
  3897. },
  3898. setGridHeight : function (nh) {
  3899. return this.each(function (){
  3900. var $t = this;
  3901. if(!$t.grid) {return;}
  3902. var bDiv = $($t.grid.bDiv);
  3903. bDiv.css({height: nh+(isNaN(nh)?"":"px")});
  3904. if($t.p.frozenColumns === true){
  3905. //follow the original set height to use 16, better scrollbar width detection
  3906. $('#'+$.jgrid.jqID($t.p.id)+"_frozen").parent().height(bDiv.height() - 16);
  3907. }
  3908. $t.p.height = nh;
  3909. if ($t.p.scroll) { $t.grid.populateVisible(); }
  3910. });
  3911. },
  3912. setCaption : function (newcap){
  3913. return this.each(function(){
  3914. this.p.caption=newcap;
  3915. $("span.ui-jqgrid-title, span.ui-jqgrid-title-rtl",this.grid.cDiv).html(newcap);
  3916. $(this.grid.cDiv).show();
  3917. });
  3918. },
  3919. setLabel : function(colname, nData, prop, attrp ){
  3920. return this.each(function(){
  3921. var $t = this, pos=-1;
  3922. if(!$t.grid) {return;}
  3923. if(colname !== undefined) {
  3924. $($t.p.colModel).each(function(i){
  3925. if (this.name === colname) {
  3926. pos = i;return false;
  3927. }
  3928. });
  3929. } else { return; }
  3930. if(pos>=0) {
  3931. var thecol = $("tr.ui-jqgrid-labels th:eq("+pos+")",$t.grid.hDiv);
  3932. if (nData){
  3933. var ico = $(".s-ico",thecol);
  3934. $("[id^=jqgh_]",thecol).empty().html(nData).append(ico);
  3935. $t.p.colNames[pos] = nData;
  3936. }
  3937. if (prop) {
  3938. if(typeof prop === 'string') {$(thecol).addClass(prop);} else {$(thecol).css(prop);}
  3939. }
  3940. if(typeof attrp === 'object') {$(thecol).attr(attrp);}
  3941. }
  3942. });
  3943. },
  3944. setCell : function(rowid,colname,nData,cssp,attrp, forceupd) {
  3945. return this.each(function(){
  3946. var $t = this, pos =-1,v, title;
  3947. if(!$t.grid) {return;}
  3948. if(isNaN(colname)) {
  3949. $($t.p.colModel).each(function(i){
  3950. if (this.name === colname) {
  3951. pos = i;return false;
  3952. }
  3953. });
  3954. } else {pos = parseInt(colname,10);}
  3955. if(pos>=0) {
  3956. var ind = $($t).jqGrid('getGridRowById', rowid);
  3957. if (ind){
  3958. var tcell = $("td:eq("+pos+")",ind);
  3959. if(nData !== "" || forceupd === true) {
  3960. v = $t.formatter(rowid, nData, pos,ind,'edit');
  3961. title = $t.p.colModel[pos].title ? {"title":$.jgrid.stripHtml(v)} : {};
  3962. if($t.p.treeGrid && $(".tree-wrap",$(tcell)).length>0) {
  3963. $("span",$(tcell)).html(v).attr(title);
  3964. } else {
  3965. $(tcell).html(v).attr(title);
  3966. }
  3967. if($t.p.datatype === "local") {
  3968. var cm = $t.p.colModel[pos], index;
  3969. nData = cm.formatter && typeof cm.formatter === 'string' && cm.formatter === 'date' ? $.unformat.date.call($t,nData,cm) : nData;
  3970. index = $t.p._index[$.jgrid.stripPref($t.p.idPrefix, rowid)];
  3971. if(index !== undefined) {
  3972. $t.p.data[index][cm.name] = nData;
  3973. }
  3974. }
  3975. }
  3976. if(typeof cssp === 'string'){
  3977. $(tcell).addClass(cssp);
  3978. } else if(cssp) {
  3979. $(tcell).css(cssp);
  3980. }
  3981. if(typeof attrp === 'object') {$(tcell).attr(attrp);}
  3982. }
  3983. }
  3984. });
  3985. },
  3986. getCell : function(rowid,col) {
  3987. var ret = false;
  3988. this.each(function(){
  3989. var $t=this, pos=-1;
  3990. if(!$t.grid) {return;}
  3991. if(isNaN(col)) {
  3992. $($t.p.colModel).each(function(i){
  3993. if (this.name === col) {
  3994. pos = i;return false;
  3995. }
  3996. });
  3997. } else {pos = parseInt(col,10);}
  3998. if(pos>=0) {
  3999. var ind = $($t).jqGrid('getGridRowById', rowid);
  4000. if(ind) {
  4001. try {
  4002. ret = $.unformat.call($t,$("td:eq("+pos+")",ind),{rowId:ind.id, colModel:$t.p.colModel[pos]},pos);
  4003. } catch (e){
  4004. ret = $.jgrid.htmlDecode($("td:eq("+pos+")",ind).html());
  4005. }
  4006. }
  4007. }
  4008. });
  4009. return ret;
  4010. },
  4011. /**
  4012. * 将所有行选中
  4013. */
  4014. selectAll: function(){
  4015. if(true == $.data(this.get(0), 'fwdatagrid').options.mutl){
  4016. getAll(this.get(0));
  4017. }else{
  4018. alert('没有设置expBtns="MUTL"');
  4019. }
  4020. },
  4021. /**
  4022. * 将所有行反选
  4023. */
  4024. unSelectAll: function(){
  4025. //清除缓存保存的选中项目
  4026. var target = this.get(0);
  4027. var opts = $.data(target, 'fwdatagrid').options;
  4028. if(true != $.data(this.get(0), 'fwdatagrid').options.mutl){
  4029. alert('没有设置expBtns="MUTL"');
  4030. return;
  4031. }
  4032. unGetAll(target);
  4033. },
  4034. /**
  4035. * 显示下拉框
  4036. * @param input 录入控件
  4037. * @param comname 下拉字典的名称
  4038. * @returns 无
  4039. */
  4040. getCol : function (col, obj, mathopr) {
  4041. var ret = [], val, sum=0, min, max, v;
  4042. obj = typeof obj !== 'boolean' ? false : obj;
  4043. if(mathopr === undefined) { mathopr = false; }
  4044. this.each(function(){
  4045. var $t=this, pos=-1;
  4046. if(!$t.grid) {return;}
  4047. if(isNaN(col)) {
  4048. $($t.p.colModel).each(function(i){
  4049. if (this.name === col) {
  4050. pos = i;return false;
  4051. }
  4052. });
  4053. } else {pos = parseInt(col,10);}
  4054. if(pos>=0) {
  4055. var ln = $t.rows.length, i =0, dlen=0;
  4056. if (ln && ln>0){
  4057. while(i<ln){
  4058. if($($t.rows[i]).hasClass('jqgrow')) {
  4059. try {
  4060. val = $.unformat.call($t,$($t.rows[i].cells[pos]),{rowId:$t.rows[i].id, colModel:$t.p.colModel[pos]},pos);
  4061. } catch (e) {
  4062. val = $.jgrid.htmlDecode($t.rows[i].cells[pos].innerHTML);
  4063. }
  4064. if(mathopr) {
  4065. v = parseFloat(val);
  4066. if(!isNaN(v)) {
  4067. sum += v;
  4068. if (max === undefined) {max = min = v;}
  4069. min = Math.min(min, v);
  4070. max = Math.max(max, v);
  4071. dlen++;
  4072. }
  4073. }
  4074. else if(obj) { ret.push( {id:$t.rows[i].id,value:val} ); }
  4075. else { ret.push( val ); }
  4076. }
  4077. i++;
  4078. }
  4079. if(mathopr) {
  4080. switch(mathopr.toLowerCase()){
  4081. case 'sum': ret =sum; break;
  4082. case 'avg': ret = sum/dlen; break;
  4083. case 'count': ret = (ln-1); break;
  4084. case 'min': ret = min; break;
  4085. case 'max': ret = max; break;
  4086. }
  4087. }
  4088. }
  4089. }
  4090. });
  4091. return ret;
  4092. },
  4093. clearGridData : function(clearfooter) {
  4094. return this.each(function(){
  4095. var $t = this;
  4096. if(!$t.grid) {return;}
  4097. if(typeof clearfooter !== 'boolean') { clearfooter = false; }
  4098. if($t.p.deepempty) {$("#"+$.jgrid.jqID($t.p.id)+" tbody:first tr:gt(0)").remove();}
  4099. else {
  4100. var trf = $("#"+$.jgrid.jqID($t.p.id)+" tbody:first tr:first")[0];
  4101. $("#"+$.jgrid.jqID($t.p.id)+" tbody:first").empty().append(trf);
  4102. }
  4103. if($t.p.footerrow && clearfooter) { $(".ui-jqgrid-ftable td",$t.grid.sDiv).html("&#160;"); }
  4104. $t.p.selrow = null; $t.p.selarrrow= []; $t.p.savedRow = [];
  4105. $t.p.records = 0;$t.p.page=1;$t.p.lastpage=0;$t.p.reccount=0;
  4106. $t.p.data = []; $t.p._index = {};
  4107. $t.updatepager(true,false);
  4108. });
  4109. },
  4110. getInd : function(rowid,rc){
  4111. var ret =false,rw;
  4112. this.each(function(){
  4113. rw = $(this).jqGrid('getGridRowById', rowid);
  4114. if(rw) {
  4115. ret = rc===true ? rw: rw.rowIndex;
  4116. }
  4117. });
  4118. return ret;
  4119. },
  4120. bindKeys : function( settings ){
  4121. var o = $.extend({
  4122. onEnter: null,
  4123. onSpace: null,
  4124. onLeftKey: null,
  4125. onRightKey: null,
  4126. scrollingRows : true
  4127. },settings || {});
  4128. return this.each(function(){
  4129. var $t = this;
  4130. if( !$('body').is('[role]') ){$('body').attr('role','application');}
  4131. $t.p.scrollrows = o.scrollingRows;
  4132. $($t).keydown(function(event){
  4133. var target = $($t).find('tr[tabindex=0]')[0], id, r, mind,
  4134. expanded = $t.p.treeReader.expanded_field;
  4135. //check for arrow keys
  4136. if(target) {
  4137. mind = $t.p._index[$.jgrid.stripPref($t.p.idPrefix, target.id)];
  4138. if(event.keyCode === 37 || event.keyCode === 38 || event.keyCode === 39 || event.keyCode === 40){
  4139. // up key
  4140. if(event.keyCode === 38 ){
  4141. r = target.previousSibling;
  4142. id = "";
  4143. if(r) {
  4144. if($(r).is(":hidden")) {
  4145. while(r) {
  4146. r = r.previousSibling;
  4147. if(!$(r).is(":hidden") && $(r).hasClass('jqgrow')) {id = r.id;break;}
  4148. }
  4149. } else {
  4150. id = r.id;
  4151. }
  4152. }
  4153. $($t).jqGrid('setSelection', id, true, event);
  4154. event.preventDefault();
  4155. }
  4156. //if key is down arrow
  4157. if(event.keyCode === 40){
  4158. r = target.nextSibling;
  4159. id ="";
  4160. if(r) {
  4161. if($(r).is(":hidden")) {
  4162. while(r) {
  4163. r = r.nextSibling;
  4164. if(!$(r).is(":hidden") && $(r).hasClass('jqgrow') ) {id = r.id;break;}
  4165. }
  4166. } else {
  4167. id = r.id;
  4168. }
  4169. }
  4170. $($t).jqGrid('setSelection', id, true, event);
  4171. event.preventDefault();
  4172. }
  4173. // left
  4174. if(event.keyCode === 37 ){
  4175. if($t.p.treeGrid && $t.p.data[mind][expanded]) {
  4176. $(target).find("div.treeclick").trigger('click');
  4177. }
  4178. $($t).triggerHandler("jqGridKeyLeft", [$t.p.selrow]);
  4179. if($.isFunction(o.onLeftKey)) {
  4180. o.onLeftKey.call($t, $t.p.selrow);
  4181. }
  4182. }
  4183. // right
  4184. if(event.keyCode === 39 ){
  4185. if($t.p.treeGrid && !$t.p.data[mind][expanded]) {
  4186. $(target).find("div.treeclick").trigger('click');
  4187. }
  4188. $($t).triggerHandler("jqGridKeyRight", [$t.p.selrow]);
  4189. if($.isFunction(o.onRightKey)) {
  4190. o.onRightKey.call($t, $t.p.selrow);
  4191. }
  4192. }
  4193. }
  4194. //check if enter was pressed on a grid or treegrid node
  4195. else if( event.keyCode === 13 ){
  4196. $($t).triggerHandler("jqGridKeyEnter", [$t.p.selrow]);
  4197. if($.isFunction(o.onEnter)) {
  4198. o.onEnter.call($t, $t.p.selrow);
  4199. }
  4200. } else if(event.keyCode === 32) {
  4201. $($t).triggerHandler("jqGridKeySpace", [$t.p.selrow]);
  4202. if($.isFunction(o.onSpace)) {
  4203. o.onSpace.call($t, $t.p.selrow);
  4204. }
  4205. }
  4206. }
  4207. });
  4208. });
  4209. },
  4210. unbindKeys : function(){
  4211. return this.each(function(){
  4212. $(this).unbind('keydown');
  4213. });
  4214. },
  4215. getLocalRow : function (rowid) {
  4216. var ret = false, ind;
  4217. this.each(function(){
  4218. if(rowid !== undefined) {
  4219. ind = this.p._index[$.jgrid.stripPref(this.p.idPrefix, rowid)];
  4220. if(ind >= 0 ) {
  4221. ret = this.p.data[ind];
  4222. }
  4223. }
  4224. });
  4225. return ret;
  4226. }
  4227. });
  4228. })(jQuery);
  4229. /*jshint eqeqeq:false */
  4230. /*global jQuery */
  4231. (function($){
  4232. /**
  4233. * jqGrid extension for custom methods
  4234. * Tony Tomov tony@trirand.com
  4235. * http://trirand.com/blog/
  4236. *
  4237. * Wildraid wildraid@mail.ru
  4238. * Oleg Kiriljuk oleg.kiriljuk@ok-soft-gmbh.com
  4239. * Dual licensed under the MIT and GPL licenses:
  4240. * http://www.opensource.org/licenses/mit-license.php
  4241. * http://www.gnu.org/licenses/gpl-2.0.html
  4242. **/
  4243. "use strict";
  4244. $.jgrid.extend({
  4245. getColProp : function(colname){
  4246. var ret ={}, $t = this[0];
  4247. if ( !$t.grid ) { return false; }
  4248. var cM = $t.p.colModel, i;
  4249. for ( i=0;i<cM.length;i++ ) {
  4250. if ( cM[i].name === colname ) {
  4251. ret = cM[i];
  4252. break;
  4253. }
  4254. }
  4255. return ret;
  4256. },
  4257. setColProp : function(colname, obj){
  4258. //do not set width will not work
  4259. return this.each(function(){
  4260. if ( this.grid ) {
  4261. if ( obj ) {
  4262. var cM = this.p.colModel, i;
  4263. for ( i=0;i<cM.length;i++ ) {
  4264. if ( cM[i].name === colname ) {
  4265. $.extend(true, this.p.colModel[i],obj);
  4266. break;
  4267. }
  4268. }
  4269. }
  4270. }
  4271. });
  4272. },
  4273. sortGrid : function(colname,reload, sor){
  4274. return this.each(function(){
  4275. var $t=this,idx=-1,i, sobj=false;
  4276. if ( !$t.grid ) { return;}
  4277. if ( !colname ) { colname = $t.p.sortname; }
  4278. for ( i=0;i<$t.p.colModel.length;i++ ) {
  4279. if ( $t.p.colModel[i].index === colname || $t.p.colModel[i].name === colname ) {
  4280. idx = i;
  4281. if($t.p.frozenColumns === true && $t.p.colModel[i].frozen === true) {
  4282. sobj = $t.grid.fhDiv.find("#" + $t.p.id + "_" + colname);
  4283. }
  4284. break;
  4285. }
  4286. }
  4287. if ( idx !== -1 ){
  4288. var sort = $t.p.colModel[idx].sortable;
  4289. if(!sobj) {
  4290. sobj = $t.grid.headers[idx].el;
  4291. }
  4292. if ( typeof sort !== 'boolean' ) { sort = true; }
  4293. if ( typeof reload !=='boolean' ) { reload = false; }
  4294. if ( sort ) { $t.sortData("jqgh_"+$t.p.id+"_" + colname, idx, reload, sor, sobj); }
  4295. }
  4296. });
  4297. },
  4298. clearBeforeUnload : function () {
  4299. return this.each(function(){
  4300. var grid = this.grid;
  4301. if ($.isFunction(grid.emptyRows)) {
  4302. grid.emptyRows.call(this, true, true); // this work quick enough and reduce the size of memory leaks if we have someone
  4303. }
  4304. $(document).unbind("mouseup.jqGrid" + this.p.id );
  4305. $(grid.hDiv).unbind("mousemove"); // TODO add namespace
  4306. $(this).unbind();
  4307. grid.dragEnd = null;
  4308. grid.dragMove = null;
  4309. grid.dragStart = null;
  4310. grid.emptyRows = null;
  4311. grid.populate = null;
  4312. grid.populateVisible = null;
  4313. grid.scrollGrid = null;
  4314. grid.selectionPreserver = null;
  4315. grid.bDiv = null;
  4316. grid.cDiv = null;
  4317. grid.hDiv = null;
  4318. grid.cols = null;
  4319. var i, l = grid.headers.length;
  4320. for (i = 0; i < l; i++) {
  4321. grid.headers[i].el = null;
  4322. }
  4323. this.formatCol = null;
  4324. this.sortData = null;
  4325. this.updatepager = null;
  4326. this.refreshIndex = null;
  4327. this.setHeadCheckBox = null;
  4328. this.constructTr = null;
  4329. this.formatter = null;
  4330. this.addXmlData = null;
  4331. this.addJSONData = null;
  4332. this.grid = null;
  4333. });
  4334. },
  4335. GridDestroy : function () {
  4336. return this.each(function(){
  4337. if ( this.grid ) {
  4338. if ( this.p.pager ) { // if not part of grid
  4339. $(this.p.pager).remove();
  4340. }
  4341. try {
  4342. $(this).jqGrid('clearBeforeUnload');
  4343. $("#gbox_"+$.jgrid.jqID(this.id)).remove();
  4344. } catch (_) {}
  4345. }
  4346. });
  4347. },
  4348. GridUnload : function(){
  4349. return this.each(function(){
  4350. if ( !this.grid ) {return;}
  4351. var defgrid = {id: $(this).attr('id'),cl: $(this).attr('class')};
  4352. if (this.p.pager) {
  4353. $(this.p.pager).empty().removeClass("ui-state-default ui-jqgrid-pager ui-corner-bottom");
  4354. }
  4355. var newtable = document.createElement('table');
  4356. $(newtable).attr({id:defgrid.id});
  4357. newtable.className = defgrid.cl;
  4358. var gid = $.jgrid.jqID(this.id);
  4359. $(newtable).removeClass("ui-jqgrid-btable");
  4360. if( $(this.p.pager).parents("#gbox_"+gid).length === 1 ) {
  4361. $(newtable).insertBefore("#gbox_"+gid).show();
  4362. $(this.p.pager).insertBefore("#gbox_"+gid);
  4363. } else {
  4364. $(newtable).insertBefore("#gbox_"+gid).show();
  4365. }
  4366. $(this).jqGrid('clearBeforeUnload');
  4367. $("#gbox_"+gid).remove();
  4368. });
  4369. },
  4370. setGridState : function(state) {
  4371. return this.each(function(){
  4372. if ( !this.grid ) {return;}
  4373. var $t = this;
  4374. if(state === 'hidden'){
  4375. $(".ui-jqgrid-bdiv, .ui-jqgrid-hdiv","#gview_"+$.jgrid.jqID($t.p.id)).slideUp("fast");
  4376. if($t.p.pager) {$($t.p.pager).slideUp("fast");}
  4377. if($t.p.toppager) {$($t.p.toppager).slideUp("fast");}
  4378. if($t.p.toolbar[0]===true) {
  4379. if( $t.p.toolbar[1] === 'both') {
  4380. $($t.grid.ubDiv).slideUp("fast");
  4381. }
  4382. $($t.grid.uDiv).slideUp("fast");
  4383. }
  4384. if($t.p.footerrow) { $(".ui-jqgrid-sdiv","#gbox_"+$.jgrid.jqID($t.p.id)).slideUp("fast"); }
  4385. $(".ui-jqgrid-titlebar-close span",$t.grid.cDiv).removeClass("ui-icon-circle-triangle-n").addClass("ui-icon-circle-triangle-s");
  4386. $t.p.gridstate = 'hidden';
  4387. } else if(state === 'visible') {
  4388. $(".ui-jqgrid-hdiv, .ui-jqgrid-bdiv","#gview_"+$.jgrid.jqID($t.p.id)).slideDown("fast");
  4389. if($t.p.pager) {$($t.p.pager).slideDown("fast");}
  4390. if($t.p.toppager) {$($t.p.toppager).slideDown("fast");}
  4391. if($t.p.toolbar[0]===true) {
  4392. if( $t.p.toolbar[1] === 'both') {
  4393. $($t.grid.ubDiv).slideDown("fast");
  4394. }
  4395. $($t.grid.uDiv).slideDown("fast");
  4396. }
  4397. if($t.p.footerrow) { $(".ui-jqgrid-sdiv","#gbox_"+$.jgrid.jqID($t.p.id)).slideDown("fast"); }
  4398. $(".ui-jqgrid-titlebar-close span",$t.grid.cDiv).removeClass("ui-icon-circle-triangle-s").addClass("ui-icon-circle-triangle-n");
  4399. $t.p.gridstate = 'visible';
  4400. }
  4401. });
  4402. },
  4403. filterToolbar : function(p){
  4404. p = $.extend({
  4405. autosearch: true,
  4406. searchOnEnter : true,
  4407. beforeSearch: null,
  4408. afterSearch: null,
  4409. beforeClear: null,
  4410. afterClear: null,
  4411. searchurl : '',
  4412. stringResult: false,
  4413. groupOp: 'AND',
  4414. defaultSearch : "bw",
  4415. searchOperators : false,
  4416. resetIcon : "x",
  4417. operands : { "eq" :"==", "ne":"!","lt":"<","le":"<=","gt":">","ge":">=","bw":"^","bn":"!^","in":"=","ni":"!=","ew":"|","en":"!@","cn":"~","nc":"!~","nu":"#","nn":"!#"}
  4418. }, $.jgrid.search , p || {});
  4419. return this.each(function(){
  4420. var $t = this;
  4421. if(this.ftoolbar) { return; }
  4422. var triggerToolbar = function() {
  4423. var sdata={}, j=0, v, nm, sopt={},so;
  4424. $.each($t.p.colModel,function(){
  4425. var $elem = $("#gs_"+$.jgrid.jqID(this.name), (this.frozen===true && $t.p.frozenColumns === true) ? $t.grid.fhDiv : $t.grid.hDiv);
  4426. nm = this.index || this.name;
  4427. if(p.searchOperators ) {
  4428. so = $elem.parent().prev().children("a").attr("soper") || p.defaultSearch;
  4429. } else {
  4430. so = (this.searchoptions && this.searchoptions.sopt) ? this.searchoptions.sopt[0] : this.stype==='select'? 'eq' : p.defaultSearch;
  4431. }
  4432. v = this.stype === "custom" && $.isFunction(this.searchoptions.custom_value) && $elem.length > 0 && $elem[0].nodeName.toUpperCase() === "SPAN" ?
  4433. this.searchoptions.custom_value.call($t, $elem.children(".customelement:first"), "get") :
  4434. $elem.val();
  4435. if(v || so==="nu" || so==="nn") {
  4436. sdata[nm] = v;
  4437. sopt[nm] = so;
  4438. j++;
  4439. } else {
  4440. try {
  4441. delete $t.p.postData[nm];
  4442. } catch (z) {}
  4443. }
  4444. });
  4445. var sd = j>0 ? true : false;
  4446. if(p.stringResult === true || $t.p.datatype === "local" || p.searchOperators === true) {
  4447. var ruleGroup = "{\"groupOp\":\"" + p.groupOp + "\",\"rules\":[";
  4448. var gi=0;
  4449. $.each(sdata,function(i,n){
  4450. if (gi > 0) {ruleGroup += ",";}
  4451. ruleGroup += "{\"field\":\"" + i + "\",";
  4452. ruleGroup += "\"op\":\"" + sopt[i] + "\",";
  4453. n+="";
  4454. ruleGroup += "\"data\":\"" + n.replace(/\\/g,'\\\\').replace(/\"/g,'\\"') + "\"}";
  4455. gi++;
  4456. });
  4457. ruleGroup += "]}";
  4458. $.extend($t.p.postData,{filters:ruleGroup});
  4459. $.each(['searchField', 'searchString', 'searchOper'], function(i, n){
  4460. if($t.p.postData.hasOwnProperty(n)) { delete $t.p.postData[n];}
  4461. });
  4462. } else {
  4463. $.extend($t.p.postData,sdata);
  4464. }
  4465. var saveurl;
  4466. if($t.p.searchurl) {
  4467. saveurl = $t.p.url;
  4468. $($t).jqGrid("setGridParam",{url:$t.p.searchurl});
  4469. }
  4470. var bsr = $($t).triggerHandler("jqGridToolbarBeforeSearch") === 'stop' ? true : false;
  4471. if(!bsr && $.isFunction(p.beforeSearch)){bsr = p.beforeSearch.call($t);}
  4472. if(!bsr) { $($t).jqGrid("setGridParam",{search:sd}).trigger("reloadGrid",[{page:1}]); }
  4473. if(saveurl) {$($t).jqGrid("setGridParam",{url:saveurl});}
  4474. $($t).triggerHandler("jqGridToolbarAfterSearch");
  4475. if($.isFunction(p.afterSearch)){p.afterSearch.call($t);}
  4476. },
  4477. clearToolbar = function(trigger){
  4478. var sdata={}, j=0, nm;
  4479. trigger = (typeof trigger !== 'boolean') ? true : trigger;
  4480. $.each($t.p.colModel,function(){
  4481. var v, $elem = $("#gs_"+$.jgrid.jqID(this.name),(this.frozen===true && $t.p.frozenColumns === true) ? $t.grid.fhDiv : $t.grid.hDiv);
  4482. if(this.searchoptions && this.searchoptions.defaultValue !== undefined) { v = this.searchoptions.defaultValue; }
  4483. nm = this.index || this.name;
  4484. switch (this.stype) {
  4485. case 'select' :
  4486. $elem.find("option").each(function (i){
  4487. if(i===0) { this.selected = true; }
  4488. if ($(this).val() === v) {
  4489. this.selected = true;
  4490. return false;
  4491. }
  4492. });
  4493. if ( v !== undefined ) {
  4494. // post the key and not the text
  4495. sdata[nm] = v;
  4496. j++;
  4497. } else {
  4498. try {
  4499. delete $t.p.postData[nm];
  4500. } catch(e) {}
  4501. }
  4502. break;
  4503. case 'text':
  4504. $elem.val(v || "");
  4505. if(v !== undefined) {
  4506. sdata[nm] = v;
  4507. j++;
  4508. } else {
  4509. try {
  4510. delete $t.p.postData[nm];
  4511. } catch (y){}
  4512. }
  4513. break;
  4514. case 'custom':
  4515. if ($.isFunction(this.searchoptions.custom_value) && $elem.length > 0 && $elem[0].nodeName.toUpperCase() === "SPAN") {
  4516. this.searchoptions.custom_value.call($t, $elem.children(".customelement:first"), "set", v || "");
  4517. }
  4518. break;
  4519. }
  4520. });
  4521. var sd = j>0 ? true : false;
  4522. $t.p.resetsearch = true;
  4523. if(p.stringResult === true || $t.p.datatype === "local") {
  4524. var ruleGroup = "{\"groupOp\":\"" + p.groupOp + "\",\"rules\":[";
  4525. var gi=0;
  4526. $.each(sdata,function(i,n){
  4527. if (gi > 0) {ruleGroup += ",";}
  4528. ruleGroup += "{\"field\":\"" + i + "\",";
  4529. ruleGroup += "\"op\":\"" + "eq" + "\",";
  4530. n+="";
  4531. ruleGroup += "\"data\":\"" + n.replace(/\\/g,'\\\\').replace(/\"/g,'\\"') + "\"}";
  4532. gi++;
  4533. });
  4534. ruleGroup += "]}";
  4535. $.extend($t.p.postData,{filters:ruleGroup});
  4536. $.each(['searchField', 'searchString', 'searchOper'], function(i, n){
  4537. if($t.p.postData.hasOwnProperty(n)) { delete $t.p.postData[n];}
  4538. });
  4539. } else {
  4540. $.extend($t.p.postData,sdata);
  4541. }
  4542. var saveurl;
  4543. if($t.p.searchurl) {
  4544. saveurl = $t.p.url;
  4545. $($t).jqGrid("setGridParam",{url:$t.p.searchurl});
  4546. }
  4547. var bcv = $($t).triggerHandler("jqGridToolbarBeforeClear") === 'stop' ? true : false;
  4548. if(!bcv && $.isFunction(p.beforeClear)){bcv = p.beforeClear.call($t);}
  4549. if(!bcv) {
  4550. if(trigger) {
  4551. $($t).jqGrid("setGridParam",{search:sd}).trigger("reloadGrid",[{page:1}]);
  4552. }
  4553. }
  4554. if(saveurl) {$($t).jqGrid("setGridParam",{url:saveurl});}
  4555. $($t).triggerHandler("jqGridToolbarAfterClear");
  4556. if($.isFunction(p.afterClear)){p.afterClear();}
  4557. },
  4558. toggleToolbar = function(){
  4559. var trow = $("tr.ui-search-toolbar",$t.grid.hDiv),
  4560. trow2 = $t.p.frozenColumns === true ? $("tr.ui-search-toolbar",$t.grid.fhDiv) : false;
  4561. if(trow.css("display") === 'none') {
  4562. trow.show();
  4563. if(trow2) {
  4564. trow2.show();
  4565. }
  4566. } else {
  4567. trow.hide();
  4568. if(trow2) {
  4569. trow2.hide();
  4570. }
  4571. }
  4572. },
  4573. buildRuleMenu = function( elem, left, top ){
  4574. $("#sopt_menu").remove();
  4575. left=parseInt(left,10);
  4576. top=parseInt(top,10) + 18;
  4577. var fs = $('.ui-jqgrid-view').css('font-size') || '11px';
  4578. var str = '<ul id="sopt_menu" class="ui-search-menu" role="menu" tabindex="0" style="font-size:'+fs+';left:'+left+'px;top:'+top+'px;">',
  4579. selected = $(elem).attr("soper"), selclass,
  4580. aoprs = [], ina;
  4581. var i=0, nm =$(elem).attr("colname"),len = $t.p.colModel.length;
  4582. while(i<len) {
  4583. if($t.p.colModel[i].name === nm) {
  4584. break;
  4585. }
  4586. i++;
  4587. }
  4588. var cm = $t.p.colModel[i], options = $.extend({}, cm.searchoptions);
  4589. if(!options.sopt) {
  4590. options.sopt = [];
  4591. options.sopt[0]= cm.stype==='select' ? 'eq' : p.defaultSearch;
  4592. }
  4593. $.each(p.odata, function() { aoprs.push(this.oper); });
  4594. for ( i = 0 ; i < options.sopt.length; i++) {
  4595. ina = $.inArray(options.sopt[i],aoprs);
  4596. if(ina !== -1) {
  4597. selclass = selected === p.odata[ina].oper ? "ui-state-highlight" : "";
  4598. 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>';
  4599. }
  4600. }
  4601. str += "</ul>";
  4602. $('body').append(str);
  4603. $("#sopt_menu").addClass("ui-menu ui-widget ui-widget-content ui-corner-all");
  4604. $("#sopt_menu > li > a").hover(
  4605. function(){ $(this).addClass("ui-state-hover"); },
  4606. function(){ $(this).removeClass("ui-state-hover"); }
  4607. ).click(function( e ){
  4608. var v = $(this).attr("value"),
  4609. oper = $(this).attr("oper");
  4610. $($t).triggerHandler("jqGridToolbarSelectOper", [v, oper, elem]);
  4611. $("#sopt_menu").hide();
  4612. $(elem).text(oper).attr("soper",v);
  4613. if(p.autosearch===true){
  4614. var inpelm = $(elem).parent().next().children()[0];
  4615. if( $(inpelm).val() || v==="nu" || v ==="nn") {
  4616. triggerToolbar();
  4617. }
  4618. }
  4619. });
  4620. };
  4621. // create the row
  4622. var tr = $("<tr class='ui-search-toolbar' role='rowheader'></tr>");
  4623. var timeoutHnd;
  4624. $.each($t.p.colModel,function(ci){
  4625. var cm=this, soptions, surl, self, select = "", sot="=", so, i,
  4626. th = $("<th role='columnheader' class='ui-state-default ui-th-column ui-th-"+$t.p.direction+"'></th>"),
  4627. thd = $("<div style='position:relative;height:auto;padding-right:0.3em;padding-left:0.3em;'></div>"),
  4628. 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>");
  4629. if(this.hidden===true) { $(th).css("display","none");}
  4630. this.search = this.search === false ? false : true;
  4631. if(this.stype === undefined) {this.stype='text';}
  4632. soptions = $.extend({},this.searchoptions || {});
  4633. if(this.search){
  4634. if(p.searchOperators) {
  4635. so = (soptions.sopt) ? soptions.sopt[0] : cm.stype==='select' ? 'eq' : p.defaultSearch;
  4636. for(i = 0;i<p.odata.length;i++) {
  4637. if(p.odata[i].oper === so) {
  4638. sot = p.operands[so] || "";
  4639. break;
  4640. }
  4641. }
  4642. var st = soptions.searchtitle != null ? soptions.searchtitle : p.operandTitle;
  4643. select = "<a title='"+st+"' style='padding-right: 0.5em;' soper='"+so+"' class='soptclass' colname='"+this.name+"'>"+sot+"</a>";
  4644. }
  4645. $("td:eq(0)",stbl).attr("colindex",ci).append(select);
  4646. if(soptions.clearSearch === undefined) {
  4647. soptions.clearSearch = true;
  4648. }
  4649. if(soptions.clearSearch) {
  4650. var csv = p.resetTitle || 'Clear Search Value';
  4651. $("td:eq(2)",stbl).append("<a title='"+csv+"' style='padding-right: 0.3em;padding-left: 0.3em;' class='clearsearchclass'>"+p.resetIcon+"</a>");
  4652. } else {
  4653. $("td:eq(2)", stbl).hide();
  4654. }
  4655. switch (this.stype)
  4656. {
  4657. case "select":
  4658. surl = this.surl || soptions.dataUrl;
  4659. if(surl) {
  4660. // data returned should have already constructed html select
  4661. // primitive jQuery load
  4662. self = thd;
  4663. $(self).append(stbl);
  4664. //alert("01");
  4665. $.ajax($.extend({
  4666. url: surl,
  4667. dataType: "html",
  4668. success: function(res) {
  4669. if(soptions.buildSelect !== undefined) {
  4670. var d = soptions.buildSelect(res);
  4671. if (d) {
  4672. $("td:eq(1)",stbl).append(d);
  4673. }
  4674. } else {
  4675. $("td:eq(1)",stbl).append(res);
  4676. }
  4677. if(soptions.defaultValue !== undefined) { $("select",self).val(soptions.defaultValue); }
  4678. $("select",self).attr({name:cm.index || cm.name, id: "gs_"+cm.name});
  4679. if(soptions.attr) {$("select",self).attr(soptions.attr);}
  4680. $("select",self).css({width: "100%"});
  4681. // preserve autoserch
  4682. $.jgrid.bindEv.call($t, $("select",self)[0], soptions);
  4683. if(p.autosearch===true){
  4684. $("select",self).change(function(){
  4685. triggerToolbar();
  4686. return false;
  4687. });
  4688. }
  4689. res=null;
  4690. }
  4691. }, $.jgrid.ajaxOptions, $t.p.ajaxSelectOptions || {} ));
  4692. } else {
  4693. var oSv, sep, delim;
  4694. if(cm.searchoptions) {
  4695. oSv = cm.searchoptions.value === undefined ? "" : cm.searchoptions.value;
  4696. sep = cm.searchoptions.separator === undefined ? ":" : cm.searchoptions.separator;
  4697. delim = cm.searchoptions.delimiter === undefined ? ";" : cm.searchoptions.delimiter;
  4698. } else if(cm.editoptions) {
  4699. oSv = cm.editoptions.value === undefined ? "" : cm.editoptions.value;
  4700. sep = cm.editoptions.separator === undefined ? ":" : cm.editoptions.separator;
  4701. delim = cm.editoptions.delimiter === undefined ? ";" : cm.editoptions.delimiter;
  4702. }
  4703. if (oSv) {
  4704. var elem = document.createElement("select");
  4705. elem.style.width = "100%";
  4706. $(elem).attr({name:cm.index || cm.name, id: "gs_"+cm.name});
  4707. var sv, ov, key, k;
  4708. if(typeof oSv === "string") {
  4709. so = oSv.split(delim);
  4710. for(k=0; k<so.length;k++){
  4711. sv = so[k].split(sep);
  4712. ov = document.createElement("option");
  4713. ov.value = sv[0]; ov.innerHTML = sv[1];
  4714. elem.appendChild(ov);
  4715. }
  4716. } else if(typeof oSv === "object" ) {
  4717. for (key in oSv) {
  4718. if(oSv.hasOwnProperty(key)) {
  4719. ov = document.createElement("option");
  4720. ov.value = key; ov.innerHTML = oSv[key];
  4721. elem.appendChild(ov);
  4722. }
  4723. }
  4724. }
  4725. if(soptions.defaultValue !== undefined) { $(elem).val(soptions.defaultValue); }
  4726. if(soptions.attr) {$(elem).attr(soptions.attr);}
  4727. $(thd).append(stbl);
  4728. $.jgrid.bindEv.call($t, elem , soptions);
  4729. $("td:eq(1)",stbl).append( elem );
  4730. if(p.autosearch===true){
  4731. $(elem).change(function(){
  4732. triggerToolbar();
  4733. return false;
  4734. });
  4735. }
  4736. }
  4737. }
  4738. break;
  4739. case "text":
  4740. var df = soptions.defaultValue !== undefined ? soptions.defaultValue: "";
  4741. $("td:eq(1)",stbl).append("<input type='text' style='width:100%;padding:0px;' name='"+(cm.index || cm.name)+"' id='gs_"+cm.name+"' value='"+df+"'/>");
  4742. $(thd).append(stbl);
  4743. if(soptions.attr) {$("input",thd).attr(soptions.attr);}
  4744. $.jgrid.bindEv.call($t, $("input",thd)[0], soptions);
  4745. if(p.autosearch===true){
  4746. if(p.searchOnEnter) {
  4747. $("input",thd).keypress(function(e){
  4748. var key = e.charCode || e.keyCode || 0;
  4749. if(key === 13){
  4750. triggerToolbar();
  4751. return false;
  4752. }
  4753. return this;
  4754. });
  4755. } else {
  4756. $("input",thd).keydown(function(e){
  4757. var key = e.which;
  4758. switch (key) {
  4759. case 13:
  4760. return false;
  4761. case 9 :
  4762. case 16:
  4763. case 37:
  4764. case 38:
  4765. case 39:
  4766. case 40:
  4767. case 27:
  4768. break;
  4769. default :
  4770. if(timeoutHnd) { clearTimeout(timeoutHnd); }
  4771. timeoutHnd = setTimeout(function(){triggerToolbar();},500);
  4772. }
  4773. });
  4774. }
  4775. }
  4776. break;
  4777. case "custom":
  4778. $("td:eq(1)",stbl).append("<span style='width:95%;padding:0px;' name='"+(cm.index || cm.name)+"' id='gs_"+cm.name+"'/>");
  4779. $(thd).append(stbl);
  4780. try {
  4781. if($.isFunction(soptions.custom_element)) {
  4782. var celm = soptions.custom_element.call($t,soptions.defaultValue !== undefined ? soptions.defaultValue: "",soptions);
  4783. if(celm) {
  4784. celm = $(celm).addClass("customelement");
  4785. $(thd).find(">span").append(celm);
  4786. } else {
  4787. throw "e2";
  4788. }
  4789. } else {
  4790. throw "e1";
  4791. }
  4792. } catch (e) {
  4793. if (e === "e1") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_element' "+$.jgrid.edit.msg.nodefined,$.jgrid.edit.bClose);}
  4794. if (e === "e2") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_element' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose);}
  4795. else { $.jgrid.info_dialog($.jgrid.errors.errcap,typeof e==="string"?e:e.message,$.jgrid.edit.bClose); }
  4796. }
  4797. break;
  4798. }
  4799. }
  4800. $(th).append(thd);
  4801. $(tr).append(th);
  4802. if(!p.searchOperators) {
  4803. $("td:eq(0)",stbl).hide();
  4804. }
  4805. });
  4806. $("table thead",$t.grid.hDiv).append(tr);
  4807. if(p.searchOperators) {
  4808. $(".soptclass",tr).click(function(e){
  4809. var offset = $(this).offset(),
  4810. left = ( offset.left ),
  4811. top = ( offset.top);
  4812. buildRuleMenu(this, left, top );
  4813. e.stopPropagation();
  4814. });
  4815. $("body").on('click', function(e){
  4816. if(e.target.className !== "soptclass") {
  4817. $("#sopt_menu").hide();
  4818. }
  4819. });
  4820. }
  4821. $(".clearsearchclass",tr).click(function(e){
  4822. var ptr = $(this).parents("tr:first"),
  4823. coli = parseInt($("td.ui-search-oper", ptr).attr('colindex'),10),
  4824. sval = $.extend({},$t.p.colModel[coli].searchoptions || {}),
  4825. dval = sval.defaultValue ? sval.defaultValue : "";
  4826. if($t.p.colModel[coli].stype === "select") {
  4827. if(dval) {
  4828. $("td.ui-search-input select", ptr).val( dval );
  4829. } else {
  4830. $("td.ui-search-input select", ptr)[0].selectedIndex = 0;
  4831. }
  4832. } else {
  4833. $("td.ui-search-input input", ptr).val( dval );
  4834. }
  4835. // ToDo custom search type
  4836. if(p.autosearch===true){
  4837. triggerToolbar();
  4838. }
  4839. });
  4840. this.ftoolbar = true;
  4841. this.triggerToolbar = triggerToolbar;
  4842. this.clearToolbar = clearToolbar;
  4843. this.toggleToolbar = toggleToolbar;
  4844. });
  4845. },
  4846. destroyFilterToolbar: function () {
  4847. return this.each(function () {
  4848. if (!this.ftoolbar) {
  4849. return;
  4850. }
  4851. this.triggerToolbar = null;
  4852. this.clearToolbar = null;
  4853. this.toggleToolbar = null;
  4854. this.ftoolbar = false;
  4855. $(this.grid.hDiv).find("table thead tr.ui-search-toolbar").remove();
  4856. });
  4857. },
  4858. destroyGroupHeader : function(nullHeader)
  4859. {
  4860. if(nullHeader === undefined) {
  4861. nullHeader = true;
  4862. }
  4863. return this.each(function()
  4864. {
  4865. var $t = this, $tr, i, l, headers, $th, $resizing, grid = $t.grid,
  4866. thead = $("table.ui-jqgrid-htable thead", grid.hDiv), cm = $t.p.colModel, hc;
  4867. if(!grid) { return; }
  4868. $(this).unbind('.setGroupHeaders');
  4869. $tr = $("<tr>", {role: "rowheader"}).addClass("ui-jqgrid-labels");
  4870. headers = grid.headers;
  4871. for (i = 0, l = headers.length; i < l; i++) {
  4872. hc = cm[i].hidden ? "none" : "";
  4873. $th = $(headers[i].el)
  4874. .width(headers[i].width)
  4875. .css('display',hc);
  4876. try {
  4877. $th.removeAttr("rowSpan");
  4878. } catch (rs) {
  4879. //IE 6/7
  4880. $th.attr("rowSpan",1);
  4881. }
  4882. $tr.append($th);
  4883. $resizing = $th.children("span.ui-jqgrid-resize");
  4884. if ($resizing.length>0) {// resizable column
  4885. $resizing[0].style.height = "";
  4886. }
  4887. $th.children("div")[0].style.top = "";
  4888. }
  4889. $(thead).children('tr.ui-jqgrid-labels').remove();
  4890. $(thead).prepend($tr);
  4891. if(nullHeader === true) {
  4892. $($t).jqGrid('setGridParam',{ 'groupHeader': null});
  4893. }
  4894. });
  4895. },
  4896. setGroupHeaders : function ( o ) {
  4897. o = $.extend({
  4898. useColSpanStyle : false,
  4899. groupHeaders: []
  4900. },o || {});
  4901. return this.each(function(){
  4902. this.p.groupHeader = o;
  4903. var ts = this,
  4904. i, cmi, skip = 0, $tr, $colHeader, th, $th, thStyle,
  4905. iCol,
  4906. cghi,
  4907. //startColumnName,
  4908. numberOfColumns,
  4909. titleText,
  4910. cVisibleColumns,
  4911. colModel = ts.p.colModel,
  4912. cml = colModel.length,
  4913. ths = ts.grid.headers,
  4914. $htable = $("table.ui-jqgrid-htable", ts.grid.hDiv),
  4915. $trLabels = $htable.children("thead").children("tr.ui-jqgrid-labels:last").addClass("jqg-second-row-header"),
  4916. $thead = $htable.children("thead"),
  4917. $theadInTable,
  4918. $firstHeaderRow = $htable.find(".jqg-first-row-header");
  4919. if($firstHeaderRow[0] === undefined) {
  4920. $firstHeaderRow = $('<tr>', {role: "row", "aria-hidden": "true"}).addClass("jqg-first-row-header").css("height", "auto");
  4921. } else {
  4922. $firstHeaderRow.empty();
  4923. }
  4924. var $firstRow,
  4925. inColumnHeader = function (text, columnHeaders) {
  4926. var length = columnHeaders.length, i;
  4927. for (i = 0; i < length; i++) {
  4928. if (columnHeaders[i].startColumnName === text) {
  4929. return i;
  4930. }
  4931. }
  4932. return -1;
  4933. };
  4934. $(ts).prepend($thead);
  4935. $tr = $('<tr>', {role: "rowheader"}).addClass("ui-jqgrid-labels jqg-third-row-header");
  4936. for (i = 0; i < cml; i++) {
  4937. th = ths[i].el;
  4938. $th = $(th);
  4939. cmi = colModel[i];
  4940. // build the next cell for the first header row
  4941. thStyle = { height: '0px', width: ths[i].width + 'px', display: (cmi.hidden ? 'none' : '')};
  4942. $("<th>", {role: 'gridcell'}).css(thStyle).addClass("ui-first-th-"+ts.p.direction).appendTo($firstHeaderRow);
  4943. th.style.width = ""; // remove unneeded style
  4944. iCol = inColumnHeader(cmi.name, o.groupHeaders);
  4945. if (iCol >= 0) {
  4946. cghi = o.groupHeaders[iCol];
  4947. numberOfColumns = cghi.numberOfColumns;
  4948. titleText = cghi.titleText;
  4949. // caclulate the number of visible columns from the next numberOfColumns columns
  4950. for (cVisibleColumns = 0, iCol = 0; iCol < numberOfColumns && (i + iCol < cml); iCol++) {
  4951. if (!colModel[i + iCol].hidden) {
  4952. cVisibleColumns++;
  4953. }
  4954. }
  4955. // The next numberOfColumns headers will be moved in the next row
  4956. // in the current row will be placed the new column header with the titleText.
  4957. // The text will be over the cVisibleColumns columns
  4958. $colHeader = $('<th>').attr({role: "columnheader"})
  4959. .addClass("ui-state-default ui-th-column-header ui-th-"+ts.p.direction)
  4960. .css({'height':'22px', 'border-top': '0 none'})
  4961. .html(titleText);
  4962. if(cVisibleColumns > 0) {
  4963. $colHeader.attr("colspan", String(cVisibleColumns));
  4964. }
  4965. if (ts.p.headertitles) {
  4966. $colHeader.attr("title", $colHeader.text());
  4967. }
  4968. // hide if not a visible cols
  4969. if( cVisibleColumns === 0) {
  4970. $colHeader.hide();
  4971. }
  4972. $th.before($colHeader); // insert new column header before the current
  4973. $tr.append(th); // move the current header in the next row
  4974. // set the coumter of headers which will be moved in the next row
  4975. skip = numberOfColumns - 1;
  4976. } else {
  4977. if (skip === 0) {
  4978. if (o.useColSpanStyle) {
  4979. // expand the header height to two rows
  4980. $th.attr("rowspan", "2");
  4981. } else {
  4982. $('<th>', {role: "columnheader"})
  4983. .addClass("ui-state-default ui-th-column-header ui-th-"+ts.p.direction)
  4984. .css({"display": cmi.hidden ? 'none' : '', 'border-top': '0 none'})
  4985. .insertBefore($th);
  4986. $tr.append(th);
  4987. }
  4988. } else {
  4989. // move the header to the next row
  4990. //$th.css({"padding-top": "2px", height: "19px"});
  4991. $tr.append(th);
  4992. skip--;
  4993. }
  4994. }
  4995. }
  4996. $theadInTable = $(ts).children("thead");
  4997. $theadInTable.prepend($firstHeaderRow);
  4998. $tr.insertAfter($trLabels);
  4999. $htable.append($theadInTable);
  5000. if (o.useColSpanStyle) {
  5001. // Increase the height of resizing span of visible headers
  5002. $htable.find("span.ui-jqgrid-resize").each(function () {
  5003. var $parent = $(this).parent();
  5004. if ($parent.is(":visible")) {
  5005. this.style.cssText = 'height: ' + $parent.height() + 'px !important; cursor: col-resize;';
  5006. }
  5007. });
  5008. // Set position of the sortable div (the main lable)
  5009. // with the column header text to the middle of the cell.
  5010. // One should not do this for hidden headers.
  5011. $htable.find("div.ui-jqgrid-sortable").each(function () {
  5012. var $ts = $(this), $parent = $ts.parent();
  5013. if ($parent.is(":visible") && $parent.is(":has(span.ui-jqgrid-resize)")) {
  5014. $ts.css('top', ($parent.height() - $ts.outerHeight()) / 2 + 'px');
  5015. }
  5016. });
  5017. }
  5018. $firstRow = $theadInTable.find("tr.jqg-first-row-header");
  5019. $(ts).bind('jqGridResizeStop.setGroupHeaders', function (e, nw, idx) {
  5020. $firstRow.find('th').eq(idx).width(nw);
  5021. });
  5022. });
  5023. },
  5024. setFrozenColumns : function () {
  5025. return this.each(function() {
  5026. if ( !this.grid ) {return;}
  5027. var $t = this, cm = $t.p.colModel,i=0, len = cm.length, maxfrozen = -1, frozen= false;
  5028. // TODO treeGrid and grouping Support
  5029. if($t.p.subGrid === true || $t.p.treeGrid === true || $t.p.cellEdit === true || $t.p.sortable || $t.p.scroll )
  5030. {
  5031. return;
  5032. }
  5033. if($t.p.rownumbers) { i++; }
  5034. if($t.p.multiselect) { i++; }
  5035. // get the max index of frozen col
  5036. while(i<len)
  5037. {
  5038. // from left, no breaking frozen
  5039. if(cm[i].frozen === true)
  5040. {
  5041. frozen = true;
  5042. maxfrozen = i;
  5043. } else {
  5044. break;
  5045. }
  5046. i++;
  5047. }
  5048. if( maxfrozen>=0 && frozen) {
  5049. var top = $t.p.caption ? $($t.grid.cDiv).outerHeight() : 0,
  5050. hth = $(".ui-jqgrid-htable","#gview_"+$.jgrid.jqID($t.p.id)).height();
  5051. //headers
  5052. if($t.p.toppager) {
  5053. top = top + $($t.grid.topDiv).outerHeight();
  5054. }
  5055. if($t.p.toolbar[0] === true) {
  5056. if($t.p.toolbar[1] !== "bottom") {
  5057. top = top + $($t.grid.uDiv).outerHeight();
  5058. }
  5059. }
  5060. $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>');
  5061. $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>');
  5062. $("#gview_"+$.jgrid.jqID($t.p.id)).append($t.grid.fhDiv);
  5063. var htbl = $(".ui-jqgrid-htable","#gview_"+$.jgrid.jqID($t.p.id)).clone(true);
  5064. // groupheader support - only if useColSpanstyle is false
  5065. if($t.p.groupHeader) {
  5066. $("tr.jqg-first-row-header, tr.jqg-third-row-header", htbl).each(function(){
  5067. $("th:gt("+maxfrozen+")",this).remove();
  5068. });
  5069. var swapfroz = -1, fdel = -1, cs, rs;
  5070. $("tr.jqg-second-row-header th", htbl).each(function(){
  5071. cs= parseInt($(this).attr("colspan"),10);
  5072. rs= parseInt($(this).attr("rowspan"),10);
  5073. if(rs) {
  5074. swapfroz++;
  5075. fdel++;
  5076. }
  5077. if(cs) {
  5078. swapfroz = swapfroz+cs;
  5079. fdel++;
  5080. }
  5081. if(swapfroz === maxfrozen) {
  5082. return false;
  5083. }
  5084. });
  5085. if(swapfroz !== maxfrozen) {
  5086. fdel = maxfrozen;
  5087. }
  5088. $("tr.jqg-second-row-header", htbl).each(function(){
  5089. $("th:gt("+fdel+")",this).remove();
  5090. });
  5091. } else {
  5092. $("tr",htbl).each(function(){
  5093. $("th:gt("+maxfrozen+")",this).remove();
  5094. });
  5095. }
  5096. $(htbl).width(1);
  5097. // resizing stuff
  5098. $($t.grid.fhDiv).append(htbl)
  5099. .mousemove(function (e) {
  5100. if($t.grid.resizing){ $t.grid.dragMove(e);return false; }
  5101. });
  5102. $($t).bind('jqGridResizeStop.setFrozenColumns', function (e, w, index) {
  5103. var rhth = $(".ui-jqgrid-htable",$t.grid.fhDiv);
  5104. $("th:eq("+index+")",rhth).width( w );
  5105. var btd = $(".ui-jqgrid-btable",$t.grid.fbDiv);
  5106. $("tr:first td:eq("+index+")",btd).width( w );
  5107. });
  5108. // sorting stuff
  5109. $($t).bind('jqGridSortCol.setFrozenColumns', function (e, index, idxcol) {
  5110. 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);
  5111. $("span.ui-grid-ico-sort",previousSelectedTh).addClass('ui-state-disabled');
  5112. $(previousSelectedTh).attr("aria-selected","false");
  5113. $("span.ui-icon-"+$t.p.sortorder,newSelectedTh).removeClass('ui-state-disabled');
  5114. $(newSelectedTh).attr("aria-selected","true");
  5115. if(!$t.p.viewsortcols[0]) {
  5116. if($t.p.lastsort !== idxcol) {
  5117. $("span.s-ico",previousSelectedTh).hide();
  5118. $("span.s-ico",newSelectedTh).show();
  5119. }
  5120. }
  5121. });
  5122. // data stuff
  5123. //TODO support for setRowData
  5124. $("#gview_"+$.jgrid.jqID($t.p.id)).append($t.grid.fbDiv);
  5125. $($t.grid.bDiv).scroll(function () {
  5126. $($t.grid.fbDiv).scrollTop($(this).scrollTop());
  5127. });
  5128. if($t.p.hoverrows === true) {
  5129. $("#"+$.jgrid.jqID($t.p.id)).unbind('mouseover').unbind('mouseout');
  5130. }
  5131. $($t).bind('jqGridAfterGridComplete.setFrozenColumns', function () {
  5132. $("#"+$.jgrid.jqID($t.p.id)+"_frozen").remove();
  5133. $($t.grid.fbDiv).height($($t.grid.bDiv).height()-16);
  5134. var btbl = $("#"+$.jgrid.jqID($t.p.id)).clone(true);
  5135. $("tr[role=row]",btbl).each(function(){
  5136. $("td[role=gridcell]:gt("+maxfrozen+")",this).remove();
  5137. });
  5138. $(btbl).width(1).attr("id",$t.p.id+"_frozen");
  5139. $($t.grid.fbDiv).append(btbl);
  5140. if($t.p.hoverrows === true) {
  5141. $("tr.jqgrow", btbl).hover(
  5142. function(){ $(this).addClass("ui-state-hover"); $("#"+$.jgrid.jqID(this.id), "#"+$.jgrid.jqID($t.p.id)).addClass("ui-state-hover"); },
  5143. function(){ $(this).removeClass("ui-state-hover"); $("#"+$.jgrid.jqID(this.id), "#"+$.jgrid.jqID($t.p.id)).removeClass("ui-state-hover"); }
  5144. );
  5145. $("tr.jqgrow", "#"+$.jgrid.jqID($t.p.id)).hover(
  5146. function(){ $(this).addClass("ui-state-hover"); $("#"+$.jgrid.jqID(this.id), "#"+$.jgrid.jqID($t.p.id)+"_frozen").addClass("ui-state-hover");},
  5147. function(){ $(this).removeClass("ui-state-hover"); $("#"+$.jgrid.jqID(this.id), "#"+$.jgrid.jqID($t.p.id)+"_frozen").removeClass("ui-state-hover"); }
  5148. );
  5149. }
  5150. btbl=null;
  5151. });
  5152. if(!$t.grid.hDiv.loading) {
  5153. $($t).triggerHandler("jqGridAfterGridComplete");
  5154. }
  5155. $t.p.frozenColumns = true;
  5156. }
  5157. });
  5158. },
  5159. destroyFrozenColumns : function() {
  5160. return this.each(function() {
  5161. if ( !this.grid ) {return;}
  5162. if(this.p.frozenColumns === true) {
  5163. var $t = this;
  5164. $($t.grid.fhDiv).remove();
  5165. $($t.grid.fbDiv).remove();
  5166. $t.grid.fhDiv = null; $t.grid.fbDiv=null;
  5167. $(this).unbind('.setFrozenColumns');
  5168. if($t.p.hoverrows === true) {
  5169. var ptr;
  5170. $("#"+$.jgrid.jqID($t.p.id)).bind('mouseover',function(e) {
  5171. ptr = $(e.target).closest("tr.jqgrow");
  5172. if($(ptr).attr("class") !== "ui-subgrid") {
  5173. $(ptr).addClass("ui-state-hover");
  5174. }
  5175. }).bind('mouseout',function(e) {
  5176. ptr = $(e.target).closest("tr.jqgrow");
  5177. $(ptr).removeClass("ui-state-hover");
  5178. });
  5179. }
  5180. this.p.frozenColumns = false;
  5181. }
  5182. });
  5183. }
  5184. });
  5185. })(jQuery);
  5186. /*
  5187. * jqModal - Minimalist Modaling with jQuery
  5188. * (http://dev.iceburg.net/jquery/jqmodal/)
  5189. *
  5190. * Copyright (c) 2007,2008 Brice Burgess <bhb@iceburg.net>
  5191. * Dual licensed under the MIT and GPL licenses:
  5192. * http://www.opensource.org/licenses/mit-license.php
  5193. * http://www.gnu.org/licenses/gpl.html
  5194. *
  5195. * $Version: 07/06/2008 +r13
  5196. */
  5197. (function($) {
  5198. $.fn.jqm=function(o){
  5199. var p={
  5200. overlay: 50,
  5201. closeoverlay : true,
  5202. overlayClass: 'jqmOverlay',
  5203. closeClass: 'jqmClose',
  5204. trigger: '.jqModal',
  5205. ajax: F,
  5206. ajaxText: '',
  5207. target: F,
  5208. modal: F,
  5209. toTop: F,
  5210. onShow: F,
  5211. onHide: F,
  5212. onLoad: F
  5213. };
  5214. return this.each(function(){if(this._jqm)return H[this._jqm].c=$.extend({},H[this._jqm].c,o);s++;this._jqm=s;
  5215. H[s]={c:$.extend(p,$.jqm.params,o),a:F,w:$(this).addClass('jqmID'+s),s:s};
  5216. if(p.trigger)$(this).jqmAddTrigger(p.trigger);
  5217. });};
  5218. $.fn.jqmAddClose=function(e){return hs(this,e,'jqmHide');};
  5219. $.fn.jqmAddTrigger=function(e){return hs(this,e,'jqmShow');};
  5220. $.fn.jqmShow=function(t){return this.each(function(){$.jqm.open(this._jqm,t);});};
  5221. $.fn.jqmHide=function(t){return this.each(function(){$.jqm.close(this._jqm,t)});};
  5222. $.jqm = {
  5223. hash:{},
  5224. 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);
  5225. if(c.modal) {if(!A[0])setTimeout(function(){L('bind');},1);A.push(s);}
  5226. else if(c.overlay > 0) {if(c.closeoverlay) h.w.jqmAddClose(o);}
  5227. else o=F;
  5228. h.o=(o)?o.addClass(c.overlayClass).prependTo('body'):F;
  5229. 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;
  5230. 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);});}
  5231. else if(cc)h.w.jqmAddClose($(cc,h.w));
  5232. if(c.toTop&&h.o)h.w.before('<span id="jqmP'+h.w[0]._jqm+'"></span>').insertAfter(h.o);
  5233. (c.onShow)?c.onShow(h):h.w.show();e(h);return F;
  5234. },
  5235. close:function(s){var h=H[s];if(!h.a)return F;h.a=F;
  5236. if(A[0]){A.pop();if(!A[0])L('unbind');}
  5237. if(h.c.toTop&&h.o)$('#jqmP'+h.w[0]._jqm).after(h.w).remove();
  5238. if(h.c.onHide)h.c.onHide(h);else{h.w.hide();if(h.o)h.o.remove();} return F;
  5239. },
  5240. params:{}};
  5241. var s=0,H=$.jqm.hash,A=[],F=false,
  5242. e=function(h){f(h);},
  5243. f=function(h){try{$(':input:visible',h.w)[0].focus();}catch(_){}},
  5244. L=function(t){$(document)[t]("keypress",m)[t]("keydown",m)[t]("mousedown",m);},
  5245. 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;},
  5246. hs=function(w,t,c){return w.each(function(){var s=this._jqm;$(t).each(function() {
  5247. 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);});});};
  5248. })(jQuery);/*
  5249. * jqDnR - Minimalistic Drag'n'Resize for jQuery.
  5250. *
  5251. * Copyright (c) 2007 Brice Burgess <bhb@iceburg.net>, http://www.iceburg.net
  5252. * Licensed under the MIT License:
  5253. * http://www.opensource.org/licenses/mit-license.php
  5254. *
  5255. * $Version: 2007.08.19 +r2
  5256. */
  5257. (function($){
  5258. $.fn.jqDrag=function(h){return i(this,h,'d');};
  5259. $.fn.jqResize=function(h,ar){return i(this,h,'r',ar);};
  5260. $.jqDnR={
  5261. dnr:{},
  5262. e:0,
  5263. drag:function(v){
  5264. if(M.k == 'd'){E.css({left:M.X+v.pageX-M.pX,top:M.Y+v.pageY-M.pY});}
  5265. else {
  5266. E.css({width:Math.max(v.pageX-M.pX+M.W,0),height:Math.max(v.pageY-M.pY+M.H,0)});
  5267. if(M1){E1.css({width:Math.max(v.pageX-M1.pX+M1.W,0),height:Math.max(v.pageY-M1.pY+M1.H,0)});}
  5268. }
  5269. return false;
  5270. },
  5271. stop:function(){
  5272. //E.css('opacity',M.o);
  5273. $(document).unbind('mousemove',J.drag).unbind('mouseup',J.stop);
  5274. }
  5275. };
  5276. var J=$.jqDnR,M=J.dnr,E=J.e,E1,M1,
  5277. i=function(e,h,k,aR){
  5278. return e.each(function(){
  5279. h=(h)?$(h,e):e;
  5280. h.bind('mousedown',{e:e,k:k},function(v){
  5281. var d=v.data,p={};E=d.e;E1 = aR ? $(aR) : false;
  5282. // attempt utilization of dimensions plugin to fix IE issues
  5283. if(E.css('position') != 'relative'){try{E.position(p);}catch(e){}}
  5284. M={
  5285. X:p.left||f('left')||0,
  5286. Y:p.top||f('top')||0,
  5287. W:f('width')||E[0].scrollWidth||0,
  5288. H:f('height')||E[0].scrollHeight||0,
  5289. pX:v.pageX,
  5290. pY:v.pageY,
  5291. k:d.k
  5292. //o:E.css('opacity')
  5293. };
  5294. // also resize
  5295. if(E1 && d.k != 'd'){
  5296. M1={
  5297. X:p.left||f1('left')||0,
  5298. Y:p.top||f1('top')||0,
  5299. W:E1[0].offsetWidth||f1('width')||0,
  5300. H:E1[0].offsetHeight||f1('height')||0,
  5301. pX:v.pageX,
  5302. pY:v.pageY,
  5303. k:d.k
  5304. };
  5305. } else {M1 = false;}
  5306. //E.css({opacity:0.8});
  5307. if($("input.hasDatepicker",E[0])[0]) {
  5308. try {$("input.hasDatepicker",E[0]).datepicker('hide');}catch (dpe){}
  5309. }
  5310. $(document).mousemove($.jqDnR.drag).mouseup($.jqDnR.stop);
  5311. return false;
  5312. });
  5313. });
  5314. },
  5315. f=function(k){return parseInt(E.css(k),10)||false;},
  5316. f1=function(k){return parseInt(E1.css(k),10)||false;};
  5317. })(jQuery);/*
  5318. The below work is licensed under Creative Commons GNU LGPL License.
  5319. Original work:
  5320. License: http://creativecommons.org/licenses/LGPL/2.1/
  5321. Author: Stefan Goessner/2006
  5322. Web: http://goessner.net/
  5323. Modifications made:
  5324. Version: 0.9-p5
  5325. Description: Restructured code, JSLint validated (no strict whitespaces),
  5326. added handling of empty arrays, empty strings, and int/floats values.
  5327. Author: Michael Sch酶ler/2008-01-29
  5328. Web: http://michael.hinnerup.net/blog/2008/01/26/converting-json-to-xml-and-xml-to-json/
  5329. Description: json2xml added support to convert functions as CDATA
  5330. so it will be easy to write characters that cause some problems when convert
  5331. Author: Tony Tomov
  5332. */
  5333. /*global alert */
  5334. var xmlJsonClass = {
  5335. // Param "xml": Element or document DOM node.
  5336. // Param "tab": Tab or indent string for pretty output formatting omit or use empty string "" to supress.
  5337. // Returns: JSON string
  5338. xml2json: function(xml, tab) {
  5339. if (xml.nodeType === 9) {
  5340. // document node
  5341. xml = xml.documentElement;
  5342. }
  5343. var nws = this.removeWhite(xml);
  5344. var obj = this.toObj(nws);
  5345. var json = this.toJson(obj, xml.nodeName, "\t");
  5346. return "{\n" + tab + (tab ? json.replace(/\t/g, tab) : json.replace(/\t|\n/g, "")) + "\n}";
  5347. },
  5348. // Param "o": JavaScript object
  5349. // Param "tab": tab or indent string for pretty output formatting omit or use empty string "" to supress.
  5350. // Returns: XML string
  5351. json2xml: function(o, tab) {
  5352. var toXml = function(v, name, ind) {
  5353. var xml = "";
  5354. var i, n;
  5355. if (v instanceof Array) {
  5356. if (v.length === 0) {
  5357. xml += ind + "<"+name+">__EMPTY_ARRAY_</"+name+">\n";
  5358. }
  5359. else {
  5360. for (i = 0, n = v.length; i < n; i += 1) {
  5361. var sXml = ind + toXml(v[i], name, ind+"\t") + "\n";
  5362. xml += sXml;
  5363. }
  5364. }
  5365. }
  5366. else if (typeof(v) === "object") {
  5367. var hasChild = false;
  5368. xml += ind + "<" + name;
  5369. var m;
  5370. for (m in v) if (v.hasOwnProperty(m)) {
  5371. if (m.charAt(0) === "@") {
  5372. xml += " " + m.substr(1) + "=\"" + v[m].toString() + "\"";
  5373. }
  5374. else {
  5375. hasChild = true;
  5376. }
  5377. }
  5378. xml += hasChild ? ">" : "/>";
  5379. if (hasChild) {
  5380. for (m in v) if (v.hasOwnProperty(m)) {
  5381. if (m === "#text") {
  5382. xml += v[m];
  5383. }
  5384. else if (m === "#cdata") {
  5385. xml += "<![CDATA[" + v[m] + "]]>";
  5386. }
  5387. else if (m.charAt(0) !== "@") {
  5388. xml += toXml(v[m], m, ind+"\t");
  5389. }
  5390. }
  5391. xml += (xml.charAt(xml.length - 1) === "\n" ? ind : "") + "</" + name + ">";
  5392. }
  5393. }
  5394. else if (typeof(v) === "function") {
  5395. xml += ind + "<" + name + ">" + "<![CDATA[" + v + "]]>" + "</" + name + ">";
  5396. }
  5397. else {
  5398. if (v === undefined ) { v = ""; }
  5399. if (v.toString() === "\"\"" || v.toString().length === 0) {
  5400. xml += ind + "<" + name + ">__EMPTY_STRING_</" + name + ">";
  5401. }
  5402. else {
  5403. xml += ind + "<" + name + ">" + v.toString() + "</" + name + ">";
  5404. }
  5405. }
  5406. return xml;
  5407. };
  5408. var xml = "";
  5409. var m;
  5410. for (m in o) if (o.hasOwnProperty(m)) {
  5411. xml += toXml(o[m], m, "");
  5412. }
  5413. return tab ? xml.replace(/\t/g, tab) : xml.replace(/\t|\n/g, "");
  5414. },
  5415. // Internal methods
  5416. toObj: function(xml) {
  5417. var o = {};
  5418. var FuncTest = /function/i;
  5419. if (xml.nodeType === 1) {
  5420. // element node ..
  5421. if (xml.attributes.length) {
  5422. // element with attributes ..
  5423. var i;
  5424. for (i = 0; i < xml.attributes.length; i += 1) {
  5425. o["@" + xml.attributes[i].nodeName] = (xml.attributes[i].nodeValue || "").toString();
  5426. }
  5427. }
  5428. if (xml.firstChild) {
  5429. // element has child nodes ..
  5430. var textChild = 0, cdataChild = 0, hasElementChild = false;
  5431. var n;
  5432. for (n = xml.firstChild; n; n = n.nextSibling) {
  5433. if (n.nodeType === 1) {
  5434. hasElementChild = true;
  5435. }
  5436. else if (n.nodeType === 3 && n.nodeValue.match(/[^ \f\n\r\t\v]/)) {
  5437. // non-whitespace text
  5438. textChild += 1;
  5439. }
  5440. else if (n.nodeType === 4) {
  5441. // cdata section node
  5442. cdataChild += 1;
  5443. }
  5444. }
  5445. if (hasElementChild) {
  5446. if (textChild < 2 && cdataChild < 2) {
  5447. // structured element with evtl. a single text or/and cdata node ..
  5448. this.removeWhite(xml);
  5449. for (n = xml.firstChild; n; n = n.nextSibling) {
  5450. if (n.nodeType === 3) {
  5451. // text node
  5452. o["#text"] = this.escape(n.nodeValue);
  5453. }
  5454. else if (n.nodeType === 4) {
  5455. // cdata node
  5456. if (FuncTest.test(n.nodeValue)) {
  5457. o[n.nodeName] = [o[n.nodeName], n.nodeValue];
  5458. } else {
  5459. o["#cdata"] = this.escape(n.nodeValue);
  5460. }
  5461. }
  5462. else if (o[n.nodeName]) {
  5463. // multiple occurence of element ..
  5464. if (o[n.nodeName] instanceof Array) {
  5465. o[n.nodeName][o[n.nodeName].length] = this.toObj(n);
  5466. }
  5467. else {
  5468. o[n.nodeName] = [o[n.nodeName], this.toObj(n)];
  5469. }
  5470. }
  5471. else {
  5472. // first occurence of element ..
  5473. o[n.nodeName] = this.toObj(n);
  5474. }
  5475. }
  5476. }
  5477. else {
  5478. // mixed content
  5479. if (!xml.attributes.length) {
  5480. o = this.escape(this.innerXml(xml));
  5481. }
  5482. else {
  5483. o["#text"] = this.escape(this.innerXml(xml));
  5484. }
  5485. }
  5486. }
  5487. else if (textChild) {
  5488. // pure text
  5489. if (!xml.attributes.length) {
  5490. o = this.escape(this.innerXml(xml));
  5491. if (o === "__EMPTY_ARRAY_") {
  5492. o = "[]";
  5493. } else if (o === "__EMPTY_STRING_") {
  5494. o = "";
  5495. }
  5496. }
  5497. else {
  5498. o["#text"] = this.escape(this.innerXml(xml));
  5499. }
  5500. }
  5501. else if (cdataChild) {
  5502. // cdata
  5503. if (cdataChild > 1) {
  5504. o = this.escape(this.innerXml(xml));
  5505. }
  5506. else {
  5507. for (n = xml.firstChild; n; n = n.nextSibling) {
  5508. if(FuncTest.test(xml.firstChild.nodeValue)) {
  5509. o = xml.firstChild.nodeValue;
  5510. break;
  5511. } else {
  5512. o["#cdata"] = this.escape(n.nodeValue);
  5513. }
  5514. }
  5515. }
  5516. }
  5517. }
  5518. if (!xml.attributes.length && !xml.firstChild) {
  5519. o = null;
  5520. }
  5521. }
  5522. else if (xml.nodeType === 9) {
  5523. // document.node
  5524. o = this.toObj(xml.documentElement);
  5525. }
  5526. else {
  5527. alert("unhandled node type: " + xml.nodeType);
  5528. }
  5529. return o;
  5530. },
  5531. toJson: function(o, name, ind, wellform) {
  5532. if(wellform === undefined) wellform = true;
  5533. var json = name ? ("\"" + name + "\"") : "", tab = "\t", newline = "\n";
  5534. if(!wellform) {
  5535. tab= ""; newline= "";
  5536. }
  5537. if (o === "[]") {
  5538. json += (name ? ":[]" : "[]");
  5539. }
  5540. else if (o instanceof Array) {
  5541. var n, i, ar=[];
  5542. for (i = 0, n = o.length; i < n; i += 1) {
  5543. ar[i] = this.toJson(o[i], "", ind + tab, wellform);
  5544. }
  5545. json += (name ? ":[" : "[") + (ar.length > 1 ? (newline + ind + tab + ar.join(","+newline + ind + tab) + newline + ind) : ar.join("")) + "]";
  5546. }
  5547. else if (o === null) {
  5548. json += (name && ":") + "null";
  5549. }
  5550. else if (typeof(o) === "object") {
  5551. var arr = [], m;
  5552. for (m in o) {
  5553. if (o.hasOwnProperty(m)) {
  5554. arr[arr.length] = this.toJson(o[m], m, ind + tab, wellform);
  5555. }
  5556. }
  5557. json += (name ? ":{" : "{") + (arr.length > 1 ? (newline + ind + tab + arr.join(","+newline + ind + tab) + newline + ind) : arr.join("")) + "}";
  5558. }
  5559. else if (typeof(o) === "string") {
  5560. /*
  5561. var objRegExp = /(^-?\d+\.?\d*$)/;
  5562. var FuncTest = /function/i;
  5563. var os = o.toString();
  5564. if (objRegExp.test(os) || FuncTest.test(os) || os==="false" || os==="true") {
  5565. // int or float
  5566. json += (name && ":") + "\"" +os + "\"";
  5567. }
  5568. else {
  5569. */
  5570. json += (name && ":") + "\"" + o.replace(/\\/g,'\\\\').replace(/\"/g,'\\"') + "\"";
  5571. //}
  5572. }
  5573. else {
  5574. json += (name && ":") + o.toString();
  5575. }
  5576. return json;
  5577. },
  5578. innerXml: function(node) {
  5579. var s = "";
  5580. if ("innerHTML" in node) {
  5581. s = node.innerHTML;
  5582. }
  5583. else {
  5584. var asXml = function(n) {
  5585. var s = "", i;
  5586. if (n.nodeType === 1) {
  5587. s += "<" + n.nodeName;
  5588. for (i = 0; i < n.attributes.length; i += 1) {
  5589. s += " " + n.attributes[i].nodeName + "=\"" + (n.attributes[i].nodeValue || "").toString() + "\"";
  5590. }
  5591. if (n.firstChild) {
  5592. s += ">";
  5593. for (var c = n.firstChild; c; c = c.nextSibling) {
  5594. s += asXml(c);
  5595. }
  5596. s += "</" + n.nodeName + ">";
  5597. }
  5598. else {
  5599. s += "/>";
  5600. }
  5601. }
  5602. else if (n.nodeType === 3) {
  5603. s += n.nodeValue;
  5604. }
  5605. else if (n.nodeType === 4) {
  5606. s += "<![CDATA[" + n.nodeValue + "]]>";
  5607. }
  5608. return s;
  5609. };
  5610. for (var c = node.firstChild; c; c = c.nextSibling) {
  5611. s += asXml(c);
  5612. }
  5613. }
  5614. return s;
  5615. },
  5616. escape: function(txt) {
  5617. return txt.replace(/[\\]/g, "\\\\").replace(/[\"]/g, '\\"').replace(/[\n]/g, '\\n').replace(/[\r]/g, '\\r');
  5618. },
  5619. removeWhite: function(e) {
  5620. e.normalize();
  5621. var n;
  5622. for (n = e.firstChild; n; ) {
  5623. if (n.nodeType === 3) {
  5624. // text node
  5625. if (!n.nodeValue.match(/[^ \f\n\r\t\v]/)) {
  5626. // pure whitespace text node
  5627. var nxt = n.nextSibling;
  5628. e.removeChild(n);
  5629. n = nxt;
  5630. }
  5631. else {
  5632. n = n.nextSibling;
  5633. }
  5634. }
  5635. else if (n.nodeType === 1) {
  5636. // element node
  5637. this.removeWhite(n);
  5638. n = n.nextSibling;
  5639. }
  5640. else {
  5641. // any other node
  5642. n = n.nextSibling;
  5643. }
  5644. }
  5645. return e;
  5646. }
  5647. };/*
  5648. **
  5649. * formatter for values but most of the values if for jqGrid
  5650. * Some of this was inspired and based on how YUI does the table datagrid but in jQuery fashion
  5651. * we are trying to keep it as light as possible
  5652. * Joshua Burnett josh@9ci.com
  5653. * http://www.greenbill.com
  5654. *
  5655. * Changes from Tony Tomov tony@trirand.com
  5656. * Dual licensed under the MIT and GPL licenses:
  5657. * http://www.opensource.org/licenses/mit-license.php
  5658. * http://www.gnu.org/licenses/gpl-2.0.html
  5659. *
  5660. **/
  5661. /*jshint eqeqeq:false */
  5662. /*global jQuery */
  5663. (function($) {
  5664. "use strict";
  5665. $.fmatter = {};
  5666. //opts can be id:row id for the row, rowdata:the data for the row, colmodel:the column model for this column
  5667. //example {id:1234,}
  5668. $.extend($.fmatter,{
  5669. isBoolean : function(o) {
  5670. return typeof o === 'boolean';
  5671. },
  5672. isObject : function(o) {
  5673. return (o && (typeof o === 'object' || $.isFunction(o))) || false;
  5674. },
  5675. isString : function(o) {
  5676. return typeof o === 'string';
  5677. },
  5678. isNumber : function(o) {
  5679. return typeof o === 'number' && isFinite(o);
  5680. },
  5681. isValue : function (o) {
  5682. return (this.isObject(o) || this.isString(o) || this.isNumber(o) || this.isBoolean(o));
  5683. },
  5684. isEmpty : function(o) {
  5685. if(!this.isString(o) && this.isValue(o)) {
  5686. return false;
  5687. }
  5688. if (!this.isValue(o)){
  5689. return true;
  5690. }
  5691. o = $.trim(o).replace(/\&nbsp\;/ig,'').replace(/\&#160\;/ig,'');
  5692. return o==="";
  5693. }
  5694. });
  5695. $.fn.fmatter = function(formatType, cellval, opts, rwd, act) {
  5696. //alert("000---"+cellval+"---"+formatType);
  5697. // build main options before element iteration
  5698. var v=cellval;
  5699. opts = $.extend({}, $.jgrid.formatter, opts);
  5700. try {
  5701. v = $.fn.fmatter[formatType].call(this, cellval, opts, rwd, act);
  5702. } catch(fe){}
  5703. return v;
  5704. };
  5705. $.fmatter.util = {
  5706. // Taken from YAHOO utils
  5707. NumberFormat : function(nData,opts) {
  5708. if(!$.fmatter.isNumber(nData)) {
  5709. nData *= 1;
  5710. }
  5711. if($.fmatter.isNumber(nData)) {
  5712. var bNegative = (nData < 0);
  5713. var sOutput = String(nData);
  5714. var sDecimalSeparator = opts.decimalSeparator || ".";
  5715. var nDotIndex;
  5716. if($.fmatter.isNumber(opts.decimalPlaces)) {
  5717. // Round to the correct decimal place
  5718. var nDecimalPlaces = opts.decimalPlaces;
  5719. var nDecimal = Math.pow(10, nDecimalPlaces);
  5720. sOutput = String(Math.round(nData*nDecimal)/nDecimal);
  5721. nDotIndex = sOutput.lastIndexOf(".");
  5722. if(nDecimalPlaces > 0) {
  5723. // Add the decimal separator
  5724. if(nDotIndex < 0) {
  5725. sOutput += sDecimalSeparator;
  5726. nDotIndex = sOutput.length-1;
  5727. }
  5728. // Replace the "."
  5729. else if(sDecimalSeparator !== "."){
  5730. sOutput = sOutput.replace(".",sDecimalSeparator);
  5731. }
  5732. // Add missing zeros
  5733. while((sOutput.length - 1 - nDotIndex) < nDecimalPlaces) {
  5734. sOutput += "0";
  5735. }
  5736. }
  5737. }
  5738. if(opts.thousandsSeparator) {
  5739. var sThousandsSeparator = opts.thousandsSeparator;
  5740. nDotIndex = sOutput.lastIndexOf(sDecimalSeparator);
  5741. nDotIndex = (nDotIndex > -1) ? nDotIndex : sOutput.length;
  5742. var sNewOutput = sOutput.substring(nDotIndex);
  5743. var nCount = -1, i;
  5744. for (i=nDotIndex; i>0; i--) {
  5745. nCount++;
  5746. if ((nCount%3 === 0) && (i !== nDotIndex) && (!bNegative || (i > 1))) {
  5747. sNewOutput = sThousandsSeparator + sNewOutput;
  5748. }
  5749. sNewOutput = sOutput.charAt(i-1) + sNewOutput;
  5750. }
  5751. sOutput = sNewOutput;
  5752. }
  5753. // Prepend prefix
  5754. sOutput = (opts.prefix) ? opts.prefix + sOutput : sOutput;
  5755. // Append suffix
  5756. sOutput = (opts.suffix) ? sOutput + opts.suffix : sOutput;
  5757. return sOutput;
  5758. }
  5759. return nData;
  5760. }
  5761. };
  5762. $.fn.fmatter.defaultFormat = function(cellval, opts) {
  5763. return ($.fmatter.isValue(cellval) && cellval!=="" ) ? cellval : opts.defaultValue || "&#160;";
  5764. };
  5765. $.fn.fmatter.email = function(cellval, opts) {
  5766. if(!$.fmatter.isEmpty(cellval)) {
  5767. return "<a href=\"mailto:" + cellval + "\">" + cellval + "</a>";
  5768. }
  5769. return $.fn.fmatter.defaultFormat(cellval,opts );
  5770. };
  5771. $.fn.fmatter.checkbox =function(cval, opts) {
  5772. var op = $.extend({},opts.checkbox), ds;
  5773. if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
  5774. op = $.extend({},op,opts.colModel.formatoptions);
  5775. }
  5776. if(op.disabled===true) {ds = "disabled=\"disabled\"";} else {ds="";}
  5777. if($.fmatter.isEmpty(cval) || cval === undefined ) {cval = $.fn.fmatter.defaultFormat(cval,op);}
  5778. cval=String(cval);
  5779. cval=(cval+"").toLowerCase();
  5780. var bchk = cval.search(/(false|f|0|no|n|off|undefined)/i)<0 ? " checked='checked' " : "";
  5781. return "<input type=\"checkbox\" " + bchk + " value=\""+ cval+"\" offval=\"no\" "+ds+ "/>";
  5782. };
  5783. $.fn.fmatter.link = function(cellval, opts) {
  5784. var op = {target:opts.target};
  5785. var target = "";
  5786. if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
  5787. op = $.extend({},op,opts.colModel.formatoptions);
  5788. }
  5789. if(op.target) {target = 'target=' + op.target;}
  5790. if(!$.fmatter.isEmpty(cellval)) {
  5791. return "<a "+target+" href=\"" + cellval + "\">" + cellval + "</a>";
  5792. }
  5793. return $.fn.fmatter.defaultFormat(cellval,opts);
  5794. };
  5795. $.fn.fmatter.showlink = function(cellval, opts) {
  5796. var op = {baseLinkUrl: opts.baseLinkUrl,showAction:opts.showAction, addParam: opts.addParam || "", target: opts.target, idName: opts.idName},
  5797. target = "", idUrl;
  5798. if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
  5799. op = $.extend({},op,opts.colModel.formatoptions);
  5800. }
  5801. if(op.target) {target = 'target=' + op.target;}
  5802. idUrl = op.baseLinkUrl+op.showAction + '?'+ op.idName+'='+opts.rowId+op.addParam;
  5803. if($.fmatter.isString(cellval) || $.fmatter.isNumber(cellval)) { //add this one even if its blank string
  5804. return "<a "+target+" href=\"" + idUrl + "\">" + cellval + "</a>";
  5805. }
  5806. return $.fn.fmatter.defaultFormat(cellval,opts);
  5807. };
  5808. $.fn.fmatter.integer = function(cellval, opts) {
  5809. var op = $.extend({},opts.integer);
  5810. if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
  5811. op = $.extend({},op,opts.colModel.formatoptions);
  5812. }
  5813. if($.fmatter.isEmpty(cellval)) {
  5814. return op.defaultValue;
  5815. }
  5816. return $.fmatter.util.NumberFormat(cellval,op);
  5817. };
  5818. $.fn.fmatter.number = function (cellval, opts) {
  5819. var op = $.extend({},opts.number);
  5820. if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
  5821. op = $.extend({},op,opts.colModel.formatoptions);
  5822. }
  5823. if($.fmatter.isEmpty(cellval)) {
  5824. return op.defaultValue;
  5825. }
  5826. return $.fmatter.util.NumberFormat(cellval,op);
  5827. };
  5828. $.fn.fmatter.currency = function (cellval, opts) {
  5829. var op = $.extend({},opts.currency);
  5830. if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
  5831. op = $.extend({},op,opts.colModel.formatoptions);
  5832. }
  5833. if($.fmatter.isEmpty(cellval)) {
  5834. return op.defaultValue;
  5835. }
  5836. return $.fmatter.util.NumberFormat(cellval,op);
  5837. };
  5838. $.fn.fmatter.date = function (cellval, opts, rwd, act) {
  5839. var op = $.extend({},opts.date);
  5840. if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
  5841. op = $.extend({},op,opts.colModel.formatoptions);
  5842. }
  5843. if(!op.reformatAfterEdit && act === 'edit'){
  5844. return $.fn.fmatter.defaultFormat(cellval, opts);
  5845. }
  5846. if(!$.fmatter.isEmpty(cellval)) {
  5847. return $.jgrid.parseDate(op.srcformat,cellval,op.newformat,op);
  5848. }
  5849. return $.fn.fmatter.defaultFormat(cellval, opts);
  5850. };
  5851. $.fn.fmatter.select = function (cellval,opts) {
  5852. // jqGrid specific
  5853. var oldValue=cellval;
  5854. cellval = String(cellval);
  5855. var oSelect = false, ret=[], sep, delim;
  5856. if(opts.colModel.formatoptions !== undefined){
  5857. oSelect= opts.colModel.formatoptions.value;
  5858. sep = opts.colModel.formatoptions.separator === undefined ? ":" : opts.colModel.formatoptions.separator;
  5859. delim = opts.colModel.formatoptions.delimiter === undefined ? ";" : opts.colModel.formatoptions.delimiter;
  5860. } else if(opts.colModel.editoptions !== undefined){
  5861. oSelect= opts.colModel.editoptions.value;
  5862. sep = opts.colModel.editoptions.separator === undefined ? ":" : opts.colModel.editoptions.separator;
  5863. delim = opts.colModel.editoptions.delimiter === undefined ? ";" : opts.colModel.editoptions.delimiter;
  5864. }
  5865. if (oSelect) {
  5866. var msl = (opts.colModel.editoptions != null && opts.colModel.editoptions.multiple === true) === true ? true : false,
  5867. scell = [], sv;
  5868. if(msl) {scell = cellval.split(",");scell = $.map(scell,function(n){return $.trim(n);});}
  5869. if ($.fmatter.isString(oSelect)) {
  5870. // mybe here we can use some caching with care ????
  5871. var so = oSelect.split(delim), j=0, i;
  5872. for(i=0; i<so.length;i++){
  5873. sv = so[i].split(sep);
  5874. if(sv.length > 2 ) {
  5875. sv[1] = $.map(sv,function(n,i){if(i>0) {return n;}}).join(sep);
  5876. }
  5877. if(msl) {
  5878. if($.inArray(sv[0],scell)>-1) {
  5879. ret[j] = sv[1];
  5880. j++;
  5881. }
  5882. } else if($.trim(sv[0]) === $.trim(cellval)) {
  5883. ret[0] = sv[1];
  5884. break;
  5885. }
  5886. }
  5887. } else if($.fmatter.isObject(oSelect)) {
  5888. // this is quicker
  5889. if(msl) {
  5890. ret = $.map(scell, function(n){
  5891. return oSelect[n];
  5892. });
  5893. } else {
  5894. ret[0] = oSelect[cellval] || "";
  5895. }
  5896. }
  5897. }
  5898. cellval = ret.join(", ");
  5899. if(cellval === ""){
  5900. cellval =oldValue;
  5901. }
  5902. return cellval === "" ? $.fn.fmatter.defaultFormat(cellval,opts) : cellval;
  5903. };
  5904. $.fn.fmatter.rowactions = function(act) {
  5905. var $tr = $(this).closest("tr.jqgrow"),
  5906. rid = $tr.attr("id"),
  5907. $id = $(this).closest("table.ui-jqgrid-btable").attr('id').replace(/_frozen([^_]*)$/,'$1'),
  5908. $grid = $("#"+$id),
  5909. $t = $grid[0],
  5910. p = $t.p,
  5911. cm = p.colModel[$.jgrid.getCellIndex(this)],
  5912. $actionsDiv = cm.frozen ? $("tr#"+rid+" td:eq("+$.jgrid.getCellIndex(this)+") > div",$grid) :$(this).parent(),
  5913. op = {
  5914. extraparam: {}
  5915. },
  5916. saverow = function(rowid, res) {
  5917. //alert("saverow");
  5918. if($.isFunction(op.afterSave)) { op.afterSave.call($t, rowid, res); }
  5919. $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show();
  5920. $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide();
  5921. },
  5922. restorerow = function(rowid) {
  5923. if($.isFunction(op.afterRestore)) { op.afterRestore.call($t, rowid); }
  5924. $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show();
  5925. $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide();
  5926. };
  5927. if (cm.formatoptions !== undefined) {
  5928. op = $.extend(op,cm.formatoptions);
  5929. }
  5930. if (p.editOptions !== undefined) {
  5931. op.editOptions = p.editOptions;
  5932. }
  5933. if (p.delOptions !== undefined) {
  5934. op.delOptions = p.delOptions;
  5935. }
  5936. if ($tr.hasClass("jqgrid-new-row")){
  5937. op.extraparam[p.prmNames.oper] = p.prmNames.addoper;
  5938. }
  5939. var actop = {
  5940. keys: op.keys,
  5941. oneditfunc: op.onEdit,
  5942. successfunc: op.onSuccess,
  5943. url: op.url,
  5944. extraparam: op.extraparam,
  5945. aftersavefunc: saverow,
  5946. errorfunc: op.onError,
  5947. afterrestorefunc: restorerow,
  5948. restoreAfterError: op.restoreAfterError,
  5949. mtype: op.mtype
  5950. };
  5951. switch(act)
  5952. {
  5953. case 'edit':
  5954. $grid.jqGrid('editRow', rid, actop);
  5955. $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").hide();
  5956. $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").show();
  5957. $grid.triggerHandler("jqGridAfterGridComplete");
  5958. break;
  5959. case 'save':
  5960. if ($grid.jqGrid('saveRow', rid, actop)) {
  5961. $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show();
  5962. $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide();
  5963. $grid.triggerHandler("jqGridAfterGridComplete");
  5964. }
  5965. break;
  5966. case 'cancel' :
  5967. $grid.jqGrid('restoreRow', rid, restorerow);
  5968. $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show();
  5969. $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide();
  5970. $grid.triggerHandler("jqGridAfterGridComplete");
  5971. break;
  5972. case 'del':
  5973. $grid.jqGrid('delGridRow', rid, op.delOptions);
  5974. break;
  5975. case 'formedit':
  5976. $grid.jqGrid('setSelection', rid);
  5977. $grid.jqGrid('editGridRow', rid, op.editOptions);
  5978. break;
  5979. }
  5980. };
  5981. $.fn.fmatter.actions = function(cellval,opts) {
  5982. var op={keys:false, editbutton:true, delbutton:true, editformbutton: false},
  5983. rowid=opts.rowId, str="",ocl;
  5984. if(opts.colModel.formatoptions !== undefined) {
  5985. op = $.extend(op,opts.colModel.formatoptions);
  5986. }
  5987. if(rowid === undefined || $.fmatter.isEmpty(rowid)) {return "";}
  5988. if(op.editformbutton){
  5989. 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'); ";
  5990. 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>";
  5991. } else if(op.editbutton){
  5992. 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') ";
  5993. 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>";
  5994. }
  5995. if(op.delbutton) {
  5996. 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'); ";
  5997. 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>";
  5998. }
  5999. 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'); ";
  6000. 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>";
  6001. 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'); ";
  6002. 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>";
  6003. return "<div style='margin-left:8px;'>" + str + "</div>";
  6004. };
  6005. $.unformat = function (cellval,options,pos,cnt) {
  6006. // specific for jqGrid only
  6007. var ret, formatType = options.colModel.formatter,
  6008. op =options.colModel.formatoptions || {}, sep,
  6009. re = /([\.\*\_\'\(\)\{\}\+\?\\])/g,
  6010. unformatFunc = options.colModel.unformat||($.fn.fmatter[formatType] && $.fn.fmatter[formatType].unformat);
  6011. if(unformatFunc !== undefined && $.isFunction(unformatFunc) ) {
  6012. ret = unformatFunc.call(this, $(cellval).text(), options, cellval);
  6013. } else if(formatType !== undefined && $.fmatter.isString(formatType) ) {
  6014. var opts = $.jgrid.formatter || {}, stripTag;
  6015. switch(formatType) {
  6016. case 'integer' :
  6017. op = $.extend({},opts.integer,op);
  6018. sep = op.thousandsSeparator.replace(re,"\\$1");
  6019. stripTag = new RegExp(sep, "g");
  6020. ret = $(cellval).text().replace(stripTag,'');
  6021. break;
  6022. case 'number' :
  6023. op = $.extend({},opts.number,op);
  6024. sep = op.thousandsSeparator.replace(re,"\\$1");
  6025. stripTag = new RegExp(sep, "g");
  6026. ret = $(cellval).text().replace(stripTag,"").replace(op.decimalSeparator,'.');
  6027. break;
  6028. case 'currency':
  6029. op = $.extend({},opts.currency,op);
  6030. sep = op.thousandsSeparator.replace(re,"\\$1");
  6031. stripTag = new RegExp(sep, "g");
  6032. ret = $(cellval).text();
  6033. if (op.prefix && op.prefix.length) {
  6034. ret = ret.substr(op.prefix.length);
  6035. }
  6036. if (op.suffix && op.suffix.length) {
  6037. ret = ret.substr(0, ret.length - op.suffix.length);
  6038. }
  6039. ret = ret.replace(stripTag,'').replace(op.decimalSeparator,'.');
  6040. break;
  6041. case 'checkbox':
  6042. var cbv = (options.colModel.editoptions) ? options.colModel.editoptions.value.split(":") : ["Yes","No"];
  6043. ret = $('input',cellval).is(":checked") ? cbv[0] : cbv[1];
  6044. break;
  6045. case 'select' :
  6046. ret = $.unformat.select(cellval,options,pos,cnt);
  6047. break;
  6048. case 'actions':
  6049. return "";
  6050. default:
  6051. ret= $(cellval).text();
  6052. }
  6053. }
  6054. return ret !== undefined ? ret : cnt===true ? $(cellval).text() : $.jgrid.htmlDecode($(cellval).html());
  6055. };
  6056. $.unformat.select = function (cellval,options,pos,cnt) {
  6057. // Spacial case when we have local data and perform a sort
  6058. // cnt is set to true only in sortDataArray
  6059. var ret = [];
  6060. var cell = $(cellval).text();
  6061. if(cnt===true) {return cell;}
  6062. var op = $.extend({}, options.colModel.formatoptions !== undefined ? options.colModel.formatoptions: options.colModel.editoptions),
  6063. sep = op.separator === undefined ? ":" : op.separator,
  6064. delim = op.delimiter === undefined ? ";" : op.delimiter;
  6065. if(op.value){
  6066. var oSelect = op.value,
  6067. msl = op.multiple === true ? true : false,
  6068. scell = [], sv;
  6069. if(msl) {scell = cell.split(",");scell = $.map(scell,function(n){return $.trim(n);});}
  6070. if ($.fmatter.isString(oSelect)) {
  6071. var so = oSelect.split(delim), j=0, i;
  6072. for(i=0; i<so.length;i++){
  6073. sv = so[i].split(sep);
  6074. if(sv.length > 2 ) {
  6075. sv[1] = $.map(sv,function(n,i){if(i>0) {return n;}}).join(sep);
  6076. }
  6077. if(msl) {
  6078. if($.inArray(sv[1],scell)>-1) {
  6079. ret[j] = sv[0];
  6080. j++;
  6081. }
  6082. } else if($.trim(sv[1]) === $.trim(cell)) {
  6083. ret[0] = sv[0];
  6084. break;
  6085. }
  6086. }
  6087. } else if($.fmatter.isObject(oSelect) || $.isArray(oSelect) ){
  6088. if(!msl) {scell[0] = cell;}
  6089. ret = $.map(scell, function(n){
  6090. var rv;
  6091. $.each(oSelect, function(i,val){
  6092. if (val === n) {
  6093. rv = i;
  6094. return false;
  6095. }
  6096. });
  6097. if( rv !== undefined ) {return rv;}
  6098. });
  6099. }
  6100. return ret.join(", ");
  6101. }
  6102. return cell || "";
  6103. };
  6104. $.unformat.date = function (cellval, opts) {
  6105. var op = $.jgrid.formatter.date || {};
  6106. if(opts.formatoptions !== undefined) {
  6107. op = $.extend({},op,opts.formatoptions);
  6108. }
  6109. if(!$.fmatter.isEmpty(cellval)) {
  6110. return $.jgrid.parseDate(op.newformat,cellval,op.srcformat,op);
  6111. }
  6112. return $.fn.fmatter.defaultFormat(cellval, opts);
  6113. };
  6114. })(jQuery);
  6115. /*jshint eqeqeq:false */
  6116. /*global jQuery */
  6117. (function($){
  6118. /*
  6119. * jqGrid common function
  6120. * Tony Tomov tony@trirand.com
  6121. * http://trirand.com/blog/
  6122. * Dual licensed under the MIT and GPL licenses:
  6123. * http://www.opensource.org/licenses/mit-license.php
  6124. * http://www.gnu.org/licenses/gpl-2.0.html
  6125. */
  6126. "use strict";
  6127. $.extend($.jgrid,{
  6128. // Modal functions
  6129. showModal : function(h) {
  6130. h.w.show();
  6131. },
  6132. closeModal : function(h) {
  6133. h.w.hide().attr("aria-hidden","true");
  6134. if(h.o) {h.o.remove();}
  6135. },
  6136. hideModal : function (selector,o) {
  6137. o = $.extend({jqm : true, gb :''}, o || {});
  6138. if(o.onClose) {
  6139. 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);
  6140. if (typeof oncret === 'boolean' && !oncret ) { return; }
  6141. }
  6142. if ($.fn.jqm && o.jqm === true) {
  6143. $(selector).attr("aria-hidden","true").jqmHide();
  6144. } else {
  6145. if(o.gb !== '') {
  6146. try {$(".jqgrid-overlay:first",o.gb).hide();} catch (e){}
  6147. }
  6148. $(selector).hide().attr("aria-hidden","true");
  6149. }
  6150. },
  6151. //Helper functions
  6152. findPos : function(obj) {
  6153. var curleft = 0, curtop = 0;
  6154. if (obj.offsetParent) {
  6155. do {
  6156. curleft += obj.offsetLeft;
  6157. curtop += obj.offsetTop;
  6158. } while (obj = obj.offsetParent);
  6159. //do not change obj == obj.offsetParent
  6160. }
  6161. return [curleft,curtop];
  6162. },
  6163. createModal : function(aIDs, content, p, insertSelector, posSelector, appendsel, css) {
  6164. p = $.extend(true, {}, $.jgrid.jqModal || {}, p);
  6165. var mw = document.createElement('div'), rtlsup, self = this;
  6166. css = $.extend({}, css || {});
  6167. rtlsup = $(p.gbox).attr("dir") === "rtl" ? true : false;
  6168. mw.className= "ui-widget ui-widget-content ui-corner-all ui-jqdialog";
  6169. mw.id = aIDs.themodal;
  6170. var mh = document.createElement('div');
  6171. mh.className = "ui-jqdialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix";
  6172. mh.id = aIDs.modalhead;
  6173. $(mh).append("<span class='ui-jqdialog-title'>"+p.caption+"</span>");
  6174. var ahr= $("<a class='ui-jqdialog-titlebar-close ui-corner-all'></a>")
  6175. .hover(function(){ahr.addClass('ui-state-hover');},
  6176. function(){ahr.removeClass('ui-state-hover');})
  6177. .append("<span class='ui-icon ui-icon-closethick'></span>");
  6178. $(mh).append(ahr);
  6179. if(rtlsup) {
  6180. mw.dir = "rtl";
  6181. $(".ui-jqdialog-title",mh).css("float","right");
  6182. $(".ui-jqdialog-titlebar-close",mh).css("left",0.3+"em");
  6183. } else {
  6184. mw.dir = "ltr";
  6185. $(".ui-jqdialog-title",mh).css("float","left");
  6186. $(".ui-jqdialog-titlebar-close",mh).css("right",0.3+"em");
  6187. }
  6188. var mc = document.createElement('div');
  6189. $(mc).addClass("ui-jqdialog-content ui-widget-content").attr("id",aIDs.modalcontent);
  6190. $(mc).append(content);
  6191. mw.appendChild(mc);
  6192. $(mw).prepend(mh);
  6193. if(appendsel===true) { $('body').append(mw); } //append as first child in body -for alert dialog
  6194. else if (typeof appendsel === "string") {
  6195. $(appendsel).append(mw);
  6196. } else {$(mw).insertBefore(insertSelector);}
  6197. $(mw).css(css);
  6198. if(p.jqModal === undefined) {p.jqModal = true;} // internal use
  6199. var coord = {};
  6200. if ( $.fn.jqm && p.jqModal === true) {
  6201. if(p.left ===0 && p.top===0 && p.overlay) {
  6202. var pos = [];
  6203. pos = $.jgrid.findPos(posSelector);
  6204. p.left = pos[0] + 4;
  6205. p.top = pos[1] + 4;
  6206. }
  6207. coord.top = p.top+"px";
  6208. coord.left = p.left;
  6209. } else if(p.left !==0 || p.top!==0) {
  6210. coord.left = p.left;
  6211. coord.top = p.top+"px";
  6212. }
  6213. $("a.ui-jqdialog-titlebar-close",mh).click(function(){
  6214. var oncm = $("#"+$.jgrid.jqID(aIDs.themodal)).data("onClose") || p.onClose;
  6215. var gboxclose = $("#"+$.jgrid.jqID(aIDs.themodal)).data("gbox") || p.gbox;
  6216. self.hideModal("#"+$.jgrid.jqID(aIDs.themodal),{gb:gboxclose,jqm:p.jqModal,onClose:oncm});
  6217. return false;
  6218. });
  6219. if (p.width === 0 || !p.width) {p.width = 300;}
  6220. if(p.height === 0 || !p.height) {p.height =200;}
  6221. if(!p.zIndex) {
  6222. var parentZ = $(insertSelector).parents("*[role=dialog]").filter(':first').css("z-index");
  6223. if(parentZ) {
  6224. p.zIndex = parseInt(parentZ,10)+2;
  6225. } else {
  6226. p.zIndex = 950;
  6227. }
  6228. }
  6229. var rtlt = 0;
  6230. if( rtlsup && coord.left && !appendsel) {
  6231. rtlt = $(p.gbox).width()- (!isNaN(p.width) ? parseInt(p.width,10) :0) - 8; // to do
  6232. // just in case
  6233. coord.left = parseInt(coord.left,10) + parseInt(rtlt,10);
  6234. }
  6235. if(coord.left) { coord.left += "px"; }
  6236. $(mw).css($.extend({
  6237. width: isNaN(p.width) ? "auto": p.width+"px",
  6238. height:isNaN(p.height) ? "auto" : p.height + "px",
  6239. zIndex:p.zIndex,
  6240. overflow: 'hidden'
  6241. },coord))
  6242. .attr({tabIndex: "-1","role":"dialog","aria-labelledby":aIDs.modalhead,"aria-hidden":"true"});
  6243. if(p.drag === undefined) { p.drag=true;}
  6244. if(p.resize === undefined) {p.resize=true;}
  6245. if (p.drag) {
  6246. $(mh).css('cursor','move');
  6247. if($.fn.jqDrag) {
  6248. $(mw).jqDrag(mh);
  6249. } else {
  6250. try {
  6251. $(mw).draggable({handle: $("#"+$.jgrid.jqID(mh.id))});
  6252. } catch (e) {}
  6253. }
  6254. }
  6255. if(p.resize) {
  6256. if($.fn.jqResize) {
  6257. $(mw).append("<div class='jqResize ui-resizable-handle ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se'></div>");
  6258. $("#"+$.jgrid.jqID(aIDs.themodal)).jqResize(".jqResize",aIDs.scrollelm ? "#"+$.jgrid.jqID(aIDs.scrollelm) : false);
  6259. } else {
  6260. try {
  6261. $(mw).resizable({handles: 'se, sw',alsoResize: aIDs.scrollelm ? "#"+$.jgrid.jqID(aIDs.scrollelm) : false});
  6262. } catch (r) {}
  6263. }
  6264. }
  6265. if(p.closeOnEscape === true){
  6266. $(mw).keydown( function( e ) {
  6267. if( e.which == 27 ) {
  6268. var cone = $("#"+$.jgrid.jqID(aIDs.themodal)).data("onClose") || p.onClose;
  6269. self.hideModal("#"+$.jgrid.jqID(aIDs.themodal),{gb:p.gbox,jqm:p.jqModal,onClose: cone});
  6270. }
  6271. });
  6272. }
  6273. },
  6274. viewModal : function (selector,o){
  6275. o = $.extend({
  6276. toTop: true,
  6277. overlay: 10,
  6278. modal: false,
  6279. overlayClass : 'ui-widget-overlay',
  6280. onShow: $.jgrid.showModal,
  6281. onHide: $.jgrid.closeModal,
  6282. gbox: '',
  6283. jqm : true,
  6284. jqM : true
  6285. }, o || {});
  6286. if ($.fn.jqm && o.jqm === true) {
  6287. if(o.jqM) { $(selector).attr("aria-hidden","false").jqm(o).jqmShow(); }
  6288. else {$(selector).attr("aria-hidden","false").jqmShow();}
  6289. } else {
  6290. if(o.gbox !== '') {
  6291. $(".jqgrid-overlay:first",o.gbox).show();
  6292. $(selector).data("gbox",o.gbox);
  6293. }
  6294. $(selector).show().attr("aria-hidden","false");
  6295. try{$(':input:visible',selector)[0].focus();}catch(_){}
  6296. }
  6297. },
  6298. info_dialog : function(caption, content,c_b, modalopt) {
  6299. var mopt = {
  6300. width:290,
  6301. height:'auto',
  6302. dataheight: 'auto',
  6303. drag: true,
  6304. resize: false,
  6305. left:250,
  6306. top:170,
  6307. zIndex : 1000,
  6308. jqModal : true,
  6309. modal : false,
  6310. closeOnEscape : true,
  6311. align: 'center',
  6312. buttonalign : 'center',
  6313. buttons : []
  6314. // {text:'textbutt', id:"buttid", onClick : function(){...}}
  6315. // 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...
  6316. };
  6317. $.extend(true, mopt, $.jgrid.jqModal || {}, {caption:"<b>"+caption+"</b>"}, modalopt || {});
  6318. var jm = mopt.jqModal, self = this;
  6319. if($.fn.jqm && !jm) { jm = false; }
  6320. // in case there is no jqModal
  6321. var buttstr ="", i;
  6322. if(mopt.buttons.length > 0) {
  6323. for(i=0;i<mopt.buttons.length;i++) {
  6324. if(mopt.buttons[i].id === undefined) { mopt.buttons[i].id = "info_button_"+i; }
  6325. buttstr += "<a id='"+mopt.buttons[i].id+"' class='fm-button ui-state-default ui-corner-all'>"+mopt.buttons[i].text+"</a>";
  6326. }
  6327. }
  6328. var dh = isNaN(mopt.dataheight) ? mopt.dataheight : mopt.dataheight+"px",
  6329. cn = "text-align:"+mopt.align+";";
  6330. var cnt = "<div id='info_id'>";
  6331. cnt += "<div id='infocnt' style='margin:0px;padding-bottom:1em;width:100%;overflow:auto;position:relative;height:"+dh+";"+cn+"'>"+content+"</div>";
  6332. 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>" :
  6333. 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>" : "";
  6334. cnt += "</div>";
  6335. try {
  6336. if($("#info_dialog").attr("aria-hidden") === "false") {
  6337. $.jgrid.hideModal("#info_dialog",{jqm:jm});
  6338. }
  6339. $("#info_dialog").remove();
  6340. } catch (e){}
  6341. $.jgrid.createModal({
  6342. themodal:'info_dialog',
  6343. modalhead:'info_head',
  6344. modalcontent:'info_content',
  6345. scrollelm: 'infocnt'},
  6346. cnt,
  6347. mopt,
  6348. '','',true
  6349. );
  6350. // attach onclick after inserting into the dom
  6351. if(buttstr) {
  6352. $.each(mopt.buttons,function(i){
  6353. $("#"+$.jgrid.jqID(this.id),"#info_id").bind('click',function(){mopt.buttons[i].onClick.call($("#info_dialog")); return false;});
  6354. });
  6355. }
  6356. $("#closedialog", "#info_id").click(function(){
  6357. self.hideModal("#info_dialog",{
  6358. jqm:jm,
  6359. onClose: $("#info_dialog").data("onClose") || mopt.onClose,
  6360. gb: $("#info_dialog").data("gbox") || mopt.gbox
  6361. });
  6362. return false;
  6363. });
  6364. $(".fm-button","#info_dialog").hover(
  6365. function(){$(this).addClass('ui-state-hover');},
  6366. function(){$(this).removeClass('ui-state-hover');}
  6367. );
  6368. if($.isFunction(mopt.beforeOpen) ) { mopt.beforeOpen(); }
  6369. $.jgrid.viewModal("#info_dialog",{
  6370. onHide: function(h) {
  6371. h.w.hide().remove();
  6372. if(h.o) { h.o.remove(); }
  6373. },
  6374. modal :mopt.modal,
  6375. jqm:jm
  6376. });
  6377. if($.isFunction(mopt.afterOpen) ) { mopt.afterOpen(); }
  6378. try{ $("#info_dialog").focus();} catch (m){}
  6379. },
  6380. bindEv: function (el, opt) {
  6381. var $t = this;
  6382. if($.isFunction(opt.dataInit)) {
  6383. opt.dataInit.call($t,el,opt);
  6384. }
  6385. if(opt.dataEvents) {
  6386. $.each(opt.dataEvents, function() {
  6387. if (this.data !== undefined) {
  6388. $(el).bind(this.type, this.data, this.fn);
  6389. } else {
  6390. $(el).bind(this.type, this.fn);
  6391. }
  6392. });
  6393. }
  6394. },
  6395. // Form Functions
  6396. createEl : function(eltype,options,vl,autowidth, ajaxso) {
  6397. var elem = "", $t = this;
  6398. function setAttributes(elm, atr, exl ) {
  6399. var exclude = ['dataInit','dataEvents','dataUrl', 'buildSelect','sopt', 'searchhidden', 'defaultValue', 'attr', 'custom_element', 'custom_value'];
  6400. if(exl !== undefined && $.isArray(exl)) {
  6401. $.merge(exclude, exl);
  6402. }
  6403. $.each(atr, function(key, value){
  6404. if($.inArray(key, exclude) === -1) {
  6405. $(elm).attr(key,value);
  6406. }
  6407. });
  6408. if(!atr.hasOwnProperty('id')) {
  6409. $(elm).attr('id', $.jgrid.randId());
  6410. }
  6411. }
  6412. switch (eltype)
  6413. {
  6414. case "textarea" :
  6415. elem = document.createElement("textarea");
  6416. if(autowidth) {
  6417. if(!options.cols) { $(elem).css({width:"98%"});}
  6418. } else if (!options.cols) { options.cols = 20; }
  6419. if(!options.rows) { options.rows = 2; }
  6420. if(vl==='&nbsp;' || vl==='&#160;' || (vl.length===1 && vl.charCodeAt(0)===160)) {vl="";}
  6421. elem.value = vl;
  6422. setAttributes(elem, options);
  6423. $(elem).attr({"role":"textbox","multiline":"true"});
  6424. break;
  6425. case "checkbox" : //what code for simple checkbox
  6426. elem = document.createElement("input");
  6427. elem.type = "checkbox";
  6428. if( !options.value ) {
  6429. var vl1 = (vl+"").toLowerCase();
  6430. if(vl1.search(/(false|f|0|no|n|off|undefined)/i)<0 && vl1!=="") {
  6431. elem.checked=true;
  6432. elem.defaultChecked=true;
  6433. elem.value = vl;
  6434. } else {
  6435. elem.value = "on";
  6436. }
  6437. $(elem).attr("offval","off");
  6438. } else {
  6439. var cbval = options.value.split(":");
  6440. if(vl === cbval[0]) {
  6441. elem.checked=true;
  6442. elem.defaultChecked=true;
  6443. }
  6444. elem.value = cbval[0];
  6445. $(elem).attr("offval",cbval[1]);
  6446. }
  6447. setAttributes(elem, options, ['value']);
  6448. $(elem).attr("role","checkbox");
  6449. break;
  6450. case "radio" : //what code for simple checkbox
  6451. elem = document.createElement("input");
  6452. elem.type = "radio";
  6453. if( !options.value ) {
  6454. var vl1 = (vl+"").toLowerCase();
  6455. if(vl1.search(/(false|f|0|no|n|off|undefined)/i)<0 && vl1!=="") {
  6456. elem.checked=true;
  6457. elem.defaultChecked=true;
  6458. elem.value = vl;
  6459. } else {
  6460. elem.value = "on";
  6461. }
  6462. $(elem).attr("offval","off");
  6463. } else {
  6464. var cbval = options.value.split(":");
  6465. if(vl === cbval[0]) {
  6466. elem.checked=true;
  6467. elem.defaultChecked=true;
  6468. }
  6469. elem.value = cbval[0];
  6470. $(elem).attr("offval",cbval[1]);
  6471. }
  6472. setAttributes(elem, options, ['value']);
  6473. $(elem).attr("role","radio");
  6474. break;
  6475. //改造字典为可过滤形式
  6476. case "select" :
  6477. elem = document.createElement("INPUT");
  6478. elem.setAttribute("class","textbox");
  6479. elem.setAttribute("type","text");
  6480. elem.setAttribute("width","80");
  6481. //elem.setAttribute("value",v1);
  6482. $(elem).bind('focus',function(){
  6483. //显示字典框DIV
  6484. showComBox($t.p.confid,this,$t.p.confid+"_"+options.name+"_combox");
  6485. });
  6486. setAttributes(elem, options, ['value']);
  6487. $(elem).attr("role","select");
  6488. break;
  6489. case "select2" :
  6490. elem = document.createElement("select");
  6491. elem.setAttribute("role","select");
  6492. var msl, ovm = [];
  6493. if(options.multiple===true) {
  6494. msl = true;
  6495. elem.multiple="multiple";
  6496. $(elem).attr("aria-multiselectable","true");
  6497. } else { msl = false; }
  6498. if(options.dataUrl !== undefined) {
  6499. var rowid = null, postData = options.postData || ajaxso.postData;
  6500. try {
  6501. rowid = options.rowId;
  6502. } catch(e) {}
  6503. if ($t.p && $t.p.idPrefix) {
  6504. rowid = $.jgrid.stripPref($t.p.idPrefix, rowid);
  6505. }
  6506. $.ajax($.extend({
  6507. url: $.isFunction(options.dataUrl) ? options.dataUrl.call($t, rowid, vl, String(options.name)) : options.dataUrl,
  6508. type : "GET",
  6509. dataType: "html",
  6510. data: $.isFunction(postData) ? postData.call($t, rowid, vl, String(options.name)) : postData,
  6511. context: {elem:elem, options:options, vl:vl},
  6512. success: function(data){
  6513. var ovm = [], elem = this.elem, vl = this.vl,
  6514. options = $.extend({},this.options),
  6515. msl = options.multiple===true,
  6516. a = $.isFunction(options.buildSelect) ? options.buildSelect.call($t,data) : data;
  6517. if(typeof a === 'string') {
  6518. a = $( $.trim( a ) ).html();
  6519. }
  6520. if(a) {
  6521. $(elem).append(a);
  6522. setAttributes(elem, options, postData ? ['postData'] : undefined );
  6523. if(options.size === undefined) { options.size = msl ? 3 : 1;}
  6524. if(msl) {
  6525. ovm = vl.split(",");
  6526. ovm = $.map(ovm,function(n){return $.trim(n);});
  6527. } else {
  6528. ovm[0] = $.trim(vl);
  6529. }
  6530. //$(elem).attr(options);
  6531. setTimeout(function(){
  6532. $("option",elem).each(function(i){
  6533. //if(i===0) { this.selected = ""; }
  6534. // fix IE8/IE7 problem with selecting of the first item on multiple=true
  6535. if (i === 0 && elem.multiple) { this.selected = false; }
  6536. $(this).attr("role","option");
  6537. if($.inArray($.trim($(this).text()),ovm) > -1 || $.inArray($.trim($(this).val()),ovm) > -1 ) {
  6538. this.selected= "selected";
  6539. }
  6540. });
  6541. },0);
  6542. }
  6543. }
  6544. },ajaxso || {}));
  6545. } else if(options.value) {
  6546. var i;
  6547. if(options.size === undefined) {
  6548. options.size = msl ? 3 : 1;
  6549. }
  6550. if(msl) {
  6551. ovm = vl.split(",");
  6552. ovm = $.map(ovm,function(n){return $.trim(n);});
  6553. }
  6554. if(typeof options.value === 'function') { options.value = options.value(); }
  6555. var so,sv, ov,
  6556. sep = options.separator === undefined ? ":" : options.separator,
  6557. delim = options.delimiter === undefined ? ";" : options.delimiter;
  6558. if(typeof options.value === 'string') {
  6559. so = options.value.split(delim);
  6560. for(i=0; i<so.length;i++){
  6561. sv = so[i].split(sep);
  6562. if(sv.length > 2 ) {
  6563. sv[1] = $.map(sv,function(n,ii){if(ii>0) { return n;} }).join(sep);
  6564. }
  6565. ov = document.createElement("option");
  6566. ov.setAttribute("role","option");
  6567. ov.value = sv[0]; ov.innerHTML = sv[1];
  6568. elem.appendChild(ov);
  6569. if (!msl && ($.trim(sv[0]) === $.trim(vl) || $.trim(sv[1]) === $.trim(vl))) { ov.selected ="selected"; }
  6570. if (msl && ($.inArray($.trim(sv[1]), ovm)>-1 || $.inArray($.trim(sv[0]), ovm)>-1)) {ov.selected ="selected";}
  6571. }
  6572. } else if (typeof options.value === 'object') {
  6573. var oSv = options.value, key;
  6574. for (key in oSv) {
  6575. if (oSv.hasOwnProperty(key ) ){
  6576. ov = document.createElement("option");
  6577. ov.setAttribute("role","option");
  6578. ov.value = key; ov.innerHTML = oSv[key];
  6579. elem.appendChild(ov);
  6580. if (!msl && ( $.trim(key) === $.trim(vl) || $.trim(oSv[key]) === $.trim(vl)) ) { ov.selected ="selected"; }
  6581. if (msl && ($.inArray($.trim(oSv[key]),ovm)>-1 || $.inArray($.trim(key),ovm)>-1)) { ov.selected ="selected"; }
  6582. }
  6583. }
  6584. }
  6585. setAttributes(elem, options, ['value']);
  6586. }
  6587. break;
  6588. case "text" :
  6589. case "password" :
  6590. case "button" :
  6591. var role;
  6592. var columnArray =$($t).jqGrid('getGridParam','colModel');
  6593. if(eltype==="button") { role = "button"; }
  6594. else { role = "textbox"; }
  6595. elem = document.createElement("input");
  6596. elem.type = eltype;
  6597. elem.value = vl;
  6598. setAttributes(elem, options);
  6599. if(eltype !== "button"){
  6600. if(autowidth) {
  6601. if(!options.size) { $(elem).css({width:"98%"}); }
  6602. } else if (!options.size) { options.size = 20; }
  6603. //if(elem.date !== "true"){
  6604. if(elem.name!=""){
  6605. var columnAttr;
  6606. for ( var i = 0; i <columnArray.length; i++){
  6607. if(elem.name==columnArray[i].name){columnAttr=columnArray[i];break;}
  6608. }
  6609. $(elem).attr("readOnly",false);
  6610. $(elem).attr("vldStr",columnAttr.vld==null?"":columnAttr.vld);
  6611. $(elem).attr("vldType",columnAttr.type);
  6612. $(elem).bind('blur',function(){
  6613. var msg = CFW.oValid._fnFWelementValidate(elem);
  6614. if(msg!=null){
  6615. CFW.oTip.fnValidateTip(this,msg);
  6616. } else {
  6617. $(this).qtip("destroy");
  6618. };
  6619. if(columnAttr.type=='02p'){//邮政编码postcode、6位数字
  6620. CFW.oValid._fnFWidcard(elem);
  6621. }else if(columnAttr.type=='02n'){//能输入数字number
  6622. CFW.oValid._fnFWnumber(elem);
  6623. }else if(columnAttr.type=='02c'){//只能输入汉字中文字符
  6624. CFW.oValid._fnFWchiness(elem);
  6625. }else if(columnAttr.type=='02f'){//浮点类型数据,统一为两位小数,支持负数
  6626. CFW.oValid._fnFWnumber(elem);
  6627. }else if(columnAttr.type=='18'){//身份证号码
  6628. CFW.oValid._fnFWidcard(elem);
  6629. }else if(columnAttr.type=='06'){//date
  6630. CFW.oValid._fnFWdatebox(elem,'yyyy-mm-dd');
  6631. }else{
  6632. }
  6633. });
  6634. }
  6635. //}
  6636. }
  6637. $(elem).attr("role",role);
  6638. break;
  6639. case "image" :
  6640. case "file" :
  6641. elem = document.createElement("input");
  6642. elem.type = eltype;
  6643. setAttributes(elem, options);
  6644. break;
  6645. case "custom" :
  6646. elem = document.createElement("span");
  6647. try {
  6648. if($.isFunction(options.custom_element)) {
  6649. var celm = options.custom_element.call($t,vl,options);
  6650. if(celm) {
  6651. celm = $(celm).addClass("customelement").attr({id:options.id,name:options.name});
  6652. $(elem).empty().append(celm);
  6653. } else {
  6654. throw "e2";
  6655. }
  6656. } else {
  6657. throw "e1";
  6658. }
  6659. } catch (e) {
  6660. if (e==="e1") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_element' "+$.jgrid.edit.msg.nodefined, $.jgrid.edit.bClose);}
  6661. if (e==="e2") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_element' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose);}
  6662. else { $.jgrid.info_dialog($.jgrid.errors.errcap,typeof e==="string"?e:e.message,$.jgrid.edit.bClose); }
  6663. }
  6664. break;
  6665. }
  6666. return elem;
  6667. },
  6668. // Date Validation Javascript
  6669. checkDate : function (format, date) {
  6670. var daysInFebruary = function(year){
  6671. // February has 29 days in any year evenly divisible by four,
  6672. // EXCEPT for centurial years which are not also divisible by 400.
  6673. return (((year % 4 === 0) && ( year % 100 !== 0 || (year % 400 === 0))) ? 29 : 28 );
  6674. },
  6675. tsp = {}, sep;
  6676. format = format.toLowerCase();
  6677. //we search for /,-,. for the date separator
  6678. if(format.indexOf("/") !== -1) {
  6679. sep = "/";
  6680. } else if(format.indexOf("-") !== -1) {
  6681. sep = "-";
  6682. } else if(format.indexOf(".") !== -1) {
  6683. sep = ".";
  6684. } else {
  6685. sep = "/";
  6686. }
  6687. format = format.split(sep);
  6688. date = date.split(sep);
  6689. if (date.length !== 3) { return false; }
  6690. var j=-1,yln, dln=-1, mln=-1, i;
  6691. for(i=0;i<format.length;i++){
  6692. var dv = isNaN(date[i]) ? 0 : parseInt(date[i],10);
  6693. tsp[format[i]] = dv;
  6694. yln = format[i];
  6695. if(yln.indexOf("y") !== -1) { j=i; }
  6696. if(yln.indexOf("m") !== -1) { mln=i; }
  6697. if(yln.indexOf("d") !== -1) { dln=i; }
  6698. }
  6699. if (format[j] === "y" || format[j] === "yyyy") {
  6700. yln=4;
  6701. } else if(format[j] ==="yy"){
  6702. yln = 2;
  6703. } else {
  6704. yln = -1;
  6705. }
  6706. var daysInMonth = [0,31,29,31,30,31,30,31,31,30,31,30,31],
  6707. strDate;
  6708. if (j === -1) {
  6709. return false;
  6710. }
  6711. strDate = tsp[format[j]].toString();
  6712. if(yln === 2 && strDate.length === 1) {yln = 1;}
  6713. if (strDate.length !== yln || (tsp[format[j]]===0 && date[j]!=="00")){
  6714. return false;
  6715. }
  6716. if(mln === -1) {
  6717. return false;
  6718. }
  6719. strDate = tsp[format[mln]].toString();
  6720. if (strDate.length<1 || tsp[format[mln]]<1 || tsp[format[mln]]>12){
  6721. return false;
  6722. }
  6723. if(dln === -1) {
  6724. return false;
  6725. }
  6726. strDate = tsp[format[dln]].toString();
  6727. 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]]]){
  6728. return false;
  6729. }
  6730. return true;
  6731. },
  6732. isEmpty : function(val)
  6733. {
  6734. if(val==null)return true;
  6735. if (val.match(/^\s+$/) || val === "") {
  6736. return true;
  6737. }
  6738. return false;
  6739. },
  6740. checkTime : function(time){
  6741. // checks only hh:ss (and optional am/pm)
  6742. var re = /^(\d{1,2}):(\d{2})([apAP][Mm])?$/,regs;
  6743. if(!$.jgrid.isEmpty(time))
  6744. {
  6745. regs = time.match(re);
  6746. if(regs) {
  6747. if(regs[3]) {
  6748. if(regs[1] < 1 || regs[1] > 12) { return false; }
  6749. } else {
  6750. if(regs[1] > 23) { return false; }
  6751. }
  6752. if(regs[2] > 59) {
  6753. return false;
  6754. }
  6755. } else {
  6756. return false;
  6757. }
  6758. }
  6759. return true;
  6760. },
  6761. checkValues : function(val, valref, customobject, nam) {
  6762. var edtrul,i, nm, dft, len,cmType, g = this, cm = g.p.colModel;
  6763. if(customobject === undefined) {
  6764. if(typeof valref==='string'){
  6765. for( i =0, len=cm.length;i<len; i++){
  6766. if(cm[i].name===valref) {
  6767. edtrul = cm[i].editrules;
  6768. valref = i;
  6769. cmType=cm[i].type;
  6770. if(cm[i].formoptions != null) { nm = cm[i].formoptions.label; }
  6771. break;
  6772. }
  6773. }
  6774. } else if(valref >=0) {
  6775. edtrul = cm[valref].editrules;
  6776. }
  6777. } else {
  6778. edtrul = customobject;
  6779. nm = nam===undefined ? "_" : nam;
  6780. }
  6781. if(edtrul) {
  6782. if(!nm) { nm = g.p.colNames != null ? g.p.colNames[valref] : cm[valref].label;cmType =cm[valref].type;}
  6783. if(edtrul.required === true) {
  6784. if( $.jgrid.isEmpty(val) ) { return [false,nm+": "+$.jgrid.edit.msg.required,""]; }
  6785. }
  6786. // force required
  6787. var rqfield = edtrul.required === false ? false : true;
  6788. if(edtrul.number === true) {
  6789. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  6790. if(isNaN(val)) { return [false,nm+": "+$.jgrid.edit.msg.number,""]; }
  6791. }
  6792. }
  6793. if(edtrul.minValue !== undefined && !isNaN(edtrul.minValue)) {
  6794. if (parseFloat(val) < parseFloat(edtrul.minValue) ) { return [false,nm+": "+$.jgrid.edit.msg.minValue+" "+edtrul.minValue,""];}
  6795. }
  6796. if(edtrul.maxValue !== undefined && !isNaN(edtrul.maxValue)) {
  6797. if (parseFloat(val) > parseFloat(edtrul.maxValue) ) { return [false,nm+": "+$.jgrid.edit.msg.maxValue+" "+edtrul.maxValue,""];}
  6798. }
  6799. var filter;
  6800. if(edtrul.email === true) {
  6801. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  6802. // taken from $ Validate plugin
  6803. 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;
  6804. if(!filter.test(val)) {return [false,nm+": "+$.jgrid.edit.msg.email,""];}
  6805. }
  6806. }
  6807. if(edtrul.integer === true) {
  6808. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  6809. if(isNaN(val)) { return [false,nm+": "+$.jgrid.edit.msg.integer,""]; }
  6810. if ((val % 1 !== 0) || (val.indexOf('.') !== -1)) { return [false,nm+": "+$.jgrid.edit.msg.integer,""];}
  6811. }
  6812. }
  6813. if(edtrul.date === true) {
  6814. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  6815. if(cm[valref].formatoptions && cm[valref].formatoptions.newformat) {
  6816. dft = cm[valref].formatoptions.newformat;
  6817. if( $.jgrid.formatter.date.masks.hasOwnProperty(dft) ) {
  6818. dft = $.jgrid.formatter.date.masks[dft];
  6819. }
  6820. } else {
  6821. dft = cm[valref].datefmt || "Y-m-d";
  6822. }
  6823. if(!$.jgrid.checkDate (dft, val)) { return [false,nm+": "+$.jgrid.edit.msg.date+" - "+dft,""]; }
  6824. }
  6825. }
  6826. if(edtrul.time === true) {
  6827. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  6828. if(!$.jgrid.checkTime (val)) { return [false,nm+": "+$.jgrid.edit.msg.date+" - hh:mm (am/pm)",""]; }
  6829. }
  6830. }
  6831. if(edtrul.url === true) {
  6832. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  6833. filter = /^(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
  6834. if(!filter.test(val)) {return [false,nm+": "+$.jgrid.edit.msg.url,""];}
  6835. }
  6836. }
  6837. var checkresult="";
  6838. if(cmType=="18"){
  6839. var resultstr=CFW.oValid._fnFWidcardCheck(val);
  6840. if(!resultstr){
  6841. checkresult=nm+":公民身份号码输入不合法;";
  6842. }
  6843. }else if(cmType=='02n'){//能输入数字number
  6844. var resultstr=CFW.oValid._fnIsNumber(val);
  6845. if(!resultstr){
  6846. checkresult+=nm+resultstr;
  6847. }
  6848. }else if(cmType=='02c'){//只能输入汉字中文字符
  6849. var resultstr=CFW.oValid._fnIschiness(val);
  6850. if(!resultstr){
  6851. checkresult+=nm+resultstr;
  6852. }
  6853. }
  6854. if(checkresult!=""){
  6855. return [false,checkresult,""];
  6856. }
  6857. if(edtrul.custom === true) {
  6858. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  6859. if($.isFunction(edtrul.custom_func)) {
  6860. var ret = edtrul.custom_func.call(g,val,nm,cmType,valref);
  6861. return $.isArray(ret) ? ret : [false,$.jgrid.edit.msg.customarray,""];
  6862. }
  6863. return [false,$.jgrid.edit.msg.customfcheck,""];
  6864. }
  6865. }
  6866. }
  6867. return [true,"",""];
  6868. }
  6869. });
  6870. })(jQuery);
  6871. /*
  6872. * jqFilter jQuery jqGrid filter addon.
  6873. * Copyright (c) 2011, Tony Tomov, tony@trirand.com
  6874. * Dual licensed under the MIT and GPL licenses
  6875. * http://www.opensource.org/licenses/mit-license.php
  6876. * http://www.gnu.org/licenses/gpl-2.0.html
  6877. *
  6878. * The work is inspired from this Stefan Pirvu
  6879. * http://www.codeproject.com/KB/scripting/json-filtering.aspx
  6880. *
  6881. * The filter uses JSON entities to hold filter rules and groups. Here is an example of a filter:
  6882. { "groupOp": "AND",
  6883. "groups" : [
  6884. { "groupOp": "OR",
  6885. "rules": [
  6886. { "field": "name", "op": "eq", "data": "England" },
  6887. { "field": "id", "op": "le", "data": "5"}
  6888. ]
  6889. }
  6890. ],
  6891. "rules": [
  6892. { "field": "name", "op": "eq", "data": "Romania" },
  6893. { "field": "id", "op": "le", "data": "1"}
  6894. ]
  6895. }
  6896. */
  6897. /*jshint eqeqeq:false, eqnull:true, devel:true */
  6898. /*global jQuery */
  6899. (function ($) {
  6900. "use strict";
  6901. $.fn.jqFilter = function( arg ) {
  6902. if (typeof arg === 'string') {
  6903. var fn = $.fn.jqFilter[arg];
  6904. if (!fn) {
  6905. throw ("jqFilter - No such method: " + arg);
  6906. }
  6907. var args = $.makeArray(arguments).slice(1);
  6908. return fn.apply(this,args);
  6909. }
  6910. var p = $.extend(true,{
  6911. filter: null,
  6912. columns: [],
  6913. onChange : null,
  6914. afterRedraw : null,
  6915. checkValues : null,
  6916. error: false,
  6917. errmsg : "",
  6918. errorcheck : true,
  6919. showQuery : true,
  6920. sopt : null,
  6921. ops : [],
  6922. operands : null,
  6923. numopts : ['eq','ne', 'lt', 'le', 'gt', 'ge', 'nu', 'nn', 'in', 'ni'],
  6924. stropts : ['eq', 'ne', 'bw', 'bn', 'ew', 'en', 'cn', 'nc', 'nu', 'nn', 'in', 'ni'],
  6925. strarr : ['text', 'string', 'blob'],
  6926. groupOps : [{ op: "AND", text: "AND" }, { op: "OR", text: "OR" }],
  6927. groupButton : true,
  6928. ruleButtons : true,
  6929. direction : "ltr"
  6930. }, $.jgrid.filter, arg || {});
  6931. return this.each( function() {
  6932. if (this.filter) {return;}
  6933. this.p = p;
  6934. // setup filter in case if they is not defined
  6935. if (this.p.filter === null || this.p.filter === undefined) {
  6936. this.p.filter = {
  6937. groupOp: this.p.groupOps[0].op,
  6938. rules: [],
  6939. groups: []
  6940. };
  6941. }
  6942. var i, len = this.p.columns.length, cl,
  6943. isIE = /msie/i.test(navigator.userAgent) && !window.opera;
  6944. // translating the options
  6945. this.p.initFilter = $.extend(true,{},this.p.filter);
  6946. // set default values for the columns if they are not set
  6947. if( !len ) {return;}
  6948. for(i=0; i < len; i++) {
  6949. cl = this.p.columns[i];
  6950. if( cl.stype ) {
  6951. // grid compatibility
  6952. cl.inputtype = cl.stype;
  6953. } else if(!cl.inputtype) {
  6954. cl.inputtype = 'text';
  6955. }
  6956. if( cl.sorttype ) {
  6957. // grid compatibility
  6958. cl.searchtype = cl.sorttype;
  6959. } else if (!cl.searchtype) {
  6960. cl.searchtype = 'string';
  6961. }
  6962. if(cl.hidden === undefined) {
  6963. // jqGrid compatibility
  6964. cl.hidden = false;
  6965. }
  6966. if(!cl.label) {
  6967. cl.label = cl.name;
  6968. }
  6969. if(cl.index) {
  6970. cl.name = cl.index;
  6971. }
  6972. if(!cl.hasOwnProperty('searchoptions')) {
  6973. cl.searchoptions = {};
  6974. }
  6975. if(!cl.hasOwnProperty('searchrules')) {
  6976. cl.searchrules = {};
  6977. }
  6978. }
  6979. if(this.p.showQuery) {
  6980. $(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>");
  6981. }
  6982. var getGrid = function () {
  6983. return $("#" + $.jgrid.jqID(p.id))[0] || null;
  6984. };
  6985. /*
  6986. *Perform checking.
  6987. *
  6988. */
  6989. var checkData = function(val, colModelItem) {
  6990. var ret = [true,""], $t = getGrid();
  6991. if($.isFunction(colModelItem.searchrules)) {
  6992. ret = colModelItem.searchrules.call($t, val, colModelItem);
  6993. } else if($.jgrid && $.jgrid.checkValues) {
  6994. try {
  6995. ret = $.jgrid.checkValues.call($t, val, -1, colModelItem.searchrules, colModelItem.label);
  6996. } catch (e) {}
  6997. }
  6998. if(ret && ret.length && ret[0] === false) {
  6999. p.error = !ret[0];
  7000. p.errmsg = ret[1];
  7001. }
  7002. };
  7003. /* moving to common
  7004. randId = function() {
  7005. return Math.floor(Math.random()*10000).toString();
  7006. };
  7007. */
  7008. this.onchange = function ( ){
  7009. // clear any error
  7010. this.p.error = false;
  7011. this.p.errmsg="";
  7012. return $.isFunction(this.p.onChange) ? this.p.onChange.call( this, this.p ) : false;
  7013. };
  7014. /*
  7015. * Redraw the filter every time when new field is added/deleted
  7016. * and field is changed
  7017. */
  7018. this.reDraw = function() {
  7019. $("table.group:first",this).remove();
  7020. var t = this.createTableForGroup(p.filter, null);
  7021. $(this).append(t);
  7022. if($.isFunction(this.p.afterRedraw) ) {
  7023. this.p.afterRedraw.call(this, this.p);
  7024. }
  7025. };
  7026. /*
  7027. * Creates a grouping data for the filter
  7028. * @param group - object
  7029. * @param parentgroup - object
  7030. */
  7031. this.createTableForGroup = function(group, parentgroup) {
  7032. var that = this, i;
  7033. // this table will hold all the group (tables) and rules (rows)
  7034. var table = $("<table class='group ui-widget ui-widget-content' style='border:0px none;'><tbody></tbody></table>"),
  7035. // create error message row
  7036. align = "left";
  7037. if(this.p.direction === "rtl") {
  7038. align = "right";
  7039. table.attr("dir","rtl");
  7040. }
  7041. if(parentgroup === null) {
  7042. table.append("<tr class='error' style='display:none;'><th colspan='5' class='ui-state-error' align='"+align+"'></th></tr>");
  7043. }
  7044. var tr = $("<tr></tr>");
  7045. table.append(tr);
  7046. // this header will hold the group operator type and group action buttons for
  7047. // creating subgroup "+ {}", creating rule "+" or deleting the group "-"
  7048. var th = $("<th colspan='5' align='"+align+"'></th>");
  7049. tr.append(th);
  7050. if(this.p.ruleButtons === true) {
  7051. // dropdown for: choosing group operator type
  7052. var groupOpSelect = $("<select class='opsel'></select>");
  7053. th.append(groupOpSelect);
  7054. // populate dropdown with all posible group operators: or, and
  7055. var str= "", selected;
  7056. for (i = 0; i < p.groupOps.length; i++) {
  7057. selected = group.groupOp === that.p.groupOps[i].op ? " selected='selected'" :"";
  7058. str += "<option value='"+that.p.groupOps[i].op+"'" + selected+">"+that.p.groupOps[i].text+"</option>";
  7059. }
  7060. groupOpSelect
  7061. .append(str)
  7062. .bind('change',function() {
  7063. group.groupOp = $(groupOpSelect).val();
  7064. that.onchange(); // signals that the filter has changed
  7065. });
  7066. }
  7067. // button for adding a new subgroup
  7068. var inputAddSubgroup ="<span></span>";
  7069. if(this.p.groupButton) {
  7070. inputAddSubgroup = $("<input type='button' value='+ {}' title='Add subgroup' class='add-group'/>");
  7071. inputAddSubgroup.bind('click',function() {
  7072. if (group.groups === undefined ) {
  7073. group.groups = [];
  7074. }
  7075. group.groups.push({
  7076. groupOp: p.groupOps[0].op,
  7077. rules: [],
  7078. groups: []
  7079. }); // adding a new group
  7080. that.reDraw(); // the html has changed, force reDraw
  7081. that.onchange(); // signals that the filter has changed
  7082. return false;
  7083. });
  7084. }
  7085. th.append(inputAddSubgroup);
  7086. if(this.p.ruleButtons === true) {
  7087. // button for adding a new rule
  7088. var inputAddRule = $("<input type='button' value='+' title='Add rule' class='add-rule ui-add'/>"), cm;
  7089. inputAddRule.bind('click',function() {
  7090. //if(!group) { group = {};}
  7091. if (group.rules === undefined) {
  7092. group.rules = [];
  7093. }
  7094. for (i = 0; i < that.p.columns.length; i++) {
  7095. // but show only serchable and serchhidden = true fields
  7096. var searchable = (that.p.columns[i].search === undefined) ? true: that.p.columns[i].search,
  7097. hidden = (that.p.columns[i].hidden === true),
  7098. ignoreHiding = (that.p.columns[i].searchoptions.searchhidden === true);
  7099. if ((ignoreHiding && searchable) || (searchable && !hidden)) {
  7100. cm = that.p.columns[i];
  7101. break;
  7102. }
  7103. }
  7104. var opr;
  7105. if( cm.searchoptions.sopt ) {opr = cm.searchoptions.sopt;}
  7106. else if(that.p.sopt) { opr= that.p.sopt; }
  7107. else if ( $.inArray(cm.searchtype, that.p.strarr) !== -1 ) {opr = that.p.stropts;}
  7108. else {opr = that.p.numopts;}
  7109. group.rules.push({
  7110. field: cm.name,
  7111. op: opr[0],
  7112. data: ""
  7113. }); // adding a new rule
  7114. that.reDraw(); // the html has changed, force reDraw
  7115. // for the moment no change have been made to the rule, so
  7116. // this will not trigger onchange event
  7117. return false;
  7118. });
  7119. th.append(inputAddRule);
  7120. }
  7121. // button for delete the group
  7122. if (parentgroup !== null) { // ignore the first group
  7123. var inputDeleteGroup = $("<input type='button' value='-' title='Delete group' class='delete-group'/>");
  7124. th.append(inputDeleteGroup);
  7125. inputDeleteGroup.bind('click',function() {
  7126. // remove group from parent
  7127. for (i = 0; i < parentgroup.groups.length; i++) {
  7128. if (parentgroup.groups[i] === group) {
  7129. parentgroup.groups.splice(i, 1);
  7130. break;
  7131. }
  7132. }
  7133. that.reDraw(); // the html has changed, force reDraw
  7134. that.onchange(); // signals that the filter has changed
  7135. return false;
  7136. });
  7137. }
  7138. // append subgroup rows
  7139. if (group.groups !== undefined) {
  7140. for (i = 0; i < group.groups.length; i++) {
  7141. var trHolderForSubgroup = $("<tr></tr>");
  7142. table.append(trHolderForSubgroup);
  7143. var tdFirstHolderForSubgroup = $("<td class='first'></td>");
  7144. trHolderForSubgroup.append(tdFirstHolderForSubgroup);
  7145. var tdMainHolderForSubgroup = $("<td colspan='4'></td>");
  7146. tdMainHolderForSubgroup.append(this.createTableForGroup(group.groups[i], group));
  7147. trHolderForSubgroup.append(tdMainHolderForSubgroup);
  7148. }
  7149. }
  7150. if(group.groupOp === undefined) {
  7151. group.groupOp = that.p.groupOps[0].op;
  7152. }
  7153. // append rules rows
  7154. if (group.rules !== undefined) {
  7155. for (i = 0; i < group.rules.length; i++) {
  7156. table.append(
  7157. this.createTableRowForRule(group.rules[i], group)
  7158. );
  7159. }
  7160. }
  7161. return table;
  7162. };
  7163. /*
  7164. * Create the rule data for the filter
  7165. */
  7166. this.createTableRowForRule = function(rule, group ) {
  7167. // save current entity in a variable so that it could
  7168. // be referenced in anonimous method calls
  7169. var that=this, $t = getGrid(), tr = $("<tr></tr>"),
  7170. //document.createElement("tr"),
  7171. // first column used for padding
  7172. //tdFirstHolderForRule = document.createElement("td"),
  7173. i, op, trpar, cm, str="", selected;
  7174. //tdFirstHolderForRule.setAttribute("class", "first");
  7175. tr.append("<td class='first'></td>");
  7176. // create field container
  7177. var ruleFieldTd = $("<td class='columns'></td>");
  7178. tr.append(ruleFieldTd);
  7179. // dropdown for: choosing field
  7180. var ruleFieldSelect = $("<select></select>"), ina, aoprs = [];
  7181. ruleFieldTd.append(ruleFieldSelect);
  7182. ruleFieldSelect.bind('change',function() {
  7183. rule.field = $(ruleFieldSelect).val();
  7184. trpar = $(this).parents("tr:first");
  7185. for (i=0;i<that.p.columns.length;i++) {
  7186. if(that.p.columns[i].name === rule.field) {
  7187. cm = that.p.columns[i];
  7188. break;
  7189. }
  7190. }
  7191. if(!cm) {return;}
  7192. cm.searchoptions.id = $.jgrid.randId();
  7193. if(isIE && cm.inputtype === "text") {
  7194. if(!cm.searchoptions.size) {
  7195. cm.searchoptions.size = 10;
  7196. }
  7197. }
  7198. var elm = $.jgrid.createEl.call($t, cm.inputtype,cm.searchoptions, "", true, that.p.ajaxSelectOptions || {}, true);
  7199. $(elm).addClass("input-elm");
  7200. //that.createElement(rule, "");
  7201. if( cm.searchoptions.sopt ) {op = cm.searchoptions.sopt;}
  7202. else if(that.p.sopt) { op= that.p.sopt; }
  7203. else if ($.inArray(cm.searchtype, that.p.strarr) !== -1) {op = that.p.stropts;}
  7204. else {op = that.p.numopts;}
  7205. // operators
  7206. var s ="", so = 0;
  7207. aoprs = [];
  7208. $.each(that.p.ops, function() { aoprs.push(this.oper); });
  7209. for ( i = 0 ; i < op.length; i++) {
  7210. ina = $.inArray(op[i],aoprs);
  7211. if(ina !== -1) {
  7212. if(so===0) {
  7213. rule.op = that.p.ops[ina].oper;
  7214. }
  7215. s += "<option value='"+that.p.ops[ina].oper+"'>"+that.p.ops[ina].text+"</option>";
  7216. so++;
  7217. }
  7218. }
  7219. $(".selectopts",trpar).empty().append( s );
  7220. $(".selectopts",trpar)[0].selectedIndex = 0;
  7221. if( $.jgrid.msie && $.jgrid.msiever() < 9) {
  7222. var sw = parseInt($("select.selectopts",trpar)[0].offsetWidth, 10) + 1;
  7223. $(".selectopts",trpar).width( sw );
  7224. $(".selectopts",trpar).css("width","auto");
  7225. }
  7226. // data
  7227. $(".data",trpar).empty().append( elm );
  7228. $.jgrid.bindEv.call($t, elm, cm.searchoptions);
  7229. $(".input-elm",trpar).bind('change',function( e ) {
  7230. var elem = e.target;
  7231. rule.data = elem.nodeName.toUpperCase() === "SPAN" && cm.searchoptions && $.isFunction(cm.searchoptions.custom_value) ?
  7232. cm.searchoptions.custom_value.call($t, $(elem).children(".customelement:first"), 'get') : elem.value;
  7233. that.onchange(); // signals that the filter has changed
  7234. });
  7235. setTimeout(function(){ //IE, Opera, Chrome
  7236. rule.data = $(elm).val();
  7237. that.onchange(); // signals that the filter has changed
  7238. }, 0);
  7239. });
  7240. // populate drop down with user provided column definitions
  7241. var j=0;
  7242. for (i = 0; i < that.p.columns.length; i++) {
  7243. // but show only serchable and serchhidden = true fields
  7244. var searchable = (that.p.columns[i].search === undefined) ? true: that.p.columns[i].search,
  7245. hidden = (that.p.columns[i].hidden === true),
  7246. ignoreHiding = (that.p.columns[i].searchoptions.searchhidden === true);
  7247. if ((ignoreHiding && searchable) || (searchable && !hidden)) {
  7248. selected = "";
  7249. if(rule.field === that.p.columns[i].name) {
  7250. selected = " selected='selected'";
  7251. j=i;
  7252. }
  7253. str += "<option value='"+that.p.columns[i].name+"'" +selected+">"+that.p.columns[i].label+"</option>";
  7254. }
  7255. }
  7256. ruleFieldSelect.append( str );
  7257. // create operator container
  7258. var ruleOperatorTd = $("<td class='operators'></td>");
  7259. tr.append(ruleOperatorTd);
  7260. cm = p.columns[j];
  7261. // create it here so it can be referentiated in the onchange event
  7262. //var RD = that.createElement(rule, rule.data);
  7263. cm.searchoptions.id = $.jgrid.randId();
  7264. if(isIE && cm.inputtype === "text") {
  7265. if(!cm.searchoptions.size) {
  7266. cm.searchoptions.size = 10;
  7267. }
  7268. }
  7269. var ruleDataInput = $.jgrid.createEl.call($t, cm.inputtype,cm.searchoptions, rule.data, true, that.p.ajaxSelectOptions || {}, true);
  7270. if(rule.op === 'nu' || rule.op === 'nn') {
  7271. $(ruleDataInput).attr('readonly','true');
  7272. $(ruleDataInput).attr('disabled','true');
  7273. } //retain the state of disabled text fields in case of null ops
  7274. // dropdown for: choosing operator
  7275. var ruleOperatorSelect = $("<select class='selectopts'></select>");
  7276. ruleOperatorTd.append(ruleOperatorSelect);
  7277. ruleOperatorSelect.bind('change',function() {
  7278. rule.op = $(ruleOperatorSelect).val();
  7279. trpar = $(this).parents("tr:first");
  7280. var rd = $(".input-elm",trpar)[0];
  7281. if (rule.op === "nu" || rule.op === "nn") { // disable for operator "is null" and "is not null"
  7282. rule.data = "";
  7283. if(rd.tagName.toUpperCase() !== 'SELECT') rd.value = "";
  7284. rd.setAttribute("readonly", "true");
  7285. rd.setAttribute("disabled", "true");
  7286. } else {
  7287. if(rd.tagName.toUpperCase() === 'SELECT') rule.data = rd.value;
  7288. rd.removeAttribute("readonly");
  7289. rd.removeAttribute("disabled");
  7290. }
  7291. that.onchange(); // signals that the filter has changed
  7292. });
  7293. // populate drop down with all available operators
  7294. if( cm.searchoptions.sopt ) {op = cm.searchoptions.sopt;}
  7295. else if(that.p.sopt) { op= that.p.sopt; }
  7296. else if ($.inArray(cm.searchtype, that.p.strarr) !== -1) {op = that.p.stropts;}
  7297. else {op = that.p.numopts;}
  7298. str="";
  7299. $.each(that.p.ops, function() { aoprs.push(this.oper); });
  7300. for ( i = 0; i < op.length; i++) {
  7301. ina = $.inArray(op[i],aoprs);
  7302. if(ina !== -1) {
  7303. selected = rule.op === that.p.ops[ina].oper ? " selected='selected'" : "";
  7304. str += "<option value='"+that.p.ops[ina].oper+"'"+selected+">"+that.p.ops[ina].text+"</option>";
  7305. }
  7306. }
  7307. ruleOperatorSelect.append( str );
  7308. // create data container
  7309. var ruleDataTd = $("<td class='data'></td>");
  7310. tr.append(ruleDataTd);
  7311. // textbox for: data
  7312. // is created previously
  7313. //ruleDataInput.setAttribute("type", "text");
  7314. ruleDataTd.append(ruleDataInput);
  7315. $.jgrid.bindEv.call($t, ruleDataInput, cm.searchoptions);
  7316. $(ruleDataInput)
  7317. .addClass("input-elm")
  7318. .bind('change', function() {
  7319. rule.data = cm.inputtype === 'custom' ? cm.searchoptions.custom_value.call($t, $(this).children(".customelement:first"),'get') : $(this).val();
  7320. that.onchange(); // signals that the filter has changed
  7321. });
  7322. // create action container
  7323. var ruleDeleteTd = $("<td></td>");
  7324. tr.append(ruleDeleteTd);
  7325. // create button for: delete rule
  7326. if(this.p.ruleButtons === true) {
  7327. var ruleDeleteInput = $("<input type='button' value='-' title='Delete rule' class='delete-rule ui-del'/>");
  7328. ruleDeleteTd.append(ruleDeleteInput);
  7329. //$(ruleDeleteInput).html("").height(20).width(30).button({icons: { primary: "ui-icon-minus", text:false}});
  7330. ruleDeleteInput.bind('click',function() {
  7331. // remove rule from group
  7332. for (i = 0; i < group.rules.length; i++) {
  7333. if (group.rules[i] === rule) {
  7334. group.rules.splice(i, 1);
  7335. break;
  7336. }
  7337. }
  7338. that.reDraw(); // the html has changed, force reDraw
  7339. that.onchange(); // signals that the filter has changed
  7340. return false;
  7341. });
  7342. }
  7343. return tr;
  7344. };
  7345. this.getStringForGroup = function(group) {
  7346. var s = "(", index;
  7347. if (group.groups !== undefined) {
  7348. for (index = 0; index < group.groups.length; index++) {
  7349. if (s.length > 1) {
  7350. s += " " + group.groupOp + " ";
  7351. }
  7352. try {
  7353. s += this.getStringForGroup(group.groups[index]);
  7354. } catch (eg) {alert(eg);}
  7355. }
  7356. }
  7357. if (group.rules !== undefined) {
  7358. try{
  7359. for (index = 0; index < group.rules.length; index++) {
  7360. if (s.length > 1) {
  7361. s += " " + group.groupOp + " ";
  7362. }
  7363. s += this.getStringForRule(group.rules[index]);
  7364. }
  7365. } catch (e) {alert(e);}
  7366. }
  7367. s += ")";
  7368. if (s === "()") {
  7369. return ""; // ignore groups that don't have rules
  7370. }
  7371. return s;
  7372. };
  7373. this.getStringForRule = function(rule) {
  7374. var opUF = "",opC="", i, cm, ret, val,
  7375. numtypes = ['int', 'integer', 'float', 'number', 'currency']; // jqGrid
  7376. for (i = 0; i < this.p.ops.length; i++) {
  7377. if (this.p.ops[i].oper === rule.op) {
  7378. opUF = this.p.operands.hasOwnProperty(rule.op) ? this.p.operands[rule.op] : "";
  7379. opC = this.p.ops[i].oper;
  7380. break;
  7381. }
  7382. }
  7383. for (i=0; i<this.p.columns.length; i++) {
  7384. if(this.p.columns[i].name === rule.field) {
  7385. cm = this.p.columns[i];
  7386. break;
  7387. }
  7388. }
  7389. if (cm == undefined) { return ""; }
  7390. val = rule.data;
  7391. if(opC === 'bw' || opC === 'bn') { val = val+"%"; }
  7392. if(opC === 'ew' || opC === 'en') { val = "%"+val; }
  7393. if(opC === 'cn' || opC === 'nc') { val = "%"+val+"%"; }
  7394. if(opC === 'in' || opC === 'ni') { val = " ("+val+")"; }
  7395. if(p.errorcheck) { checkData(rule.data, cm); }
  7396. if($.inArray(cm.searchtype, numtypes) !== -1 || opC === 'nn' || opC === 'nu') { ret = rule.field + " " + opUF + " " + val; }
  7397. else { ret = rule.field + " " + opUF + " \"" + val + "\""; }
  7398. return ret;
  7399. };
  7400. this.resetFilter = function () {
  7401. this.p.filter = $.extend(true,{},this.p.initFilter);
  7402. this.reDraw();
  7403. this.onchange();
  7404. };
  7405. this.hideError = function() {
  7406. $("th.ui-state-error", this).html("");
  7407. $("tr.error", this).hide();
  7408. };
  7409. this.showError = function() {
  7410. $("th.ui-state-error", this).html(this.p.errmsg);
  7411. $("tr.error", this).show();
  7412. };
  7413. this.toUserFriendlyString = function() {
  7414. return this.getStringForGroup(p.filter);
  7415. };
  7416. this.toString = function() {
  7417. // this will obtain a string that can be used to match an item.
  7418. var that = this;
  7419. function getStringRule(rule) {
  7420. if(that.p.errorcheck) {
  7421. var i, cm;
  7422. for (i=0; i<that.p.columns.length; i++) {
  7423. if(that.p.columns[i].name === rule.field) {
  7424. cm = that.p.columns[i];
  7425. break;
  7426. }
  7427. }
  7428. if(cm) {checkData(rule.data, cm);}
  7429. }
  7430. return rule.op + "(item." + rule.field + ",'" + rule.data + "')";
  7431. }
  7432. function getStringForGroup(group) {
  7433. var s = "(", index;
  7434. if (group.groups !== undefined) {
  7435. for (index = 0; index < group.groups.length; index++) {
  7436. if (s.length > 1) {
  7437. if (group.groupOp === "OR") {
  7438. s += " || ";
  7439. }
  7440. else {
  7441. s += " && ";
  7442. }
  7443. }
  7444. s += getStringForGroup(group.groups[index]);
  7445. }
  7446. }
  7447. if (group.rules !== undefined) {
  7448. for (index = 0; index < group.rules.length; index++) {
  7449. if (s.length > 1) {
  7450. if (group.groupOp === "OR") {
  7451. s += " || ";
  7452. }
  7453. else {
  7454. s += " && ";
  7455. }
  7456. }
  7457. s += getStringRule(group.rules[index]);
  7458. }
  7459. }
  7460. s += ")";
  7461. if (s === "()") {
  7462. return ""; // ignore groups that don't have rules
  7463. }
  7464. return s;
  7465. }
  7466. return getStringForGroup(this.p.filter);
  7467. };
  7468. // Here we init the filter
  7469. this.reDraw();
  7470. if(this.p.showQuery) {
  7471. this.onchange();
  7472. }
  7473. // mark is as created so that it will not be created twice on this element
  7474. this.filter = true;
  7475. });
  7476. };
  7477. $.extend($.fn.jqFilter,{
  7478. /*
  7479. * Return SQL like string. Can be used directly
  7480. */
  7481. toSQLString : function()
  7482. {
  7483. var s ="";
  7484. this.each(function(){
  7485. s = this.toUserFriendlyString();
  7486. });
  7487. return s;
  7488. },
  7489. /*
  7490. * Return filter data as object.
  7491. */
  7492. filterData : function()
  7493. {
  7494. var s;
  7495. this.each(function(){
  7496. s = this.p.filter;
  7497. });
  7498. return s;
  7499. },
  7500. getParameter : function (param) {
  7501. if(param !== undefined) {
  7502. if (this.p.hasOwnProperty(param) ) {
  7503. return this.p[param];
  7504. }
  7505. }
  7506. return this.p;
  7507. },
  7508. resetFilter: function() {
  7509. return this.each(function(){
  7510. this.resetFilter();
  7511. });
  7512. },
  7513. addFilter: function (pfilter) {
  7514. if (typeof pfilter === "string") {
  7515. pfilter = $.jgrid.parse( pfilter );
  7516. }
  7517. this.each(function(){
  7518. this.p.filter = pfilter;
  7519. this.reDraw();
  7520. this.onchange();
  7521. });
  7522. }
  7523. });
  7524. })(jQuery);
  7525. /*jshint eqeqeq:false, eqnull:true, devel:true */
  7526. /*global xmlJsonClass, jQuery */
  7527. (function($){
  7528. /**
  7529. * jqGrid extension for form editing Grid Data
  7530. * Tony Tomov tony@trirand.com
  7531. * http://trirand.com/blog/
  7532. * Dual licensed under the MIT and GPL licenses:
  7533. * http://www.opensource.org/licenses/mit-license.php
  7534. * http://www.gnu.org/licenses/gpl-2.0.html
  7535. **/
  7536. "use strict";
  7537. var rp_ge = {};
  7538. $.jgrid.extend({
  7539. searchGrid : function (p) {
  7540. p = $.extend(true, {
  7541. recreateFilter: false,
  7542. drag: true,
  7543. sField:'searchField',
  7544. sValue:'searchString',
  7545. sOper: 'searchOper',
  7546. sFilter: 'filters',
  7547. loadDefaults: true, // this options activates loading of default filters from grid's postData for Multipe Search only.
  7548. beforeShowSearch: null,
  7549. afterShowSearch : null,
  7550. onInitializeSearch: null,
  7551. afterRedraw : null,
  7552. afterChange: null,
  7553. closeAfterSearch : false,
  7554. closeAfterReset: false,
  7555. closeOnEscape : false,
  7556. searchOnEnter : false,
  7557. multipleSearch : false,
  7558. multipleGroup : false,
  7559. //cloneSearchRowOnAdd: true,
  7560. top : 0,
  7561. left: 0,
  7562. jqModal : true,
  7563. modal: false,
  7564. resize : true,
  7565. width: 450,
  7566. height: 'auto',
  7567. dataheight: 'auto',
  7568. showQuery: false,
  7569. errorcheck : true,
  7570. sopt: null,
  7571. stringResult: undefined,
  7572. onClose : null,
  7573. onSearch : null,
  7574. onReset : null,
  7575. toTop : true,
  7576. overlay : 30,
  7577. columns : [],
  7578. tmplNames : null,
  7579. tmplFilters : null,
  7580. tmplLabel : ' Template: ',
  7581. showOnLoad: false,
  7582. layer: null,
  7583. 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"}
  7584. }, $.jgrid.search, p || {});
  7585. return this.each(function() {
  7586. var $t = this;
  7587. if(!$t.grid) {return;}
  7588. var fid = "fbox_"+$t.p.id,
  7589. showFrm = true,
  7590. mustReload = true,
  7591. IDs = {themodal:'searchmod'+fid,modalhead:'searchhd'+fid,modalcontent:'searchcnt'+fid, scrollelm : fid},
  7592. defaultFilters = $t.p.postData[p.sFilter],
  7593. fl;
  7594. if(typeof defaultFilters === "string") {
  7595. defaultFilters = $.jgrid.parse( defaultFilters );
  7596. }
  7597. if(p.recreateFilter === true) {
  7598. $("#"+$.jgrid.jqID(IDs.themodal)).remove();
  7599. }
  7600. function showFilter(_filter) {
  7601. showFrm = $($t).triggerHandler("jqGridFilterBeforeShow", [_filter]);
  7602. if(showFrm === undefined) {
  7603. showFrm = true;
  7604. }
  7605. if(showFrm && $.isFunction(p.beforeShowSearch)) {
  7606. showFrm = p.beforeShowSearch.call($t,_filter);
  7607. }
  7608. if(showFrm) {
  7609. $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{gbox:"#gbox_"+$.jgrid.jqID(fid),jqm:p.jqModal, modal:p.modal, overlay: p.overlay, toTop: p.toTop});
  7610. $($t).triggerHandler("jqGridFilterAfterShow", [_filter]);
  7611. if($.isFunction(p.afterShowSearch)) {
  7612. p.afterShowSearch.call($t, _filter);
  7613. }
  7614. }
  7615. }
  7616. if ( $("#"+$.jgrid.jqID(IDs.themodal))[0] !== undefined ) {
  7617. showFilter($("#fbox_"+$.jgrid.jqID(+$t.p.id)));
  7618. } else {
  7619. var fil = $("<div><div id='"+fid+"' class='searchFilter' style='overflow:auto'></div></div>").insertBefore("#gview_"+$.jgrid.jqID($t.p.id)),
  7620. align = "left", butleft ="";
  7621. if($t.p.direction === "rtl") {
  7622. align = "right";
  7623. butleft = " style='text-align:left'";
  7624. fil.attr("dir","rtl");
  7625. }
  7626. var columns = $.extend([],$t.p.colModel),
  7627. 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>",
  7628. 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>",
  7629. bQ = "", tmpl="", colnm, found = false, bt, cmi=-1;
  7630. if(p.showQuery) {
  7631. 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>";
  7632. }
  7633. if(!p.columns.length) {
  7634. $.each(columns, function(i,n){
  7635. if(!n.label) {
  7636. n.label = $t.p.colNames[i];
  7637. }
  7638. // find first searchable column and set it if no default filter
  7639. if(!found) {
  7640. var searchable = (n.search === undefined) ? true: n.search ,
  7641. hidden = (n.hidden === true),
  7642. ignoreHiding = (n.searchoptions && n.searchoptions.searchhidden === true);
  7643. if ((ignoreHiding && searchable) || (searchable && !hidden)) {
  7644. found = true;
  7645. colnm = n.index || n.name;
  7646. cmi =i;
  7647. }
  7648. }
  7649. });
  7650. } else {
  7651. columns = p.columns;
  7652. cmi = 0;
  7653. colnm = columns[0].index || columns[0].name;
  7654. }
  7655. // old behaviour
  7656. if( (!defaultFilters && colnm) || p.multipleSearch === false ) {
  7657. var cmop = "eq";
  7658. if(cmi >=0 && columns[cmi].searchoptions && columns[cmi].searchoptions.sopt) {
  7659. cmop = columns[cmi].searchoptions.sopt[0];
  7660. } else if(p.sopt && p.sopt.length) {
  7661. cmop = p.sopt[0];
  7662. }
  7663. defaultFilters = {groupOp: "AND", rules: [{field: colnm, op: cmop, data: ""}]};
  7664. }
  7665. found = false;
  7666. if(p.tmplNames && p.tmplNames.length) {
  7667. found = true;
  7668. tmpl = p.tmplLabel;
  7669. tmpl += "<select class='ui-template'>";
  7670. tmpl += "<option value='default'>Default</option>";
  7671. $.each(p.tmplNames, function(i,n){
  7672. tmpl += "<option value='"+i+"'>"+n+"</option>";
  7673. });
  7674. tmpl += "</select>";
  7675. }
  7676. 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>";
  7677. fid = $.jgrid.jqID( fid);
  7678. $("#"+fid).jqFilter({
  7679. columns : columns,
  7680. filter: p.loadDefaults ? defaultFilters : null,
  7681. showQuery: p.showQuery,
  7682. errorcheck : p.errorcheck,
  7683. sopt: p.sopt,
  7684. groupButton : p.multipleGroup,
  7685. ruleButtons : p.multipleSearch,
  7686. afterRedraw : p.afterRedraw,
  7687. ops : p.odata,
  7688. operands : p.operands,
  7689. ajaxSelectOptions: $t.p.ajaxSelectOptions,
  7690. groupOps: p.groupOps,
  7691. onChange : function() {
  7692. if(this.p.showQuery) {
  7693. $('.query',this).html(this.toUserFriendlyString());
  7694. }
  7695. if ($.isFunction(p.afterChange)) {
  7696. p.afterChange.call($t, $("#"+fid), p);
  7697. }
  7698. },
  7699. direction : $t.p.direction,
  7700. id: $t.p.id
  7701. });
  7702. fil.append( bt );
  7703. if(found && p.tmplFilters && p.tmplFilters.length) {
  7704. $(".ui-template", fil).bind('change', function(){
  7705. var curtempl = $(this).val();
  7706. if(curtempl==="default") {
  7707. $("#"+fid).jqFilter('addFilter', defaultFilters);
  7708. } else {
  7709. $("#"+fid).jqFilter('addFilter', p.tmplFilters[parseInt(curtempl,10)]);
  7710. }
  7711. return false;
  7712. });
  7713. }
  7714. if(p.multipleGroup === true) {p.multipleSearch = true;}
  7715. $($t).triggerHandler("jqGridFilterInitialize", [$("#"+fid)]);
  7716. if($.isFunction(p.onInitializeSearch) ) {
  7717. p.onInitializeSearch.call($t, $("#"+fid));
  7718. }
  7719. p.gbox = "#gbox_"+fid;
  7720. if (p.layer) {
  7721. $.jgrid.createModal(IDs ,fil,p,"#gview_"+$.jgrid.jqID($t.p.id),$("#gbox_"+$.jgrid.jqID($t.p.id))[0], "#"+$.jgrid.jqID(p.layer), {position: "relative"});
  7722. } else {
  7723. $.jgrid.createModal(IDs ,fil,p,"#gview_"+$.jgrid.jqID($t.p.id),$("#gbox_"+$.jgrid.jqID($t.p.id))[0]);
  7724. }
  7725. if (p.searchOnEnter || p.closeOnEscape) {
  7726. $("#"+$.jgrid.jqID(IDs.themodal)).keydown(function (e) {
  7727. var $target = $(e.target);
  7728. if (p.searchOnEnter && e.which === 13 && // 13 === $.ui.keyCode.ENTER
  7729. !$target.hasClass('add-group') && !$target.hasClass('add-rule') &&
  7730. !$target.hasClass('delete-group') && !$target.hasClass('delete-rule') &&
  7731. (!$target.hasClass("fm-button") || !$target.is("[id$=_query]"))) {
  7732. $("#"+fid+"_search").click();
  7733. return false;
  7734. }
  7735. if (p.closeOnEscape && e.which === 27) { // 27 === $.ui.keyCode.ESCAPE
  7736. $("#"+$.jgrid.jqID(IDs.modalhead)).find(".ui-jqdialog-titlebar-close").click();
  7737. return false;
  7738. }
  7739. });
  7740. }
  7741. if(bQ) {
  7742. $("#"+fid+"_query").bind('click', function(){
  7743. $(".queryresult", fil).toggle();
  7744. return false;
  7745. });
  7746. }
  7747. if (p.stringResult===undefined) {
  7748. // to provide backward compatibility, inferring stringResult value from multipleSearch
  7749. p.stringResult = p.multipleSearch;
  7750. }
  7751. $("#"+fid+"_search").bind('click', function(){
  7752. var sdata={}, res, filters;
  7753. fl = $("#"+fid);
  7754. fl.find(".input-elm:focus").change();
  7755. filters = fl.jqFilter('filterData');
  7756. if(p.errorcheck) {
  7757. fl[0].hideError();
  7758. if(!p.showQuery) {fl.jqFilter('toSQLString');}
  7759. if(fl[0].p.error) {
  7760. fl[0].showError();
  7761. return false;
  7762. }
  7763. }
  7764. if(p.stringResult) {
  7765. try {
  7766. // xmlJsonClass or JSON.stringify
  7767. res = xmlJsonClass.toJson(filters, '', '', false);
  7768. } catch (e) {
  7769. try {
  7770. res = JSON.stringify(filters);
  7771. } catch (e2) { }
  7772. }
  7773. if(typeof res==="string") {
  7774. sdata[p.sFilter] = res;
  7775. $.each([p.sField,p.sValue, p.sOper], function() {sdata[this] = "";});
  7776. }
  7777. } else {
  7778. if(p.multipleSearch) {
  7779. sdata[p.sFilter] = filters;
  7780. $.each([p.sField,p.sValue, p.sOper], function() {sdata[this] = "";});
  7781. } else {
  7782. sdata[p.sField] = filters.rules[0].field;
  7783. sdata[p.sValue] = filters.rules[0].data;
  7784. sdata[p.sOper] = filters.rules[0].op;
  7785. sdata[p.sFilter] = "";
  7786. }
  7787. }
  7788. $t.p.search = true;
  7789. $.extend($t.p.postData,sdata);
  7790. mustReload = $($t).triggerHandler("jqGridFilterSearch");
  7791. if( mustReload === undefined) {
  7792. mustReload = true;
  7793. }
  7794. if(mustReload && $.isFunction(p.onSearch) ) {
  7795. mustReload = p.onSearch.call($t, $t.p.filters);
  7796. }
  7797. if (mustReload !== false) {
  7798. $($t).trigger("reloadGrid",[{page:1}]);
  7799. }
  7800. if(p.closeAfterSearch) {
  7801. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:p.jqModal,onClose: p.onClose});
  7802. }
  7803. return false;
  7804. });
  7805. $("#"+fid+"_reset").bind('click', function(){
  7806. var sdata={},
  7807. fl = $("#"+fid);
  7808. $t.p.search = false;
  7809. $t.p.resetsearch = true;
  7810. if(p.multipleSearch===false) {
  7811. sdata[p.sField] = sdata[p.sValue] = sdata[p.sOper] = "";
  7812. } else {
  7813. sdata[p.sFilter] = "";
  7814. }
  7815. fl[0].resetFilter();
  7816. if(found) {
  7817. $(".ui-template", fil).val("default");
  7818. }
  7819. $.extend($t.p.postData,sdata);
  7820. mustReload = $($t).triggerHandler("jqGridFilterReset");
  7821. if(mustReload === undefined) {
  7822. mustReload = true;
  7823. }
  7824. if(mustReload && $.isFunction(p.onReset) ) {
  7825. mustReload = p.onReset.call($t);
  7826. }
  7827. if(mustReload !== false) {
  7828. $($t).trigger("reloadGrid",[{page:1}]);
  7829. }
  7830. if (p.closeAfterReset) {
  7831. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:p.jqModal,onClose: p.onClose});
  7832. }
  7833. return false;
  7834. });
  7835. showFilter($("#"+fid));
  7836. $(".fm-button:not(.ui-state-disabled)",fil).hover(
  7837. function(){$(this).addClass('ui-state-hover');},
  7838. function(){$(this).removeClass('ui-state-hover');}
  7839. );
  7840. }
  7841. });
  7842. },
  7843. editGridRow : function(rowid, p){
  7844. var listId=$(this)[0].p.id;
  7845. p = $.extend(true, {
  7846. top : 0,
  7847. left: 0,
  7848. width: 300,
  7849. datawidth: 'auto',
  7850. height: 'auto',
  7851. dataheight: 'auto',
  7852. modal: false,
  7853. overlay : 30,
  7854. drag: true,
  7855. resize: true,
  7856. url: null,
  7857. mtype : "POST",
  7858. clearAfterAdd :true,
  7859. closeAfterEdit : false,
  7860. reloadAfterSubmit : true,
  7861. onInitializeForm: null,
  7862. beforeInitData: null,
  7863. beforeShowForm: null,
  7864. afterShowForm: null,
  7865. beforeSubmit: null,
  7866. afterSubmit: null,
  7867. onclickSubmit: function(params, posdata){
  7868. var sFunName=listId+"_saveSubmit";
  7869. var para = $('#FrmGrid_'+listId).serializeObject() ;
  7870. var callBackFunction = window[sFunName];
  7871. para["pid"]=rowid;
  7872. if(callBackFunction&&typeof(callBackFunction)=="function"){callBackFunction(rowid,para);}
  7873. return;
  7874. },
  7875. afterComplete: null,
  7876. onclickPgButtons : null,
  7877. afterclickPgButtons: null,
  7878. editData : {},
  7879. recreateForm : false,
  7880. jqModal : true,
  7881. closeOnEscape : false,
  7882. addedrow : "first",
  7883. topinfo : '',
  7884. bottominfo: '',
  7885. saveicon : [],
  7886. closeicon : [],
  7887. savekey: [false,13],
  7888. navkeys: [false,38,40],
  7889. checkOnSubmit : false,
  7890. checkOnUpdate : false,
  7891. _savedData : {},
  7892. processing : false,
  7893. onClose : null,
  7894. ajaxEditOptions : {},
  7895. serializeEditData : null,
  7896. viewPagerButtons : true,
  7897. overlayClass : 'ui-widget-overlay'
  7898. }, $.jgrid.edit, p || {});
  7899. rp_ge[$(this)[0].p.id] = p;
  7900. return this.each(function(){
  7901. var $t = this;
  7902. if (!$t.grid || !rowid) {return;}
  7903. var gID = $t.p.id,
  7904. frmgr = "FrmGrid_"+gID, frmtborg = "TblGrid_"+gID, frmtb = "#"+$.jgrid.jqID(frmtborg),
  7905. IDs = {themodal:'editmod'+gID,modalhead:'edithd'+gID,modalcontent:'editcnt'+gID, scrollelm : frmgr},
  7906. onBeforeShow = $.isFunction(rp_ge[$t.p.id].beforeShowForm) ? rp_ge[$t.p.id].beforeShowForm : false,
  7907. onAfterShow = $.isFunction(rp_ge[$t.p.id].afterShowForm) ? rp_ge[$t.p.id].afterShowForm : false,
  7908. onBeforeInit = $.isFunction(rp_ge[$t.p.id].beforeInitData) ? rp_ge[$t.p.id].beforeInitData : false,
  7909. onInitializeForm = $.isFunction(rp_ge[$t.p.id].onInitializeForm) ? rp_ge[$t.p.id].onInitializeForm : false,
  7910. showFrm = true,
  7911. maxCols = 1, maxRows=0, postdata, diff, frmoper;
  7912. frmgr = $.jgrid.jqID(frmgr);
  7913. if (rowid === "new") {
  7914. rowid = "_empty";
  7915. frmoper = "add";
  7916. p.caption=rp_ge[$t.p.id].addCaption;
  7917. } else {
  7918. p.caption=rp_ge[$t.p.id].editCaption;
  7919. frmoper = "edit";
  7920. }
  7921. if(!p.recreateForm) {
  7922. if( $($t).data("formProp") ) {
  7923. $.extend(rp_ge[$(this)[0].p.id], $($t).data("formProp"));
  7924. }
  7925. }
  7926. var closeovrl = true;
  7927. if(p.checkOnUpdate && p.jqModal && !p.modal) {
  7928. closeovrl = false;
  7929. }
  7930. function getFormData(){
  7931. $(frmtb+" > tbody > tr > td > .FormElement").each(function() {
  7932. var celm = $(".customelement", this);
  7933. if (celm.length) {
  7934. var elem = celm[0], nm = $(elem).attr('name');
  7935. $.each($t.p.colModel, function(){
  7936. if(this.name === nm && this.editoptions && $.isFunction(this.editoptions.custom_value)) {
  7937. try {
  7938. postdata[nm] = this.editoptions.custom_value.call($t, $("#"+$.jgrid.jqID(nm),frmtb),'get');
  7939. if (postdata[nm] === undefined) {throw "e1";}
  7940. } catch (e) {
  7941. if (e==="e1") {$.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose);}
  7942. else {$.jgrid.info_dialog($.jgrid.errors.errcap,e.message,$.jgrid.edit.bClose);}
  7943. }
  7944. return true;
  7945. }
  7946. });
  7947. } else {
  7948. switch ($(this).get(0).type){
  7949. case "checkbox":
  7950. if($(this).is(":checked")) {
  7951. postdata[this.name]= $(this).val();
  7952. }else {
  7953. var ofv = $(this).attr("offval");
  7954. postdata[this.name]= ofv;
  7955. }
  7956. break;
  7957. case "select-one":
  7958. postdata[this.name]= $("option:selected",this).val();
  7959. break;
  7960. case "select-multiple":
  7961. postdata[this.name]= $(this).val();
  7962. if(postdata[this.name]) {postdata[this.name] = postdata[this.name].join(",");}
  7963. else {postdata[this.name] ="";}
  7964. var selectedText = [];
  7965. $("option:selected",this).each(
  7966. function(i,selected){
  7967. selectedText[i] = $(selected).text();
  7968. }
  7969. );
  7970. break;
  7971. case "password":
  7972. case "text":
  7973. case "textarea":
  7974. case "button":
  7975. postdata[this.name] = $(this).val();
  7976. break;
  7977. }
  7978. if($t.p.autoencode) {postdata[this.name] = $.jgrid.htmlEncode(postdata[this.name]);}
  7979. }
  7980. });
  7981. return true;
  7982. }
  7983. function createData(rowid,obj,tb,maxcols){
  7984. var nm, hc,trdata, cnt=0,tmp, dc,elc, retpos=[], ind=false,
  7985. tdtmpl = "<td class='CaptionTD'>&#160;</td><td class='DataTD'>&#160;</td>", tmpl="", i; //*2
  7986. for (i =1; i<=maxcols;i++) {
  7987. tmpl += tdtmpl;
  7988. }
  7989. if(rowid !== '_empty') {
  7990. ind = $(obj).jqGrid("getInd",rowid);
  7991. }
  7992. $(obj.p.colModel).each( function(i) {
  7993. nm = this.name;
  7994. // hidden fields are included in the form
  7995. if(this.editrules && this.editrules.edithidden === true) {
  7996. hc = false;
  7997. } else {
  7998. hc = this.hidden === true ? true : false;
  7999. }
  8000. dc = hc ? "style='display:none'" : "";
  8001. if ( nm !== 'cb' && nm !== 'subgrid' && this.editable===true && nm !== 'rn') {
  8002. if(ind === false) {
  8003. tmp = "";
  8004. } else {
  8005. if(nm === obj.p.ExpandColumn && obj.p.treeGrid === true) {
  8006. tmp = $("td[role='gridcell']:eq("+i+")",obj.rows[ind]).text();
  8007. } else {
  8008. try {
  8009. tmp = $.unformat.call(obj, $("td[role='gridcell']:eq("+i+")",obj.rows[ind]),{rowId:rowid, colModel:this},i);
  8010. } catch (_) {
  8011. tmp = (this.edittype && this.edittype === "textarea") ? $("td[role='gridcell']:eq("+i+")",obj.rows[ind]).text() : $("td[role='gridcell']:eq("+i+")",obj.rows[ind]).html();
  8012. }
  8013. if(!tmp || tmp === "&nbsp;" || tmp === "&#160;" || (tmp.length===1 && tmp.charCodeAt(0)===160) ) {tmp='';}
  8014. }
  8015. }
  8016. var opt = $.extend({}, this.editoptions || {} ,{id:nm,name:nm, rowId: rowid}),
  8017. frmopt = $.extend({}, {elmprefix:'',elmsuffix:'',rowabove:false,rowcontent:''}, this.formoptions || {}),
  8018. rp = parseInt(frmopt.rowpos,10) || cnt+1,
  8019. cp = parseInt((parseInt(frmopt.colpos,10) || 1)*2,10);
  8020. if(rowid === "_empty" && opt.defaultValue ) {
  8021. tmp = $.isFunction(opt.defaultValue) ? opt.defaultValue.call($t) : opt.defaultValue;
  8022. }
  8023. if(!this.edittype) {this.edittype = "text";}
  8024. if($t.p.autoencode) {tmp = $.jgrid.htmlDecode(tmp);}
  8025. elc = $.jgrid.createEl.call($t,this.edittype,opt,tmp,false,$.extend({},$.jgrid.ajaxOptions,obj.p.ajaxSelectOptions || {}));
  8026. var elem1;
  8027. if("select"==$(elc).attr("role")){
  8028. var elcId=$t.p.confid+"_NEW_"+opt.name;
  8029. elem1 = document.createElement("INPUT");
  8030. elem1.setAttribute("type","hidden");
  8031. elem1.setAttribute("name",opt.name);
  8032. elem1.setAttribute("id",elcId);
  8033. elem1.setAttribute("value",tmp);
  8034. var text=$("td[role='gridcell']:eq("+i+")",obj.rows[ind]).html();
  8035. if(text=="")text=tmp;
  8036. $(elc).attr("value",text);
  8037. $(elc).attr("name",opt.name+"_filter");
  8038. $(elc).attr("id",elcId+"_filter");
  8039. $(elc).unbind().bind('focus',function(){
  8040. //显示字典框DIV
  8041. showComBox("TblGrid_"+$t.p.confid,this,$t.p.confid+"_"+opt.name+"_combox");
  8042. });
  8043. }
  8044. //if(tmp === "" && this.edittype == "checkbox") {tmp = $(elc).attr("offval");}
  8045. //if(tmp === "" && this.edittype == "select") {tmp = $("option:eq(0)",elc).text();}
  8046. if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {rp_ge[$t.p.id]._savedData[nm] = tmp;}
  8047. $(elc).addClass("FormElement");
  8048. if( $.inArray(this.edittype, ['text','textarea','password','select']) > -1) {
  8049. $(elc).addClass("ui-widget-content ui-corner-all");
  8050. }
  8051. trdata = $(tb).find("tr[rowpos="+rp+"]");
  8052. if(frmopt.rowabove) {
  8053. var newdata = $("<tr><td class='contentinfo' colspan='"+(maxcols*2)+"'>"+frmopt.rowcontent+"</td></tr>");
  8054. $(tb).append(newdata);
  8055. newdata[0].rp = rp;
  8056. }
  8057. if ( trdata.length===0 ) {
  8058. trdata = $("<tr "+dc+" rowpos='"+rp+"'></tr>").addClass("FormData").attr("id","tr_"+nm);
  8059. $(trdata).append(tmpl);
  8060. $(tb).append(trdata);
  8061. trdata[0].rp = rp;
  8062. }
  8063. $("td:eq("+(cp-2)+")",trdata[0]).html(frmopt.label === undefined ? obj.p.colNames[i]: frmopt.label);
  8064. if("select"==$(elc).attr("role")){
  8065. $("td:eq("+(cp-1)+")",trdata[0]).append(frmopt.elmprefix).append(elem1).append(elc).append(frmopt.elmsuffix);
  8066. }else{
  8067. $("td:eq("+(cp-1)+")",trdata[0]).append(frmopt.elmprefix).append(elc).append(frmopt.elmsuffix);
  8068. }
  8069. if(this.edittype==='custom' && $.isFunction(opt.custom_value) ) {
  8070. opt.custom_value.call($t, $("#"+nm,"#"+frmgr),'set',tmp);
  8071. }
  8072. $.jgrid.bindEv.call($t, elc, opt);
  8073. retpos[cnt] = i;
  8074. cnt++;
  8075. }
  8076. });
  8077. if( cnt > 0) {
  8078. 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>");
  8079. idrow[0].rp = cnt+999;
  8080. $(tb).append(idrow);
  8081. if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {rp_ge[$t.p.id]._savedData[obj.p.id+"_id"] = rowid;}
  8082. }
  8083. return retpos;
  8084. }
  8085. function fillData(rowid,obj,fmid){
  8086. var nm,cnt=0,tmp, fld,opt,vl,vlc;
  8087. 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;}
  8088. var cm = obj.p.colModel;
  8089. if(rowid === '_empty') {
  8090. $(cm).each(function(){
  8091. nm = this.name;
  8092. opt = $.extend({}, this.editoptions || {} );
  8093. fld = $("#"+$.jgrid.jqID(nm),"#"+fmid);
  8094. if(fld && fld.length && fld[0] !== null) {
  8095. vl = "";
  8096. if(this.edittype === 'custom' && $.isFunction(opt.custom_value)) {
  8097. opt.custom_value.call($t, $("#"+nm,"#"+fmid),'set',vl);
  8098. } else if(opt.defaultValue ) {
  8099. vl = $.isFunction(opt.defaultValue) ? opt.defaultValue.call($t) : opt.defaultValue;
  8100. if(fld[0].type==='checkbox') {
  8101. vlc = vl.toLowerCase();
  8102. if(vlc.search(/(false|f|0|no|n|off|undefined)/i)<0 && vlc!=="") {
  8103. fld[0].checked = true;
  8104. fld[0].defaultChecked = true;
  8105. fld[0].value = vl;
  8106. } else {
  8107. fld[0].checked = false;
  8108. fld[0].defaultChecked = false;
  8109. }
  8110. } else {fld.val(vl);}
  8111. } else {
  8112. if( fld[0].type==='checkbox' ) {
  8113. fld[0].checked = false;
  8114. fld[0].defaultChecked = false;
  8115. vl = $(fld).attr("offval");
  8116. } else if (fld[0].type && fld[0].type.substr(0,6)==='select') {
  8117. fld[0].selectedIndex = 0;
  8118. } else {
  8119. fld.val(vl);
  8120. }
  8121. }
  8122. if(rp_ge[$t.p.id].checkOnSubmit===true || rp_ge[$t.p.id].checkOnUpdate) {rp_ge[$t.p.id]._savedData[nm] = vl;}
  8123. }
  8124. });
  8125. $("#id_g","#"+fmid).val(rowid);
  8126. return;
  8127. }
  8128. var tre = $(obj).jqGrid("getInd",rowid,true);
  8129. if(!tre) {return;}
  8130. $('td[role="gridcell"]',tre).each( function(i) {
  8131. nm = cm[i].name;
  8132. // hidden fields are included in the form
  8133. if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn' && cm[i].editable===true) {
  8134. if(nm === obj.p.ExpandColumn && obj.p.treeGrid === true) {
  8135. tmp = $(this).text();
  8136. } else {
  8137. try {
  8138. tmp = $.unformat.call(obj, $(this),{rowId:rowid, colModel:cm[i]},i);
  8139. } catch (_) {
  8140. tmp = cm[i].edittype==="textarea" ? $(this).text() : $(this).html();
  8141. }
  8142. }
  8143. if($t.p.autoencode) {tmp = $.jgrid.htmlDecode(tmp);}
  8144. if(rp_ge[$t.p.id].checkOnSubmit===true || rp_ge[$t.p.id].checkOnUpdate) {rp_ge[$t.p.id]._savedData[nm] = tmp;}
  8145. nm = $.jgrid.jqID(nm);
  8146. switch (cm[i].edittype) {
  8147. case "password":
  8148. case "text":
  8149. case "button" :
  8150. case "image":
  8151. case "textarea":
  8152. if(tmp === "&nbsp;" || tmp === "&#160;" || (tmp.length===1 && tmp.charCodeAt(0)===160) ) {tmp='';}
  8153. $("#"+nm,"#"+fmid).val(tmp);
  8154. break;
  8155. case "select":
  8156. var opv = tmp.split(",");
  8157. opv = $.map(opv,function(n){return $.trim(n);});
  8158. $("#"+nm+" option","#"+fmid).each(function(){
  8159. if (!cm[i].editoptions.multiple && ($.trim(tmp) === $.trim($(this).text()) || opv[0] === $.trim($(this).text()) || opv[0] === $.trim($(this).val())) ){
  8160. this.selected= true;
  8161. } else if (cm[i].editoptions.multiple){
  8162. if( $.inArray($.trim($(this).text()), opv ) > -1 || $.inArray($.trim($(this).val()), opv ) > -1 ){
  8163. this.selected = true;
  8164. }else{
  8165. this.selected = false;
  8166. }
  8167. } else {
  8168. this.selected = false;
  8169. }
  8170. });
  8171. break;
  8172. case "checkbox":
  8173. tmp = String(tmp);
  8174. if(cm[i].editoptions && cm[i].editoptions.value) {
  8175. var cb = cm[i].editoptions.value.split(":");
  8176. if(cb[0] === tmp) {
  8177. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']({"checked":true, "defaultChecked" : true});
  8178. } else {
  8179. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']({"checked":false, "defaultChecked" : false});
  8180. }
  8181. } else {
  8182. tmp = tmp.toLowerCase();
  8183. if(tmp.search(/(false|f|0|no|n|off|undefined)/i)<0 && tmp!=="") {
  8184. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("checked",true);
  8185. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("defaultChecked",true); //ie
  8186. } else {
  8187. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("checked", false);
  8188. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("defaultChecked", false); //ie
  8189. }
  8190. }
  8191. break;
  8192. case 'custom' :
  8193. try {
  8194. if(cm[i].editoptions && $.isFunction(cm[i].editoptions.custom_value)) {
  8195. cm[i].editoptions.custom_value.call($t, $("#"+nm,"#"+fmid),'set',tmp);
  8196. } else {throw "e1";}
  8197. } catch (e) {
  8198. if (e==="e1") {$.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.nodefined,$.jgrid.edit.bClose);}
  8199. else {$.jgrid.info_dialog($.jgrid.errors.errcap,e.message,$.jgrid.edit.bClose);}
  8200. }
  8201. break;
  8202. }
  8203. cnt++;
  8204. }
  8205. });
  8206. if(cnt>0) {$("#id_g",frmtb).val(rowid);}
  8207. }
  8208. function setNulls() {
  8209. $.each($t.p.colModel, function(i,n){
  8210. if(n.editoptions && n.editoptions.NullIfEmpty === true) {
  8211. if(postdata.hasOwnProperty(n.name) && postdata[n.name] === "") {
  8212. postdata[n.name] = 'null';
  8213. }
  8214. }
  8215. });
  8216. }
  8217. function postIt() {
  8218. var copydata, ret=[true,"",""], onCS = {}, opers = $t.p.prmNames, idname, oper, key, selr, i;
  8219. var retvals = $($t).triggerHandler("jqGridAddEditBeforeCheckValues", [$("#"+frmgr), frmoper]);
  8220. if(retvals && typeof retvals === 'object') {postdata = retvals;}
  8221. if($.isFunction(rp_ge[$t.p.id].beforeCheckValues)) {
  8222. retvals = rp_ge[$t.p.id].beforeCheckValues.call($t, postdata,$("#"+frmgr),frmoper);
  8223. if(retvals && typeof retvals === 'object') {postdata = retvals;}
  8224. }
  8225. for( key in postdata ){
  8226. if(postdata.hasOwnProperty(key)) {
  8227. ret = $.jgrid.checkValues.call($t,postdata[key],key);
  8228. if(ret[0] === false) {break;}
  8229. }
  8230. }
  8231. setNulls();
  8232. if(ret[0]) {
  8233. onCS = $($t).triggerHandler("jqGridAddEditClickSubmit", [rp_ge[$t.p.id], postdata, frmoper]);
  8234. if( onCS === undefined && $.isFunction( rp_ge[$t.p.id].onclickSubmit)) {
  8235. onCS = rp_ge[$t.p.id].onclickSubmit.call($t, rp_ge[$t.p.id], postdata, frmoper) || {};
  8236. }
  8237. ret = $($t).triggerHandler("jqGridAddEditBeforeSubmit", [postdata, $("#"+frmgr), frmoper]);
  8238. if(ret === undefined) {
  8239. ret = [true,"",""];
  8240. }
  8241. if( ret[0] && $.isFunction(rp_ge[$t.p.id].beforeSubmit)) {
  8242. ret = rp_ge[$t.p.id].beforeSubmit.call($t,postdata,$("#"+frmgr), frmoper);
  8243. }
  8244. }
  8245. if(ret[0] && !rp_ge[$t.p.id].processing) {
  8246. rp_ge[$t.p.id].processing = true;
  8247. $("#sData", frmtb+"_2").addClass('ui-state-active');
  8248. oper = opers.oper;
  8249. idname = opers.id;
  8250. // we add to pos data array the action - the name is oper
  8251. postdata[oper] = ($.trim(postdata[$t.p.id+"_id"]) === "_empty") ? opers.addoper : opers.editoper;
  8252. if(postdata[oper] !== opers.addoper) {
  8253. postdata[idname] = postdata[$t.p.id+"_id"];
  8254. } else {
  8255. // check to see if we have allredy this field in the form and if yes lieve it
  8256. if( postdata[idname] === undefined ) {postdata[idname] = postdata[$t.p.id+"_id"];}
  8257. }
  8258. delete postdata[$t.p.id+"_id"];
  8259. postdata = $.extend(postdata,rp_ge[$t.p.id].editData,onCS);
  8260. if($t.p.treeGrid === true) {
  8261. if(postdata[oper] === opers.addoper) {
  8262. selr = $($t).jqGrid("getGridParam", 'selrow');
  8263. var tr_par_id = $t.p.treeGridModel === 'adjacency' ? $t.p.treeReader.parent_id_field : 'parent_id';
  8264. postdata[tr_par_id] = selr;
  8265. }
  8266. for(i in $t.p.treeReader){
  8267. if($t.p.treeReader.hasOwnProperty(i)) {
  8268. var itm = $t.p.treeReader[i];
  8269. if(postdata.hasOwnProperty(itm)) {
  8270. if(postdata[oper] === opers.addoper && i === 'parent_id_field') {continue;}
  8271. delete postdata[itm];
  8272. }
  8273. }
  8274. }
  8275. }
  8276. postdata[idname] = $.jgrid.stripPref($t.p.idPrefix, postdata[idname]);
  8277. var ajaxOptions = $.extend({
  8278. url: rp_ge[$t.p.id].url || $($t).jqGrid('getGridParam','editurl'),
  8279. type: rp_ge[$t.p.id].mtype,
  8280. data: $.isFunction(rp_ge[$t.p.id].serializeEditData) ? rp_ge[$t.p.id].serializeEditData.call($t,postdata) : postdata,
  8281. complete:function(data,status){
  8282. var key;
  8283. postdata[idname] = $t.p.idPrefix + postdata[idname];
  8284. if(data.status >= 300 && data.status !== 304) {
  8285. ret[0] = false;
  8286. ret[1] = $($t).triggerHandler("jqGridAddEditErrorTextFormat", [data, frmoper]);
  8287. if ($.isFunction(rp_ge[$t.p.id].errorTextFormat)) {
  8288. ret[1] = rp_ge[$t.p.id].errorTextFormat.call($t, data, frmoper);
  8289. } else {
  8290. ret[1] = status + " Status: '" + data.statusText + "'. Error code: " + data.status;
  8291. }
  8292. } else {
  8293. // data is posted successful
  8294. // execute aftersubmit with the returned data from server
  8295. ret = $($t).triggerHandler("jqGridAddEditAfterSubmit", [data, postdata, frmoper]);
  8296. if(ret === undefined) {
  8297. ret = [true,"",""];
  8298. }
  8299. if( ret[0] && $.isFunction(rp_ge[$t.p.id].afterSubmit) ) {
  8300. ret = rp_ge[$t.p.id].afterSubmit.call($t, data,postdata, frmoper);
  8301. }
  8302. }
  8303. if(ret[0] === false) {
  8304. $("#FormError>td",frmtb).html(ret[1]);
  8305. $("#FormError",frmtb).show();
  8306. } else {
  8307. if($t.p.autoencode) {
  8308. $.each(postdata,function(n,v){
  8309. postdata[n] = $.jgrid.htmlDecode(v);
  8310. });
  8311. }
  8312. //rp_ge[$t.p.id].reloadAfterSubmit = rp_ge[$t.p.id].reloadAfterSubmit && $t.p.datatype != "local";
  8313. // the action is add
  8314. if(postdata[oper] === opers.addoper ) {
  8315. //id processing
  8316. // user not set the id ret[2]
  8317. if(!ret[2]) {ret[2] = $.jgrid.randId();}
  8318. postdata[idname] = ret[2];
  8319. if(rp_ge[$t.p.id].reloadAfterSubmit) {
  8320. $($t).trigger("reloadGrid");
  8321. } else {
  8322. if($t.p.treeGrid === true){
  8323. $($t).jqGrid("addChildNode",ret[2],selr,postdata );
  8324. } else {
  8325. $($t).jqGrid("addRowData",ret[2],postdata,p.addedrow);
  8326. }
  8327. }
  8328. if(rp_ge[$t.p.id].closeAfterAdd) {
  8329. if($t.p.treeGrid !== true){
  8330. $($t).jqGrid("setSelection",ret[2]);
  8331. }
  8332. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose});
  8333. } else if (rp_ge[$t.p.id].clearAfterAdd) {
  8334. fillData("_empty",$t,frmgr);
  8335. }
  8336. } else {
  8337. // the action is update
  8338. if(rp_ge[$t.p.id].reloadAfterSubmit) {
  8339. $($t).trigger("reloadGrid");
  8340. if( !rp_ge[$t.p.id].closeAfterEdit ) {setTimeout(function(){$($t).jqGrid("setSelection",postdata[idname]);},1000);}
  8341. } else {
  8342. if($t.p.treeGrid === true) {
  8343. $($t).jqGrid("setTreeRow", postdata[idname],postdata);
  8344. } else {
  8345. $($t).jqGrid("setRowData", postdata[idname],postdata);
  8346. }
  8347. }
  8348. 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});}
  8349. }
  8350. if($.isFunction(rp_ge[$t.p.id].afterComplete)) {
  8351. copydata = data;
  8352. setTimeout(function(){
  8353. $($t).triggerHandler("jqGridAddEditAfterComplete", [copydata, postdata, $("#"+frmgr), frmoper]);
  8354. rp_ge[$t.p.id].afterComplete.call($t, copydata, postdata, $("#"+frmgr), frmoper);
  8355. copydata=null;
  8356. },500);
  8357. }
  8358. if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {
  8359. $("#"+frmgr).data("disabled",false);
  8360. if(rp_ge[$t.p.id]._savedData[$t.p.id+"_id"] !== "_empty"){
  8361. for(key in rp_ge[$t.p.id]._savedData) {
  8362. if(rp_ge[$t.p.id]._savedData.hasOwnProperty(key) && postdata[key]) {
  8363. rp_ge[$t.p.id]._savedData[key] = postdata[key];
  8364. }
  8365. }
  8366. }
  8367. }
  8368. }
  8369. rp_ge[$t.p.id].processing=false;
  8370. $("#sData", frmtb+"_2").removeClass('ui-state-active');
  8371. try{$(':input:visible',"#"+frmgr)[0].focus();} catch (e){}
  8372. }
  8373. }, $.jgrid.ajaxOptions, rp_ge[$t.p.id].ajaxEditOptions );
  8374. if (!ajaxOptions.url && !rp_ge[$t.p.id].useDataProxy) {
  8375. if ($.isFunction($t.p.dataProxy)) {
  8376. rp_ge[$t.p.id].useDataProxy = true;
  8377. } else {
  8378. ret[0]=false;ret[1] += " "+$.jgrid.errors.nourl;
  8379. }
  8380. }
  8381. if (ret[0]) {
  8382. if (rp_ge[$t.p.id].useDataProxy) {
  8383. var dpret = $t.p.dataProxy.call($t, ajaxOptions, "set_"+$t.p.id);
  8384. if(dpret === undefined) {
  8385. dpret = [true, ""];
  8386. }
  8387. if(dpret[0] === false ) {
  8388. ret[0] = false;
  8389. ret[1] = dpret[1] || "Error deleting the selected row!" ;
  8390. } else {
  8391. if(ajaxOptions.data.oper === opers.addoper && rp_ge[$t.p.id].closeAfterAdd ) {
  8392. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});
  8393. }
  8394. if(ajaxOptions.data.oper === opers.editoper && rp_ge[$t.p.id].closeAfterEdit ) {
  8395. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});
  8396. }
  8397. }
  8398. } else {
  8399. if(ajaxOptions.url === "clientArray") {
  8400. postdata = ajaxOptions.data;
  8401. ajaxOptions.complete({status:200, statusText:''},'');
  8402. } else {
  8403. //alert("03");
  8404. $.ajax(ajaxOptions);
  8405. }
  8406. }
  8407. }
  8408. }
  8409. if(ret[0] === false) {
  8410. $("#FormError>td",frmtb).html(ret[1]);
  8411. $("#FormError",frmtb).show();
  8412. // return;
  8413. }
  8414. }
  8415. function compareData(nObj, oObj ) {
  8416. var ret = false,key;
  8417. for (key in nObj) {
  8418. if(nObj.hasOwnProperty(key) && nObj[key] != oObj[key]) {
  8419. ret = true;
  8420. break;
  8421. }
  8422. }
  8423. return ret;
  8424. }
  8425. function checkUpdates () {
  8426. var stat = true;
  8427. $("#FormError",frmtb).hide();
  8428. if(rp_ge[$t.p.id].checkOnUpdate) {
  8429. postdata = {};
  8430. getFormData();
  8431. diff = compareData(postdata,rp_ge[$t.p.id]._savedData);
  8432. if(diff) {
  8433. $("#"+frmgr).data("disabled",true);
  8434. $(".confirm","#"+IDs.themodal).show();
  8435. stat = false;
  8436. }
  8437. }
  8438. return stat;
  8439. }
  8440. function restoreInline()
  8441. {
  8442. var i;
  8443. if (rowid !== "_empty" && $t.p.savedRow !== undefined && $t.p.savedRow.length > 0 && $.isFunction($.fn.jqGrid.restoreRow)) {
  8444. for (i=0;i<$t.p.savedRow.length;i++) {
  8445. if ($t.p.savedRow[i].id == rowid) {
  8446. $($t).jqGrid('restoreRow',rowid);
  8447. break;
  8448. }
  8449. }
  8450. }
  8451. }
  8452. function updateNav(cr, posarr){
  8453. var totr = posarr[1].length-1;
  8454. if (cr===0) {
  8455. $("#pData",frmtb+"_2").addClass('ui-state-disabled');
  8456. } else if( posarr[1][cr-1] !== undefined && $("#"+$.jgrid.jqID(posarr[1][cr-1])).hasClass('ui-state-disabled')) {
  8457. $("#pData",frmtb+"_2").addClass('ui-state-disabled');
  8458. } else {
  8459. $("#pData",frmtb+"_2").removeClass('ui-state-disabled');
  8460. }
  8461. if (cr===totr) {
  8462. $("#nData",frmtb+"_2").addClass('ui-state-disabled');
  8463. } else if( posarr[1][cr+1] !== undefined && $("#"+$.jgrid.jqID(posarr[1][cr+1])).hasClass('ui-state-disabled')) {
  8464. $("#nData",frmtb+"_2").addClass('ui-state-disabled');
  8465. } else {
  8466. $("#nData",frmtb+"_2").removeClass('ui-state-disabled');
  8467. }
  8468. }
  8469. function getCurrPos() {
  8470. var rowsInGrid = $($t).jqGrid("getDataIDs"),
  8471. selrow = $("#id_g",frmtb).val(),
  8472. pos = $.inArray(selrow,rowsInGrid);
  8473. return [pos,rowsInGrid];
  8474. }
  8475. 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",
  8476. dw = isNaN(rp_ge[$(this)[0].p.id].datawidth) ? rp_ge[$(this)[0].p.id].datawidth : rp_ge[$(this)[0].p.id].datawidth+"px",
  8477. frm = $("<form name='FormPost' id='"+frmgr+"' class='FormGrid' onSubmit='return false;' style='width:"+dw+";overflow:auto;position:relative;height:"+dh+";'></form>").data("disabled",false),
  8478. tbl = $("<table id='"+frmtborg+"' class='EditTable' cellspacing='0' cellpadding='0' border='0'><tbody></tbody></table>");
  8479. $($t.p.colModel).each( function() {
  8480. var fmto = this.formoptions;
  8481. maxCols = Math.max(maxCols, fmto ? fmto.colpos || 0 : 0 );
  8482. maxRows = Math.max(maxRows, fmto ? fmto.rowpos || 0 : 0 );
  8483. });
  8484. $(frm).append(tbl);
  8485. var flr = $("<tr id='FormError' style='display:none'><td class='ui-state-error' colspan='"+(maxCols*2)+"'></td></tr>");
  8486. flr[0].rp = 0;
  8487. $(tbl).append(flr);
  8488. //topinfo
  8489. flr = $("<tr style='display:none' class='tinfo'><td class='topinfo' colspan='"+(maxCols*2)+"'>"+rp_ge[$t.p.id].topinfo+"</td></tr>");
  8490. flr[0].rp = 0;
  8491. $(tbl).append(flr);
  8492. showFrm = $($t).triggerHandler("jqGridAddEditBeforeInitData", [frm, frmoper]);
  8493. if(showFrm === undefined) {
  8494. showFrm = true;
  8495. }
  8496. if(showFrm && onBeforeInit) {
  8497. showFrm = onBeforeInit.call($t,frm, frmoper);
  8498. }
  8499. if(showFrm === false) {return;}
  8500. restoreInline();
  8501. // set the id.
  8502. // use carefull only to change here colproperties.
  8503. // create data
  8504. var rtlb = $t.p.direction === "rtl" ? true :false,
  8505. bp = rtlb ? "nData" : "pData",
  8506. bn = rtlb ? "pData" : "nData";
  8507. createData(rowid,$t,tbl,maxCols);
  8508. // buttons at footer
  8509. 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>",
  8510. bN = "<a id='"+bn+"' class='fm-button ui-state-default ui-corner-right'><span class='ui-icon ui-icon-triangle-1-e'></span></a>",
  8511. bS ="<a id='sData' class='fm-button ui-state-default ui-corner-all'>"+p.bSubmit+"</a>",
  8512. bC ="<a id='cData' class='fm-button ui-state-default ui-corner-all'>"+p.bCancel+"</a>";
  8513. 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>";
  8514. bt += "<tr style='display:none' class='binfo'><td class='bottominfo' colspan='2'>"+rp_ge[$t.p.id].bottominfo+"</td></tr>";
  8515. bt += "</tbody></table>";
  8516. if(maxRows > 0) {
  8517. var sd=[];
  8518. $.each($(tbl)[0].rows,function(i,r){
  8519. sd[i] = r;
  8520. });
  8521. sd.sort(function(a,b){
  8522. if(a.rp > b.rp) {return 1;}
  8523. if(a.rp < b.rp) {return -1;}
  8524. return 0;
  8525. });
  8526. $.each(sd, function(index, row) {
  8527. $('tbody',tbl).append(row);
  8528. });
  8529. }
  8530. p.gbox = "#gbox_"+$.jgrid.jqID(gID);
  8531. var cle = false;
  8532. if(p.closeOnEscape===true){
  8533. p.closeOnEscape = false;
  8534. cle = true;
  8535. }
  8536. var tms = $("<div></div>").append(frm).append(bt);
  8537. $.jgrid.createModal(IDs,tms, rp_ge[$(this)[0].p.id] ,"#gview_"+$.jgrid.jqID($t.p.id),$("#gbox_"+$.jgrid.jqID($t.p.id))[0]);
  8538. if(rtlb) {
  8539. $("#pData, #nData",frmtb+"_2").css("float","right");
  8540. $(".EditButton",frmtb+"_2").css("text-align","left");
  8541. }
  8542. if(rp_ge[$t.p.id].topinfo) {$(".tinfo",frmtb).show();}
  8543. if(rp_ge[$t.p.id].bottominfo) {$(".binfo",frmtb+"_2").show();}
  8544. tms = null;bt=null;
  8545. $("#"+$.jgrid.jqID(IDs.themodal)).keydown( function( e ) {
  8546. var wkey = e.target;
  8547. if ($("#"+frmgr).data("disabled")===true ) {return false;}//??
  8548. if(rp_ge[$t.p.id].savekey[0] === true && e.which === rp_ge[$t.p.id].savekey[1]) { // save
  8549. if(wkey.tagName !== "TEXTAREA") {
  8550. $("#sData", frmtb+"_2").trigger("click");
  8551. return false;
  8552. }
  8553. }
  8554. if(e.which === 27) {
  8555. if(!checkUpdates()) {return false;}
  8556. if(cle) {$.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:p.gbox,jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});}
  8557. return false;
  8558. }
  8559. if(rp_ge[$t.p.id].navkeys[0]===true) {
  8560. if($("#id_g",frmtb).val() === "_empty") {return true;}
  8561. if(e.which === rp_ge[$t.p.id].navkeys[1]){ //up
  8562. $("#pData", frmtb+"_2").trigger("click");
  8563. return false;
  8564. }
  8565. if(e.which === rp_ge[$t.p.id].navkeys[2]){ //down
  8566. $("#nData", frmtb+"_2").trigger("click");
  8567. return false;
  8568. }
  8569. }
  8570. });
  8571. if(p.checkOnUpdate) {
  8572. $("a.ui-jqdialog-titlebar-close span","#"+$.jgrid.jqID(IDs.themodal)).removeClass("jqmClose");
  8573. $("a.ui-jqdialog-titlebar-close","#"+$.jgrid.jqID(IDs.themodal)).unbind("click")
  8574. .click(function(){
  8575. if(!checkUpdates()) {return false;}
  8576. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose});
  8577. return false;
  8578. });
  8579. }
  8580. p.saveicon = $.extend([true,"left","ui-icon-disk"],p.saveicon);
  8581. p.closeicon = $.extend([true,"left","ui-icon-close"],p.closeicon);
  8582. // beforeinitdata after creation of the form
  8583. if(p.saveicon[0]===true) {
  8584. $("#sData",frmtb+"_2").addClass(p.saveicon[1] === "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  8585. .append("<span class='ui-icon "+p.saveicon[2]+"'></span>");
  8586. }
  8587. if(p.closeicon[0]===true) {
  8588. $("#cData",frmtb+"_2").addClass(p.closeicon[1] === "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  8589. .append("<span class='ui-icon "+p.closeicon[2]+"'></span>");
  8590. }
  8591. if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {
  8592. bS ="<a id='sNew' class='fm-button ui-state-default ui-corner-all' style='z-index:1002'>"+p.bYes+"</a>";
  8593. bN ="<a id='nNew' class='fm-button ui-state-default ui-corner-all' style='z-index:1002'>"+p.bNo+"</a>";
  8594. bC ="<a id='cNew' class='fm-button ui-state-default ui-corner-all' style='z-index:1002'>"+p.bExit+"</a>";
  8595. var zI = p.zIndex || 999;zI ++;
  8596. $("<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);
  8597. $("#sNew","#"+$.jgrid.jqID(IDs.themodal)).click(function(){
  8598. postIt();
  8599. $("#"+frmgr).data("disabled",false);
  8600. $(".confirm","#"+$.jgrid.jqID(IDs.themodal)).hide();
  8601. return false;
  8602. });
  8603. $("#nNew","#"+$.jgrid.jqID(IDs.themodal)).click(function(){
  8604. $(".confirm","#"+$.jgrid.jqID(IDs.themodal)).hide();
  8605. $("#"+frmgr).data("disabled",false);
  8606. setTimeout(function(){$(":input:visible","#"+frmgr)[0].focus();},0);
  8607. return false;
  8608. });
  8609. $("#cNew","#"+$.jgrid.jqID(IDs.themodal)).click(function(){
  8610. $(".confirm","#"+$.jgrid.jqID(IDs.themodal)).hide();
  8611. $("#"+frmgr).data("disabled",false);
  8612. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose});
  8613. return false;
  8614. });
  8615. }
  8616. // here initform - only once
  8617. $($t).triggerHandler("jqGridAddEditInitializeForm", [$("#"+frmgr), frmoper]);
  8618. if(onInitializeForm) {onInitializeForm.call($t,$("#"+frmgr), frmoper);}
  8619. if(rowid==="_empty" || !rp_ge[$t.p.id].viewPagerButtons) {$("#pData,#nData",frmtb+"_2").hide();} else {$("#pData,#nData",frmtb+"_2").show();}
  8620. $($t).triggerHandler("jqGridAddEditBeforeShowForm", [$("#"+frmgr), frmoper]);
  8621. if(onBeforeShow) { onBeforeShow.call($t, $("#"+frmgr), frmoper);}
  8622. $("#"+$.jgrid.jqID(IDs.themodal)).data("onClose",rp_ge[$t.p.id].onClose);
  8623. $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{
  8624. gbox:"#gbox_"+$.jgrid.jqID(gID),
  8625. jqm:p.jqModal,
  8626. overlay: p.overlay,
  8627. modal:p.modal,
  8628. overlayClass: p.overlayClass,
  8629. onHide : function(h) {
  8630. var fh = $('#editmod'+gID)[0].style.height;
  8631. if(fh.indexOf("px") > -1 ) {
  8632. fh = parseFloat(fh);
  8633. }
  8634. $($t).data("formProp", {
  8635. top:parseFloat($(h.w).css("top")),
  8636. left : parseFloat($(h.w).css("left")),
  8637. width : $(h.w).width(),
  8638. height : fh,
  8639. dataheight : $("#"+frmgr).height(),
  8640. datawidth: $("#"+frmgr).width()
  8641. });
  8642. h.w.remove();
  8643. if(h.o) {h.o.remove();}
  8644. }
  8645. });
  8646. if(!closeovrl) {
  8647. $("." + $.jgrid.jqID(p.overlayClass)).click(function(){
  8648. if(!checkUpdates()) {return false;}
  8649. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});
  8650. return false;
  8651. });
  8652. }
  8653. $(".fm-button","#"+$.jgrid.jqID(IDs.themodal)).hover(
  8654. function(){$(this).addClass('ui-state-hover');},
  8655. function(){$(this).removeClass('ui-state-hover');}
  8656. );
  8657. $("#sData", frmtb+"_2").click(function(){
  8658. postdata = {};
  8659. $("#FormError",frmtb).hide();
  8660. // all depend on ret array
  8661. //ret[0] - succes
  8662. //ret[1] - msg if not succes
  8663. //ret[2] - the id that will be set if reload after submit false
  8664. getFormData();
  8665. if(postdata[$t.p.id+"_id"] === "_empty") {postIt();}
  8666. else if(p.checkOnSubmit===true ) {
  8667. diff = compareData(postdata,rp_ge[$t.p.id]._savedData);
  8668. if(diff) {
  8669. $("#"+frmgr).data("disabled",true);
  8670. $(".confirm","#"+$.jgrid.jqID(IDs.themodal)).show();
  8671. } else {
  8672. postIt();
  8673. }
  8674. } else {
  8675. postIt();
  8676. }
  8677. return false;
  8678. });
  8679. $("#cData", frmtb+"_2").click(function(){
  8680. if(!checkUpdates()) {return false;}
  8681. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose});
  8682. return false;
  8683. });
  8684. $("#nData", frmtb+"_2").click(function(){
  8685. if(!checkUpdates()) {return false;}
  8686. $("#FormError",frmtb).hide();
  8687. var npos = getCurrPos();
  8688. npos[0] = parseInt(npos[0],10);
  8689. if(npos[0] !== -1 && npos[1][npos[0]+1]) {
  8690. $($t).triggerHandler("jqGridAddEditClickPgButtons", ['next',$("#"+frmgr),npos[1][npos[0]]]);
  8691. var nposret;
  8692. if($.isFunction(p.onclickPgButtons)) {
  8693. nposret = p.onclickPgButtons.call($t, 'next',$("#"+frmgr),npos[1][npos[0]]);
  8694. if( nposret !== undefined && nposret === false ) {return false;}
  8695. }
  8696. if( $("#"+$.jgrid.jqID(npos[1][npos[0]+1])).hasClass('ui-state-disabled')) {return false;}
  8697. fillData(npos[1][npos[0]+1],$t,frmgr);
  8698. $($t).jqGrid("setSelection",npos[1][npos[0]+1]);
  8699. $($t).triggerHandler("jqGridAddEditAfterClickPgButtons", ['next',$("#"+frmgr),npos[1][npos[0]]]);
  8700. if($.isFunction(p.afterclickPgButtons)) {
  8701. p.afterclickPgButtons.call($t, 'next',$("#"+frmgr),npos[1][npos[0]+1]);
  8702. }
  8703. updateNav(npos[0]+1,npos);
  8704. }
  8705. return false;
  8706. });
  8707. $("#pData", frmtb+"_2").click(function(){
  8708. if(!checkUpdates()) {return false;}
  8709. $("#FormError",frmtb).hide();
  8710. var ppos = getCurrPos();
  8711. if(ppos[0] !== -1 && ppos[1][ppos[0]-1]) {
  8712. $($t).triggerHandler("jqGridAddEditClickPgButtons", ['prev',$("#"+frmgr),ppos[1][ppos[0]]]);
  8713. var pposret;
  8714. if($.isFunction(p.onclickPgButtons)) {
  8715. pposret = p.onclickPgButtons.call($t, 'prev',$("#"+frmgr),ppos[1][ppos[0]]);
  8716. if( pposret !== undefined && pposret === false ) {return false;}
  8717. }
  8718. if( $("#"+$.jgrid.jqID(ppos[1][ppos[0]-1])).hasClass('ui-state-disabled')) {return false;}
  8719. fillData(ppos[1][ppos[0]-1],$t,frmgr);
  8720. $($t).jqGrid("setSelection",ppos[1][ppos[0]-1]);
  8721. $($t).triggerHandler("jqGridAddEditAfterClickPgButtons", ['prev',$("#"+frmgr),ppos[1][ppos[0]]]);
  8722. if($.isFunction(p.afterclickPgButtons)) {
  8723. p.afterclickPgButtons.call($t, 'prev',$("#"+frmgr),ppos[1][ppos[0]-1]);
  8724. }
  8725. updateNav(ppos[0]-1,ppos);
  8726. }
  8727. return false;
  8728. });
  8729. $($t).triggerHandler("jqGridAddEditAfterShowForm", [$("#"+frmgr), frmoper]);
  8730. if(onAfterShow) { onAfterShow.call($t, $("#"+frmgr), frmoper); }
  8731. var posInit =getCurrPos();
  8732. updateNav(posInit[0],posInit);
  8733. });
  8734. },
  8735. viewGridRow : function(rowid, p){
  8736. p = $.extend(true, {
  8737. top : 0,
  8738. left: 0,
  8739. width: 0,
  8740. datawidth: 'auto',
  8741. height: 'auto',
  8742. dataheight: 'auto',
  8743. modal: false,
  8744. overlay: 30,
  8745. drag: true,
  8746. resize: true,
  8747. jqModal: true,
  8748. closeOnEscape : false,
  8749. labelswidth: '30%',
  8750. closeicon: [],
  8751. navkeys: [false,38,40],
  8752. onClose: null,
  8753. beforeShowForm : null,
  8754. beforeInitData : null,
  8755. viewPagerButtons : true,
  8756. recreateForm : false
  8757. }, $.jgrid.view, p || {});
  8758. rp_ge[$(this)[0].p.id] = p;
  8759. return this.each(function(){
  8760. var $t = this;
  8761. if (!$t.grid || !rowid) {return;}
  8762. var gID = $t.p.id,
  8763. frmgr = "ViewGrid_"+$.jgrid.jqID( gID ), frmtb = "ViewTbl_" + $.jgrid.jqID( gID ),
  8764. frmgr_id = "ViewGrid_"+gID, frmtb_id = "ViewTbl_"+gID,
  8765. IDs = {themodal:'viewmod'+gID,modalhead:'viewhd'+gID,modalcontent:'viewcnt'+gID, scrollelm : frmgr},
  8766. onBeforeInit = $.isFunction(rp_ge[$t.p.id].beforeInitData) ? rp_ge[$t.p.id].beforeInitData : false,
  8767. showFrm = true,
  8768. maxCols = 1, maxRows=0;
  8769. if(!p.recreateForm) {
  8770. if( $($t).data("viewProp") ) {
  8771. $.extend(rp_ge[$(this)[0].p.id], $($t).data("viewProp"));
  8772. }
  8773. }
  8774. function focusaref(){ //Sfari 3 issues
  8775. if(rp_ge[$t.p.id].closeOnEscape===true || rp_ge[$t.p.id].navkeys[0]===true) {
  8776. setTimeout(function(){$(".ui-jqdialog-titlebar-close","#"+$.jgrid.jqID(IDs.modalhead)).attr("tabindex", "-1").focus();},0);
  8777. }
  8778. }
  8779. function createData(rowid,obj,tb,maxcols){
  8780. var nm, hc,trdata, cnt=0,tmp, dc, retpos=[], ind=false, i,
  8781. 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="",
  8782. tdtmpl2 = "<td class='CaptionTD form-view-label ui-widget-content'>&#160;</td><td class='DataTD form-view-data ui-widget-content'>&#160;</td>",
  8783. fmtnum = ['integer','number','currency'],max1 =0, max2=0 ,maxw,setme, viewfld;
  8784. for (i=1;i<=maxcols;i++) {
  8785. tmpl += i === 1 ? tdtmpl : tdtmpl2;
  8786. }
  8787. // find max number align rigth with property formatter
  8788. $(obj.p.colModel).each( function() {
  8789. if(this.editrules && this.editrules.edithidden === true) {
  8790. hc = false;
  8791. } else {
  8792. hc = this.hidden === true ? true : false;
  8793. }
  8794. if(!hc && this.align==='right') {
  8795. if(this.formatter && $.inArray(this.formatter,fmtnum) !== -1 ) {
  8796. max1 = Math.max(max1,parseInt(this.width,10));
  8797. } else {
  8798. max2 = Math.max(max2,parseInt(this.width,10));
  8799. }
  8800. }
  8801. });
  8802. maxw = max1 !==0 ? max1 : max2 !==0 ? max2 : 0;
  8803. ind = $(obj).jqGrid("getInd",rowid);
  8804. $(obj.p.colModel).each( function(i) {
  8805. nm = this.name;
  8806. setme = false;
  8807. // hidden fields are included in the form
  8808. if(this.editrules && this.editrules.edithidden === true) {
  8809. hc = false;
  8810. } else {
  8811. hc = this.hidden === true ? true : false;
  8812. }
  8813. dc = hc ? "style='display:none'" : "";
  8814. viewfld = (typeof this.viewable !== 'boolean') ? true : this.viewable;
  8815. if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn' && viewfld) {
  8816. if(ind === false) {
  8817. tmp = "";
  8818. } else {
  8819. if(nm === obj.p.ExpandColumn && obj.p.treeGrid === true) {
  8820. tmp = $("td:eq("+i+")",obj.rows[ind]).text();
  8821. } else {
  8822. tmp = $("td:eq("+i+")",obj.rows[ind]).html();
  8823. }
  8824. }
  8825. setme = this.align === 'right' && maxw !==0 ? true : false;
  8826. var frmopt = $.extend({},{rowabove:false,rowcontent:''}, this.formoptions || {}),
  8827. rp = parseInt(frmopt.rowpos,10) || cnt+1,
  8828. cp = parseInt((parseInt(frmopt.colpos,10) || 1)*2,10);
  8829. if(frmopt.rowabove) {
  8830. var newdata = $("<tr><td class='contentinfo' colspan='"+(maxcols*2)+"'>"+frmopt.rowcontent+"</td></tr>");
  8831. $(tb).append(newdata);
  8832. newdata[0].rp = rp;
  8833. }
  8834. trdata = $(tb).find("tr[rowpos="+rp+"]");
  8835. if ( trdata.length===0 ) {
  8836. trdata = $("<tr "+dc+" rowpos='"+rp+"'></tr>").addClass("FormData").attr("id","trv_"+nm);
  8837. $(trdata).append(tmpl);
  8838. $(tb).append(trdata);
  8839. trdata[0].rp = rp;
  8840. }
  8841. $("td:eq("+(cp-2)+")",trdata[0]).html('<b>'+ (frmopt.label === undefined ? obj.p.colNames[i]: frmopt.label)+'</b>');
  8842. $("td:eq("+(cp-1)+")",trdata[0]).append("<span>"+tmp+"</span>").attr("id","v_"+nm);
  8843. if(setme){
  8844. $("td:eq("+(cp-1)+") span",trdata[0]).css({'text-align':'right',width:maxw+"px"});
  8845. }
  8846. retpos[cnt] = i;
  8847. cnt++;
  8848. }
  8849. });
  8850. if( cnt > 0) {
  8851. 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>");
  8852. idrow[0].rp = cnt+99;
  8853. $(tb).append(idrow);
  8854. }
  8855. return retpos;
  8856. }
  8857. function fillData(rowid,obj){
  8858. var nm, hc,cnt=0,tmp,trv;
  8859. trv = $(obj).jqGrid("getInd",rowid,true);
  8860. if(!trv) {return;}
  8861. $('td',trv).each( function(i) {
  8862. nm = obj.p.colModel[i].name;
  8863. // hidden fields are included in the form
  8864. if(obj.p.colModel[i].editrules && obj.p.colModel[i].editrules.edithidden === true) {
  8865. hc = false;
  8866. } else {
  8867. hc = obj.p.colModel[i].hidden === true ? true : false;
  8868. }
  8869. if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn') {
  8870. if(nm === obj.p.ExpandColumn && obj.p.treeGrid === true) {
  8871. tmp = $(this).text();
  8872. } else {
  8873. tmp = $(this).html();
  8874. }
  8875. nm = $.jgrid.jqID("v_"+nm);
  8876. $("#"+nm+" span","#"+frmtb).html(tmp);
  8877. if (hc) {$("#"+nm,"#"+frmtb).parents("tr:first").hide();}
  8878. cnt++;
  8879. }
  8880. });
  8881. if(cnt>0) {$("#id_g","#"+frmtb).val(rowid);}
  8882. }
  8883. function updateNav(cr,posarr){
  8884. var totr = posarr[1].length-1;
  8885. if (cr===0) {
  8886. $("#pData","#"+frmtb+"_2").addClass('ui-state-disabled');
  8887. } else if( posarr[1][cr-1] !== undefined && $("#"+$.jgrid.jqID(posarr[1][cr-1])).hasClass('ui-state-disabled')) {
  8888. $("#pData",frmtb+"_2").addClass('ui-state-disabled');
  8889. } else {
  8890. $("#pData","#"+frmtb+"_2").removeClass('ui-state-disabled');
  8891. }
  8892. if (cr===totr) {
  8893. $("#nData","#"+frmtb+"_2").addClass('ui-state-disabled');
  8894. } else if( posarr[1][cr+1] !== undefined && $("#"+$.jgrid.jqID(posarr[1][cr+1])).hasClass('ui-state-disabled')) {
  8895. $("#nData",frmtb+"_2").addClass('ui-state-disabled');
  8896. } else {
  8897. $("#nData","#"+frmtb+"_2").removeClass('ui-state-disabled');
  8898. }
  8899. }
  8900. function getCurrPos() {
  8901. var rowsInGrid = $($t).jqGrid("getDataIDs"),
  8902. selrow = $("#id_g","#"+frmtb).val(),
  8903. pos = $.inArray(selrow,rowsInGrid);
  8904. return [pos,rowsInGrid];
  8905. }
  8906. 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",
  8907. dw = isNaN(rp_ge[$(this)[0].p.id].datawidth) ? rp_ge[$(this)[0].p.id].datawidth : rp_ge[$(this)[0].p.id].datawidth+"px",
  8908. frm = $("<form name='FormPost' id='"+frmgr_id+"' class='FormGrid' style='width:"+dw+";overflow:auto;position:relative;height:"+dh+";'></form>"),
  8909. tbl =$("<table id='"+frmtb_id+"' class='EditTable' cellspacing='1' cellpadding='2' border='0' style='table-layout:fixed'><tbody></tbody></table>");
  8910. $($t.p.colModel).each( function() {
  8911. var fmto = this.formoptions;
  8912. maxCols = Math.max(maxCols, fmto ? fmto.colpos || 0 : 0 );
  8913. maxRows = Math.max(maxRows, fmto ? fmto.rowpos || 0 : 0 );
  8914. });
  8915. // set the id.
  8916. $(frm).append(tbl);
  8917. if(onBeforeInit) {
  8918. showFrm = onBeforeInit.call($t, frm );
  8919. if(showFrm === undefined) {
  8920. showFrm = true;
  8921. }
  8922. }
  8923. if(showFrm === false) {return;}
  8924. createData(rowid, $t, tbl, maxCols);
  8925. var rtlb = $t.p.direction === "rtl" ? true :false,
  8926. bp = rtlb ? "nData" : "pData",
  8927. bn = rtlb ? "pData" : "nData",
  8928. // buttons at footer
  8929. bP = "<a id='"+bp+"' class='fm-button ui-state-default ui-corner-left'><span class='ui-icon ui-icon-triangle-1-w'></span></a>",
  8930. bN = "<a id='"+bn+"' class='fm-button ui-state-default ui-corner-right'><span class='ui-icon ui-icon-triangle-1-e'></span></a>",
  8931. bC ="<a id='cData' class='fm-button ui-state-default ui-corner-all'>"+p.bClose+"</a>";
  8932. if(maxRows > 0) {
  8933. var sd=[];
  8934. $.each($(tbl)[0].rows,function(i,r){
  8935. sd[i] = r;
  8936. });
  8937. sd.sort(function(a,b){
  8938. if(a.rp > b.rp) {return 1;}
  8939. if(a.rp < b.rp) {return -1;}
  8940. return 0;
  8941. });
  8942. $.each(sd, function(index, row) {
  8943. $('tbody',tbl).append(row);
  8944. });
  8945. }
  8946. p.gbox = "#gbox_"+$.jgrid.jqID(gID);
  8947. 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>");
  8948. $.jgrid.createModal(IDs,bt,p,"#gview_"+$.jgrid.jqID($t.p.id),$("#gview_"+$.jgrid.jqID($t.p.id))[0]);
  8949. if(rtlb) {
  8950. $("#pData, #nData","#"+frmtb+"_2").css("float","right");
  8951. $(".EditButton","#"+frmtb+"_2").css("text-align","left");
  8952. }
  8953. if(!p.viewPagerButtons) {$("#pData, #nData","#"+frmtb+"_2").hide();}
  8954. bt = null;
  8955. $("#"+IDs.themodal).keydown( function( e ) {
  8956. if(e.which === 27) {
  8957. if(rp_ge[$t.p.id].closeOnEscape) {$.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:p.gbox,jqm:p.jqModal, onClose: p.onClose});}
  8958. return false;
  8959. }
  8960. if(p.navkeys[0]===true) {
  8961. if(e.which === p.navkeys[1]){ //up
  8962. $("#pData", "#"+frmtb+"_2").trigger("click");
  8963. return false;
  8964. }
  8965. if(e.which === p.navkeys[2]){ //down
  8966. $("#nData", "#"+frmtb+"_2").trigger("click");
  8967. return false;
  8968. }
  8969. }
  8970. });
  8971. p.closeicon = $.extend([true,"left","ui-icon-close"],p.closeicon);
  8972. if(p.closeicon[0]===true) {
  8973. $("#cData","#"+frmtb+"_2").addClass(p.closeicon[1] === "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  8974. .append("<span class='ui-icon "+p.closeicon[2]+"'></span>");
  8975. }
  8976. if($.isFunction(p.beforeShowForm)) {p.beforeShowForm.call($t,$("#"+frmgr));}
  8977. $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{
  8978. gbox:"#gbox_"+$.jgrid.jqID(gID),
  8979. jqm:p.jqModal,
  8980. overlay: p.overlay,
  8981. modal:p.modal,
  8982. onHide : function(h) {
  8983. $($t).data("viewProp", {
  8984. top:parseFloat($(h.w).css("top")),
  8985. left : parseFloat($(h.w).css("left")),
  8986. width : $(h.w).width(),
  8987. height : $(h.w).height(),
  8988. dataheight : $("#"+frmgr).height(),
  8989. datawidth: $("#"+frmgr).width()
  8990. });
  8991. h.w.remove();
  8992. if(h.o) {h.o.remove();}
  8993. }
  8994. });
  8995. $(".fm-button:not(.ui-state-disabled)","#"+frmtb+"_2").hover(
  8996. function(){$(this).addClass('ui-state-hover');},
  8997. function(){$(this).removeClass('ui-state-hover');}
  8998. );
  8999. focusaref();
  9000. $("#cData", "#"+frmtb+"_2").click(function(){
  9001. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: p.onClose});
  9002. return false;
  9003. });
  9004. $("#nData", "#"+frmtb+"_2").click(function(){
  9005. $("#FormError","#"+frmtb).hide();
  9006. var npos = getCurrPos();
  9007. npos[0] = parseInt(npos[0],10);
  9008. if(npos[0] !== -1 && npos[1][npos[0]+1]) {
  9009. if($.isFunction(p.onclickPgButtons)) {
  9010. p.onclickPgButtons.call($t,'next',$("#"+frmgr),npos[1][npos[0]]);
  9011. }
  9012. fillData(npos[1][npos[0]+1],$t);
  9013. $($t).jqGrid("setSelection",npos[1][npos[0]+1]);
  9014. if($.isFunction(p.afterclickPgButtons)) {
  9015. p.afterclickPgButtons.call($t,'next',$("#"+frmgr),npos[1][npos[0]+1]);
  9016. }
  9017. updateNav(npos[0]+1,npos);
  9018. }
  9019. focusaref();
  9020. return false;
  9021. });
  9022. $("#pData", "#"+frmtb+"_2").click(function(){
  9023. $("#FormError","#"+frmtb).hide();
  9024. var ppos = getCurrPos();
  9025. if(ppos[0] !== -1 && ppos[1][ppos[0]-1]) {
  9026. if($.isFunction(p.onclickPgButtons)) {
  9027. p.onclickPgButtons.call($t,'prev',$("#"+frmgr),ppos[1][ppos[0]]);
  9028. }
  9029. fillData(ppos[1][ppos[0]-1],$t);
  9030. $($t).jqGrid("setSelection",ppos[1][ppos[0]-1]);
  9031. if($.isFunction(p.afterclickPgButtons)) {
  9032. p.afterclickPgButtons.call($t,'prev',$("#"+frmgr),ppos[1][ppos[0]-1]);
  9033. }
  9034. updateNav(ppos[0]-1,ppos);
  9035. }
  9036. focusaref();
  9037. return false;
  9038. });
  9039. var posInit =getCurrPos();
  9040. updateNav(posInit[0],posInit);
  9041. });
  9042. },
  9043. delGridRow : function(rowids,p) {
  9044. var listId=$(this)[0].p.id;
  9045. p = $.extend(true, {
  9046. top : 0,
  9047. left: 0,
  9048. width: 240,
  9049. height: 'auto',
  9050. dataheight : 'auto',
  9051. modal: false,
  9052. overlay: 30,
  9053. drag: true,
  9054. resize: true,
  9055. url : '',
  9056. mtype : "POST",
  9057. reloadAfterSubmit: true,
  9058. beforeShowForm: null,
  9059. beforeInitData : null,
  9060. afterShowForm: null,
  9061. beforeSubmit: null,
  9062. onclickSubmit: function(){
  9063. var sFunName=listId+"_delSubmit";
  9064. var callBackFunction = window[sFunName];
  9065. if(callBackFunction&&typeof(callBackFunction)=="function"){callBackFunction(rowids);}
  9066. },
  9067. afterSubmit:null,
  9068. jqModal : true,
  9069. closeOnEscape : false,
  9070. delData: {},
  9071. delicon : [],
  9072. cancelicon : [],
  9073. onClose : null,
  9074. ajaxDelOptions : {},
  9075. processing : false,
  9076. serializeDelData : null,
  9077. useDataProxy : false
  9078. }, $.jgrid.del, p ||{});
  9079. rp_ge[$(this)[0].p.id] = p;
  9080. return this.each(function(){
  9081. var $t = this;
  9082. if (!$t.grid ) {return;}
  9083. if(!rowids) {return;}
  9084. var onBeforeShow = $.isFunction( rp_ge[$t.p.id].beforeShowForm ),
  9085. onAfterShow = $.isFunction( rp_ge[$t.p.id].afterShowForm ),
  9086. onBeforeInit = $.isFunction(rp_ge[$t.p.id].beforeInitData) ? rp_ge[$t.p.id].beforeInitData : false,
  9087. gID = $t.p.id, onCS = {},
  9088. showFrm = true,
  9089. dtbl = "DelTbl_"+$.jgrid.jqID(gID),postd, idname, opers, oper,
  9090. dtbl_id = "DelTbl_" + gID,
  9091. IDs = {themodal:'delmod'+gID,modalhead:'delhd'+gID,modalcontent:'delcnt'+gID, scrollelm: dtbl};
  9092. if ($.isArray(rowids)) {rowids = rowids.join();}
  9093. if ( $("#"+$.jgrid.jqID(IDs.themodal))[0] !== undefined ) {
  9094. if(onBeforeInit) {
  9095. showFrm = onBeforeInit.call($t,$("#"+dtbl));
  9096. if(showFrm === undefined) {
  9097. showFrm = true;
  9098. }
  9099. }
  9100. if(showFrm === false) {return;}
  9101. $("#DelData>td","#"+dtbl).text(rowids);
  9102. $("#DelError","#"+dtbl).hide();
  9103. if( rp_ge[$t.p.id].processing === true) {
  9104. rp_ge[$t.p.id].processing=false;
  9105. $("#dData", "#"+dtbl).removeClass('ui-state-active');
  9106. }
  9107. if(onBeforeShow) {rp_ge[$t.p.id].beforeShowForm.call($t,$("#"+dtbl));}
  9108. $.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});
  9109. if(onAfterShow) {rp_ge[$t.p.id].afterShowForm.call($t,$("#"+dtbl));}
  9110. } else {
  9111. var dh = isNaN(rp_ge[$t.p.id].dataheight) ? rp_ge[$t.p.id].dataheight : rp_ge[$t.p.id].dataheight+"px",
  9112. dw = isNaN(p.datawidth) ? p.datawidth : p.datawidth+"px",
  9113. tbl = "<div id='"+dtbl_id+"' class='formdata' style='width:"+dw+";overflow:auto;position:relative;height:"+dh+";'>";
  9114. tbl += "<table class='DelTable'><tbody>";
  9115. // error data
  9116. tbl += "<tr id='DelError' style='display:none'><td class='ui-state-error'></td></tr>";
  9117. tbl += "<tr id='DelData' style='display:none'><td >"+rowids+"</td></tr>";
  9118. tbl += "<tr><td class=\"delmsg\" style=\"white-space:pre;\">"+rp_ge[$t.p.id].msg+"</td></tr><tr><td >&#160;</td></tr>";
  9119. // buttons at footer
  9120. tbl += "</tbody></table></div>";
  9121. var bS = "<a id='dData' class='fm-button ui-state-default ui-corner-all'>"+p.bSubmit+"</a>",
  9122. bC = "<a id='eData' class='fm-button ui-state-default ui-corner-all'>"+p.bCancel+"</a>";
  9123. 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>";
  9124. p.gbox = "#gbox_"+$.jgrid.jqID(gID);
  9125. $.jgrid.createModal(IDs,tbl,p,"#gview_"+$.jgrid.jqID($t.p.id),$("#gview_"+$.jgrid.jqID($t.p.id))[0]);
  9126. if(onBeforeInit) {
  9127. showFrm = onBeforeInit.call($t,$(tbl));
  9128. if(showFrm === undefined) {
  9129. showFrm = true;
  9130. }
  9131. }
  9132. if(showFrm === false) {return;}
  9133. $(".fm-button","#"+dtbl+"_2").hover(
  9134. function(){$(this).addClass('ui-state-hover');},
  9135. function(){$(this).removeClass('ui-state-hover');}
  9136. );
  9137. p.delicon = $.extend([true,"left","ui-icon-scissors"],rp_ge[$t.p.id].delicon);
  9138. p.cancelicon = $.extend([true,"left","ui-icon-cancel"],rp_ge[$t.p.id].cancelicon);
  9139. if(p.delicon[0]===true) {
  9140. $("#dData","#"+dtbl+"_2").addClass(p.delicon[1] === "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  9141. .append("<span class='ui-icon "+p.delicon[2]+"'></span>");
  9142. }
  9143. if(p.cancelicon[0]===true) {
  9144. $("#eData","#"+dtbl+"_2").addClass(p.cancelicon[1] === "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  9145. .append("<span class='ui-icon "+p.cancelicon[2]+"'></span>");
  9146. }
  9147. $("#dData","#"+dtbl+"_2").click(function(){
  9148. var ret=[true,""], pk,
  9149. postdata = $("#DelData>td","#"+dtbl).text(); //the pair is name=val1,val2,...
  9150. onCS = {};
  9151. if( $.isFunction( rp_ge[$t.p.id].onclickSubmit ) ) {onCS = rp_ge[$t.p.id].onclickSubmit.call($t,rp_ge[$t.p.id], postdata) || {};}
  9152. if( $.isFunction( rp_ge[$t.p.id].beforeSubmit ) ) {ret = rp_ge[$t.p.id].beforeSubmit.call($t,postdata);}
  9153. if(ret[0] && !rp_ge[$t.p.id].processing) {
  9154. rp_ge[$t.p.id].processing = true;
  9155. opers = $t.p.prmNames;
  9156. postd = $.extend({},rp_ge[$t.p.id].delData, onCS);
  9157. oper = opers.oper;
  9158. postd[oper] = opers.deloper;
  9159. idname = opers.id;
  9160. postdata = String(postdata).split(",");
  9161. if(!postdata.length) { return false; }
  9162. for(pk in postdata) {
  9163. if(postdata.hasOwnProperty(pk)) {
  9164. postdata[pk] = $.jgrid.stripPref($t.p.idPrefix, postdata[pk]);
  9165. }
  9166. }
  9167. postd[idname] = postdata.join();
  9168. $(this).addClass('ui-state-active');
  9169. var ajaxOptions = $.extend({
  9170. url: rp_ge[$t.p.id].url || $($t).jqGrid('getGridParam','editurl'),
  9171. type: rp_ge[$t.p.id].mtype,
  9172. data: $.isFunction(rp_ge[$t.p.id].serializeDelData) ? rp_ge[$t.p.id].serializeDelData.call($t,postd) : postd,
  9173. complete:function(data,status){
  9174. var i;
  9175. if(data.status >= 300 && data.status !== 304) {
  9176. ret[0] = false;
  9177. if ($.isFunction(rp_ge[$t.p.id].errorTextFormat)) {
  9178. ret[1] = rp_ge[$t.p.id].errorTextFormat.call($t,data);
  9179. } else {
  9180. ret[1] = status + " Status: '" + data.statusText + "'. Error code: " + data.status;
  9181. }
  9182. } else {
  9183. // data is posted successful
  9184. // execute aftersubmit with the returned data from server
  9185. if( $.isFunction( rp_ge[$t.p.id].afterSubmit ) ) {
  9186. ret = rp_ge[$t.p.id].afterSubmit.call($t,data,postd);
  9187. }
  9188. }
  9189. if(ret[0] === false) {
  9190. $("#DelError>td","#"+dtbl).html(ret[1]);
  9191. $("#DelError","#"+dtbl).show();
  9192. } else {
  9193. if(rp_ge[$t.p.id].reloadAfterSubmit && $t.p.datatype !== "local") {
  9194. $($t).trigger("reloadGrid");
  9195. } else {
  9196. if($t.p.treeGrid===true){
  9197. try {$($t).jqGrid("delTreeNode",$t.p.idPrefix+postdata[0]);} catch(e){}
  9198. } else {
  9199. for(i=0;i<postdata.length;i++) {
  9200. $($t).jqGrid("delRowData",$t.p.idPrefix+ postdata[i]);
  9201. }
  9202. }
  9203. $t.p.selrow = null;
  9204. $t.p.selarrrow = [];
  9205. }
  9206. if($.isFunction(rp_ge[$t.p.id].afterComplete)) {
  9207. setTimeout(function(){rp_ge[$t.p.id].afterComplete.call($t,data,postdata);},500);
  9208. }
  9209. }
  9210. rp_ge[$t.p.id].processing=false;
  9211. $("#dData", "#"+dtbl+"_2").removeClass('ui-state-active');
  9212. if(ret[0]) {$.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});}
  9213. }
  9214. }, $.jgrid.ajaxOptions, rp_ge[$t.p.id].ajaxDelOptions);
  9215. if (!ajaxOptions.url && !rp_ge[$t.p.id].useDataProxy) {
  9216. if ($.isFunction($t.p.dataProxy)) {
  9217. rp_ge[$t.p.id].useDataProxy = true;
  9218. } else {
  9219. ret[0]=false;ret[1] += " "+$.jgrid.errors.nourl;
  9220. }
  9221. }
  9222. if (ret[0]) {
  9223. if (rp_ge[$t.p.id].useDataProxy) {
  9224. var dpret = $t.p.dataProxy.call($t, ajaxOptions, "del_"+$t.p.id);
  9225. if(dpret === undefined) {
  9226. dpret = [true, ""];
  9227. }
  9228. if(dpret[0] === false ) {
  9229. ret[0] = false;
  9230. ret[1] = dpret[1] || "Error deleting the selected row!" ;
  9231. } else {
  9232. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});
  9233. }
  9234. }
  9235. else {
  9236. if(ajaxOptions.url === "clientArray") {
  9237. postd = ajaxOptions.data;
  9238. ajaxOptions.complete({status:200, statusText:''},'');
  9239. } else {
  9240. //alert("04");
  9241. $.ajax(ajaxOptions);
  9242. }
  9243. }
  9244. }
  9245. }
  9246. if(ret[0] === false) {
  9247. $("#DelError>td","#"+dtbl).html(ret[1]);
  9248. $("#DelError","#"+dtbl).show();
  9249. }
  9250. return false;
  9251. });
  9252. $("#eData", "#"+dtbl+"_2").click(function(){
  9253. $.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});
  9254. return false;
  9255. });
  9256. if(onBeforeShow) {rp_ge[$t.p.id].beforeShowForm.call($t,$("#"+dtbl));}
  9257. $.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});
  9258. if(onAfterShow) {rp_ge[$t.p.id].afterShowForm.call($t,$("#"+dtbl));}
  9259. }
  9260. if(rp_ge[$t.p.id].closeOnEscape===true) {
  9261. setTimeout(function(){$(".ui-jqdialog-titlebar-close","#"+$.jgrid.jqID(IDs.modalhead)).attr("tabindex","-1").focus();},0);
  9262. }
  9263. });
  9264. },
  9265. navGrid : function (elem, o, pEdit,pAdd,pDel,pSearch, pView) {
  9266. o = $.extend({
  9267. edit: false,
  9268. editicon: "ui-icon-pencil",
  9269. add: false,
  9270. addicon:"ui-icon-plus",
  9271. del: true,
  9272. delicon:"ui-icon-trash",
  9273. search: true,
  9274. searchicon:"ui-icon-search",
  9275. refresh: true,
  9276. refreshicon:"ui-icon-refresh",
  9277. refreshstate: 'firstpage',
  9278. excelExp: false,
  9279. excelicon: "ui-icon-refresh",
  9280. MUTL:false,//跨页全选
  9281. pdfExp: false,
  9282. csvExp: false,
  9283. xlsxExp: false,
  9284. etExp: false,
  9285. view: false,
  9286. viewicon : "ui-icon-document",
  9287. position : "left",
  9288. closeOnEscape : true,
  9289. beforeRefresh : null,
  9290. afterRefresh : null,
  9291. cloneToTop : false,
  9292. alertwidth : 200,
  9293. alertheight : 'auto',
  9294. alerttop: null,
  9295. alertleft: null,
  9296. alertzIndex : null
  9297. }, $.jgrid.nav, o ||{});
  9298. return this.each(function() {
  9299. if(this.nav) {return;}
  9300. var alertIDs = {themodal: 'alertmod_' + this.p.id, modalhead: 'alerthd_' + this.p.id,modalcontent: 'alertcnt_' + this.p.id},
  9301. $t = this, twd, tdw;
  9302. if(!$t.grid || typeof elem !== 'string') {return;}
  9303. if ($("#"+alertIDs.themodal)[0] === undefined) {
  9304. if(!o.alerttop && !o.alertleft) {
  9305. if (window.innerWidth !== undefined) {
  9306. o.alertleft = window.innerWidth;
  9307. o.alerttop = window.innerHeight;
  9308. } else if (document.documentElement !== undefined && document.documentElement.clientWidth !== undefined && document.documentElement.clientWidth !== 0) {
  9309. o.alertleft = document.documentElement.clientWidth;
  9310. o.alerttop = document.documentElement.clientHeight;
  9311. } else {
  9312. o.alertleft=1024;
  9313. o.alerttop=768;
  9314. }
  9315. o.alertleft = o.alertleft/2 - parseInt(o.alertwidth,10)/2;
  9316. o.alerttop = o.alerttop/2-25;
  9317. }
  9318. $.jgrid.createModal(alertIDs,
  9319. "<div>"+o.alerttext+"</div><span tabindex='0'><span tabindex='-1' id='jqg_alrt'></span></span>",
  9320. {
  9321. gbox:"#gbox_"+$.jgrid.jqID($t.p.id),
  9322. jqModal:true,
  9323. drag:true,
  9324. resize:true,
  9325. caption:o.alertcap,
  9326. top:o.alerttop,
  9327. left:o.alertleft,
  9328. width:o.alertwidth,
  9329. height: o.alertheight,
  9330. closeOnEscape:o.closeOnEscape,
  9331. zIndex: o.alertzIndex
  9332. },
  9333. "#gview_"+$.jgrid.jqID($t.p.id),
  9334. $("#gbox_"+$.jgrid.jqID($t.p.id))[0],
  9335. true
  9336. );
  9337. }
  9338. var clone = 1, i,
  9339. onHoverIn = function () {
  9340. if (!$(this).hasClass('ui-state-disabled')) {
  9341. $(this).addClass("ui-state-hover");
  9342. }
  9343. },
  9344. onHoverOut = function () {
  9345. $(this).removeClass("ui-state-hover");
  9346. };
  9347. if(o.cloneToTop && $t.p.toppager) {clone = 2;}
  9348. for(i = 0; i<clone; i++) {
  9349. var tbd,
  9350. navtbl = $("<table cellspacing='0' cellpadding='0' border='0' class='ui-pg-table navtable' style='float:left;table-layout:auto;'><tbody><tr></tr></tbody></table>"),
  9351. sep = "<td class='ui-pg-button ui-state-disabled' style='width:4px;'><span class='ui-separator'></span></td>",
  9352. pgid, elemids;
  9353. if(i===0) {
  9354. pgid = elem;
  9355. elemids = $t.p.id;
  9356. if(pgid === $t.p.toppager) {
  9357. elemids += "_top";
  9358. clone = 1;
  9359. }
  9360. } else {
  9361. pgid = $t.p.toppager;
  9362. elemids = $t.p.id+"_top";
  9363. }
  9364. if($t.p.direction === "rtl") {$(navtbl).attr("dir","rtl").css("float","right");}
  9365. if (o.add) {
  9366. pAdd = pAdd || {};
  9367. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  9368. $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.addicon+"'></span>"+o.addtext+"</div>");
  9369. $("tr",navtbl).append(tbd);
  9370. $(tbd,navtbl)
  9371. .attr({"title":o.addtitle || "",id : pAdd.id || "add_"+elemids})
  9372. .click(function(){
  9373. if (!$(this).hasClass('ui-state-disabled')) {
  9374. if ($.isFunction( o.addfunc )) {
  9375. o.addfunc.call($t);
  9376. } else {
  9377. $($t).jqGrid("editGridRow","new",pAdd);
  9378. }
  9379. }
  9380. return false;
  9381. }).hover(onHoverIn, onHoverOut);
  9382. tbd = null;
  9383. }
  9384. if (o.edit) {
  9385. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  9386. pEdit = pEdit || {};
  9387. $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.editicon+"'></span>"+o.edittext+"</div>");
  9388. $("tr",navtbl).append(tbd);
  9389. $(tbd,navtbl)
  9390. .attr({"title":o.edittitle || "",id: pEdit.id || "edit_"+elemids})
  9391. .click(function(){
  9392. if (!$(this).hasClass('ui-state-disabled')) {
  9393. var sr = $t.p.selrow;
  9394. if (sr) {
  9395. if($.isFunction( o.editfunc ) ) {
  9396. o.editfunc.call($t, sr);
  9397. } else {
  9398. $($t).jqGrid("editGridRow",sr,pEdit);
  9399. }
  9400. } else {
  9401. $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:true});
  9402. $("#jqg_alrt").focus();
  9403. }
  9404. }
  9405. return false;
  9406. }).hover(onHoverIn, onHoverOut);
  9407. tbd = null;
  9408. }
  9409. if (o.view) {
  9410. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  9411. pView = pView || {};
  9412. $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.viewicon+"'></span>"+o.viewtext+"</div>");
  9413. $("tr",navtbl).append(tbd);
  9414. $(tbd,navtbl)
  9415. .attr({"title":o.viewtitle || "",id: pView.id || "view_"+elemids})
  9416. .click(function(){
  9417. if (!$(this).hasClass('ui-state-disabled')) {
  9418. var sr = $t.p.selrow;
  9419. if (sr) {
  9420. if($.isFunction( o.viewfunc ) ) {
  9421. o.viewfunc.call($t, sr);
  9422. } else {
  9423. $($t).jqGrid("viewGridRow",sr,pView);
  9424. }
  9425. } else {
  9426. $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:true});
  9427. $("#jqg_alrt").focus();
  9428. }
  9429. }
  9430. return false;
  9431. }).hover(onHoverIn, onHoverOut);
  9432. tbd = null;
  9433. }
  9434. if (o.del) {
  9435. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  9436. pDel = pDel || {};
  9437. $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.delicon+"'></span>"+o.deltext+"</div>");
  9438. $("tr",navtbl).append(tbd);
  9439. $(tbd,navtbl)
  9440. .attr({"title":o.deltitle || "",id: pDel.id || "del_"+elemids})
  9441. .click(function(){
  9442. if (!$(this).hasClass('ui-state-disabled')) {
  9443. var dr;
  9444. if($t.p.multiselect) {
  9445. dr = $t.p.selarrrow;
  9446. if(dr.length===0) {dr = null;}
  9447. } else {
  9448. dr = $t.p.selrow;
  9449. }
  9450. if(dr){
  9451. if($.isFunction( o.delfunc )){
  9452. o.delfunc.call($t, dr);
  9453. }else{
  9454. $($t).jqGrid("delGridRow",dr,pDel);
  9455. }
  9456. } else {
  9457. $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:true});$("#jqg_alrt").focus();
  9458. }
  9459. }
  9460. return false;
  9461. }).hover(onHoverIn, onHoverOut);
  9462. tbd = null;
  9463. }
  9464. if(o.add || o.edit || o.del || o.view) {$("tr",navtbl).append(sep);}
  9465. if (o.search) {
  9466. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  9467. pSearch = pSearch || {};
  9468. $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.searchicon+"'></span>"+o.searchtext+"</div>");
  9469. $("tr",navtbl).append(tbd);
  9470. $(tbd,navtbl)
  9471. .attr({"title":o.searchtitle || "",id:pSearch.id || "search_"+elemids})
  9472. .click(function(){
  9473. if (!$(this).hasClass('ui-state-disabled')) {
  9474. if($.isFunction( o.searchfunc )) {
  9475. o.searchfunc.call($t, pSearch);
  9476. } else {
  9477. $($t).jqGrid("searchGrid",pSearch);
  9478. }
  9479. }
  9480. return false;
  9481. }).hover(onHoverIn, onHoverOut);
  9482. if (pSearch.showOnLoad && pSearch.showOnLoad === true) {
  9483. $(tbd,navtbl).click();
  9484. }
  9485. tbd = null;
  9486. }
  9487. if (o.refresh) {
  9488. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  9489. $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.refreshicon+"'></span>"+o.refreshtext+"</div>");
  9490. $("tr",navtbl).append(tbd);
  9491. $(tbd,navtbl)
  9492. .attr({"title":o.refreshtitle || "",id: "refresh_"+elemids})
  9493. .click(function(){
  9494. if (!$(this).hasClass('ui-state-disabled')) {
  9495. if($.isFunction(o.beforeRefresh)) {o.beforeRefresh.call($t);}
  9496. $t.p.search = false;
  9497. $t.p.resetsearch = true;
  9498. try {
  9499. if( o.refreshstate !== 'currentfilter') {
  9500. var gID = $t.p.id;
  9501. $t.p.postData.filters ="";
  9502. try {
  9503. $("#fbox_"+$.jgrid.jqID(gID)).jqFilter('resetFilter');
  9504. } catch(ef) {}
  9505. if($.isFunction($t.clearToolbar)) {$t.clearToolbar.call($t,false);}
  9506. }
  9507. } catch (e) {}
  9508. switch (o.refreshstate) {
  9509. case 'firstpage':
  9510. $($t).trigger("reloadGrid", [{page:1}]);
  9511. break;
  9512. case 'current':
  9513. case 'currentfilter':
  9514. $($t).trigger("reloadGrid", [{current:true}]);
  9515. break;
  9516. }
  9517. if($.isFunction(o.afterRefresh)) {o.afterRefresh.call($t);}
  9518. }
  9519. return false;
  9520. }).hover(onHoverIn, onHoverOut);
  9521. tbd = null;
  9522. }
  9523. //alert(o.excelExp+"----------------"+o.pdfExp);
  9524. if (o.excelExp) {
  9525. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  9526. $(tbd).append("<div class='ui-pg-div'><span class='l-btn-empty jqdatagrid-excel'></span></div>");
  9527. $("tr",navtbl).append(tbd);
  9528. $(tbd,navtbl)
  9529. .attr({"title":"EXCEL导出" || "",id: "excel_"+elemids})
  9530. .click(function(){
  9531. downfile($t.p, "EXCEL");
  9532. }).hover(onHoverIn, onHoverOut);
  9533. tbd = null;
  9534. }
  9535. if (o.pdfExp) {
  9536. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  9537. $(tbd).append("<div class='ui-pg-div'><span class='l-btn-empty jqdatagrid-pdf'></span></div>");
  9538. $("tr",navtbl).append(tbd);
  9539. $(tbd,navtbl)
  9540. .attr({"title":"PDF导出" || "",id: "pdf_"+elemids})
  9541. .click(function(){
  9542. downfile($t.p, "PDF");
  9543. }).hover(onHoverIn, onHoverOut);
  9544. tbd = null;
  9545. }
  9546. if (o.xlsxExp) {
  9547. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  9548. $(tbd).append("<div class='ui-pg-div'><span class='l-btn-empty jqdatagrid-xlsx'></span></div>");
  9549. $("tr",navtbl).append(tbd);
  9550. $(tbd,navtbl)
  9551. .attr({"title":"XLSX导出" || "",id: "xlsx_"+elemids})
  9552. .click(function(){
  9553. downfile($t.p, "XLSX");
  9554. }).hover(onHoverIn, onHoverOut);
  9555. tbd = null;
  9556. }
  9557. if (o.etExp) {
  9558. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  9559. $(tbd).append("<div class='ui-pg-div'><span class='l-btn-empty jqdatagrid-et'></span></div>");
  9560. $("tr",navtbl).append(tbd);
  9561. $(tbd,navtbl)
  9562. .attr({"title":"ET导出" || "",id: "et_"+elemids})
  9563. .click(function(){
  9564. downfile($t.p, "ET");
  9565. }).hover(onHoverIn, onHoverOut);
  9566. tbd = null;
  9567. }
  9568. if (o.csvExp) {
  9569. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  9570. $(tbd).append("<div class='ui-pg-div'><span class='l-btn-empty jqdatagrid-csv'></span></div>");
  9571. $("tr",navtbl).append(tbd);
  9572. $(tbd,navtbl)
  9573. .attr({"title":"CSV导出" || "",id: "cxv_"+elemids})
  9574. .click(function(){
  9575. downfile($t.p, "CSV");
  9576. }).hover(onHoverIn, onHoverOut);
  9577. tbd = null;
  9578. }
  9579. if($t.p.multiselect && o.MUTL){
  9580. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  9581. $(tbd).append("<div class='ui-pg-div'><a href=\"javascript:void(0)\" title=\"全部分页的记录都设置为选中状态\" class=\"mutl\">跨页全选 </a></div>");
  9582. $("tr",navtbl).append(tbd);
  9583. $(tbd,navtbl)
  9584. .attr({"title":"跨页全选" || "",id: "mutl_"+elemids})
  9585. .click(function(){
  9586. this.disabled = true;
  9587. getAll($t.p);
  9588. this.disabled = false;
  9589. return true;
  9590. }).hover(onHoverIn, onHoverOut);
  9591. tbd = null;
  9592. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  9593. $(tbd).append("<div class='ui-pg-div'><a href=\"javascript:void(0)\" title=\"取消所有选中状态\" class=\"mutlq\">取消全选 </a></div>");
  9594. $("tr",navtbl).append(tbd);
  9595. $(tbd,navtbl)
  9596. .attr({"title":"取消全选" || "",id: "canclemutl_"+elemids})
  9597. .click(function(){
  9598. this.disabled = true;
  9599. unGetAll($t.p);
  9600. $t.p.checkArray=[];
  9601. $t.p.selarrrow=[];
  9602. this.disabled = false;
  9603. return true;
  9604. }).hover(onHoverIn, onHoverOut);
  9605. tbd = null;
  9606. }
  9607. tdw = $(".ui-jqgrid").css("font-size") || "11px";
  9608. $('body').append("<div id='testpg2' class='ui-jqgrid ui-widget ui-widget-content' style='font-size:"+tdw+";visibility:hidden;' ></div>");
  9609. twd = $(navtbl).clone().appendTo("#testpg2").width();
  9610. $("#testpg2").remove();
  9611. $(pgid+"_"+o.position,pgid).append(navtbl);
  9612. if($t.p._nvtd) {
  9613. if(twd > $t.p._nvtd[0] ) {
  9614. $(pgid+"_"+o.position,pgid).width(twd);
  9615. $t.p._nvtd[0] = twd;
  9616. }
  9617. $t.p._nvtd[1] = twd;
  9618. }
  9619. tdw =null;twd=null;navtbl =null;
  9620. this.nav = true;
  9621. }
  9622. });
  9623. },
  9624. navButtonAdd : function (elem, p) {
  9625. p = $.extend({
  9626. caption : "newButton",
  9627. title: '',
  9628. buttonicon : 'ui-icon-newwin',
  9629. onClickButton: null,
  9630. position : "last",
  9631. cursor : 'pointer'
  9632. }, p ||{});
  9633. return this.each(function() {
  9634. if( !this.grid) {return;}
  9635. if( typeof elem === "string" && elem.indexOf("#") !== 0) {elem = "#"+$.jgrid.jqID(elem);}
  9636. var findnav = $(".navtable",elem)[0], $t = this;
  9637. if (findnav) {
  9638. if( p.id && $("#"+$.jgrid.jqID(p.id), findnav)[0] !== undefined ) {return;}
  9639. var tbd = $("<td></td>");
  9640. if(p.buttonicon.toString().toUpperCase() === "NONE") {
  9641. $(tbd).addClass('ui-pg-button ui-corner-all').append("<div class='ui-pg-div'>"+p.caption+"</div>");
  9642. } else {
  9643. $(tbd).addClass('ui-pg-button ui-corner-all').append("<div class='ui-pg-div'><span class='ui-icon "+p.buttonicon+"'></span>"+p.caption+"</div>");
  9644. }
  9645. if(p.id) {$(tbd).attr("id",p.id);}
  9646. if(p.position==='first'){
  9647. if(findnav.rows[0].cells.length ===0 ) {
  9648. $("tr",findnav).append(tbd);
  9649. } else {
  9650. $("tr td:eq(0)",findnav).before(tbd);
  9651. }
  9652. } else {
  9653. $("tr",findnav).append(tbd);
  9654. }
  9655. $(tbd,findnav)
  9656. .attr("title",p.title || "")
  9657. .click(function(e){
  9658. if (!$(this).hasClass('ui-state-disabled')) {
  9659. if ($.isFunction(p.onClickButton) ) {p.onClickButton.call($t,e);}
  9660. }
  9661. return false;
  9662. })
  9663. .hover(
  9664. function () {
  9665. if (!$(this).hasClass('ui-state-disabled')) {
  9666. $(this).addClass('ui-state-hover');
  9667. }
  9668. },
  9669. function () {$(this).removeClass("ui-state-hover");}
  9670. );
  9671. }
  9672. });
  9673. },
  9674. navSeparatorAdd:function (elem,p) {
  9675. p = $.extend({
  9676. sepclass : "ui-separator",
  9677. sepcontent: '',
  9678. position : "last"
  9679. }, p ||{});
  9680. return this.each(function() {
  9681. if( !this.grid) {return;}
  9682. if( typeof elem === "string" && elem.indexOf("#") !== 0) {elem = "#"+$.jgrid.jqID(elem);}
  9683. var findnav = $(".navtable",elem)[0];
  9684. if(findnav) {
  9685. var sep = "<td class='ui-pg-button ui-state-disabled' style='width:4px;'><span class='"+p.sepclass+"'></span>"+p.sepcontent+"</td>";
  9686. if (p.position === 'first') {
  9687. if (findnav.rows[0].cells.length === 0) {
  9688. $("tr", findnav).append(sep);
  9689. } else {
  9690. $("tr td:eq(0)", findnav).before(sep);
  9691. }
  9692. } else {
  9693. $("tr", findnav).append(sep);
  9694. }
  9695. }
  9696. });
  9697. },
  9698. GridToForm : function( rowid, formid ) {
  9699. return this.each(function(){
  9700. var $t = this, i;
  9701. if (!$t.grid) {return;}
  9702. var rowdata = $($t).jqGrid("getRowData",rowid);
  9703. if (rowdata) {
  9704. for(i in rowdata) {
  9705. if(rowdata.hasOwnProperty(i)) {
  9706. if ( $("[name="+$.jgrid.jqID(i)+"]",formid).is("input:radio") || $("[name="+$.jgrid.jqID(i)+"]",formid).is("input:checkbox")) {
  9707. $("[name="+$.jgrid.jqID(i)+"]",formid).each( function() {
  9708. if( $(this).val() == rowdata[i] ) {
  9709. $(this)[$t.p.useProp ? 'prop': 'attr']("checked",true);
  9710. } else {
  9711. $(this)[$t.p.useProp ? 'prop': 'attr']("checked", false);
  9712. }
  9713. });
  9714. } else {
  9715. // this is very slow on big table and form.
  9716. $("[name="+$.jgrid.jqID(i)+"]",formid).val(rowdata[i]);
  9717. }
  9718. }
  9719. }
  9720. }
  9721. });
  9722. },
  9723. FormToGrid : function(rowid, formid, mode, position){
  9724. return this.each(function() {
  9725. var $t = this;
  9726. if(!$t.grid) {return;}
  9727. if(!mode) {mode = 'set';}
  9728. if(!position) {position = 'first';}
  9729. var fields = $(formid).serializeArray();
  9730. var griddata = {};
  9731. $.each(fields, function(i, field){
  9732. griddata[field.name] = field.value;
  9733. });
  9734. if(mode==='add') {$($t).jqGrid("addRowData",rowid,griddata, position);}
  9735. else if(mode==='set') {$($t).jqGrid("setRowData",rowid,griddata);}
  9736. });
  9737. }
  9738. });
  9739. })(jQuery);
  9740. /*jshint eqeqeq:false, eqnull:true, devel:true */
  9741. /*global jQuery */
  9742. (function($){
  9743. /**
  9744. * jqGrid extension for manipulating Grid Data
  9745. * Tony Tomov tony@trirand.com
  9746. * http://trirand.com/blog/
  9747. * Dual licensed under the MIT and GPL licenses:
  9748. * http://www.opensource.org/licenses/mit-license.php
  9749. * http://www.gnu.org/licenses/gpl-2.0.html
  9750. **/
  9751. "use strict";
  9752. $.jgrid.inlineEdit = $.jgrid.inlineEdit || {};
  9753. $.jgrid.extend({
  9754. //Editing
  9755. editRow : function(rowid,keys,oneditfunc,successfunc, url, extraparam, aftersavefunc,errorfunc, afterrestorefunc) {
  9756. // Compatible mode old versions
  9757. var o={}, args = $.makeArray(arguments).slice(1);
  9758. if( $.type(args[0]) === "object" ) {
  9759. o = args[0];
  9760. } else {
  9761. if (keys !== undefined) { o.keys = keys; }
  9762. if ($.isFunction(oneditfunc)) { o.oneditfunc = oneditfunc; }
  9763. if ($.isFunction(successfunc)) { o.successfunc = successfunc; }
  9764. if (url !== undefined) { o.url = url; }
  9765. if (extraparam !== undefined) { o.extraparam = extraparam; }
  9766. if ($.isFunction(aftersavefunc)) { o.aftersavefunc = aftersavefunc; }
  9767. if ($.isFunction(errorfunc)) { o.errorfunc = errorfunc; }
  9768. if ($.isFunction(afterrestorefunc)) { o.afterrestorefunc = afterrestorefunc; }
  9769. // last two not as param, but as object (sorry)
  9770. //if (restoreAfterError !== undefined) { o.restoreAfterError = restoreAfterError; }
  9771. //if (mtype !== undefined) { o.mtype = mtype || "POST"; }
  9772. }
  9773. o = $.extend(true, {
  9774. keys : false,
  9775. oneditfunc: null,
  9776. successfunc: null,
  9777. url: null,
  9778. extraparam: {},
  9779. aftersavefunc: null,
  9780. errorfunc: null,
  9781. afterrestorefunc: null,
  9782. restoreAfterError: true,
  9783. mtype: "POST",
  9784. focusField : true
  9785. }, $.jgrid.inlineEdit, o );
  9786. // End compatible
  9787. return this.each(function(){
  9788. var $t = this, nm, tmp, editable, cnt=0, focus=null, svr={}, ind,cm, bfer;
  9789. if (!$t.grid ) { return; }
  9790. ind = $($t).jqGrid("getInd",rowid,true);
  9791. if( ind === false ) {return;}
  9792. bfer = $.isFunction( o.beforeEditRow ) ? o.beforeEditRow.call($t,o, rowid) : undefined;
  9793. if( bfer === undefined ) {
  9794. bfer = true;
  9795. }
  9796. if(!bfer) { return; }
  9797. editable = $(ind).attr("editable") || "0";
  9798. if (editable === "0" && !$(ind).hasClass("not-editable-row")) {
  9799. cm = $t.p.colModel;
  9800. $('td[role="gridcell"]',ind).each( function(i) {
  9801. nm = cm[i].name;
  9802. var treeg = $t.p.treeGrid===true && nm === $t.p.ExpandColumn;
  9803. if(treeg) { tmp = $("span:first",this).html();}
  9804. else {
  9805. try {
  9806. tmp = $.unformat.call($t,this,{rowId:rowid, colModel:cm[i]},i);
  9807. } catch (_) {
  9808. tmp = ( cm[i].edittype && cm[i].edittype === 'textarea' ) ? $(this).text() : $(this).html();
  9809. }
  9810. }
  9811. if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn') {
  9812. if($t.p.autoencode) { tmp = $.jgrid.htmlDecode(tmp); }
  9813. svr[nm]=tmp;
  9814. if(cm[i].editable===true) {
  9815. if(focus===null) { focus = i; }
  9816. if (treeg) { $("span:first",this).html(""); }
  9817. else { $(this).html(""); }
  9818. var opt = $.extend({},cm[i].editoptions || {},{id:rowid+"_"+nm,name:nm,rowId:rowid});
  9819. if(!cm[i].edittype) { cm[i].edittype = "text"; }
  9820. if(tmp === "&nbsp;" || tmp === "&#160;" || (tmp.length===1 && tmp.charCodeAt(0)===160) ) {tmp='';}
  9821. var elc = $.jgrid.createEl.call($t,cm[i].edittype,opt,tmp,true,$.extend({},$.jgrid.ajaxOptions,$t.p.ajaxSelectOptions || {}));
  9822. if("select"==$(elc).attr("role")){
  9823. var elem1 = document.createElement("INPUT");
  9824. elem1.setAttribute("type","hidden");
  9825. elem1.setAttribute("name",opt.name);
  9826. elem1.setAttribute("id",$(elc).attr("id"));
  9827. elem1.setAttribute("value",tmp);
  9828. $(this).append(elem1);
  9829. var text=$("div.gltcombox-item[value=" + tmp + "]",'#'+$(this).attr("aria-describedby")+"_combox").attr("text");
  9830. if(text=="")text=tmp;
  9831. $(elc).attr("value",text);
  9832. $(elc).attr("name",opt.name+"_filter");
  9833. $(elc).attr("id",$(elc).attr("id")+"_filter");
  9834. }
  9835. $(elc).addClass("editable");
  9836. if(treeg) { $("span:first",this).append(elc); }
  9837. else { $(this).append(elc); }
  9838. $.jgrid.bindEv.call($t, elc, opt);
  9839. //Again IE
  9840. if(cm[i].edittype === "select" && cm[i].editoptions!==undefined && cm[i].editoptions.multiple===true && cm[i].editoptions.dataUrl===undefined && $.jgrid.msie) {
  9841. $(elc).width($(elc).width());
  9842. }
  9843. cnt++;
  9844. }
  9845. }
  9846. });
  9847. if(cnt > 0) {
  9848. svr.id = rowid; $t.p.savedRow.push(svr);
  9849. $(ind).attr("editable","1");
  9850. if(o.focusField ) {
  9851. if(typeof o.focusField === 'number' && parseInt(o.focusField,10) <= cm.length) {
  9852. focus = o.focusField;
  9853. }
  9854. setTimeout(function(){
  9855. var fe = $("td:eq("+focus+") input",ind).not(":disabled");
  9856. if(fe.length > 0) {
  9857. fe.focus();
  9858. }
  9859. },0);
  9860. }
  9861. if(o.keys===true) {
  9862. $(ind).bind("keydown",function(e) {
  9863. if (e.keyCode === 27) {
  9864. $($t).jqGrid("restoreRow",rowid, o.afterrestorefunc);
  9865. if($t.p._inlinenav) {
  9866. try {
  9867. $($t).jqGrid('showAddEditButtons');
  9868. } catch (eer1) {}
  9869. }
  9870. return false;
  9871. }
  9872. if (e.keyCode === 13) {
  9873. var ta = e.target;
  9874. if(ta.tagName === 'TEXTAREA') { return true; }
  9875. if( $($t).jqGrid("saveRow", rowid, o ) ) {
  9876. if($t.p._inlinenav) {
  9877. try {
  9878. $($t).jqGrid('showAddEditButtons');
  9879. } catch (eer2) {}
  9880. }
  9881. }
  9882. return false;
  9883. }
  9884. });
  9885. }
  9886. $($t).triggerHandler("jqGridInlineEditRow", [rowid, o]);
  9887. if( $.isFunction(o.oneditfunc)) { o.oneditfunc.call($t, rowid); }
  9888. }
  9889. }
  9890. });
  9891. },
  9892. saveRow : function(rowid, successfunc, url, extraparam, aftersavefunc,errorfunc, afterrestorefunc) {
  9893. // Compatible mode old versions
  9894. var args = $.makeArray(arguments).slice(1), o = {};
  9895. if( $.type(args[0]) === "object" ) {
  9896. o = args[0];
  9897. } else {
  9898. if ($.isFunction(successfunc)) { o.successfunc = successfunc; }
  9899. if (url !== undefined) { o.url = url; }
  9900. if (extraparam !== undefined) { o.extraparam = extraparam; }
  9901. if ($.isFunction(aftersavefunc)) { o.aftersavefunc = aftersavefunc; }
  9902. if ($.isFunction(errorfunc)) { o.errorfunc = errorfunc; }
  9903. if ($.isFunction(afterrestorefunc)) { o.afterrestorefunc = afterrestorefunc; }
  9904. }
  9905. o = $.extend(true, {
  9906. successfunc: null,
  9907. url: null,
  9908. extraparam: {},
  9909. aftersavefunc: null,
  9910. errorfunc: null,
  9911. afterrestorefunc: null,
  9912. restoreAfterError: true,
  9913. mtype: "POST"
  9914. }, $.jgrid.inlineEdit, o );
  9915. // End compatible
  9916. var success = false;
  9917. var $t = this[0], nm, tmp={}, tmp2={}, tmp3= {}, editable, fr, cv, ind;
  9918. if (!$t.grid ) { return success; }
  9919. ind = $($t).jqGrid("getInd",rowid,true);
  9920. if(ind === false) {return success;}
  9921. var bfsr = $.isFunction( o.beforeSaveRow ) ? o.beforeSaveRow.call($t,o, rowid) : undefined;
  9922. if( bfsr === undefined ) {
  9923. bfsr = true;
  9924. }
  9925. if(!bfsr) { return; }
  9926. editable = $(ind).attr("editable");
  9927. o.url = o.url || $t.p.editurl;
  9928. if (editable==="1") {
  9929. var cm;
  9930. $('td[role="gridcell"]',ind).each(function(i) {
  9931. cm = $t.p.colModel[i];
  9932. nm = cm.name;
  9933. if ( nm !== 'cb' && nm !== 'subgrid' && cm.editable===true && nm !== 'rn' && !$(this).hasClass('not-editable-cell')) {
  9934. //alert("--cm.edittype--"+cm.edittype);
  9935. switch (cm.edittype) {
  9936. case "checkbox":
  9937. var cbv = ["Yes","No"];
  9938. if(cm.editoptions ) {
  9939. cbv = cm.editoptions.value.split(":");
  9940. }
  9941. tmp[nm]= $("input",this).is(":checked") ? cbv[0] : cbv[1];
  9942. break;
  9943. case 'text':
  9944. case 'password':
  9945. case 'textarea':
  9946. case "button" :
  9947. tmp[nm]=$("input, textarea",this).val();
  9948. break;
  9949. case 'select':
  9950. if(!cm.editoptions.multiple) {
  9951. tmp[nm]=$("input",this).val();
  9952. } else {
  9953. tmp[nm]=$("input",this).val();
  9954. }
  9955. if(cm.formatter && cm.formatter === 'select') { tmp2={}; }
  9956. break;
  9957. case 'select2':
  9958. if(!cm.editoptions.multiple) {
  9959. tmp[nm] = $("select option:selected",this).val();
  9960. tmp2[nm] = $("select option:selected", this).text();
  9961. } else {
  9962. var sel = $("select",this), selectedText = [];
  9963. tmp[nm] = $(sel).val();
  9964. if(tmp[nm]) { tmp[nm]= tmp[nm].join(","); } else { tmp[nm] =""; }
  9965. $("select option:selected",this).each(
  9966. function(i,selected){
  9967. selectedText[i] = $(selected).text();
  9968. }
  9969. );
  9970. tmp2[nm] = selectedText.join(",");
  9971. }
  9972. if(cm.formatter && cm.formatter === 'select') { tmp2={}; }
  9973. break;
  9974. case 'custom' :
  9975. try {
  9976. if(cm.editoptions && $.isFunction(cm.editoptions.custom_value)) {
  9977. tmp[nm] = cm.editoptions.custom_value.call($t, $(".customelement",this),'get');
  9978. if (tmp[nm] === undefined) { throw "e2"; }
  9979. } else { throw "e1"; }
  9980. } catch (e) {
  9981. if (e==="e1") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.nodefined,$.jgrid.edit.bClose); }
  9982. if (e==="e2") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose); }
  9983. else { $.jgrid.info_dialog($.jgrid.errors.errcap,e.message,$.jgrid.edit.bClose); }
  9984. }
  9985. break;
  9986. }
  9987. cv = $.jgrid.checkValues.call($t,tmp[nm],i);
  9988. if(cv[0] === false) {
  9989. return false;
  9990. }
  9991. if($t.p.autoencode) { tmp[nm] = $.jgrid.htmlEncode(tmp[nm]); }
  9992. if(o.url !== 'clientArray' && cm.editoptions && cm.editoptions.NullIfEmpty === true) {
  9993. if(tmp[nm] === "") {
  9994. tmp3[nm] = 'null';
  9995. }
  9996. }
  9997. }
  9998. });
  9999. if (cv[0] === false){
  10000. try {
  10001. var tr = $($t).jqGrid('getGridRowById', rowid), positions = $.jgrid.findPos(tr);
  10002. $.jgrid.info_dialog($.jgrid.errors.errcap,cv[1],$.jgrid.edit.bClose,{left:positions[0],top:positions[1]+$(tr).outerHeight()});
  10003. } catch (e) {
  10004. alert(cv[1]);
  10005. }
  10006. return success;
  10007. }
  10008. var idname, opers = $t.p.prmNames, oldRowId = rowid;
  10009. if ($t.p.keyName === false) {
  10010. idname = opers.id;
  10011. } else {
  10012. idname = $t.p.keyName;
  10013. }
  10014. if(tmp) {
  10015. tmp[opers.oper] = opers.editoper;
  10016. if (tmp[idname] === undefined || tmp[idname]==="") {
  10017. tmp[idname] = rowid;
  10018. } else if (ind.id !== $t.p.idPrefix + tmp[idname]) {
  10019. // rename rowid
  10020. var oldid = $.jgrid.stripPref($t.p.idPrefix, rowid);
  10021. if ($t.p._index[oldid] !== undefined) {
  10022. $t.p._index[tmp[idname]] = $t.p._index[oldid];
  10023. delete $t.p._index[oldid];
  10024. }
  10025. rowid = $t.p.idPrefix + tmp[idname];
  10026. $(ind).attr("id", rowid);
  10027. if ($t.p.selrow === oldRowId) {
  10028. $t.p.selrow = rowid;
  10029. }
  10030. if ($.isArray($t.p.selarrrow)) {
  10031. var i = $.inArray(oldRowId, $t.p.selarrrow);
  10032. if (i>=0) {
  10033. $t.p.selarrrow[i] = rowid;
  10034. }
  10035. }
  10036. if ($t.p.multiselect) {
  10037. var newCboxId = "jqg_" + $t.p.id + "_" + rowid;
  10038. $("input.cbox",ind)
  10039. .attr("id", newCboxId)
  10040. .attr("name", newCboxId);
  10041. }
  10042. // TODO: to test the case of frozen columns
  10043. }
  10044. if($t.p.inlineData === undefined) { $t.p.inlineData ={}; }
  10045. tmp = $.extend({},tmp,$t.p.inlineData,o.extraparam);
  10046. }
  10047. if (o.url === 'clientArray') {
  10048. tmp = $.extend({},tmp, tmp2);
  10049. if($t.p.autoencode) {
  10050. $.each(tmp,function(n,v){
  10051. tmp[n] = $.jgrid.htmlDecode(v);
  10052. });
  10053. }
  10054. var k, resp = $($t).jqGrid("setRowData",rowid,tmp);
  10055. $(ind).attr("editable","0");
  10056. for(k=0;k<$t.p.savedRow.length;k++) {
  10057. if( String($t.p.savedRow[k].id) === String(oldRowId)) {fr = k; break;}
  10058. }
  10059. if(fr >= 0) { $t.p.savedRow.splice(fr,1); }
  10060. $($t).triggerHandler("jqGridInlineAfterSaveRow", [rowid, resp, tmp, o]);
  10061. if( $.isFunction(o.aftersavefunc) ) { o.aftersavefunc.call($t, rowid, resp, tmp, o); }
  10062. success = true;
  10063. $(ind).removeClass("jqgrid-new-row").unbind("keydown");
  10064. } else {
  10065. $("#lui_"+$.jgrid.jqID($t.p.id)).show();
  10066. tmp3 = $.extend({},tmp,tmp3);
  10067. tmp3[idname] = $.jgrid.stripPref($t.p.idPrefix, tmp3[idname]);
  10068. $.ajax($.extend({
  10069. url:o.url,
  10070. data: $.isFunction($t.p.serializeRowData) ? $t.p.serializeRowData.call($t, tmp3) : tmp3,
  10071. type: o.mtype,
  10072. async : false, //?!?
  10073. complete: function(res,stat){
  10074. $("#lui_"+$.jgrid.jqID($t.p.id)).hide();
  10075. if (stat === "success"){
  10076. var ret = true, sucret, k;
  10077. sucret = $($t).triggerHandler("jqGridInlineSuccessSaveRow", [res, rowid, o]);
  10078. if (!$.isArray(sucret)) {sucret = [true, tmp];}
  10079. if (sucret[0] && $.isFunction(o.successfunc)) {sucret = o.successfunc.call($t, res);}
  10080. if($.isArray(sucret)) {
  10081. // expect array - status, data, rowid
  10082. ret = sucret[0];
  10083. tmp = sucret[1] || tmp;
  10084. } else {
  10085. ret = sucret;
  10086. }
  10087. if (ret===true) {
  10088. if($t.p.autoencode) {
  10089. $.each(tmp,function(n,v){
  10090. tmp[n] = $.jgrid.htmlDecode(v);
  10091. });
  10092. }
  10093. tmp = $.extend({},tmp, tmp2);
  10094. $($t).jqGrid("setRowData",rowid,tmp);
  10095. $(ind).attr("editable","0");
  10096. for(k=0;k<$t.p.savedRow.length;k++) {
  10097. if( String($t.p.savedRow[k].id) === String(rowid)) {fr = k; break;}
  10098. }
  10099. if(fr >= 0) { $t.p.savedRow.splice(fr,1); }
  10100. $($t).triggerHandler("jqGridInlineAfterSaveRow", [rowid, res, tmp, o]);
  10101. if( $.isFunction(o.aftersavefunc) ) { o.aftersavefunc.call($t, rowid, res, tmp, o); }
  10102. success = true;
  10103. $(ind).removeClass("jqgrid-new-row").unbind("keydown");
  10104. } else {
  10105. $($t).triggerHandler("jqGridInlineErrorSaveRow", [rowid, res, stat, null, o]);
  10106. if($.isFunction(o.errorfunc) ) {
  10107. o.errorfunc.call($t, rowid, res, stat, null);
  10108. }
  10109. if(o.restoreAfterError === true) {
  10110. $($t).jqGrid("restoreRow",rowid, o.afterrestorefunc);
  10111. }
  10112. }
  10113. }
  10114. },
  10115. error:function(res,stat,err){
  10116. $("#lui_"+$.jgrid.jqID($t.p.id)).hide();
  10117. $($t).triggerHandler("jqGridInlineErrorSaveRow", [rowid, res, stat, err, o]);
  10118. if($.isFunction(o.errorfunc) ) {
  10119. o.errorfunc.call($t, rowid, res, stat, err);
  10120. } else {
  10121. var rT = res.responseText || res.statusText;
  10122. try {
  10123. $.jgrid.info_dialog($.jgrid.errors.errcap,'<div class="ui-state-error">'+ rT +'</div>', $.jgrid.edit.bClose,{buttonalign:'right'});
  10124. } catch(e) {
  10125. alert(rT);
  10126. }
  10127. }
  10128. if(o.restoreAfterError === true) {
  10129. $($t).jqGrid("restoreRow",rowid, o.afterrestorefunc);
  10130. }
  10131. }
  10132. }, $.jgrid.ajaxOptions, $t.p.ajaxRowOptions || {}));
  10133. }
  10134. }
  10135. return success;
  10136. },
  10137. restoreRow : function(rowid, afterrestorefunc) {
  10138. // Compatible mode old versions
  10139. var args = $.makeArray(arguments).slice(1), o={};
  10140. if( $.type(args[0]) === "object" ) {
  10141. o = args[0];
  10142. } else {
  10143. if ($.isFunction(afterrestorefunc)) { o.afterrestorefunc = afterrestorefunc; }
  10144. }
  10145. o = $.extend(true, {}, $.jgrid.inlineEdit, o );
  10146. // End compatible
  10147. return this.each(function(){
  10148. var $t= this, fr=-1, ind, ares={}, k;
  10149. if (!$t.grid ) { return; }
  10150. ind = $($t).jqGrid("getInd",rowid,true);
  10151. if(ind === false) {return;}
  10152. var bfcr = $.isFunction( o.beforeCancelRow ) ? o.beforeCancelRow.call($t, o, sr) : undefined;
  10153. if( bfcr === undefined ) {
  10154. bfcr = true;
  10155. }
  10156. if(!bfcr) { return; }
  10157. for(k=0;k<$t.p.savedRow.length;k++) {
  10158. if( String($t.p.savedRow[k].id) === String(rowid)) {fr = k; break;}
  10159. }
  10160. if(fr >= 0) {
  10161. if($.isFunction($.fn.datepicker)) {
  10162. try {
  10163. $("input.hasDatepicker","#"+$.jgrid.jqID(ind.id)).datepicker('hide');
  10164. } catch (e) {}
  10165. }
  10166. $.each($t.p.colModel, function(){
  10167. if(this.editable === true && $t.p.savedRow[fr].hasOwnProperty(this.name)) {
  10168. ares[this.name] = $t.p.savedRow[fr][this.name];
  10169. }
  10170. });
  10171. $($t).jqGrid("setRowData",rowid,ares);
  10172. $(ind).attr("editable","0").unbind("keydown");
  10173. $t.p.savedRow.splice(fr,1);
  10174. if($("#"+$.jgrid.jqID(rowid), "#"+$.jgrid.jqID($t.p.id)).hasClass("jqgrid-new-row")){
  10175. setTimeout(function(){
  10176. $($t).jqGrid("delRowData",rowid);
  10177. $($t).jqGrid('showAddEditButtons');
  10178. },0);
  10179. }
  10180. }
  10181. $($t).triggerHandler("jqGridInlineAfterRestoreRow", [rowid]);
  10182. if ($.isFunction(o.afterrestorefunc))
  10183. {
  10184. o.afterrestorefunc.call($t, rowid);
  10185. }
  10186. });
  10187. },
  10188. addRow : function ( p ) {
  10189. p = $.extend(true, {
  10190. rowID : null,
  10191. initdata : {},
  10192. position :"first",
  10193. useDefValues : true,
  10194. useFormatter : false,
  10195. addRowParams : {extraparam:{}}
  10196. },p || {});
  10197. return this.each(function(){
  10198. if (!this.grid ) { return; }
  10199. var $t = this;
  10200. var bfar = $.isFunction( p.beforeAddRow ) ? p.beforeAddRow.call($t,p.addRowParams) : undefined;
  10201. if( bfar === undefined ) {
  10202. bfar = true;
  10203. }
  10204. if(!bfar) { return; }
  10205. p.rowID = $.isFunction(p.rowID) ? p.rowID.call($t, p) : ( (p.rowID != null) ? p.rowID : $.jgrid.randId());
  10206. if(p.useDefValues === true) {
  10207. $($t.p.colModel).each(function(){
  10208. if( this.editoptions && this.editoptions.defaultValue ) {
  10209. var opt = this.editoptions.defaultValue,
  10210. tmp = $.isFunction(opt) ? opt.call($t) : opt;
  10211. p.initdata[this.name] = tmp;
  10212. }
  10213. });
  10214. }
  10215. $($t).jqGrid('addRowData', p.rowID, p.initdata, p.position);
  10216. p.rowID = $t.p.idPrefix + p.rowID;
  10217. $("#"+$.jgrid.jqID(p.rowID), "#"+$.jgrid.jqID($t.p.id)).addClass("jqgrid-new-row");
  10218. if(p.useFormatter) {
  10219. $("#"+$.jgrid.jqID(p.rowID)+" .ui-inline-edit", "#"+$.jgrid.jqID($t.p.id)).click();
  10220. } else {
  10221. var opers = $t.p.prmNames,
  10222. oper = opers.oper;
  10223. p.addRowParams.extraparam[oper] = opers.addoper;
  10224. $($t).jqGrid('editRow', p.rowID, p.addRowParams);
  10225. $($t).jqGrid('setSelection', p.rowID);
  10226. }
  10227. });
  10228. },
  10229. inlineNav : function (elem, o) {
  10230. o = $.extend(true,{
  10231. edit: true,
  10232. editicon: "ui-icon-pencil",
  10233. add: true,
  10234. addicon:"ui-icon-plus",
  10235. save: true,
  10236. saveicon:"ui-icon-disk",
  10237. cancel: true,
  10238. cancelicon:"ui-icon-cancel",
  10239. addParams : {addRowParams: {extraparam: {}}},
  10240. editParams : {},
  10241. restoreAfterSelect : true
  10242. }, $.jgrid.nav, o ||{});
  10243. return this.each(function(){
  10244. if (!this.grid ) { return; }
  10245. var $t = this, onSelect, gID = $.jgrid.jqID($t.p.id);
  10246. $t.p._inlinenav = true;
  10247. // detect the formatactions column
  10248. if(o.addParams.useFormatter === true) {
  10249. var cm = $t.p.colModel,i;
  10250. for (i = 0; i<cm.length; i++) {
  10251. if(cm[i].formatter && cm[i].formatter === "actions" ) {
  10252. if(cm[i].formatoptions) {
  10253. var defaults = {
  10254. keys:false,
  10255. onEdit : null,
  10256. onSuccess: null,
  10257. afterSave:null,
  10258. onError: null,
  10259. afterRestore: null,
  10260. extraparam: {},
  10261. url: null
  10262. },
  10263. ap = $.extend( defaults, cm[i].formatoptions );
  10264. o.addParams.addRowParams = {
  10265. "keys" : ap.keys,
  10266. "oneditfunc" : ap.onEdit,
  10267. "successfunc" : ap.onSuccess,
  10268. "url" : ap.url,
  10269. "extraparam" : ap.extraparam,
  10270. "aftersavefunc" : ap.afterSave,
  10271. "errorfunc": ap.onError,
  10272. "afterrestorefunc" : ap.afterRestore
  10273. };
  10274. }
  10275. break;
  10276. }
  10277. }
  10278. }
  10279. if(o.add) {
  10280. $($t).jqGrid('navButtonAdd', elem,{
  10281. caption : o.addtext,
  10282. title : o.addtitle,
  10283. buttonicon : o.addicon,
  10284. id : $t.p.id+"_iladd",
  10285. onClickButton : function () {
  10286. $($t).jqGrid('addRow', o.addParams);
  10287. if(!o.addParams.useFormatter) {
  10288. $("#"+gID+"_ilsave").removeClass('ui-state-disabled');
  10289. $("#"+gID+"_ilcancel").removeClass('ui-state-disabled');
  10290. $("#"+gID+"_iladd").addClass('ui-state-disabled');
  10291. $("#"+gID+"_iledit").addClass('ui-state-disabled');
  10292. }
  10293. }
  10294. });
  10295. }
  10296. if(o.edit) {
  10297. $($t).jqGrid('navButtonAdd', elem,{
  10298. caption : o.edittext,
  10299. title : o.edittitle,
  10300. buttonicon : o.editicon,
  10301. id : $t.p.id+"_iledit",
  10302. onClickButton : function () {
  10303. var sr = $($t).jqGrid('getGridParam','selrow');
  10304. if(sr) {
  10305. $($t).jqGrid('editRow', sr, o.editParams);
  10306. $("#"+gID+"_ilsave").removeClass('ui-state-disabled');
  10307. $("#"+gID+"_ilcancel").removeClass('ui-state-disabled');
  10308. $("#"+gID+"_iladd").addClass('ui-state-disabled');
  10309. $("#"+gID+"_iledit").addClass('ui-state-disabled');
  10310. } else {
  10311. $.jgrid.viewModal("#alertmod",{gbox:"#gbox_"+gID,jqm:true});$("#jqg_alrt").focus();
  10312. }
  10313. }
  10314. });
  10315. }
  10316. if(o.save) {
  10317. $($t).jqGrid('navButtonAdd', elem,{
  10318. caption : o.savetext || '',
  10319. title : o.savetitle || 'Save row',
  10320. buttonicon : o.saveicon,
  10321. id : $t.p.id+"_ilsave",
  10322. onClickButton : function () {
  10323. var sr = $t.p.savedRow[0].id;
  10324. if(sr) {
  10325. var opers = $t.p.prmNames,
  10326. oper = opers.oper, tmpParams = o.editParams;
  10327. if($("#"+$.jgrid.jqID(sr), "#"+gID ).hasClass("jqgrid-new-row")) {
  10328. o.addParams.addRowParams.extraparam[oper] = opers.addoper;
  10329. tmpParams = o.addParams.addRowParams;
  10330. } else {
  10331. if(!o.editParams.extraparam) {
  10332. o.editParams.extraparam = {};
  10333. }
  10334. o.editParams.extraparam[oper] = opers.editoper;
  10335. }
  10336. if( $($t).jqGrid('saveRow', sr, tmpParams) ) {
  10337. $($t).jqGrid('showAddEditButtons');
  10338. }
  10339. } else {
  10340. $.jgrid.viewModal("#alertmod",{gbox:"#gbox_"+gID,jqm:true});$("#jqg_alrt").focus();
  10341. }
  10342. }
  10343. });
  10344. $("#"+gID+"_ilsave").addClass('ui-state-disabled');
  10345. }
  10346. if(o.cancel) {
  10347. $($t).jqGrid('navButtonAdd', elem,{
  10348. caption : o.canceltext || '',
  10349. title : o.canceltitle || 'Cancel row editing',
  10350. buttonicon : o.cancelicon,
  10351. id : $t.p.id+"_ilcancel",
  10352. onClickButton : function () {
  10353. var sr = $t.p.savedRow[0].id, cancelPrm = o.editParams;
  10354. if(sr) {
  10355. if($("#"+$.jgrid.jqID(sr), "#"+gID ).hasClass("jqgrid-new-row")) {
  10356. cancelPrm = o.addParams.addRowParams;
  10357. }
  10358. $($t).jqGrid('restoreRow', sr, cancelPrm);
  10359. $($t).jqGrid('showAddEditButtons');
  10360. } else {
  10361. $.jgrid.viewModal("#alertmod",{gbox:"#gbox_"+gID,jqm:true});$("#jqg_alrt").focus();
  10362. }
  10363. }
  10364. });
  10365. $("#"+gID+"_ilcancel").addClass('ui-state-disabled');
  10366. }
  10367. if(o.restoreAfterSelect === true) {
  10368. if($.isFunction($t.p.beforeSelectRow)) {
  10369. onSelect = $t.p.beforeSelectRow;
  10370. } else {
  10371. onSelect = false;
  10372. }
  10373. $t.p.beforeSelectRow = function(id, stat) {
  10374. var ret = true;
  10375. if($t.p.savedRow.length > 0 && $t.p._inlinenav===true && ( id !== $t.p.selrow && $t.p.selrow !==null) ) {
  10376. if($t.p.selrow === o.addParams.rowID ) {
  10377. $($t).jqGrid('delRowData', $t.p.selrow);
  10378. } else {
  10379. $($t).jqGrid('restoreRow', $t.p.selrow, o.editParams);
  10380. }
  10381. $($t).jqGrid('showAddEditButtons');
  10382. }
  10383. if(onSelect) {
  10384. ret = onSelect.call($t, id, stat);
  10385. }
  10386. return ret;
  10387. };
  10388. }
  10389. });
  10390. },
  10391. showAddEditButtons : function() {
  10392. return this.each(function(){
  10393. if (!this.grid ) { return; }
  10394. var gID = $.jgrid.jqID(this.p.id);
  10395. $("#"+gID+"_ilsave").addClass('ui-state-disabled');
  10396. $("#"+gID+"_ilcancel").addClass('ui-state-disabled');
  10397. $("#"+gID+"_iladd").removeClass('ui-state-disabled');
  10398. $("#"+gID+"_iledit").removeClass('ui-state-disabled');
  10399. });
  10400. }
  10401. //end inline edit
  10402. });
  10403. })(jQuery);
  10404. /*jshint eqeqeq:false */
  10405. /*global jQuery */
  10406. (function($){
  10407. /*
  10408. **
  10409. * jqGrid extension for cellediting Grid Data
  10410. * Tony Tomov tony@trirand.com
  10411. * http://trirand.com/blog/
  10412. * Dual licensed under the MIT and GPL licenses:
  10413. * http://www.opensource.org/licenses/mit-license.php
  10414. * http://www.gnu.org/licenses/gpl-2.0.html
  10415. **/
  10416. /**
  10417. * all events and options here are aded anonynous and not in the base grid
  10418. * since the array is to big. Here is the order of execution.
  10419. * From this point we use jQuery isFunction
  10420. * formatCell
  10421. * beforeEditCell,
  10422. * onSelectCell (used only for noneditable cels)
  10423. * afterEditCell,
  10424. * beforeSaveCell, (called before validation of values if any)
  10425. * beforeSubmitCell (if cellsubmit remote (ajax))
  10426. * afterSubmitCell(if cellsubmit remote (ajax)),
  10427. * afterSaveCell,
  10428. * errorCell,
  10429. * serializeCellData - new
  10430. * Options
  10431. * cellsubmit (remote,clientArray) (added in grid options)
  10432. * cellurl
  10433. * ajaxCellOptions
  10434. * */
  10435. "use strict";
  10436. $.jgrid.extend({
  10437. editCell : function (iRow,iCol, ed){
  10438. return this.each(function (){
  10439. var $t = this, nm, tmp,cc, cm;
  10440. if (!$t.grid || $t.p.cellEdit !== true) {return;}
  10441. iCol = parseInt(iCol,10);
  10442. // select the row that can be used for other methods
  10443. $t.p.selrow = $t.rows[iRow].id;
  10444. if (!$t.p.knv) {$($t).jqGrid("GridNav");}
  10445. // check to see if we have already edited cell
  10446. if ($t.p.savedRow.length>0) {
  10447. // prevent second click on that field and enable selects
  10448. if (ed===true ) {
  10449. if(iRow == $t.p.iRow && iCol == $t.p.iCol){
  10450. return;
  10451. }
  10452. }
  10453. // save the cell
  10454. $($t).jqGrid("saveCell",$t.p.savedRow[0].id,$t.p.savedRow[0].ic);
  10455. } else {
  10456. window.setTimeout(function () { $("#"+$.jgrid.jqID($t.p.knv)).attr("tabindex","-1").focus();},1);
  10457. }
  10458. cm = $t.p.colModel[iCol];
  10459. nm = cm.name;
  10460. if (nm==='subgrid' || nm==='cb' || nm==='rn') {return;}
  10461. cc = $("td:eq("+iCol+")",$t.rows[iRow]);
  10462. if (cm.editable===true && ed===true && !cc.hasClass("not-editable-cell")) {
  10463. if(parseInt($t.p.iCol,10)>=0 && parseInt($t.p.iRow,10)>=0) {
  10464. $("td:eq("+$t.p.iCol+")",$t.rows[$t.p.iRow]).removeClass("edit-cell ui-state-highlight");
  10465. $($t.rows[$t.p.iRow]).removeClass("selected-row ui-state-hover");
  10466. }
  10467. $(cc).addClass("edit-cell ui-state-highlight");
  10468. $($t.rows[iRow]).addClass("selected-row ui-state-hover");
  10469. try {
  10470. tmp = $.unformat.call($t,cc,{rowId: $t.rows[iRow].id, colModel:cm},iCol);
  10471. } catch (_) {
  10472. tmp = ( cm.edittype && cm.edittype === 'textarea' ) ? $(cc).text() : $(cc).html();
  10473. }
  10474. if($t.p.autoencode) { tmp = $.jgrid.htmlDecode(tmp); }
  10475. if (!cm.edittype) {cm.edittype = "text";}
  10476. $t.p.savedRow.push({id:iRow,ic:iCol,name:nm,v:tmp});
  10477. if(tmp === "&nbsp;" || tmp === "&#160;" || (tmp.length===1 && tmp.charCodeAt(0)===160) ) {tmp='';}
  10478. if($.isFunction($t.p.formatCell)) {
  10479. var tmp2 = $t.p.formatCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
  10480. if(tmp2 !== undefined ) {tmp = tmp2;}
  10481. }
  10482. $($t).triggerHandler("jqGridBeforeEditCell", [$t.rows[iRow].id, nm, tmp, iRow, iCol]);
  10483. if ($.isFunction($t.p.beforeEditCell)) {
  10484. $t.p.beforeEditCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
  10485. }
  10486. var opt = $.extend({}, cm.editoptions || {} ,{id:iRow+"_"+nm,name:nm,rowId: $t.rows[iRow].id});
  10487. var elc = $.jgrid.createEl.call($t,cm.edittype,opt,tmp,true,$.extend({},$.jgrid.ajaxOptions,$t.p.ajaxSelectOptions || {}));
  10488. $(cc).html("").append(elc).attr("tabindex","0");
  10489. $.jgrid.bindEv.call($t, elc, opt);
  10490. window.setTimeout(function () { $(elc).focus();},1);
  10491. $("input, select, textarea",cc).bind("keydown",function(e) {
  10492. if (e.keyCode === 27) {
  10493. if($("input.hasDatepicker",cc).length >0) {
  10494. if( $(".ui-datepicker").is(":hidden") ) { $($t).jqGrid("restoreCell",iRow,iCol); }
  10495. else { $("input.hasDatepicker",cc).datepicker('hide'); }
  10496. } else {
  10497. $($t).jqGrid("restoreCell",iRow,iCol);
  10498. }
  10499. } //ESC
  10500. if (e.keyCode === 13) {
  10501. $($t).jqGrid("saveCell",iRow,iCol);
  10502. // Prevent default action
  10503. return false;
  10504. } //Enter
  10505. if (e.keyCode === 9) {
  10506. if(!$t.grid.hDiv.loading ) {
  10507. if (e.shiftKey) {$($t).jqGrid("prevCell",iRow,iCol);} //Shift TAb
  10508. else {$($t).jqGrid("nextCell",iRow,iCol);} //Tab
  10509. } else {
  10510. return false;
  10511. }
  10512. }
  10513. e.stopPropagation();
  10514. });
  10515. $($t).triggerHandler("jqGridAfterEditCell", [$t.rows[iRow].id, nm, tmp, iRow, iCol]);
  10516. if ($.isFunction($t.p.afterEditCell)) {
  10517. $t.p.afterEditCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
  10518. }
  10519. } else {
  10520. if (parseInt($t.p.iCol,10)>=0 && parseInt($t.p.iRow,10)>=0) {
  10521. $("td:eq("+$t.p.iCol+")",$t.rows[$t.p.iRow]).removeClass("edit-cell ui-state-highlight");
  10522. $($t.rows[$t.p.iRow]).removeClass("selected-row ui-state-hover");
  10523. }
  10524. cc.addClass("edit-cell ui-state-highlight");
  10525. $($t.rows[iRow]).addClass("selected-row ui-state-hover");
  10526. tmp = cc.html().replace(/\&#160\;/ig,'');
  10527. $($t).triggerHandler("jqGridSelectCell", [$t.rows[iRow].id, nm, tmp, iRow, iCol]);
  10528. if ($.isFunction($t.p.onSelectCell)) {
  10529. $t.p.onSelectCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
  10530. }
  10531. }
  10532. $t.p.iCol = iCol; $t.p.iRow = iRow;
  10533. });
  10534. },
  10535. saveCell : function (iRow, iCol){
  10536. return this.each(function(){
  10537. var $t= this, fr;
  10538. if (!$t.grid || $t.p.cellEdit !== true) {return;}
  10539. if ( $t.p.savedRow.length >= 1) {fr = 0;} else {fr=null;}
  10540. if(fr !== null) {
  10541. var cc = $("td:eq("+iCol+")",$t.rows[iRow]),v,v2,
  10542. cm = $t.p.colModel[iCol], nm = cm.name, nmjq = $.jgrid.jqID(nm) ;
  10543. switch (cm.edittype) {
  10544. case "select":
  10545. if(!cm.editoptions.multiple) {
  10546. v = $("#"+iRow+"_"+nmjq+" option:selected",$t.rows[iRow]).val();
  10547. v2 = $("#"+iRow+"_"+nmjq+" option:selected",$t.rows[iRow]).text();
  10548. } else {
  10549. var sel = $("#"+iRow+"_"+nmjq,$t.rows[iRow]), selectedText = [];
  10550. v = $(sel).val();
  10551. if(v) { v.join(",");} else { v=""; }
  10552. $("option:selected",sel).each(
  10553. function(i,selected){
  10554. selectedText[i] = $(selected).text();
  10555. }
  10556. );
  10557. v2 = selectedText.join(",");
  10558. }
  10559. if(cm.formatter) { v2 = v; }
  10560. break;
  10561. case "checkbox":
  10562. var cbv = ["Yes","No"];
  10563. if(cm.editoptions){
  10564. cbv = cm.editoptions.value.split(":");
  10565. }
  10566. v = $("#"+iRow+"_"+nmjq,$t.rows[iRow]).is(":checked") ? cbv[0] : cbv[1];
  10567. v2=v;
  10568. break;
  10569. case "password":
  10570. case "text":
  10571. case "textarea":
  10572. case "button" :
  10573. v = $("#"+iRow+"_"+nmjq,$t.rows[iRow]).val();
  10574. v2=v;
  10575. break;
  10576. case 'custom' :
  10577. try {
  10578. if(cm.editoptions && $.isFunction(cm.editoptions.custom_value)) {
  10579. v = cm.editoptions.custom_value.call($t, $(".customelement",cc),'get');
  10580. if (v===undefined) { throw "e2";} else { v2=v; }
  10581. } else { throw "e1"; }
  10582. } catch (e) {
  10583. if (e==="e1") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.nodefined,$.jgrid.edit.bClose); }
  10584. if (e==="e2") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose); }
  10585. else {$.jgrid.info_dialog($.jgrid.errors.errcap,e.message,$.jgrid.edit.bClose); }
  10586. }
  10587. break;
  10588. }
  10589. // The common approach is if nothing changed do not do anything
  10590. if (v2 !== $t.p.savedRow[fr].v){
  10591. var vvv = $($t).triggerHandler("jqGridBeforeSaveCell", [$t.rows[iRow].id, nm, v, iRow, iCol]);
  10592. if (vvv) {v = vvv; v2=vvv;}
  10593. if ($.isFunction($t.p.beforeSaveCell)) {
  10594. var vv = $t.p.beforeSaveCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
  10595. if (vv) {v = vv; v2=vv;}
  10596. }
  10597. var cv = $.jgrid.checkValues.call($t,v,iCol);
  10598. if(cv[0] === true) {
  10599. var addpost = $($t).triggerHandler("jqGridBeforeSubmitCell", [$t.rows[iRow].id, nm, v, iRow, iCol]) || {};
  10600. if ($.isFunction($t.p.beforeSubmitCell)) {
  10601. addpost = $t.p.beforeSubmitCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
  10602. if (!addpost) {addpost={};}
  10603. }
  10604. if( $("input.hasDatepicker",cc).length >0) { $("input.hasDatepicker",cc).datepicker('hide'); }
  10605. if ($t.p.cellsubmit === 'remote') {
  10606. if ($t.p.cellurl) {
  10607. var postdata = {};
  10608. if($t.p.autoencode) { v = $.jgrid.htmlEncode(v); }
  10609. postdata[nm] = v;
  10610. var idname,oper, opers;
  10611. opers = $t.p.prmNames;
  10612. idname = opers.id;
  10613. oper = opers.oper;
  10614. postdata[idname] = $.jgrid.stripPref($t.p.idPrefix, $t.rows[iRow].id);
  10615. postdata[oper] = opers.editoper;
  10616. postdata = $.extend(addpost,postdata);
  10617. $("#lui_"+$.jgrid.jqID($t.p.id)).show();
  10618. $t.grid.hDiv.loading = true;
  10619. //alert("06");
  10620. $.ajax( $.extend( {
  10621. url: $t.p.cellurl,
  10622. data :$.isFunction($t.p.serializeCellData) ? $t.p.serializeCellData.call($t, postdata) : postdata,
  10623. type: "POST",
  10624. complete: function (result, stat) {
  10625. $("#lui_"+$t.p.id).hide();
  10626. $t.grid.hDiv.loading = false;
  10627. if (stat === 'success') {
  10628. var ret = $($t).triggerHandler("jqGridAfterSubmitCell", [$t, result, postdata.id, nm, v, iRow, iCol]) || [true, ''];
  10629. if (ret[0] === true && $.isFunction($t.p.afterSubmitCell)) {
  10630. ret = $t.p.afterSubmitCell.call($t, result,postdata.id,nm,v,iRow,iCol);
  10631. }
  10632. if(ret[0] === true){
  10633. $(cc).empty();
  10634. $($t).jqGrid("setCell",$t.rows[iRow].id, iCol, v2, false, false, true);
  10635. $(cc).addClass("dirty-cell");
  10636. $($t.rows[iRow]).addClass("edited");
  10637. $($t).triggerHandler("jqGridAfterSaveCell", [$t.rows[iRow].id, nm, v, iRow, iCol]);
  10638. if ($.isFunction($t.p.afterSaveCell)) {
  10639. $t.p.afterSaveCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
  10640. }
  10641. $t.p.savedRow.splice(0,1);
  10642. } else {
  10643. $.jgrid.info_dialog($.jgrid.errors.errcap,ret[1],$.jgrid.edit.bClose);
  10644. $($t).jqGrid("restoreCell",iRow,iCol);
  10645. }
  10646. }
  10647. },
  10648. error:function(res,stat,err) {
  10649. $("#lui_"+$.jgrid.jqID($t.p.id)).hide();
  10650. $t.grid.hDiv.loading = false;
  10651. $($t).triggerHandler("jqGridErrorCell", [res, stat, err]);
  10652. if ($.isFunction($t.p.errorCell)) {
  10653. $t.p.errorCell.call($t, res,stat,err);
  10654. $($t).jqGrid("restoreCell",iRow,iCol);
  10655. } else {
  10656. $.jgrid.info_dialog($.jgrid.errors.errcap,res.status+" : "+res.statusText+"<br/>"+stat,$.jgrid.edit.bClose);
  10657. $($t).jqGrid("restoreCell",iRow,iCol);
  10658. }
  10659. }
  10660. }, $.jgrid.ajaxOptions, $t.p.ajaxCellOptions || {}));
  10661. } else {
  10662. try {
  10663. $.jgrid.info_dialog($.jgrid.errors.errcap,$.jgrid.errors.nourl,$.jgrid.edit.bClose);
  10664. $($t).jqGrid("restoreCell",iRow,iCol);
  10665. } catch (e) {}
  10666. }
  10667. }
  10668. if ($t.p.cellsubmit === 'clientArray') {
  10669. $(cc).empty();
  10670. $($t).jqGrid("setCell",$t.rows[iRow].id,iCol, v2, false, false, true);
  10671. $(cc).addClass("dirty-cell");
  10672. $($t.rows[iRow]).addClass("edited");
  10673. $($t).triggerHandler("jqGridAfterSaveCell", [$t.rows[iRow].id, nm, v, iRow, iCol]);
  10674. if ($.isFunction($t.p.afterSaveCell)) {
  10675. $t.p.afterSaveCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
  10676. }
  10677. $t.p.savedRow.splice(0,1);
  10678. }
  10679. } else {
  10680. try {
  10681. window.setTimeout(function(){$.jgrid.info_dialog($.jgrid.errors.errcap,v+" "+cv[1],$.jgrid.edit.bClose);},100);
  10682. $($t).jqGrid("restoreCell",iRow,iCol);
  10683. } catch (e) {}
  10684. }
  10685. } else {
  10686. $($t).jqGrid("restoreCell",iRow,iCol);
  10687. }
  10688. }
  10689. window.setTimeout(function () { $("#"+$.jgrid.jqID($t.p.knv)).attr("tabindex","-1").focus();},0);
  10690. });
  10691. },
  10692. restoreCell : function(iRow, iCol) {
  10693. return this.each(function(){
  10694. var $t= this, fr;
  10695. if (!$t.grid || $t.p.cellEdit !== true ) {return;}
  10696. if ( $t.p.savedRow.length >= 1) {fr = 0;} else {fr=null;}
  10697. if(fr !== null) {
  10698. var cc = $("td:eq("+iCol+")",$t.rows[iRow]);
  10699. // datepicker fix
  10700. if($.isFunction($.fn.datepicker)) {
  10701. try {
  10702. $("input.hasDatepicker",cc).datepicker('hide');
  10703. } catch (e) {}
  10704. }
  10705. $(cc).empty().attr("tabindex","-1");
  10706. $($t).jqGrid("setCell",$t.rows[iRow].id, iCol, $t.p.savedRow[fr].v, false, false, true);
  10707. $($t).triggerHandler("jqGridAfterRestoreCell", [$t.rows[iRow].id, $t.p.savedRow[fr].v, iRow, iCol]);
  10708. if ($.isFunction($t.p.afterRestoreCell)) {
  10709. $t.p.afterRestoreCell.call($t, $t.rows[iRow].id, $t.p.savedRow[fr].v, iRow, iCol);
  10710. }
  10711. $t.p.savedRow.splice(0,1);
  10712. }
  10713. window.setTimeout(function () { $("#"+$t.p.knv).attr("tabindex","-1").focus();},0);
  10714. });
  10715. },
  10716. nextCell : function (iRow,iCol) {
  10717. return this.each(function (){
  10718. var $t = this, nCol=false, i;
  10719. if (!$t.grid || $t.p.cellEdit !== true) {return;}
  10720. // try to find next editable cell
  10721. for (i=iCol+1; i<$t.p.colModel.length; i++) {
  10722. if ( $t.p.colModel[i].editable ===true) {
  10723. nCol = i; break;
  10724. }
  10725. }
  10726. if(nCol !== false) {
  10727. $($t).jqGrid("editCell",iRow,nCol,true);
  10728. } else {
  10729. if ($t.p.savedRow.length >0) {
  10730. $($t).jqGrid("saveCell",iRow,iCol);
  10731. }
  10732. }
  10733. });
  10734. },
  10735. prevCell : function (iRow,iCol) {
  10736. return this.each(function (){
  10737. var $t = this, nCol=false, i;
  10738. if (!$t.grid || $t.p.cellEdit !== true) {return;}
  10739. // try to find next editable cell
  10740. for (i=iCol-1; i>=0; i--) {
  10741. if ( $t.p.colModel[i].editable ===true) {
  10742. nCol = i; break;
  10743. }
  10744. }
  10745. if(nCol !== false) {
  10746. $($t).jqGrid("editCell",iRow,nCol,true);
  10747. } else {
  10748. if ($t.p.savedRow.length >0) {
  10749. $($t).jqGrid("saveCell",iRow,iCol);
  10750. }
  10751. }
  10752. });
  10753. },
  10754. GridNav : function() {
  10755. return this.each(function () {
  10756. var $t = this;
  10757. if (!$t.grid || $t.p.cellEdit !== true ) {return;}
  10758. // trick to process keydown on non input elements
  10759. $t.p.knv = $t.p.id + "_kn";
  10760. 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>"),
  10761. i, kdir;
  10762. function scrollGrid(iR, iC, tp){
  10763. if (tp.substr(0,1)==='v') {
  10764. var ch = $($t.grid.bDiv)[0].clientHeight,
  10765. st = $($t.grid.bDiv)[0].scrollTop,
  10766. nROT = $t.rows[iR].offsetTop+$t.rows[iR].clientHeight,
  10767. pROT = $t.rows[iR].offsetTop;
  10768. if(tp === 'vd') {
  10769. if(nROT >= ch) {
  10770. $($t.grid.bDiv)[0].scrollTop = $($t.grid.bDiv)[0].scrollTop + $t.rows[iR].clientHeight;
  10771. }
  10772. }
  10773. if(tp === 'vu'){
  10774. if (pROT < st ) {
  10775. $($t.grid.bDiv)[0].scrollTop = $($t.grid.bDiv)[0].scrollTop - $t.rows[iR].clientHeight;
  10776. }
  10777. }
  10778. }
  10779. if(tp==='h') {
  10780. var cw = $($t.grid.bDiv)[0].clientWidth,
  10781. sl = $($t.grid.bDiv)[0].scrollLeft,
  10782. nCOL = $t.rows[iR].cells[iC].offsetLeft+$t.rows[iR].cells[iC].clientWidth,
  10783. pCOL = $t.rows[iR].cells[iC].offsetLeft;
  10784. if(nCOL >= cw+parseInt(sl,10)) {
  10785. $($t.grid.bDiv)[0].scrollLeft = $($t.grid.bDiv)[0].scrollLeft + $t.rows[iR].cells[iC].clientWidth;
  10786. } else if (pCOL < sl) {
  10787. $($t.grid.bDiv)[0].scrollLeft = $($t.grid.bDiv)[0].scrollLeft - $t.rows[iR].cells[iC].clientWidth;
  10788. }
  10789. }
  10790. }
  10791. function findNextVisible(iC,act){
  10792. var ind, i;
  10793. if(act === 'lft') {
  10794. ind = iC+1;
  10795. for (i=iC;i>=0;i--){
  10796. if ($t.p.colModel[i].hidden !== true) {
  10797. ind = i;
  10798. break;
  10799. }
  10800. }
  10801. }
  10802. if(act === 'rgt') {
  10803. ind = iC-1;
  10804. for (i=iC; i<$t.p.colModel.length;i++){
  10805. if ($t.p.colModel[i].hidden !== true) {
  10806. ind = i;
  10807. break;
  10808. }
  10809. }
  10810. }
  10811. return ind;
  10812. }
  10813. $(selection).insertBefore($t.grid.cDiv);
  10814. $("#"+$t.p.knv)
  10815. .focus()
  10816. .keydown(function (e){
  10817. kdir = e.keyCode;
  10818. if($t.p.direction === "rtl") {
  10819. if(kdir===37) { kdir = 39;}
  10820. else if (kdir===39) { kdir = 37; }
  10821. }
  10822. switch (kdir) {
  10823. case 38:
  10824. if ($t.p.iRow-1 >0 ) {
  10825. scrollGrid($t.p.iRow-1,$t.p.iCol,'vu');
  10826. $($t).jqGrid("editCell",$t.p.iRow-1,$t.p.iCol,false);
  10827. }
  10828. break;
  10829. case 40 :
  10830. if ($t.p.iRow+1 <= $t.rows.length-1) {
  10831. scrollGrid($t.p.iRow+1,$t.p.iCol,'vd');
  10832. $($t).jqGrid("editCell",$t.p.iRow+1,$t.p.iCol,false);
  10833. }
  10834. break;
  10835. case 37 :
  10836. if ($t.p.iCol -1 >= 0) {
  10837. i = findNextVisible($t.p.iCol-1,'lft');
  10838. scrollGrid($t.p.iRow, i,'h');
  10839. $($t).jqGrid("editCell",$t.p.iRow, i,false);
  10840. }
  10841. break;
  10842. case 39 :
  10843. if ($t.p.iCol +1 <= $t.p.colModel.length-1) {
  10844. i = findNextVisible($t.p.iCol+1,'rgt');
  10845. scrollGrid($t.p.iRow,i,'h');
  10846. $($t).jqGrid("editCell",$t.p.iRow,i,false);
  10847. }
  10848. break;
  10849. case 13:
  10850. if (parseInt($t.p.iCol,10)>=0 && parseInt($t.p.iRow,10)>=0) {
  10851. $($t).jqGrid("editCell",$t.p.iRow,$t.p.iCol,true);
  10852. }
  10853. break;
  10854. default :
  10855. return true;
  10856. }
  10857. return false;
  10858. });
  10859. });
  10860. },
  10861. getChangedCells : function (mthd) {
  10862. var ret=[];
  10863. if (!mthd) {mthd='all';}
  10864. this.each(function(){
  10865. var $t= this,nm;
  10866. if (!$t.grid || $t.p.cellEdit !== true ) {return;}
  10867. $($t.rows).each(function(j){
  10868. var res = {};
  10869. if ($(this).hasClass("edited")) {
  10870. $('td',this).each( function(i) {
  10871. nm = $t.p.colModel[i].name;
  10872. if ( nm !== 'cb' && nm !== 'subgrid') {
  10873. if (mthd==='dirty') {
  10874. if ($(this).hasClass('dirty-cell')) {
  10875. try {
  10876. res[nm] = $.unformat.call($t,this,{rowId:$t.rows[j].id, colModel:$t.p.colModel[i]},i);
  10877. } catch (e){
  10878. res[nm] = $.jgrid.htmlDecode($(this).html());
  10879. }
  10880. }
  10881. } else {
  10882. try {
  10883. res[nm] = $.unformat.call($t,this,{rowId:$t.rows[j].id,colModel:$t.p.colModel[i]},i);
  10884. } catch (e) {
  10885. res[nm] = $.jgrid.htmlDecode($(this).html());
  10886. }
  10887. }
  10888. }
  10889. });
  10890. res.id = this.id;
  10891. ret.push(res);
  10892. }
  10893. });
  10894. });
  10895. return ret;
  10896. }
  10897. /// end cell editing
  10898. });
  10899. })(jQuery);
  10900. /*jshint eqeqeq:false */
  10901. /*global jQuery */
  10902. (function($){
  10903. /**
  10904. * jqGrid extension for SubGrid Data
  10905. * Tony Tomov tony@trirand.com
  10906. * http://trirand.com/blog/
  10907. * Dual licensed under the MIT and GPL licenses:
  10908. * http://www.opensource.org/licenses/mit-license.php
  10909. * http://www.gnu.org/licenses/gpl-2.0.html
  10910. **/
  10911. "use strict";
  10912. $.jgrid.extend({
  10913. setSubGrid : function () {
  10914. return this.each(function (){
  10915. var $t = this, cm, i,
  10916. suboptions = {
  10917. plusicon : "ui-icon-plus",
  10918. minusicon : "ui-icon-minus",
  10919. openicon: "ui-icon-carat-1-sw",
  10920. expandOnLoad: false,
  10921. delayOnLoad : 50,
  10922. selectOnExpand : false,
  10923. selectOnCollapse : false,
  10924. reloadOnExpand : true
  10925. };
  10926. $t.p.subGridOptions = $.extend(suboptions, $t.p.subGridOptions || {});
  10927. $t.p.colNames.unshift("");
  10928. $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});
  10929. cm = $t.p.subGridModel;
  10930. if(cm[0]) {
  10931. cm[0].align = $.extend([],cm[0].align || []);
  10932. for(i=0;i<cm[0].name.length;i++) { cm[0].align[i] = cm[0].align[i] || 'left';}
  10933. }
  10934. });
  10935. },
  10936. addSubGridCell :function (pos,iRow) {
  10937. var prp='',ic,sid;
  10938. this.each(function(){
  10939. prp = this.formatCol(pos,iRow);
  10940. sid= this.p.id;
  10941. ic = this.p.subGridOptions.plusicon;
  10942. });
  10943. 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>";
  10944. },
  10945. addSubGrid : function( pos, sind ) {
  10946. return this.each(function(){
  10947. var ts = this;
  10948. if (!ts.grid ) { return; }
  10949. //-------------------------
  10950. var subGridCell = function(trdiv,cell,pos)
  10951. {
  10952. var tddiv = $("<td align='"+ts.p.subGridModel[0].align[pos]+"'></td>").html(cell);
  10953. $(trdiv).append(tddiv);
  10954. };
  10955. var subGridXml = function(sjxml, sbid){
  10956. var tddiv, i, sgmap,
  10957. dummy = $("<table cellspacing='0' cellpadding='0' border='0'><tbody></tbody></table>"),
  10958. trdiv = $("<tr></tr>");
  10959. for (i = 0; i<ts.p.subGridModel[0].name.length; i++) {
  10960. tddiv = $("<th class='ui-state-default ui-th-subgrid ui-th-column ui-th-"+ts.p.direction+"'></th>");
  10961. $(tddiv).html(ts.p.subGridModel[0].name[i]);
  10962. $(tddiv).width( ts.p.subGridModel[0].width[i]);
  10963. $(trdiv).append(tddiv);
  10964. }
  10965. $(dummy).append(trdiv);
  10966. if (sjxml){
  10967. sgmap = ts.p.xmlReader.subgrid;
  10968. $(sgmap.root+" "+sgmap.row, sjxml).each( function(){
  10969. trdiv = $("<tr class='ui-widget-content ui-subtblcell'></tr>");
  10970. if(sgmap.repeatitems === true) {
  10971. $(sgmap.cell,this).each( function(i) {
  10972. subGridCell(trdiv, $(this).text() || '&#160;',i);
  10973. });
  10974. } else {
  10975. var f = ts.p.subGridModel[0].mapping || ts.p.subGridModel[0].name;
  10976. if (f) {
  10977. for (i=0;i<f.length;i++) {
  10978. subGridCell(trdiv, $(f[i],this).text() || '&#160;',i);
  10979. }
  10980. }
  10981. }
  10982. $(dummy).append(trdiv);
  10983. });
  10984. }
  10985. var pID = $("table:first",ts.grid.bDiv).attr("id")+"_";
  10986. $("#"+$.jgrid.jqID(pID+sbid)).append(dummy);
  10987. ts.grid.hDiv.loading = false;
  10988. $("#load_"+$.jgrid.jqID(ts.p.id)).hide();
  10989. return false;
  10990. };
  10991. var subGridJson = function(sjxml, sbid){
  10992. var tddiv,result,i,cur, sgmap,j,
  10993. dummy = $("<table cellspacing='0' cellpadding='0' border='0'><tbody></tbody></table>"),
  10994. trdiv = $("<tr></tr>");
  10995. for (i = 0; i<ts.p.subGridModel[0].name.length; i++) {
  10996. tddiv = $("<th class='ui-state-default ui-th-subgrid ui-th-column ui-th-"+ts.p.direction+"'></th>");
  10997. $(tddiv).html(ts.p.subGridModel[0].name[i]);
  10998. $(tddiv).width( ts.p.subGridModel[0].width[i]);
  10999. $(trdiv).append(tddiv);
  11000. }
  11001. $(dummy).append(trdiv);
  11002. if (sjxml){
  11003. sgmap = ts.p.jsonReader.subgrid;
  11004. result = $.jgrid.getAccessor(sjxml, sgmap.root);
  11005. if ( result !== undefined ) {
  11006. for (i=0;i<result.length;i++) {
  11007. cur = result[i];
  11008. trdiv = $("<tr class='ui-widget-content ui-subtblcell'></tr>");
  11009. if(sgmap.repeatitems === true) {
  11010. if(sgmap.cell) { cur=cur[sgmap.cell]; }
  11011. for (j=0;j<cur.length;j++) {
  11012. subGridCell(trdiv, cur[j] || '&#160;',j);
  11013. }
  11014. } else {
  11015. var f = ts.p.subGridModel[0].mapping || ts.p.subGridModel[0].name;
  11016. if(f.length) {
  11017. for (j=0;j<f.length;j++) {
  11018. subGridCell(trdiv, cur[f[j]] || '&#160;',j);
  11019. }
  11020. }
  11021. }
  11022. $(dummy).append(trdiv);
  11023. }
  11024. }
  11025. }
  11026. var pID = $("table:first",ts.grid.bDiv).attr("id")+"_";
  11027. $("#"+$.jgrid.jqID(pID+sbid)).append(dummy);
  11028. ts.grid.hDiv.loading = false;
  11029. $("#load_"+$.jgrid.jqID(ts.p.id)).hide();
  11030. return false;
  11031. };
  11032. var populatesubgrid = function( rd )
  11033. {
  11034. var sid,dp, i, j;
  11035. sid = $(rd).attr("id");
  11036. dp = {nd_: (new Date().getTime())};
  11037. dp[ts.p.prmNames.subgridid]=sid;
  11038. if(!ts.p.subGridModel[0]) { return false; }
  11039. if(ts.p.subGridModel[0].params) {
  11040. for(j=0; j < ts.p.subGridModel[0].params.length; j++) {
  11041. for(i=0; i<ts.p.colModel.length; i++) {
  11042. if(ts.p.colModel[i].name === ts.p.subGridModel[0].params[j]) {
  11043. dp[ts.p.colModel[i].name]= $("td:eq("+i+")",rd).text().replace(/\&#160\;/ig,'');
  11044. }
  11045. }
  11046. }
  11047. }
  11048. if(!ts.grid.hDiv.loading) {
  11049. ts.grid.hDiv.loading = true;
  11050. $("#load_"+$.jgrid.jqID(ts.p.id)).show();
  11051. if(!ts.p.subgridtype) { ts.p.subgridtype = ts.p.datatype; }
  11052. if($.isFunction(ts.p.subgridtype)) {
  11053. ts.p.subgridtype.call(ts, dp);
  11054. } else {
  11055. ts.p.subgridtype = ts.p.subgridtype.toLowerCase();
  11056. }
  11057. switch(ts.p.subgridtype) {
  11058. case "xml":
  11059. case "json":
  11060. //alert("07");
  11061. $.ajax($.extend({
  11062. type:ts.p.mtype,
  11063. url: ts.p.subGridUrl,
  11064. dataType:ts.p.subgridtype,
  11065. data: $.isFunction(ts.p.serializeSubGridData)? ts.p.serializeSubGridData.call(ts, dp) : dp,
  11066. complete: function(sxml) {
  11067. if(ts.p.subgridtype === "xml") {
  11068. subGridXml(sxml.responseXML, sid);
  11069. } else {
  11070. subGridJson($.jgrid.parse(sxml.responseText),sid);
  11071. }
  11072. sxml=null;
  11073. }
  11074. }, $.jgrid.ajaxOptions, ts.p.ajaxSubgridOptions || {}));
  11075. break;
  11076. }
  11077. }
  11078. return false;
  11079. };
  11080. var _id, pID,atd, nhc=0, bfsc, r;
  11081. $.each(ts.p.colModel,function(){
  11082. if(this.hidden === true || this.name === 'rn' || this.name === 'cb') {
  11083. nhc++;
  11084. }
  11085. });
  11086. var len = ts.rows.length, i=1;
  11087. if( sind !== undefined && sind > 0) {
  11088. i = sind;
  11089. len = sind+1;
  11090. }
  11091. while(i < len) {
  11092. if($(ts.rows[i]).hasClass('jqgrow')) {
  11093. if(ts.p.scroll) {
  11094. $(ts.rows[i].cells[pos]).unbind('click');
  11095. }
  11096. $(ts.rows[i].cells[pos]).bind('click', function() {
  11097. var tr = $(this).parent("tr")[0];
  11098. r = tr.nextSibling;
  11099. if($(this).hasClass("sgcollapsed")) {
  11100. pID = ts.p.id;
  11101. _id = tr.id;
  11102. if(ts.p.subGridOptions.reloadOnExpand === true || ( ts.p.subGridOptions.reloadOnExpand === false && !$(r).hasClass('ui-subgrid') ) ) {
  11103. atd = pos >=1 ? "<td colspan='"+pos+"'>&#160;</td>":"";
  11104. bfsc = $(ts).triggerHandler("jqGridSubGridBeforeExpand", [pID + "_" + _id, _id]);
  11105. bfsc = (bfsc === false || bfsc === 'stop') ? false : true;
  11106. if(bfsc && $.isFunction(ts.p.subGridBeforeExpand)) {
  11107. bfsc = ts.p.subGridBeforeExpand.call(ts, pID+"_"+_id,_id);
  11108. }
  11109. if(bfsc === false) {return false;}
  11110. $(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>" );
  11111. $(ts).triggerHandler("jqGridSubGridRowExpanded", [pID + "_" + _id, _id]);
  11112. if( $.isFunction(ts.p.subGridRowExpanded)) {
  11113. ts.p.subGridRowExpanded.call(ts, pID+"_"+ _id,_id);
  11114. } else {
  11115. populatesubgrid(tr);
  11116. }
  11117. } else {
  11118. $(r).show();
  11119. }
  11120. $(this).html("<a style='cursor:pointer;'><span class='ui-icon "+ts.p.subGridOptions.minusicon+"'></span></a>").removeClass("sgcollapsed").addClass("sgexpanded");
  11121. if(ts.p.subGridOptions.selectOnExpand) {
  11122. $(ts).jqGrid('setSelection',_id);
  11123. }
  11124. } else if($(this).hasClass("sgexpanded")) {
  11125. bfsc = $(ts).triggerHandler("jqGridSubGridRowColapsed", [pID + "_" + _id, _id]);
  11126. bfsc = (bfsc === false || bfsc === 'stop') ? false : true;
  11127. _id = tr.id;
  11128. if( bfsc && $.isFunction(ts.p.subGridRowColapsed)) {
  11129. bfsc = ts.p.subGridRowColapsed.call(ts, pID+"_"+_id,_id );
  11130. }
  11131. if(bfsc===false) {return false;}
  11132. if(ts.p.subGridOptions.reloadOnExpand === true) {
  11133. $(r).remove(".ui-subgrid");
  11134. } else if($(r).hasClass('ui-subgrid')) { // incase of dynamic deleting
  11135. $(r).hide();
  11136. }
  11137. $(this).html("<a style='cursor:pointer;'><span class='ui-icon "+ts.p.subGridOptions.plusicon+"'></span></a>").removeClass("sgexpanded").addClass("sgcollapsed");
  11138. if(ts.p.subGridOptions.selectOnCollapse) {
  11139. $(ts).jqGrid('setSelection',_id);
  11140. }
  11141. }
  11142. return false;
  11143. });
  11144. }
  11145. i++;
  11146. }
  11147. if(ts.p.subGridOptions.expandOnLoad === true) {
  11148. $(ts.rows).filter('.jqgrow').each(function(index,row){
  11149. $(row.cells[0]).click();
  11150. });
  11151. }
  11152. ts.subGridXml = function(xml,sid) {subGridXml(xml,sid);};
  11153. ts.subGridJson = function(json,sid) {subGridJson(json,sid);};
  11154. });
  11155. },
  11156. expandSubGridRow : function(rowid) {
  11157. return this.each(function () {
  11158. var $t = this;
  11159. if(!$t.grid && !rowid) {return;}
  11160. if($t.p.subGrid===true) {
  11161. var rc = $(this).jqGrid("getInd",rowid,true);
  11162. if(rc) {
  11163. var sgc = $("td.sgcollapsed",rc)[0];
  11164. if(sgc) {
  11165. $(sgc).trigger("click");
  11166. }
  11167. }
  11168. }
  11169. });
  11170. },
  11171. collapseSubGridRow : function(rowid) {
  11172. return this.each(function () {
  11173. var $t = this;
  11174. if(!$t.grid && !rowid) {return;}
  11175. if($t.p.subGrid===true) {
  11176. var rc = $(this).jqGrid("getInd",rowid,true);
  11177. if(rc) {
  11178. var sgc = $("td.sgexpanded",rc)[0];
  11179. if(sgc) {
  11180. $(sgc).trigger("click");
  11181. }
  11182. }
  11183. }
  11184. });
  11185. },
  11186. toggleSubGridRow : function(rowid) {
  11187. return this.each(function () {
  11188. var $t = this;
  11189. if(!$t.grid && !rowid) {return;}
  11190. if($t.p.subGrid===true) {
  11191. var rc = $(this).jqGrid("getInd",rowid,true);
  11192. if(rc) {
  11193. var sgc = $("td.sgcollapsed",rc)[0];
  11194. if(sgc) {
  11195. $(sgc).trigger("click");
  11196. } else {
  11197. sgc = $("td.sgexpanded",rc)[0];
  11198. if(sgc) {
  11199. $(sgc).trigger("click");
  11200. }
  11201. }
  11202. }
  11203. }
  11204. });
  11205. }
  11206. });
  11207. })(jQuery);
  11208. /**
  11209. * jqGrid extension - Tree Grid
  11210. * Tony Tomov tony@trirand.com
  11211. * http://trirand.com/blog/
  11212. * Dual licensed under the MIT and GPL licenses:
  11213. * http://www.opensource.org/licenses/mit-license.php
  11214. * http://www.gnu.org/licenses/gpl.html
  11215. **/
  11216. /*jshint eqeqeq:false */
  11217. /*global jQuery */
  11218. (function($) {
  11219. "use strict";
  11220. $.jgrid.extend({
  11221. setTreeNode : function(i, len){
  11222. return this.each(function(){
  11223. var $t = this;
  11224. if( !$t.grid || !$t.p.treeGrid ) {return;}
  11225. var expCol = $t.p.expColInd,
  11226. expanded = $t.p.treeReader.expanded_field,
  11227. isLeaf = $t.p.treeReader.leaf_field,
  11228. level = $t.p.treeReader.level_field,
  11229. icon = $t.p.treeReader.icon_field,
  11230. loaded = $t.p.treeReader.loaded, lft, rgt, curLevel, ident,lftpos, twrap,
  11231. ldat, lf;
  11232. while(i<len) {
  11233. var ind = $.jgrid.stripPref($t.p.idPrefix, $t.rows[i].id), dind = $t.p._index[ind], expan;
  11234. ldat = $t.p.data[dind];
  11235. //$t.rows[i].level = ldat[level];
  11236. if($t.p.treeGridModel === 'nested') {
  11237. if(!ldat[isLeaf]) {
  11238. lft = parseInt(ldat[$t.p.treeReader.left_field],10);
  11239. rgt = parseInt(ldat[$t.p.treeReader.right_field],10);
  11240. // NS Model
  11241. ldat[isLeaf] = (rgt === lft+1) ? 'true' : 'false';
  11242. $t.rows[i].cells[$t.p._treeleafpos].innerHTML = ldat[isLeaf];
  11243. }
  11244. }
  11245. //else {
  11246. //row.parent_id = rd[$t.p.treeReader.parent_id_field];
  11247. //}
  11248. curLevel = parseInt(ldat[level],10);
  11249. if($t.p.tree_root_level === 0) {
  11250. ident = curLevel+1;
  11251. lftpos = curLevel;
  11252. } else {
  11253. ident = curLevel;
  11254. lftpos = curLevel -1;
  11255. }
  11256. twrap = "<div class='tree-wrap tree-wrap-"+$t.p.direction+"' style='width:"+(ident*18)+"px;'>";
  11257. twrap += "<div style='"+($t.p.direction==="rtl" ? "right:" : "left:")+(lftpos*18)+"px;' class='ui-icon ";
  11258. if(ldat[loaded] !== undefined) {
  11259. if(ldat[loaded]==="true" || ldat[loaded]===true) {
  11260. ldat[loaded] = true;
  11261. } else {
  11262. ldat[loaded] = false;
  11263. }
  11264. }
  11265. if(ldat[isLeaf] === "true" || ldat[isLeaf] === true) {
  11266. twrap += ((ldat[icon] !== undefined && ldat[icon] !== "") ? ldat[icon] : $t.p.treeIcons.leaf)+" tree-leaf treeclick";
  11267. ldat[isLeaf] = true;
  11268. lf="leaf";
  11269. } else {
  11270. ldat[isLeaf] = false;
  11271. lf="";
  11272. }
  11273. ldat[expanded] = ((ldat[expanded] === "true" || ldat[expanded] === true) ? true : false) && (ldat[loaded] || ldat[loaded] === undefined);
  11274. if(ldat[expanded] === false) {
  11275. twrap += ((ldat[isLeaf] === true) ? "'" : $t.p.treeIcons.plus+" tree-plus treeclick'");
  11276. } else {
  11277. twrap += ((ldat[isLeaf] === true) ? "'" : $t.p.treeIcons.minus+" tree-minus treeclick'");
  11278. }
  11279. twrap += "></div></div>";
  11280. $($t.rows[i].cells[expCol]).wrapInner("<span class='cell-wrapper"+lf+"'></span>").prepend(twrap);
  11281. if(curLevel !== parseInt($t.p.tree_root_level,10)) {
  11282. var pn = $($t).jqGrid('getNodeParent',ldat);
  11283. expan = pn && pn.hasOwnProperty(expanded) ? pn[expanded] : true;
  11284. if( !expan ){
  11285. $($t.rows[i]).css("display","none");
  11286. }
  11287. }
  11288. $($t.rows[i].cells[expCol])
  11289. .find("div.treeclick")
  11290. .bind("click",function(e){
  11291. var target = e.target || e.srcElement,
  11292. ind2 =$.jgrid.stripPref($t.p.idPrefix,$(target,$t.rows).closest("tr.jqgrow")[0].id),
  11293. pos = $t.p._index[ind2];
  11294. if(!$t.p.data[pos][isLeaf]){
  11295. if($t.p.data[pos][expanded]){
  11296. $($t).jqGrid("collapseRow",$t.p.data[pos]);
  11297. $($t).jqGrid("collapseNode",$t.p.data[pos]);
  11298. } else {
  11299. $($t).jqGrid("expandRow",$t.p.data[pos]);
  11300. $($t).jqGrid("expandNode",$t.p.data[pos]);
  11301. }
  11302. }
  11303. return false;
  11304. });
  11305. if($t.p.ExpandColClick === true) {
  11306. $($t.rows[i].cells[expCol])
  11307. .find("span.cell-wrapper")
  11308. .css("cursor","pointer")
  11309. .bind("click",function(e) {
  11310. var target = e.target || e.srcElement,
  11311. ind2 =$.jgrid.stripPref($t.p.idPrefix,$(target,$t.rows).closest("tr.jqgrow")[0].id),
  11312. pos = $t.p._index[ind2];
  11313. if(!$t.p.data[pos][isLeaf]){
  11314. if($t.p.data[pos][expanded]){
  11315. $($t).jqGrid("collapseRow",$t.p.data[pos]);
  11316. $($t).jqGrid("collapseNode",$t.p.data[pos]);
  11317. } else {
  11318. $($t).jqGrid("expandRow",$t.p.data[pos]);
  11319. $($t).jqGrid("expandNode",$t.p.data[pos]);
  11320. }
  11321. }
  11322. $($t).jqGrid("setSelection",ind2);
  11323. return false;
  11324. });
  11325. }
  11326. i++;
  11327. }
  11328. });
  11329. },
  11330. setTreeGrid : function() {
  11331. return this.each(function (){
  11332. var $t = this, i=0, pico, ecol = false, nm, key, tkey, dupcols=[];
  11333. if(!$t.p.treeGrid) {return;}
  11334. if(!$t.p.treedatatype ) {$.extend($t.p,{treedatatype: $t.p.datatype});}
  11335. $t.p.subGrid = false;$t.p.altRows =false;
  11336. $t.p.pgbuttons = false;$t.p.pginput = false;
  11337. $t.p.gridview = true;
  11338. if($t.p.rowTotal === null ) { $t.p.rowNum = 10000; }
  11339. $t.p.multiselect = false;$t.p.rowList = [];
  11340. $t.p.expColInd = 0;
  11341. pico = 'ui-icon-triangle-1-' + ($t.p.direction==="rtl" ? 'w' : 'e');
  11342. $t.p.treeIcons = $.extend({plus:pico,minus:'ui-icon-triangle-1-s',leaf:'ui-icon-radio-off'},$t.p.treeIcons || {});
  11343. if($t.p.treeGridModel === 'nested') {
  11344. $t.p.treeReader = $.extend({
  11345. level_field: "level",
  11346. left_field:"lft",
  11347. right_field: "rgt",
  11348. leaf_field: "isLeaf",
  11349. expanded_field: "expanded",
  11350. loaded: "loaded",
  11351. icon_field: "icon"
  11352. },$t.p.treeReader);
  11353. } else if($t.p.treeGridModel === 'adjacency') {
  11354. $t.p.treeReader = $.extend({
  11355. level_field: "level",
  11356. parent_id_field: "parent",
  11357. leaf_field: "isLeaf",
  11358. expanded_field: "expanded",
  11359. loaded: "loaded",
  11360. icon_field: "icon"
  11361. },$t.p.treeReader );
  11362. }
  11363. for ( key in $t.p.colModel){
  11364. if($t.p.colModel.hasOwnProperty(key)) {
  11365. nm = $t.p.colModel[key].name;
  11366. if( nm === $t.p.ExpandColumn && !ecol ) {
  11367. ecol = true;
  11368. $t.p.expColInd = i;
  11369. }
  11370. i++;
  11371. //
  11372. for(tkey in $t.p.treeReader) {
  11373. if($t.p.treeReader.hasOwnProperty(tkey) && $t.p.treeReader[tkey] === nm) {
  11374. dupcols.push(nm);
  11375. }
  11376. }
  11377. }
  11378. }
  11379. $.each($t.p.treeReader,function(j,n){
  11380. if(n && $.inArray(n, dupcols) === -1){
  11381. if(j==='leaf_field') { $t.p._treeleafpos= i; }
  11382. i++;
  11383. $t.p.colNames.push(n);
  11384. $t.p.colModel.push({name:n,width:1,hidden:true,sortable:false,resizable:false,hidedlg:true,editable:true,search:false});
  11385. }
  11386. });
  11387. });
  11388. },
  11389. expandRow: function (record){
  11390. this.each(function(){
  11391. var $t = this;
  11392. if(!$t.grid || !$t.p.treeGrid) {return;}
  11393. var childern = $($t).jqGrid("getNodeChildren",record),
  11394. //if ($($t).jqGrid("isVisibleNode",record)) {
  11395. expanded = $t.p.treeReader.expanded_field;
  11396. $(childern).each(function(){
  11397. var id = $t.p.idPrefix + $.jgrid.getAccessor(this,$t.p.localReader.id);
  11398. $($($t).jqGrid('getGridRowById', id)).css("display","");
  11399. if(this[expanded]) {
  11400. $($t).jqGrid("expandRow",this);
  11401. }
  11402. });
  11403. //}
  11404. });
  11405. },
  11406. collapseRow : function (record) {
  11407. this.each(function(){
  11408. var $t = this;
  11409. if(!$t.grid || !$t.p.treeGrid) {return;}
  11410. var childern = $($t).jqGrid("getNodeChildren",record),
  11411. expanded = $t.p.treeReader.expanded_field;
  11412. $(childern).each(function(){
  11413. var id = $t.p.idPrefix + $.jgrid.getAccessor(this,$t.p.localReader.id);
  11414. $($($t).jqGrid('getGridRowById', id)).css("display","none");
  11415. if(this[expanded]){
  11416. $($t).jqGrid("collapseRow",this);
  11417. }
  11418. });
  11419. });
  11420. },
  11421. // NS ,adjacency models
  11422. getRootNodes : function() {
  11423. var result = [];
  11424. this.each(function(){
  11425. var $t = this;
  11426. if(!$t.grid || !$t.p.treeGrid) {return;}
  11427. switch ($t.p.treeGridModel) {
  11428. case 'nested' :
  11429. var level = $t.p.treeReader.level_field;
  11430. $($t.p.data).each(function(){
  11431. if(parseInt(this[level],10) === parseInt($t.p.tree_root_level,10)) {
  11432. result.push(this);
  11433. }
  11434. });
  11435. break;
  11436. case 'adjacency' :
  11437. var parent_id = $t.p.treeReader.parent_id_field;
  11438. $($t.p.data).each(function(){
  11439. if(this[parent_id] === null || String(this[parent_id]).toLowerCase() === "null") {
  11440. result.push(this);
  11441. }
  11442. });
  11443. break;
  11444. }
  11445. });
  11446. return result;
  11447. },
  11448. getNodeDepth : function(rc) {
  11449. var ret = null;
  11450. this.each(function(){
  11451. if(!this.grid || !this.p.treeGrid) {return;}
  11452. var $t = this;
  11453. switch ($t.p.treeGridModel) {
  11454. case 'nested' :
  11455. var level = $t.p.treeReader.level_field;
  11456. ret = parseInt(rc[level],10) - parseInt($t.p.tree_root_level,10);
  11457. break;
  11458. case 'adjacency' :
  11459. ret = $($t).jqGrid("getNodeAncestors",rc).length;
  11460. break;
  11461. }
  11462. });
  11463. return ret;
  11464. },
  11465. getNodeParent : function(rc) {
  11466. var result = null;
  11467. this.each(function(){
  11468. var $t = this;
  11469. if(!$t.grid || !$t.p.treeGrid) {return;}
  11470. switch ($t.p.treeGridModel) {
  11471. case 'nested' :
  11472. var lftc = $t.p.treeReader.left_field,
  11473. rgtc = $t.p.treeReader.right_field,
  11474. levelc = $t.p.treeReader.level_field,
  11475. lft = parseInt(rc[lftc],10), rgt = parseInt(rc[rgtc],10), level = parseInt(rc[levelc],10);
  11476. $(this.p.data).each(function(){
  11477. if(parseInt(this[levelc],10) === level-1 && parseInt(this[lftc],10) < lft && parseInt(this[rgtc],10) > rgt) {
  11478. result = this;
  11479. return false;
  11480. }
  11481. });
  11482. break;
  11483. case 'adjacency' :
  11484. var parent_id = $t.p.treeReader.parent_id_field,
  11485. dtid = $t.p.localReader.id,
  11486. ind = rc[dtid], pos = $t.p._index[ind];
  11487. while(pos--) {
  11488. if($t.p.data[pos][dtid] === $.jgrid.stripPref($t.p.idPrefix, rc[parent_id])) {
  11489. result = $t.p.data[pos];
  11490. break;
  11491. }
  11492. }
  11493. break;
  11494. }
  11495. });
  11496. return result;
  11497. },
  11498. getNodeChildren : function(rc) {
  11499. var result = [];
  11500. this.each(function(){
  11501. var $t = this;
  11502. if(!$t.grid || !$t.p.treeGrid) {return;}
  11503. switch ($t.p.treeGridModel) {
  11504. case 'nested' :
  11505. var lftc = $t.p.treeReader.left_field,
  11506. rgtc = $t.p.treeReader.right_field,
  11507. levelc = $t.p.treeReader.level_field,
  11508. lft = parseInt(rc[lftc],10), rgt = parseInt(rc[rgtc],10), level = parseInt(rc[levelc],10);
  11509. $(this.p.data).each(function(){
  11510. if(parseInt(this[levelc],10) === level+1 && parseInt(this[lftc],10) > lft && parseInt(this[rgtc],10) < rgt) {
  11511. result.push(this);
  11512. }
  11513. });
  11514. break;
  11515. case 'adjacency' :
  11516. var parent_id = $t.p.treeReader.parent_id_field,
  11517. dtid = $t.p.localReader.id;
  11518. $(this.p.data).each(function(){
  11519. if(this[parent_id] == $.jgrid.stripPref($t.p.idPrefix, rc[dtid])) {
  11520. result.push(this);
  11521. }
  11522. });
  11523. break;
  11524. }
  11525. });
  11526. return result;
  11527. },
  11528. getFullTreeNode : function(rc) {
  11529. var result = [];
  11530. this.each(function(){
  11531. var $t = this, len;
  11532. if(!$t.grid || !$t.p.treeGrid) {return;}
  11533. switch ($t.p.treeGridModel) {
  11534. case 'nested' :
  11535. var lftc = $t.p.treeReader.left_field,
  11536. rgtc = $t.p.treeReader.right_field,
  11537. levelc = $t.p.treeReader.level_field,
  11538. lft = parseInt(rc[lftc],10), rgt = parseInt(rc[rgtc],10), level = parseInt(rc[levelc],10);
  11539. $(this.p.data).each(function(){
  11540. if(parseInt(this[levelc],10) >= level && parseInt(this[lftc],10) >= lft && parseInt(this[lftc],10) <= rgt) {
  11541. result.push(this);
  11542. }
  11543. });
  11544. break;
  11545. case 'adjacency' :
  11546. if(rc) {
  11547. result.push(rc);
  11548. var parent_id = $t.p.treeReader.parent_id_field,
  11549. dtid = $t.p.localReader.id;
  11550. $(this.p.data).each(function(i){
  11551. len = result.length;
  11552. for (i = 0; i < len; i++) {
  11553. if ($.jgrid.stripPref($t.p.idPrefix, result[i][dtid]) === this[parent_id]) {
  11554. result.push(this);
  11555. break;
  11556. }
  11557. }
  11558. });
  11559. }
  11560. break;
  11561. }
  11562. });
  11563. return result;
  11564. },
  11565. // End NS, adjacency Model
  11566. getNodeAncestors : function(rc) {
  11567. var ancestors = [];
  11568. this.each(function(){
  11569. if(!this.grid || !this.p.treeGrid) {return;}
  11570. var parent = $(this).jqGrid("getNodeParent",rc);
  11571. while (parent) {
  11572. ancestors.push(parent);
  11573. parent = $(this).jqGrid("getNodeParent",parent);
  11574. }
  11575. });
  11576. return ancestors;
  11577. },
  11578. isVisibleNode : function(rc) {
  11579. var result = true;
  11580. this.each(function(){
  11581. var $t = this;
  11582. if(!$t.grid || !$t.p.treeGrid) {return;}
  11583. var ancestors = $($t).jqGrid("getNodeAncestors",rc),
  11584. expanded = $t.p.treeReader.expanded_field;
  11585. $(ancestors).each(function(){
  11586. result = result && this[expanded];
  11587. if(!result) {return false;}
  11588. });
  11589. });
  11590. return result;
  11591. },
  11592. isNodeLoaded : function(rc) {
  11593. var result;
  11594. this.each(function(){
  11595. var $t = this;
  11596. if(!$t.grid || !$t.p.treeGrid) {return;}
  11597. var isLeaf = $t.p.treeReader.leaf_field,
  11598. loaded = $t.p.treeReader.loaded;
  11599. if(rc !== undefined ) {
  11600. if(rc[loaded] !== undefined) {
  11601. result = rc[loaded];
  11602. } else if( rc[isLeaf] || $($t).jqGrid("getNodeChildren",rc).length > 0){
  11603. result = true;
  11604. } else {
  11605. result = false;
  11606. }
  11607. } else {
  11608. result = false;
  11609. }
  11610. });
  11611. return result;
  11612. },
  11613. expandNode : function(rc) {
  11614. return this.each(function(){
  11615. if(!this.grid || !this.p.treeGrid) {return;}
  11616. var expanded = this.p.treeReader.expanded_field,
  11617. parent = this.p.treeReader.parent_id_field,
  11618. loaded = this.p.treeReader.loaded,
  11619. level = this.p.treeReader.level_field,
  11620. lft = this.p.treeReader.left_field,
  11621. rgt = this.p.treeReader.right_field;
  11622. if(!rc[expanded]) {
  11623. var id = $.jgrid.getAccessor(rc,this.p.localReader.id);
  11624. var rc1 = $("#" + this.p.idPrefix + $.jgrid.jqID(id),this.grid.bDiv)[0];
  11625. var position = this.p._index[id];
  11626. if( $(this).jqGrid("isNodeLoaded",this.p.data[position]) ) {
  11627. rc[expanded] = true;
  11628. $("div.treeclick",rc1).removeClass(this.p.treeIcons.plus+" tree-plus").addClass(this.p.treeIcons.minus+" tree-minus");
  11629. } else if (!this.grid.hDiv.loading) {
  11630. rc[expanded] = true;
  11631. $("div.treeclick",rc1).removeClass(this.p.treeIcons.plus+" tree-plus").addClass(this.p.treeIcons.minus+" tree-minus");
  11632. this.p.treeANode = rc1.rowIndex;
  11633. this.p.datatype = this.p.treedatatype;
  11634. if(this.p.treeGridModel === 'nested') {
  11635. $(this).jqGrid("setGridParam",{postData:{nodeid:id,n_left:rc[lft],n_right:rc[rgt],n_level:rc[level]}});
  11636. } else {
  11637. $(this).jqGrid("setGridParam",{postData:{nodeid:id,parentid:rc[parent],n_level:rc[level]}} );
  11638. }
  11639. $(this).trigger("reloadGrid");
  11640. rc[loaded] = true;
  11641. if(this.p.treeGridModel === 'nested') {
  11642. $(this).jqGrid("setGridParam",{postData:{nodeid:'',n_left:'',n_right:'',n_level:''}});
  11643. } else {
  11644. $(this).jqGrid("setGridParam",{postData:{nodeid:'',parentid:'',n_level:''}});
  11645. }
  11646. }
  11647. }
  11648. });
  11649. },
  11650. collapseNode : function(rc) {
  11651. return this.each(function(){
  11652. if(!this.grid || !this.p.treeGrid) {return;}
  11653. var expanded = this.p.treeReader.expanded_field;
  11654. if(rc[expanded]) {
  11655. rc[expanded] = false;
  11656. var id = $.jgrid.getAccessor(rc,this.p.localReader.id);
  11657. var rc1 = $("#" + this.p.idPrefix + $.jgrid.jqID(id),this.grid.bDiv)[0];
  11658. $("div.treeclick",rc1).removeClass(this.p.treeIcons.minus+" tree-minus").addClass(this.p.treeIcons.plus+" tree-plus");
  11659. }
  11660. });
  11661. },
  11662. SortTree : function( sortname, newDir, st, datefmt) {
  11663. return this.each(function(){
  11664. if(!this.grid || !this.p.treeGrid) {return;}
  11665. var i, len,
  11666. rec, records = [], $t = this, query, roots,
  11667. rt = $(this).jqGrid("getRootNodes");
  11668. // Sorting roots
  11669. query = $.jgrid.from(rt);
  11670. query.orderBy(sortname,newDir,st, datefmt);
  11671. roots = query.select();
  11672. // Sorting children
  11673. for (i = 0, len = roots.length; i < len; i++) {
  11674. rec = roots[i];
  11675. records.push(rec);
  11676. $(this).jqGrid("collectChildrenSortTree",records, rec, sortname, newDir,st, datefmt);
  11677. }
  11678. $.each(records, function(index) {
  11679. var id = $.jgrid.getAccessor(this,$t.p.localReader.id);
  11680. $('#'+$.jgrid.jqID($t.p.id)+ ' tbody tr:eq('+index+')').after($('tr#'+$.jgrid.jqID(id),$t.grid.bDiv));
  11681. });
  11682. query = null;roots=null;records=null;
  11683. });
  11684. },
  11685. collectChildrenSortTree : function(records, rec, sortname, newDir,st, datefmt) {
  11686. return this.each(function(){
  11687. if(!this.grid || !this.p.treeGrid) {return;}
  11688. var i, len,
  11689. child, ch, query, children;
  11690. ch = $(this).jqGrid("getNodeChildren",rec);
  11691. query = $.jgrid.from(ch);
  11692. query.orderBy(sortname, newDir, st, datefmt);
  11693. children = query.select();
  11694. for (i = 0, len = children.length; i < len; i++) {
  11695. child = children[i];
  11696. records.push(child);
  11697. $(this).jqGrid("collectChildrenSortTree",records, child, sortname, newDir, st, datefmt);
  11698. }
  11699. });
  11700. },
  11701. // experimental
  11702. setTreeRow : function(rowid, data) {
  11703. var success=false;
  11704. this.each(function(){
  11705. var t = this;
  11706. if(!t.grid || !t.p.treeGrid) {return;}
  11707. success = $(t).jqGrid("setRowData",rowid,data);
  11708. });
  11709. return success;
  11710. },
  11711. delTreeNode : function (rowid) {
  11712. return this.each(function () {
  11713. var $t = this, rid = $t.p.localReader.id, i,
  11714. left = $t.p.treeReader.left_field,
  11715. right = $t.p.treeReader.right_field, myright, width, res, key;
  11716. if(!$t.grid || !$t.p.treeGrid) {return;}
  11717. var rc = $t.p._index[rowid];
  11718. if (rc !== undefined) {
  11719. // nested
  11720. myright = parseInt($t.p.data[rc][right],10);
  11721. width = myright - parseInt($t.p.data[rc][left],10) + 1;
  11722. var dr = $($t).jqGrid("getFullTreeNode",$t.p.data[rc]);
  11723. if(dr.length>0){
  11724. for (i=0;i<dr.length;i++){
  11725. $($t).jqGrid("delRowData",dr[i][rid]);
  11726. }
  11727. }
  11728. if( $t.p.treeGridModel === "nested") {
  11729. // ToDo - update grid data
  11730. res = $.jgrid.from($t.p.data)
  11731. .greater(left,myright,{stype:'integer'})
  11732. .select();
  11733. if(res.length) {
  11734. for( key in res) {
  11735. if(res.hasOwnProperty(key)) {
  11736. res[key][left] = parseInt(res[key][left],10) - width ;
  11737. }
  11738. }
  11739. }
  11740. res = $.jgrid.from($t.p.data)
  11741. .greater(right,myright,{stype:'integer'})
  11742. .select();
  11743. if(res.length) {
  11744. for( key in res) {
  11745. if(res.hasOwnProperty(key)) {
  11746. res[key][right] = parseInt(res[key][right],10) - width ;
  11747. }
  11748. }
  11749. }
  11750. }
  11751. }
  11752. });
  11753. },
  11754. addChildNode : function( nodeid, parentid, data, expandData ) {
  11755. //return this.each(function(){
  11756. var $t = this[0];
  11757. if(data) {
  11758. // we suppose tha the id is autoincremet and
  11759. var expanded = $t.p.treeReader.expanded_field,
  11760. isLeaf = $t.p.treeReader.leaf_field,
  11761. level = $t.p.treeReader.level_field,
  11762. //icon = $t.p.treeReader.icon_field,
  11763. parent = $t.p.treeReader.parent_id_field,
  11764. left = $t.p.treeReader.left_field,
  11765. right = $t.p.treeReader.right_field,
  11766. loaded = $t.p.treeReader.loaded,
  11767. method, parentindex, parentdata, parentlevel, i, len, max=0, rowind = parentid, leaf, maxright;
  11768. if(expandData===undefined) {expandData = false;}
  11769. if ( nodeid === undefined || nodeid === null ) {
  11770. i = $t.p.data.length-1;
  11771. if( i>= 0 ) {
  11772. while(i>=0){max = Math.max(max, parseInt($t.p.data[i][$t.p.localReader.id],10)); i--;}
  11773. }
  11774. nodeid = max+1;
  11775. }
  11776. var prow = $($t).jqGrid('getInd', parentid);
  11777. leaf = false;
  11778. // if not a parent we assume root
  11779. if ( parentid === undefined || parentid === null || parentid==="") {
  11780. parentid = null;
  11781. rowind = null;
  11782. method = 'last';
  11783. parentlevel = $t.p.tree_root_level;
  11784. i = $t.p.data.length+1;
  11785. } else {
  11786. method = 'after';
  11787. parentindex = $t.p._index[parentid];
  11788. parentdata = $t.p.data[parentindex];
  11789. parentid = parentdata[$t.p.localReader.id];
  11790. parentlevel = parseInt(parentdata[level],10)+1;
  11791. var childs = $($t).jqGrid('getFullTreeNode', parentdata);
  11792. // if there are child nodes get the last index of it
  11793. if(childs.length) {
  11794. i = childs[childs.length-1][$t.p.localReader.id];
  11795. rowind = i;
  11796. i = $($t).jqGrid('getInd',rowind)+1;
  11797. } else {
  11798. i = $($t).jqGrid('getInd', parentid)+1;
  11799. }
  11800. // if the node is leaf
  11801. if(parentdata[isLeaf]) {
  11802. leaf = true;
  11803. parentdata[expanded] = true;
  11804. //var prow = $($t).jqGrid('getInd', parentid);
  11805. $($t.rows[prow])
  11806. .find("span.cell-wrapperleaf").removeClass("cell-wrapperleaf").addClass("cell-wrapper")
  11807. .end()
  11808. .find("div.tree-leaf").removeClass($t.p.treeIcons.leaf+" tree-leaf").addClass($t.p.treeIcons.minus+" tree-minus");
  11809. $t.p.data[parentindex][isLeaf] = false;
  11810. parentdata[loaded] = true;
  11811. }
  11812. }
  11813. len = i+1;
  11814. if( data[expanded]===undefined) {data[expanded]= false;}
  11815. if( data[loaded]===undefined ) { data[loaded] = false;}
  11816. data[level] = parentlevel;
  11817. if( data[isLeaf]===undefined) {data[isLeaf]= true;}
  11818. if( $t.p.treeGridModel === "adjacency") {
  11819. data[parent] = parentid;
  11820. }
  11821. if( $t.p.treeGridModel === "nested") {
  11822. // this method requiere more attention
  11823. var query, res, key;
  11824. //maxright = parseInt(maxright,10);
  11825. // ToDo - update grid data
  11826. if(parentid !== null) {
  11827. maxright = parseInt(parentdata[right],10);
  11828. query = $.jgrid.from($t.p.data);
  11829. query = query.greaterOrEquals(right,maxright,{stype:'integer'});
  11830. res = query.select();
  11831. if(res.length) {
  11832. for( key in res) {
  11833. if(res.hasOwnProperty(key)) {
  11834. res[key][left] = res[key][left] > maxright ? parseInt(res[key][left],10) +2 : res[key][left];
  11835. res[key][right] = res[key][right] >= maxright ? parseInt(res[key][right],10) +2 : res[key][right];
  11836. }
  11837. }
  11838. }
  11839. data[left] = maxright;
  11840. data[right]= maxright+1;
  11841. } else {
  11842. maxright = parseInt( $($t).jqGrid('getCol', right, false, 'max'), 10);
  11843. res = $.jgrid.from($t.p.data)
  11844. .greater(left,maxright,{stype:'integer'})
  11845. .select();
  11846. if(res.length) {
  11847. for( key in res) {
  11848. if(res.hasOwnProperty(key)) {
  11849. res[key][left] = parseInt(res[key][left],10) +2 ;
  11850. }
  11851. }
  11852. }
  11853. res = $.jgrid.from($t.p.data)
  11854. .greater(right,maxright,{stype:'integer'})
  11855. .select();
  11856. if(res.length) {
  11857. for( key in res) {
  11858. if(res.hasOwnProperty(key)) {
  11859. res[key][right] = parseInt(res[key][right],10) +2 ;
  11860. }
  11861. }
  11862. }
  11863. data[left] = maxright+1;
  11864. data[right] = maxright + 2;
  11865. }
  11866. }
  11867. if( parentid === null || $($t).jqGrid("isNodeLoaded",parentdata) || leaf ) {
  11868. $($t).jqGrid('addRowData', nodeid, data, method, rowind);
  11869. $($t).jqGrid('setTreeNode', i, len);
  11870. }
  11871. if(parentdata && !parentdata[expanded] && expandData) {
  11872. $($t.rows[prow])
  11873. .find("div.treeclick")
  11874. .click();
  11875. }
  11876. }
  11877. //});
  11878. }
  11879. });
  11880. })(jQuery);
  11881. /*jshint eqeqeq:false, eqnull:true */
  11882. /*global jQuery */
  11883. // Grouping module
  11884. (function($){
  11885. "use strict";
  11886. $.extend($.jgrid,{
  11887. template : function(format){ //jqgformat
  11888. var args = $.makeArray(arguments).slice(1), j, al = args.length;
  11889. if(format==null) { format = ""; }
  11890. return format.replace(/\{([\w\-]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g, function(m,i){
  11891. if(!isNaN(parseInt(i,10))) {
  11892. return args[parseInt(i,10)];
  11893. }
  11894. for(j=0; j < al;j++) {
  11895. if($.isArray(args[j])) {
  11896. var nmarr = args[ j ],
  11897. k = nmarr.length;
  11898. while(k--) {
  11899. if(i===nmarr[k].nm) {
  11900. return nmarr[k].v;
  11901. }
  11902. }
  11903. }
  11904. }
  11905. });
  11906. }
  11907. });
  11908. $.jgrid.extend({
  11909. groupingSetup : function () {
  11910. return this.each(function (){
  11911. var $t = this, i, j, cml, cm = $t.p.colModel, grp = $t.p.groupingView;
  11912. if(grp !== null && ( (typeof grp === 'object') || $.isFunction(grp) ) ) {
  11913. if(!grp.groupField.length) {
  11914. $t.p.grouping = false;
  11915. } else {
  11916. if (grp.visibiltyOnNextGrouping === undefined) {
  11917. grp.visibiltyOnNextGrouping = [];
  11918. }
  11919. grp.lastvalues=[];
  11920. if(!grp._locgr) {
  11921. grp.groups =[];
  11922. }
  11923. grp.counters =[];
  11924. for(i=0;i<grp.groupField.length;i++) {
  11925. if(!grp.groupOrder[i]) {
  11926. grp.groupOrder[i] = 'asc';
  11927. }
  11928. if(!grp.groupText[i]) {
  11929. grp.groupText[i] = '{0}';
  11930. }
  11931. if( typeof grp.groupColumnShow[i] !== 'boolean') {
  11932. grp.groupColumnShow[i] = true;
  11933. }
  11934. if( typeof grp.groupSummary[i] !== 'boolean') {
  11935. grp.groupSummary[i] = false;
  11936. }
  11937. if( !grp.groupSummaryPos[i]) {
  11938. grp.groupSummaryPos[i] = 'footer';
  11939. }
  11940. if(grp.groupColumnShow[i] === true) {
  11941. grp.visibiltyOnNextGrouping[i] = true;
  11942. $($t).jqGrid('showCol',grp.groupField[i]);
  11943. } else {
  11944. grp.visibiltyOnNextGrouping[i] = $("#"+$.jgrid.jqID($t.p.id+"_"+grp.groupField[i])).is(":visible");
  11945. $($t).jqGrid('hideCol',grp.groupField[i]);
  11946. }
  11947. }
  11948. grp.summary =[];
  11949. if(grp.hideFirstGroupCol) {
  11950. grp.formatDisplayField[0] = function (v) { return v;};
  11951. }
  11952. for(j=0, cml = cm.length; j < cml; j++) {
  11953. if(grp.hideFirstGroupCol) {
  11954. if(!cm[j].hidden && grp.groupField[0] === cm[j].name) {
  11955. cm[j].formatter = function(){return '';};
  11956. }
  11957. }
  11958. if(cm[j].summaryType ) {
  11959. if(cm[j].summaryDivider) {
  11960. 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'});
  11961. } else {
  11962. grp.summary.push({nm:cm[j].name,st:cm[j].summaryType, v: '', sr: cm[j].summaryRound, srt: cm[j].summaryRoundType || 'round'});
  11963. }
  11964. }
  11965. }
  11966. }
  11967. } else {
  11968. $t.p.grouping = false;
  11969. }
  11970. });
  11971. },
  11972. groupingPrepare : function ( record, irow ) {
  11973. this.each(function(){
  11974. var grp = this.p.groupingView, $t= this, i,
  11975. grlen = grp.groupField.length,
  11976. fieldName,
  11977. v,
  11978. displayName,
  11979. displayValue,
  11980. changed = 0;
  11981. for(i=0;i<grlen;i++) {
  11982. fieldName = grp.groupField[i];
  11983. displayName = grp.displayField[i];
  11984. v = record[fieldName];
  11985. displayValue = displayName == null ? null : record[displayName];
  11986. if( displayValue == null ) {
  11987. displayValue = v;
  11988. }
  11989. if( v !== undefined ) {
  11990. if(irow === 0 ) {
  11991. // First record always starts a new group
  11992. grp.groups.push({idx:i,dataIndex:fieldName,value:v, displayValue: displayValue, startRow: irow, cnt:1, summary : [] } );
  11993. grp.lastvalues[i] = v;
  11994. grp.counters[i] = {cnt:1, pos:grp.groups.length-1, summary: $.extend(true,[],grp.summary)};
  11995. $.each(grp.counters[i].summary,function() {
  11996. if ($.isFunction(this.st)) {
  11997. this.v = this.st.call($t, this.v, this.nm, record);
  11998. } else {
  11999. this.v = $($t).jqGrid('groupingCalculations.handler',this.st, this.v, this.nm, this.sr, this.srt, record);
  12000. if(this.st.toLowerCase() === 'avg' && this.sd) {
  12001. this.vd = $($t).jqGrid('groupingCalculations.handler',this.st, this.vd, this.sd, this.sr, this.srt, record);
  12002. }
  12003. }
  12004. });
  12005. grp.groups[grp.counters[i].pos].summary = grp.counters[i].summary;
  12006. } else {
  12007. 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)) {
  12008. // This record is not in same group as previous one
  12009. grp.groups.push({idx:i,dataIndex:fieldName,value:v, displayValue: displayValue, startRow: irow, cnt:1, summary : [] } );
  12010. grp.lastvalues[i] = v;
  12011. changed = 1;
  12012. grp.counters[i] = {cnt:1, pos:grp.groups.length-1, summary: $.extend(true,[],grp.summary)};
  12013. $.each(grp.counters[i].summary,function() {
  12014. if ($.isFunction(this.st)) {
  12015. this.v = this.st.call($t, this.v, this.nm, record);
  12016. } else {
  12017. this.v = $($t).jqGrid('groupingCalculations.handler',this.st, this.v, this.nm, this.sr, this.srt, record);
  12018. if(this.st.toLowerCase() === 'avg' && this.sd) {
  12019. this.vd = $($t).jqGrid('groupingCalculations.handler',this.st, this.vd, this.sd, this.sr, this.srt, record);
  12020. }
  12021. }
  12022. });
  12023. grp.groups[grp.counters[i].pos].summary = grp.counters[i].summary;
  12024. } else {
  12025. if (changed === 1) {
  12026. // This group has changed because an earlier group changed.
  12027. grp.groups.push({idx:i,dataIndex:fieldName,value:v, displayValue: displayValue, startRow: irow, cnt:1, summary : [] } );
  12028. grp.lastvalues[i] = v;
  12029. grp.counters[i] = {cnt:1, pos:grp.groups.length-1, summary: $.extend(true,[],grp.summary)};
  12030. $.each(grp.counters[i].summary,function() {
  12031. if ($.isFunction(this.st)) {
  12032. this.v = this.st.call($t, this.v, this.nm, record);
  12033. } else {
  12034. this.v = $($t).jqGrid('groupingCalculations.handler',this.st, this.v, this.nm, this.sr, this.srt, record);
  12035. if(this.st.toLowerCase() === 'avg' && this.sd) {
  12036. this.vd = $($t).jqGrid('groupingCalculations.handler',this.st, this.vd, this.sd, this.sr, this.srt, record);
  12037. }
  12038. }
  12039. });
  12040. grp.groups[grp.counters[i].pos].summary = grp.counters[i].summary;
  12041. } else {
  12042. grp.counters[i].cnt += 1;
  12043. grp.groups[grp.counters[i].pos].cnt = grp.counters[i].cnt;
  12044. $.each(grp.counters[i].summary,function() {
  12045. if ($.isFunction(this.st)) {
  12046. this.v = this.st.call($t, this.v, this.nm, record);
  12047. } else {
  12048. this.v = $($t).jqGrid('groupingCalculations.handler',this.st, this.v, this.nm, this.sr, this.srt, record);
  12049. if(this.st.toLowerCase() === 'avg' && this.sd) {
  12050. this.vd = $($t).jqGrid('groupingCalculations.handler',this.st, this.vd, this.sd, this.sr, this.srt, record);
  12051. }
  12052. }
  12053. });
  12054. grp.groups[grp.counters[i].pos].summary = grp.counters[i].summary;
  12055. }
  12056. }
  12057. }
  12058. }
  12059. }
  12060. //gdata.push( rData );
  12061. });
  12062. return this;
  12063. },
  12064. groupingToggle : function(hid){
  12065. this.each(function(){
  12066. var $t = this,
  12067. grp = $t.p.groupingView,
  12068. strpos = hid.split('_'),
  12069. num = parseInt(strpos[strpos.length-2], 10);
  12070. strpos.splice(strpos.length-2,2);
  12071. var uid = strpos.join("_"),
  12072. minus = grp.minusicon,
  12073. plus = grp.plusicon,
  12074. tar = $("#"+$.jgrid.jqID(hid)),
  12075. r = tar.length ? tar[0].nextSibling : null,
  12076. tarspan = $("#"+$.jgrid.jqID(hid)+" span."+"tree-wrap-"+$t.p.direction),
  12077. getGroupingLevelFromClass = function (className) {
  12078. var nums = $.map(className.split(" "), function (item) {
  12079. if (item.substring(0, uid.length + 1) === uid + "_") {
  12080. return parseInt(item.substring(uid.length + 1), 10);
  12081. }
  12082. });
  12083. return nums.length > 0 ? nums[0] : undefined;
  12084. },
  12085. itemGroupingLevel,
  12086. showData,
  12087. collapsed = false,
  12088. frz = $t.p.frozenColumns ? $t.p.id+"_frozen" : false,
  12089. tar2 = frz ? $("#"+$.jgrid.jqID(hid), "#"+$.jgrid.jqID(frz) ) : false,
  12090. r2 = (tar2 && tar2.length) ? tar2[0].nextSibling : null;
  12091. if( tarspan.hasClass(minus) ) {
  12092. if(grp.showSummaryOnHide) {
  12093. if(r){
  12094. while(r) {
  12095. if($(r).hasClass('jqfoot') ) {
  12096. var lv = parseInt($(r).attr("jqfootlevel"),10);
  12097. if( lv <= num) {
  12098. break;
  12099. }
  12100. }
  12101. $(r).hide();
  12102. r = r.nextSibling;
  12103. if(frz) {
  12104. $(r2).hide();
  12105. r2 = r2.nextSibling;
  12106. }
  12107. }
  12108. }
  12109. } else {
  12110. if(r){
  12111. while(r) {
  12112. itemGroupingLevel = getGroupingLevelFromClass(r.className);
  12113. if (itemGroupingLevel !== undefined && itemGroupingLevel <= num) {
  12114. break;
  12115. }
  12116. $(r).hide();
  12117. r = r.nextSibling;
  12118. if(frz) {
  12119. $(r2).hide();
  12120. r2 = r2.nextSibling;
  12121. }
  12122. }
  12123. }
  12124. }
  12125. tarspan.removeClass(minus).addClass(plus);
  12126. collapsed = true;
  12127. } else {
  12128. if(r){
  12129. showData = undefined;
  12130. while(r) {
  12131. itemGroupingLevel = getGroupingLevelFromClass(r.className);
  12132. if (showData === undefined) {
  12133. showData = itemGroupingLevel === undefined; // if the first row after the opening group is data row then show the data rows
  12134. }
  12135. if (itemGroupingLevel !== undefined) {
  12136. if (itemGroupingLevel <= num) {
  12137. break;// next item of the same lever are found
  12138. }
  12139. if (itemGroupingLevel === num + 1) {
  12140. $(r).show().find(">td>span."+"tree-wrap-"+$t.p.direction).removeClass(minus).addClass(plus);
  12141. if(frz) {
  12142. $(r2).show().find(">td>span."+"tree-wrap-"+$t.p.direction).removeClass(minus).addClass(plus);
  12143. }
  12144. }
  12145. } else if (showData) {
  12146. $(r).show();
  12147. if(frz) {
  12148. $(r2).show();
  12149. }
  12150. }
  12151. r = r.nextSibling;
  12152. if(frz) {
  12153. r2 = r2.nextSibling;
  12154. }
  12155. }
  12156. }
  12157. tarspan.removeClass(plus).addClass(minus);
  12158. }
  12159. $($t).triggerHandler("jqGridGroupingClickGroup", [hid , collapsed]);
  12160. if( $.isFunction($t.p.onClickGroup)) { $t.p.onClickGroup.call($t, hid , collapsed); }
  12161. });
  12162. return false;
  12163. },
  12164. groupingRender : function (grdata, colspans, page, rn ) {
  12165. return this.each(function(){
  12166. var $t = this,
  12167. grp = $t.p.groupingView,
  12168. str = "", icon = "", hid, clid, pmrtl = grp.groupCollapse ? grp.plusicon : grp.minusicon, gv, cp=[], len =grp.groupField.length;
  12169. pmrtl += " tree-wrap-"+$t.p.direction;
  12170. $.each($t.p.colModel, function (i,n){
  12171. var ii;
  12172. for(ii=0;ii<len;ii++) {
  12173. if(grp.groupField[ii] === n.name ) {
  12174. cp[ii] = i;
  12175. break;
  12176. }
  12177. }
  12178. });
  12179. var toEnd = 0;
  12180. function findGroupIdx( ind , offset, grp) {
  12181. var ret = false, i;
  12182. if(offset===0) {
  12183. ret = grp[ind];
  12184. } else {
  12185. var id = grp[ind].idx;
  12186. if(id===0) {
  12187. ret = grp[ind];
  12188. } else {
  12189. for(i=ind;i >= 0; i--) {
  12190. if(grp[i].idx === id-offset) {
  12191. ret = grp[i];
  12192. break;
  12193. }
  12194. }
  12195. }
  12196. }
  12197. return ret;
  12198. }
  12199. function buildSummaryTd(i, ik, grp, foffset) {
  12200. var fdata = findGroupIdx(i, ik, grp),
  12201. cm = $t.p.colModel,
  12202. vv, grlen = fdata.cnt, str="", k;
  12203. for(k=foffset; k<colspans;k++) {
  12204. var tmpdata = "<td "+$t.formatCol(k,1,'')+">&#160;</td>",
  12205. tplfld = "{0}";
  12206. $.each(fdata.summary,function(){
  12207. if(this.nm === cm[k].name) {
  12208. if(cm[k].summaryTpl) {
  12209. tplfld = cm[k].summaryTpl;
  12210. }
  12211. if(typeof this.st === 'string' && this.st.toLowerCase() === 'avg') {
  12212. if(this.sd && this.vd) {
  12213. this.v = (this.v/this.vd);
  12214. } else if(this.v && grlen > 0) {
  12215. this.v = (this.v/grlen);
  12216. }
  12217. }
  12218. try {
  12219. this.groupCount = fdata.cnt;
  12220. this.groupIndex = fdata.dataIndex;
  12221. this.groupValue = fdata.value;
  12222. vv = $t.formatter('', this.v, k, this);
  12223. } catch (ef) {
  12224. vv = this.v;
  12225. }
  12226. tmpdata= "<td "+$t.formatCol(k,1,'')+">"+$.jgrid.format(tplfld,vv)+ "</td>";
  12227. return false;
  12228. }
  12229. });
  12230. str += tmpdata;
  12231. }
  12232. return str;
  12233. }
  12234. var sumreverse = $.makeArray(grp.groupSummary), mul;
  12235. sumreverse.reverse();
  12236. mul = $t.p.multiselect ? " colspan=\"2\"" : "";
  12237. $.each(grp.groups,function(i,n){
  12238. if(grp._locgr) {
  12239. if( !(n.startRow +n.cnt > (page-1)*rn && n.startRow < page*rn)) {
  12240. return true;
  12241. }
  12242. }
  12243. toEnd++;
  12244. clid = $t.p.id+"ghead_"+n.idx;
  12245. hid = clid+"_"+i;
  12246. icon = "<span style='cursor:pointer;' class='ui-icon "+pmrtl+"' onclick=\"jQuery('#"+$.jgrid.jqID($t.p.id)+"').jqGrid('groupingToggle','"+hid+"');return false;\"></span>";
  12247. try {
  12248. if ($.isArray(grp.formatDisplayField) && $.isFunction(grp.formatDisplayField[n.idx])) {
  12249. n.displayValue = grp.formatDisplayField[n.idx].call($t, n.displayValue, n.value, $t.p.colModel[cp[n.idx]], n.idx, grp);
  12250. gv = n.displayValue;
  12251. } else {
  12252. gv = $t.formatter(hid, n.displayValue, cp[n.idx], n.value );
  12253. }
  12254. } catch (egv) {
  12255. gv = n.displayValue;
  12256. }
  12257. if(grp.groupSummaryPos[n.idx] === 'header') {
  12258. 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;"+"\"" + mul +">"+icon+$.jgrid.template(grp.groupText[n.idx], gv, n.cnt, n.summary)+"</td>";
  12259. str += buildSummaryTd(i, n.idx-1, grp.groups, (mul ==="") ? 1 : 2 );
  12260. str += "</tr>";
  12261. } else {
  12262. 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>";
  12263. }
  12264. var leaf = len-1 === n.idx;
  12265. if( leaf ) {
  12266. var gg = grp.groups[i+1], kk, ik, offset = 0, sgr = n.startRow,
  12267. end = gg !== undefined ? gg.startRow : grp.groups[i].startRow + grp.groups[i].cnt;
  12268. if(grp._locgr) {
  12269. offset = (page-1)*rn;
  12270. if(offset > n.startRow) {
  12271. sgr = offset;
  12272. }
  12273. }
  12274. for(kk=sgr;kk<end;kk++) {
  12275. if(!grdata[kk - offset]) { break; }
  12276. str += grdata[kk - offset].join('');
  12277. }
  12278. if(grp.groupSummaryPos[n.idx] !== 'header') {
  12279. var jj;
  12280. if (gg !== undefined) {
  12281. for (jj = 0; jj < grp.groupField.length; jj++) {
  12282. if (gg.dataIndex === grp.groupField[jj]) {
  12283. break;
  12284. }
  12285. }
  12286. toEnd = grp.groupField.length - jj;
  12287. }
  12288. for (ik = 0; ik < toEnd; ik++) {
  12289. if(!sumreverse[ik]) { continue; }
  12290. var hhdr = "";
  12291. if(grp.groupCollapse && !grp.showSummaryOnHide) {
  12292. hhdr = " style=\"display:none;\"";
  12293. }
  12294. str += "<tr"+hhdr+" jqfootlevel=\""+(n.idx-ik)+"\" role=\"row\" class=\"ui-widget-content jqfoot ui-row-"+$t.p.direction+"\">";
  12295. str += buildSummaryTd(i, ik, grp.groups, 0);
  12296. str += "</tr>";
  12297. }
  12298. toEnd = jj;
  12299. }
  12300. }
  12301. });
  12302. $("#"+$.jgrid.jqID($t.p.id)+" tbody:first").append(str);
  12303. // free up memory
  12304. str = null;
  12305. });
  12306. },
  12307. groupingGroupBy : function (name, options ) {
  12308. return this.each(function(){
  12309. var $t = this;
  12310. if(typeof name === "string") {
  12311. name = [name];
  12312. }
  12313. var grp = $t.p.groupingView;
  12314. $t.p.grouping = true;
  12315. //Set default, in case visibilityOnNextGrouping is undefined
  12316. if (grp.visibiltyOnNextGrouping === undefined) {
  12317. grp.visibiltyOnNextGrouping = [];
  12318. }
  12319. var i;
  12320. // show previous hidden groups if they are hidden and weren't removed yet
  12321. for(i=0;i<grp.groupField.length;i++) {
  12322. if(!grp.groupColumnShow[i] && grp.visibiltyOnNextGrouping[i]) {
  12323. $($t).jqGrid('showCol',grp.groupField[i]);
  12324. }
  12325. }
  12326. // set visibility status of current group columns on next grouping
  12327. for(i=0;i<name.length;i++) {
  12328. grp.visibiltyOnNextGrouping[i] = $("#"+$.jgrid.jqID($t.p.id)+"_"+$.jgrid.jqID(name[i])).is(":visible");
  12329. }
  12330. $t.p.groupingView = $.extend($t.p.groupingView, options || {});
  12331. grp.groupField = name;
  12332. $($t).trigger("reloadGrid");
  12333. });
  12334. },
  12335. groupingRemove : function (current) {
  12336. return this.each(function(){
  12337. var $t = this;
  12338. if(current === undefined) {
  12339. current = true;
  12340. }
  12341. $t.p.grouping = false;
  12342. if(current===true) {
  12343. var grp = $t.p.groupingView, i;
  12344. // show previous hidden groups if they are hidden and weren't removed yet
  12345. for(i=0;i<grp.groupField.length;i++) {
  12346. if (!grp.groupColumnShow[i] && grp.visibiltyOnNextGrouping[i]) {
  12347. $($t).jqGrid('showCol', grp.groupField);
  12348. }
  12349. }
  12350. $("tr.jqgroup, tr.jqfoot","#"+$.jgrid.jqID($t.p.id)+" tbody:first").remove();
  12351. $("tr.jqgrow:hidden","#"+$.jgrid.jqID($t.p.id)+" tbody:first").show();
  12352. } else {
  12353. $($t).trigger("reloadGrid");
  12354. }
  12355. });
  12356. },
  12357. groupingCalculations : {
  12358. handler: function(fn, v, field, round, roundType, rc) {
  12359. var funcs = {
  12360. sum: function() {
  12361. return parseFloat(v||0) + parseFloat((rc[field]||0));
  12362. },
  12363. min: function() {
  12364. if(v==="") {
  12365. return parseFloat(rc[field]||0);
  12366. }
  12367. return Math.min(parseFloat(v),parseFloat(rc[field]||0));
  12368. },
  12369. max: function() {
  12370. if(v==="") {
  12371. return parseFloat(rc[field]||0);
  12372. }
  12373. return Math.max(parseFloat(v),parseFloat(rc[field]||0));
  12374. },
  12375. count: function() {
  12376. if(v==="") {v=0;}
  12377. if(rc.hasOwnProperty(field)) {
  12378. return v+1;
  12379. }
  12380. return 0;
  12381. },
  12382. avg: function() {
  12383. // the same as sum, but at end we divide it
  12384. // so use sum instead of duplicating the code (?)
  12385. return funcs.sum();
  12386. }
  12387. };
  12388. if(!funcs[fn]) {
  12389. throw ("jqGrid Grouping No such method: " + fn);
  12390. }
  12391. var res = funcs[fn]();
  12392. if (round != null) {
  12393. if (roundType === 'fixed') {
  12394. res = res.toFixed(round);
  12395. } else {
  12396. var mul = Math.pow(10, round);
  12397. res = Math.round(res * mul) / mul;
  12398. }
  12399. }
  12400. return res;
  12401. }
  12402. }
  12403. });
  12404. })(jQuery);
  12405. /*jshint eqeqeq:false, eqnull:true, devel:true */
  12406. /*global jQuery, xmlJsonClass */
  12407. (function($){
  12408. /*
  12409. * jqGrid extension for constructing Grid Data from external file
  12410. * Tony Tomov tony@trirand.com
  12411. * http://trirand.com/blog/
  12412. * Dual licensed under the MIT and GPL licenses:
  12413. * http://www.opensource.org/licenses/mit-license.php
  12414. * http://www.gnu.org/licenses/gpl-2.0.html
  12415. **/
  12416. "use strict";
  12417. $.jgrid.extend({
  12418. jqGridImport : function(o) {
  12419. o = $.extend({
  12420. imptype : "xml", // xml, json, xmlstring, jsonstring
  12421. impstring: "",
  12422. impurl: "",
  12423. mtype: "GET",
  12424. impData : {},
  12425. xmlGrid :{
  12426. config : "roots>grid",
  12427. data: "roots>rows"
  12428. },
  12429. jsonGrid :{
  12430. config : "grid",
  12431. data: "data"
  12432. },
  12433. ajaxOptions :{}
  12434. }, o || {});
  12435. return this.each(function(){
  12436. var $t = this;
  12437. var xmlConvert = function (xml,o) {
  12438. var cnfg = $(o.xmlGrid.config,xml)[0];
  12439. var xmldata = $(o.xmlGrid.data,xml)[0], jstr, jstr1, key;
  12440. if(xmlJsonClass.xml2json && $.jgrid.parse) {
  12441. jstr = xmlJsonClass.xml2json(cnfg," ");
  12442. jstr = $.jgrid.parse(jstr);
  12443. for(key in jstr) {
  12444. if(jstr.hasOwnProperty(key)) {
  12445. jstr1=jstr[key];
  12446. }
  12447. }
  12448. if(xmldata) {
  12449. // save the datatype
  12450. var svdatatype = jstr.grid.datatype;
  12451. jstr.grid.datatype = 'xmlstring';
  12452. jstr.grid.datastr = xml;
  12453. $($t).jqGrid( jstr1 ).jqGrid("setGridParam",{datatype:svdatatype});
  12454. } else {
  12455. $($t).jqGrid( jstr1 );
  12456. }
  12457. jstr = null;jstr1=null;
  12458. } else {
  12459. alert("xml2json or parse are not present");
  12460. }
  12461. };
  12462. var jsonConvert = function (jsonstr,o){
  12463. if (jsonstr && typeof jsonstr === 'string') {
  12464. var _jsonparse = false;
  12465. if($.jgrid.useJSON) {
  12466. $.jgrid.useJSON = false;
  12467. _jsonparse = true;
  12468. }
  12469. var json = $.jgrid.parse(jsonstr);
  12470. if(_jsonparse) { $.jgrid.useJSON = true; }
  12471. var gprm = json[o.jsonGrid.config];
  12472. var jdata = json[o.jsonGrid.data];
  12473. if(jdata) {
  12474. var svdatatype = gprm.datatype;
  12475. gprm.datatype = 'jsonstring';
  12476. gprm.datastr = jdata;
  12477. $($t).jqGrid( gprm ).jqGrid("setGridParam",{datatype:svdatatype});
  12478. } else {
  12479. $($t).jqGrid( gprm );
  12480. }
  12481. }
  12482. };
  12483. switch (o.imptype){
  12484. case 'xml':
  12485. //alert("08");
  12486. $.ajax($.extend({
  12487. url:o.impurl,
  12488. type:o.mtype,
  12489. data: o.impData,
  12490. dataType:"xml",
  12491. complete: function(xml,stat) {
  12492. if(stat === 'success') {
  12493. xmlConvert(xml.responseXML,o);
  12494. $($t).triggerHandler("jqGridImportComplete", [xml, o]);
  12495. if($.isFunction(o.importComplete)) {
  12496. o.importComplete(xml);
  12497. }
  12498. }
  12499. xml=null;
  12500. }
  12501. }, o.ajaxOptions));
  12502. break;
  12503. case 'xmlstring' :
  12504. // we need to make just the conversion and use the same code as xml
  12505. if(o.impstring && typeof o.impstring === 'string') {
  12506. var xmld = $.parseXML(o.impstring);
  12507. if(xmld) {
  12508. xmlConvert(xmld,o);
  12509. $($t).triggerHandler("jqGridImportComplete", [xmld, o]);
  12510. if($.isFunction(o.importComplete)) {
  12511. o.importComplete(xmld);
  12512. }
  12513. o.impstring = null;
  12514. }
  12515. xmld = null;
  12516. }
  12517. break;
  12518. case 'json':
  12519. alert("09");
  12520. $.ajax($.extend({
  12521. url:o.impurl,
  12522. type:o.mtype,
  12523. data: o.impData,
  12524. dataType:"json",
  12525. complete: function(json) {
  12526. try {
  12527. jsonConvert(json.responseText,o );
  12528. $($t).triggerHandler("jqGridImportComplete", [json, o]);
  12529. if($.isFunction(o.importComplete)) {
  12530. o.importComplete(json);
  12531. }
  12532. } catch (ee){}
  12533. json=null;
  12534. }
  12535. }, o.ajaxOptions ));
  12536. break;
  12537. case 'jsonstring' :
  12538. if(o.impstring && typeof o.impstring === 'string') {
  12539. jsonConvert(o.impstring,o );
  12540. $($t).triggerHandler("jqGridImportComplete", [o.impstring, o]);
  12541. if($.isFunction(o.importComplete)) {
  12542. o.importComplete(o.impstring);
  12543. }
  12544. o.impstring = null;
  12545. }
  12546. break;
  12547. }
  12548. });
  12549. },
  12550. jqGridExport : function(o) {
  12551. o = $.extend({
  12552. exptype : "xmlstring",
  12553. root: "grid",
  12554. ident: "\t"
  12555. }, o || {});
  12556. var ret = null;
  12557. this.each(function () {
  12558. if(!this.grid) { return;}
  12559. var key, gprm = $.extend(true, {},$(this).jqGrid("getGridParam"));
  12560. // we need to check for:
  12561. // 1.multiselect, 2.subgrid 3. treegrid and remove the unneded columns from colNames
  12562. if(gprm.rownumbers) {
  12563. gprm.colNames.splice(0,1);
  12564. gprm.colModel.splice(0,1);
  12565. }
  12566. if(gprm.multiselect) {
  12567. gprm.colNames.splice(0,1);
  12568. gprm.colModel.splice(0,1);
  12569. }
  12570. if(gprm.subGrid) {
  12571. gprm.colNames.splice(0,1);
  12572. gprm.colModel.splice(0,1);
  12573. }
  12574. gprm.knv = null;
  12575. if(gprm.treeGrid) {
  12576. for (key in gprm.treeReader) {
  12577. if(gprm.treeReader.hasOwnProperty(key)) {
  12578. gprm.colNames.splice(gprm.colNames.length-1);
  12579. gprm.colModel.splice(gprm.colModel.length-1);
  12580. }
  12581. }
  12582. }
  12583. switch (o.exptype) {
  12584. case 'xmlstring' :
  12585. ret = "<"+o.root+">"+xmlJsonClass.json2xml(gprm,o.ident)+"</"+o.root+">";
  12586. break;
  12587. case 'jsonstring' :
  12588. ret = "{"+ xmlJsonClass.toJson(gprm,o.root,o.ident,false)+"}";
  12589. if(gprm.postData.filters !== undefined) {
  12590. ret=ret.replace(/filters":"/,'filters":');
  12591. ret=ret.replace(/}]}"/,'}]}');
  12592. }
  12593. break;
  12594. }
  12595. });
  12596. return ret;
  12597. },
  12598. excelExport : function(o) {
  12599. o = $.extend({
  12600. exptype : "remote",
  12601. url : null,
  12602. oper: "oper",
  12603. tag: "excel",
  12604. exportOptions : {}
  12605. }, o || {});
  12606. return this.each(function(){
  12607. if(!this.grid) { return;}
  12608. var url;
  12609. if(o.exptype === "remote") {
  12610. var pdata = $.extend({},this.p.postData);
  12611. pdata[o.oper] = o.tag;
  12612. var params = jQuery.param(pdata);
  12613. if(o.url.indexOf("?") !== -1) { url = o.url+"&"+params; }
  12614. else { url = o.url+"?"+params; }
  12615. window.location = url;
  12616. }
  12617. });
  12618. }
  12619. });
  12620. })(jQuery);
  12621. /*jshint evil:true, eqeqeq:false, eqnull:true, devel:true */
  12622. /*global jQuery */
  12623. (function($){
  12624. /*
  12625. **
  12626. * jqGrid addons using jQuery UI
  12627. * Author: Mark Williams
  12628. * Dual licensed under the MIT and GPL licenses:
  12629. * http://www.opensource.org/licenses/mit-license.php
  12630. * http://www.gnu.org/licenses/gpl-2.0.html
  12631. * depends on jQuery UI
  12632. **/
  12633. "use strict";
  12634. if ($.jgrid.msie && $.jgrid.msiever()===8) {
  12635. $.expr[":"].hidden = function(elem) {
  12636. return elem.offsetWidth === 0 || elem.offsetHeight === 0 ||
  12637. elem.style.display === "none";
  12638. };
  12639. }
  12640. // requiere load multiselect before grid
  12641. $.jgrid._multiselect = false;
  12642. if($.ui) {
  12643. if ($.ui.multiselect ) {
  12644. if($.ui.multiselect.prototype._setSelected) {
  12645. var setSelected = $.ui.multiselect.prototype._setSelected;
  12646. $.ui.multiselect.prototype._setSelected = function(item,selected) {
  12647. var ret = setSelected.call(this,item,selected);
  12648. if (selected && this.selectedList) {
  12649. var elt = this.element;
  12650. this.selectedList.find('li').each(function() {
  12651. if ($(this).data('optionLink')) {
  12652. $(this).data('optionLink').remove().appendTo(elt);
  12653. }
  12654. });
  12655. }
  12656. return ret;
  12657. };
  12658. }
  12659. if($.ui.multiselect.prototype.destroy) {
  12660. $.ui.multiselect.prototype.destroy = function() {
  12661. this.element.show();
  12662. this.container.remove();
  12663. if ($.Widget === undefined) {
  12664. $.widget.prototype.destroy.apply(this, arguments);
  12665. } else {
  12666. $.Widget.prototype.destroy.apply(this, arguments);
  12667. }
  12668. };
  12669. }
  12670. $.jgrid._multiselect = true;
  12671. }
  12672. }
  12673. $.jgrid.extend({
  12674. sortableColumns : function (tblrow)
  12675. {
  12676. return this.each(function (){
  12677. var ts = this, tid= $.jgrid.jqID( ts.p.id );
  12678. function start() {ts.p.disableClick = true;}
  12679. var sortable_opts = {
  12680. "tolerance" : "pointer",
  12681. "axis" : "x",
  12682. "scrollSensitivity": "1",
  12683. "items": '>th:not(:has(#jqgh_'+tid+'_cb'+',#jqgh_'+tid+'_rn'+',#jqgh_'+tid+'_subgrid),:hidden)',
  12684. "placeholder": {
  12685. element: function(item) {
  12686. var el = $(document.createElement(item[0].nodeName))
  12687. .addClass(item[0].className+" ui-sortable-placeholder ui-state-highlight")
  12688. .removeClass("ui-sortable-helper")[0];
  12689. return el;
  12690. },
  12691. update: function(self, p) {
  12692. p.height(self.currentItem.innerHeight() - parseInt(self.currentItem.css('paddingTop')||0, 10) - parseInt(self.currentItem.css('paddingBottom')||0, 10));
  12693. p.width(self.currentItem.innerWidth() - parseInt(self.currentItem.css('paddingLeft')||0, 10) - parseInt(self.currentItem.css('paddingRight')||0, 10));
  12694. }
  12695. },
  12696. "update": function(event, ui) {
  12697. var p = $(ui.item).parent(),
  12698. th = $(">th", p),
  12699. colModel = ts.p.colModel,
  12700. cmMap = {}, tid= ts.p.id+"_";
  12701. $.each(colModel, function(i) { cmMap[this.name]=i; });
  12702. var permutation = [];
  12703. th.each(function() {
  12704. var id = $(">div", this).get(0).id.replace(/^jqgh_/, "").replace(tid,"");
  12705. if (cmMap.hasOwnProperty(id)) {
  12706. permutation.push(cmMap[id]);
  12707. }
  12708. });
  12709. $(ts).jqGrid("remapColumns",permutation, true, true);
  12710. if ($.isFunction(ts.p.sortable.update)) {
  12711. ts.p.sortable.update(permutation);
  12712. }
  12713. setTimeout(function(){ts.p.disableClick=false;}, 50);
  12714. }
  12715. };
  12716. if (ts.p.sortable.options) {
  12717. $.extend(sortable_opts, ts.p.sortable.options);
  12718. } else if ($.isFunction(ts.p.sortable)) {
  12719. ts.p.sortable = { "update" : ts.p.sortable };
  12720. }
  12721. if (sortable_opts.start) {
  12722. var s = sortable_opts.start;
  12723. sortable_opts.start = function(e,ui) {
  12724. start();
  12725. s.call(this,e,ui);
  12726. };
  12727. } else {
  12728. sortable_opts.start = start;
  12729. }
  12730. if (ts.p.sortable.exclude) {
  12731. sortable_opts.items += ":not("+ts.p.sortable.exclude+")";
  12732. }
  12733. tblrow.sortable(sortable_opts).data("sortable").floating = true;
  12734. });
  12735. },
  12736. columnChooser : function(opts) {
  12737. var self = this;
  12738. if($("#colchooser_"+$.jgrid.jqID(self[0].p.id)).length ) { return; }
  12739. var selector = $('<div id="colchooser_'+self[0].p.id+'" style="position:relative;overflow:hidden"><div><select multiple="multiple"></select></div></div>');
  12740. var select = $('select', selector);
  12741. function insert(perm,i,v) {
  12742. if(i>=0){
  12743. var a = perm.slice();
  12744. var b = a.splice(i,Math.max(perm.length-i,i));
  12745. if(i>perm.length) { i = perm.length; }
  12746. a[i] = v;
  12747. return a.concat(b);
  12748. }
  12749. }
  12750. opts = $.extend({
  12751. "width" : 420,
  12752. "height" : 240,
  12753. "classname" : null,
  12754. "done" : function(perm) { if (perm) { self.jqGrid("remapColumns", perm, true); } },
  12755. /* msel is either the name of a ui widget class that
  12756. extends a multiselect, or a function that supports
  12757. creating a multiselect object (with no argument,
  12758. or when passed an object), and destroying it (when
  12759. passed the string "destroy"). */
  12760. "msel" : "multiselect",
  12761. /* "msel_opts" : {}, */
  12762. /* dlog is either the name of a ui widget class that
  12763. behaves in a dialog-like way, or a function, that
  12764. supports creating a dialog (when passed dlog_opts)
  12765. or destroying a dialog (when passed the string
  12766. "destroy")
  12767. */
  12768. "dlog" : "dialog",
  12769. "dialog_opts" : {
  12770. "minWidth": 470
  12771. },
  12772. /* dlog_opts is either an option object to be passed
  12773. to "dlog", or (more likely) a function that creates
  12774. the options object.
  12775. The default produces a suitable options object for
  12776. ui.dialog */
  12777. "dlog_opts" : function(opts) {
  12778. var buttons = {};
  12779. buttons[opts.bSubmit] = function() {
  12780. opts.apply_perm();
  12781. opts.cleanup(false);
  12782. };
  12783. buttons[opts.bCancel] = function() {
  12784. opts.cleanup(true);
  12785. };
  12786. return $.extend(true, {
  12787. "buttons": buttons,
  12788. "close": function() {
  12789. opts.cleanup(true);
  12790. },
  12791. "modal" : opts.modal || false,
  12792. "resizable": opts.resizable || true,
  12793. "width": opts.width+20
  12794. }, opts.dialog_opts || {});
  12795. },
  12796. /* Function to get the permutation array, and pass it to the
  12797. "done" function */
  12798. "apply_perm" : function() {
  12799. $('option',select).each(function() {
  12800. if (this.selected) {
  12801. self.jqGrid("showCol", colModel[this.value].name);
  12802. } else {
  12803. self.jqGrid("hideCol", colModel[this.value].name);
  12804. }
  12805. });
  12806. var perm = [];
  12807. //fixedCols.slice(0);
  12808. $('option:selected',select).each(function() { perm.push(parseInt(this.value,10)); });
  12809. $.each(perm, function() { delete colMap[colModel[parseInt(this,10)].name]; });
  12810. $.each(colMap, function() {
  12811. var ti = parseInt(this,10);
  12812. perm = insert(perm,ti,ti);
  12813. });
  12814. if (opts.done) {
  12815. opts.done.call(self, perm);
  12816. }
  12817. },
  12818. /* Function to cleanup the dialog, and select. Also calls the
  12819. done function with no permutation (to indicate that the
  12820. columnChooser was aborted */
  12821. "cleanup" : function(calldone) {
  12822. call(opts.dlog, selector, 'destroy');
  12823. call(opts.msel, select, 'destroy');
  12824. selector.remove();
  12825. if (calldone && opts.done) {
  12826. opts.done.call(self);
  12827. }
  12828. },
  12829. "msel_opts" : {}
  12830. }, $.jgrid.col, opts || {});
  12831. if($.ui) {
  12832. if ($.ui.multiselect ) {
  12833. if(opts.msel === "multiselect") {
  12834. if(!$.jgrid._multiselect) {
  12835. // should be in language file
  12836. alert("Multiselect plugin loaded after jqGrid. Please load the plugin before the jqGrid!");
  12837. return;
  12838. }
  12839. opts.msel_opts = $.extend($.ui.multiselect.defaults,opts.msel_opts);
  12840. }
  12841. }
  12842. }
  12843. if (opts.caption) {
  12844. selector.attr("title", opts.caption);
  12845. }
  12846. if (opts.classname) {
  12847. selector.addClass(opts.classname);
  12848. select.addClass(opts.classname);
  12849. }
  12850. if (opts.width) {
  12851. $(">div",selector).css({"width": opts.width,"margin":"0 auto"});
  12852. select.css("width", opts.width);
  12853. }
  12854. if (opts.height) {
  12855. $(">div",selector).css("height", opts.height);
  12856. select.css("height", opts.height - 10);
  12857. }
  12858. var colModel = self.jqGrid("getGridParam", "colModel");
  12859. var colNames = self.jqGrid("getGridParam", "colNames");
  12860. var colMap = {}, fixedCols = [];
  12861. select.empty();
  12862. $.each(colModel, function(i) {
  12863. colMap[this.name] = i;
  12864. if (this.hidedlg) {
  12865. if (!this.hidden) {
  12866. fixedCols.push(i);
  12867. }
  12868. return;
  12869. }
  12870. select.append("<option value='"+i+"' "+
  12871. (this.hidden?"":"selected='selected'")+">"+$.jgrid.stripHtml(colNames[i])+"</option>");
  12872. });
  12873. function call(fn, obj) {
  12874. if (!fn) { return; }
  12875. if (typeof fn === 'string') {
  12876. if ($.fn[fn]) {
  12877. $.fn[fn].apply(obj, $.makeArray(arguments).slice(2));
  12878. }
  12879. } else if ($.isFunction(fn)) {
  12880. fn.apply(obj, $.makeArray(arguments).slice(2));
  12881. }
  12882. }
  12883. var dopts = $.isFunction(opts.dlog_opts) ? opts.dlog_opts.call(self, opts) : opts.dlog_opts;
  12884. call(opts.dlog, selector, dopts);
  12885. var mopts = $.isFunction(opts.msel_opts) ? opts.msel_opts.call(self, opts) : opts.msel_opts;
  12886. call(opts.msel, select, mopts);
  12887. },
  12888. sortableRows : function (opts) {
  12889. // Can accept all sortable options and events
  12890. return this.each(function(){
  12891. var $t = this;
  12892. if(!$t.grid) { return; }
  12893. // Currently we disable a treeGrid sortable
  12894. if($t.p.treeGrid) { return; }
  12895. if($.fn.sortable) {
  12896. opts = $.extend({
  12897. "cursor":"move",
  12898. "axis" : "y",
  12899. "items": ".jqgrow"
  12900. },
  12901. opts || {});
  12902. if(opts.start && $.isFunction(opts.start)) {
  12903. opts._start_ = opts.start;
  12904. delete opts.start;
  12905. } else {opts._start_=false;}
  12906. if(opts.update && $.isFunction(opts.update)) {
  12907. opts._update_ = opts.update;
  12908. delete opts.update;
  12909. } else {opts._update_ = false;}
  12910. opts.start = function(ev,ui) {
  12911. $(ui.item).css("border-width","0");
  12912. $("td",ui.item).each(function(i){
  12913. this.style.width = $t.grid.cols[i].style.width;
  12914. });
  12915. if($t.p.subGrid) {
  12916. var subgid = $(ui.item).attr("id");
  12917. try {
  12918. $($t).jqGrid('collapseSubGridRow',subgid);
  12919. } catch (e) {}
  12920. }
  12921. if(opts._start_) {
  12922. opts._start_.apply(this,[ev,ui]);
  12923. }
  12924. };
  12925. opts.update = function (ev,ui) {
  12926. $(ui.item).css("border-width","");
  12927. if($t.p.rownumbers === true) {
  12928. $("td.jqgrid-rownum",$t.rows).each(function( i ){
  12929. $(this).html( i+1+(parseInt($t.p.page,10)-1)*parseInt($t.p.rowNum,10) );
  12930. });
  12931. }
  12932. if(opts._update_) {
  12933. opts._update_.apply(this,[ev,ui]);
  12934. }
  12935. };
  12936. $("tbody:first",$t).sortable(opts);
  12937. $("tbody:first",$t).disableSelection();
  12938. }
  12939. });
  12940. },
  12941. gridDnD : function(opts) {
  12942. return this.each(function(){
  12943. var $t = this, i, cn;
  12944. if(!$t.grid) { return; }
  12945. // Currently we disable a treeGrid drag and drop
  12946. if($t.p.treeGrid) { return; }
  12947. if(!$.fn.draggable || !$.fn.droppable) { return; }
  12948. function updateDnD ()
  12949. {
  12950. var datadnd = $.data($t,"dnd");
  12951. $("tr.jqgrow:not(.ui-draggable)",$t).draggable($.isFunction(datadnd.drag) ? datadnd.drag.call($($t),datadnd) : datadnd.drag);
  12952. }
  12953. var appender = "<table id='jqgrid_dnd' class='ui-jqgrid-dnd'></table>";
  12954. if($("#jqgrid_dnd")[0] === undefined) {
  12955. $('body').append(appender);
  12956. }
  12957. if(typeof opts === 'string' && opts === 'updateDnD' && $t.p.jqgdnd===true) {
  12958. updateDnD();
  12959. return;
  12960. }
  12961. opts = $.extend({
  12962. "drag" : function (opts) {
  12963. return $.extend({
  12964. start : function (ev, ui) {
  12965. var i, subgid;
  12966. // if we are in subgrid mode try to collapse the node
  12967. if($t.p.subGrid) {
  12968. subgid = $(ui.helper).attr("id");
  12969. try {
  12970. $($t).jqGrid('collapseSubGridRow',subgid);
  12971. } catch (e) {}
  12972. }
  12973. // hack
  12974. // drag and drop does not insert tr in table, when the table has no rows
  12975. // we try to insert new empty row on the target(s)
  12976. for (i=0;i<$.data($t,"dnd").connectWith.length;i++){
  12977. if($($.data($t,"dnd").connectWith[i]).jqGrid('getGridParam','reccount') === 0 ){
  12978. $($.data($t,"dnd").connectWith[i]).jqGrid('addRowData','jqg_empty_row',{});
  12979. }
  12980. }
  12981. ui.helper.addClass("ui-state-highlight");
  12982. $("td",ui.helper).each(function(i) {
  12983. this.style.width = $t.grid.headers[i].width+"px";
  12984. });
  12985. if(opts.onstart && $.isFunction(opts.onstart) ) { opts.onstart.call($($t),ev,ui); }
  12986. },
  12987. stop :function(ev,ui) {
  12988. var i, ids;
  12989. if(ui.helper.dropped && !opts.dragcopy) {
  12990. ids = $(ui.helper).attr("id");
  12991. if(ids === undefined) { ids = $(this).attr("id"); }
  12992. $($t).jqGrid('delRowData',ids );
  12993. }
  12994. // if we have a empty row inserted from start event try to delete it
  12995. for (i=0;i<$.data($t,"dnd").connectWith.length;i++){
  12996. $($.data($t,"dnd").connectWith[i]).jqGrid('delRowData','jqg_empty_row');
  12997. }
  12998. if(opts.onstop && $.isFunction(opts.onstop) ) { opts.onstop.call($($t),ev,ui); }
  12999. }
  13000. },opts.drag_opts || {});
  13001. },
  13002. "drop" : function (opts) {
  13003. return $.extend({
  13004. accept: function(d) {
  13005. if (!$(d).hasClass('jqgrow')) { return d;}
  13006. var tid = $(d).closest("table.ui-jqgrid-btable");
  13007. if(tid.length > 0 && $.data(tid[0],"dnd") !== undefined) {
  13008. var cn = $.data(tid[0],"dnd").connectWith;
  13009. return $.inArray('#'+$.jgrid.jqID(this.id),cn) !== -1 ? true : false;
  13010. }
  13011. return false;
  13012. },
  13013. drop: function(ev, ui) {
  13014. if (!$(ui.draggable).hasClass('jqgrow')) { return; }
  13015. var accept = $(ui.draggable).attr("id");
  13016. var getdata = ui.draggable.parent().parent().jqGrid('getRowData',accept);
  13017. if(!opts.dropbyname) {
  13018. var j =0, tmpdata = {}, nm, key;
  13019. var dropmodel = $("#"+$.jgrid.jqID(this.id)).jqGrid('getGridParam','colModel');
  13020. try {
  13021. for (key in getdata) {
  13022. if (getdata.hasOwnProperty(key)) {
  13023. nm = dropmodel[j].name;
  13024. if( !(nm === 'cb' || nm === 'rn' || nm === 'subgrid' )) {
  13025. if(getdata.hasOwnProperty(key) && dropmodel[j]) {
  13026. tmpdata[nm] = getdata[key];
  13027. }
  13028. }
  13029. j++;
  13030. }
  13031. }
  13032. getdata = tmpdata;
  13033. } catch (e) {}
  13034. }
  13035. ui.helper.dropped = true;
  13036. if(opts.beforedrop && $.isFunction(opts.beforedrop) ) {
  13037. //parameters to this callback - event, element, data to be inserted, sender, reciever
  13038. // should return object which will be inserted into the reciever
  13039. var datatoinsert = opts.beforedrop.call(this,ev,ui,getdata,$('#'+$.jgrid.jqID($t.p.id)),$(this));
  13040. if (datatoinsert !== undefined && datatoinsert !== null && typeof datatoinsert === "object") { getdata = datatoinsert; }
  13041. }
  13042. if(ui.helper.dropped) {
  13043. var grid;
  13044. if(opts.autoid) {
  13045. if($.isFunction(opts.autoid)) {
  13046. grid = opts.autoid.call(this,getdata);
  13047. } else {
  13048. grid = Math.ceil(Math.random()*1000);
  13049. grid = opts.autoidprefix+grid;
  13050. }
  13051. }
  13052. // NULL is interpreted as undefined while null as object
  13053. $("#"+$.jgrid.jqID(this.id)).jqGrid('addRowData',grid,getdata,opts.droppos);
  13054. }
  13055. if(opts.ondrop && $.isFunction(opts.ondrop) ) { opts.ondrop.call(this,ev,ui, getdata); }
  13056. }}, opts.drop_opts || {});
  13057. },
  13058. "onstart" : null,
  13059. "onstop" : null,
  13060. "beforedrop": null,
  13061. "ondrop" : null,
  13062. "drop_opts" : {
  13063. "activeClass": "ui-state-active",
  13064. "hoverClass": "ui-state-hover"
  13065. },
  13066. "drag_opts" : {
  13067. "revert": "invalid",
  13068. "helper": "clone",
  13069. "cursor": "move",
  13070. "appendTo" : "#jqgrid_dnd",
  13071. "zIndex": 5000
  13072. },
  13073. "dragcopy": false,
  13074. "dropbyname" : false,
  13075. "droppos" : "first",
  13076. "autoid" : true,
  13077. "autoidprefix" : "dnd_"
  13078. }, opts || {});
  13079. if(!opts.connectWith) { return; }
  13080. opts.connectWith = opts.connectWith.split(",");
  13081. opts.connectWith = $.map(opts.connectWith,function(n){return $.trim(n);});
  13082. $.data($t,"dnd",opts);
  13083. if($t.p.reccount !== 0 && !$t.p.jqgdnd) {
  13084. updateDnD();
  13085. }
  13086. $t.p.jqgdnd = true;
  13087. for (i=0;i<opts.connectWith.length;i++){
  13088. cn =opts.connectWith[i];
  13089. $(cn).droppable($.isFunction(opts.drop) ? opts.drop.call($($t),opts) : opts.drop);
  13090. }
  13091. });
  13092. },
  13093. gridResize : function(opts) {
  13094. return this.each(function(){
  13095. var $t = this, gID = $.jgrid.jqID($t.p.id);
  13096. if(!$t.grid || !$.fn.resizable) { return; }
  13097. opts = $.extend({}, opts || {});
  13098. if(opts.alsoResize ) {
  13099. opts._alsoResize_ = opts.alsoResize;
  13100. delete opts.alsoResize;
  13101. } else {
  13102. opts._alsoResize_ = false;
  13103. }
  13104. if(opts.stop && $.isFunction(opts.stop)) {
  13105. opts._stop_ = opts.stop;
  13106. delete opts.stop;
  13107. } else {
  13108. opts._stop_ = false;
  13109. }
  13110. opts.stop = function (ev, ui) {
  13111. $($t).jqGrid('setGridParam',{height:$("#gview_"+gID+" .ui-jqgrid-bdiv").height()});
  13112. $($t).jqGrid('setGridWidth',ui.size.width,opts.shrinkToFit);
  13113. if(opts._stop_) { opts._stop_.call($t,ev,ui); }
  13114. };
  13115. if(opts._alsoResize_) {
  13116. var optstest = "{\'#gview_"+gID+" .ui-jqgrid-bdiv\':true,'" +opts._alsoResize_+"':true}";
  13117. opts.alsoResize = eval('('+optstest+')'); // the only way that I found to do this
  13118. } else {
  13119. opts.alsoResize = $(".ui-jqgrid-bdiv","#gview_"+gID);
  13120. }
  13121. delete opts._alsoResize_;
  13122. $("#gbox_"+gID).resizable(opts);
  13123. });
  13124. }
  13125. });
  13126. })(jQuery);
  13127. /*
  13128. Transform a table to a jqGrid.
  13129. Peter Romianowski <peter.romianowski@optivo.de>
  13130. If the first column of the table contains checkboxes or
  13131. radiobuttons then the jqGrid is made selectable.
  13132. */
  13133. // Addition - selector can be a class or id
  13134. function tableToGrid(selector, options) {
  13135. jQuery(selector).each(function() {
  13136. if(this.grid) {return;} //Adedd from Tony Tomov
  13137. // This is a small "hack" to make the width of the jqGrid 100%
  13138. jQuery(this).width("99%");
  13139. var w = jQuery(this).width();
  13140. // Text whether we have single or multi select
  13141. var inputCheckbox = jQuery('tr td:first-child input[type=checkbox]:first', jQuery(this));
  13142. var inputRadio = jQuery('tr td:first-child input[type=radio]:first', jQuery(this));
  13143. var selectMultiple = inputCheckbox.length > 0;
  13144. var selectSingle = !selectMultiple && inputRadio.length > 0;
  13145. var selectable = selectMultiple || selectSingle;
  13146. //var inputName = inputCheckbox.attr("name") || inputRadio.attr("name");
  13147. // Build up the columnModel and the data
  13148. var colModel = [];
  13149. var colNames = [];
  13150. jQuery('th', jQuery(this)).each(function() {
  13151. if (colModel.length === 0 && selectable) {
  13152. colModel.push({
  13153. name: '__selection__',
  13154. index: '__selection__',
  13155. width: 0,
  13156. hidden: true
  13157. });
  13158. colNames.push('__selection__');
  13159. } else {
  13160. colModel.push({
  13161. name: jQuery(this).attr("id") || jQuery.trim(jQuery.jgrid.stripHtml(jQuery(this).html())).split(' ').join('_'),
  13162. index: jQuery(this).attr("id") || jQuery.trim(jQuery.jgrid.stripHtml(jQuery(this).html())).split(' ').join('_'),
  13163. width: jQuery(this).width() || 150
  13164. });
  13165. colNames.push(jQuery(this).html());
  13166. }
  13167. });
  13168. var data = [];
  13169. var rowIds = [];
  13170. var rowChecked = [];
  13171. jQuery('tbody > tr', jQuery(this)).each(function() {
  13172. var row = {};
  13173. var rowPos = 0;
  13174. jQuery('td', jQuery(this)).each(function() {
  13175. if (rowPos === 0 && selectable) {
  13176. var input = jQuery('input', jQuery(this));
  13177. var rowId = input.attr("value");
  13178. rowIds.push(rowId || data.length);
  13179. if (input.is(":checked")) {
  13180. rowChecked.push(rowId);
  13181. }
  13182. row[colModel[rowPos].name] = input.attr("value");
  13183. } else {
  13184. row[colModel[rowPos].name] = jQuery(this).html();
  13185. }
  13186. rowPos++;
  13187. });
  13188. if(rowPos >0) { data.push(row); }
  13189. });
  13190. // Clear the original HTML table
  13191. jQuery(this).empty();
  13192. // Mark it as jqGrid
  13193. jQuery(this).addClass("scroll");
  13194. jQuery(this).jqGrid(jQuery.extend({
  13195. datatype: "local",
  13196. width: w,
  13197. colNames: colNames,
  13198. colModel: colModel,
  13199. multiselect: selectMultiple
  13200. //inputName: inputName,
  13201. //inputValueCol: imputName != null ? "__selection__" : null
  13202. }, options || {}));
  13203. // Add data
  13204. var a;
  13205. for (a = 0; a < data.length; a++) {
  13206. var id = null;
  13207. if (rowIds.length > 0) {
  13208. id = rowIds[a];
  13209. if (id && id.replace) {
  13210. // We have to do this since the value of a checkbox
  13211. // or radio button can be anything
  13212. id = encodeURIComponent(id).replace(/[.\-%]/g, "_");
  13213. }
  13214. }
  13215. if (id === null) {
  13216. id = a + 1;
  13217. }
  13218. jQuery(this).jqGrid("addRowData",id, data[a]);
  13219. }
  13220. // Set the selection
  13221. for (a = 0; a < rowChecked.length; a++) {
  13222. jQuery(this).jqGrid("setSelection",rowChecked[a]);
  13223. }
  13224. });
  13225. };
  13226. /*jshint eqeqeq:false */
  13227. /*global jQuery */
  13228. (function($){
  13229. /**
  13230. * jqGrid pivot functions
  13231. * Tony Tomov tony@trirand.com
  13232. * http://trirand.com/blog/
  13233. * Dual licensed under the MIT and GPL licenses:
  13234. * http://www.opensource.org/licenses/mit-license.php
  13235. * http://www.gnu.org/licenses/gpl-2.0.html
  13236. */
  13237. "use strict";
  13238. // To optimize the search we need custom array filter
  13239. // This code is taken from
  13240. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter
  13241. function _pivotfilter (fn, context) {
  13242. var i,
  13243. value,
  13244. result = [],
  13245. length;
  13246. if (!this || typeof fn !== 'function' || (fn instanceof RegExp)) {
  13247. throw new TypeError();
  13248. }
  13249. length = this.length;
  13250. for (i = 0; i < length; i++) {
  13251. if (this.hasOwnProperty(i)) {
  13252. value = this[i];
  13253. if (fn.call(context, value, i, this)) {
  13254. result.push(value);
  13255. // We need break in order to cancel loop
  13256. // in case the row is found
  13257. break;
  13258. }
  13259. }
  13260. }
  13261. return result;
  13262. }
  13263. $.assocArraySize = function(obj) {
  13264. // http://stackoverflow.com/a/6700/11236
  13265. var size = 0, key;
  13266. for (key in obj) {
  13267. if (obj.hasOwnProperty(key)) {
  13268. size++;
  13269. }
  13270. }
  13271. return size;
  13272. };
  13273. $.jgrid.extend({
  13274. pivotSetup : function( data, options ){
  13275. // data should come in json format
  13276. // The function return the new colModel and the transformed data
  13277. // again with group setup options which then will be passed to the grid
  13278. var columns =[],
  13279. pivotrows =[],
  13280. summaries = [],
  13281. member=[],
  13282. groupOptions = {
  13283. grouping : true,
  13284. groupingView : {
  13285. groupField : [],
  13286. groupSummary: [],
  13287. groupSummaryPos:[]
  13288. }
  13289. },
  13290. headers = [],
  13291. o = $.extend ( {
  13292. rowTotals : false,
  13293. rowTotalsText : 'Total',
  13294. // summary columns
  13295. colTotals : false,
  13296. groupSummary : true,
  13297. groupSummaryPos : 'header',
  13298. frozenStaticCols : false
  13299. }, options || {});
  13300. this.each(function(){
  13301. var
  13302. row,
  13303. rowindex,
  13304. i,
  13305. rowlen = data.length,
  13306. xlen, ylen, aggrlen,
  13307. tmp,
  13308. newObj,
  13309. r=0;
  13310. // utility funcs
  13311. /*
  13312. * Filter the data to a given criteria. Return the firt occurance
  13313. */
  13314. function find(ar, fun, extra) {
  13315. var res;
  13316. res = _pivotfilter.call(ar, fun, extra);
  13317. return res.length > 0 ? res[0] : null;
  13318. }
  13319. /*
  13320. * Check if the grouped row column exist (See find)
  13321. * If the row is not find in pivot rows retun null,
  13322. * otherviese the column
  13323. */
  13324. function findGroup(item, index) {
  13325. var j = 0, ret = true, i;
  13326. for(i in item) {
  13327. if(item[i] != this[j]) {
  13328. ret = false;
  13329. break;
  13330. }
  13331. j++;
  13332. if(j>=this.length) {
  13333. break;
  13334. }
  13335. }
  13336. if(ret) {
  13337. rowindex = index;
  13338. }
  13339. return ret;
  13340. }
  13341. /*
  13342. * Perform calculations of the pivot values.
  13343. */
  13344. function calculation(oper, v, field, rc) {
  13345. var ret;
  13346. switch (oper) {
  13347. case "sum" :
  13348. ret = parseFloat(v||0) + parseFloat((rc[field]||0));
  13349. break;
  13350. case "count" :
  13351. if(v==="" || v == null) {
  13352. v=0;
  13353. }
  13354. if(rc.hasOwnProperty(field)) {
  13355. ret = v+1;
  13356. } else {
  13357. ret = 0;
  13358. }
  13359. break;
  13360. case "min" :
  13361. if(v==="" || v == null) {
  13362. ret = parseFloat(rc[field]||0);
  13363. } else {
  13364. ret =Math.min(parseFloat(v),parseFloat(rc[field]||0));
  13365. }
  13366. break;
  13367. case "max" :
  13368. if(v==="" || v == null) {
  13369. ret = parseFloat(rc[field]||0);
  13370. } else {
  13371. ret = Math.max(parseFloat(v),parseFloat(rc[field]||0));
  13372. }
  13373. break;
  13374. }
  13375. return ret;
  13376. }
  13377. /*
  13378. * The function agragates the values of the pivot grid.
  13379. * Return the current row with pivot summary values
  13380. */
  13381. function agregateFunc ( row, aggr, value, curr) {
  13382. // default is sum
  13383. var arrln = aggr.length, i, label, j, jv;
  13384. if($.isArray(value)) {
  13385. jv = value.length;
  13386. } else {
  13387. jv = 1;
  13388. }
  13389. member = [];
  13390. member.root = 0;
  13391. for(j=0;j<jv;j++) {
  13392. var tmpmember = [], vl;
  13393. for(i=0; i < arrln; i++) {
  13394. if(value == null) {
  13395. label = $.trim(aggr[i].member)+"_"+aggr[i].aggregator;
  13396. vl = label;
  13397. } else {
  13398. vl = value[j].replace(/\s+/g, '');
  13399. try {
  13400. label = (arrln === 1 ? vl : vl+"_"+aggr[i].aggregator+"_"+i);
  13401. } catch(e) {}
  13402. }
  13403. label = !isNaN(parseInt(label,10)) ? label + " " : label;
  13404. curr[label] = tmpmember[label] = calculation( aggr[i].aggregator, curr[label], aggr[i].member, row);
  13405. }
  13406. vl = !isNaN(parseInt(vl,10)) ? vl + " " : vl;
  13407. member[vl] = tmpmember;
  13408. }
  13409. return curr;
  13410. }
  13411. // Making the row totals without to add in yDimension
  13412. if(o.rowTotals && o.yDimension.length > 0) {
  13413. var dn = o.yDimension[0].dataName;
  13414. o.yDimension.splice(0,0,{dataName:dn});
  13415. o.yDimension[0].converter = function(){ return '_r_Totals'; };
  13416. }
  13417. // build initial columns (colModel) from xDimension
  13418. xlen = $.isArray(o.xDimension) ? o.xDimension.length : 0;
  13419. ylen = o.yDimension.length;
  13420. aggrlen = $.isArray(o.aggregates) ? o.aggregates.length : 0;
  13421. if(xlen === 0 || aggrlen === 0) {
  13422. throw("xDimension or aggregates optiona are not set!");
  13423. }
  13424. var colc;
  13425. for(i = 0; i< xlen; i++) {
  13426. colc = {name:o.xDimension[i].dataName, frozen: o.frozenStaticCols};
  13427. if(o.xDimension[i].isGroupField == null) {
  13428. o.xDimension[i].isGroupField = true;
  13429. }
  13430. colc = $.extend(true, colc, o.xDimension[i]);
  13431. columns.push( colc );
  13432. }
  13433. var groupfields = xlen - 1, tree={};
  13434. //tree = { text: 'root', leaf: false, children: [] };
  13435. //loop over alll the source data
  13436. while( r < rowlen ) {
  13437. row = data[r];
  13438. var xValue = [];
  13439. var yValue = [];
  13440. tmp = {};
  13441. i = 0;
  13442. // build the data from xDimension
  13443. do {
  13444. xValue[i] = $.trim(row[o.xDimension[i].dataName]);
  13445. tmp[o.xDimension[i].dataName] = xValue[i];
  13446. i++;
  13447. } while( i < xlen );
  13448. var k = 0;
  13449. rowindex = -1;
  13450. // check to see if the row is in our new pivotrow set
  13451. newObj = find(pivotrows, findGroup, xValue);
  13452. if(!newObj) {
  13453. // if the row is not in our set
  13454. k = 0;
  13455. // if yDimension is set
  13456. if(ylen>=1) {
  13457. // build the cols set in yDimension
  13458. for(k=0;k<ylen;k++) {
  13459. yValue[k] = $.trim(row[o.yDimension[k].dataName]);
  13460. // Check to see if we have user defined conditions
  13461. if(o.yDimension[k].converter && $.isFunction(o.yDimension[k].converter)) {
  13462. yValue[k] = o.yDimension[k].converter.call(this, yValue[k], xValue, yValue);
  13463. }
  13464. }
  13465. // make the colums based on aggregates definition
  13466. // and return the members for late calculation
  13467. tmp = agregateFunc( row, o.aggregates, yValue, tmp );
  13468. } else if( ylen === 0 ) {
  13469. // if not set use direct the aggregates
  13470. tmp = agregateFunc( row, o.aggregates, null, tmp );
  13471. }
  13472. // add the result in pivot rows
  13473. pivotrows.push( tmp );
  13474. } else {
  13475. // the pivot exists
  13476. if( rowindex >= 0) {
  13477. k = 0;
  13478. // make the recalculations
  13479. if(ylen>=1) {
  13480. for(k=0;k<ylen;k++) {
  13481. yValue[k] = $.trim(row[o.yDimension[k].dataName]);
  13482. if(o.yDimension[k].converter && $.isFunction(o.yDimension[k].converter)) {
  13483. yValue[k] = o.yDimension[k].converter.call(this, yValue[k], xValue, yValue);
  13484. }
  13485. }
  13486. newObj = agregateFunc( row, o.aggregates, yValue, newObj );
  13487. } else if( ylen === 0 ) {
  13488. newObj = agregateFunc( row, o.aggregates, null, newObj );
  13489. }
  13490. // update the row
  13491. pivotrows[rowindex] = newObj;
  13492. }
  13493. }
  13494. var kj=0, current = null,existing = null, kk;
  13495. // Build a JSON tree from the member (see aggregateFunc)
  13496. // to make later the columns
  13497. //
  13498. for (kk in member) {
  13499. if(kj === 0) {
  13500. if (!tree.children||tree.children === undefined){
  13501. tree = { text: kk, level : 0, children: [] };
  13502. }
  13503. current = tree.children;
  13504. } else {
  13505. existing = null;
  13506. for (i=0; i < current.length; i++) {
  13507. if (current[i].text === kk) {
  13508. //current[i].fields=member[kk];
  13509. existing = current[i];
  13510. break;
  13511. }
  13512. }
  13513. if (existing) {
  13514. current = existing.children;
  13515. } else {
  13516. current.push({ children: [], text: kk, level: kj, fields: member[kk] });
  13517. current = current[current.length - 1].children;
  13518. }
  13519. }
  13520. kj++;
  13521. }
  13522. r++;
  13523. }
  13524. var lastval=[], initColLen = columns.length, swaplen = initColLen;
  13525. if(ylen>0) {
  13526. headers[ylen-1] = { useColSpanStyle: false, groupHeaders: []};
  13527. }
  13528. /*
  13529. * Recursive function which uses the tree to build the
  13530. * columns from the pivot values and set the group Headers
  13531. */
  13532. function list(items) {
  13533. var l, j, key, k, col;
  13534. for (key in items) { // iterate
  13535. if (items.hasOwnProperty(key)) {
  13536. // write amount of spaces according to level
  13537. // and write name and newline
  13538. if(typeof items[key] !== "object") {
  13539. // If not a object build the header of the appropriate level
  13540. if( key === 'level') {
  13541. if(lastval[items.level] === undefined) {
  13542. lastval[items.level] ='';
  13543. if(items.level>0 && items.text !== '_r_Totals') {
  13544. headers[items.level-1] = {
  13545. useColSpanStyle: false,
  13546. groupHeaders: []
  13547. };
  13548. }
  13549. }
  13550. if(lastval[items.level] !== items.text && items.children.length && items.text !== '_r_Totals') {
  13551. if(items.level>0) {
  13552. headers[items.level-1].groupHeaders.push({
  13553. titleText: items.text
  13554. });
  13555. var collen = headers[items.level-1].groupHeaders.length,
  13556. colpos = collen === 1 ? swaplen : initColLen+(collen-1)*aggrlen;
  13557. headers[items.level-1].groupHeaders[collen-1].startColumnName = columns[colpos].name;
  13558. headers[items.level-1].groupHeaders[collen-1].numberOfColumns = columns.length - colpos;
  13559. initColLen = columns.length;
  13560. }
  13561. }
  13562. lastval[items.level] = items.text;
  13563. }
  13564. // This is in case when the member contain more than one summary item
  13565. if(items.level === ylen && key==='level' && ylen >0) {
  13566. if( aggrlen > 1){
  13567. var ll=1;
  13568. for( l in items.fields) {
  13569. if(ll===1) {
  13570. headers[ylen-1].groupHeaders.push({startColumnName: l, numberOfColumns: 1, titleText: items.text});
  13571. }
  13572. ll++;
  13573. }
  13574. headers[ylen-1].groupHeaders[headers[ylen-1].groupHeaders.length-1].numberOfColumns = ll-1;
  13575. } else {
  13576. headers.splice(ylen-1,1);
  13577. }
  13578. }
  13579. }
  13580. // if object, call recursively
  13581. if (items[key] != null && typeof items[key] === "object") {
  13582. list(items[key]);
  13583. }
  13584. // Finally build the coulumns
  13585. if( key === 'level') {
  13586. if(items.level >0){
  13587. j=0;
  13588. for(l in items.fields) {
  13589. col = {};
  13590. for(k in o.aggregates[j]) {
  13591. if(o.aggregates[j].hasOwnProperty(k)) {
  13592. switch( k ) {
  13593. case 'member':
  13594. case 'label':
  13595. case 'aggregator':
  13596. break;
  13597. default:
  13598. col[k] = o.aggregates[j][k];
  13599. }
  13600. }
  13601. }
  13602. if(aggrlen>1) {
  13603. col.name = l;
  13604. col.label = o.aggregates[j].label || l;
  13605. } else {
  13606. col.name = items.text;
  13607. col.label = items.text==='_r_Totals' ? o.rowTotalsText : items.text;
  13608. }
  13609. columns.push (col);
  13610. j++;
  13611. }
  13612. }
  13613. }
  13614. }
  13615. }
  13616. }
  13617. list(tree, 0);
  13618. var nm;
  13619. // loop again trougth the pivot rows in order to build grand total
  13620. if(o.colTotals) {
  13621. var plen = pivotrows.length;
  13622. while(plen--) {
  13623. for(i=xlen;i<columns.length;i++) {
  13624. nm = columns[i].name;
  13625. if(!summaries[nm]) {
  13626. summaries[nm] = parseFloat(pivotrows[plen][nm] || 0);
  13627. } else {
  13628. summaries[nm] += parseFloat(pivotrows[plen][nm] || 0);
  13629. }
  13630. }
  13631. }
  13632. }
  13633. // based on xDimension levels build grouping
  13634. if( groupfields > 0) {
  13635. for(i=0;i<groupfields;i++) {
  13636. if(columns[i].isGroupField) {
  13637. groupOptions.groupingView.groupField.push(columns[i].name);
  13638. groupOptions.groupingView.groupSummary.push(o.groupSummary);
  13639. groupOptions.groupingView.groupSummaryPos.push(o.groupSummaryPos);
  13640. }
  13641. }
  13642. } else {
  13643. // no grouping is needed
  13644. groupOptions.grouping = false;
  13645. }
  13646. groupOptions.sortname = columns[groupfields].name;
  13647. groupOptions.groupingView.hideFirstGroupCol = true;
  13648. });
  13649. // return the final result.
  13650. return { "colModel" : columns, "rows": pivotrows, "groupOptions" : groupOptions, "groupHeaders" : headers, summary : summaries };
  13651. },
  13652. jqPivot : function( data, pivotOpt, gridOpt, ajaxOpt) {
  13653. return this.each(function(){
  13654. var $t = this;
  13655. function pivot( data) {
  13656. var pivotGrid = jQuery($t).jqGrid('pivotSetup',data, pivotOpt),
  13657. footerrow = $.assocArraySize(pivotGrid.summary) > 0 ? true : false,
  13658. query= $.jgrid.from(pivotGrid.rows), i;
  13659. for(i=0; i< pivotGrid.groupOptions.groupingView.groupField.length; i++) {
  13660. query.orderBy(pivotGrid.groupOptions.groupingView.groupField[i], "a", 'text', '');
  13661. }
  13662. jQuery($t).jqGrid($.extend(true, {
  13663. datastr: $.extend(query.select(),footerrow ? {userdata:pivotGrid.summary} : {}),
  13664. datatype: "jsonstring",
  13665. footerrow : footerrow,
  13666. userDataOnFooter: footerrow,
  13667. colModel: pivotGrid.colModel,
  13668. viewrecords: true,
  13669. sortname: pivotOpt.xDimension[0].dataName // ?????
  13670. }, pivotGrid.groupOptions, gridOpt || {}));
  13671. var gHead = pivotGrid.groupHeaders;
  13672. if(gHead.length) {
  13673. for( i = 0;i < gHead.length ; i++) {
  13674. if(gHead[i] && gHead[i].groupHeaders.length) {
  13675. jQuery($t).jqGrid('setGroupHeaders',gHead[i]);
  13676. }
  13677. }
  13678. }
  13679. if(pivotOpt.frozenStaticCols) {
  13680. jQuery($t).jqGrid("setFrozenColumns");
  13681. }
  13682. }
  13683. if(typeof data === "string") {
  13684. //alert("10");
  13685. $.ajax($.extend({
  13686. url : data,
  13687. dataType: 'json',
  13688. success : function(response) {
  13689. pivot($.jgrid.getAccessor(response, ajaxOpt && ajaxOpt.reader ? ajaxOpt.reader: 'rows') );
  13690. }
  13691. }, ajaxOpt || {}) );
  13692. } else {
  13693. pivot( data );
  13694. }
  13695. });
  13696. }
  13697. });
  13698. })(jQuery);
  13699. function downfile(opts, type) {
  13700. var typeMap = {
  13701. 'EXCEL' : {
  13702. 'serviceId' : 'gltExcelService',
  13703. method : 'exportGlt'
  13704. },
  13705. 'CSV' : {
  13706. 'serviceId' : 'csvService',
  13707. method : 'exportFile'
  13708. },'ET' : {
  13709. 'serviceId' : 'etService',
  13710. method : 'exportGlt'
  13711. },'XLSX' : {
  13712. 'serviceId' : 'gltExcel2007Service',
  13713. method : 'exportGlt'
  13714. },'PDF' : {
  13715. 'serviceId' : 'gltPdfService',
  13716. method : 'exportGlt'
  13717. }
  13718. };
  13719. if (!typeMap[type]) {
  13720. CFW.oWin.fnAlert('类型' + type + '目前没有导出选项');
  13721. return;
  13722. }
  13723. var listWhereCls = [ opts.whereCls ];
  13724. var param = {
  13725. listWhereCls : opts.whereCls,
  13726. configId : opts.confid,
  13727. _ds : opts.dsId,
  13728. dynDictWhereCls : JSON.stringify(opts.dynDictWhereCls),
  13729. _t : new Date().getTime(),
  13730. '_multiple' : [ 'listWhereCls' ].join(',')
  13731. };
  13732. try{
  13733. eval(' var InterceptorFun = '+ opts.confid+"_downfile;");
  13734. } catch(e) {}
  13735. var downFileName = "";
  13736. //调用自定义过渡方法
  13737. if (typeof (InterceptorFun) == 'function'){
  13738. try{
  13739. downFileName = InterceptorFun(opts.confid) ;
  13740. }catch(ex){
  13741. CFW.oWin.fnAlert(ex.message);
  13742. }
  13743. }
  13744. param['cusName'] = downFileName;
  13745. $.extend(param, typeMap[type]);
  13746. CFW.oComm.fnSendRequest(contextPath + '/downFile.do',param);
  13747. }
  13748. function callEvent(sFunName){
  13749. var callBackFunction = window[sFunName];
  13750. if(callBackFunction&&typeof(callBackFunction)=="function"){ callBackFunction(); }
  13751. }
  13752. //跨页全选-设置checkbox是否选中 2011-11-08
  13753. function setCheckBoxDb(mutldbId,key,checked){
  13754. if(true == checked){//选中
  13755. //同步选择项到数据库
  13756. new Service({
  13757. serviceId:"mutlSelectService",
  13758. method:"addOne",
  13759. parameters:{TABLE_NAME:"fw_mutl_select",ID:mutldbId,VALUE:key}
  13760. }).sentAjax('同步选择项到数据库',function(data){
  13761. })
  13762. }else{//取消选中
  13763. //同步选择项到数据库
  13764. new Service({
  13765. serviceId:"mutlSelectService",
  13766. method:"delOne",
  13767. parameters:{TABLE_NAME:"fw_mutl_select",ID:mutldbId,VALUE:key}
  13768. }).sentAjax('同步选择项到数据库',function(data){
  13769. })
  13770. }
  13771. }
  13772. //跨页全选时获取多记录表单的全部关键值 2011-11-08
  13773. function getAll(opts){
  13774. var selected = opts.checkArray;
  13775. var whereCls = opts.whereCls;
  13776. var confid = opts.confid+'_mutl';
  13777. if(_ENCRYPT_WHERE){
  13778. if(whereCls!=null&&whereCls!='null'&&whereCls!=''&&whereCls!='undefined'){
  13779. whereCls=stringToHex(encrypt(WHEREKEY,whereCls));
  13780. }
  13781. }
  13782. if(opts.mutldb){
  13783. new Service({
  13784. serviceId:"mutlSelectService",
  13785. method:"addAll",
  13786. parameters:{TABLE_NAME:"fw_mutl_select",ID:opts.mutldbId,QUERYSQL_ID:confid,QUERYSQL_WHERECLS:whereCls}}
  13787. ).sentAjax('同步选择项到数据库',function(data){
  13788. });
  13789. }
  13790. new Service({
  13791. serviceId:'gtService',
  13792. method:'getFwQuerySql',
  13793. parameters:{ID:confid,WHERECLS:whereCls}
  13794. }).sentAjax('正在更新表单,请稍候!', function(data){
  13795. var rows = data[0];
  13796. var iLen = rows.length;
  13797. if(iLen>0){
  13798. selected = [];
  13799. }
  13800. for(i=0;i<rows.length;i++){
  13801. for(key in rows[i]){
  13802. if("ROWNUM_"==key)continue;
  13803. selected.push(rows[i][key]+"");
  13804. }
  13805. }
  13806. var confid = opts.confid;
  13807. var checkboxes = $("tbody :checkbox","#"+confid);
  13808. checkboxes.each(function(){
  13809. if(false == this.checked){
  13810. this.checked = true;
  13811. }
  13812. });
  13813. $("#cb_"+confid).attr("checked",true);;
  13814. $("#"+confid).jqGrid("setAllChecked",selected);
  13815. setTimeout(function(){
  13816. try {
  13817. var fun = window[confid+"_mutl_all"];
  13818. fun(true);
  13819. } catch(e){}
  13820. },50);
  13821. });
  13822. }
  13823. //跨页全选时取消全部的跨页全选
  13824. function unGetAll(opts){
  13825. opts.checkArray = [];
  13826. //同步选择项到数据库
  13827. if(opts.mutldb){
  13828. new Service({
  13829. serviceId:"mutlSelectService",
  13830. method:"delAll",
  13831. parameters:{TABLE_NAME:"fw_mutl_select",ID:opts.mutldbId}}
  13832. ).sentAjax('同步选择项到数据库',function(data){
  13833. });
  13834. }
  13835. var confid = opts.confid;
  13836. var checkboxes = $("tbody :checkbox","#"+confid);
  13837. checkboxes.each(function(){
  13838. if(true == this.checked){
  13839. this.checked = false;
  13840. }
  13841. });
  13842. setTimeout(function(){
  13843. try {
  13844. var fun = window[confid+"_mutl_all"];
  13845. fun(false);
  13846. } catch(e){}
  13847. },50);
  13848. }
  13849. /**
  13850. * 生成下拉框的DIV
  13851. */
  13852. function iniDicts(opts){
  13853. var dicts = opts.dicts;
  13854. var confid = opts.confid;
  13855. var div ="";
  13856. var dt;
  13857. for(key in dicts){
  13858. var dts = dicts[key];
  13859. var div = "<DIV id=\""+confid+"_"+key+"_combox\" class=\"gltcombox-panel\" style=\"width:134px; display:none;\">";
  13860. div += "<div style=\"height:200px\" class=gltcombox-panel-body>";
  13861. for(ky in dts){
  13862. div += "<div class=gltcombox-item value=\""+ky+"\" text=\""+dts[ky]+"\">"+ky+"-"+dts[ky]+"</div>";
  13863. }
  13864. div += "<div class=\"gltcombox-item gltcombox-item-selected\" value=\"\" text=\"\">&nbsp;</div>";
  13865. div += " </div> ";
  13866. div += " </DIV> ";
  13867. $(div).appendTo('body');
  13868. }
  13869. }
  13870. function showComBox(configId,input,comname){
  13871. var target=$("#"+configId);
  13872. var zIndex = 99999999;
  13873. var iLeft = $(input).offset().left;
  13874. var iTop = $(input).offset().top + 20;
  13875. var combox = $('#'+comname);
  13876. var comobj;
  13877. comobj=eval('document.all.'+comname);
  13878. setComBox(target,comobj,input);
  13879. var hidden = getComHidden(target,input);
  13880. $(comobj).css("width",$(input).width());//div宽度建议跟多记录表中对应列宽度一致
  13881. var panel = $(comobj).find('div.gltcombox-panel-body');
  13882. panel.find('div.gltcombox-item-selected').removeClass('gltcombox-item-selected');
  13883. if(hidden!=null)panel.find('div.gltcombox-item[value=' + hidden.value + ']').addClass('gltcombox-item-selected');
  13884. var ind = parseInt(combox.css('zIndex'),10);
  13885. if(isNaN(ind)){
  13886. ind=0;
  13887. }
  13888. if(zIndex>ind){
  13889. ind = zIndex;
  13890. };
  13891. //下拉框在fwwindow内需要根据当前input的zindex重置panel的index保证下拉框在最前
  13892. var inputZIndex = 0;
  13893. $(input).parents().each(function(){
  13894. inputZIndex+=parseInt($(this).css('z-index'));
  13895. });
  13896. if(inputZIndex>ind){
  13897. ind=inputZIndex+1;
  13898. }
  13899. combox.css({
  13900. display:'block',
  13901. left:iLeft,
  13902. top:iTop,
  13903. zIndex:ind
  13904. });
  13905. }
  13906. /**
  13907. * 初始化下拉框
  13908. * @param input 录入控件
  13909. * @param comname 下拉字典的名称
  13910. * @return 无
  13911. */
  13912. function setComBox(target,combox,input){
  13913. var panel = $('.gltcombox-panel-body',combox);
  13914. $('.gltcombox-item', panel).unbind('hover');
  13915. $('.gltcombox-item', panel).unbind('click');
  13916. $('.gltcombox-item', panel).hover(
  13917. function(){$(this).addClass('gltcombox-item-hover');},
  13918. function(){$(this).removeClass('gltcombox-item-hover');}
  13919. ).click(function(){
  13920. var item = $(this);
  13921. $(combox).css({
  13922. display:'none'
  13923. });
  13924. setValue(target,combox,input,$.trim(item.attr('text')),item.attr('value'),true);
  13925. });
  13926. panel.find('div.gltcombox-item').each(function(){
  13927. var item = $(this);
  13928. item.show();
  13929. });
  13930. //鼠标点击其他地方就隐藏列表
  13931. $(document).bind('mousedown', function(e){
  13932. $('div.gltcombox-panel').hide();
  13933. });
  13934. //鼠标移动到上面屏蔽掉
  13935. panel.bind('mousedown', function(e){
  13936. return false;
  13937. });
  13938. jQuery(input).bind('mousedown', function(e){
  13939. return false;
  13940. });
  13941. //当录入框第一次获取录入焦点,初始话该控件的事件
  13942. if($.data(input, 'input') == null){
  13943. $(input).data('input', {});
  13944. //单击ENTER键失去焦点时
  13945. $(input).bind('keydown',function(e){
  13946. if(e.keyCode==13||e.keyCode==9){
  13947. $(combox).css({
  13948. display:'none'
  13949. });
  13950. //selectCur(target,input,combox);
  13951. }
  13952. });
  13953. //按上下左右键时选择下拉框的内容
  13954. $(input).bind('keyup', function(e){
  13955. switch(e.keyCode){
  13956. case 37: // left
  13957. case 38: // up
  13958. selectPrev(target,input,combox);
  13959. break;
  13960. case 39: // right
  13961. case 40: // down
  13962. selectNext(target,input,combox);
  13963. break;
  13964. case 16://shift
  13965. return true;
  13966. break;
  13967. case 17://ctrl
  13968. return true;
  13969. break;
  13970. case 18://atl
  13971. return true;
  13972. break;
  13973. case 32://空格
  13974. return true;
  13975. break;
  13976. default:
  13977. if(!input.readOnly){
  13978. setTimeout(function(){
  13979. filter(target,combox,input);
  13980. },1000*0.3); //延迟两秒处理
  13981. }
  13982. }
  13983. });
  13984. }
  13985. }
  13986. /**
  13987. * 过滤下拉框的内容
  13988. */
  13989. function filter(target,combox,input){
  13990. var query = input.value;
  13991. var panel = $('div.gltcombox-panel-body',combox);
  13992. var hidden = getComHidden(target,input);
  13993. hidden.value =""; //原来的值
  13994. panel.find('div.gltcombox-item').each(function(){
  13995. var item = $(this);
  13996. if (item.text().indexOf(query) == 0){
  13997. item.show();
  13998. if (item.text() == query){
  13999. item.addClass('gltcombox-item-selected');
  14000. hidden.value = item.attr('value');
  14001. }
  14002. }else if(item.attr('text').indexOf(query) == 0){//若是跟下拉列表内比较不成功,则跟隐藏的比较
  14003. if(item.attr('text') == query){
  14004. item.addClass('gltcombox-item-selected');
  14005. hidden.value = item.attr('value');
  14006. }
  14007. }else{
  14008. item.hide();
  14009. }
  14010. });
  14011. }
  14012. /**
  14013. * 获取下拉字典项保存字典值的HIDDEN input 对象
  14014. */
  14015. function getComHidden(target,input){
  14016. var obj;
  14017. var nd = input.id;
  14018. nd=nd.replace("_filter","");
  14019. $('input[type="hidden"][id='+nd+']',target).each(function(){
  14020. obj = this;
  14021. return false;
  14022. });
  14023. return obj;
  14024. }
  14025. /**
  14026. * 设置该值 HIDDEN input 保存字典值
  14027. */
  14028. function setValue(target,combox,input,text,value,confirm){
  14029. var panelbody = $('.gltcombox-panel-body',combox);
  14030. panelbody.find('div.gltcombox-item-selected').removeClass('gltcombox-item-selected');
  14031. panelbody.find('div.gltcombox-item[value=' + value + ']').addClass('gltcombox-item-selected');
  14032. if(confirm){
  14033. var obj=getComHidden(target,input);
  14034. input.value = text;
  14035. obj.value = value;
  14036. var fun = window[input.doselect];
  14037. if(fun){
  14038. fun(input,{AAA102:value,AAA103:text});
  14039. }
  14040. }
  14041. }
  14042. $.fn.serializeObject = function() {
  14043. var o = {"unique_id":new Date().getTime()};
  14044. var a = this.serializeArray();
  14045. $.each(a, function() {
  14046. if (o[this.name]) {
  14047. if (!o[this.name].push) {
  14048. o[this.name] = [o[this.name]];
  14049. }
  14050. o[this.name].push(this.value || '');
  14051. } else {
  14052. o[this.name] = this.value || '';
  14053. }
  14054. });
  14055. return o;
  14056. };