jquery.jqGrid.js 462 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532
  1. // ==ClosureCompiler==
  2. // @compilation_level SIMPLE_OPTIMIZATIONS
  3. /**
  4. * @license jqGrid 4.7.0 - jQuery Grid
  5. * Copyright (c) 2008, Tony Tomov, tony@trirand.com
  6. * Dual licensed under the MIT and GPL licenses
  7. * http://www.opensource.org/licenses/mit-license.php
  8. * http://www.gnu.org/licenses/gpl-2.0.html
  9. * Date: 2014-12-08
  10. */
  11. //jsHint options
  12. /*jshint evil:true, eqeqeq:false, eqnull:true, devel:true */
  13. /*global jQuery */
  14. (function ($) {
  15. "use strict";
  16. $.jgrid = $.jgrid || {};
  17. $.extend($.jgrid,{
  18. version : "4.7.0",
  19. htmlDecode : function(value){
  20. if(value && (value===' ' || value===' ' || (value.length===1 && value.charCodeAt(0)===160))) { return "";}
  21. return !value ? value : String(value).replace(/&gt;/g, ">").replace(/&lt;/g, "<").replace(/&quot;/g, '"').replace(/&amp;/g, "&");
  22. },
  23. htmlEncode : function (value){
  24. return !value ? value : String(value).replace(/&/g, "&amp;").replace(/\"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
  25. },
  26. format : function(format){ //jqgformat
  27. var args = $.makeArray(arguments).slice(1);
  28. if(format==null) { format = ""; }
  29. return format.replace(/\{(\d+)\}/g, function(m, i){
  30. return args[i];
  31. });
  32. },
  33. msie : navigator.appName === 'Microsoft Internet Explorer',
  34. msiever : function () {
  35. var rv = -1;
  36. var ua = navigator.userAgent;
  37. var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
  38. if (re.exec(ua) != null) {
  39. rv = parseFloat( RegExp.$1 );
  40. }
  41. return rv;
  42. },
  43. getCellIndex : function (cell) {
  44. var c = $(cell);
  45. if (c.is('tr')) { return -1; }
  46. c = (!c.is('td') && !c.is('th') ? c.closest("td,th") : c)[0];
  47. if ($.jgrid.msie) { return $.inArray(c, c.parentNode.cells); }
  48. return c.cellIndex;
  49. },
  50. stripHtml : function(v) {
  51. v = String(v);
  52. var regexp = /<("[^"]*"|'[^']*'|[^'">])*>/gi;
  53. if (v) {
  54. v = v.replace(regexp,"");
  55. return (v && v !== '&nbsp;' && v !== '&#160;') ? v.replace(/\"/g,"'") : "";
  56. }
  57. return v;
  58. },
  59. stripPref : function (pref, id) {
  60. var obj = $.type( pref );
  61. if( obj === "string" || obj === "number") {
  62. pref = String(pref);
  63. id = pref !== "" ? String(id).replace(String(pref), "") : id;
  64. }
  65. return id;
  66. },
  67. parse : function(jsonString) {
  68. var js = jsonString;
  69. if (js.substr(0,9) === "while(1);") { js = js.substr(9); }
  70. if (js.substr(0,2) === "/*") { js = js.substr(2,js.length-4); }
  71. if(!js) { js = "{}"; }
  72. return ($.jgrid.useJSON===true && typeof JSON === 'object' && typeof JSON.parse === 'function') ?
  73. JSON.parse(js) :
  74. eval('(' + js + ')');
  75. },
  76. parseDate : function(format, date, newformat, opts) {
  77. var token = /\\.|[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]/g,
  78. timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
  79. timezoneClip = /[^-+\dA-Z]/g,
  80. msDateRegExp = new RegExp("^\/Date\\((([-+])?[0-9]+)(([-+])([0-9]{2})([0-9]{2}))?\\)\/$"),
  81. msMatch = ((typeof date === 'string') ? date.match(msDateRegExp): null),
  82. pad = function (value, length) {
  83. value = String(value);
  84. length = parseInt(length,10) || 2;
  85. while (value.length < length) { value = '0' + value; }
  86. return value;
  87. },
  88. ts = {m : 1, d : 1, y : 1970, h : 0, i : 0, s : 0, u:0},
  89. timestamp=0, dM, k,hl,
  90. h12to24 = function(ampm, h){
  91. if (ampm === 0){ if (h === 12) { h = 0;} }
  92. else { if (h !== 12) { h += 12; } }
  93. return h;
  94. },
  95. offset =0;
  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. 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. //Support ISO8601Long that have Z at the end to indicate UTC timezone
  121. if(opts.srcformat === 'ISO8601Long' && date.charAt(date.length - 1) === 'Z') {
  122. offset -= (new Date()).getTimezoneOffset();
  123. }
  124. date = String(date).replace(/\T/g,"#").replace(/\t/,"%").split(opts.parseRe);
  125. format = format.replace(/\T/g,"#").replace(/\t/,"%").split(opts.parseRe);
  126. // parsing for month names
  127. for(k=0,hl=format.length;k<hl;k++){
  128. if(format[k] === 'M') {
  129. dM = $.inArray(date[k],opts.monthNames);
  130. if(dM !== -1 && dM < 12){date[k] = dM+1; ts.m = date[k];}
  131. }
  132. if(format[k] === 'F') {
  133. dM = $.inArray(date[k],opts.monthNames,12);
  134. if(dM !== -1 && dM > 11){date[k] = dM+1-12; ts.m = date[k];}
  135. }
  136. if(format[k] === 'a') {
  137. dM = $.inArray(date[k],opts.AmPm);
  138. if(dM !== -1 && dM < 2 && date[k] === opts.AmPm[dM]){
  139. date[k] = dM;
  140. ts.h = h12to24(date[k], ts.h);
  141. }
  142. }
  143. if(format[k] === 'A') {
  144. dM = $.inArray(date[k],opts.AmPm);
  145. if(dM !== -1 && dM > 1 && date[k] === opts.AmPm[dM]){
  146. date[k] = dM-2;
  147. ts.h = h12to24(date[k], ts.h);
  148. }
  149. }
  150. if (format[k] === 'g') {
  151. ts.h = parseInt(date[k], 10);
  152. }
  153. if(date[k] !== undefined) {
  154. ts[format[k].toLowerCase()] = parseInt(date[k],10);
  155. }
  156. }
  157. if(ts.f) {ts.m = ts.f;}
  158. if( ts.m === 0 && ts.y === 0 && ts.d === 0) {
  159. return "&#160;" ;
  160. }
  161. ts.m = parseInt(ts.m,10)-1;
  162. var ty = ts.y;
  163. if (ty >= 70 && ty <= 99) {ts.y = 1900+ts.y;}
  164. else if (ty >=0 && ty <=69) {ts.y= 2000+ts.y;}
  165. timestamp = new Date(ts.y, ts.m, ts.d, ts.h, ts.i, ts.s, ts.u);
  166. //Apply offset to show date as local time.
  167. if(offset > 0) {
  168. timestamp.setTime(Number(Number(timestamp) + (offset * 60 * 1000)));
  169. }
  170. }
  171. } else {
  172. timestamp = new Date(ts.y, ts.m, ts.d, ts.h, ts.i, ts.s, ts.u);
  173. }
  174. if(opts.userLocalTime && offset === 0) {
  175. offset -= (new Date()).getTimezoneOffset();
  176. if( offset > 0 ) {
  177. timestamp.setTime(Number(Number(timestamp) + (offset * 60 * 1000)));
  178. }
  179. }
  180. if( newformat === undefined ) {
  181. return timestamp;
  182. }
  183. if( opts.masks.hasOwnProperty(newformat) ) {
  184. newformat = opts.masks[newformat];
  185. } else if ( !newformat ) {
  186. newformat = 'Y-m-d';
  187. }
  188. var
  189. G = timestamp.getHours(),
  190. i = timestamp.getMinutes(),
  191. j = timestamp.getDate(),
  192. n = timestamp.getMonth() + 1,
  193. o = timestamp.getTimezoneOffset(),
  194. s = timestamp.getSeconds(),
  195. u = timestamp.getMilliseconds(),
  196. w = timestamp.getDay(),
  197. Y = timestamp.getFullYear(),
  198. N = (w + 6) % 7 + 1,
  199. z = (new Date(Y, n - 1, j) - new Date(Y, 0, 1)) / 86400000,
  200. flags = {
  201. // Day
  202. d: pad(j),
  203. D: opts.dayNames[w],
  204. j: j,
  205. l: opts.dayNames[w + 7],
  206. N: N,
  207. S: opts.S(j),
  208. //j < 11 || j > 13 ? ['st', 'nd', 'rd', 'th'][Math.min((j - 1) % 10, 3)] : 'th',
  209. w: w,
  210. z: z,
  211. // Week
  212. 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),
  213. // Month
  214. F: opts.monthNames[n - 1 + 12],
  215. m: pad(n),
  216. M: opts.monthNames[n - 1],
  217. n: n,
  218. t: '?',
  219. // Year
  220. L: '?',
  221. o: '?',
  222. Y: Y,
  223. y: String(Y).substring(2),
  224. // Time
  225. a: G < 12 ? opts.AmPm[0] : opts.AmPm[1],
  226. A: G < 12 ? opts.AmPm[2] : opts.AmPm[3],
  227. B: '?',
  228. g: G % 12 || 12,
  229. G: G,
  230. h: pad(G % 12 || 12),
  231. H: pad(G),
  232. i: pad(i),
  233. s: pad(s),
  234. u: u,
  235. // Timezone
  236. e: '?',
  237. I: '?',
  238. O: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
  239. P: '?',
  240. T: (String(timestamp).match(timezone) || [""]).pop().replace(timezoneClip, ""),
  241. Z: '?',
  242. // Full Date/Time
  243. c: '?',
  244. r: '?',
  245. U: Math.floor(timestamp / 1000)
  246. };
  247. return newformat.replace(token, function ($0) {
  248. return flags.hasOwnProperty($0) ? flags[$0] : $0.substring(1);
  249. });
  250. },
  251. jqID : function(sid){
  252. return String(sid).replace(/[!"#$%&'()*+,.\/:; <=>?@\[\\\]\^`{|}~]/g,"\\$&");
  253. },
  254. guid : 1,
  255. uidPref: 'jqg',
  256. randId : function( prefix ) {
  257. return (prefix || $.jgrid.uidPref) + ($.jgrid.guid++);
  258. },
  259. getAccessor : function(obj, expr) {
  260. var ret,p,prm = [], i;
  261. if( typeof expr === 'function') { return expr(obj); }
  262. ret = obj[expr];
  263. if(ret===undefined) {
  264. try {
  265. if ( typeof expr === 'string' ) {
  266. prm = expr.split('.');
  267. }
  268. i = prm.length;
  269. if( i ) {
  270. ret = obj;
  271. while (ret && i--) {
  272. p = prm.shift();
  273. ret = ret[p];
  274. }
  275. }
  276. } catch (e) {}
  277. }
  278. return ret;
  279. },
  280. getXmlData: function (obj, expr, returnObj) {
  281. var ret, m = typeof expr === 'string' ? expr.match(/^(.*)\[(\w+)\]$/) : null;
  282. if (typeof expr === 'function') { return expr(obj); }
  283. if (m && m[2]) {
  284. // m[2] is the attribute selector
  285. // m[1] is an optional element selector
  286. // examples: "[id]", "rows[page]"
  287. return m[1] ? $(m[1], obj).attr(m[2]) : $(obj).attr(m[2]);
  288. }
  289. ret = $(expr, obj);
  290. if (returnObj) { return ret; }
  291. //$(expr, obj).filter(':last'); // we use ':last' to be more compatible with old version of jqGrid
  292. return ret.length > 0 ? $(ret).text() : undefined;
  293. },
  294. cellWidth : function () {
  295. 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>"),
  296. testCell = $testDiv.appendTo("body")
  297. .find("td")
  298. .width();
  299. $testDiv.remove();
  300. return Math.abs(testCell-5) > 0.1;
  301. },
  302. cell_width : true,
  303. ajaxOptions: {},
  304. from : function(source){
  305. // Original Author Hugo Bonacci
  306. // License MIT http://jlinq.codeplex.com/license
  307. var QueryObject=function(d,q){
  308. if(typeof d==="string"){
  309. d=$.data(d);
  310. }
  311. var self=this,
  312. _data=d,
  313. _usecase=true,
  314. _trim=false,
  315. _query=q,
  316. _stripNum = /[\$,%]/g,
  317. _lastCommand=null,
  318. _lastField=null,
  319. _orDepth=0,
  320. _negate=false,
  321. _queuedOperator="",
  322. _sorting=[],
  323. _useProperties=true;
  324. if(typeof d==="object"&&d.push) {
  325. if(d.length>0){
  326. if(typeof d[0]!=="object"){
  327. _useProperties=false;
  328. }else{
  329. _useProperties=true;
  330. }
  331. }
  332. }else{
  333. throw "data provides is not an array";
  334. }
  335. this._hasData=function(){
  336. return _data===null?false:_data.length===0?false:true;
  337. };
  338. this._getStr=function(s){
  339. var phrase=[];
  340. if(_trim){
  341. phrase.push("jQuery.trim(");
  342. }
  343. phrase.push("String("+s+")");
  344. if(_trim){
  345. phrase.push(")");
  346. }
  347. if(!_usecase){
  348. phrase.push(".toLowerCase()");
  349. }
  350. return phrase.join("");
  351. };
  352. this._strComp=function(val){
  353. if(typeof val==="string"){
  354. return".toString()";
  355. }
  356. return"";
  357. };
  358. this._group=function(f,u){
  359. return({field:f.toString(),unique:u,items:[]});
  360. };
  361. this._toStr=function(phrase){
  362. if(_trim){
  363. phrase=$.trim(phrase);
  364. }
  365. phrase=phrase.toString().replace(/\\/g,'\\\\').replace(/\"/g,'\\"');
  366. return _usecase ? phrase : phrase.toLowerCase();
  367. };
  368. this._funcLoop=function(func){
  369. var results=[];
  370. $.each(_data,function(i,v){
  371. results.push(func(v));
  372. });
  373. return results;
  374. };
  375. this._append=function(s){
  376. var i;
  377. if(_query===null){
  378. _query="";
  379. } else {
  380. _query+=_queuedOperator === "" ? " && " :_queuedOperator;
  381. }
  382. for (i=0;i<_orDepth;i++){
  383. _query+="(";
  384. }
  385. if(_negate){
  386. _query+="!";
  387. }
  388. _query+="("+s+")";
  389. _negate=false;
  390. _queuedOperator="";
  391. _orDepth=0;
  392. };
  393. this._setCommand=function(f,c){
  394. _lastCommand=f;
  395. _lastField=c;
  396. };
  397. this._resetNegate=function(){
  398. _negate=false;
  399. };
  400. this._repeatCommand=function(f,v){
  401. if(_lastCommand===null){
  402. return self;
  403. }
  404. if(f!==null&&v!==null){
  405. return _lastCommand(f,v);
  406. }
  407. if(_lastField===null){
  408. return _lastCommand(f);
  409. }
  410. if(!_useProperties){
  411. return _lastCommand(f);
  412. }
  413. return _lastCommand(_lastField,f);
  414. };
  415. this._equals=function(a,b){
  416. return(self._compare(a,b,1)===0);
  417. };
  418. this._compare=function(a,b,d){
  419. var toString = Object.prototype.toString;
  420. if( d === undefined) { d = 1; }
  421. if(a===undefined) { a = null; }
  422. if(b===undefined) { b = null; }
  423. if(a===null && b===null){
  424. return 0;
  425. }
  426. if(a===null&&b!==null){
  427. return 1;
  428. }
  429. if(a!==null&&b===null){
  430. return -1;
  431. }
  432. if (toString.call(a) === '[object Date]' && toString.call(b) === '[object Date]') {
  433. if (a < b) { return -d; }
  434. if (a > b) { return d; }
  435. return 0;
  436. }
  437. if(!_usecase && typeof a !== "number" && typeof b !== "number" ) {
  438. a=String(a);
  439. b=String(b);
  440. }
  441. if(a<b){return -d;}
  442. if(a>b){return d;}
  443. return 0;
  444. };
  445. this._performSort=function(){
  446. if(_sorting.length===0){return;}
  447. _data=self._doSort(_data,0);
  448. };
  449. this._doSort=function(d,q){
  450. var by=_sorting[q].by,
  451. dir=_sorting[q].dir,
  452. type = _sorting[q].type,
  453. dfmt = _sorting[q].datefmt,
  454. sfunc = _sorting[q].sfunc;
  455. if(q===_sorting.length-1){
  456. return self._getOrder(d, by, dir, type, dfmt, sfunc);
  457. }
  458. q++;
  459. var values=self._getGroup(d,by,dir,type,dfmt), results=[], i, j, sorted;
  460. for(i=0;i<values.length;i++){
  461. sorted=self._doSort(values[i].items,q);
  462. for(j=0;j<sorted.length;j++){
  463. results.push(sorted[j]);
  464. }
  465. }
  466. return results;
  467. };
  468. this._getOrder=function(data,by,dir,type, dfmt, sfunc){
  469. var sortData=[],_sortData=[], newDir = dir==="a" ? 1 : -1, i,ab,j,
  470. findSortKey;
  471. if(type === undefined ) { type = "text"; }
  472. if (type === 'float' || type=== 'number' || type=== 'currency' || type=== 'numeric') {
  473. findSortKey = function($cell) {
  474. var key = parseFloat( String($cell).replace(_stripNum, ''));
  475. return isNaN(key) ? Number.NEGATIVE_INFINITY : key;
  476. };
  477. } else if (type==='int' || type==='integer') {
  478. findSortKey = function($cell) {
  479. return $cell ? parseFloat(String($cell).replace(_stripNum, '')) : Number.NEGATIVE_INFINITY;
  480. };
  481. } else if(type === 'date' || type === 'datetime') {
  482. findSortKey = function($cell) {
  483. return $.jgrid.parseDate(dfmt,$cell).getTime();
  484. };
  485. } else if($.isFunction(type)) {
  486. findSortKey = type;
  487. } else {
  488. findSortKey = function($cell) {
  489. $cell = $cell ? $.trim(String($cell)) : "";
  490. return _usecase ? $cell : $cell.toLowerCase();
  491. };
  492. }
  493. $.each(data,function(i,v){
  494. ab = by!=="" ? $.jgrid.getAccessor(v,by) : v;
  495. if(ab === undefined) { ab = ""; }
  496. ab = findSortKey(ab, v);
  497. _sortData.push({ 'vSort': ab,'index':i});
  498. });
  499. if($.isFunction(sfunc)) {
  500. _sortData.sort(function(a,b){
  501. a = a.vSort;
  502. b = b.vSort;
  503. return sfunc.call(this,a,b,newDir);
  504. });
  505. } else {
  506. _sortData.sort(function(a,b){
  507. a = a.vSort;
  508. b = b.vSort;
  509. return self._compare(a,b,newDir);
  510. });
  511. }
  512. j=0;
  513. var nrec= data.length;
  514. // overhead, but we do not change the original data.
  515. while(j<nrec) {
  516. i = _sortData[j].index;
  517. sortData.push(data[i]);
  518. j++;
  519. }
  520. return sortData;
  521. };
  522. this._getGroup=function(data,by,dir,type, dfmt){
  523. var results=[],
  524. group=null,
  525. last=null, val;
  526. $.each(self._getOrder(data,by,dir,type, dfmt),function(i,v){
  527. val = $.jgrid.getAccessor(v, by);
  528. if(val == null) { val = ""; }
  529. if(!self._equals(last,val)){
  530. last=val;
  531. if(group !== null){
  532. results.push(group);
  533. }
  534. group=self._group(by,val);
  535. }
  536. group.items.push(v);
  537. });
  538. if(group !== null){
  539. results.push(group);
  540. }
  541. return results;
  542. };
  543. this.ignoreCase=function(){
  544. _usecase=false;
  545. return self;
  546. };
  547. this.useCase=function(){
  548. _usecase=true;
  549. return self;
  550. };
  551. this.trim=function(){
  552. _trim=true;
  553. return self;
  554. };
  555. this.noTrim=function(){
  556. _trim=false;
  557. return self;
  558. };
  559. this.execute=function(){
  560. var match=_query, results=[];
  561. if(match === null){
  562. return self;
  563. }
  564. $.each(_data,function(){
  565. if(eval(match)){results.push(this);}
  566. });
  567. _data=results;
  568. return self;
  569. };
  570. this.data=function(){
  571. return _data;
  572. };
  573. this.select=function(f){
  574. self._performSort();
  575. if(!self._hasData()){ return[]; }
  576. self.execute();
  577. if($.isFunction(f)){
  578. var results=[];
  579. $.each(_data,function(i,v){
  580. results.push(f(v));
  581. });
  582. return results;
  583. }
  584. return _data;
  585. };
  586. this.hasMatch=function(){
  587. if(!self._hasData()) { return false; }
  588. self.execute();
  589. return _data.length>0;
  590. };
  591. this.andNot=function(f,v,x){
  592. _negate=!_negate;
  593. return self.and(f,v,x);
  594. };
  595. this.orNot=function(f,v,x){
  596. _negate=!_negate;
  597. return self.or(f,v,x);
  598. };
  599. this.not=function(f,v,x){
  600. return self.andNot(f,v,x);
  601. };
  602. this.and=function(f,v,x){
  603. _queuedOperator=" && ";
  604. if(f===undefined){
  605. return self;
  606. }
  607. return self._repeatCommand(f,v,x);
  608. };
  609. this.or=function(f,v,x){
  610. _queuedOperator=" || ";
  611. if(f===undefined) { return self; }
  612. return self._repeatCommand(f,v,x);
  613. };
  614. this.orBegin=function(){
  615. _orDepth++;
  616. return self;
  617. };
  618. this.orEnd=function(){
  619. if (_query !== null){
  620. _query+=")";
  621. }
  622. return self;
  623. };
  624. this.isNot=function(f){
  625. _negate=!_negate;
  626. return self.is(f);
  627. };
  628. this.is=function(f){
  629. self._append('this.'+f);
  630. self._resetNegate();
  631. return self;
  632. };
  633. this._compareValues=function(func,f,v,how,t){
  634. var fld;
  635. if(_useProperties){
  636. fld='jQuery.jgrid.getAccessor(this,\''+f+'\')';
  637. }else{
  638. fld='this';
  639. }
  640. if(v===undefined) { v = null; }
  641. //var val=v===null?f:v,
  642. var val =v,
  643. swst = t.stype === undefined ? "text" : t.stype;
  644. if(v !== null) {
  645. switch(swst) {
  646. case 'int':
  647. case 'integer':
  648. val = (isNaN(Number(val)) || val==="") ? '0' : val; // To be fixed with more inteligent code
  649. fld = 'parseInt('+fld+',10)';
  650. val = 'parseInt('+val+',10)';
  651. break;
  652. case 'float':
  653. case 'number':
  654. case 'numeric':
  655. val = String(val).replace(_stripNum, '');
  656. val = (isNaN(Number(val)) || val==="") ? '0' : val; // To be fixed with more inteligent code
  657. fld = 'parseFloat('+fld+')';
  658. val = 'parseFloat('+val+')';
  659. break;
  660. case 'date':
  661. case 'datetime':
  662. val = String($.jgrid.parseDate(t.newfmt || 'Y-m-d',val).getTime());
  663. fld = 'jQuery.jgrid.parseDate("'+t.srcfmt+'",'+fld+').getTime()';
  664. break;
  665. default :
  666. fld=self._getStr(fld);
  667. val=self._getStr('"'+self._toStr(val)+'"');
  668. }
  669. }
  670. self._append(fld+' '+how+' '+val);
  671. self._setCommand(func,f);
  672. self._resetNegate();
  673. return self;
  674. };
  675. this.equals=function(f,v,t){
  676. return self._compareValues(self.equals,f,v,"==",t);
  677. };
  678. this.notEquals=function(f,v,t){
  679. return self._compareValues(self.equals,f,v,"!==",t);
  680. };
  681. this.isNull = function(f,v,t){
  682. return self._compareValues(self.equals,f,null,"===",t);
  683. };
  684. this.greater=function(f,v,t){
  685. return self._compareValues(self.greater,f,v,">",t);
  686. };
  687. this.less=function(f,v,t){
  688. return self._compareValues(self.less,f,v,"<",t);
  689. };
  690. this.greaterOrEquals=function(f,v,t){
  691. return self._compareValues(self.greaterOrEquals,f,v,">=",t);
  692. };
  693. this.lessOrEquals=function(f,v,t){
  694. return self._compareValues(self.lessOrEquals,f,v,"<=",t);
  695. };
  696. this.startsWith=function(f,v){
  697. var val = (v==null) ? f: v,
  698. length=_trim ? $.trim(val.toString()).length : val.toString().length;
  699. if(_useProperties){
  700. self._append(self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.substr(0,'+length+') == '+self._getStr('"'+self._toStr(v)+'"'));
  701. }else{
  702. if (v!=null) { length=_trim?$.trim(v.toString()).length:v.toString().length; }
  703. self._append(self._getStr('this')+'.substr(0,'+length+') == '+self._getStr('"'+self._toStr(f)+'"'));
  704. }
  705. self._setCommand(self.startsWith,f);
  706. self._resetNegate();
  707. return self;
  708. };
  709. this.endsWith=function(f,v){
  710. var val = (v==null) ? f: v,
  711. length=_trim ? $.trim(val.toString()).length:val.toString().length;
  712. if(_useProperties){
  713. self._append(self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.substr('+self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.length-'+length+','+length+') == "'+self._toStr(v)+'"');
  714. } else {
  715. self._append(self._getStr('this')+'.substr('+self._getStr('this')+'.length-"'+self._toStr(f)+'".length,"'+self._toStr(f)+'".length) == "'+self._toStr(f)+'"');
  716. }
  717. self._setCommand(self.endsWith,f);self._resetNegate();
  718. return self;
  719. };
  720. this.contains=function(f,v){
  721. if(_useProperties){
  722. self._append(self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.indexOf("'+self._toStr(v)+'",0) > -1');
  723. }else{
  724. self._append(self._getStr('this')+'.indexOf("'+self._toStr(f)+'",0) > -1');
  725. }
  726. self._setCommand(self.contains,f);
  727. self._resetNegate();
  728. return self;
  729. };
  730. this.groupBy=function(by,dir,type, datefmt){
  731. if(!self._hasData()){
  732. return null;
  733. }
  734. return self._getGroup(_data,by,dir,type, datefmt);
  735. };
  736. this.orderBy=function(by,dir,stype, dfmt, sfunc){
  737. dir = dir == null ? "a" :$.trim(dir.toString().toLowerCase());
  738. if(stype == null) { stype = "text"; }
  739. if(dfmt == null) { dfmt = "Y-m-d"; }
  740. if(sfunc == null) { sfunc = false; }
  741. if(dir==="desc"||dir==="descending"){dir="d";}
  742. if(dir==="asc"||dir==="ascending"){dir="a";}
  743. _sorting.push({by:by,dir:dir,type:stype, datefmt: dfmt, sfunc: sfunc});
  744. return self;
  745. };
  746. return self;
  747. };
  748. return new QueryObject(source,null);
  749. },
  750. getMethod: function (name) {
  751. return this.getAccessor($.fn.jqGrid, name);
  752. },
  753. extend : function(methods) {
  754. $.extend($.fn.jqGrid,methods);
  755. if (!this.no_legacy_api) {
  756. $.fn.extend(methods);
  757. }
  758. }
  759. });
  760. $.fn.jqGrid = function( pin ) {
  761. if (typeof pin === 'string') {
  762. var fn = $.jgrid.getMethod(pin);
  763. if (!fn) {
  764. throw ("jqGrid - No such method: " + pin);
  765. }
  766. var args = $.makeArray(arguments).slice(1);
  767. return fn.apply(this,args);
  768. }
  769. return this.each( function() {
  770. if(this.grid) {return;}
  771. var localData;
  772. if (pin != null && pin.data !== undefined) {
  773. localData = pin.data;
  774. pin.data = [];
  775. }
  776. var p = $.extend(true,{
  777. url: "",
  778. height: 150,
  779. page: 1,
  780. rowNum: 20,
  781. rowTotal : null,
  782. records: 0,
  783. pager: "",
  784. pgbuttons: true,
  785. pginput: true,
  786. colModel: [],
  787. rowList: [],
  788. colNames: [],
  789. sortorder: "asc",
  790. sortname: "",
  791. datatype: "xml",
  792. mtype: "GET",
  793. altRows: false,
  794. selarrrow: [],
  795. savedRow: [],
  796. shrinkToFit: true,
  797. xmlReader: {},
  798. jsonReader: {},
  799. subGrid: false,
  800. subGridModel :[],
  801. reccount: 0,
  802. lastpage: 0,
  803. lastsort: 0,
  804. selrow: null,
  805. beforeSelectRow: null,
  806. onSelectRow: null,
  807. onSortCol: null,
  808. ondblClickRow: null,
  809. onRightClickRow: null,
  810. onPaging: null,
  811. onSelectAll: null,
  812. onInitGrid : null,
  813. loadComplete: null,
  814. gridComplete: null,
  815. loadError: null,
  816. loadBeforeSend: null,
  817. afterInsertRow: null,
  818. beforeRequest: null,
  819. beforeProcessing : null,
  820. onHeaderClick: null,
  821. viewrecords: false,
  822. loadonce: false,
  823. multiselect: false,
  824. multikey: false,
  825. editurl: null,
  826. search: false,
  827. caption: "",
  828. hidegrid: true,
  829. hiddengrid: false,
  830. postData: {},
  831. userData: {},
  832. treeGrid : false,
  833. treeGridModel : 'nested',
  834. treeReader : {},
  835. treeANode : -1,
  836. ExpandColumn: null,
  837. tree_root_level : 0,
  838. prmNames: {page:"page",rows:"rows", sort: "sidx",order: "sord", search:"_search", nd:"nd", id:"id",oper:"oper",editoper:"edit",addoper:"add",deloper:"del", subgridid:"id", npage: null, totalrows:"totalrows"},
  839. forceFit : false,
  840. gridstate : "visible",
  841. cellEdit: false,
  842. cellsubmit: "remote",
  843. nv:0,
  844. loadui: "enable",
  845. toolbar: [false,""],
  846. scroll: false,
  847. multiboxonly : false,
  848. deselectAfterSort : true,
  849. scrollrows : false,
  850. autowidth: false,
  851. scrollOffset :18,
  852. cellLayout: 5,
  853. subGridWidth: 20,
  854. multiselectWidth: 20,
  855. gridview: false,
  856. rownumWidth: 25,
  857. rownumbers : false,
  858. pagerpos: 'center',
  859. recordpos: 'right',
  860. footerrow : false,
  861. userDataOnFooter : false,
  862. hoverrows : true,
  863. altclass : 'ui-priority-secondary',
  864. viewsortcols : [false,'vertical',true],
  865. resizeclass : '',
  866. autoencode : false,
  867. remapColumns : [],
  868. ajaxGridOptions :{},
  869. direction : "ltr",
  870. toppager: false,
  871. headertitles: false,
  872. scrollTimeout: 40,
  873. data : [],
  874. _index : {},
  875. grouping : false,
  876. 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},
  877. ignoreCase : false,
  878. cmTemplate : {},
  879. idPrefix : "",
  880. multiSort : false,
  881. minColWidth : 33
  882. }, $.jgrid.defaults, pin || {});
  883. if (localData !== undefined) {
  884. p.data = localData;
  885. pin.data = localData;
  886. }
  887. var ts= this, grid={
  888. headers:[],
  889. cols:[],
  890. footers: [],
  891. dragStart: function(i,x,y) {
  892. var gridLeftPos = $(this.bDiv).offset().left;
  893. this.resizing = { idx: i, startX: x.pageX, sOL : x.pageX - gridLeftPos };
  894. this.hDiv.style.cursor = "col-resize";
  895. this.curGbox = $("#rs_m"+$.jgrid.jqID(p.id),"#gbox_"+$.jgrid.jqID(p.id));
  896. this.curGbox.css({display:"block",left:x.pageX-gridLeftPos,top:y[1],height:y[2]});
  897. $(ts).triggerHandler("jqGridResizeStart", [x, i]);
  898. if($.isFunction(p.resizeStart)) { p.resizeStart.call(ts,x,i); }
  899. document.onselectstart=function(){return false;};
  900. },
  901. dragMove: function(x) {
  902. if(this.resizing) {
  903. var diff = x.pageX-this.resizing.startX,
  904. h = this.headers[this.resizing.idx],
  905. newWidth = p.direction === "ltr" ? h.width + diff : h.width - diff, hn, nWn;
  906. if(newWidth > 33) {
  907. this.curGbox.css({left:this.resizing.sOL+diff});
  908. if(p.forceFit===true ){
  909. hn = this.headers[this.resizing.idx+p.nv];
  910. nWn = p.direction === "ltr" ? hn.width - diff : hn.width + diff;
  911. if(nWn > p.minColWidth ) {
  912. h.newWidth = newWidth;
  913. hn.newWidth = nWn;
  914. }
  915. } else {
  916. this.newWidth = p.direction === "ltr" ? p.tblwidth+diff : p.tblwidth-diff;
  917. h.newWidth = newWidth;
  918. }
  919. }
  920. }
  921. },
  922. dragEnd: function() {
  923. this.hDiv.style.cursor = "default";
  924. if(this.resizing) {
  925. var idx = this.resizing.idx,
  926. nw = this.headers[idx].newWidth || this.headers[idx].width;
  927. nw = parseInt(nw,10);
  928. this.resizing = false;
  929. $("#rs_m"+$.jgrid.jqID(p.id)).css("display","none");
  930. p.colModel[idx].width = nw;
  931. this.headers[idx].width = nw;
  932. this.headers[idx].el.style.width = nw + "px";
  933. this.cols[idx].style.width = nw+"px";
  934. if(this.footers.length>0) {this.footers[idx].style.width = nw+"px";}
  935. if(p.forceFit===true){
  936. nw = this.headers[idx+p.nv].newWidth || this.headers[idx+p.nv].width;
  937. this.headers[idx+p.nv].width = nw;
  938. this.headers[idx+p.nv].el.style.width = nw + "px";
  939. this.cols[idx+p.nv].style.width = nw+"px";
  940. if(this.footers.length>0) {this.footers[idx+p.nv].style.width = nw+"px";}
  941. p.colModel[idx+p.nv].width = nw;
  942. } else {
  943. p.tblwidth = this.newWidth || p.tblwidth;
  944. $('table:first',this.bDiv).css("width",p.tblwidth+"px");
  945. $('table:first',this.hDiv).css("width",p.tblwidth+"px");
  946. this.hDiv.scrollLeft = this.bDiv.scrollLeft;
  947. if(p.footerrow) {
  948. $('table:first',this.sDiv).css("width",p.tblwidth+"px");
  949. this.sDiv.scrollLeft = this.bDiv.scrollLeft;
  950. }
  951. }
  952. $(ts).triggerHandler("jqGridResizeStop", [nw, idx]);
  953. if($.isFunction(p.resizeStop)) { p.resizeStop.call(ts,nw,idx); }
  954. }
  955. this.curGbox = null;
  956. document.onselectstart=function(){return true;};
  957. },
  958. populateVisible: function() {
  959. if (grid.timer) { clearTimeout(grid.timer); }
  960. grid.timer = null;
  961. var dh = $(grid.bDiv).height();
  962. if (!dh) { return; }
  963. var table = $("table:first", grid.bDiv);
  964. var rows, rh;
  965. if(table[0].rows.length) {
  966. try {
  967. rows = table[0].rows[1];
  968. rh = rows ? $(rows).outerHeight() || grid.prevRowHeight : grid.prevRowHeight;
  969. } catch (pv) {
  970. rh = grid.prevRowHeight;
  971. }
  972. }
  973. if (!rh) { return; }
  974. grid.prevRowHeight = rh;
  975. var rn = p.rowNum;
  976. var scrollTop = grid.scrollTop = grid.bDiv.scrollTop;
  977. var ttop = Math.round(table.position().top) - scrollTop;
  978. var tbot = ttop + table.height();
  979. var div = rh * rn;
  980. var page, npage, empty;
  981. if ( tbot < dh && ttop <= 0 &&
  982. (p.lastpage===undefined||(parseInt((tbot + scrollTop + div - 1) / div,10) || 0) <= p.lastpage))
  983. {
  984. npage = parseInt((dh - tbot + div - 1) / div,10) || 1;
  985. if (tbot >= 0 || npage < 2 || p.scroll === true) {
  986. page = ( Math.round((tbot + scrollTop) / div) || 0) + 1;
  987. ttop = -1;
  988. } else {
  989. ttop = 1;
  990. }
  991. }
  992. if (ttop > 0) {
  993. page = ( parseInt(scrollTop / div,10) || 0 ) + 1;
  994. npage = (parseInt((scrollTop + dh) / div,10) || 0) + 2 - page;
  995. empty = true;
  996. }
  997. if (npage) {
  998. if (p.lastpage && (page > p.lastpage || p.lastpage===1 || (page === p.page && page===p.lastpage)) ) {
  999. return;
  1000. }
  1001. if (grid.hDiv.loading) {
  1002. grid.timer = setTimeout(grid.populateVisible, p.scrollTimeout);
  1003. } else {
  1004. p.page = page;
  1005. if (empty) {
  1006. grid.selectionPreserver(table[0]);
  1007. grid.emptyRows.call(table[0], false, false);
  1008. }
  1009. grid.populate(npage);
  1010. }
  1011. }
  1012. },
  1013. scrollGrid: function( e ) {
  1014. if(p.scroll) {
  1015. var scrollTop = grid.bDiv.scrollTop;
  1016. if(grid.scrollTop === undefined) { grid.scrollTop = 0; }
  1017. if (scrollTop !== grid.scrollTop) {
  1018. grid.scrollTop = scrollTop;
  1019. if (grid.timer) { clearTimeout(grid.timer); }
  1020. grid.timer = setTimeout(grid.populateVisible, p.scrollTimeout);
  1021. }
  1022. }
  1023. grid.hDiv.scrollLeft = grid.bDiv.scrollLeft;
  1024. if(p.footerrow) {
  1025. grid.sDiv.scrollLeft = grid.bDiv.scrollLeft;
  1026. }
  1027. if( e ) { e.stopPropagation(); }
  1028. },
  1029. selectionPreserver : function(ts) {
  1030. var p = ts.p,
  1031. sr = p.selrow, sra = p.selarrrow ? $.makeArray(p.selarrrow) : null,
  1032. left = ts.grid.bDiv.scrollLeft,
  1033. restoreSelection = function() {
  1034. var i;
  1035. p.selrow = null;
  1036. p.selarrrow = [];
  1037. if(p.multiselect && sra && sra.length>0) {
  1038. for(i=0;i<sra.length;i++){
  1039. if (sra[i] !== sr) {
  1040. $(ts).jqGrid("setSelection",sra[i],false, null);
  1041. }
  1042. }
  1043. }
  1044. if (sr) {
  1045. $(ts).jqGrid("setSelection",sr,false,null);
  1046. }
  1047. ts.grid.bDiv.scrollLeft = left;
  1048. $(ts).unbind('.selectionPreserver', restoreSelection);
  1049. };
  1050. $(ts).bind('jqGridGridComplete.selectionPreserver', restoreSelection);
  1051. }
  1052. };
  1053. if(this.tagName.toUpperCase() !== 'TABLE' || this.id == null) {
  1054. alert("Element is not a table or has no id!");
  1055. return;
  1056. }
  1057. if(document.documentMode !== undefined ) { // IE only
  1058. if(document.documentMode <= 5) {
  1059. alert("Grid can not be used in this ('quirks') mode!");
  1060. return;
  1061. }
  1062. }
  1063. $(this).empty().attr("tabindex","0");
  1064. this.p = p ;
  1065. this.p.useProp = !!$.fn.prop;
  1066. var i, dir;
  1067. if(this.p.colNames.length === 0) {
  1068. for (i=0;i<this.p.colModel.length;i++){
  1069. this.p.colNames[i] = this.p.colModel[i].label || this.p.colModel[i].name;
  1070. }
  1071. }
  1072. if( this.p.colNames.length !== this.p.colModel.length ) {
  1073. alert($.jgrid.errors.model);
  1074. return;
  1075. }
  1076. var gv = $("<div class='ui-jqgrid-view' role='grid'></div>"),
  1077. isMSIE = $.jgrid.msie;
  1078. ts.p.direction = $.trim(ts.p.direction.toLowerCase());
  1079. if($.inArray(ts.p.direction,["ltr","rtl"]) === -1) { ts.p.direction = "ltr"; }
  1080. dir = ts.p.direction;
  1081. $(gv).insertBefore(this);
  1082. $(this).removeClass("scroll").appendTo(gv);
  1083. var eg = $("<div class='ui-jqgrid ui-widget ui-widget-content ui-corner-all'></div>");
  1084. $(eg).attr({"id" : "gbox_"+this.id,"dir":dir}).insertBefore(gv);
  1085. $(gv).attr("id","gview_"+this.id).appendTo(eg);
  1086. $("<div class='ui-widget-overlay jqgrid-overlay' id='lui_"+this.id+"'></div>").insertBefore(gv);
  1087. $("<div class='loading ui-state-default ui-state-active' id='load_"+this.id+"'>"+this.p.loadtext+"</div>").insertBefore(gv);
  1088. $(this).attr({cellspacing:"0",cellpadding:"0",border:"0","role":"presentation","aria-multiselectable":!!this.p.multiselect,"aria-labelledby":"gbox_"+this.id});
  1089. var sortkeys = ["shiftKey","altKey","ctrlKey"],
  1090. intNum = function(val,defval) {
  1091. val = parseInt(val,10);
  1092. if (isNaN(val)) { return defval || 0;}
  1093. return val;
  1094. },
  1095. formatCol = function (pos, rowInd, tv, rawObject, rowId, rdata){
  1096. var cm = ts.p.colModel[pos], cellAttrFunc,
  1097. ral = cm.align, result="style=\"", clas = cm.classes, nm = cm.name, celp, acp=[];
  1098. if(ral) { result += "text-align:"+ral+";"; }
  1099. if(cm.hidden===true) { result += "display:none;"; }
  1100. if(rowInd===0) {
  1101. result += "width: "+grid.headers[pos].width+"px;";
  1102. } else if ($.isFunction(cm.cellattr) || (typeof cm.cellattr === "string" && $.jgrid.cellattr != null && $.isFunction($.jgrid.cellattr[cm.cellattr]))) {
  1103. cellAttrFunc = $.isFunction(cm.cellattr) ? cm.cellattr : $.jgrid.cellattr[cm.cellattr];
  1104. celp = cellAttrFunc.call(ts, rowId, tv, rawObject, cm, rdata);
  1105. if(celp && typeof celp === "string") {
  1106. celp = celp.replace(/style/i,'style').replace(/title/i,'title');
  1107. if(celp.indexOf('title') > -1) { cm.title=false;}
  1108. if(celp.indexOf('class') > -1) { clas = undefined;}
  1109. acp = celp.replace(/\-style/g,'-sti').split(/style/);
  1110. if(acp.length === 2 ) {
  1111. acp[1] = $.trim(acp[1].replace(/\-sti/g,'-style').replace("=",""));
  1112. if(acp[1].indexOf("'") === 0 || acp[1].indexOf('"') === 0) {
  1113. acp[1] = acp[1].substring(1);
  1114. }
  1115. result += acp[1].replace(/'/gi,'"');
  1116. } else {
  1117. result += "\"";
  1118. }
  1119. }
  1120. }
  1121. if(!acp.length) { acp[0] = ""; result += "\"";}
  1122. result += (clas !== undefined ? (" class=\""+clas+"\"") :"") + ((cm.title && tv) ? (" title=\""+$.jgrid.stripHtml(tv)+"\"") :"");
  1123. result += " aria-describedby=\""+ts.p.id+"_"+nm+"\"";
  1124. return result + acp[0];
  1125. },
  1126. cellVal = function (val) {
  1127. return val == null || val === "" ? "&#160;" : (ts.p.autoencode ? $.jgrid.htmlEncode(val) : String(val));
  1128. },
  1129. formatter = function (rowId, cellval , colpos, rwdat, _act){
  1130. var cm = ts.p.colModel[colpos],v;
  1131. if(cm.formatter !== undefined) {
  1132. rowId = String(ts.p.idPrefix) !== "" ? $.jgrid.stripPref(ts.p.idPrefix, rowId) : rowId;
  1133. var opts= {rowId: rowId, colModel:cm, gid:ts.p.id, pos:colpos };
  1134. if($.isFunction( cm.formatter ) ) {
  1135. v = cm.formatter.call(ts,cellval,opts,rwdat,_act);
  1136. } else if($.fmatter){
  1137. v = $.fn.fmatter.call(ts,cm.formatter,cellval,opts,rwdat,_act);
  1138. } else {
  1139. v = cellVal(cellval);
  1140. }
  1141. } else {
  1142. v = cellVal(cellval);
  1143. }
  1144. return v;
  1145. },
  1146. addCell = function(rowId,cell,pos,irow, srvr, rdata) {
  1147. var v,prp;
  1148. v = formatter(rowId,cell,pos,srvr,'add');
  1149. prp = formatCol( pos,irow, v, srvr, rowId, rdata);
  1150. return "<td role=\"gridcell\" "+prp+">"+v+"</td>";
  1151. },
  1152. addMulti = function(rowid,pos,irow,checked){
  1153. var v = "<input role=\"checkbox\" type=\"checkbox\""+" id=\"jqg_"+ts.p.id+"_"+rowid+"\" class=\"cbox\" name=\"jqg_"+ts.p.id+"_"+rowid+"\"" + (checked ? "checked=\"checked\"" : "")+"/>",
  1154. prp = formatCol( pos,irow,'',null, rowid, true);
  1155. return "<td role=\"gridcell\" "+prp+">"+v+"</td>";
  1156. },
  1157. addRowNum = function (pos,irow,pG,rN) {
  1158. var v = (parseInt(pG,10)-1)*parseInt(rN,10)+1+irow,
  1159. prp = formatCol( pos,irow,v, null, irow, true);
  1160. return "<td role=\"gridcell\" class=\"ui-state-default jqgrid-rownum\" "+prp+">"+v+"</td>";
  1161. },
  1162. reader = function (datatype) {
  1163. var field, f=[], j=0, i;
  1164. for(i =0; i<ts.p.colModel.length; i++){
  1165. field = ts.p.colModel[i];
  1166. if (field.name !== 'cb' && field.name !=='subgrid' && field.name !=='rn') {
  1167. f[j]= datatype === "local" ?
  1168. field.name :
  1169. ( (datatype==="xml" || datatype === "xmlstring") ? field.xmlmap || field.name : field.jsonmap || field.name );
  1170. if(ts.p.keyName !== false && field.key===true ) {
  1171. ts.p.keyName = f[j];
  1172. }
  1173. j++;
  1174. }
  1175. }
  1176. return f;
  1177. },
  1178. orderedCols = function (offset) {
  1179. var order = ts.p.remapColumns;
  1180. if (!order || !order.length) {
  1181. order = $.map(ts.p.colModel, function(v,i) { return i; });
  1182. }
  1183. if (offset) {
  1184. order = $.map(order, function(v) { return v<offset?null:v-offset; });
  1185. }
  1186. return order;
  1187. },
  1188. emptyRows = function (scroll, locdata) {
  1189. var firstrow;
  1190. if (this.p.deepempty) {
  1191. $(this.rows).slice(1).remove();
  1192. } else {
  1193. firstrow = this.rows.length > 0 ? this.rows[0] : null;
  1194. $(this.firstChild).empty().append(firstrow);
  1195. }
  1196. if (scroll && this.p.scroll) {
  1197. $(this.grid.bDiv.firstChild).css({height: "auto"});
  1198. $(this.grid.bDiv.firstChild.firstChild).css({height: 0, display: "none"});
  1199. if (this.grid.bDiv.scrollTop !== 0) {
  1200. this.grid.bDiv.scrollTop = 0;
  1201. }
  1202. }
  1203. if(locdata === true && this.p.treeGrid) {
  1204. this.p.data = []; this.p._index = {};
  1205. }
  1206. },
  1207. normalizeData = function() {
  1208. var p = ts.p, data = p.data, dataLength = data.length, i, j, cur, idn, idr, ccur, v, rd,
  1209. localReader = p.localReader,
  1210. colModel = p.colModel,
  1211. cellName = localReader.cell,
  1212. iOffset = (p.multiselect === true ? 1 : 0) + (p.subGrid === true ? 1 : 0) + (p.rownumbers === true ? 1 : 0),
  1213. br = p.scroll ? $.jgrid.randId() : 1,
  1214. arrayReader, objectReader, rowReader;
  1215. if (p.datatype !== "local" || localReader.repeatitems !== true) {
  1216. return; // nothing to do
  1217. }
  1218. arrayReader = orderedCols(iOffset);
  1219. objectReader = reader("local");
  1220. // read ALL input items and convert items to be read by
  1221. // $.jgrid.getAccessor with column name as the second parameter
  1222. idn = p.keyIndex === false ?
  1223. ($.isFunction(localReader.id) ? localReader.id.call(ts, data) : localReader.id) :
  1224. p.keyIndex;
  1225. for (i = 0; i < dataLength; i++) {
  1226. cur = data[i];
  1227. // read id in the same way like addJSONData do
  1228. // probably it would be better to start with "if (cellName) {...}"
  1229. // but the goal of the current implementation was just have THE SAME
  1230. // id values like in addJSONData ...
  1231. idr = $.jgrid.getAccessor(cur, idn);
  1232. if (idr === undefined) {
  1233. if (typeof idn === "number" && colModel[idn + iOffset] != null) {
  1234. // reread id by name
  1235. idr = $.jgrid.getAccessor(cur, colModel[idn + iOffset].name);
  1236. }
  1237. if (idr === undefined) {
  1238. idr = br + i;
  1239. if (cellName) {
  1240. ccur = $.jgrid.getAccessor(cur, cellName) || cur;
  1241. idr = ccur != null && ccur[idn] !== undefined ? ccur[idn] : idr;
  1242. ccur = null;
  1243. }
  1244. }
  1245. }
  1246. rd = { };
  1247. rd[localReader.id] = idr;
  1248. if (cellName) {
  1249. cur = $.jgrid.getAccessor(cur, cellName) || cur;
  1250. }
  1251. rowReader = $.isArray(cur) ? arrayReader : objectReader;
  1252. for (j = 0; j < rowReader.length; j++) {
  1253. v = $.jgrid.getAccessor(cur, rowReader[j]);
  1254. rd[colModel[j + iOffset].name] = v;
  1255. }
  1256. $.extend(true, data[i], rd);
  1257. }
  1258. },
  1259. refreshIndex = function() {
  1260. var datalen = ts.p.data.length, idname, i, val;
  1261. if(ts.p.keyName === false || ts.p.loadonce === true) {
  1262. idname = ts.p.localReader.id;
  1263. } else {
  1264. idname = ts.p.keyName;
  1265. }
  1266. ts.p._index = [];
  1267. for(i =0;i < datalen; i++) {
  1268. val = $.jgrid.getAccessor(ts.p.data[i],idname);
  1269. if (val === undefined) { val=String(i+1); }
  1270. ts.p._index[val] = i;
  1271. }
  1272. },
  1273. constructTr = function(id, hide, altClass, rd, cur, selected) {
  1274. var tabindex = '-1', restAttr = '', attrName, style = hide ? 'display:none;' : '',
  1275. classes = 'ui-widget-content jqgrow ui-row-' + ts.p.direction + (altClass ? ' ' + altClass : '') + (selected ? ' ui-state-highlight' : ''),
  1276. rowAttrObj = $(ts).triggerHandler("jqGridRowAttr", [rd, cur, id]);
  1277. if( typeof rowAttrObj !== "object" ) {
  1278. rowAttrObj = $.isFunction(ts.p.rowattr) ? ts.p.rowattr.call(ts, rd, cur, id) :
  1279. (typeof ts.p.rowattr === "string" && $.jgrid.rowattr != null && $.isFunction($.jgrid.rowattr[ts.p.rowattr]) ?
  1280. $.jgrid.rowattr[ts.p.rowattr].call(ts, rd, cur, id) : {});
  1281. }
  1282. if(!$.isEmptyObject( rowAttrObj )) {
  1283. if (rowAttrObj.hasOwnProperty("id")) {
  1284. id = rowAttrObj.id;
  1285. delete rowAttrObj.id;
  1286. }
  1287. if (rowAttrObj.hasOwnProperty("tabindex")) {
  1288. tabindex = rowAttrObj.tabindex;
  1289. delete rowAttrObj.tabindex;
  1290. }
  1291. if (rowAttrObj.hasOwnProperty("style")) {
  1292. style += rowAttrObj.style;
  1293. delete rowAttrObj.style;
  1294. }
  1295. if (rowAttrObj.hasOwnProperty("class")) {
  1296. classes += ' ' + rowAttrObj['class'];
  1297. delete rowAttrObj['class'];
  1298. }
  1299. // dot't allow to change role attribute
  1300. try { delete rowAttrObj.role; } catch(ra){}
  1301. for (attrName in rowAttrObj) {
  1302. if (rowAttrObj.hasOwnProperty(attrName)) {
  1303. restAttr += ' ' + attrName + '=' + rowAttrObj[attrName];
  1304. }
  1305. }
  1306. }
  1307. return '<tr role="row" id="' + id + '" tabindex="' + tabindex + '" class="' + classes + '"' +
  1308. (style === '' ? '' : ' style="' + style + '"') + restAttr + '>';
  1309. },
  1310. addXmlData = function (xml,t, rcnt, more, adjust) {
  1311. var startReq = new Date(),
  1312. locdata = (ts.p.datatype !== "local" && ts.p.loadonce) || ts.p.datatype === "xmlstring",
  1313. xmlid = "_id_", xmlRd = ts.p.xmlReader,
  1314. frd = ts.p.datatype === "local" ? "local" : "xml";
  1315. if(locdata) {
  1316. ts.p.data = [];
  1317. ts.p._index = {};
  1318. ts.p.localReader.id = xmlid;
  1319. }
  1320. ts.p.reccount = 0;
  1321. if($.isXMLDoc(xml)) {
  1322. if(ts.p.treeANode===-1 && !ts.p.scroll) {
  1323. emptyRows.call(ts, false, true);
  1324. rcnt=1;
  1325. } else { rcnt = rcnt > 1 ? rcnt :1; }
  1326. } else { return; }
  1327. 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;
  1328. if(ts.p.subGrid===true) {
  1329. si = 1;
  1330. addSubGridCell = $.jgrid.getMethod("addSubGridCell");
  1331. }
  1332. if(!xmlRd.repeatitems) {f = reader(frd);}
  1333. if( ts.p.keyName===false) {
  1334. idn = $.isFunction( xmlRd.id ) ? xmlRd.id.call(ts, xml) : xmlRd.id;
  1335. } else {
  1336. idn = ts.p.keyName;
  1337. }
  1338. if( String(idn).indexOf("[") === -1 ) {
  1339. if (f.length) {
  1340. getId = function( trow, k) {return $(idn,trow).text() || k;};
  1341. } else {
  1342. getId = function( trow, k) {return $(xmlRd.cell,trow).eq(idn).text() || k;};
  1343. }
  1344. }
  1345. else {
  1346. getId = function( trow, k) {return trow.getAttribute(idn.replace(/[\[\]]/g,"")) || k;};
  1347. }
  1348. ts.p.userData = {};
  1349. ts.p.page = intNum($.jgrid.getXmlData(xml, xmlRd.page), ts.p.page);
  1350. ts.p.lastpage = intNum($.jgrid.getXmlData(xml, xmlRd.total), 1);
  1351. ts.p.records = intNum($.jgrid.getXmlData(xml, xmlRd.records));
  1352. if($.isFunction(xmlRd.userdata)) {
  1353. ts.p.userData = xmlRd.userdata.call(ts, xml) || {};
  1354. } else {
  1355. $.jgrid.getXmlData(xml, xmlRd.userdata, true).each(function() {ts.p.userData[this.getAttribute("name")]= $(this).text();});
  1356. }
  1357. var gxml = $.jgrid.getXmlData( xml, xmlRd.root, true);
  1358. gxml = $.jgrid.getXmlData( gxml, xmlRd.row, true);
  1359. if (!gxml) { gxml = []; }
  1360. var gl = gxml.length, j=0, grpdata=[], rn = parseInt(ts.p.rowNum,10), br=ts.p.scroll?$.jgrid.randId():1, altr;
  1361. if (gl > 0 && ts.p.page <= 0) { ts.p.page = 1; }
  1362. if(gxml && gl){
  1363. if (adjust) { rn *= adjust+1; }
  1364. var afterInsRow = $.isFunction(ts.p.afterInsertRow), hiderow=false, groupingPrepare;
  1365. if(ts.p.grouping) {
  1366. hiderow = ts.p.groupingView.groupCollapse === true;
  1367. groupingPrepare = $.jgrid.getMethod("groupingPrepare");
  1368. }
  1369. while (j<gl) {
  1370. xmlr = gxml[j];
  1371. rid = getId(xmlr,br+j);
  1372. rid = ts.p.idPrefix + rid;
  1373. altr = rcnt === 0 ? 0 : rcnt+1;
  1374. cn1 = (altr+j)%2 === 1 ? cn : '';
  1375. var iStartTrTag = rowData.length;
  1376. rowData.push("");
  1377. if( ni ) {
  1378. rowData.push( addRowNum(0,j,ts.p.page,ts.p.rowNum) );
  1379. }
  1380. if( gi ) {
  1381. rowData.push( addMulti(rid,ni,j, false) );
  1382. }
  1383. if( si ) {
  1384. rowData.push( addSubGridCell.call(self,gi+ni,j+rcnt) );
  1385. }
  1386. if(xmlRd.repeatitems){
  1387. if (!F) { F=orderedCols(gi+si+ni); }
  1388. var cells = $.jgrid.getXmlData( xmlr, xmlRd.cell, true);
  1389. $.each(F, function (k) {
  1390. var cell = cells[this];
  1391. if (!cell) { return false; }
  1392. v = cell.textContent || cell.text;
  1393. rd[ts.p.colModel[k+gi+si+ni].name] = v;
  1394. rowData.push( addCell(rid,v,k+gi+si+ni,j+rcnt,xmlr, rd) );
  1395. });
  1396. } else {
  1397. for(i = 0; i < f.length;i++) {
  1398. v = $.jgrid.getXmlData( xmlr, f[i]);
  1399. rd[ts.p.colModel[i+gi+si+ni].name] = v;
  1400. rowData.push( addCell(rid, v, i+gi+si+ni, j+rcnt, xmlr, rd) );
  1401. }
  1402. }
  1403. rowData[iStartTrTag] = constructTr(rid, hiderow, cn1, rd, xmlr, false);
  1404. rowData.push("</tr>");
  1405. if(ts.p.grouping) {
  1406. grpdata.push( rowData );
  1407. if(!ts.p.groupingView._locgr) {
  1408. groupingPrepare.call(self, rd, j );
  1409. }
  1410. rowData = [];
  1411. }
  1412. if(locdata || ts.p.treeGrid === true) {
  1413. rd[xmlid] = $.jgrid.stripPref(ts.p.idPrefix, rid);
  1414. ts.p.data.push(rd);
  1415. ts.p._index[rd[xmlid]] = ts.p.data.length-1;
  1416. }
  1417. if(ts.p.gridview === false ) {
  1418. $("tbody:first",t).append(rowData.join(''));
  1419. self.triggerHandler("jqGridAfterInsertRow", [rid, rd, xmlr]);
  1420. if(afterInsRow) {ts.p.afterInsertRow.call(ts,rid,rd,xmlr);}
  1421. rowData=[];
  1422. }
  1423. rd={};
  1424. ir++;
  1425. j++;
  1426. if(ir===rn) {break;}
  1427. }
  1428. }
  1429. if(ts.p.gridview === true) {
  1430. fpos = ts.p.treeANode > -1 ? ts.p.treeANode: 0;
  1431. if(ts.p.grouping) {
  1432. if(!locdata) {
  1433. self.jqGrid('groupingRender',grpdata,ts.p.colModel.length, ts.p.page, rn);
  1434. grpdata = null;
  1435. }
  1436. } else if(ts.p.treeGrid === true && fpos > 0) {
  1437. $(ts.rows[fpos]).after(rowData.join(''));
  1438. } else {
  1439. //$("tbody:first",t).append(rowData.join(''));
  1440. ts.firstElementChild.innerHTML += rowData.join(''); // append to innerHTML of tbody which contains the first row (.jqgfirstrow)
  1441. ts.grid.cols = ts.rows[0].cells; // update cached first row
  1442. }
  1443. }
  1444. if(ts.p.subGrid === true ) {
  1445. try {self.jqGrid("addSubGrid",gi+ni);} catch (_){}
  1446. }
  1447. ts.p.totaltime = new Date() - startReq;
  1448. if(ir>0) { if(ts.p.records===0) { ts.p.records=gl;} }
  1449. rowData =null;
  1450. if( ts.p.treeGrid === true) {
  1451. try {self.jqGrid("setTreeNode", fpos+1, ir+fpos+1);} catch (e) {}
  1452. }
  1453. //if(!ts.p.treeGrid && !ts.p.scroll) {ts.grid.bDiv.scrollTop = 0;}
  1454. ts.p.reccount=ir;
  1455. ts.p.treeANode = -1;
  1456. if(ts.p.userDataOnFooter) { self.jqGrid("footerData","set",ts.p.userData,true); }
  1457. if(locdata) {
  1458. ts.p.records = gl;
  1459. ts.p.lastpage = Math.ceil(gl/ rn);
  1460. }
  1461. if (!more) { ts.updatepager(false,true); }
  1462. if(locdata) {
  1463. while (ir<gl) {
  1464. xmlr = gxml[ir];
  1465. rid = getId(xmlr,ir+br);
  1466. rid = ts.p.idPrefix + rid;
  1467. if(xmlRd.repeatitems){
  1468. if (!F) { F=orderedCols(gi+si+ni); }
  1469. var cells2 = $.jgrid.getXmlData( xmlr, xmlRd.cell, true);
  1470. $.each(F, function (k) {
  1471. var cell = cells2[this];
  1472. if (!cell) { return false; }
  1473. v = cell.textContent || cell.text;
  1474. rd[ts.p.colModel[k+gi+si+ni].name] = v;
  1475. });
  1476. } else {
  1477. for(i = 0; i < f.length;i++) {
  1478. v = $.jgrid.getXmlData( xmlr, f[i]);
  1479. rd[ts.p.colModel[i+gi+si+ni].name] = v;
  1480. }
  1481. }
  1482. rd[xmlid] = $.jgrid.stripPref(ts.p.idPrefix, rid);
  1483. if(ts.p.grouping) {
  1484. groupingPrepare.call(self, rd, ir );
  1485. }
  1486. ts.p.data.push(rd);
  1487. ts.p._index[rd[xmlid]] = ts.p.data.length-1;
  1488. rd = {};
  1489. ir++;
  1490. }
  1491. if(ts.p.grouping) {
  1492. ts.p.groupingView._locgr = true;
  1493. self.jqGrid('groupingRender', grpdata, ts.p.colModel.length, ts.p.page, rn);
  1494. grpdata = null;
  1495. }
  1496. }
  1497. },
  1498. addJSONData = function(data,t, rcnt, more, adjust) {
  1499. var startReq = new Date();
  1500. if(data) {
  1501. if(ts.p.treeANode === -1 && !ts.p.scroll) {
  1502. emptyRows.call(ts, false, true);
  1503. rcnt=1;
  1504. } else { rcnt = rcnt > 1 ? rcnt :1; }
  1505. } else { return; }
  1506. var dReader, locid = "_id_", frd,
  1507. locdata = (ts.p.datatype !== "local" && ts.p.loadonce) || ts.p.datatype === "jsonstring";
  1508. if(locdata) { ts.p.data = []; ts.p._index = {}; ts.p.localReader.id = locid;}
  1509. ts.p.reccount = 0;
  1510. if(ts.p.datatype === "local") {
  1511. dReader = ts.p.localReader;
  1512. frd= 'local';
  1513. } else {
  1514. dReader = ts.p.jsonReader;
  1515. frd='json';
  1516. }
  1517. 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;
  1518. ts.p.page = intNum($.jgrid.getAccessor(data,dReader.page), ts.p.page);
  1519. ts.p.lastpage = intNum($.jgrid.getAccessor(data,dReader.total), 1);
  1520. ts.p.records = intNum($.jgrid.getAccessor(data,dReader.records));
  1521. ts.p.userData = $.jgrid.getAccessor(data,dReader.userdata) || {};
  1522. if(si) {
  1523. addSubGridCell = $.jgrid.getMethod("addSubGridCell");
  1524. }
  1525. if( ts.p.keyName===false ) {
  1526. idn = $.isFunction(dReader.id) ? dReader.id.call(ts, data) : dReader.id;
  1527. } else {
  1528. idn = ts.p.keyName;
  1529. }
  1530. drows = $.jgrid.getAccessor(data,dReader.root);
  1531. if (drows == null && $.isArray(data)) { drows = data; }
  1532. if (!drows) { drows = []; }
  1533. len = drows.length; i=0;
  1534. if (len > 0 && ts.p.page <= 0) { ts.p.page = 1; }
  1535. var rn = parseInt(ts.p.rowNum,10),br=ts.p.scroll?$.jgrid.randId():1, altr, selected=false, selr;
  1536. if (adjust) { rn *= adjust+1; }
  1537. if(ts.p.datatype === "local" && !ts.p.deselectAfterSort) {
  1538. selected = true;
  1539. }
  1540. var afterInsRow = $.isFunction(ts.p.afterInsertRow), grpdata=[],hiderow=false, groupingPrepare;
  1541. if(ts.p.grouping) {
  1542. hiderow = ts.p.groupingView.groupCollapse === true;
  1543. groupingPrepare = $.jgrid.getMethod("groupingPrepare");
  1544. }
  1545. while (i<len) {
  1546. cur = drows[i];
  1547. idr = $.jgrid.getAccessor(cur,idn);
  1548. if(idr === undefined) {
  1549. if (typeof idn === "number" && ts.p.colModel[idn+gi+si+ni] != null) {
  1550. // reread id by name
  1551. idr = $.jgrid.getAccessor(cur,ts.p.colModel[idn+gi+si+ni].name);
  1552. }
  1553. if(idr === undefined) {
  1554. idr = br+i;
  1555. if(f.length===0){
  1556. if(dReader.cell){
  1557. var ccur = $.jgrid.getAccessor(cur,dReader.cell) || cur;
  1558. idr = ccur != null && ccur[idn] !== undefined ? ccur[idn] : idr;
  1559. ccur=null;
  1560. }
  1561. }
  1562. }
  1563. }
  1564. idr = ts.p.idPrefix + idr;
  1565. altr = rcnt === 1 ? 0 : rcnt;
  1566. cn1 = (altr+i)%2 === 1 ? cn : '';
  1567. if( selected) {
  1568. if( ts.p.multiselect) {
  1569. selr = ($.inArray(idr, ts.p.selarrrow) !== -1);
  1570. } else {
  1571. selr = (idr === ts.p.selrow);
  1572. }
  1573. }
  1574. var iStartTrTag = rowData.length;
  1575. rowData.push("");
  1576. if( ni ) {
  1577. rowData.push( addRowNum(0,i,ts.p.page,ts.p.rowNum) );
  1578. }
  1579. if( gi ){
  1580. rowData.push( addMulti(idr,ni,i,selr) );
  1581. }
  1582. if( si ) {
  1583. rowData.push( addSubGridCell.call(self,gi+ni,i+rcnt) );
  1584. }
  1585. rowReader=objectReader;
  1586. if (dReader.repeatitems) {
  1587. if(dReader.cell) {cur = $.jgrid.getAccessor(cur,dReader.cell) || cur;}
  1588. if ($.isArray(cur)) { rowReader=arrayReader; }
  1589. }
  1590. for (j=0;j<rowReader.length;j++) {
  1591. v = $.jgrid.getAccessor(cur,rowReader[j]);
  1592. rd[ts.p.colModel[j+gi+si+ni].name] = v;
  1593. rowData.push( addCell(idr,v,j+gi+si+ni,i+rcnt,cur, rd) );
  1594. }
  1595. rowData[iStartTrTag] = constructTr(idr, hiderow, cn1, rd, cur, selr);
  1596. rowData.push( "</tr>" );
  1597. if(ts.p.grouping) {
  1598. grpdata.push( rowData );
  1599. if(!ts.p.groupingView._locgr) {
  1600. groupingPrepare.call(self, rd, i);
  1601. }
  1602. rowData = [];
  1603. }
  1604. if(locdata || ts.p.treeGrid===true) {
  1605. rd[locid] = $.jgrid.stripPref(ts.p.idPrefix, idr);
  1606. ts.p.data.push(rd);
  1607. ts.p._index[rd[locid]] = ts.p.data.length-1;
  1608. }
  1609. if(ts.p.gridview === false ) {
  1610. $("#"+$.jgrid.jqID(ts.p.id)+" tbody:first").append(rowData.join(''));
  1611. self.triggerHandler("jqGridAfterInsertRow", [idr, rd, cur]);
  1612. if(afterInsRow) {ts.p.afterInsertRow.call(ts,idr,rd,cur);}
  1613. rowData=[];//ari=0;
  1614. }
  1615. rd={};
  1616. ir++;
  1617. i++;
  1618. if(ir===rn) { break; }
  1619. }
  1620. if(ts.p.gridview === true ) {
  1621. fpos = ts.p.treeANode > -1 ? ts.p.treeANode: 0;
  1622. if(ts.p.grouping) {
  1623. if(!locdata) {
  1624. self.jqGrid('groupingRender', grpdata, ts.p.colModel.length, ts.p.page, rn);
  1625. grpdata = null;
  1626. }
  1627. } else if(ts.p.treeGrid === true && fpos > 0) {
  1628. $(ts.rows[fpos]).after(rowData.join(''));
  1629. } else {
  1630. //$("#"+$.jgrid.jqID(ts.p.id)+" tbody:first").append(rowData.join(''));
  1631. ts.firstElementChild.innerHTML += rowData.join(''); // append to innerHTML of tbody which contains the first row (.jqgfirstrow)
  1632. ts.grid.cols = ts.rows[0].cells; // update cached first row
  1633. }
  1634. }
  1635. if(ts.p.subGrid === true ) {
  1636. try { self.jqGrid("addSubGrid",gi+ni);} catch (_){}
  1637. }
  1638. ts.p.totaltime = new Date() - startReq;
  1639. if(ir>0) {
  1640. if(ts.p.records===0) { ts.p.records=len; }
  1641. }
  1642. rowData = null;
  1643. if( ts.p.treeGrid === true) {
  1644. try {self.jqGrid("setTreeNode", fpos+1, ir+fpos+1);} catch (e) {}
  1645. }
  1646. //if(!ts.p.treeGrid && !ts.p.scroll) {ts.grid.bDiv.scrollTop = 0;}
  1647. ts.p.reccount=ir;
  1648. ts.p.treeANode = -1;
  1649. if(ts.p.userDataOnFooter) { self.jqGrid("footerData","set",ts.p.userData,true); }
  1650. if(locdata) {
  1651. ts.p.records = len;
  1652. ts.p.lastpage = Math.ceil(len/ rn);
  1653. }
  1654. if (!more) { ts.updatepager(false,true); }
  1655. if(locdata) {
  1656. while (ir<len && drows[ir]) {
  1657. cur = drows[ir];
  1658. idr = $.jgrid.getAccessor(cur,idn);
  1659. if(idr === undefined) {
  1660. if (typeof idn === "number" && ts.p.colModel[idn+gi+si+ni] != null) {
  1661. // reread id by name
  1662. idr = $.jgrid.getAccessor(cur,ts.p.colModel[idn+gi+si+ni].name);
  1663. }
  1664. if(idr === undefined) {
  1665. idr = br+ir;
  1666. if(f.length===0){
  1667. if(dReader.cell){
  1668. var ccur2 = $.jgrid.getAccessor(cur,dReader.cell) || cur;
  1669. idr = ccur2 != null && ccur2[idn] !== undefined ? ccur2[idn] : idr;
  1670. ccur2=null;
  1671. }
  1672. }
  1673. }
  1674. }
  1675. if(cur) {
  1676. idr = ts.p.idPrefix + idr;
  1677. rowReader=objectReader;
  1678. if (dReader.repeatitems) {
  1679. if(dReader.cell) {cur = $.jgrid.getAccessor(cur,dReader.cell) || cur;}
  1680. if ($.isArray(cur)) { rowReader=arrayReader; }
  1681. }
  1682. for (j=0;j<rowReader.length;j++) {
  1683. rd[ts.p.colModel[j+gi+si+ni].name] = $.jgrid.getAccessor(cur,rowReader[j]);
  1684. }
  1685. rd[locid] = $.jgrid.stripPref(ts.p.idPrefix, idr);
  1686. if(ts.p.grouping) {
  1687. groupingPrepare.call(self, rd, ir );
  1688. }
  1689. ts.p.data.push(rd);
  1690. ts.p._index[rd[locid]] = ts.p.data.length-1;
  1691. rd = {};
  1692. }
  1693. ir++;
  1694. }
  1695. if(ts.p.grouping) {
  1696. ts.p.groupingView._locgr = true;
  1697. self.jqGrid('groupingRender', grpdata, ts.p.colModel.length, ts.p.page, rn);
  1698. grpdata = null;
  1699. }
  1700. }
  1701. },
  1702. addLocalData = function() {
  1703. var st = ts.p.multiSort ? [] : "", sto=[], fndsort=false, cmtypes={}, grtypes=[], grindexes=[], srcformat, sorttype, newformat;
  1704. if(!$.isArray(ts.p.data)) {
  1705. return;
  1706. }
  1707. var grpview = ts.p.grouping ? ts.p.groupingView : false, lengrp, gin;
  1708. $.each(ts.p.colModel,function(){
  1709. sorttype = this.sorttype || "text";
  1710. if(sorttype === "date" || sorttype === "datetime") {
  1711. if(this.formatter && typeof this.formatter === 'string' && this.formatter === 'date') {
  1712. if(this.formatoptions && this.formatoptions.srcformat) {
  1713. srcformat = this.formatoptions.srcformat;
  1714. } else {
  1715. srcformat = $.jgrid.formatter.date.srcformat;
  1716. }
  1717. if(this.formatoptions && this.formatoptions.newformat) {
  1718. newformat = this.formatoptions.newformat;
  1719. } else {
  1720. newformat = $.jgrid.formatter.date.newformat;
  1721. }
  1722. } else {
  1723. srcformat = newformat = this.datefmt || "Y-m-d";
  1724. }
  1725. cmtypes[this.name] = {"stype": sorttype, "srcfmt": srcformat,"newfmt":newformat, "sfunc": this.sortfunc || null};
  1726. } else {
  1727. cmtypes[this.name] = {"stype": sorttype, "srcfmt":'',"newfmt":'', "sfunc": this.sortfunc || null};
  1728. }
  1729. if(ts.p.grouping ) {
  1730. for(gin =0, lengrp = grpview.groupField.length; gin< lengrp; gin++) {
  1731. if( this.name === grpview.groupField[gin]) {
  1732. var grindex = this.name;
  1733. if (this.index) {
  1734. grindex = this.index;
  1735. }
  1736. grtypes[gin] = cmtypes[grindex];
  1737. grindexes[gin]= grindex;
  1738. }
  1739. }
  1740. }
  1741. if(ts.p.multiSort) {
  1742. if(this.lso) {
  1743. st.push(this.name);
  1744. var tmplso= this.lso.split("-");
  1745. sto.push( tmplso[tmplso.length-1] );
  1746. }
  1747. } else {
  1748. if(!fndsort && (this.index === ts.p.sortname || this.name === ts.p.sortname)){
  1749. st = this.name; // ???
  1750. fndsort = true;
  1751. }
  1752. }
  1753. });
  1754. if(ts.p.treeGrid) {
  1755. $(ts).jqGrid("SortTree", st, ts.p.sortorder, cmtypes[st].stype || 'text', cmtypes[st].srcfmt || '');
  1756. return;
  1757. }
  1758. var compareFnMap = {
  1759. 'eq':function(queryObj) {return queryObj.equals;},
  1760. 'ne':function(queryObj) {return queryObj.notEquals;},
  1761. 'lt':function(queryObj) {return queryObj.less;},
  1762. 'le':function(queryObj) {return queryObj.lessOrEquals;},
  1763. 'gt':function(queryObj) {return queryObj.greater;},
  1764. 'ge':function(queryObj) {return queryObj.greaterOrEquals;},
  1765. 'cn':function(queryObj) {return queryObj.contains;},
  1766. 'nc':function(queryObj,op) {return op === "OR" ? queryObj.orNot().contains : queryObj.andNot().contains;},
  1767. 'bw':function(queryObj) {return queryObj.startsWith;},
  1768. 'bn':function(queryObj,op) {return op === "OR" ? queryObj.orNot().startsWith : queryObj.andNot().startsWith;},
  1769. 'en':function(queryObj,op) {return op === "OR" ? queryObj.orNot().endsWith : queryObj.andNot().endsWith;},
  1770. 'ew':function(queryObj) {return queryObj.endsWith;},
  1771. 'ni':function(queryObj,op) {return op === "OR" ? queryObj.orNot().equals : queryObj.andNot().equals;},
  1772. 'in':function(queryObj) {return queryObj.equals;},
  1773. 'nu':function(queryObj) {return queryObj.isNull;},
  1774. 'nn':function(queryObj,op) {return op === "OR" ? queryObj.orNot().isNull : queryObj.andNot().isNull;}
  1775. },
  1776. query = $.jgrid.from(ts.p.data);
  1777. if (ts.p.ignoreCase) { query = query.ignoreCase(); }
  1778. function tojLinq ( group ) {
  1779. var s = 0, index, gor, ror, opr, rule;
  1780. if (group.groups != null) {
  1781. gor = group.groups.length && group.groupOp.toString().toUpperCase() === "OR";
  1782. if (gor) {
  1783. query.orBegin();
  1784. }
  1785. for (index = 0; index < group.groups.length; index++) {
  1786. if (s > 0 && gor) {
  1787. query.or();
  1788. }
  1789. try {
  1790. tojLinq(group.groups[index]);
  1791. } catch (e) {alert(e);}
  1792. s++;
  1793. }
  1794. if (gor) {
  1795. query.orEnd();
  1796. }
  1797. }
  1798. if (group.rules != null) {
  1799. //if(s>0) {
  1800. // var result = query.select();
  1801. // query = $.jgrid.from( result);
  1802. // if (ts.p.ignoreCase) { query = query.ignoreCase(); }
  1803. //}
  1804. try{
  1805. ror = group.rules.length && group.groupOp.toString().toUpperCase() === "OR";
  1806. if (ror) {
  1807. query.orBegin();
  1808. }
  1809. for (index = 0; index < group.rules.length; index++) {
  1810. rule = group.rules[index];
  1811. opr = group.groupOp.toString().toUpperCase();
  1812. if (compareFnMap[rule.op] && rule.field ) {
  1813. if(s > 0 && opr && opr === "OR") {
  1814. query = query.or();
  1815. }
  1816. query = compareFnMap[rule.op](query, opr)(rule.field, rule.data, cmtypes[rule.field]);
  1817. }
  1818. s++;
  1819. }
  1820. if (ror) {
  1821. query.orEnd();
  1822. }
  1823. } catch (g) {alert(g);}
  1824. }
  1825. }
  1826. if (ts.p.search === true) {
  1827. var srules = ts.p.postData.filters;
  1828. if(srules) {
  1829. if(typeof srules === "string") { srules = $.jgrid.parse(srules);}
  1830. tojLinq( srules );
  1831. } else {
  1832. try {
  1833. query = compareFnMap[ts.p.postData.searchOper](query)(ts.p.postData.searchField, ts.p.postData.searchString,cmtypes[ts.p.postData.searchField]);
  1834. } catch (se){}
  1835. }
  1836. }
  1837. if(ts.p.grouping) {
  1838. for(gin=0; gin<lengrp;gin++) {
  1839. query.orderBy(grindexes[gin],grpview.groupOrder[gin],grtypes[gin].stype, grtypes[gin].srcfmt);
  1840. }
  1841. }
  1842. if(ts.p.multiSort) {
  1843. $.each(st,function(i){
  1844. query.orderBy(this, sto[i], cmtypes[this].stype, cmtypes[this].srcfmt, cmtypes[this].sfunc);
  1845. });
  1846. } else {
  1847. if (st && ts.p.sortorder && fndsort) {
  1848. if(ts.p.sortorder.toUpperCase() === "DESC") {
  1849. query.orderBy(ts.p.sortname, "d", cmtypes[st].stype, cmtypes[st].srcfmt, cmtypes[st].sfunc);
  1850. } else {
  1851. query.orderBy(ts.p.sortname, "a", cmtypes[st].stype, cmtypes[st].srcfmt, cmtypes[st].sfunc);
  1852. }
  1853. }
  1854. }
  1855. var queryResults = query.select(),
  1856. recordsperpage = parseInt(ts.p.rowNum,10),
  1857. total = queryResults.length,
  1858. page = parseInt(ts.p.page,10),
  1859. totalpages = Math.ceil(total / recordsperpage),
  1860. retresult = {};
  1861. if((ts.p.search || ts.p.resetsearch) && ts.p.grouping && ts.p.groupingView._locgr) {
  1862. ts.p.groupingView.groups =[];
  1863. var j, grPrepare = $.jgrid.getMethod("groupingPrepare"), key, udc;
  1864. if(ts.p.footerrow && ts.p.userDataOnFooter) {
  1865. for (key in ts.p.userData) {
  1866. if(ts.p.userData.hasOwnProperty(key)) {
  1867. ts.p.userData[key] = 0;
  1868. }
  1869. }
  1870. udc = true;
  1871. }
  1872. for(j=0; j<total; j++) {
  1873. if(udc) {
  1874. for(key in ts.p.userData){
  1875. ts.p.userData[key] += parseFloat(queryResults[j][key] || 0);
  1876. }
  1877. }
  1878. grPrepare.call($(ts),queryResults[j],j, recordsperpage );
  1879. }
  1880. }
  1881. queryResults = queryResults.slice( (page-1)*recordsperpage , page*recordsperpage );
  1882. query = null;
  1883. cmtypes = null;
  1884. retresult[ts.p.localReader.total] = totalpages;
  1885. retresult[ts.p.localReader.page] = page;
  1886. retresult[ts.p.localReader.records] = total;
  1887. retresult[ts.p.localReader.root] = queryResults;
  1888. retresult[ts.p.localReader.userdata] = ts.p.userData;
  1889. queryResults = null;
  1890. return retresult;
  1891. },
  1892. updatepager = function(rn, dnd) {
  1893. var cp, last, base, from,to,tot,fmt, pgboxes = "", sppg,
  1894. tspg = ts.p.pager ? "_"+$.jgrid.jqID(ts.p.pager.substr(1)) : "",
  1895. tspg_t = ts.p.toppager ? "_"+ts.p.toppager.substr(1) : "";
  1896. base = parseInt(ts.p.page,10)-1;
  1897. if(base < 0) { base = 0; }
  1898. base = base*parseInt(ts.p.rowNum,10);
  1899. to = base + ts.p.reccount;
  1900. if (ts.p.scroll) {
  1901. var rows = $("tbody:first > tr:gt(0)", ts.grid.bDiv);
  1902. base = to - rows.length;
  1903. ts.p.reccount = rows.length;
  1904. var rh = rows.outerHeight() || ts.grid.prevRowHeight;
  1905. if (rh) {
  1906. var top = base * rh;
  1907. var height = parseInt(ts.p.records,10) * rh;
  1908. $(">div:first",ts.grid.bDiv).css({height : height}).children("div:first").css({height:top,display:top?"":"none"});
  1909. if (ts.grid.bDiv.scrollTop == 0 && ts.p.page > 1) {
  1910. ts.grid.bDiv.scrollTop = ts.p.rowNum * (ts.p.page - 1) * rh;
  1911. }
  1912. }
  1913. ts.grid.bDiv.scrollLeft = ts.grid.hDiv.scrollLeft;
  1914. }
  1915. pgboxes = ts.p.pager || "";
  1916. pgboxes += ts.p.toppager ? (pgboxes ? "," + ts.p.toppager : ts.p.toppager) : "";
  1917. if(pgboxes) {
  1918. fmt = $.jgrid.formatter.integer || {};
  1919. cp = intNum(ts.p.page);
  1920. last = intNum(ts.p.lastpage);
  1921. $(".selbox",pgboxes)[ this.p.useProp ? 'prop' : 'attr' ]("disabled",false);
  1922. if(ts.p.pginput===true) {
  1923. $('.ui-pg-input',pgboxes).val(ts.p.page);
  1924. sppg = ts.p.toppager ? '#sp_1'+tspg+",#sp_1"+tspg_t : '#sp_1'+tspg;
  1925. $(sppg).html($.fmatter ? $.fmatter.util.NumberFormat(ts.p.lastpage,fmt):ts.p.lastpage);
  1926. }
  1927. if (ts.p.viewrecords){
  1928. if(ts.p.reccount === 0) {
  1929. $(".ui-paging-info",pgboxes).html(ts.p.emptyrecords);
  1930. } else {
  1931. from = base+1;
  1932. tot=ts.p.records;
  1933. if($.fmatter) {
  1934. from = $.fmatter.util.NumberFormat(from,fmt);
  1935. to = $.fmatter.util.NumberFormat(to,fmt);
  1936. tot = $.fmatter.util.NumberFormat(tot,fmt);
  1937. }
  1938. $(".ui-paging-info",pgboxes).html($.jgrid.format(ts.p.recordtext,from,to,tot));
  1939. }
  1940. }
  1941. if(ts.p.pgbuttons===true) {
  1942. if(cp<=0) {cp = last = 0;}
  1943. if(cp===1 || cp === 0) {
  1944. $("#first"+tspg+", #prev"+tspg).addClass('ui-state-disabled').removeClass('ui-state-hover');
  1945. if(ts.p.toppager) { $("#first_t"+tspg_t+", #prev_t"+tspg_t).addClass('ui-state-disabled').removeClass('ui-state-hover'); }
  1946. } else {
  1947. $("#first"+tspg+", #prev"+tspg).removeClass('ui-state-disabled');
  1948. if(ts.p.toppager) { $("#first_t"+tspg_t+", #prev_t"+tspg_t).removeClass('ui-state-disabled'); }
  1949. }
  1950. if(cp===last || cp === 0) {
  1951. $("#next"+tspg+", #last"+tspg).addClass('ui-state-disabled').removeClass('ui-state-hover');
  1952. if(ts.p.toppager) { $("#next_t"+tspg_t+", #last_t"+tspg_t).addClass('ui-state-disabled').removeClass('ui-state-hover'); }
  1953. } else {
  1954. $("#next"+tspg+", #last"+tspg).removeClass('ui-state-disabled');
  1955. if(ts.p.toppager) { $("#next_t"+tspg_t+", #last_t"+tspg_t).removeClass('ui-state-disabled'); }
  1956. }
  1957. }
  1958. }
  1959. if(rn===true && ts.p.rownumbers === true) {
  1960. $(">td.jqgrid-rownum",ts.rows).each(function(i){
  1961. $(this).html(base+1+i);
  1962. });
  1963. }
  1964. if(dnd && ts.p.jqgdnd) { $(ts).jqGrid('gridDnD','updateDnD');}
  1965. $(ts).triggerHandler("jqGridGridComplete");
  1966. if($.isFunction(ts.p.gridComplete)) {ts.p.gridComplete.call(ts);}
  1967. $(ts).triggerHandler("jqGridAfterGridComplete");
  1968. },
  1969. beginReq = function() {
  1970. ts.grid.hDiv.loading = true;
  1971. if(ts.p.hiddengrid) { return;}
  1972. $(ts).jqGrid("progressBar", {method:"show", loadtype : ts.p.loadui, htmlcontent: ts.p.loadtext });
  1973. },
  1974. endReq = function() {
  1975. ts.grid.hDiv.loading = false;
  1976. $(ts).jqGrid("progressBar", {method:"hide", loadtype : ts.p.loadui });
  1977. },
  1978. populate = function (npage) {
  1979. if(!ts.grid.hDiv.loading) {
  1980. var pvis = ts.p.scroll && npage === false,
  1981. prm = {}, dt, dstr, pN=ts.p.prmNames;
  1982. if(ts.p.page <=0) { ts.p.page = Math.min(1,ts.p.lastpage); }
  1983. if(pN.search !== null) {prm[pN.search] = ts.p.search;} if(pN.nd !== null) {prm[pN.nd] = new Date().getTime();}
  1984. if(pN.rows !== null) {prm[pN.rows]= ts.p.rowNum;} if(pN.page !== null) {prm[pN.page]= ts.p.page;}
  1985. if(pN.sort !== null) {prm[pN.sort]= ts.p.sortname;} if(pN.order !== null) {prm[pN.order]= ts.p.sortorder;}
  1986. if(ts.p.rowTotal !== null && pN.totalrows !== null) { prm[pN.totalrows]= ts.p.rowTotal; }
  1987. var lcf = $.isFunction(ts.p.loadComplete), lc = lcf ? ts.p.loadComplete : null;
  1988. var adjust = 0;
  1989. npage = npage || 1;
  1990. if (npage > 1) {
  1991. if(pN.npage !== null) {
  1992. prm[pN.npage] = npage;
  1993. adjust = npage - 1;
  1994. npage = 1;
  1995. } else {
  1996. lc = function(req) {
  1997. ts.p.page++;
  1998. ts.grid.hDiv.loading = false;
  1999. if (lcf) {
  2000. ts.p.loadComplete.call(ts,req);
  2001. }
  2002. populate(npage-1);
  2003. };
  2004. }
  2005. } else if (pN.npage !== null) {
  2006. delete ts.p.postData[pN.npage];
  2007. }
  2008. if(ts.p.grouping) {
  2009. $(ts).jqGrid('groupingSetup');
  2010. var grp = ts.p.groupingView, gi, gs="";
  2011. for(gi=0;gi<grp.groupField.length;gi++) {
  2012. var index = grp.groupField[gi];
  2013. $.each(ts.p.colModel, function(cmIndex, cmValue) {
  2014. if (cmValue.name === index && cmValue.index){
  2015. index = cmValue.index;
  2016. }
  2017. } );
  2018. gs += index +" "+grp.groupOrder[gi]+", ";
  2019. }
  2020. prm[pN.sort] = gs + prm[pN.sort];
  2021. }
  2022. $.extend(ts.p.postData,prm);
  2023. var rcnt = !ts.p.scroll ? 1 : ts.rows.length-1;
  2024. var bfr = $(ts).triggerHandler("jqGridBeforeRequest");
  2025. if (bfr === false || bfr === 'stop') { return; }
  2026. if ($.isFunction(ts.p.datatype)) { ts.p.datatype.call(ts,ts.p.postData,"load_"+ts.p.id, rcnt, npage, adjust); return;}
  2027. if ($.isFunction(ts.p.beforeRequest)) {
  2028. bfr = ts.p.beforeRequest.call(ts);
  2029. if(bfr === undefined) { bfr = true; }
  2030. if ( bfr === false ) { return; }
  2031. }
  2032. dt = ts.p.datatype.toLowerCase();
  2033. switch(dt)
  2034. {
  2035. case "json":
  2036. case "jsonp":
  2037. case "xml":
  2038. case "script":
  2039. $.ajax($.extend({
  2040. url:ts.p.url,
  2041. type:ts.p.mtype,
  2042. dataType: dt ,
  2043. data: $.isFunction(ts.p.serializeGridData)? ts.p.serializeGridData.call(ts,ts.p.postData) : ts.p.postData,
  2044. success:function(data,st, xhr) {
  2045. if ($.isFunction(ts.p.beforeProcessing)) {
  2046. if (ts.p.beforeProcessing.call(ts, data, st, xhr) === false) {
  2047. endReq();
  2048. return;
  2049. }
  2050. }
  2051. if(dt === "xml") { addXmlData(data,ts.grid.bDiv,rcnt,npage>1,adjust); }
  2052. else { addJSONData(data,ts.grid.bDiv,rcnt,npage>1,adjust); }
  2053. $(ts).triggerHandler("jqGridLoadComplete", [data]);
  2054. if(lc) { lc.call(ts,data); }
  2055. $(ts).triggerHandler("jqGridAfterLoadComplete", [data]);
  2056. if (pvis) { ts.grid.populateVisible(); }
  2057. if( ts.p.loadonce || ts.p.treeGrid) {ts.p.datatype = "local";}
  2058. data=null;
  2059. if (npage === 1) { endReq(); }
  2060. },
  2061. error:function(xhr,st,err){
  2062. if($.isFunction(ts.p.loadError)) { ts.p.loadError.call(ts,xhr,st,err); }
  2063. if (npage === 1) { endReq(); }
  2064. xhr=null;
  2065. },
  2066. beforeSend: function(xhr, settings ){
  2067. var gotoreq = true;
  2068. if($.isFunction(ts.p.loadBeforeSend)) {
  2069. gotoreq = ts.p.loadBeforeSend.call(ts,xhr, settings);
  2070. }
  2071. if(gotoreq === undefined) { gotoreq = true; }
  2072. if(gotoreq === false) {
  2073. return false;
  2074. }
  2075. beginReq();
  2076. }
  2077. },$.jgrid.ajaxOptions, ts.p.ajaxGridOptions));
  2078. break;
  2079. case "xmlstring":
  2080. beginReq();
  2081. dstr = typeof ts.p.datastr !== 'string' ? ts.p.datastr : $.parseXML(ts.p.datastr);
  2082. addXmlData(dstr,ts.grid.bDiv);
  2083. $(ts).triggerHandler("jqGridLoadComplete", [dstr]);
  2084. if(lcf) {ts.p.loadComplete.call(ts,dstr);}
  2085. $(ts).triggerHandler("jqGridAfterLoadComplete", [dstr]);
  2086. ts.p.datatype = "local";
  2087. ts.p.datastr = null;
  2088. endReq();
  2089. break;
  2090. case "jsonstring":
  2091. beginReq();
  2092. if(typeof ts.p.datastr === 'string') { dstr = $.jgrid.parse(ts.p.datastr); }
  2093. else { dstr = ts.p.datastr; }
  2094. addJSONData(dstr,ts.grid.bDiv);
  2095. $(ts).triggerHandler("jqGridLoadComplete", [dstr]);
  2096. if(lcf) {ts.p.loadComplete.call(ts,dstr);}
  2097. $(ts).triggerHandler("jqGridAfterLoadComplete", [dstr]);
  2098. ts.p.datatype = "local";
  2099. ts.p.datastr = null;
  2100. endReq();
  2101. break;
  2102. case "local":
  2103. case "clientside":
  2104. beginReq();
  2105. ts.p.datatype = "local";
  2106. var req = addLocalData();
  2107. addJSONData(req,ts.grid.bDiv,rcnt,npage>1,adjust);
  2108. $(ts).triggerHandler("jqGridLoadComplete", [req]);
  2109. if(lc) { lc.call(ts,req); }
  2110. $(ts).triggerHandler("jqGridAfterLoadComplete", [req]);
  2111. if (pvis) { ts.grid.populateVisible(); }
  2112. endReq();
  2113. break;
  2114. }
  2115. }
  2116. },
  2117. setHeadCheckBox = function ( checked ) {
  2118. $('#cb_'+$.jgrid.jqID(ts.p.id),ts.grid.hDiv)[ts.p.useProp ? 'prop': 'attr']("checked", checked);
  2119. var fid = ts.p.frozenColumns ? ts.p.id+"_frozen" : "";
  2120. if(fid) {
  2121. $('#cb_'+$.jgrid.jqID(ts.p.id),ts.grid.fhDiv)[ts.p.useProp ? 'prop': 'attr']("checked", checked);
  2122. }
  2123. },
  2124. setPager = function (pgid, tp){
  2125. // TBD - consider escaping pgid with pgid = $.jgrid.jqID(pgid);
  2126. var sep = "<td class='ui-pg-button ui-state-disabled' style='width:4px;'><span class='ui-separator'></span></td>",
  2127. pginp = "",
  2128. pgl="<table cellspacing='0' cellpadding='0' border='0' style='table-layout:auto;' class='ui-pg-table'><tbody><tr>",
  2129. str="", pgcnt, lft, cent, rgt, twd, tdw, i,
  2130. clearVals = function(onpaging){
  2131. var ret;
  2132. if ($.isFunction(ts.p.onPaging) ) { ret = ts.p.onPaging.call(ts,onpaging); }
  2133. if(ret==='stop') {return false;}
  2134. ts.p.selrow = null;
  2135. if(ts.p.multiselect) {ts.p.selarrrow =[]; setHeadCheckBox( false );}
  2136. ts.p.savedRow = [];
  2137. return true;
  2138. };
  2139. pgid = pgid.substr(1);
  2140. tp += "_" + pgid;
  2141. pgcnt = "pg_"+pgid;
  2142. lft = pgid+"_left"; cent = pgid+"_center"; rgt = pgid+"_right";
  2143. $("#"+$.jgrid.jqID(pgid) )
  2144. .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>")
  2145. .attr("dir","ltr"); //explicit setting
  2146. if(ts.p.rowList.length >0){
  2147. str = "<td dir='"+dir+"'>";
  2148. str +="<select class='ui-pg-selbox' role='listbox' " + (ts.p.pgrecs ? "title='"+ts.p.pgrecs +"'" : "")+ ">";
  2149. var strnm;
  2150. for(i=0;i<ts.p.rowList.length;i++){
  2151. strnm = ts.p.rowList[i].toString().split(":");
  2152. if(strnm.length === 1) {
  2153. strnm[1] = strnm[0];
  2154. }
  2155. str +="<option role=\"option\" value=\""+strnm[0]+"\""+(( intNum(ts.p.rowNum,0) === intNum(strnm[0],0))?" selected=\"selected\"":"")+">"+strnm[1]+"</option>";
  2156. }
  2157. str +="</select></td>";
  2158. }
  2159. if(dir==="rtl") { pgl += str; }
  2160. 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>";}
  2161. if(ts.p.pgbuttons===true) {
  2162. var po=["first"+tp,"prev"+tp, "next"+tp,"last"+tp]; if(dir==="rtl") { po.reverse(); }
  2163. pgl += "<td id='"+po[0]+"' class='ui-pg-button ui-corner-all' " + (ts.p.pgfirst ? "title='"+ts.p.pgfirst +"'" : "")+"><span class='ui-icon ui-icon-seek-first'></span></td>";
  2164. pgl += "<td id='"+po[1]+"' class='ui-pg-button ui-corner-all' " + (ts.p.pgprev ? "title='"+ts.p.pgprev +"'" : "")+"><span class='ui-icon ui-icon-seek-prev'></span></td>";
  2165. pgl += pginp !== "" ? sep+pginp+sep:"";
  2166. pgl += "<td id='"+po[2]+"' class='ui-pg-button ui-corner-all' " + (ts.p.pgnext ? "title='"+ts.p.pgnext +"'" : "")+"><span class='ui-icon ui-icon-seek-next'></span></td>";
  2167. pgl += "<td id='"+po[3]+"' class='ui-pg-button ui-corner-all' " + (ts.p.pglast ? "title='"+ts.p.pglast +"'" : "")+"><span class='ui-icon ui-icon-seek-end'></span></td>";
  2168. } else if (pginp !== "") { pgl += pginp; }
  2169. if(dir==="ltr") { pgl += str; }
  2170. pgl += "</tr></tbody></table>";
  2171. 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>");}
  2172. $("td#"+pgid+"_"+ts.p.pagerpos,"#"+pgcnt).append(pgl);
  2173. tdw = $(".ui-jqgrid").css("font-size") || "11px";
  2174. $(document.body).append("<div id='testpg' class='ui-jqgrid ui-widget ui-widget-content' style='font-size:"+tdw+";visibility:hidden;' ></div>");
  2175. twd = $(pgl).clone().appendTo("#testpg").width();
  2176. $("#testpg").remove();
  2177. if(twd > 0) {
  2178. if(pginp !== "") { twd += 50; } //should be param
  2179. $("td#"+pgid+"_"+ts.p.pagerpos,"#"+pgcnt).width(twd);
  2180. }
  2181. ts.p._nvtd = [];
  2182. ts.p._nvtd[0] = twd ? Math.floor((ts.p.width - twd)/2) : Math.floor(ts.p.width/3);
  2183. ts.p._nvtd[1] = 0;
  2184. pgl=null;
  2185. $('.ui-pg-selbox',"#"+pgcnt).bind('change',function() {
  2186. if(!clearVals('records')) { return false; }
  2187. ts.p.page = Math.round(ts.p.rowNum*(ts.p.page-1)/this.value-0.5)+1;
  2188. ts.p.rowNum = this.value;
  2189. if(ts.p.pager) { $('.ui-pg-selbox',ts.p.pager).val(this.value); }
  2190. if(ts.p.toppager) { $('.ui-pg-selbox',ts.p.toppager).val(this.value); }
  2191. populate();
  2192. return false;
  2193. });
  2194. if(ts.p.pgbuttons===true) {
  2195. $(".ui-pg-button","#"+pgcnt).hover(function(){
  2196. if($(this).hasClass('ui-state-disabled')) {
  2197. this.style.cursor='default';
  2198. } else {
  2199. $(this).addClass('ui-state-hover');
  2200. this.style.cursor='pointer';
  2201. }
  2202. },function() {
  2203. if(!$(this).hasClass('ui-state-disabled')) {
  2204. $(this).removeClass('ui-state-hover');
  2205. this.style.cursor= "default";
  2206. }
  2207. });
  2208. $("#first"+$.jgrid.jqID(tp)+", #prev"+$.jgrid.jqID(tp)+", #next"+$.jgrid.jqID(tp)+", #last"+$.jgrid.jqID(tp)).click( function() {
  2209. if ($(this).hasClass("ui-state-disabled")) {
  2210. return false;
  2211. }
  2212. var cp = intNum(ts.p.page,1),
  2213. last = intNum(ts.p.lastpage,1), selclick = false,
  2214. fp=true, pp=true, np=true,lp=true;
  2215. if(last ===0 || last===1) {fp=false;pp=false;np=false;lp=false; }
  2216. else if( last>1 && cp >=1) {
  2217. if( cp === 1) { fp=false; pp=false; }
  2218. //else if( cp>1 && cp <last){ }
  2219. else if( cp===last){ np=false;lp=false; }
  2220. } else if( last>1 && cp===0 ) { np=false;lp=false; cp=last-1;}
  2221. if(!clearVals(this.id)) { return false; }
  2222. if( this.id === 'first'+tp && fp ) { ts.p.page=1; selclick=true;}
  2223. if( this.id === 'prev'+tp && pp) { ts.p.page=(cp-1); selclick=true;}
  2224. if( this.id === 'next'+tp && np) { ts.p.page=(cp+1); selclick=true;}
  2225. if( this.id === 'last'+tp && lp) { ts.p.page=last; selclick=true;}
  2226. if(selclick) {
  2227. populate();
  2228. }
  2229. return false;
  2230. });
  2231. }
  2232. if(ts.p.pginput===true) {
  2233. $('input.ui-pg-input',"#"+pgcnt).keypress( function(e) {
  2234. var key = e.charCode || e.keyCode || 0;
  2235. if(key === 13) {
  2236. if(!clearVals('user')) { return false; }
  2237. $(this).val( intNum( $(this).val(), 1));
  2238. ts.p.page = ($(this).val()>0) ? $(this).val():ts.p.page;
  2239. populate();
  2240. return false;
  2241. }
  2242. return this;
  2243. });
  2244. }
  2245. },
  2246. multiSort = function(iCol, obj ) {
  2247. var splas, sort="", cm = ts.p.colModel, fs=false, ls,
  2248. selTh = ts.p.frozenColumns ? obj : ts.grid.headers[iCol].el, so="";
  2249. $("span.ui-grid-ico-sort",selTh).addClass('ui-state-disabled');
  2250. $(selTh).attr("aria-selected","false");
  2251. if(cm[iCol].lso) {
  2252. if(cm[iCol].lso==="asc") {
  2253. cm[iCol].lso += "-desc";
  2254. so = "desc";
  2255. } else if(cm[iCol].lso==="desc") {
  2256. cm[iCol].lso += "-asc";
  2257. so = "asc";
  2258. } else if(cm[iCol].lso==="asc-desc" || cm[iCol].lso==="desc-asc") {
  2259. cm[iCol].lso="";
  2260. }
  2261. } else {
  2262. cm[iCol].lso = so = cm[iCol].firstsortorder || 'asc';
  2263. }
  2264. if( so ) {
  2265. $("span.s-ico",selTh).show();
  2266. $("span.ui-icon-"+so,selTh).removeClass('ui-state-disabled');
  2267. $(selTh).attr("aria-selected","true");
  2268. } else {
  2269. if(!ts.p.viewsortcols[0]) {
  2270. $("span.s-ico",selTh).hide();
  2271. }
  2272. }
  2273. ts.p.sortorder = "";
  2274. $.each(cm, function(i){
  2275. if(this.lso) {
  2276. if(i>0 && fs) {
  2277. sort += ", ";
  2278. }
  2279. splas = this.lso.split("-");
  2280. sort += cm[i].index || cm[i].name;
  2281. sort += " "+splas[splas.length-1];
  2282. fs = true;
  2283. ts.p.sortorder = splas[splas.length-1];
  2284. }
  2285. });
  2286. ls = sort.lastIndexOf(ts.p.sortorder);
  2287. sort = sort.substring(0, ls);
  2288. ts.p.sortname = sort;
  2289. },
  2290. sortData = function (index, idxcol,reload,sor, obj){
  2291. if(!ts.p.colModel[idxcol].sortable) { return; }
  2292. if(ts.p.savedRow.length > 0) {return;}
  2293. if(!reload) {
  2294. if( ts.p.lastsort === idxcol && ts.p.sortname !== "" ) {
  2295. if( ts.p.sortorder === 'asc') {
  2296. ts.p.sortorder = 'desc';
  2297. } else if(ts.p.sortorder === 'desc') { ts.p.sortorder = 'asc';}
  2298. } else { ts.p.sortorder = ts.p.colModel[idxcol].firstsortorder || 'asc'; }
  2299. ts.p.page = 1;
  2300. }
  2301. if(ts.p.multiSort) {
  2302. multiSort( idxcol, obj);
  2303. } else {
  2304. if(sor) {
  2305. if(ts.p.lastsort === idxcol && ts.p.sortorder === sor && !reload) { return; }
  2306. ts.p.sortorder = sor;
  2307. }
  2308. var previousSelectedTh = ts.grid.headers[ts.p.lastsort].el, newSelectedTh = ts.p.frozenColumns ? obj : ts.grid.headers[idxcol].el;
  2309. $("span.ui-grid-ico-sort",previousSelectedTh).addClass('ui-state-disabled');
  2310. $(previousSelectedTh).attr("aria-selected","false");
  2311. if(ts.p.frozenColumns) {
  2312. ts.grid.fhDiv.find("span.ui-grid-ico-sort").addClass('ui-state-disabled');
  2313. ts.grid.fhDiv.find("th").attr("aria-selected","false");
  2314. }
  2315. $("span.ui-icon-"+ts.p.sortorder,newSelectedTh).removeClass('ui-state-disabled');
  2316. $(newSelectedTh).attr("aria-selected","true");
  2317. if(!ts.p.viewsortcols[0]) {
  2318. if(ts.p.lastsort !== idxcol) {
  2319. if(ts.p.frozenColumns){
  2320. ts.grid.fhDiv.find("span.s-ico").hide();
  2321. }
  2322. $("span.s-ico",previousSelectedTh).hide();
  2323. $("span.s-ico",newSelectedTh).show();
  2324. } else if (ts.p.sortname === "") { // if ts.p.lastsort === idxcol but ts.p.sortname === ""
  2325. $("span.s-ico",newSelectedTh).show();
  2326. }
  2327. }
  2328. index = index.substring(5 + ts.p.id.length + 1); // bad to be changed!?!
  2329. ts.p.sortname = ts.p.colModel[idxcol].index || index;
  2330. }
  2331. if ($(ts).triggerHandler("jqGridSortCol", [ts.p.sortname, idxcol, ts.p.sortorder]) === 'stop') {
  2332. ts.p.lastsort = idxcol;
  2333. return;
  2334. }
  2335. if($.isFunction(ts.p.onSortCol)) {if (ts.p.onSortCol.call(ts, ts.p.sortname, idxcol, ts.p.sortorder)==='stop') {ts.p.lastsort = idxcol; return;}}
  2336. if(ts.p.datatype === "local") {
  2337. if(ts.p.deselectAfterSort) {$(ts).jqGrid("resetSelection");}
  2338. } else {
  2339. ts.p.selrow = null;
  2340. if(ts.p.multiselect){setHeadCheckBox( false );}
  2341. ts.p.selarrrow =[];
  2342. ts.p.savedRow =[];
  2343. }
  2344. if(ts.p.scroll) {
  2345. var sscroll = ts.grid.bDiv.scrollLeft;
  2346. emptyRows.call(ts, true, false);
  2347. ts.grid.hDiv.scrollLeft = sscroll;
  2348. }
  2349. if(ts.p.subGrid && ts.p.datatype === 'local') {
  2350. $("td.sgexpanded","#"+$.jgrid.jqID(ts.p.id)).each(function(){
  2351. $(this).trigger("click");
  2352. });
  2353. }
  2354. populate();
  2355. ts.p.lastsort = idxcol;
  2356. if(ts.p.sortname !== index && idxcol) {ts.p.lastsort = idxcol;}
  2357. },
  2358. setColWidth = function () {
  2359. 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;
  2360. $.each(ts.p.colModel, function() {
  2361. if(this.hidden === undefined) {this.hidden=false;}
  2362. if(ts.p.grouping && ts.p.autowidth) {
  2363. var ind = $.inArray(this.name, ts.p.groupingView.groupField);
  2364. if(ind >= 0 && ts.p.groupingView.groupColumnShow.length > ind) {
  2365. this.hidden = !ts.p.groupingView.groupColumnShow[ind];
  2366. }
  2367. }
  2368. this.widthOrg = cw = intNum(this.width,0);
  2369. if(this.hidden===false){
  2370. initwidth += cw+brd;
  2371. if(this.fixed) {
  2372. gw += cw+brd;
  2373. } else {
  2374. vc++;
  2375. }
  2376. }
  2377. });
  2378. if(isNaN(ts.p.width)) {
  2379. ts.p.width = initwidth + ((ts.p.shrinkToFit ===false && !isNaN(ts.p.height)) ? scw : 0);
  2380. }
  2381. grid.width = ts.p.width;
  2382. ts.p.tblwidth = initwidth;
  2383. if(ts.p.shrinkToFit ===false && ts.p.forceFit === true) {ts.p.forceFit=false;}
  2384. if(ts.p.shrinkToFit===true && vc > 0) {
  2385. aw = grid.width-brd*vc-gw;
  2386. if(!isNaN(ts.p.height)) {
  2387. aw -= scw;
  2388. hs = true;
  2389. }
  2390. initwidth =0;
  2391. $.each(ts.p.colModel, function(i) {
  2392. if(this.hidden === false && !this.fixed){
  2393. cw = Math.round(aw*this.width/(ts.p.tblwidth-brd*vc-gw));
  2394. this.width =cw;
  2395. initwidth += cw;
  2396. lvc = i;
  2397. }
  2398. });
  2399. cr =0;
  2400. if (hs) {
  2401. if(grid.width-gw-(initwidth+brd*vc) !== scw){
  2402. cr = grid.width-gw-(initwidth+brd*vc)-scw;
  2403. }
  2404. } else if(!hs && Math.abs(grid.width-gw-(initwidth+brd*vc)) !== 1) {
  2405. cr = grid.width-gw-(initwidth+brd*vc);
  2406. }
  2407. ts.p.colModel[lvc].width += cr;
  2408. ts.p.tblwidth = initwidth+cr+brd*vc+gw;
  2409. if(ts.p.tblwidth > ts.p.width) {
  2410. ts.p.colModel[lvc].width -= (ts.p.tblwidth - parseInt(ts.p.width,10));
  2411. ts.p.tblwidth = ts.p.width;
  2412. }
  2413. }
  2414. },
  2415. nextVisible= function(iCol) {
  2416. var ret = iCol, j=iCol, i;
  2417. for (i = iCol+1;i<ts.p.colModel.length;i++){
  2418. if(ts.p.colModel[i].hidden !== true ) {
  2419. j=i; break;
  2420. }
  2421. }
  2422. return j-ret;
  2423. },
  2424. getOffset = function (iCol) {
  2425. var $th = $(ts.grid.headers[iCol].el), ret = [$th.position().left + $th.outerWidth()];
  2426. if(ts.p.direction==="rtl") { ret[0] = ts.p.width - ret[0]; }
  2427. ret[0] -= ts.grid.bDiv.scrollLeft;
  2428. ret.push($(ts.grid.hDiv).position().top);
  2429. ret.push($(ts.grid.bDiv).offset().top - $(ts.grid.hDiv).offset().top + $(ts.grid.bDiv).height());
  2430. return ret;
  2431. },
  2432. getColumnHeaderIndex = function (th) {
  2433. var i, headers = ts.grid.headers, ci = $.jgrid.getCellIndex(th);
  2434. for (i = 0; i < headers.length; i++) {
  2435. if (th === headers[i].el) {
  2436. ci = i;
  2437. break;
  2438. }
  2439. }
  2440. return ci;
  2441. },
  2442. colTemplate;
  2443. this.p.id = this.id;
  2444. if ($.inArray(ts.p.multikey,sortkeys) === -1 ) {ts.p.multikey = false;}
  2445. ts.p.keyName=false;
  2446. for (i=0; i<ts.p.colModel.length;i++) {
  2447. colTemplate = typeof ts.p.colModel[i].template === "string" ?
  2448. ($.jgrid.cmTemplate != null && typeof $.jgrid.cmTemplate[ts.p.colModel[i].template] === "object" ? $.jgrid.cmTemplate[ts.p.colModel[i].template]: {}) :
  2449. ts.p.colModel[i].template;
  2450. ts.p.colModel[i] = $.extend(true, {}, ts.p.cmTemplate, colTemplate || {}, ts.p.colModel[i]);
  2451. if (ts.p.keyName === false && ts.p.colModel[i].key===true) {
  2452. ts.p.keyName = ts.p.colModel[i].name;
  2453. }
  2454. }
  2455. ts.p.sortorder = ts.p.sortorder.toLowerCase();
  2456. $.jgrid.cell_width = $.jgrid.cellWidth();
  2457. if(ts.p.grouping===true) {
  2458. ts.p.scroll = false;
  2459. ts.p.rownumbers = false;
  2460. //ts.p.subGrid = false; expiremental
  2461. ts.p.treeGrid = false;
  2462. ts.p.gridview = true;
  2463. }
  2464. if(this.p.treeGrid === true) {
  2465. try { $(this).jqGrid("setTreeGrid");} catch (_) {}
  2466. if(ts.p.datatype !== "local") { ts.p.localReader = {id: "_id_"}; }
  2467. }
  2468. if(this.p.subGrid) {
  2469. try { $(ts).jqGrid("setSubGrid");} catch (s){}
  2470. }
  2471. if(this.p.multiselect) {
  2472. this.p.colNames.unshift("<input role='checkbox' id='cb_"+this.p.id+"' class='cbox' type='checkbox'/>");
  2473. 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});
  2474. }
  2475. if(this.p.rownumbers) {
  2476. this.p.colNames.unshift("");
  2477. this.p.colModel.unshift({name:'rn',width:ts.p.rownumWidth,sortable:false,resizable:false,hidedlg:true,search:false,align:'center',fixed:true});
  2478. }
  2479. ts.p.xmlReader = $.extend(true,{
  2480. root: "rows",
  2481. row: "row",
  2482. page: "rows>page",
  2483. total: "rows>total",
  2484. records : "rows>records",
  2485. repeatitems: true,
  2486. cell: "cell",
  2487. id: "[id]",
  2488. userdata: "userdata",
  2489. subgrid: {root:"rows", row: "row", repeatitems: true, cell:"cell"}
  2490. }, ts.p.xmlReader);
  2491. ts.p.jsonReader = $.extend(true,{
  2492. root: "rows",
  2493. page: "page",
  2494. total: "total",
  2495. records: "records",
  2496. repeatitems: true,
  2497. cell: "cell",
  2498. id: "id",
  2499. userdata: "userdata",
  2500. subgrid: {root:"rows", repeatitems: true, cell:"cell"}
  2501. },ts.p.jsonReader);
  2502. ts.p.localReader = $.extend(true,{
  2503. root: "rows",
  2504. page: "page",
  2505. total: "total",
  2506. records: "records",
  2507. repeatitems: false,
  2508. cell: "cell",
  2509. id: "id",
  2510. userdata: "userdata",
  2511. subgrid: {root:"rows", repeatitems: true, cell:"cell"}
  2512. },ts.p.localReader);
  2513. if(ts.p.scroll){
  2514. ts.p.pgbuttons = false; ts.p.pginput=false; ts.p.rowList=[];
  2515. }
  2516. if(ts.p.data.length) { normalizeData(); refreshIndex(); }
  2517. var thead = "<thead><tr class='ui-jqgrid-labels' role='row'>",
  2518. tdc, idn, w, res, sort,
  2519. td, ptr, tbody, imgs,iac="",idc="",sortarr=[], sortord=[], sotmp=[];
  2520. if(ts.p.shrinkToFit===true && ts.p.forceFit===true) {
  2521. for (i=ts.p.colModel.length-1;i>=0;i--){
  2522. if(!ts.p.colModel[i].hidden) {
  2523. ts.p.colModel[i].resizable=false;
  2524. break;
  2525. }
  2526. }
  2527. }
  2528. if(ts.p.viewsortcols[1] === 'horizontal') {iac=" ui-i-asc";idc=" ui-i-desc";}
  2529. tdc = isMSIE ? "class='ui-th-div-ie'" :"";
  2530. 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>";
  2531. 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>";
  2532. if(ts.p.multiSort) {
  2533. sortarr = ts.p.sortname.split(",");
  2534. for (i=0; i<sortarr.length; i++) {
  2535. sotmp = $.trim(sortarr[i]).split(" ");
  2536. sortarr[i] = $.trim(sotmp[0]);
  2537. sortord[i] = sotmp[1] ? $.trim(sotmp[1]) : ts.p.sortorder || "asc";
  2538. }
  2539. }
  2540. for(i=0;i<this.p.colNames.length;i++){
  2541. var tooltip = ts.p.headertitles ? (" title=\""+$.jgrid.stripHtml(ts.p.colNames[i])+"\"") :"";
  2542. thead += "<th id='"+ts.p.id+"_"+ts.p.colModel[i].name+"' role='columnheader' class='ui-state-default ui-th-column ui-th-"+dir+"'"+ tooltip+">";
  2543. idn = ts.p.colModel[i].index || ts.p.colModel[i].name;
  2544. thead += "<div id='jqgh_"+ts.p.id+"_"+ts.p.colModel[i].name+"' "+tdc+">"+ts.p.colNames[i];
  2545. if(!ts.p.colModel[i].width) { ts.p.colModel[i].width = 150; }
  2546. else { ts.p.colModel[i].width = parseInt(ts.p.colModel[i].width,10); }
  2547. if(typeof ts.p.colModel[i].title !== "boolean") { ts.p.colModel[i].title = true; }
  2548. ts.p.colModel[i].lso = "";
  2549. if (idn === ts.p.sortname) {
  2550. ts.p.lastsort = i;
  2551. }
  2552. if(ts.p.multiSort) {
  2553. sotmp = $.inArray(idn,sortarr);
  2554. if( sotmp !== -1 ) {
  2555. ts.p.colModel[i].lso = sortord[sotmp];
  2556. }
  2557. }
  2558. thead += imgs+"</div></th>";
  2559. }
  2560. thead += "</tr></thead>";
  2561. imgs = null;
  2562. $(this).append(thead);
  2563. $("thead tr:first th",this).hover(function(){$(this).addClass('ui-state-hover');},function(){$(this).removeClass('ui-state-hover');});
  2564. if(this.p.multiselect) {
  2565. var emp=[], chk;
  2566. $('#cb_'+$.jgrid.jqID(ts.p.id),this).bind('click',function(){
  2567. ts.p.selarrrow = [];
  2568. var froz = ts.p.frozenColumns === true ? ts.p.id + "_frozen" : "";
  2569. if (this.checked) {
  2570. $(ts.rows).each(function(i) {
  2571. if (i>0) {
  2572. if(!$(this).hasClass("ui-subgrid") && !$(this).hasClass("jqgroup") && !$(this).hasClass('ui-state-disabled') && !$(this).hasClass("jqfoot")){
  2573. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id) )[ts.p.useProp ? 'prop': 'attr']("checked",true);
  2574. $(this).addClass("ui-state-highlight").attr("aria-selected","true");
  2575. ts.p.selarrrow.push(this.id);
  2576. ts.p.selrow = this.id;
  2577. if(froz) {
  2578. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id), ts.grid.fbDiv )[ts.p.useProp ? 'prop': 'attr']("checked",true);
  2579. $("#"+$.jgrid.jqID(this.id), ts.grid.fbDiv).addClass("ui-state-highlight");
  2580. }
  2581. }
  2582. }
  2583. });
  2584. chk=true;
  2585. emp=[];
  2586. }
  2587. else {
  2588. $(ts.rows).each(function(i) {
  2589. if(i>0) {
  2590. if(!$(this).hasClass("ui-subgrid") && !$(this).hasClass("jqgroup") && !$(this).hasClass('ui-state-disabled') && !$(this).hasClass("jqfoot")){
  2591. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id) )[ts.p.useProp ? 'prop': 'attr']("checked", false);
  2592. $(this).removeClass("ui-state-highlight").attr("aria-selected","false");
  2593. emp.push(this.id);
  2594. if(froz) {
  2595. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id), ts.grid.fbDiv )[ts.p.useProp ? 'prop': 'attr']("checked",false);
  2596. $("#"+$.jgrid.jqID(this.id), ts.grid.fbDiv).removeClass("ui-state-highlight");
  2597. }
  2598. }
  2599. }
  2600. });
  2601. ts.p.selrow = null;
  2602. chk=false;
  2603. }
  2604. $(ts).triggerHandler("jqGridSelectAll", [chk ? ts.p.selarrrow : emp, chk]);
  2605. if($.isFunction(ts.p.onSelectAll)) {ts.p.onSelectAll.call(ts, chk ? ts.p.selarrrow : emp,chk);}
  2606. });
  2607. }
  2608. if(ts.p.autowidth===true) {
  2609. var pw = $(eg).innerWidth();
  2610. ts.p.width = pw > 0? pw: 'nw';
  2611. }
  2612. setColWidth();
  2613. $(eg).css("width",grid.width+"px").append("<div class='ui-jqgrid-resize-mark' id='rs_m"+ts.p.id+"'>&#160;</div>");
  2614. $(gv).css("width",grid.width+"px");
  2615. thead = $("thead:first",ts).get(0);
  2616. var tfoot = "";
  2617. if(ts.p.footerrow) { tfoot += "<table role='presentation' 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+"'>"; }
  2618. var thr = $("tr:first",thead),
  2619. firstr = "<tr class='jqgfirstrow' role='row' style='height:auto'>";
  2620. ts.p.disableClick=false;
  2621. $("th",thr).each(function ( j ) {
  2622. w = ts.p.colModel[j].width;
  2623. if(ts.p.colModel[j].resizable === undefined) {ts.p.colModel[j].resizable = true;}
  2624. if(ts.p.colModel[j].resizable){
  2625. res = document.createElement("span");
  2626. $(res).html("&#160;").addClass('ui-jqgrid-resize ui-jqgrid-resize-'+dir)
  2627. .css("cursor","col-resize");
  2628. $(this).addClass(ts.p.resizeclass);
  2629. } else {
  2630. res = "";
  2631. }
  2632. $(this).css("width",w+"px").prepend(res);
  2633. res = null;
  2634. var hdcol = "";
  2635. if( ts.p.colModel[j].hidden ) {
  2636. $(this).css("display","none");
  2637. hdcol = "display:none;";
  2638. }
  2639. firstr += "<td role='gridcell' style='height:0px;width:"+w+"px;"+hdcol+"'></td>";
  2640. grid.headers[j] = { width: w, el: this };
  2641. sort = ts.p.colModel[j].sortable;
  2642. if( typeof sort !== 'boolean') {ts.p.colModel[j].sortable = true; sort=true;}
  2643. var nm = ts.p.colModel[j].name;
  2644. if( !(nm === 'cb' || nm==='subgrid' || nm==='rn') ) {
  2645. if(ts.p.viewsortcols[2]){
  2646. $(">div",this).addClass('ui-jqgrid-sortable');
  2647. }
  2648. }
  2649. if(sort) {
  2650. if(ts.p.multiSort) {
  2651. if(ts.p.viewsortcols[0]) {
  2652. $("div span.s-ico",this).show();
  2653. if(ts.p.colModel[j].lso){
  2654. $("div span.ui-icon-"+ts.p.colModel[j].lso,this).removeClass("ui-state-disabled");
  2655. }
  2656. } else if( ts.p.colModel[j].lso) {
  2657. $("div span.s-ico",this).show();
  2658. $("div span.ui-icon-"+ts.p.colModel[j].lso,this).removeClass("ui-state-disabled");
  2659. }
  2660. } else {
  2661. 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");}}
  2662. else if(j === ts.p.lastsort && ts.p.sortname !== "") {$("div span.s-ico",this).show();$("div span.ui-icon-"+ts.p.sortorder,this).removeClass("ui-state-disabled");}
  2663. }
  2664. }
  2665. if(ts.p.footerrow) { tfoot += "<td role='gridcell' "+formatCol(j,0,'', null, '', false)+">&#160;</td>"; }
  2666. }).mousedown(function(e) {
  2667. if ($(e.target).closest("th>span.ui-jqgrid-resize").length !== 1) { return; }
  2668. var ci = getColumnHeaderIndex(this);
  2669. if(ts.p.forceFit===true) {ts.p.nv= nextVisible(ci);}
  2670. grid.dragStart(ci, e, getOffset(ci));
  2671. return false;
  2672. }).click(function(e) {
  2673. if (ts.p.disableClick) {
  2674. ts.p.disableClick = false;
  2675. return false;
  2676. }
  2677. var s = "th>div.ui-jqgrid-sortable",r,d;
  2678. if (!ts.p.viewsortcols[2]) { s = "th>div>span>span.ui-grid-ico-sort"; }
  2679. var t = $(e.target).closest(s);
  2680. if (t.length !== 1) { return; }
  2681. var ci;
  2682. if(ts.p.frozenColumns) {
  2683. var tid = $(this)[0].id.substring( ts.p.id.length + 1 );
  2684. $(ts.p.colModel).each(function(i){
  2685. if (this.name === tid) {
  2686. ci = i;return false;
  2687. }
  2688. });
  2689. } else {
  2690. ci = getColumnHeaderIndex(this);
  2691. }
  2692. if (!ts.p.viewsortcols[2]) { r=true;d=t.attr("sort"); }
  2693. if(ci != null){
  2694. sortData( $('div',this)[0].id, ci, r, d, this);
  2695. }
  2696. return false;
  2697. });
  2698. if (ts.p.sortable && $.fn.sortable) {
  2699. try {
  2700. $(ts).jqGrid("sortableColumns", thr);
  2701. } catch (e){}
  2702. }
  2703. if(ts.p.footerrow) { tfoot += "</tr></tbody></table>"; }
  2704. firstr += "</tr>";
  2705. tbody = document.createElement("tbody");
  2706. this.appendChild(tbody);
  2707. $(this).addClass('ui-jqgrid-btable').append(firstr);
  2708. firstr = null;
  2709. var hTable = $("<table class='ui-jqgrid-htable' style='width:"+ts.p.tblwidth+"px' role='presentation' aria-labelledby='gbox_"+this.id+"' cellspacing='0' cellpadding='0' border='0'></table>").append(thead),
  2710. hg = (ts.p.caption && ts.p.hiddengrid===true) ? true : false,
  2711. hb = $("<div class='ui-jqgrid-hbox" + (dir==="rtl" ? "-rtl" : "" )+"'></div>");
  2712. thead = null;
  2713. grid.hDiv = document.createElement("div");
  2714. $(grid.hDiv)
  2715. .css({ width: grid.width+"px"})
  2716. .addClass("ui-state-default ui-jqgrid-hdiv")
  2717. .append(hb);
  2718. $(hb).append(hTable);
  2719. hTable = null;
  2720. if(hg) { $(grid.hDiv).hide(); }
  2721. if(ts.p.pager){
  2722. // TBD -- escape ts.p.pager here?
  2723. if(typeof ts.p.pager === "string") {if(ts.p.pager.substr(0,1) !== "#") { ts.p.pager = "#"+ts.p.pager;} }
  2724. else { ts.p.pager = "#"+ $(ts.p.pager).attr("id");}
  2725. $(ts.p.pager).css({width: grid.width+"px"}).addClass('ui-state-default ui-jqgrid-pager ui-corner-bottom').appendTo(eg);
  2726. if(hg) {$(ts.p.pager).hide();}
  2727. setPager(ts.p.pager,'');
  2728. }
  2729. if( ts.p.cellEdit === false && ts.p.hoverrows === true) {
  2730. $(ts).bind('mouseover',function(e) {
  2731. ptr = $(e.target).closest("tr.jqgrow");
  2732. if($(ptr).attr("class") !== "ui-subgrid") {
  2733. $(ptr).addClass("ui-state-hover");
  2734. }
  2735. }).bind('mouseout',function(e) {
  2736. ptr = $(e.target).closest("tr.jqgrow");
  2737. $(ptr).removeClass("ui-state-hover");
  2738. });
  2739. }
  2740. var ri,ci, tdHtml;
  2741. $(ts).before(grid.hDiv).click(function(e) {
  2742. td = e.target;
  2743. ptr = $(td,ts.rows).closest("tr.jqgrow");
  2744. 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 ) {
  2745. return this;
  2746. }
  2747. var scb = $(td).hasClass("cbox"),
  2748. cSel = $(ts).triggerHandler("jqGridBeforeSelectRow", [ptr[0].id, e]);
  2749. cSel = (cSel === false || cSel === 'stop') ? false : true;
  2750. if ($.isFunction(ts.p.beforeSelectRow)) {
  2751. var allowRowSelect = ts.p.beforeSelectRow.call(ts, ptr[0].id, e);
  2752. if (allowRowSelect === false || allowRowSelect === 'stop') {
  2753. cSel = false;
  2754. }
  2755. }
  2756. if (td.tagName === 'A' || ((td.tagName === 'INPUT' || td.tagName === 'TEXTAREA' || td.tagName === 'OPTION' || td.tagName === 'SELECT' ) && !scb) ) { return; }
  2757. ri = ptr[0].id;
  2758. td = $(td).closest("tr.jqgrow>td");
  2759. if (td.length > 0) {
  2760. ci = $.jgrid.getCellIndex(td);
  2761. tdHtml = $(td).closest("td,th").html();
  2762. $(ts).triggerHandler("jqGridCellSelect", [ri,ci,tdHtml,e]);
  2763. if($.isFunction(ts.p.onCellSelect)) {
  2764. ts.p.onCellSelect.call(ts,ri,ci,tdHtml,e);
  2765. }
  2766. }
  2767. if(ts.p.cellEdit === true) {
  2768. if(ts.p.multiselect && scb && cSel){
  2769. $(ts).jqGrid("setSelection", ri ,true,e);
  2770. } else if (td.length > 0) {
  2771. ri = ptr[0].rowIndex;
  2772. try {$(ts).jqGrid("editCell",ri,ci,true);} catch (_) {}
  2773. }
  2774. }
  2775. if (!cSel) {
  2776. return;
  2777. }
  2778. if ( !ts.p.multikey ) {
  2779. if(ts.p.multiselect && ts.p.multiboxonly) {
  2780. if(scb){$(ts).jqGrid("setSelection",ri,true,e);}
  2781. else {
  2782. var frz = ts.p.frozenColumns ? ts.p.id+"_frozen" : "";
  2783. $(ts.p.selarrrow).each(function(i,n){
  2784. var trid = $(ts).jqGrid('getGridRowById',n);
  2785. if(trid) { $( trid ).removeClass("ui-state-highlight"); }
  2786. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(n))[ts.p.useProp ? 'prop': 'attr']("checked", false);
  2787. if(frz) {
  2788. $("#"+$.jgrid.jqID(n), "#"+$.jgrid.jqID(frz)).removeClass("ui-state-highlight");
  2789. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(n), "#"+$.jgrid.jqID(frz))[ts.p.useProp ? 'prop': 'attr']("checked", false);
  2790. }
  2791. });
  2792. ts.p.selarrrow = [];
  2793. $(ts).jqGrid("setSelection",ri,true,e);
  2794. }
  2795. } else {
  2796. $(ts).jqGrid("setSelection",ri,true,e);
  2797. }
  2798. } else {
  2799. if(e[ts.p.multikey]) {
  2800. $(ts).jqGrid("setSelection",ri,true,e);
  2801. } else if(ts.p.multiselect && scb) {
  2802. scb = $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+ri).is(":checked");
  2803. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+ri)[ts.p.useProp ? 'prop' : 'attr']("checked", scb);
  2804. }
  2805. }
  2806. }).bind('reloadGrid', function(e,opts) {
  2807. if(ts.p.treeGrid ===true) { ts.p.datatype = ts.p.treedatatype;}
  2808. if (opts && opts.current) {
  2809. ts.grid.selectionPreserver(ts);
  2810. }
  2811. if(ts.p.datatype==="local"){ $(ts).jqGrid("resetSelection"); if(ts.p.data.length) { normalizeData(); refreshIndex();} }
  2812. else if(!ts.p.treeGrid) {
  2813. ts.p.selrow=null;
  2814. if(ts.p.multiselect) {ts.p.selarrrow =[];setHeadCheckBox(false);}
  2815. ts.p.savedRow = [];
  2816. }
  2817. if(ts.p.scroll) {emptyRows.call(ts, true, false);}
  2818. if (opts && opts.page) {
  2819. var page = opts.page;
  2820. if (page > ts.p.lastpage) { page = ts.p.lastpage; }
  2821. if (page < 1) { page = 1; }
  2822. ts.p.page = page;
  2823. if (ts.grid.prevRowHeight) {
  2824. ts.grid.bDiv.scrollTop = (page - 1) * ts.grid.prevRowHeight * ts.p.rowNum;
  2825. } else {
  2826. ts.grid.bDiv.scrollTop = 0;
  2827. }
  2828. }
  2829. if (ts.grid.prevRowHeight && ts.p.scroll) {
  2830. delete ts.p.lastpage;
  2831. ts.grid.populateVisible();
  2832. } else {
  2833. ts.grid.populate();
  2834. }
  2835. if(ts.p._inlinenav===true) {$(ts).jqGrid('showAddEditButtons');}
  2836. return false;
  2837. })
  2838. .dblclick(function(e) {
  2839. td = e.target;
  2840. ptr = $(td,ts.rows).closest("tr.jqgrow");
  2841. if($(ptr).length === 0 ){return;}
  2842. ri = ptr[0].rowIndex;
  2843. ci = $.jgrid.getCellIndex(td);
  2844. var dbcr = $(ts).triggerHandler("jqGridDblClickRow", [$(ptr).attr("id"),ri,ci,e]);
  2845. if( dbcr != null) { return dbcr; }
  2846. if ($.isFunction(ts.p.ondblClickRow)) {
  2847. dbcr = ts.p.ondblClickRow.call(ts,$(ptr).attr("id"),ri,ci, e);
  2848. if( dbcr != null) { return dbcr; }
  2849. }
  2850. })
  2851. .bind('contextmenu', function(e) {
  2852. td = e.target;
  2853. ptr = $(td,ts.rows).closest("tr.jqgrow");
  2854. if($(ptr).length === 0 ){return;}
  2855. if(!ts.p.multiselect) { $(ts).jqGrid("setSelection",ptr[0].id,true,e); }
  2856. ri = ptr[0].rowIndex;
  2857. ci = $.jgrid.getCellIndex(td);
  2858. var rcr = $(ts).triggerHandler("jqGridRightClickRow", [$(ptr).attr("id"),ri,ci,e]);
  2859. if( rcr != null) { return rcr; }
  2860. if ($.isFunction(ts.p.onRightClickRow)) {
  2861. rcr = ts.p.onRightClickRow.call(ts,$(ptr).attr("id"),ri,ci, e);
  2862. if( rcr != null) { return rcr; }
  2863. }
  2864. });
  2865. grid.bDiv = document.createElement("div");
  2866. if(isMSIE) { if(String(ts.p.height).toLowerCase() === "auto") { ts.p.height = "100%"; } }
  2867. $(grid.bDiv)
  2868. .append($('<div style="position:relative;'+(isMSIE && $.jgrid.msiever() < 8 ? "height:0.01%;" : "")+'"></div>').append('<div></div>').append(this))
  2869. .addClass("ui-jqgrid-bdiv")
  2870. .css({ height: ts.p.height+(isNaN(ts.p.height)?"":"px"), width: (grid.width)+"px"})
  2871. .scroll(grid.scrollGrid);
  2872. $("table:first",grid.bDiv).css({width:ts.p.tblwidth+"px"});
  2873. if( !$.support.tbody ) { //IE
  2874. if( $("tbody",this).length === 2 ) { $("tbody:gt(0)",this).remove();}
  2875. }
  2876. if(ts.p.multikey){
  2877. if( $.jgrid.msie) {
  2878. $(grid.bDiv).bind("selectstart",function(){return false;});
  2879. } else {
  2880. $(grid.bDiv).bind("mousedown",function(){return false;});
  2881. }
  2882. }
  2883. if(hg) {$(grid.bDiv).hide();}
  2884. grid.cDiv = document.createElement("div");
  2885. var arf = ts.p.hidegrid===true ? $("<a role='link' class='ui-jqgrid-titlebar-close ui-corner-all HeaderButton' " + (ts.p.showhide ? "title='"+ts.p.showhide+"'" : "")+" />").hover(
  2886. function(){ arf.addClass('ui-state-hover');},
  2887. function() {arf.removeClass('ui-state-hover');})
  2888. .append("<span class='ui-icon ui-icon-circle-triangle-n'></span>").css((dir==="rtl"?"left":"right"),"0px") : "";
  2889. $(grid.cDiv).append(arf).append("<span class='ui-jqgrid-title'>"+ts.p.caption+"</span>")
  2890. .addClass("ui-jqgrid-titlebar ui-jqgrid-caption"+(dir==="rtl" ? "-rtl" :"" )+" ui-widget-header ui-corner-top ui-helper-clearfix");
  2891. $(grid.cDiv).insertBefore(grid.hDiv);
  2892. if( ts.p.toolbar[0] ) {
  2893. grid.uDiv = document.createElement("div");
  2894. if(ts.p.toolbar[1] === "top") {$(grid.uDiv).insertBefore(grid.hDiv);}
  2895. else if (ts.p.toolbar[1]==="bottom" ) {$(grid.uDiv).insertAfter(grid.hDiv);}
  2896. if(ts.p.toolbar[1]==="both") {
  2897. grid.ubDiv = document.createElement("div");
  2898. $(grid.uDiv).addClass("ui-userdata ui-state-default").attr("id","t_"+this.id).insertBefore(grid.hDiv);
  2899. $(grid.ubDiv).addClass("ui-userdata ui-state-default").attr("id","tb_"+this.id).insertAfter(grid.hDiv);
  2900. if(hg) {$(grid.ubDiv).hide();}
  2901. } else {
  2902. $(grid.uDiv).width(grid.width).addClass("ui-userdata ui-state-default").attr("id","t_"+this.id);
  2903. }
  2904. if(hg) {$(grid.uDiv).hide();}
  2905. }
  2906. if(ts.p.toppager) {
  2907. ts.p.toppager = $.jgrid.jqID(ts.p.id)+"_toppager";
  2908. grid.topDiv = $("<div id='"+ts.p.toppager+"'></div>")[0];
  2909. ts.p.toppager = "#"+ts.p.toppager;
  2910. $(grid.topDiv).addClass('ui-state-default ui-jqgrid-toppager').width(grid.width).insertBefore(grid.hDiv);
  2911. setPager(ts.p.toppager,'_t');
  2912. }
  2913. if(ts.p.footerrow) {
  2914. grid.sDiv = $("<div class='ui-jqgrid-sdiv'></div>")[0];
  2915. hb = $("<div class='ui-jqgrid-hbox"+(dir==="rtl"?"-rtl":"")+"'></div>");
  2916. $(grid.sDiv).append(hb).width(grid.width).insertAfter(grid.hDiv);
  2917. $(hb).append(tfoot);
  2918. grid.footers = $(".ui-jqgrid-ftable",grid.sDiv)[0].rows[0].cells;
  2919. if(ts.p.rownumbers) { grid.footers[0].className = 'ui-state-default jqgrid-rownum'; }
  2920. if(hg) {$(grid.sDiv).hide();}
  2921. }
  2922. hb = null;
  2923. if(ts.p.caption) {
  2924. var tdt = ts.p.datatype;
  2925. if(ts.p.hidegrid===true) {
  2926. $(".ui-jqgrid-titlebar-close",grid.cDiv).click( function(e){
  2927. var onHdCl = $.isFunction(ts.p.onHeaderClick),
  2928. elems = ".ui-jqgrid-bdiv, .ui-jqgrid-hdiv, .ui-jqgrid-pager, .ui-jqgrid-sdiv",
  2929. counter, self = this;
  2930. if(ts.p.toolbar[0]===true) {
  2931. if( ts.p.toolbar[1]==='both') {
  2932. elems += ', #' + $(grid.ubDiv).attr('id');
  2933. }
  2934. elems += ', #' + $(grid.uDiv).attr('id');
  2935. }
  2936. counter = $(elems,"#gview_"+$.jgrid.jqID(ts.p.id)).length;
  2937. if(ts.p.gridstate === 'visible') {
  2938. $(elems,"#gbox_"+$.jgrid.jqID(ts.p.id)).slideUp("fast", function() {
  2939. counter--;
  2940. if (counter === 0) {
  2941. $("span",self).removeClass("ui-icon-circle-triangle-n").addClass("ui-icon-circle-triangle-s");
  2942. ts.p.gridstate = 'hidden';
  2943. if($("#gbox_"+$.jgrid.jqID(ts.p.id)).hasClass("ui-resizable")) { $(".ui-resizable-handle","#gbox_"+$.jgrid.jqID(ts.p.id)).hide(); }
  2944. $(ts).triggerHandler("jqGridHeaderClick", [ts.p.gridstate,e]);
  2945. if(onHdCl) {if(!hg) {ts.p.onHeaderClick.call(ts,ts.p.gridstate,e);}}
  2946. }
  2947. });
  2948. } else if(ts.p.gridstate === 'hidden'){
  2949. $(elems,"#gbox_"+$.jgrid.jqID(ts.p.id)).slideDown("fast", function() {
  2950. counter--;
  2951. if (counter === 0) {
  2952. $("span",self).removeClass("ui-icon-circle-triangle-s").addClass("ui-icon-circle-triangle-n");
  2953. if(hg) {ts.p.datatype = tdt;populate();hg=false;}
  2954. ts.p.gridstate = 'visible';
  2955. if($("#gbox_"+$.jgrid.jqID(ts.p.id)).hasClass("ui-resizable")) { $(".ui-resizable-handle","#gbox_"+$.jgrid.jqID(ts.p.id)).show(); }
  2956. $(ts).triggerHandler("jqGridHeaderClick", [ts.p.gridstate,e]);
  2957. if(onHdCl) {if(!hg) {ts.p.onHeaderClick.call(ts,ts.p.gridstate,e);}}
  2958. }
  2959. });
  2960. }
  2961. return false;
  2962. });
  2963. if(hg) {ts.p.datatype="local"; $(".ui-jqgrid-titlebar-close",grid.cDiv).trigger("click");}
  2964. }
  2965. } else {
  2966. $(grid.cDiv).hide();
  2967. $(grid.hDiv).addClass('ui-corner-top');
  2968. }
  2969. $(grid.hDiv).after(grid.bDiv)
  2970. .mousemove(function (e) {
  2971. if(grid.resizing){grid.dragMove(e);return false;}
  2972. });
  2973. $(".ui-jqgrid-labels",grid.hDiv).bind("selectstart", function () { return false; });
  2974. $(document).bind( "mouseup.jqGrid" + ts.p.id, function () {
  2975. if(grid.resizing) { grid.dragEnd(); return false;}
  2976. return true;
  2977. });
  2978. ts.formatCol = formatCol;
  2979. ts.sortData = sortData;
  2980. ts.updatepager = updatepager;
  2981. ts.refreshIndex = refreshIndex;
  2982. ts.setHeadCheckBox = setHeadCheckBox;
  2983. ts.constructTr = constructTr;
  2984. ts.formatter = function ( rowId, cellval , colpos, rwdat, act){return formatter(rowId, cellval , colpos, rwdat, act);};
  2985. $.extend(grid,{populate : populate, emptyRows: emptyRows, beginReq: beginReq, endReq: endReq});
  2986. this.grid = grid;
  2987. ts.addXmlData = function(d) {addXmlData(d,ts.grid.bDiv);};
  2988. ts.addJSONData = function(d) {addJSONData(d,ts.grid.bDiv);};
  2989. this.grid.cols = this.rows[0].cells;
  2990. $(ts).triggerHandler("jqGridInitGrid");
  2991. if ($.isFunction( ts.p.onInitGrid )) { ts.p.onInitGrid.call(ts); }
  2992. populate();ts.p.hiddengrid=false;
  2993. });
  2994. };
  2995. $.jgrid.extend({
  2996. getGridParam : function(pName) {
  2997. var $t = this[0];
  2998. if (!$t || !$t.grid) {return;}
  2999. if (!pName) { return $t.p; }
  3000. return $t.p[pName] !== undefined ? $t.p[pName] : null;
  3001. },
  3002. setGridParam : function (newParams, overwrite){
  3003. return this.each(function(){
  3004. if(overwrite == null) {
  3005. overwrite = false;
  3006. }
  3007. if (this.grid && typeof newParams === 'object') {
  3008. if(overwrite === true) {
  3009. var params = $.extend({}, this.p, newParams);
  3010. this.p = params;
  3011. } else {
  3012. $.extend(true,this.p,newParams);
  3013. }
  3014. }
  3015. });
  3016. },
  3017. getGridRowById: function ( rowid ) {
  3018. var row;
  3019. this.each( function(){
  3020. try {
  3021. //row = this.rows.namedItem( rowid );
  3022. var i = this.rows.length;
  3023. while(i--) {
  3024. if( rowid.toString() === this.rows[i].id) {
  3025. row = this.rows[i];
  3026. break;
  3027. }
  3028. }
  3029. } catch ( e ) {
  3030. row = $(this.grid.bDiv).find( "#" + $.jgrid.jqID( rowid ));
  3031. }
  3032. });
  3033. return row;
  3034. },
  3035. getDataIDs : function () {
  3036. var ids=[], i=0, len, j=0;
  3037. this.each(function(){
  3038. len = this.rows.length;
  3039. if(len && len>0){
  3040. while(i<len) {
  3041. if($(this.rows[i]).hasClass('jqgrow')) {
  3042. ids[j] = this.rows[i].id;
  3043. j++;
  3044. }
  3045. i++;
  3046. }
  3047. }
  3048. });
  3049. return ids;
  3050. },
  3051. setSelection : function(selection,onsr, e) {
  3052. return this.each(function(){
  3053. var $t = this, stat,pt, ner, ia, tpsr, fid, csr;
  3054. if(selection === undefined) { return; }
  3055. onsr = onsr === false ? false : true;
  3056. pt=$($t).jqGrid('getGridRowById', selection);
  3057. if(!pt || !pt.className || pt.className.indexOf( 'ui-state-disabled' ) > -1 ) { return; }
  3058. function scrGrid(iR){
  3059. var ch = $($t.grid.bDiv)[0].clientHeight,
  3060. st = $($t.grid.bDiv)[0].scrollTop,
  3061. rpos = $($t.rows[iR]).position().top,
  3062. rh = $t.rows[iR].clientHeight;
  3063. if(rpos+rh >= ch+st) { $($t.grid.bDiv)[0].scrollTop = rpos-(ch+st)+rh+st; }
  3064. else if(rpos < ch+st) {
  3065. if(rpos < st) {
  3066. $($t.grid.bDiv)[0].scrollTop = rpos;
  3067. }
  3068. }
  3069. }
  3070. if($t.p.scrollrows===true) {
  3071. ner = $($t).jqGrid('getGridRowById',selection).rowIndex;
  3072. if(ner >=0 ){
  3073. scrGrid(ner);
  3074. }
  3075. }
  3076. if($t.p.frozenColumns === true ) {
  3077. fid = $t.p.id+"_frozen";
  3078. }
  3079. if(!$t.p.multiselect) {
  3080. if(pt.className !== "ui-subgrid") {
  3081. if( $t.p.selrow !== pt.id ) {
  3082. csr = $($t).jqGrid('getGridRowById', $t.p.selrow);
  3083. if( csr ) {
  3084. $( csr ).removeClass("ui-state-highlight").attr({"aria-selected":"false", "tabindex" : "-1"});
  3085. }
  3086. $(pt).addClass("ui-state-highlight").attr({"aria-selected":"true", "tabindex" : "0"});//.focus();
  3087. if(fid) {
  3088. $("#"+$.jgrid.jqID($t.p.selrow), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight");
  3089. $("#"+$.jgrid.jqID(selection), "#"+$.jgrid.jqID(fid)).addClass("ui-state-highlight");
  3090. }
  3091. stat = true;
  3092. } else {
  3093. stat = false;
  3094. }
  3095. $t.p.selrow = pt.id;
  3096. if( onsr ) {
  3097. $($t).triggerHandler("jqGridSelectRow", [pt.id, stat, e]);
  3098. if( $t.p.onSelectRow) { $t.p.onSelectRow.call($t, pt.id, stat, e); }
  3099. }
  3100. }
  3101. } else {
  3102. //unselect selectall checkbox when deselecting a specific row
  3103. $t.setHeadCheckBox( false );
  3104. $t.p.selrow = pt.id;
  3105. ia = $.inArray($t.p.selrow,$t.p.selarrrow);
  3106. if ( ia === -1 ){
  3107. if(pt.className !== "ui-subgrid") { $(pt).addClass("ui-state-highlight").attr("aria-selected","true");}
  3108. stat = true;
  3109. $t.p.selarrrow.push($t.p.selrow);
  3110. } else {
  3111. if(pt.className !== "ui-subgrid") { $(pt).removeClass("ui-state-highlight").attr("aria-selected","false");}
  3112. stat = false;
  3113. $t.p.selarrrow.splice(ia,1);
  3114. tpsr = $t.p.selarrrow[0];
  3115. $t.p.selrow = (tpsr === undefined) ? null : tpsr;
  3116. }
  3117. $("#jqg_"+$.jgrid.jqID($t.p.id)+"_"+$.jgrid.jqID(pt.id))[$t.p.useProp ? 'prop': 'attr']("checked",stat);
  3118. if(fid) {
  3119. if(ia === -1) {
  3120. $("#"+$.jgrid.jqID(selection), "#"+$.jgrid.jqID(fid)).addClass("ui-state-highlight");
  3121. } else {
  3122. $("#"+$.jgrid.jqID(selection), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight");
  3123. }
  3124. $("#jqg_"+$.jgrid.jqID($t.p.id)+"_"+$.jgrid.jqID(selection), "#"+$.jgrid.jqID(fid))[$t.p.useProp ? 'prop': 'attr']("checked",stat);
  3125. }
  3126. if( onsr ) {
  3127. $($t).triggerHandler("jqGridSelectRow", [pt.id, stat, e]);
  3128. if( $t.p.onSelectRow) { $t.p.onSelectRow.call($t, pt.id , stat, e); }
  3129. }
  3130. }
  3131. });
  3132. },
  3133. resetSelection : function( rowid ){
  3134. return this.each(function(){
  3135. var t = this, sr, fid;
  3136. if( t.p.frozenColumns === true ) {
  3137. fid = t.p.id+"_frozen";
  3138. }
  3139. if(rowid !== undefined ) {
  3140. sr = rowid === t.p.selrow ? t.p.selrow : rowid;
  3141. $("#"+$.jgrid.jqID(t.p.id)+" tbody:first tr#"+$.jgrid.jqID(sr)).removeClass("ui-state-highlight").attr("aria-selected","false");
  3142. if (fid) { $("#"+$.jgrid.jqID(sr), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight"); }
  3143. if(t.p.multiselect) {
  3144. $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(sr), "#"+$.jgrid.jqID(t.p.id))[t.p.useProp ? 'prop': 'attr']("checked",false);
  3145. if(fid) { $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(sr), "#"+$.jgrid.jqID(fid))[t.p.useProp ? 'prop': 'attr']("checked",false); }
  3146. t.setHeadCheckBox( false);
  3147. var ia = $.inArray($.jgrid.jqID(sr), t.p.selarrrow);
  3148. if ( ia !== -1 ){
  3149. t.p.selarrrow.splice(ia,1);
  3150. }
  3151. }
  3152. sr = null;
  3153. } else if(!t.p.multiselect) {
  3154. if(t.p.selrow) {
  3155. $("#"+$.jgrid.jqID(t.p.id)+" tbody:first tr#"+$.jgrid.jqID(t.p.selrow)).removeClass("ui-state-highlight").attr("aria-selected","false");
  3156. if(fid) { $("#"+$.jgrid.jqID(t.p.selrow), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight"); }
  3157. t.p.selrow = null;
  3158. }
  3159. } else {
  3160. $(t.p.selarrrow).each(function(i,n){
  3161. $( $(t).jqGrid('getGridRowById',n) ).removeClass("ui-state-highlight").attr("aria-selected","false");
  3162. $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(n))[t.p.useProp ? 'prop': 'attr']("checked",false);
  3163. if(fid) {
  3164. $("#"+$.jgrid.jqID(n), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight");
  3165. $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(n), "#"+$.jgrid.jqID(fid))[t.p.useProp ? 'prop': 'attr']("checked",false);
  3166. }
  3167. });
  3168. t.setHeadCheckBox( false );
  3169. t.p.selarrrow = [];
  3170. t.p.selrow = null;
  3171. }
  3172. if(t.p.cellEdit === true) {
  3173. if(parseInt(t.p.iCol,10)>=0 && parseInt(t.p.iRow,10)>=0) {
  3174. $("td:eq("+t.p.iCol+")",t.rows[t.p.iRow]).removeClass("edit-cell ui-state-highlight");
  3175. $(t.rows[t.p.iRow]).removeClass("selected-row ui-state-hover");
  3176. }
  3177. }
  3178. t.p.savedRow = [];
  3179. });
  3180. },
  3181. getRowData : function( rowid ) {
  3182. var res = {}, resall, getall=false, len, j=0;
  3183. this.each(function(){
  3184. var $t = this,nm,ind;
  3185. if(rowid === undefined) {
  3186. getall = true;
  3187. resall = [];
  3188. len = $t.rows.length;
  3189. } else {
  3190. ind = $($t).jqGrid('getGridRowById', rowid);
  3191. if(!ind) { return res; }
  3192. len = 2;
  3193. }
  3194. while(j<len){
  3195. if(getall) { ind = $t.rows[j]; }
  3196. if( $(ind).hasClass('jqgrow') ) {
  3197. $('td[role="gridcell"]',ind).each( function(i) {
  3198. nm = $t.p.colModel[i].name;
  3199. if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn') {
  3200. if($t.p.treeGrid===true && nm === $t.p.ExpandColumn) {
  3201. res[nm] = $.jgrid.htmlDecode($("span:first",this).html());
  3202. } else {
  3203. try {
  3204. res[nm] = $.unformat.call($t,this,{rowId:ind.id, colModel:$t.p.colModel[i]},i);
  3205. } catch (e){
  3206. res[nm] = $.jgrid.htmlDecode($(this).html());
  3207. }
  3208. }
  3209. }
  3210. });
  3211. if(getall) { resall.push(res); res={}; }
  3212. }
  3213. j++;
  3214. }
  3215. });
  3216. return resall || res;
  3217. },
  3218. delRowData : function(rowid) {
  3219. var success = false, rowInd, ia, nextRow;
  3220. this.each(function() {
  3221. var $t = this;
  3222. rowInd = $($t).jqGrid('getGridRowById', rowid);
  3223. if(!rowInd) {return false;}
  3224. if($t.p.subGrid) {
  3225. nextRow = $(rowInd).next();
  3226. if(nextRow.hasClass('ui-subgrid')) {
  3227. nextRow.remove();
  3228. }
  3229. }
  3230. $(rowInd).remove();
  3231. $t.p.records--;
  3232. $t.p.reccount--;
  3233. $t.updatepager(true,false);
  3234. success=true;
  3235. if($t.p.multiselect) {
  3236. ia = $.inArray(rowid,$t.p.selarrrow);
  3237. if(ia !== -1) { $t.p.selarrrow.splice(ia,1);}
  3238. }
  3239. if ($t.p.multiselect && $t.p.selarrrow.length > 0) {
  3240. $t.p.selrow = $t.p.selarrrow[$t.p.selarrrow.length-1];
  3241. } else {
  3242. $t.p.selrow = null;
  3243. }
  3244. if($t.p.datatype === 'local') {
  3245. var id = $.jgrid.stripPref($t.p.idPrefix, rowid),
  3246. pos = $t.p._index[id];
  3247. if(pos !== undefined) {
  3248. $t.p.data.splice(pos,1);
  3249. $t.refreshIndex();
  3250. }
  3251. }
  3252. if( $t.p.altRows === true && success ) {
  3253. var cn = $t.p.altclass;
  3254. $($t.rows).each(function(i){
  3255. if(i % 2 === 1) { $(this).addClass(cn); }
  3256. else { $(this).removeClass(cn); }
  3257. });
  3258. }
  3259. });
  3260. return success;
  3261. },
  3262. setRowData : function(rowid, data, cssp) {
  3263. var nm, success=true, title;
  3264. this.each(function(){
  3265. if(!this.grid) {return false;}
  3266. var t = this, vl, ind, cp = typeof cssp, lcdata={};
  3267. ind = $(this).jqGrid('getGridRowById', rowid);
  3268. if(!ind) { return false; }
  3269. if( data ) {
  3270. try {
  3271. $(this.p.colModel).each(function(i){
  3272. nm = this.name;
  3273. var dval =$.jgrid.getAccessor(data,nm);
  3274. if( dval !== undefined) {
  3275. lcdata[nm] = this.formatter && typeof this.formatter === 'string' && this.formatter === 'date' ? $.unformat.date.call(t,dval,this) : dval;
  3276. vl = t.formatter( rowid, lcdata[nm], i, data, 'edit');
  3277. title = this.title ? {"title":$.jgrid.stripHtml(vl)} : {};
  3278. if(t.p.treeGrid===true && nm === t.p.ExpandColumn) {
  3279. $("td[role='gridcell']:eq("+i+") > span:first",ind).html(vl).attr(title);
  3280. } else {
  3281. $("td[role='gridcell']:eq("+i+")",ind).html(vl).attr(title);
  3282. }
  3283. }
  3284. });
  3285. if(t.p.datatype === 'local') {
  3286. var id = $.jgrid.stripPref(t.p.idPrefix, rowid),
  3287. pos = t.p._index[id], key;
  3288. if(t.p.treeGrid) {
  3289. for(key in t.p.treeReader){
  3290. if(t.p.treeReader.hasOwnProperty(key)) {
  3291. delete lcdata[t.p.treeReader[key]];
  3292. }
  3293. }
  3294. }
  3295. if(pos !== undefined) {
  3296. t.p.data[pos] = $.extend(true, t.p.data[pos], lcdata);
  3297. }
  3298. lcdata = null;
  3299. }
  3300. } catch (e) {
  3301. success = false;
  3302. }
  3303. }
  3304. if(success) {
  3305. if(cp === 'string') {$(ind).addClass(cssp);} else if(cssp !== null && cp === 'object') {$(ind).css(cssp);}
  3306. $(t).triggerHandler("jqGridAfterGridComplete");
  3307. }
  3308. });
  3309. return success;
  3310. },
  3311. addRowData : function(rowid,rdata,pos,src) {
  3312. if(["first", "last", "before", "after"].indexOf(pos) == -1) {pos = "last";}
  3313. var success = false, nm, row, gi, si, ni,sind, i, v, prp="", aradd, cnm, cn, data, cm, id;
  3314. if(rdata) {
  3315. if($.isArray(rdata)) {
  3316. aradd=true;
  3317. //pos = "last";
  3318. cnm = rowid;
  3319. } else {
  3320. rdata = [rdata];
  3321. aradd = false;
  3322. }
  3323. this.each(function() {
  3324. var t = this, datalen = rdata.length;
  3325. ni = t.p.rownumbers===true ? 1 :0;
  3326. gi = t.p.multiselect ===true ? 1 :0;
  3327. si = t.p.subGrid===true ? 1 :0;
  3328. if(!aradd) {
  3329. if(rowid !== undefined) { rowid = String(rowid);}
  3330. else {
  3331. rowid = $.jgrid.randId();
  3332. if(t.p.keyName !== false) {
  3333. cnm = t.p.keyName;
  3334. if(rdata[0][cnm] !== undefined) { rowid = rdata[0][cnm]; }
  3335. }
  3336. }
  3337. }
  3338. cn = t.p.altclass;
  3339. var k = 0, cna ="", lcdata = {},
  3340. air = $.isFunction(t.p.afterInsertRow) ? true : false;
  3341. while(k < datalen) {
  3342. data = rdata[k];
  3343. row=[];
  3344. if(aradd) {
  3345. try {
  3346. rowid = data[cnm];
  3347. if(rowid===undefined) {
  3348. rowid = $.jgrid.randId();
  3349. }
  3350. }
  3351. catch (e) {rowid = $.jgrid.randId();}
  3352. cna = t.p.altRows === true ? (t.rows.length-1)%2 === 0 ? cn : "" : "";
  3353. }
  3354. id = rowid;
  3355. rowid = t.p.idPrefix + rowid;
  3356. if(ni){
  3357. prp = t.formatCol(0,1,'',null,rowid, true);
  3358. row[row.length] = "<td role=\"gridcell\" class=\"ui-state-default jqgrid-rownum\" "+prp+">0</td>";
  3359. }
  3360. if(gi) {
  3361. v = "<input role=\"checkbox\" type=\"checkbox\""+" id=\"jqg_"+t.p.id+"_"+rowid+"\" class=\"cbox\"/>";
  3362. prp = t.formatCol(ni,1,'', null, rowid, true);
  3363. row[row.length] = "<td role=\"gridcell\" "+prp+">"+v+"</td>";
  3364. }
  3365. if(si) {
  3366. row[row.length] = $(t).jqGrid("addSubGridCell",gi+ni,1);
  3367. }
  3368. for(i = gi+si+ni; i < t.p.colModel.length;i++){
  3369. cm = t.p.colModel[i];
  3370. nm = cm.name;
  3371. lcdata[nm] = data[nm];
  3372. v = t.formatter( rowid, $.jgrid.getAccessor(data,nm), i, data );
  3373. prp = t.formatCol(i,1,v, data, rowid, lcdata);
  3374. row[row.length] = "<td role=\"gridcell\" "+prp+">"+v+"</td>";
  3375. }
  3376. row.unshift( t.constructTr(rowid, false, cna, lcdata, data, false ) );
  3377. row[row.length] = "</tr>";
  3378. if(t.rows.length === 0){
  3379. $("table:first",t.grid.bDiv).append(row.join(''));
  3380. } else {
  3381. switch (pos) {
  3382. case 'last':
  3383. $(t.rows[t.rows.length-1]).after(row.join(''));
  3384. sind = t.rows.length-1;
  3385. break;
  3386. case 'first':
  3387. $(t.rows[0]).after(row.join(''));
  3388. sind = 1;
  3389. break;
  3390. case 'after':
  3391. sind = $(t).jqGrid('getGridRowById', src);
  3392. if (sind) {
  3393. if($(t.rows[sind.rowIndex+1]).hasClass("ui-subgrid")) { $(t.rows[sind.rowIndex+1]).after(row); }
  3394. else { $(sind).after(row.join('')); }
  3395. sind=sind.rowIndex + 1;
  3396. }
  3397. break;
  3398. case 'before':
  3399. sind = $(t).jqGrid('getGridRowById', src);
  3400. if(sind) {
  3401. $(sind).before(row.join(''));
  3402. sind=sind.rowIndex - 1;
  3403. }
  3404. break;
  3405. }
  3406. }
  3407. if(t.p.subGrid===true) {
  3408. $(t).jqGrid("addSubGrid",gi+ni, sind);
  3409. }
  3410. t.p.records++;
  3411. t.p.reccount++;
  3412. $(t).triggerHandler("jqGridAfterInsertRow", [rowid,data,data]);
  3413. if(air) { t.p.afterInsertRow.call(t,rowid,data,data); }
  3414. k++;
  3415. if(t.p.datatype === 'local') {
  3416. lcdata[t.p.localReader.id] = id;
  3417. t.p._index[id] = t.p.data.length;
  3418. t.p.data.push(lcdata);
  3419. lcdata = {};
  3420. }
  3421. }
  3422. if( t.p.altRows === true && !aradd) {
  3423. if (pos === "last") {
  3424. if ((t.rows.length-1)%2 === 1) {$(t.rows[t.rows.length-1]).addClass(cn);}
  3425. } else {
  3426. $(t.rows).each(function(i){
  3427. if(i % 2 ===1) { $(this).addClass(cn); }
  3428. else { $(this).removeClass(cn); }
  3429. });
  3430. }
  3431. }
  3432. t.updatepager(true,true);
  3433. success = true;
  3434. });
  3435. }
  3436. return success;
  3437. },
  3438. footerData : function(action,data, format) {
  3439. var nm, success=false, res={}, title;
  3440. function isEmpty(obj) {
  3441. var i;
  3442. for(i in obj) {
  3443. if (obj.hasOwnProperty(i)) { return false; }
  3444. }
  3445. return true;
  3446. }
  3447. if(action == undefined) { action = "get"; }
  3448. if(typeof format !== "boolean") { format = true; }
  3449. action = action.toLowerCase();
  3450. this.each(function(){
  3451. var t = this, vl;
  3452. if(!t.grid || !t.p.footerrow) {return false;}
  3453. if(action === "set") { if(isEmpty(data)) { return false; } }
  3454. success=true;
  3455. $(this.p.colModel).each(function(i){
  3456. nm = this.name;
  3457. if(action === "set") {
  3458. if( data[nm] !== undefined) {
  3459. vl = format ? t.formatter( "", data[nm], i, data, 'edit') : data[nm];
  3460. title = this.title ? {"title":$.jgrid.stripHtml(vl)} : {};
  3461. $("tr.footrow td:eq("+i+")",t.grid.sDiv).html(vl).attr(title);
  3462. success = true;
  3463. }
  3464. } else if(action === "get") {
  3465. res[nm] = $("tr.footrow td:eq("+i+")",t.grid.sDiv).html();
  3466. }
  3467. });
  3468. });
  3469. return action === "get" ? res : success;
  3470. },
  3471. showHideCol : function(colname,show) {
  3472. return this.each(function() {
  3473. var $t = this, fndh=false, brd=$.jgrid.cell_width ? 0: $t.p.cellLayout, cw;
  3474. if (!$t.grid ) {return;}
  3475. if( typeof colname === 'string') {colname=[colname];}
  3476. show = show !== "none" ? "" : "none";
  3477. var sw = show === "" ? true :false,
  3478. gh = $t.p.groupHeader && (typeof $t.p.groupHeader === 'object' || $.isFunction($t.p.groupHeader) );
  3479. if(gh) { $($t).jqGrid('destroyGroupHeader', false); }
  3480. $(this.p.colModel).each(function(i) {
  3481. if ($.inArray(this.name,colname) !== -1 && this.hidden === sw) {
  3482. if($t.p.frozenColumns === true && this.frozen === true) {
  3483. return true;
  3484. }
  3485. $("tr[role=row]",$t.grid.hDiv).each(function(){
  3486. $(this.cells[i]).css("display", show);
  3487. });
  3488. $($t.rows).each(function(){
  3489. if (!$(this).hasClass("jqgroup")) {
  3490. $(this.cells[i]).css("display", show);
  3491. }
  3492. });
  3493. if($t.p.footerrow) { $("tr.footrow td:eq("+i+")", $t.grid.sDiv).css("display", show); }
  3494. cw = parseInt(this.width,10);
  3495. if(show === "none") {
  3496. $t.p.tblwidth -= cw+brd;
  3497. } else {
  3498. $t.p.tblwidth += cw+brd;
  3499. }
  3500. this.hidden = !sw;
  3501. fndh=true;
  3502. $($t).triggerHandler("jqGridShowHideCol", [sw,this.name,i]);
  3503. }
  3504. });
  3505. if(fndh===true) {
  3506. if($t.p.shrinkToFit === true && !isNaN($t.p.height)) { $t.p.tblwidth += parseInt($t.p.scrollOffset,10);}
  3507. $($t).jqGrid("setGridWidth",$t.p.shrinkToFit === true ? $t.p.tblwidth : $t.p.width );
  3508. }
  3509. if( gh ) {
  3510. $($t).jqGrid('setGroupHeaders',$t.p.groupHeader);
  3511. }
  3512. });
  3513. },
  3514. hideCol : function (colname) {
  3515. return this.each(function(){$(this).jqGrid("showHideCol",colname,"none");});
  3516. },
  3517. showCol : function(colname) {
  3518. return this.each(function(){$(this).jqGrid("showHideCol",colname,"");});
  3519. },
  3520. remapColumns : function(permutation, updateCells, keepHeader)
  3521. {
  3522. function resortArray(a) {
  3523. var ac;
  3524. if (a.length) {
  3525. ac = $.makeArray(a);
  3526. } else {
  3527. ac = $.extend({}, a);
  3528. }
  3529. $.each(permutation, function(i) {
  3530. a[i] = ac[this];
  3531. });
  3532. }
  3533. var ts = this.get(0);
  3534. function resortRows(parent, clobj) {
  3535. $(">tr"+(clobj||""), parent).each(function() {
  3536. var row = this;
  3537. var elems = $.makeArray(row.cells);
  3538. $.each(permutation, function() {
  3539. var e = elems[this];
  3540. if (e) {
  3541. row.appendChild(e);
  3542. }
  3543. });
  3544. });
  3545. }
  3546. resortArray(ts.p.colModel);
  3547. resortArray(ts.p.colNames);
  3548. resortArray(ts.grid.headers);
  3549. resortRows($("thead:first", ts.grid.hDiv), keepHeader && ":not(.ui-jqgrid-labels)");
  3550. if (updateCells) {
  3551. resortRows($("#"+$.jgrid.jqID(ts.p.id)+" tbody:first"), ".jqgfirstrow, tr.jqgrow, tr.jqfoot");
  3552. }
  3553. if (ts.p.footerrow) {
  3554. resortRows($("tbody:first", ts.grid.sDiv));
  3555. }
  3556. if (ts.p.remapColumns) {
  3557. if (!ts.p.remapColumns.length){
  3558. ts.p.remapColumns = $.makeArray(permutation);
  3559. } else {
  3560. resortArray(ts.p.remapColumns);
  3561. }
  3562. }
  3563. ts.p.lastsort = $.inArray(ts.p.lastsort, permutation);
  3564. if(ts.p.treeGrid) { ts.p.expColInd = $.inArray(ts.p.expColInd, permutation); }
  3565. $(ts).triggerHandler("jqGridRemapColumns", [permutation, updateCells, keepHeader]);
  3566. },
  3567. setGridWidth : function(nwidth, shrink) {
  3568. return this.each(function(){
  3569. if (!this.grid ) {return;}
  3570. var $t = this, cw,
  3571. initwidth = 0, brd=$.jgrid.cell_width ? 0: $t.p.cellLayout, lvc, vc=0, hs=false, scw=$t.p.scrollOffset, aw, gw=0, cr;
  3572. if(typeof shrink !== 'boolean') {
  3573. shrink=$t.p.shrinkToFit;
  3574. }
  3575. if(isNaN(nwidth)) {return;}
  3576. nwidth = parseInt(nwidth,10);
  3577. $t.grid.width = $t.p.width = nwidth;
  3578. $("#gbox_"+$.jgrid.jqID($t.p.id)).css("width",nwidth+"px");
  3579. $("#gview_"+$.jgrid.jqID($t.p.id)).css("width",nwidth+"px");
  3580. $($t.grid.bDiv).css("width",nwidth+"px");
  3581. $($t.grid.hDiv).css("width",nwidth+"px");
  3582. if($t.p.pager ) {$($t.p.pager).css("width",nwidth+"px");}
  3583. if($t.p.toppager ) {$($t.p.toppager).css("width",nwidth+"px");}
  3584. if($t.p.toolbar[0] === true){
  3585. $($t.grid.uDiv).css("width",nwidth+"px");
  3586. if($t.p.toolbar[1]==="both") {$($t.grid.ubDiv).css("width",nwidth+"px");}
  3587. }
  3588. if($t.p.footerrow) { $($t.grid.sDiv).css("width",nwidth+"px"); }
  3589. if(shrink ===false && $t.p.forceFit === true) {$t.p.forceFit=false;}
  3590. if(shrink===true) {
  3591. $.each($t.p.colModel, function() {
  3592. if(this.hidden===false){
  3593. cw = this.widthOrg;
  3594. initwidth += cw+brd;
  3595. if(this.fixed) {
  3596. gw += cw+brd;
  3597. } else {
  3598. vc++;
  3599. }
  3600. }
  3601. });
  3602. if(vc === 0) { return; }
  3603. $t.p.tblwidth = initwidth;
  3604. aw = nwidth-brd*vc-gw;
  3605. if(!isNaN($t.p.height)) {
  3606. if($($t.grid.bDiv)[0].clientHeight < $($t.grid.bDiv)[0].scrollHeight || $t.rows.length === 1){
  3607. hs = true;
  3608. aw -= scw;
  3609. }
  3610. }
  3611. initwidth =0;
  3612. var cle = $t.grid.cols.length >0;
  3613. $.each($t.p.colModel, function(i) {
  3614. if(this.hidden === false && !this.fixed){
  3615. cw = this.widthOrg;
  3616. cw = Math.round(aw*cw/($t.p.tblwidth-brd*vc-gw));
  3617. if (cw < 0) { return; }
  3618. this.width =cw;
  3619. initwidth += cw;
  3620. $t.grid.headers[i].width=cw;
  3621. $t.grid.headers[i].el.style.width=cw+"px";
  3622. if($t.p.footerrow) { $t.grid.footers[i].style.width = cw+"px"; }
  3623. if(cle) { $t.grid.cols[i].style.width = cw+"px"; }
  3624. lvc = i;
  3625. }
  3626. });
  3627. if (!lvc) { return; }
  3628. cr =0;
  3629. if (hs) {
  3630. if(nwidth-gw-(initwidth+brd*vc) !== scw){
  3631. cr = nwidth-gw-(initwidth+brd*vc)-scw;
  3632. }
  3633. } else if( Math.abs(nwidth-gw-(initwidth+brd*vc)) !== 1) {
  3634. cr = nwidth-gw-(initwidth+brd*vc);
  3635. }
  3636. $t.p.colModel[lvc].width += cr;
  3637. $t.p.tblwidth = initwidth+cr+brd*vc+gw;
  3638. if($t.p.tblwidth > nwidth) {
  3639. var delta = $t.p.tblwidth - parseInt(nwidth,10);
  3640. $t.p.tblwidth = nwidth;
  3641. cw = $t.p.colModel[lvc].width = $t.p.colModel[lvc].width-delta;
  3642. } else {
  3643. cw= $t.p.colModel[lvc].width;
  3644. }
  3645. $t.grid.headers[lvc].width = cw;
  3646. $t.grid.headers[lvc].el.style.width=cw+"px";
  3647. if(cle) { $t.grid.cols[lvc].style.width = cw+"px"; }
  3648. if($t.p.footerrow) {
  3649. $t.grid.footers[lvc].style.width = cw+"px";
  3650. }
  3651. }
  3652. if($t.p.tblwidth) {
  3653. $('table:first',$t.grid.bDiv).css("width",$t.p.tblwidth+"px");
  3654. $('table:first',$t.grid.hDiv).css("width",$t.p.tblwidth+"px");
  3655. $t.grid.hDiv.scrollLeft = $t.grid.bDiv.scrollLeft;
  3656. if($t.p.footerrow) {
  3657. $('table:first',$t.grid.sDiv).css("width",$t.p.tblwidth+"px");
  3658. }
  3659. }
  3660. });
  3661. },
  3662. setGridHeight : function (nh) {
  3663. return this.each(function (){
  3664. var $t = this;
  3665. if(!$t.grid) {return;}
  3666. var bDiv = $($t.grid.bDiv);
  3667. bDiv.css({height: nh+(isNaN(nh)?"":"px")});
  3668. if($t.p.frozenColumns === true){
  3669. //follow the original set height to use 16, better scrollbar width detection
  3670. $('#'+$.jgrid.jqID($t.p.id)+"_frozen").parent().height(bDiv.height() - 16);
  3671. }
  3672. $t.p.height = nh;
  3673. if ($t.p.scroll) { $t.grid.populateVisible(); }
  3674. });
  3675. },
  3676. setCaption : function (newcap){
  3677. return this.each(function(){
  3678. this.p.caption=newcap;
  3679. $("span.ui-jqgrid-title, span.ui-jqgrid-title-rtl",this.grid.cDiv).html(newcap);
  3680. $(this.grid.cDiv).show();
  3681. $(this.grid.hDiv).removeClass('ui-corner-top');
  3682. });
  3683. },
  3684. setLabel : function(colname, nData, prop, attrp ){
  3685. return this.each(function(){
  3686. var $t = this, pos=-1;
  3687. if(!$t.grid) {return;}
  3688. if(colname !== undefined) {
  3689. $($t.p.colModel).each(function(i){
  3690. if (this.name === colname) {
  3691. pos = i;return false;
  3692. }
  3693. });
  3694. } else { return; }
  3695. if(pos>=0) {
  3696. var thecol = $("tr.ui-jqgrid-labels th:eq("+pos+")",$t.grid.hDiv);
  3697. if (nData){
  3698. var ico = $(".s-ico",thecol);
  3699. $("[id^=jqgh_]",thecol).empty().html(nData).append(ico);
  3700. $t.p.colNames[pos] = nData;
  3701. }
  3702. if (prop) {
  3703. if(typeof prop === 'string') {$(thecol).addClass(prop);} else {$(thecol).css(prop);}
  3704. }
  3705. if(typeof attrp === 'object') {$(thecol).attr(attrp);}
  3706. }
  3707. });
  3708. },
  3709. setCell : function(rowid,colname,nData,cssp,attrp, forceupd) {
  3710. return this.each(function(){
  3711. var $t = this, pos =-1,v, title;
  3712. if(!$t.grid) {return;}
  3713. if(isNaN(colname)) {
  3714. $($t.p.colModel).each(function(i){
  3715. if (this.name === colname) {
  3716. pos = i;return false;
  3717. }
  3718. });
  3719. } else {pos = parseInt(colname,10);}
  3720. if(pos>=0) {
  3721. var ind = $($t).jqGrid('getGridRowById', rowid);
  3722. if (ind){
  3723. var tcell = $("td:eq("+pos+")",ind), cl=0, rawdat=[];
  3724. if(nData !== "" || forceupd === true) {
  3725. while(cl<ind.cells.length) {
  3726. // slow down speed
  3727. rawdat.push(ind.cells[cl].innerHTML);
  3728. cl++;
  3729. }
  3730. v = $t.formatter(rowid, nData, pos, rawdat, 'edit');
  3731. title = $t.p.colModel[pos].title ? {"title":$.jgrid.stripHtml(v)} : {};
  3732. if($t.p.treeGrid && $(".tree-wrap",$(tcell)).length>0) {
  3733. $("span",$(tcell)).html(v).attr(title);
  3734. } else {
  3735. $(tcell).html(v).attr(title);
  3736. }
  3737. if($t.p.datatype === "local") {
  3738. var cm = $t.p.colModel[pos], index;
  3739. nData = cm.formatter && typeof cm.formatter === 'string' && cm.formatter === 'date' ? $.unformat.date.call($t,nData,cm) : nData;
  3740. index = $t.p._index[$.jgrid.stripPref($t.p.idPrefix, rowid)];
  3741. if(index !== undefined) {
  3742. $t.p.data[index][cm.name] = nData;
  3743. }
  3744. }
  3745. }
  3746. if(typeof cssp === 'string'){
  3747. $(tcell).addClass(cssp);
  3748. } else if(cssp) {
  3749. $(tcell).css(cssp);
  3750. }
  3751. if(typeof attrp === 'object') {$(tcell).attr(attrp);}
  3752. }
  3753. }
  3754. });
  3755. },
  3756. getCell : function(rowid,col) {
  3757. var ret = false;
  3758. this.each(function(){
  3759. var $t=this, pos=-1;
  3760. if(!$t.grid) {return;}
  3761. if(isNaN(col)) {
  3762. $($t.p.colModel).each(function(i){
  3763. if (this.name === col) {
  3764. pos = i;return false;
  3765. }
  3766. });
  3767. } else {pos = parseInt(col,10);}
  3768. if(pos>=0) {
  3769. var ind = $($t).jqGrid('getGridRowById', rowid);
  3770. if(ind) {
  3771. try {
  3772. ret = $.unformat.call($t,$("td:eq("+pos+")",ind),{rowId:ind.id, colModel:$t.p.colModel[pos]},pos);
  3773. } catch (e){
  3774. ret = $.jgrid.htmlDecode($("td:eq("+pos+")",ind).html());
  3775. }
  3776. }
  3777. }
  3778. });
  3779. return ret;
  3780. },
  3781. getCol : function (col, obj, mathopr) {
  3782. var ret = [], val, sum=0, min, max, v;
  3783. obj = typeof obj !== 'boolean' ? false : obj;
  3784. if(mathopr === undefined) { mathopr = false; }
  3785. this.each(function(){
  3786. var $t=this, pos=-1;
  3787. if(!$t.grid) {return;}
  3788. if(isNaN(col)) {
  3789. $($t.p.colModel).each(function(i){
  3790. if (this.name === col) {
  3791. pos = i;return false;
  3792. }
  3793. });
  3794. } else {pos = parseInt(col,10);}
  3795. if(pos>=0) {
  3796. var ln = $t.rows.length, i =0, dlen=0;
  3797. if (ln && ln>0){
  3798. while(i<ln){
  3799. if($($t.rows[i]).hasClass('jqgrow')) {
  3800. try {
  3801. val = $.unformat.call($t,$($t.rows[i].cells[pos]),{rowId:$t.rows[i].id, colModel:$t.p.colModel[pos]},pos);
  3802. } catch (e) {
  3803. val = $.jgrid.htmlDecode($t.rows[i].cells[pos].innerHTML);
  3804. }
  3805. if(mathopr) {
  3806. v = parseFloat(val);
  3807. if(!isNaN(v)) {
  3808. sum += v;
  3809. if (max === undefined) {max = min = v;}
  3810. min = Math.min(min, v);
  3811. max = Math.max(max, v);
  3812. dlen++;
  3813. }
  3814. }
  3815. else if(obj) { ret.push( {id:$t.rows[i].id,value:val} ); }
  3816. else { ret.push( val ); }
  3817. }
  3818. i++;
  3819. }
  3820. if(mathopr) {
  3821. switch(mathopr.toLowerCase()){
  3822. case 'sum': ret =sum; break;
  3823. case 'avg': ret = sum/dlen; break;
  3824. case 'count': ret = (ln-1); break;
  3825. case 'min': ret = min; break;
  3826. case 'max': ret = max; break;
  3827. }
  3828. }
  3829. }
  3830. }
  3831. });
  3832. return ret;
  3833. },
  3834. clearGridData : function(clearfooter) {
  3835. return this.each(function(){
  3836. var $t = this;
  3837. if(!$t.grid) {return;}
  3838. if(typeof clearfooter !== 'boolean') { clearfooter = false; }
  3839. if($t.p.deepempty) {$("#"+$.jgrid.jqID($t.p.id)+" tbody:first tr:gt(0)").remove();}
  3840. else {
  3841. var trf = $("#"+$.jgrid.jqID($t.p.id)+" tbody:first tr:first")[0];
  3842. $("#"+$.jgrid.jqID($t.p.id)+" tbody:first").empty().append(trf);
  3843. }
  3844. if($t.p.footerrow && clearfooter) { $(".ui-jqgrid-ftable td",$t.grid.sDiv).html("&#160;"); }
  3845. $t.p.selrow = null; $t.p.selarrrow= []; $t.p.savedRow = [];
  3846. $t.p.records = 0;$t.p.page=1;$t.p.lastpage=0;$t.p.reccount=0;
  3847. $t.p.data = []; $t.p._index = {};
  3848. $t.updatepager(true,false);
  3849. });
  3850. },
  3851. getInd : function(rowid,rc){
  3852. var ret =false,rw;
  3853. this.each(function(){
  3854. rw = $(this).jqGrid('getGridRowById', rowid);
  3855. if(rw) {
  3856. ret = rc===true ? rw: rw.rowIndex;
  3857. }
  3858. });
  3859. return ret;
  3860. },
  3861. bindKeys : function( settings ){
  3862. var o = $.extend({
  3863. onEnter: null,
  3864. onSpace: null,
  3865. onLeftKey: null,
  3866. onRightKey: null,
  3867. scrollingRows : true
  3868. },settings || {});
  3869. return this.each(function(){
  3870. var $t = this;
  3871. if( !$('body').is('[role]') ){$('body').attr('role','application');}
  3872. $t.p.scrollrows = o.scrollingRows;
  3873. $($t).keydown(function(event){
  3874. var target = $($t).find('tr[tabindex=0]')[0], id, r, mind,
  3875. expanded = $t.p.treeReader.expanded_field;
  3876. //check for arrow keys
  3877. if(target) {
  3878. mind = $t.p._index[$.jgrid.stripPref($t.p.idPrefix, target.id)];
  3879. if(event.keyCode === 37 || event.keyCode === 38 || event.keyCode === 39 || event.keyCode === 40){
  3880. // up key
  3881. if(event.keyCode === 38 ){
  3882. r = target.previousSibling;
  3883. id = "";
  3884. if(r) {
  3885. if($(r).is(":hidden")) {
  3886. while(r) {
  3887. r = r.previousSibling;
  3888. if(!$(r).is(":hidden") && $(r).hasClass('jqgrow')) {id = r.id;break;}
  3889. }
  3890. } else {
  3891. id = r.id;
  3892. }
  3893. }
  3894. $($t).jqGrid('setSelection', id, true, event);
  3895. event.preventDefault();
  3896. }
  3897. //if key is down arrow
  3898. if(event.keyCode === 40){
  3899. r = target.nextSibling;
  3900. id ="";
  3901. if(r) {
  3902. if($(r).is(":hidden")) {
  3903. while(r) {
  3904. r = r.nextSibling;
  3905. if(!$(r).is(":hidden") && $(r).hasClass('jqgrow') ) {id = r.id;break;}
  3906. }
  3907. } else {
  3908. id = r.id;
  3909. }
  3910. }
  3911. $($t).jqGrid('setSelection', id, true, event);
  3912. event.preventDefault();
  3913. }
  3914. // left
  3915. if(event.keyCode === 37 ){
  3916. if($t.p.treeGrid && $t.p.data[mind][expanded]) {
  3917. $(target).find("div.treeclick").trigger('click');
  3918. }
  3919. $($t).triggerHandler("jqGridKeyLeft", [$t.p.selrow]);
  3920. if($.isFunction(o.onLeftKey)) {
  3921. o.onLeftKey.call($t, $t.p.selrow);
  3922. }
  3923. }
  3924. // right
  3925. if(event.keyCode === 39 ){
  3926. if($t.p.treeGrid && !$t.p.data[mind][expanded]) {
  3927. $(target).find("div.treeclick").trigger('click');
  3928. }
  3929. $($t).triggerHandler("jqGridKeyRight", [$t.p.selrow]);
  3930. if($.isFunction(o.onRightKey)) {
  3931. o.onRightKey.call($t, $t.p.selrow);
  3932. }
  3933. }
  3934. }
  3935. //check if enter was pressed on a grid or treegrid node
  3936. else if( event.keyCode === 13 ){
  3937. $($t).triggerHandler("jqGridKeyEnter", [$t.p.selrow]);
  3938. if($.isFunction(o.onEnter)) {
  3939. o.onEnter.call($t, $t.p.selrow);
  3940. }
  3941. } else if(event.keyCode === 32) {
  3942. $($t).triggerHandler("jqGridKeySpace", [$t.p.selrow]);
  3943. if($.isFunction(o.onSpace)) {
  3944. o.onSpace.call($t, $t.p.selrow);
  3945. }
  3946. }
  3947. }
  3948. });
  3949. });
  3950. },
  3951. unbindKeys : function(){
  3952. return this.each(function(){
  3953. $(this).unbind('keydown');
  3954. });
  3955. },
  3956. getLocalRow : function (rowid) {
  3957. var ret = false, ind;
  3958. this.each(function(){
  3959. if(rowid !== undefined) {
  3960. ind = this.p._index[$.jgrid.stripPref(this.p.idPrefix, rowid)];
  3961. if(ind >= 0 ) {
  3962. ret = this.p.data[ind];
  3963. }
  3964. }
  3965. });
  3966. return ret;
  3967. },
  3968. progressBar : function ( p ) {
  3969. p = $.extend({
  3970. htmlcontent : "",
  3971. method : "hide",
  3972. loadtype : "disable"
  3973. }, p || {});
  3974. return this.each(function(){
  3975. var sh = p.method==="show" ? true : false;
  3976. if(p.htmlcontent !== "") {
  3977. $("#load_"+$.jgrid.jqID(this.p.id)).html( p.htmlcontent );
  3978. }
  3979. switch(p.loadtype) {
  3980. case "disable":
  3981. break;
  3982. case "enable":
  3983. $("#load_"+$.jgrid.jqID(this.p.id)).toggle( sh );
  3984. break;
  3985. case "block":
  3986. $("#lui_"+$.jgrid.jqID(this.p.id)).toggle( sh );
  3987. $("#load_"+$.jgrid.jqID(this.p.id)).toggle( sh );
  3988. break;
  3989. }
  3990. });
  3991. }
  3992. });
  3993. })(jQuery);
  3994. /*jshint eqeqeq:false */
  3995. /*global jQuery */
  3996. (function($){
  3997. /*
  3998. **
  3999. * jqGrid extension for cellediting Grid Data
  4000. * Tony Tomov tony@trirand.com
  4001. * http://trirand.com/blog/
  4002. * Dual licensed under the MIT and GPL licenses:
  4003. * http://www.opensource.org/licenses/mit-license.php
  4004. * http://www.gnu.org/licenses/gpl-2.0.html
  4005. **/
  4006. /**
  4007. * all events and options here are aded anonynous and not in the base grid
  4008. * since the array is to big. Here is the order of execution.
  4009. * From this point we use jQuery isFunction
  4010. * formatCell
  4011. * beforeEditCell,
  4012. * onSelectCell (used only for noneditable cels)
  4013. * afterEditCell,
  4014. * beforeSaveCell, (called before validation of values if any)
  4015. * beforeSubmitCell (if cellsubmit remote (ajax))
  4016. * afterSubmitCell(if cellsubmit remote (ajax)),
  4017. * afterSaveCell,
  4018. * errorCell,
  4019. * serializeCellData - new
  4020. * Options
  4021. * cellsubmit (remote,clientArray) (added in grid options)
  4022. * cellurl
  4023. * ajaxCellOptions
  4024. * */
  4025. "use strict";
  4026. $.jgrid.extend({
  4027. editCell : function (iRow,iCol, ed){
  4028. return this.each(function (){
  4029. var $t = this, nm, tmp,cc, cm;
  4030. if (!$t.grid || $t.p.cellEdit !== true) {return;}
  4031. iCol = parseInt(iCol,10);
  4032. // select the row that can be used for other methods
  4033. $t.p.selrow = $t.rows[iRow].id;
  4034. if (!$t.p.knv) {$($t).jqGrid("GridNav");}
  4035. // check to see if we have already edited cell
  4036. if ($t.p.savedRow.length>0) {
  4037. // prevent second click on that field and enable selects
  4038. if (ed===true ) {
  4039. if(iRow == $t.p.iRow && iCol == $t.p.iCol){
  4040. return;
  4041. }
  4042. }
  4043. // save the cell
  4044. $($t).jqGrid("saveCell",$t.p.savedRow[0].id,$t.p.savedRow[0].ic);
  4045. } else {
  4046. window.setTimeout(function () { $("#"+$.jgrid.jqID($t.p.knv)).attr("tabindex","-1").focus();},1);
  4047. }
  4048. cm = $t.p.colModel[iCol];
  4049. nm = cm.name;
  4050. if (nm==='subgrid' || nm==='cb' || nm==='rn') {return;}
  4051. cc = $("td:eq("+iCol+")",$t.rows[iRow]);
  4052. if (cm.editable===true && ed===true && !cc.hasClass("not-editable-cell")) {
  4053. if(parseInt($t.p.iCol,10)>=0 && parseInt($t.p.iRow,10)>=0) {
  4054. $("td:eq("+$t.p.iCol+")",$t.rows[$t.p.iRow]).removeClass("edit-cell ui-state-highlight");
  4055. $($t.rows[$t.p.iRow]).removeClass("selected-row ui-state-hover");
  4056. }
  4057. $(cc).addClass("edit-cell ui-state-highlight");
  4058. $($t.rows[iRow]).addClass("selected-row ui-state-hover");
  4059. try {
  4060. tmp = $.unformat.call($t,cc,{rowId: $t.rows[iRow].id, colModel:cm},iCol);
  4061. } catch (_) {
  4062. tmp = ( cm.edittype && cm.edittype === 'textarea' ) ? $(cc).text() : $(cc).html();
  4063. }
  4064. if($t.p.autoencode) { tmp = $.jgrid.htmlDecode(tmp); }
  4065. if (!cm.edittype) {cm.edittype = "text";}
  4066. $t.p.savedRow.push({id:iRow,ic:iCol,name:nm,v:tmp});
  4067. if(tmp === "&nbsp;" || tmp === "&#160;" || (tmp.length===1 && tmp.charCodeAt(0)===160) ) {tmp='';}
  4068. if($.isFunction($t.p.formatCell)) {
  4069. var tmp2 = $t.p.formatCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
  4070. if(tmp2 !== undefined ) {tmp = tmp2;}
  4071. }
  4072. $($t).triggerHandler("jqGridBeforeEditCell", [$t.rows[iRow].id, nm, tmp, iRow, iCol]);
  4073. if ($.isFunction($t.p.beforeEditCell)) {
  4074. $t.p.beforeEditCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
  4075. }
  4076. var opt = $.extend({}, cm.editoptions || {} ,{id:iRow+"_"+nm,name:nm,rowId: $t.rows[iRow].id});
  4077. var elc = $.jgrid.createEl.call($t,cm.edittype,opt,tmp,true,$.extend({},$.jgrid.ajaxOptions,$t.p.ajaxSelectOptions || {}));
  4078. $(cc).html("").append(elc).attr("tabindex","0");
  4079. $.jgrid.bindEv.call($t, elc, opt);
  4080. window.setTimeout(function () { $(elc).focus();},1);
  4081. $("input, select, textarea",cc).bind("keydown",function(e) {
  4082. if (e.keyCode === 27) {
  4083. if($("input.hasDatepicker",cc).length >0) {
  4084. if( $(".ui-datepicker").is(":hidden") ) { $($t).jqGrid("restoreCell",iRow,iCol); }
  4085. else { $("input.hasDatepicker",cc).datepicker('hide'); }
  4086. } else {
  4087. $($t).jqGrid("restoreCell",iRow,iCol);
  4088. }
  4089. } //ESC
  4090. if (e.keyCode === 13 && !e.shiftKey) {
  4091. $($t).jqGrid("saveCell",iRow,iCol);
  4092. // Prevent default action
  4093. return false;
  4094. } //Enter
  4095. if (e.keyCode === 9) {
  4096. if(!$t.grid.hDiv.loading ) {
  4097. if (e.shiftKey) {$($t).jqGrid("prevCell",iRow,iCol);} //Shift TAb
  4098. else {$($t).jqGrid("nextCell",iRow,iCol);} //Tab
  4099. } else {
  4100. return false;
  4101. }
  4102. }
  4103. e.stopPropagation();
  4104. });
  4105. $($t).triggerHandler("jqGridAfterEditCell", [$t.rows[iRow].id, nm, tmp, iRow, iCol]);
  4106. if ($.isFunction($t.p.afterEditCell)) {
  4107. $t.p.afterEditCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
  4108. }
  4109. } else {
  4110. if (parseInt($t.p.iCol,10)>=0 && parseInt($t.p.iRow,10)>=0) {
  4111. $("td:eq("+$t.p.iCol+")",$t.rows[$t.p.iRow]).removeClass("edit-cell ui-state-highlight");
  4112. $($t.rows[$t.p.iRow]).removeClass("selected-row ui-state-hover");
  4113. }
  4114. cc.addClass("edit-cell ui-state-highlight");
  4115. $($t.rows[iRow]).addClass("selected-row ui-state-hover");
  4116. tmp = cc.html().replace(/\&#160\;/ig,'');
  4117. $($t).triggerHandler("jqGridSelectCell", [$t.rows[iRow].id, nm, tmp, iRow, iCol]);
  4118. if ($.isFunction($t.p.onSelectCell)) {
  4119. $t.p.onSelectCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
  4120. }
  4121. }
  4122. $t.p.iCol = iCol; $t.p.iRow = iRow;
  4123. });
  4124. },
  4125. saveCell : function (iRow, iCol){
  4126. return this.each(function(){
  4127. var $t= this, fr;
  4128. if (!$t.grid || $t.p.cellEdit !== true) {return;}
  4129. if ( $t.p.savedRow.length >= 1) {fr = 0;} else {fr=null;}
  4130. if(fr !== null) {
  4131. var cc = $("td:eq("+iCol+")",$t.rows[iRow]),v,v2,
  4132. cm = $t.p.colModel[iCol], nm = cm.name, nmjq = $.jgrid.jqID(nm) ;
  4133. switch (cm.edittype) {
  4134. case "select":
  4135. if(!cm.editoptions.multiple) {
  4136. v = $("#"+iRow+"_"+nmjq+" option:selected",$t.rows[iRow]).val();
  4137. v2 = $("#"+iRow+"_"+nmjq+" option:selected",$t.rows[iRow]).text();
  4138. } else {
  4139. var sel = $("#"+iRow+"_"+nmjq,$t.rows[iRow]), selectedText = [];
  4140. v = $(sel).val();
  4141. if(v) { v.join(",");} else { v=""; }
  4142. $("option:selected",sel).each(
  4143. function(i,selected){
  4144. selectedText[i] = $(selected).text();
  4145. }
  4146. );
  4147. v2 = selectedText.join(",");
  4148. }
  4149. if(cm.formatter) { v2 = v; }
  4150. break;
  4151. case "checkbox":
  4152. var cbv = ["Yes","No"];
  4153. if(cm.editoptions){
  4154. cbv = cm.editoptions.value.split(":");
  4155. }
  4156. v = $("#"+iRow+"_"+nmjq,$t.rows[iRow]).is(":checked") ? cbv[0] : cbv[1];
  4157. v2=v;
  4158. break;
  4159. case "password":
  4160. case "text":
  4161. case "textarea":
  4162. case "button" :
  4163. v = $("#"+iRow+"_"+nmjq,$t.rows[iRow]).val();
  4164. v2=v;
  4165. break;
  4166. case 'custom' :
  4167. try {
  4168. if(cm.editoptions && $.isFunction(cm.editoptions.custom_value)) {
  4169. v = cm.editoptions.custom_value.call($t, $(".customelement",cc),'get');
  4170. if (v===undefined) { throw "e2";} else { v2=v; }
  4171. } else { throw "e1"; }
  4172. } catch (e) {
  4173. if (e==="e1") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.nodefined,$.jgrid.edit.bClose); }
  4174. if (e==="e2") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose); }
  4175. else {$.jgrid.info_dialog($.jgrid.errors.errcap,e.message,$.jgrid.edit.bClose); }
  4176. }
  4177. break;
  4178. }
  4179. // The common approach is if nothing changed do not do anything
  4180. if (v2 !== $t.p.savedRow[fr].v){
  4181. var vvv = $($t).triggerHandler("jqGridBeforeSaveCell", [$t.rows[iRow].id, nm, v, iRow, iCol]);
  4182. if (vvv) {v = vvv; v2=vvv;}
  4183. if ($.isFunction($t.p.beforeSaveCell)) {
  4184. var vv = $t.p.beforeSaveCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
  4185. if (vv) {v = vv; v2=vv;}
  4186. }
  4187. var cv = $.jgrid.checkValues.call($t,v,iCol);
  4188. if(cv[0] === true) {
  4189. var addpost = $($t).triggerHandler("jqGridBeforeSubmitCell", [$t.rows[iRow].id, nm, v, iRow, iCol]) || {};
  4190. if ($.isFunction($t.p.beforeSubmitCell)) {
  4191. addpost = $t.p.beforeSubmitCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
  4192. if (!addpost) {addpost={};}
  4193. }
  4194. if( $("input.hasDatepicker",cc).length >0) { $("input.hasDatepicker",cc).datepicker('hide'); }
  4195. if ($t.p.cellsubmit === 'remote') {
  4196. if ($t.p.cellurl) {
  4197. var postdata = {};
  4198. if($t.p.autoencode) { v = $.jgrid.htmlEncode(v); }
  4199. postdata[nm] = v;
  4200. var idname,oper, opers;
  4201. opers = $t.p.prmNames;
  4202. idname = opers.id;
  4203. oper = opers.oper;
  4204. postdata[idname] = $.jgrid.stripPref($t.p.idPrefix, $t.rows[iRow].id);
  4205. postdata[oper] = opers.editoper;
  4206. postdata = $.extend(addpost,postdata);
  4207. $($t).jqGrid("progressBar", {method:"show", loadtype : $t.p.loadui, htmlcontent: $.jgrid.defaults.savetext || "Saving..." });
  4208. $t.grid.hDiv.loading = true;
  4209. $.ajax( $.extend( {
  4210. url: $t.p.cellurl,
  4211. data :$.isFunction($t.p.serializeCellData) ? $t.p.serializeCellData.call($t, postdata) : postdata,
  4212. type: "POST",
  4213. complete: function (result, stat) {
  4214. $($t).jqGrid("progressBar", {method:"hide", loadtype : $t.p.loadui });
  4215. $t.grid.hDiv.loading = false;
  4216. if (stat === 'success') {
  4217. var ret = $($t).triggerHandler("jqGridAfterSubmitCell", [$t, result, postdata.id, nm, v, iRow, iCol]) || [true, ''];
  4218. if (ret[0] === true && $.isFunction($t.p.afterSubmitCell)) {
  4219. ret = $t.p.afterSubmitCell.call($t, result,postdata.id,nm,v,iRow,iCol);
  4220. }
  4221. if(ret[0] === true){
  4222. $(cc).empty();
  4223. $($t).jqGrid("setCell",$t.rows[iRow].id, iCol, v2, false, false, true);
  4224. $(cc).addClass("dirty-cell");
  4225. $($t.rows[iRow]).addClass("edited");
  4226. $($t).triggerHandler("jqGridAfterSaveCell", [$t.rows[iRow].id, nm, v, iRow, iCol]);
  4227. if ($.isFunction($t.p.afterSaveCell)) {
  4228. $t.p.afterSaveCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
  4229. }
  4230. $t.p.savedRow.splice(0,1);
  4231. } else {
  4232. $.jgrid.info_dialog($.jgrid.errors.errcap,ret[1],$.jgrid.edit.bClose);
  4233. $($t).jqGrid("restoreCell",iRow,iCol);
  4234. }
  4235. }
  4236. },
  4237. error:function(res,stat,err) {
  4238. $("#lui_"+$.jgrid.jqID($t.p.id)).hide();
  4239. $t.grid.hDiv.loading = false;
  4240. $($t).triggerHandler("jqGridErrorCell", [res, stat, err]);
  4241. if ($.isFunction($t.p.errorCell)) {
  4242. $t.p.errorCell.call($t, res,stat,err);
  4243. $($t).jqGrid("restoreCell",iRow,iCol);
  4244. } else {
  4245. $.jgrid.info_dialog($.jgrid.errors.errcap,res.status+" : "+res.statusText+"<br/>"+stat,$.jgrid.edit.bClose);
  4246. $($t).jqGrid("restoreCell",iRow,iCol);
  4247. }
  4248. }
  4249. }, $.jgrid.ajaxOptions, $t.p.ajaxCellOptions || {}));
  4250. } else {
  4251. try {
  4252. $.jgrid.info_dialog($.jgrid.errors.errcap,$.jgrid.errors.nourl,$.jgrid.edit.bClose);
  4253. $($t).jqGrid("restoreCell",iRow,iCol);
  4254. } catch (e) {}
  4255. }
  4256. }
  4257. if ($t.p.cellsubmit === 'clientArray') {
  4258. $(cc).empty();
  4259. $($t).jqGrid("setCell",$t.rows[iRow].id,iCol, v2, false, false, true);
  4260. $(cc).addClass("dirty-cell");
  4261. $($t.rows[iRow]).addClass("edited");
  4262. $($t).triggerHandler("jqGridAfterSaveCell", [$t.rows[iRow].id, nm, v, iRow, iCol]);
  4263. if ($.isFunction($t.p.afterSaveCell)) {
  4264. $t.p.afterSaveCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
  4265. }
  4266. $t.p.savedRow.splice(0,1);
  4267. }
  4268. } else {
  4269. try {
  4270. window.setTimeout(function(){$.jgrid.info_dialog($.jgrid.errors.errcap,v+" "+cv[1],$.jgrid.edit.bClose);},100);
  4271. $($t).jqGrid("restoreCell",iRow,iCol);
  4272. } catch (e) {}
  4273. }
  4274. } else {
  4275. $($t).jqGrid("restoreCell",iRow,iCol);
  4276. }
  4277. }
  4278. window.setTimeout(function () { $("#"+$.jgrid.jqID($t.p.knv)).attr("tabindex","-1").focus();},0);
  4279. });
  4280. },
  4281. restoreCell : function(iRow, iCol) {
  4282. return this.each(function(){
  4283. var $t= this, fr;
  4284. if (!$t.grid || $t.p.cellEdit !== true ) {return;}
  4285. if ( $t.p.savedRow.length >= 1) {fr = 0;} else {fr=null;}
  4286. if(fr !== null) {
  4287. var cc = $("td:eq("+iCol+")",$t.rows[iRow]);
  4288. // datepicker fix
  4289. if($.isFunction($.fn.datepicker)) {
  4290. try {
  4291. $("input.hasDatepicker",cc).datepicker('hide');
  4292. } catch (e) {}
  4293. }
  4294. $(cc).empty().attr("tabindex","-1");
  4295. $($t).jqGrid("setCell",$t.rows[iRow].id, iCol, $t.p.savedRow[fr].v, false, false, true);
  4296. $($t).triggerHandler("jqGridAfterRestoreCell", [$t.rows[iRow].id, $t.p.savedRow[fr].v, iRow, iCol]);
  4297. if ($.isFunction($t.p.afterRestoreCell)) {
  4298. $t.p.afterRestoreCell.call($t, $t.rows[iRow].id, $t.p.savedRow[fr].v, iRow, iCol);
  4299. }
  4300. $t.p.savedRow.splice(0,1);
  4301. }
  4302. window.setTimeout(function () { $("#"+$t.p.knv).attr("tabindex","-1").focus();},0);
  4303. });
  4304. },
  4305. nextCell : function (iRow,iCol) {
  4306. return this.each(function (){
  4307. var $t = this, nCol=false, i;
  4308. if (!$t.grid || $t.p.cellEdit !== true) {return;}
  4309. // try to find next editable cell
  4310. for (i=iCol+1; i<$t.p.colModel.length; i++) {
  4311. if ( $t.p.colModel[i].editable ===true) {
  4312. nCol = i; break;
  4313. }
  4314. }
  4315. if(nCol !== false) {
  4316. $($t).jqGrid("editCell",iRow,nCol,true);
  4317. } else {
  4318. if ($t.p.savedRow.length >0) {
  4319. $($t).jqGrid("saveCell",iRow,iCol);
  4320. }
  4321. }
  4322. });
  4323. },
  4324. prevCell : function (iRow,iCol) {
  4325. return this.each(function (){
  4326. var $t = this, nCol=false, i;
  4327. if (!$t.grid || $t.p.cellEdit !== true) {return;}
  4328. // try to find next editable cell
  4329. for (i=iCol-1; i>=0; i--) {
  4330. if ( $t.p.colModel[i].editable ===true) {
  4331. nCol = i; break;
  4332. }
  4333. }
  4334. if(nCol !== false) {
  4335. $($t).jqGrid("editCell",iRow,nCol,true);
  4336. } else {
  4337. if ($t.p.savedRow.length >0) {
  4338. $($t).jqGrid("saveCell",iRow,iCol);
  4339. }
  4340. }
  4341. });
  4342. },
  4343. GridNav : function() {
  4344. return this.each(function () {
  4345. var $t = this;
  4346. if (!$t.grid || $t.p.cellEdit !== true ) {return;}
  4347. // trick to process keydown on non input elements
  4348. $t.p.knv = $t.p.id + "_kn";
  4349. 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>"),
  4350. i, kdir;
  4351. function scrollGrid(iR, iC, tp){
  4352. if (tp.substr(0,1)==='v') {
  4353. var ch = $($t.grid.bDiv)[0].clientHeight,
  4354. st = $($t.grid.bDiv)[0].scrollTop,
  4355. nROT = $t.rows[iR].offsetTop+$t.rows[iR].clientHeight,
  4356. pROT = $t.rows[iR].offsetTop;
  4357. if(tp === 'vd') {
  4358. if(nROT >= ch) {
  4359. $($t.grid.bDiv)[0].scrollTop = $($t.grid.bDiv)[0].scrollTop + $t.rows[iR].clientHeight;
  4360. }
  4361. }
  4362. if(tp === 'vu'){
  4363. if (pROT < st ) {
  4364. $($t.grid.bDiv)[0].scrollTop = $($t.grid.bDiv)[0].scrollTop - $t.rows[iR].clientHeight;
  4365. }
  4366. }
  4367. }
  4368. if(tp==='h') {
  4369. var cw = $($t.grid.bDiv)[0].clientWidth,
  4370. sl = $($t.grid.bDiv)[0].scrollLeft,
  4371. nCOL = $t.rows[iR].cells[iC].offsetLeft+$t.rows[iR].cells[iC].clientWidth,
  4372. pCOL = $t.rows[iR].cells[iC].offsetLeft;
  4373. if(nCOL >= cw+parseInt(sl,10)) {
  4374. $($t.grid.bDiv)[0].scrollLeft = $($t.grid.bDiv)[0].scrollLeft + $t.rows[iR].cells[iC].clientWidth;
  4375. } else if (pCOL < sl) {
  4376. $($t.grid.bDiv)[0].scrollLeft = $($t.grid.bDiv)[0].scrollLeft - $t.rows[iR].cells[iC].clientWidth;
  4377. }
  4378. }
  4379. }
  4380. function findNextVisible(iC,act){
  4381. var ind, i;
  4382. if(act === 'lft') {
  4383. ind = iC+1;
  4384. for (i=iC;i>=0;i--){
  4385. if ($t.p.colModel[i].hidden !== true) {
  4386. ind = i;
  4387. break;
  4388. }
  4389. }
  4390. }
  4391. if(act === 'rgt') {
  4392. ind = iC-1;
  4393. for (i=iC; i<$t.p.colModel.length;i++){
  4394. if ($t.p.colModel[i].hidden !== true) {
  4395. ind = i;
  4396. break;
  4397. }
  4398. }
  4399. }
  4400. return ind;
  4401. }
  4402. $(selection).insertBefore($t.grid.cDiv);
  4403. $("#"+$t.p.knv)
  4404. .focus()
  4405. .keydown(function (e){
  4406. kdir = e.keyCode;
  4407. if($t.p.direction === "rtl") {
  4408. if(kdir===37) { kdir = 39;}
  4409. else if (kdir===39) { kdir = 37; }
  4410. }
  4411. switch (kdir) {
  4412. case 38:
  4413. if ($t.p.iRow-1 >0 ) {
  4414. scrollGrid($t.p.iRow-1,$t.p.iCol,'vu');
  4415. $($t).jqGrid("editCell",$t.p.iRow-1,$t.p.iCol,false);
  4416. }
  4417. break;
  4418. case 40 :
  4419. if ($t.p.iRow+1 <= $t.rows.length-1) {
  4420. scrollGrid($t.p.iRow+1,$t.p.iCol,'vd');
  4421. $($t).jqGrid("editCell",$t.p.iRow+1,$t.p.iCol,false);
  4422. }
  4423. break;
  4424. case 37 :
  4425. if ($t.p.iCol -1 >= 0) {
  4426. i = findNextVisible($t.p.iCol-1,'lft');
  4427. scrollGrid($t.p.iRow, i,'h');
  4428. $($t).jqGrid("editCell",$t.p.iRow, i,false);
  4429. }
  4430. break;
  4431. case 39 :
  4432. if ($t.p.iCol +1 <= $t.p.colModel.length-1) {
  4433. i = findNextVisible($t.p.iCol+1,'rgt');
  4434. scrollGrid($t.p.iRow,i,'h');
  4435. $($t).jqGrid("editCell",$t.p.iRow,i,false);
  4436. }
  4437. break;
  4438. case 13:
  4439. if (parseInt($t.p.iCol,10)>=0 && parseInt($t.p.iRow,10)>=0) {
  4440. $($t).jqGrid("editCell",$t.p.iRow,$t.p.iCol,true);
  4441. }
  4442. break;
  4443. default :
  4444. return true;
  4445. }
  4446. return false;
  4447. });
  4448. });
  4449. },
  4450. getChangedCells : function (mthd) {
  4451. var ret=[];
  4452. if (!mthd) {mthd='all';}
  4453. this.each(function(){
  4454. var $t= this,nm;
  4455. if (!$t.grid || $t.p.cellEdit !== true ) {return;}
  4456. $($t.rows).each(function(j){
  4457. var res = {};
  4458. if ($(this).hasClass("edited")) {
  4459. $('td',this).each( function(i) {
  4460. nm = $t.p.colModel[i].name;
  4461. if ( nm !== 'cb' && nm !== 'subgrid') {
  4462. if (mthd==='dirty') {
  4463. if ($(this).hasClass('dirty-cell')) {
  4464. try {
  4465. res[nm] = $.unformat.call($t,this,{rowId:$t.rows[j].id, colModel:$t.p.colModel[i]},i);
  4466. } catch (e){
  4467. res[nm] = $.jgrid.htmlDecode($(this).html());
  4468. }
  4469. }
  4470. } else {
  4471. try {
  4472. res[nm] = $.unformat.call($t,this,{rowId:$t.rows[j].id,colModel:$t.p.colModel[i]},i);
  4473. } catch (e) {
  4474. res[nm] = $.jgrid.htmlDecode($(this).html());
  4475. }
  4476. }
  4477. }
  4478. });
  4479. res.id = this.id;
  4480. ret.push(res);
  4481. }
  4482. });
  4483. });
  4484. return ret;
  4485. }
  4486. /// end cell editing
  4487. });
  4488. })(jQuery);
  4489. /*jshint eqeqeq:false */
  4490. /*global jQuery */
  4491. (function($){
  4492. /*
  4493. * jqGrid common function
  4494. * Tony Tomov tony@trirand.com
  4495. * http://trirand.com/blog/
  4496. * Dual licensed under the MIT and GPL licenses:
  4497. * http://www.opensource.org/licenses/mit-license.php
  4498. * http://www.gnu.org/licenses/gpl-2.0.html
  4499. */
  4500. "use strict";
  4501. $.extend($.jgrid,{
  4502. // Modal functions
  4503. showModal : function(h) {
  4504. h.w.show();
  4505. },
  4506. closeModal : function(h) {
  4507. h.w.hide().attr("aria-hidden","true");
  4508. if(h.o) {h.o.remove();}
  4509. },
  4510. hideModal : function (selector,o) {
  4511. o = $.extend({jqm : true, gb :'', removemodal: false, formprop: false, form : ''}, o || {});
  4512. var thisgrid = o.gb && typeof o.gb === "string" && o.gb.substr(0,6) === "#gbox_" ? $("#" + o.gb.substr(6))[0] : false;
  4513. if(o.onClose) {
  4514. var oncret = thisgrid ? o.onClose.call(thisgrid, selector) : o.onClose(selector);
  4515. if (typeof oncret === 'boolean' && !oncret ) { return; }
  4516. }
  4517. if( o.formprop && thisgrid && o.form) {
  4518. var fh = $(selector)[0].style.height;
  4519. if(fh.indexOf("px") > -1 ) {
  4520. fh = parseFloat(fh);
  4521. }
  4522. var frmgr, frmdata;
  4523. if(o.form==='edit'){
  4524. frmgr = '#' +$.jgrid.jqID("FrmGrid_"+ o.gb.substr(6));
  4525. frmdata = "formProp";
  4526. } else if( o.form === 'view') {
  4527. frmgr = '#' +$.jgrid.jqID("ViewGrid_"+ o.gb.substr(6));
  4528. frmdata = "viewProp";
  4529. }
  4530. $(thisgrid).data(frmdata, {
  4531. top:parseFloat($(selector).css("top")),
  4532. left : parseFloat($(selector).css("left")),
  4533. width : $(selector).width(),
  4534. height : fh,
  4535. dataheight : $(frmgr).height(),
  4536. datawidth: $(frmgr).width()
  4537. });
  4538. }
  4539. if ($.fn.jqm && o.jqm === true) {
  4540. $(selector).attr("aria-hidden","true").jqmHide();
  4541. } else {
  4542. if(o.gb !== '') {
  4543. try {$(".jqgrid-overlay:first",o.gb).hide();} catch (e){}
  4544. }
  4545. $(selector).hide().attr("aria-hidden","true");
  4546. }
  4547. if( o.removemodal ) {
  4548. $(selector).remove();
  4549. }
  4550. },
  4551. //Helper functions
  4552. findPos : function(obj) {
  4553. var curleft = 0, curtop = 0;
  4554. if (obj.offsetParent) {
  4555. do {
  4556. curleft += obj.offsetLeft;
  4557. curtop += obj.offsetTop;
  4558. } while (obj = obj.offsetParent);
  4559. //do not change obj == obj.offsetParent
  4560. }
  4561. return [curleft,curtop];
  4562. },
  4563. createModal : function(aIDs, content, p, insertSelector, posSelector, appendsel, css) {
  4564. p = $.extend(true, {}, $.jgrid.jqModal || {}, p);
  4565. var mw = document.createElement('div'), rtlsup, self = this;
  4566. css = $.extend({}, css || {});
  4567. rtlsup = $(p.gbox).attr("dir") === "rtl" ? true : false;
  4568. mw.className= "ui-widget ui-widget-content ui-corner-all ui-jqdialog";
  4569. mw.id = aIDs.themodal;
  4570. var mh = document.createElement('div');
  4571. mh.className = "ui-jqdialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix";
  4572. mh.id = aIDs.modalhead;
  4573. $(mh).append("<span class='ui-jqdialog-title'>"+p.caption+"</span>");
  4574. var ahr= $("<a class='ui-jqdialog-titlebar-close ui-corner-all'></a>")
  4575. .hover(function(){ahr.addClass('ui-state-hover');},
  4576. function(){ahr.removeClass('ui-state-hover');})
  4577. .append("<span class='ui-icon ui-icon-closethick'></span>");
  4578. $(mh).append(ahr);
  4579. if(rtlsup) {
  4580. mw.dir = "rtl";
  4581. $(".ui-jqdialog-title",mh).css("float","right");
  4582. $(".ui-jqdialog-titlebar-close",mh).css("left",0.3+"em");
  4583. } else {
  4584. mw.dir = "ltr";
  4585. $(".ui-jqdialog-title",mh).css("float","left");
  4586. $(".ui-jqdialog-titlebar-close",mh).css("right",0.3+"em");
  4587. }
  4588. var mc = document.createElement('div');
  4589. $(mc).addClass("ui-jqdialog-content ui-widget-content").attr("id",aIDs.modalcontent);
  4590. $(mc).append(content);
  4591. mw.appendChild(mc);
  4592. $(mw).prepend(mh);
  4593. if(appendsel===true) { $('body').append(mw); } //append as first child in body -for alert dialog
  4594. else if (typeof appendsel === "string") {
  4595. $(appendsel).append(mw);
  4596. } else {$(mw).insertBefore(insertSelector);}
  4597. $(mw).css(css);
  4598. if(p.jqModal === undefined) {p.jqModal = true;} // internal use
  4599. var coord = {};
  4600. if ( $.fn.jqm && p.jqModal === true) {
  4601. if(p.left ===0 && p.top===0 && p.overlay) {
  4602. var pos = [];
  4603. pos = $.jgrid.findPos(posSelector);
  4604. p.left = pos[0] + 4;
  4605. p.top = pos[1] + 4;
  4606. }
  4607. coord.top = p.top+"px";
  4608. coord.left = p.left;
  4609. } else if(p.left !==0 || p.top!==0) {
  4610. coord.left = p.left;
  4611. coord.top = p.top+"px";
  4612. }
  4613. $("a.ui-jqdialog-titlebar-close",mh).click(function(){
  4614. var oncm = $("#"+$.jgrid.jqID(aIDs.themodal)).data("onClose") || p.onClose;
  4615. var gboxclose = $("#"+$.jgrid.jqID(aIDs.themodal)).data("gbox") || p.gbox;
  4616. self.hideModal("#"+$.jgrid.jqID(aIDs.themodal),{gb:gboxclose,jqm:p.jqModal,onClose:oncm, removemodal: p.removemodal || false, formprop : !p.recreateForm || false, form: p.form || ''});
  4617. return false;
  4618. });
  4619. if (p.width === 0 || !p.width) {p.width = 300;}
  4620. if(p.height === 0 || !p.height) {p.height =200;}
  4621. if(!p.zIndex) {
  4622. var parentZ = $(insertSelector).parents("*[role=dialog]").filter(':first').css("z-index");
  4623. if(parentZ) {
  4624. p.zIndex = parseInt(parentZ,10)+2;
  4625. } else {
  4626. p.zIndex = 950;
  4627. }
  4628. }
  4629. var rtlt = 0;
  4630. if( rtlsup && coord.left && !appendsel) {
  4631. rtlt = $(p.gbox).width()- (!isNaN(p.width) ? parseInt(p.width,10) :0) - 8; // to do
  4632. // just in case
  4633. coord.left = parseInt(coord.left,10) + parseInt(rtlt,10);
  4634. }
  4635. if(coord.left) { coord.left += "px"; }
  4636. $(mw).css($.extend({
  4637. width: isNaN(p.width) ? "auto": p.width+"px",
  4638. height:isNaN(p.height) ? "auto" : p.height + "px",
  4639. zIndex:p.zIndex,
  4640. overflow: 'hidden'
  4641. },coord))
  4642. .attr({tabIndex: "-1","role":"dialog","aria-labelledby":aIDs.modalhead,"aria-hidden":"true"});
  4643. if(p.drag === undefined) { p.drag=true;}
  4644. if(p.resize === undefined) {p.resize=true;}
  4645. if (p.drag) {
  4646. $(mh).css('cursor','move');
  4647. if($.fn.jqDrag) {
  4648. $(mw).jqDrag(mh);
  4649. } else {
  4650. try {
  4651. $(mw).draggable({handle: $("#"+$.jgrid.jqID(mh.id))});
  4652. } catch (e) {}
  4653. }
  4654. }
  4655. if(p.resize) {
  4656. if($.fn.jqResize) {
  4657. $(mw).append("<div class='jqResize ui-resizable-handle ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se'></div>");
  4658. $("#"+$.jgrid.jqID(aIDs.themodal)).jqResize(".jqResize",aIDs.scrollelm ? "#"+$.jgrid.jqID(aIDs.scrollelm) : false);
  4659. } else {
  4660. try {
  4661. $(mw).resizable({handles: 'se, sw',alsoResize: aIDs.scrollelm ? "#"+$.jgrid.jqID(aIDs.scrollelm) : false});
  4662. } catch (r) {}
  4663. }
  4664. }
  4665. if(p.closeOnEscape === true){
  4666. $(mw).keydown( function( e ) {
  4667. if( e.which === 27 ) {
  4668. var cone = $("#"+$.jgrid.jqID(aIDs.themodal)).data("onClose") || p.onClose;
  4669. self.hideModal("#"+$.jgrid.jqID(aIDs.themodal),{gb:p.gbox,jqm:p.jqModal,onClose: cone, removemodal: p.removemodal || false, formprop : !p.recreateForm || false, form: p.form || ''});
  4670. }
  4671. });
  4672. }
  4673. },
  4674. viewModal : function (selector,o){
  4675. o = $.extend({
  4676. toTop: true,
  4677. overlay: 10,
  4678. modal: false,
  4679. overlayClass : 'ui-widget-overlay',
  4680. onShow: $.jgrid.showModal,
  4681. onHide: $.jgrid.closeModal,
  4682. gbox: '',
  4683. jqm : true,
  4684. jqM : true
  4685. }, o || {});
  4686. if ($.fn.jqm && o.jqm === true) {
  4687. if(o.jqM) { $(selector).attr("aria-hidden","false").jqm(o).jqmShow(); }
  4688. else {$(selector).attr("aria-hidden","false").jqmShow();}
  4689. } else {
  4690. if(o.gbox !== '') {
  4691. $(".jqgrid-overlay:first",o.gbox).show();
  4692. $(selector).data("gbox",o.gbox);
  4693. }
  4694. $(selector).show().attr("aria-hidden","false");
  4695. try{$(':input:visible',selector)[0].focus();}catch(_){}
  4696. }
  4697. },
  4698. info_dialog : function(caption, content,c_b, modalopt) {
  4699. var mopt = {
  4700. width:290,
  4701. height:'auto',
  4702. dataheight: 'auto',
  4703. drag: true,
  4704. resize: false,
  4705. left:250,
  4706. top:170,
  4707. zIndex : 1000,
  4708. jqModal : true,
  4709. modal : false,
  4710. closeOnEscape : true,
  4711. align: 'center',
  4712. buttonalign : 'center',
  4713. buttons : []
  4714. // {text:'textbutt', id:"buttid", onClick : function(){...}}
  4715. // 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...
  4716. };
  4717. $.extend(true, mopt, $.jgrid.jqModal || {}, {caption:"<b>"+caption+"</b>"}, modalopt || {});
  4718. var jm = mopt.jqModal, self = this;
  4719. if($.fn.jqm && !jm) { jm = false; }
  4720. // in case there is no jqModal
  4721. var buttstr ="", i;
  4722. if(mopt.buttons.length > 0) {
  4723. for(i=0;i<mopt.buttons.length;i++) {
  4724. if(mopt.buttons[i].id === undefined) { mopt.buttons[i].id = "info_button_"+i; }
  4725. buttstr += "<a id='"+mopt.buttons[i].id+"' class='fm-button ui-state-default ui-corner-all'>"+mopt.buttons[i].text+"</a>";
  4726. }
  4727. }
  4728. var dh = isNaN(mopt.dataheight) ? mopt.dataheight : mopt.dataheight+"px",
  4729. cn = "text-align:"+mopt.align+";";
  4730. var cnt = "<div id='info_id'>";
  4731. cnt += "<div id='infocnt' style='margin:0px;padding-bottom:1em;width:100%;overflow:auto;position:relative;height:"+dh+";"+cn+"'>"+content+"</div>";
  4732. 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>" :
  4733. 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>" : "";
  4734. cnt += "</div>";
  4735. try {
  4736. if($("#info_dialog").attr("aria-hidden") === "false") {
  4737. $.jgrid.hideModal("#info_dialog",{jqm:jm});
  4738. }
  4739. $("#info_dialog").remove();
  4740. } catch (e){}
  4741. $.jgrid.createModal({
  4742. themodal:'info_dialog',
  4743. modalhead:'info_head',
  4744. modalcontent:'info_content',
  4745. scrollelm: 'infocnt'},
  4746. cnt,
  4747. mopt,
  4748. '','',true
  4749. );
  4750. // attach onclick after inserting into the dom
  4751. if(buttstr) {
  4752. $.each(mopt.buttons,function(i){
  4753. $("#"+$.jgrid.jqID(this.id),"#info_id").bind('click',function(){mopt.buttons[i].onClick.call($("#info_dialog")); return false;});
  4754. });
  4755. }
  4756. $("#closedialog", "#info_id").click(function(){
  4757. self.hideModal("#info_dialog",{
  4758. jqm:jm,
  4759. onClose: $("#info_dialog").data("onClose") || mopt.onClose,
  4760. gb: $("#info_dialog").data("gbox") || mopt.gbox
  4761. });
  4762. return false;
  4763. });
  4764. $(".fm-button","#info_dialog").hover(
  4765. function(){$(this).addClass('ui-state-hover');},
  4766. function(){$(this).removeClass('ui-state-hover');}
  4767. );
  4768. if($.isFunction(mopt.beforeOpen) ) { mopt.beforeOpen(); }
  4769. $.jgrid.viewModal("#info_dialog",{
  4770. onHide: function(h) {
  4771. h.w.hide().remove();
  4772. if(h.o) { h.o.remove(); }
  4773. },
  4774. modal :mopt.modal,
  4775. jqm:jm
  4776. });
  4777. if($.isFunction(mopt.afterOpen) ) { mopt.afterOpen(); }
  4778. try{ $("#info_dialog").focus();} catch (m){}
  4779. },
  4780. bindEv: function (el, opt) {
  4781. var $t = this;
  4782. if($.isFunction(opt.dataInit)) {
  4783. opt.dataInit.call($t,el,opt);
  4784. }
  4785. if(opt.dataEvents) {
  4786. $.each(opt.dataEvents, function() {
  4787. if (this.data !== undefined) {
  4788. $(el).bind(this.type, this.data, this.fn);
  4789. } else {
  4790. $(el).bind(this.type, this.fn);
  4791. }
  4792. });
  4793. }
  4794. },
  4795. // Form Functions
  4796. createEl : function(eltype,options,vl,autowidth, ajaxso) {
  4797. var elem = "", $t = this;
  4798. function setAttributes(elm, atr, exl ) {
  4799. var exclude = ['dataInit','dataEvents','dataUrl', 'buildSelect','sopt', 'searchhidden', 'defaultValue', 'attr', 'custom_element', 'custom_value'];
  4800. if(exl !== undefined && $.isArray(exl)) {
  4801. $.merge(exclude, exl);
  4802. }
  4803. $.each(atr, function(key, value){
  4804. if($.inArray(key, exclude) === -1) {
  4805. $(elm).attr(key,value);
  4806. }
  4807. });
  4808. if(!atr.hasOwnProperty('id')) {
  4809. $(elm).attr('id', $.jgrid.randId());
  4810. }
  4811. }
  4812. switch (eltype)
  4813. {
  4814. case "textarea" :
  4815. elem = document.createElement("textarea");
  4816. if(autowidth) {
  4817. if(!options.cols) { $(elem).css({width:"98%"});}
  4818. } else if (!options.cols) { options.cols = 20; }
  4819. if(!options.rows) { options.rows = 2; }
  4820. if(vl==='&nbsp;' || vl==='&#160;' || (vl.length===1 && vl.charCodeAt(0)===160)) {vl="";}
  4821. elem.value = vl;
  4822. setAttributes(elem, options);
  4823. $(elem).attr({"role":"textbox","multiline":"true"});
  4824. break;
  4825. case "checkbox" : //what code for simple checkbox
  4826. elem = document.createElement("input");
  4827. elem.type = "checkbox";
  4828. if( !options.value ) {
  4829. var vl1 = (vl+"").toLowerCase();
  4830. if(vl1.search(/(false|f|0|no|n|off|undefined)/i)<0 && vl1!=="") {
  4831. elem.checked=true;
  4832. elem.defaultChecked=true;
  4833. elem.value = vl;
  4834. } else {
  4835. elem.value = "on";
  4836. }
  4837. $(elem).attr("offval","off");
  4838. } else {
  4839. var cbval = options.value.split(":");
  4840. if(vl === cbval[0]) {
  4841. elem.checked=true;
  4842. elem.defaultChecked=true;
  4843. }
  4844. elem.value = cbval[0];
  4845. $(elem).attr("offval",cbval[1]);
  4846. }
  4847. setAttributes(elem, options, ['value']);
  4848. $(elem).attr("role","checkbox");
  4849. break;
  4850. case "select" :
  4851. elem = document.createElement("select");
  4852. elem.setAttribute("role","select");
  4853. var msl, ovm = [];
  4854. if(options.multiple===true) {
  4855. msl = true;
  4856. elem.multiple="multiple";
  4857. $(elem).attr("aria-multiselectable","true");
  4858. } else { msl = false; }
  4859. if(options.dataUrl !== undefined) {
  4860. var rowid = null, postData = options.postData || ajaxso.postData;
  4861. try {
  4862. rowid = options.rowId;
  4863. } catch(e) {}
  4864. if ($t.p && $t.p.idPrefix) {
  4865. rowid = $.jgrid.stripPref($t.p.idPrefix, rowid);
  4866. }
  4867. $.ajax($.extend({
  4868. url: $.isFunction(options.dataUrl) ? options.dataUrl.call($t, rowid, vl, String(options.name)) : options.dataUrl,
  4869. type : "GET",
  4870. dataType: "html",
  4871. data: $.isFunction(postData) ? postData.call($t, rowid, vl, String(options.name)) : postData,
  4872. context: {elem:elem, options:options, vl:vl},
  4873. success: function(data){
  4874. var ovm = [], elem = this.elem, vl = this.vl,
  4875. options = $.extend({},this.options),
  4876. msl = options.multiple===true,
  4877. a = $.isFunction(options.buildSelect) ? options.buildSelect.call($t,data) : data;
  4878. if(typeof a === 'string') {
  4879. a = $( $.trim( a ) ).html();
  4880. }
  4881. if(a) {
  4882. $(elem).append(a);
  4883. setAttributes(elem, options, postData ? ['postData'] : undefined );
  4884. if(options.size === undefined) { options.size = msl ? 3 : 1;}
  4885. if(msl) {
  4886. ovm = vl.split(",");
  4887. ovm = $.map(ovm,function(n){return $.trim(n);});
  4888. } else {
  4889. ovm[0] = $.trim(vl);
  4890. }
  4891. //$(elem).attr(options);
  4892. setTimeout(function(){
  4893. $("option",elem).each(function(i){
  4894. //if(i===0) { this.selected = ""; }
  4895. // fix IE8/IE7 problem with selecting of the first item on multiple=true
  4896. if (i === 0 && elem.multiple) { this.selected = false; }
  4897. $(this).attr("role","option");
  4898. if($.inArray($.trim($(this).text()),ovm) > -1 || $.inArray($.trim($(this).val()),ovm) > -1 ) {
  4899. this.selected= "selected";
  4900. }
  4901. });
  4902. },0);
  4903. }
  4904. }
  4905. },ajaxso || {}));
  4906. } else if(options.value) {
  4907. var i;
  4908. if(options.size === undefined) {
  4909. options.size = msl ? 3 : 1;
  4910. }
  4911. if(msl) {
  4912. ovm = vl.split(",");
  4913. ovm = $.map(ovm,function(n){return $.trim(n);});
  4914. }
  4915. if(typeof options.value === 'function') { options.value = options.value(); }
  4916. var so,sv, ov,
  4917. sep = options.separator === undefined ? ":" : options.separator,
  4918. delim = options.delimiter === undefined ? ";" : options.delimiter;
  4919. if(typeof options.value === 'string') {
  4920. so = options.value.split(delim);
  4921. for(i=0; i<so.length;i++){
  4922. sv = so[i].split(sep);
  4923. if(sv.length > 2 ) {
  4924. sv[1] = $.map(sv,function(n,ii){if(ii>0) { return n;} }).join(sep);
  4925. }
  4926. ov = document.createElement("option");
  4927. ov.setAttribute("role","option");
  4928. ov.value = sv[0]; ov.innerHTML = sv[1];
  4929. elem.appendChild(ov);
  4930. if (!msl && ($.trim(sv[0]) === $.trim(vl) || $.trim(sv[1]) === $.trim(vl))) { ov.selected ="selected"; }
  4931. if (msl && ($.inArray($.trim(sv[1]), ovm)>-1 || $.inArray($.trim(sv[0]), ovm)>-1)) {ov.selected ="selected";}
  4932. }
  4933. } else if (typeof options.value === 'object') {
  4934. var oSv = options.value, key;
  4935. for (key in oSv) {
  4936. if (oSv.hasOwnProperty(key ) ){
  4937. ov = document.createElement("option");
  4938. ov.setAttribute("role","option");
  4939. ov.value = key; ov.innerHTML = oSv[key];
  4940. elem.appendChild(ov);
  4941. if (!msl && ( $.trim(key) === $.trim(vl) || $.trim(oSv[key]) === $.trim(vl)) ) { ov.selected ="selected"; }
  4942. if (msl && ($.inArray($.trim(oSv[key]),ovm)>-1 || $.inArray($.trim(key),ovm)>-1)) { ov.selected ="selected"; }
  4943. }
  4944. }
  4945. }
  4946. setAttributes(elem, options, ['value']);
  4947. }
  4948. break;
  4949. case "text" :
  4950. case "password" :
  4951. case "button" :
  4952. var role;
  4953. if(eltype==="button") { role = "button"; }
  4954. else { role = "textbox"; }
  4955. elem = document.createElement("input");
  4956. elem.type = eltype;
  4957. elem.value = vl;
  4958. setAttributes(elem, options);
  4959. if(eltype !== "button"){
  4960. if(autowidth) {
  4961. if(!options.size) { $(elem).css({width:"98%"}); }
  4962. } else if (!options.size) { options.size = 20; }
  4963. }
  4964. $(elem).attr("role",role);
  4965. break;
  4966. case "image" :
  4967. case "file" :
  4968. elem = document.createElement("input");
  4969. elem.type = eltype;
  4970. setAttributes(elem, options);
  4971. break;
  4972. case "custom" :
  4973. elem = document.createElement("span");
  4974. try {
  4975. if($.isFunction(options.custom_element)) {
  4976. var celm = options.custom_element.call($t,vl,options);
  4977. if(celm) {
  4978. celm = $(celm).addClass("customelement").attr({id:options.id,name:options.name});
  4979. $(elem).empty().append(celm);
  4980. } else {
  4981. throw "e2";
  4982. }
  4983. } else {
  4984. throw "e1";
  4985. }
  4986. } catch (e) {
  4987. if (e==="e1") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_element' "+$.jgrid.edit.msg.nodefined, $.jgrid.edit.bClose);}
  4988. if (e==="e2") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_element' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose);}
  4989. else { $.jgrid.info_dialog($.jgrid.errors.errcap,typeof e==="string"?e:e.message,$.jgrid.edit.bClose); }
  4990. }
  4991. break;
  4992. }
  4993. return elem;
  4994. },
  4995. // Date Validation Javascript
  4996. checkDate : function (format, date) {
  4997. var daysInFebruary = function(year){
  4998. // February has 29 days in any year evenly divisible by four,
  4999. // EXCEPT for centurial years which are not also divisible by 400.
  5000. return (((year % 4 === 0) && ( year % 100 !== 0 || (year % 400 === 0))) ? 29 : 28 );
  5001. },
  5002. tsp = {}, sep;
  5003. format = format.toLowerCase();
  5004. //we search for /,-,. for the date separator
  5005. if(format.indexOf("/") !== -1) {
  5006. sep = "/";
  5007. } else if(format.indexOf("-") !== -1) {
  5008. sep = "-";
  5009. } else if(format.indexOf(".") !== -1) {
  5010. sep = ".";
  5011. } else {
  5012. sep = "/";
  5013. }
  5014. format = format.split(sep);
  5015. date = date.split(sep);
  5016. if (date.length !== 3) { return false; }
  5017. var j=-1,yln, dln=-1, mln=-1, i;
  5018. for(i=0;i<format.length;i++){
  5019. var dv = isNaN(date[i]) ? 0 : parseInt(date[i],10);
  5020. tsp[format[i]] = dv;
  5021. yln = format[i];
  5022. if(yln.indexOf("y") !== -1) { j=i; }
  5023. if(yln.indexOf("m") !== -1) { mln=i; }
  5024. if(yln.indexOf("d") !== -1) { dln=i; }
  5025. }
  5026. if (format[j] === "y" || format[j] === "yyyy") {
  5027. yln=4;
  5028. } else if(format[j] ==="yy"){
  5029. yln = 2;
  5030. } else {
  5031. yln = -1;
  5032. }
  5033. var daysInMonth = [0,31,29,31,30,31,30,31,31,30,31,30,31],
  5034. strDate;
  5035. if (j === -1) {
  5036. return false;
  5037. }
  5038. strDate = tsp[format[j]].toString();
  5039. if(yln === 2 && strDate.length === 1) {yln = 1;}
  5040. if (strDate.length !== yln || (tsp[format[j]]===0 && date[j]!=="00")){
  5041. return false;
  5042. }
  5043. if(mln === -1) {
  5044. return false;
  5045. }
  5046. strDate = tsp[format[mln]].toString();
  5047. if (strDate.length<1 || tsp[format[mln]]<1 || tsp[format[mln]]>12){
  5048. return false;
  5049. }
  5050. if(dln === -1) {
  5051. return false;
  5052. }
  5053. strDate = tsp[format[dln]].toString();
  5054. 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]]]){
  5055. return false;
  5056. }
  5057. return true;
  5058. },
  5059. isEmpty : function(val)
  5060. {
  5061. if (val.match(/^\s+$/) || val === "") {
  5062. return true;
  5063. }
  5064. return false;
  5065. },
  5066. checkTime : function(time){
  5067. // checks only hh:ss (and optional am/pm)
  5068. var re = /^(\d{1,2}):(\d{2})([apAP][Mm])?$/,regs;
  5069. if(!$.jgrid.isEmpty(time))
  5070. {
  5071. regs = time.match(re);
  5072. if(regs) {
  5073. if(regs[3]) {
  5074. if(regs[1] < 1 || regs[1] > 12) { return false; }
  5075. } else {
  5076. if(regs[1] > 23) { return false; }
  5077. }
  5078. if(regs[2] > 59) {
  5079. return false;
  5080. }
  5081. } else {
  5082. return false;
  5083. }
  5084. }
  5085. return true;
  5086. },
  5087. checkValues : function(val, valref, customobject, nam) {
  5088. var edtrul,i, nm, dft, len, g = this, cm = g.p.colModel;
  5089. if(customobject === undefined) {
  5090. if(typeof valref==='string'){
  5091. for( i =0, len=cm.length;i<len; i++){
  5092. if(cm[i].name===valref) {
  5093. edtrul = cm[i].editrules;
  5094. valref = i;
  5095. if(cm[i].formoptions != null) { nm = cm[i].formoptions.label; }
  5096. break;
  5097. }
  5098. }
  5099. } else if(valref >=0) {
  5100. edtrul = cm[valref].editrules;
  5101. }
  5102. } else {
  5103. edtrul = customobject;
  5104. nm = nam===undefined ? "_" : nam;
  5105. }
  5106. if(edtrul) {
  5107. if(!nm) { nm = g.p.colNames != null ? g.p.colNames[valref] : cm[valref].label; }
  5108. if(edtrul.required === true) {
  5109. if( $.jgrid.isEmpty(val) ) { return [false,nm+": "+$.jgrid.edit.msg.required,""]; }
  5110. }
  5111. // force required
  5112. var rqfield = edtrul.required === false ? false : true;
  5113. if(edtrul.number === true) {
  5114. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  5115. if(isNaN(val)) { return [false,nm+": "+$.jgrid.edit.msg.number,""]; }
  5116. }
  5117. }
  5118. if(edtrul.minValue !== undefined && !isNaN(edtrul.minValue)) {
  5119. if (parseFloat(val) < parseFloat(edtrul.minValue) ) { return [false,nm+": "+$.jgrid.edit.msg.minValue+" "+edtrul.minValue,""];}
  5120. }
  5121. if(edtrul.maxValue !== undefined && !isNaN(edtrul.maxValue)) {
  5122. if (parseFloat(val) > parseFloat(edtrul.maxValue) ) { return [false,nm+": "+$.jgrid.edit.msg.maxValue+" "+edtrul.maxValue,""];}
  5123. }
  5124. var filter;
  5125. if(edtrul.email === true) {
  5126. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  5127. // taken from $ Validate plugin
  5128. 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;
  5129. if(!filter.test(val)) {return [false,nm+": "+$.jgrid.edit.msg.email,""];}
  5130. }
  5131. }
  5132. if(edtrul.integer === true) {
  5133. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  5134. if(isNaN(val)) { return [false,nm+": "+$.jgrid.edit.msg.integer,""]; }
  5135. if ((val % 1 !== 0) || (val.indexOf('.') !== -1)) { return [false,nm+": "+$.jgrid.edit.msg.integer,""];}
  5136. }
  5137. }
  5138. if(edtrul.date === true) {
  5139. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  5140. if(cm[valref].formatoptions && cm[valref].formatoptions.newformat) {
  5141. dft = cm[valref].formatoptions.newformat;
  5142. if( $.jgrid.formatter.date.masks.hasOwnProperty(dft) ) {
  5143. dft = $.jgrid.formatter.date.masks[dft];
  5144. }
  5145. } else {
  5146. dft = cm[valref].datefmt || "Y-m-d";
  5147. }
  5148. if(!$.jgrid.checkDate (dft, val)) { return [false,nm+": "+$.jgrid.edit.msg.date+" - "+dft,""]; }
  5149. }
  5150. }
  5151. if(edtrul.time === true) {
  5152. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  5153. if(!$.jgrid.checkTime (val)) { return [false,nm+": "+$.jgrid.edit.msg.date+" - hh:mm (am/pm)",""]; }
  5154. }
  5155. }
  5156. if(edtrul.url === true) {
  5157. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  5158. filter = /^(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
  5159. if(!filter.test(val)) {return [false,nm+": "+$.jgrid.edit.msg.url,""];}
  5160. }
  5161. }
  5162. if(edtrul.custom === true) {
  5163. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  5164. if($.isFunction(edtrul.custom_func)) {
  5165. var ret = edtrul.custom_func.call(g,val,nm,valref);
  5166. return $.isArray(ret) ? ret : [false,$.jgrid.edit.msg.customarray,""];
  5167. }
  5168. return [false,$.jgrid.edit.msg.customfcheck,""];
  5169. }
  5170. }
  5171. }
  5172. return [true,"",""];
  5173. }
  5174. });
  5175. })(jQuery);
  5176. /*jshint eqeqeq:false */
  5177. /*global jQuery */
  5178. (function($){
  5179. /**
  5180. * jqGrid extension for custom methods
  5181. * Tony Tomov tony@trirand.com
  5182. * http://trirand.com/blog/
  5183. *
  5184. * Wildraid wildraid@mail.ru
  5185. * Oleg Kiriljuk oleg.kiriljuk@ok-soft-gmbh.com
  5186. * Dual licensed under the MIT and GPL licenses:
  5187. * http://www.opensource.org/licenses/mit-license.php
  5188. * http://www.gnu.org/licenses/gpl-2.0.html
  5189. **/
  5190. "use strict";
  5191. $.jgrid.extend({
  5192. getColProp : function(colname){
  5193. var ret ={}, $t = this[0];
  5194. if ( !$t.grid ) { return false; }
  5195. var cM = $t.p.colModel, i;
  5196. for ( i=0;i<cM.length;i++ ) {
  5197. if ( cM[i].name === colname ) {
  5198. ret = cM[i];
  5199. break;
  5200. }
  5201. }
  5202. return ret;
  5203. },
  5204. setColProp : function(colname, obj){
  5205. //do not set width will not work
  5206. return this.each(function(){
  5207. if ( this.grid ) {
  5208. if ( obj ) {
  5209. var cM = this.p.colModel, i;
  5210. for ( i=0;i<cM.length;i++ ) {
  5211. if ( cM[i].name === colname ) {
  5212. $.extend(true, this.p.colModel[i],obj);
  5213. break;
  5214. }
  5215. }
  5216. }
  5217. }
  5218. });
  5219. },
  5220. sortGrid : function(colname,reload, sor){
  5221. return this.each(function(){
  5222. var $t=this,idx=-1,i, sobj=false;
  5223. if ( !$t.grid ) { return;}
  5224. if ( !colname ) { colname = $t.p.sortname; }
  5225. for ( i=0;i<$t.p.colModel.length;i++ ) {
  5226. if ( $t.p.colModel[i].index === colname || $t.p.colModel[i].name === colname ) {
  5227. idx = i;
  5228. if($t.p.frozenColumns === true && $t.p.colModel[i].frozen === true) {
  5229. sobj = $t.grid.fhDiv.find("#" + $t.p.id + "_" + colname);
  5230. }
  5231. break;
  5232. }
  5233. }
  5234. if ( idx !== -1 ){
  5235. var sort = $t.p.colModel[idx].sortable;
  5236. if(!sobj) {
  5237. sobj = $t.grid.headers[idx].el;
  5238. }
  5239. if ( typeof sort !== 'boolean' ) { sort = true; }
  5240. if ( typeof reload !=='boolean' ) { reload = false; }
  5241. if ( sort ) { $t.sortData("jqgh_"+$t.p.id+"_" + colname, idx, reload, sor, sobj); }
  5242. }
  5243. });
  5244. },
  5245. clearBeforeUnload : function () {
  5246. return this.each(function(){
  5247. var grid = this.grid;
  5248. if ($.isFunction(grid.emptyRows)) {
  5249. grid.emptyRows.call(this, true, true); // this work quick enough and reduce the size of memory leaks if we have someone
  5250. }
  5251. $(document).unbind("mouseup.jqGrid" + this.p.id );
  5252. $(grid.hDiv).unbind("mousemove"); // TODO add namespace
  5253. $(this).unbind();
  5254. grid.dragEnd = null;
  5255. grid.dragMove = null;
  5256. grid.dragStart = null;
  5257. grid.emptyRows = null;
  5258. grid.populate = null;
  5259. grid.populateVisible = null;
  5260. grid.scrollGrid = null;
  5261. grid.selectionPreserver = null;
  5262. grid.bDiv = null;
  5263. grid.cDiv = null;
  5264. grid.hDiv = null;
  5265. grid.cols = null;
  5266. var i, l = grid.headers.length;
  5267. for (i = 0; i < l; i++) {
  5268. grid.headers[i].el = null;
  5269. }
  5270. this.formatCol = null;
  5271. this.sortData = null;
  5272. this.updatepager = null;
  5273. this.refreshIndex = null;
  5274. this.setHeadCheckBox = null;
  5275. this.constructTr = null;
  5276. this.formatter = null;
  5277. this.addXmlData = null;
  5278. this.addJSONData = null;
  5279. this.grid = null;
  5280. });
  5281. },
  5282. GridDestroy : function () {
  5283. return this.each(function(){
  5284. if ( this.grid ) {
  5285. if ( this.p.pager ) { // if not part of grid
  5286. $(this.p.pager).remove();
  5287. }
  5288. try {
  5289. $(this).jqGrid('clearBeforeUnload');
  5290. $("#gbox_"+$.jgrid.jqID(this.id)).remove();
  5291. $("#alertmod_"+$.jgrid.jqID(this.id)).remove();
  5292. } catch (_) {}
  5293. }
  5294. });
  5295. },
  5296. GridUnload : function(){
  5297. return this.each(function(){
  5298. if ( !this.grid ) {return;}
  5299. var defgrid = {id: $(this).attr('id'),cl: $(this).attr('class')};
  5300. if (this.p.pager) {
  5301. $(this.p.pager).empty().removeClass("ui-state-default ui-jqgrid-pager ui-corner-bottom");
  5302. }
  5303. var newtable = document.createElement('table');
  5304. $(newtable).attr({id:defgrid.id});
  5305. newtable.className = defgrid.cl;
  5306. var gid = $.jgrid.jqID(this.id);
  5307. $(newtable).removeClass("ui-jqgrid-btable");
  5308. if( $(this.p.pager).parents("#gbox_"+gid).length === 1 ) {
  5309. $(newtable).insertBefore("#gbox_"+gid).show();
  5310. $(this.p.pager).insertBefore("#gbox_"+gid);
  5311. } else {
  5312. $(newtable).insertBefore("#gbox_"+gid).show();
  5313. }
  5314. $(this).jqGrid('clearBeforeUnload');
  5315. $("#gbox_"+gid).remove();
  5316. });
  5317. },
  5318. setGridState : function(state) {
  5319. return this.each(function(){
  5320. if ( !this.grid ) {return;}
  5321. var $t = this;
  5322. if(state === 'hidden'){
  5323. $(".ui-jqgrid-bdiv, .ui-jqgrid-hdiv","#gview_"+$.jgrid.jqID($t.p.id)).slideUp("fast");
  5324. if($t.p.pager) {$($t.p.pager).slideUp("fast");}
  5325. if($t.p.toppager) {$($t.p.toppager).slideUp("fast");}
  5326. if($t.p.toolbar[0]===true) {
  5327. if( $t.p.toolbar[1] === 'both') {
  5328. $($t.grid.ubDiv).slideUp("fast");
  5329. }
  5330. $($t.grid.uDiv).slideUp("fast");
  5331. }
  5332. if($t.p.footerrow) { $(".ui-jqgrid-sdiv","#gbox_"+$.jgrid.jqID($t.p.id)).slideUp("fast"); }
  5333. $(".ui-jqgrid-titlebar-close span",$t.grid.cDiv).removeClass("ui-icon-circle-triangle-n").addClass("ui-icon-circle-triangle-s");
  5334. $t.p.gridstate = 'hidden';
  5335. } else if(state === 'visible') {
  5336. $(".ui-jqgrid-hdiv, .ui-jqgrid-bdiv","#gview_"+$.jgrid.jqID($t.p.id)).slideDown("fast");
  5337. if($t.p.pager) {$($t.p.pager).slideDown("fast");}
  5338. if($t.p.toppager) {$($t.p.toppager).slideDown("fast");}
  5339. if($t.p.toolbar[0]===true) {
  5340. if( $t.p.toolbar[1] === 'both') {
  5341. $($t.grid.ubDiv).slideDown("fast");
  5342. }
  5343. $($t.grid.uDiv).slideDown("fast");
  5344. }
  5345. if($t.p.footerrow) { $(".ui-jqgrid-sdiv","#gbox_"+$.jgrid.jqID($t.p.id)).slideDown("fast"); }
  5346. $(".ui-jqgrid-titlebar-close span",$t.grid.cDiv).removeClass("ui-icon-circle-triangle-s").addClass("ui-icon-circle-triangle-n");
  5347. $t.p.gridstate = 'visible';
  5348. }
  5349. });
  5350. },
  5351. filterToolbar : function(p){
  5352. p = $.extend({
  5353. autosearch: true,
  5354. autosearchDelay: 500,
  5355. searchOnEnter : true,
  5356. beforeSearch: null,
  5357. afterSearch: null,
  5358. beforeClear: null,
  5359. afterClear: null,
  5360. searchurl : '',
  5361. stringResult: false,
  5362. groupOp: 'AND',
  5363. defaultSearch : "bw",
  5364. searchOperators : false,
  5365. resetIcon : "x",
  5366. operands : { "eq" :"==", "ne":"!","lt":"<","le":"<=","gt":">","ge":">=","bw":"^","bn":"!^","in":"=","ni":"!=","ew":"|","en":"!@","cn":"~","nc":"!~","nu":"#","nn":"!#"}
  5367. }, $.jgrid.search , p || {});
  5368. return this.each(function(){
  5369. var $t = this;
  5370. if(this.ftoolbar) { return; }
  5371. var triggerToolbar = function() {
  5372. var sdata={}, j=0, v, nm, sopt={},so;
  5373. $.each($t.p.colModel,function(){
  5374. var $elem = $("#gs_"+$.jgrid.jqID(this.name), (this.frozen===true && $t.p.frozenColumns === true) ? $t.grid.fhDiv : $t.grid.hDiv);
  5375. nm = this.index || this.name;
  5376. if(p.searchOperators ) {
  5377. so = $elem.parent().prev().children("a").attr("soper") || p.defaultSearch;
  5378. } else {
  5379. so = (this.searchoptions && this.searchoptions.sopt) ? this.searchoptions.sopt[0] : this.stype==='select'? 'eq' : p.defaultSearch;
  5380. }
  5381. v = this.stype === "custom" && $.isFunction(this.searchoptions.custom_value) && $elem.length > 0 && $elem[0].nodeName.toUpperCase() === "SPAN" ?
  5382. this.searchoptions.custom_value.call($t, $elem.children(".customelement:first"), "get") :
  5383. $elem.val();
  5384. if(v || so==="nu" || so==="nn") {
  5385. sdata[nm] = v;
  5386. sopt[nm] = so;
  5387. j++;
  5388. } else {
  5389. try {
  5390. delete $t.p.postData[nm];
  5391. } catch (z) {}
  5392. }
  5393. });
  5394. var sd = j>0 ? true : false;
  5395. if(p.stringResult === true || $t.p.datatype === "local" || p.searchOperators === true) {
  5396. var ruleGroup = "{\"groupOp\":\"" + p.groupOp + "\",\"rules\":[";
  5397. var gi=0;
  5398. $.each(sdata,function(i,n){
  5399. if (gi > 0) {ruleGroup += ",";}
  5400. ruleGroup += "{\"field\":\"" + i + "\",";
  5401. ruleGroup += "\"op\":\"" + sopt[i] + "\",";
  5402. n+="";
  5403. ruleGroup += "\"data\":\"" + n.replace(/\\/g,'\\\\').replace(/\"/g,'\\"') + "\"}";
  5404. gi++;
  5405. });
  5406. ruleGroup += "]}";
  5407. $.extend($t.p.postData,{filters:ruleGroup});
  5408. $.each(['searchField', 'searchString', 'searchOper'], function(i, n){
  5409. if($t.p.postData.hasOwnProperty(n)) { delete $t.p.postData[n];}
  5410. });
  5411. } else {
  5412. $.extend($t.p.postData,sdata);
  5413. }
  5414. var saveurl;
  5415. if($t.p.searchurl) {
  5416. saveurl = $t.p.url;
  5417. $($t).jqGrid("setGridParam",{url:$t.p.searchurl});
  5418. }
  5419. var bsr = $($t).triggerHandler("jqGridToolbarBeforeSearch") === 'stop' ? true : false;
  5420. if(!bsr && $.isFunction(p.beforeSearch)){bsr = p.beforeSearch.call($t);}
  5421. if(!bsr) { $($t).jqGrid("setGridParam",{search:sd}).trigger("reloadGrid",[{page:1}]); }
  5422. if(saveurl) {$($t).jqGrid("setGridParam",{url:saveurl});}
  5423. $($t).triggerHandler("jqGridToolbarAfterSearch");
  5424. if($.isFunction(p.afterSearch)){p.afterSearch.call($t);}
  5425. },
  5426. clearToolbar = function(trigger){
  5427. var sdata={}, j=0, nm;
  5428. trigger = (typeof trigger !== 'boolean') ? true : trigger;
  5429. $.each($t.p.colModel,function(){
  5430. var v, $elem = $("#gs_"+$.jgrid.jqID(this.name),(this.frozen===true && $t.p.frozenColumns === true) ? $t.grid.fhDiv : $t.grid.hDiv);
  5431. if(this.searchoptions && this.searchoptions.defaultValue !== undefined) { v = this.searchoptions.defaultValue; }
  5432. nm = this.index || this.name;
  5433. switch (this.stype) {
  5434. case 'select' :
  5435. $elem.find("option").each(function (i){
  5436. if(i===0) { this.selected = true; }
  5437. if ($(this).val() === v) {
  5438. this.selected = true;
  5439. return false;
  5440. }
  5441. });
  5442. if ( v !== undefined ) {
  5443. // post the key and not the text
  5444. sdata[nm] = v;
  5445. j++;
  5446. } else {
  5447. try {
  5448. delete $t.p.postData[nm];
  5449. } catch(e) {}
  5450. }
  5451. break;
  5452. case 'text':
  5453. $elem.val(v || "");
  5454. if(v !== undefined) {
  5455. sdata[nm] = v;
  5456. j++;
  5457. } else {
  5458. try {
  5459. delete $t.p.postData[nm];
  5460. } catch (y){}
  5461. }
  5462. break;
  5463. case 'custom':
  5464. if ($.isFunction(this.searchoptions.custom_value) && $elem.length > 0 && $elem[0].nodeName.toUpperCase() === "SPAN") {
  5465. this.searchoptions.custom_value.call($t, $elem.children(".customelement:first"), "set", v || "");
  5466. }
  5467. break;
  5468. }
  5469. });
  5470. var sd = j>0 ? true : false;
  5471. $t.p.resetsearch = true;
  5472. if(p.stringResult === true || $t.p.datatype === "local") {
  5473. var ruleGroup = "{\"groupOp\":\"" + p.groupOp + "\",\"rules\":[";
  5474. var gi=0;
  5475. $.each(sdata,function(i,n){
  5476. if (gi > 0) {ruleGroup += ",";}
  5477. ruleGroup += "{\"field\":\"" + i + "\",";
  5478. ruleGroup += "\"op\":\"" + "eq" + "\",";
  5479. n+="";
  5480. ruleGroup += "\"data\":\"" + n.replace(/\\/g,'\\\\').replace(/\"/g,'\\"') + "\"}";
  5481. gi++;
  5482. });
  5483. ruleGroup += "]}";
  5484. $.extend($t.p.postData,{filters:ruleGroup});
  5485. $.each(['searchField', 'searchString', 'searchOper'], function(i, n){
  5486. if($t.p.postData.hasOwnProperty(n)) { delete $t.p.postData[n];}
  5487. });
  5488. } else {
  5489. $.extend($t.p.postData,sdata);
  5490. }
  5491. var saveurl;
  5492. if($t.p.searchurl) {
  5493. saveurl = $t.p.url;
  5494. $($t).jqGrid("setGridParam",{url:$t.p.searchurl});
  5495. }
  5496. var bcv = $($t).triggerHandler("jqGridToolbarBeforeClear") === 'stop' ? true : false;
  5497. if(!bcv && $.isFunction(p.beforeClear)){bcv = p.beforeClear.call($t);}
  5498. if(!bcv) {
  5499. if(trigger) {
  5500. $($t).jqGrid("setGridParam",{search:sd}).trigger("reloadGrid",[{page:1}]);
  5501. }
  5502. }
  5503. if(saveurl) {$($t).jqGrid("setGridParam",{url:saveurl});}
  5504. $($t).triggerHandler("jqGridToolbarAfterClear");
  5505. if($.isFunction(p.afterClear)){p.afterClear();}
  5506. },
  5507. toggleToolbar = function(){
  5508. var trow = $("tr.ui-search-toolbar",$t.grid.hDiv),
  5509. trow2 = $t.p.frozenColumns === true ? $("tr.ui-search-toolbar",$t.grid.fhDiv) : false;
  5510. if(trow.css("display") === 'none') {
  5511. trow.show();
  5512. if(trow2) {
  5513. trow2.show();
  5514. }
  5515. } else {
  5516. trow.hide();
  5517. if(trow2) {
  5518. trow2.hide();
  5519. }
  5520. }
  5521. },
  5522. buildRuleMenu = function( elem, left, top ){
  5523. $("#sopt_menu").remove();
  5524. left=parseInt(left,10);
  5525. top=parseInt(top,10) + 18;
  5526. var fs = $('.ui-jqgrid-view').css('font-size') || '11px';
  5527. var str = '<ul id="sopt_menu" class="ui-search-menu" role="menu" tabindex="0" style="font-size:'+fs+';left:'+left+'px;top:'+top+'px;">',
  5528. selected = $(elem).attr("soper"), selclass,
  5529. aoprs = [], ina;
  5530. var i=0, nm =$(elem).attr("colname"),len = $t.p.colModel.length;
  5531. while(i<len) {
  5532. if($t.p.colModel[i].name === nm) {
  5533. break;
  5534. }
  5535. i++;
  5536. }
  5537. var cm = $t.p.colModel[i], options = $.extend({}, cm.searchoptions);
  5538. if(!options.sopt) {
  5539. options.sopt = [];
  5540. options.sopt[0]= cm.stype==='select' ? 'eq' : p.defaultSearch;
  5541. }
  5542. $.each(p.odata, function() { aoprs.push(this.oper); });
  5543. for ( i = 0 ; i < options.sopt.length; i++) {
  5544. ina = $.inArray(options.sopt[i],aoprs);
  5545. if(ina !== -1) {
  5546. selclass = selected === p.odata[ina].oper ? "ui-state-highlight" : "";
  5547. 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>';
  5548. }
  5549. }
  5550. str += "</ul>";
  5551. $('body').append(str);
  5552. $("#sopt_menu").addClass("ui-menu ui-widget ui-widget-content ui-corner-all");
  5553. $("#sopt_menu > li > a").hover(
  5554. function(){ $(this).addClass("ui-state-hover"); },
  5555. function(){ $(this).removeClass("ui-state-hover"); }
  5556. ).click(function( e ){
  5557. var v = $(this).attr("value"),
  5558. oper = $(this).attr("oper");
  5559. $($t).triggerHandler("jqGridToolbarSelectOper", [v, oper, elem]);
  5560. $("#sopt_menu").hide();
  5561. $(elem).text(oper).attr("soper",v);
  5562. if(p.autosearch===true){
  5563. var inpelm = $(elem).parent().next().children()[0];
  5564. if( $(inpelm).val() || v==="nu" || v ==="nn") {
  5565. triggerToolbar();
  5566. }
  5567. }
  5568. });
  5569. };
  5570. // create the row
  5571. var tr = $("<tr class='ui-search-toolbar' role='row'></tr>");
  5572. var timeoutHnd;
  5573. $.each($t.p.colModel,function(ci){
  5574. var cm=this, soptions, surl, self, select = "", sot="=", so, i,
  5575. th = $("<th role='columnheader' class='ui-state-default ui-th-column ui-th-"+$t.p.direction+"'></th>"),
  5576. thd = $("<div style='position:relative;height:auto;padding-right:0.3em;padding-left:0.3em;'></div>"),
  5577. 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>");
  5578. if(this.hidden===true) { $(th).css("display","none");}
  5579. this.search = this.search === false ? false : true;
  5580. if(this.stype === undefined) {this.stype='text';}
  5581. soptions = $.extend({},this.searchoptions || {});
  5582. if(this.search){
  5583. if(p.searchOperators) {
  5584. so = (soptions.sopt) ? soptions.sopt[0] : cm.stype==='select' ? 'eq' : p.defaultSearch;
  5585. for(i = 0;i<p.odata.length;i++) {
  5586. if(p.odata[i].oper === so) {
  5587. sot = p.operands[so] || "";
  5588. break;
  5589. }
  5590. }
  5591. var st = soptions.searchtitle != null ? soptions.searchtitle : p.operandTitle;
  5592. select = "<a title='"+st+"' style='padding-right: 0.5em;' soper='"+so+"' class='soptclass' colname='"+this.name+"'>"+sot+"</a>";
  5593. }
  5594. $("td:eq(0)",stbl).attr("colindex",ci).append(select);
  5595. if(soptions.clearSearch === undefined) {
  5596. soptions.clearSearch = true;
  5597. }
  5598. if(soptions.clearSearch) {
  5599. var csv = p.resetTitle || 'Clear Search Value';
  5600. $("td:eq(2)",stbl).append("<a title='"+csv+"' style='padding-right: 0.3em;padding-left: 0.3em;' class='clearsearchclass'>"+p.resetIcon+"</a>");
  5601. } else {
  5602. $("td:eq(2)", stbl).hide();
  5603. }
  5604. switch (this.stype)
  5605. {
  5606. case "select":
  5607. surl = this.surl || soptions.dataUrl;
  5608. if(surl) {
  5609. // data returned should have already constructed html select
  5610. // primitive jQuery load
  5611. self = thd;
  5612. $(self).append(stbl);
  5613. $.ajax($.extend({
  5614. url: surl,
  5615. dataType: "html",
  5616. success: function(res) {
  5617. if(soptions.buildSelect !== undefined) {
  5618. var d = soptions.buildSelect(res);
  5619. if (d) {
  5620. $("td:eq(1)",stbl).append(d);
  5621. }
  5622. } else {
  5623. $("td:eq(1)",stbl).append(res);
  5624. }
  5625. if(soptions.defaultValue !== undefined) { $("select",self).val(soptions.defaultValue); }
  5626. $("select",self).attr({name:cm.index || cm.name, id: "gs_"+cm.name});
  5627. if(soptions.attr) {$("select",self).attr(soptions.attr);}
  5628. $("select",self).css({width: "100%"});
  5629. // preserve autoserch
  5630. $.jgrid.bindEv.call($t, $("select",self)[0], soptions);
  5631. if(p.autosearch===true){
  5632. $("select",self).change(function(){
  5633. triggerToolbar();
  5634. return false;
  5635. });
  5636. }
  5637. res=null;
  5638. }
  5639. }, $.jgrid.ajaxOptions, $t.p.ajaxSelectOptions || {} ));
  5640. } else {
  5641. var oSv, sep, delim;
  5642. if(cm.searchoptions) {
  5643. oSv = cm.searchoptions.value === undefined ? "" : cm.searchoptions.value;
  5644. sep = cm.searchoptions.separator === undefined ? ":" : cm.searchoptions.separator;
  5645. delim = cm.searchoptions.delimiter === undefined ? ";" : cm.searchoptions.delimiter;
  5646. } else if(cm.editoptions) {
  5647. oSv = cm.editoptions.value === undefined ? "" : cm.editoptions.value;
  5648. sep = cm.editoptions.separator === undefined ? ":" : cm.editoptions.separator;
  5649. delim = cm.editoptions.delimiter === undefined ? ";" : cm.editoptions.delimiter;
  5650. }
  5651. if (oSv) {
  5652. var elem = document.createElement("select");
  5653. elem.style.width = "100%";
  5654. $(elem).attr({name:cm.index || cm.name, id: "gs_"+cm.name});
  5655. var sv, ov, key, k;
  5656. if(typeof oSv === "string") {
  5657. so = oSv.split(delim);
  5658. for(k=0; k<so.length;k++){
  5659. sv = so[k].split(sep);
  5660. ov = document.createElement("option");
  5661. ov.value = sv[0]; ov.innerHTML = sv[1];
  5662. elem.appendChild(ov);
  5663. }
  5664. } else if(typeof oSv === "object" ) {
  5665. for (key in oSv) {
  5666. if(oSv.hasOwnProperty(key)) {
  5667. ov = document.createElement("option");
  5668. ov.value = key; ov.innerHTML = oSv[key];
  5669. elem.appendChild(ov);
  5670. }
  5671. }
  5672. }
  5673. if(soptions.defaultValue !== undefined) { $(elem).val(soptions.defaultValue); }
  5674. if(soptions.attr) {$(elem).attr(soptions.attr);}
  5675. $(thd).append(stbl);
  5676. $.jgrid.bindEv.call($t, elem , soptions);
  5677. $("td:eq(1)",stbl).append( elem );
  5678. if(p.autosearch===true){
  5679. $(elem).change(function(){
  5680. triggerToolbar();
  5681. return false;
  5682. });
  5683. }
  5684. }
  5685. }
  5686. break;
  5687. case "text":
  5688. var df = soptions.defaultValue !== undefined ? soptions.defaultValue: "";
  5689. $("td:eq(1)",stbl).append("<input type='text' style='width:100%;padding:0px;' name='"+(cm.index || cm.name)+"' id='gs_"+cm.name+"' value='"+df+"'/>");
  5690. $(thd).append(stbl);
  5691. if(soptions.attr) {$("input",thd).attr(soptions.attr);}
  5692. $.jgrid.bindEv.call($t, $("input",thd)[0], soptions);
  5693. if(p.autosearch===true){
  5694. if(p.searchOnEnter) {
  5695. $("input",thd).keypress(function(e){
  5696. var key = e.charCode || e.keyCode || 0;
  5697. if(key === 13){
  5698. triggerToolbar();
  5699. return false;
  5700. }
  5701. return this;
  5702. });
  5703. } else {
  5704. $("input",thd).keydown(function(e){
  5705. var key = e.which;
  5706. switch (key) {
  5707. case 13:
  5708. return false;
  5709. case 9 :
  5710. case 16:
  5711. case 37:
  5712. case 38:
  5713. case 39:
  5714. case 40:
  5715. case 27:
  5716. break;
  5717. default :
  5718. if(timeoutHnd) { clearTimeout(timeoutHnd); }
  5719. timeoutHnd = setTimeout(function(){triggerToolbar();}, p.autosearchDelay);
  5720. }
  5721. });
  5722. }
  5723. }
  5724. break;
  5725. case "custom":
  5726. $("td:eq(1)",stbl).append("<span style='width:95%;padding:0px;' name='"+(cm.index || cm.name)+"' id='gs_"+cm.name+"'/>");
  5727. $(thd).append(stbl);
  5728. try {
  5729. if($.isFunction(soptions.custom_element)) {
  5730. var celm = soptions.custom_element.call($t,soptions.defaultValue !== undefined ? soptions.defaultValue: "",soptions);
  5731. if(celm) {
  5732. celm = $(celm).addClass("customelement");
  5733. $(thd).find("span[name='" + (cm.index || cm.name) + "']").append(celm);
  5734. } else {
  5735. throw "e2";
  5736. }
  5737. } else {
  5738. throw "e1";
  5739. }
  5740. } catch (e) {
  5741. if (e === "e1") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_element' "+$.jgrid.edit.msg.nodefined,$.jgrid.edit.bClose);}
  5742. if (e === "e2") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_element' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose);}
  5743. else { $.jgrid.info_dialog($.jgrid.errors.errcap,typeof e==="string"?e:e.message,$.jgrid.edit.bClose); }
  5744. }
  5745. break;
  5746. }
  5747. }
  5748. $(th).append(thd);
  5749. $(tr).append(th);
  5750. if(!p.searchOperators) {
  5751. $("td:eq(0)",stbl).hide();
  5752. }
  5753. });
  5754. $("table thead",$t.grid.hDiv).append(tr);
  5755. if(p.searchOperators) {
  5756. $(".soptclass",tr).click(function(e){
  5757. var offset = $(this).offset(),
  5758. left = ( offset.left ),
  5759. top = ( offset.top);
  5760. buildRuleMenu(this, left, top );
  5761. e.stopPropagation();
  5762. });
  5763. $("body").on('click', function(e){
  5764. if(e.target.className !== "soptclass") {
  5765. $("#sopt_menu").hide();
  5766. }
  5767. });
  5768. }
  5769. $(".clearsearchclass",tr).click(function(e){
  5770. var ptr = $(this).parents("tr:first"),
  5771. coli = parseInt($("td.ui-search-oper", ptr).attr('colindex'),10),
  5772. sval = $.extend({},$t.p.colModel[coli].searchoptions || {}),
  5773. dval = sval.defaultValue ? sval.defaultValue : "";
  5774. if($t.p.colModel[coli].stype === "select") {
  5775. if(dval) {
  5776. $("td.ui-search-input select", ptr).val( dval );
  5777. } else {
  5778. $("td.ui-search-input select", ptr)[0].selectedIndex = 0;
  5779. }
  5780. } else {
  5781. $("td.ui-search-input input", ptr).val( dval );
  5782. }
  5783. // ToDo custom search type
  5784. if(p.autosearch===true){
  5785. triggerToolbar();
  5786. }
  5787. });
  5788. this.ftoolbar = true;
  5789. this.triggerToolbar = triggerToolbar;
  5790. this.clearToolbar = clearToolbar;
  5791. this.toggleToolbar = toggleToolbar;
  5792. });
  5793. },
  5794. destroyFilterToolbar: function () {
  5795. return this.each(function () {
  5796. if (!this.ftoolbar) {
  5797. return;
  5798. }
  5799. this.triggerToolbar = null;
  5800. this.clearToolbar = null;
  5801. this.toggleToolbar = null;
  5802. this.ftoolbar = false;
  5803. $(this.grid.hDiv).find("table thead tr.ui-search-toolbar").remove();
  5804. });
  5805. },
  5806. destroyGroupHeader : function(nullHeader)
  5807. {
  5808. if(nullHeader === undefined) {
  5809. nullHeader = true;
  5810. }
  5811. return this.each(function()
  5812. {
  5813. var $t = this, $tr, i, l, headers, $th, $resizing, grid = $t.grid,
  5814. thead = $("table.ui-jqgrid-htable thead", grid.hDiv), cm = $t.p.colModel, hc;
  5815. if(!grid) { return; }
  5816. $(this).unbind('.setGroupHeaders');
  5817. $tr = $("<tr>", {role: "row"}).addClass("ui-jqgrid-labels");
  5818. headers = grid.headers;
  5819. for (i = 0, l = headers.length; i < l; i++) {
  5820. hc = cm[i].hidden ? "none" : "";
  5821. $th = $(headers[i].el)
  5822. .width(headers[i].width)
  5823. .css('display',hc);
  5824. try {
  5825. $th.removeAttr("rowSpan");
  5826. } catch (rs) {
  5827. //IE 6/7
  5828. $th.attr("rowSpan",1);
  5829. }
  5830. $tr.append($th);
  5831. $resizing = $th.children("span.ui-jqgrid-resize");
  5832. if ($resizing.length>0) {// resizable column
  5833. $resizing[0].style.height = "";
  5834. }
  5835. $th.children("div")[0].style.top = "";
  5836. }
  5837. $(thead).children('tr.ui-jqgrid-labels').remove();
  5838. $(thead).prepend($tr);
  5839. if(nullHeader === true) {
  5840. $($t).jqGrid('setGridParam',{ 'groupHeader': null});
  5841. }
  5842. });
  5843. },
  5844. setGroupHeaders : function ( o ) {
  5845. o = $.extend({
  5846. useColSpanStyle : false,
  5847. groupHeaders: []
  5848. },o || {});
  5849. return this.each(function(){
  5850. this.p.groupHeader = o;
  5851. var ts = this,
  5852. i, cmi, skip = 0, $tr, $colHeader, th, $th, thStyle,
  5853. iCol,
  5854. cghi,
  5855. //startColumnName,
  5856. numberOfColumns,
  5857. titleText,
  5858. cVisibleColumns,
  5859. colModel = ts.p.colModel,
  5860. cml = colModel.length,
  5861. ths = ts.grid.headers,
  5862. $htable = $("table.ui-jqgrid-htable", ts.grid.hDiv),
  5863. $trLabels = $htable.children("thead").children("tr.ui-jqgrid-labels:last").addClass("jqg-second-row-header"),
  5864. $thead = $htable.children("thead"),
  5865. $theadInTable,
  5866. $firstHeaderRow = $htable.find(".jqg-first-row-header");
  5867. if($firstHeaderRow[0] === undefined) {
  5868. $firstHeaderRow = $('<tr>', {role: "row", "aria-hidden": "true"}).addClass("jqg-first-row-header").css("height", "auto");
  5869. } else {
  5870. $firstHeaderRow.empty();
  5871. }
  5872. var $firstRow,
  5873. inColumnHeader = function (text, columnHeaders) {
  5874. var length = columnHeaders.length, i;
  5875. for (i = 0; i < length; i++) {
  5876. if (columnHeaders[i].startColumnName === text) {
  5877. return i;
  5878. }
  5879. }
  5880. return -1;
  5881. };
  5882. $(ts).prepend($thead);
  5883. $tr = $('<tr>', {role: "row"}).addClass("ui-jqgrid-labels jqg-third-row-header");
  5884. for (i = 0; i < cml; i++) {
  5885. th = ths[i].el;
  5886. $th = $(th);
  5887. cmi = colModel[i];
  5888. // build the next cell for the first header row
  5889. thStyle = { height: '0px', width: ths[i].width + 'px', display: (cmi.hidden ? 'none' : '')};
  5890. $("<th>", {role: 'gridcell'}).css(thStyle).addClass("ui-first-th-"+ts.p.direction).appendTo($firstHeaderRow);
  5891. th.style.width = ""; // remove unneeded style
  5892. iCol = inColumnHeader(cmi.name, o.groupHeaders);
  5893. if (iCol >= 0) {
  5894. cghi = o.groupHeaders[iCol];
  5895. numberOfColumns = cghi.numberOfColumns;
  5896. titleText = cghi.titleText;
  5897. // caclulate the number of visible columns from the next numberOfColumns columns
  5898. for (cVisibleColumns = 0, iCol = 0; iCol < numberOfColumns && (i + iCol < cml); iCol++) {
  5899. if (!colModel[i + iCol].hidden) {
  5900. cVisibleColumns++;
  5901. }
  5902. }
  5903. // The next numberOfColumns headers will be moved in the next row
  5904. // in the current row will be placed the new column header with the titleText.
  5905. // The text will be over the cVisibleColumns columns
  5906. $colHeader = $('<th>').attr({role: "columnheader"})
  5907. .addClass("ui-state-default ui-th-column-header ui-th-"+ts.p.direction)
  5908. .css({'height':'22px', 'border-top': '0 none'})
  5909. .html(titleText);
  5910. if(cVisibleColumns > 0) {
  5911. $colHeader.attr("colspan", String(cVisibleColumns));
  5912. }
  5913. if (ts.p.headertitles) {
  5914. $colHeader.attr("title", $colHeader.text());
  5915. }
  5916. // hide if not a visible cols
  5917. if( cVisibleColumns === 0) {
  5918. $colHeader.hide();
  5919. }
  5920. $th.before($colHeader); // insert new column header before the current
  5921. $tr.append(th); // move the current header in the next row
  5922. // set the coumter of headers which will be moved in the next row
  5923. skip = numberOfColumns - 1;
  5924. } else {
  5925. if (skip === 0) {
  5926. if (o.useColSpanStyle) {
  5927. // expand the header height to two rows
  5928. $th.attr("rowspan", "2");
  5929. } else {
  5930. $('<th>', {role: "columnheader"})
  5931. .addClass("ui-state-default ui-th-column-header ui-th-"+ts.p.direction)
  5932. .css({"display": cmi.hidden ? 'none' : '', 'border-top': '0 none'})
  5933. .insertBefore($th);
  5934. $tr.append(th);
  5935. }
  5936. } else {
  5937. // move the header to the next row
  5938. //$th.css({"padding-top": "2px", height: "19px"});
  5939. $tr.append(th);
  5940. skip--;
  5941. }
  5942. }
  5943. }
  5944. $theadInTable = $(ts).children("thead");
  5945. $theadInTable.prepend($firstHeaderRow);
  5946. $tr.insertAfter($trLabels);
  5947. $htable.append($theadInTable);
  5948. if (o.useColSpanStyle) {
  5949. // Increase the height of resizing span of visible headers
  5950. $htable.find("span.ui-jqgrid-resize").each(function () {
  5951. var $parent = $(this).parent();
  5952. if ($parent.is(":visible")) {
  5953. this.style.cssText = 'height: ' + $parent.height() + 'px !important; cursor: col-resize;';
  5954. }
  5955. });
  5956. // Set position of the sortable div (the main lable)
  5957. // with the column header text to the middle of the cell.
  5958. // One should not do this for hidden headers.
  5959. $htable.find("div.ui-jqgrid-sortable").each(function () {
  5960. var $ts = $(this), $parent = $ts.parent();
  5961. if ($parent.is(":visible") && $parent.is(":has(span.ui-jqgrid-resize)")) {
  5962. $ts.css('top', ($parent.height() - $ts.outerHeight()) / 2 + 'px');
  5963. }
  5964. });
  5965. }
  5966. $firstRow = $theadInTable.find("tr.jqg-first-row-header");
  5967. $(ts).bind('jqGridResizeStop.setGroupHeaders', function (e, nw, idx) {
  5968. $firstRow.find('th').eq(idx).width(nw);
  5969. });
  5970. });
  5971. },
  5972. setFrozenColumns : function () {
  5973. return this.each(function() {
  5974. if ( !this.grid ) {return;}
  5975. var $t = this, cm = $t.p.colModel,i=0, len = cm.length, maxfrozen = -1, frozen= false;
  5976. // TODO treeGrid and grouping Support
  5977. if($t.p.subGrid === true || $t.p.treeGrid === true || $t.p.cellEdit === true || $t.p.sortable || $t.p.scroll )
  5978. {
  5979. return;
  5980. }
  5981. if($t.p.rownumbers) { i++; }
  5982. if($t.p.multiselect) { i++; }
  5983. // get the max index of frozen col
  5984. while(i<len)
  5985. {
  5986. // from left, no breaking frozen
  5987. if(cm[i].frozen === true)
  5988. {
  5989. frozen = true;
  5990. maxfrozen = i;
  5991. } else {
  5992. break;
  5993. }
  5994. i++;
  5995. }
  5996. if( maxfrozen>=0 && frozen) {
  5997. var top = $t.p.caption ? $($t.grid.cDiv).outerHeight() : 0,
  5998. hth = $(".ui-jqgrid-htable","#gview_"+$.jgrid.jqID($t.p.id)).height();
  5999. //headers
  6000. if($t.p.toppager) {
  6001. top = top + $($t.grid.topDiv).outerHeight();
  6002. }
  6003. if($t.p.toolbar[0] === true) {
  6004. if($t.p.toolbar[1] !== "bottom") {
  6005. top = top + $($t.grid.uDiv).outerHeight();
  6006. }
  6007. }
  6008. $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>');
  6009. $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>');
  6010. $("#gview_"+$.jgrid.jqID($t.p.id)).append($t.grid.fhDiv);
  6011. var htbl = $(".ui-jqgrid-htable","#gview_"+$.jgrid.jqID($t.p.id)).clone(true);
  6012. // groupheader support - only if useColSpanstyle is false
  6013. if($t.p.groupHeader) {
  6014. $("tr.jqg-first-row-header, tr.jqg-third-row-header", htbl).each(function(){
  6015. $("th:gt("+maxfrozen+")",this).remove();
  6016. });
  6017. var swapfroz = -1, fdel = -1, cs, rs;
  6018. $("tr.jqg-second-row-header th", htbl).each(function(){
  6019. cs= parseInt($(this).attr("colspan"),10);
  6020. rs= parseInt($(this).attr("rowspan"),10);
  6021. if(rs) {
  6022. swapfroz++;
  6023. fdel++;
  6024. }
  6025. if(cs) {
  6026. swapfroz = swapfroz+cs;
  6027. fdel++;
  6028. }
  6029. if(swapfroz === maxfrozen) {
  6030. return false;
  6031. }
  6032. });
  6033. if(swapfroz !== maxfrozen) {
  6034. fdel = maxfrozen;
  6035. }
  6036. $("tr.jqg-second-row-header", htbl).each(function(){
  6037. $("th:gt("+fdel+")",this).remove();
  6038. });
  6039. } else {
  6040. $("tr",htbl).each(function(){
  6041. $("th:gt("+maxfrozen+")",this).remove();
  6042. });
  6043. }
  6044. $(htbl).width(1);
  6045. // resizing stuff
  6046. $($t.grid.fhDiv).append(htbl)
  6047. .mousemove(function (e) {
  6048. if($t.grid.resizing){ $t.grid.dragMove(e);return false; }
  6049. });
  6050. if($t.p.footerrow) {
  6051. var hbd = $(".ui-jqgrid-bdiv","#gview_"+$.jgrid.jqID($t.p.id)).height();
  6052. $t.grid.fsDiv = $('<div style="position:absolute;left:0px;top:'+(parseInt(top,10)+parseInt(hth,10) + parseInt(hbd,10)+1)+'px;" class="frozen-sdiv ui-jqgrid-sdiv"></div>');
  6053. $("#gview_"+$.jgrid.jqID($t.p.id)).append($t.grid.fsDiv);
  6054. var ftbl = $(".ui-jqgrid-ftable","#gview_"+$.jgrid.jqID($t.p.id)).clone(true);
  6055. $("tr",ftbl).each(function(){
  6056. $("td:gt("+maxfrozen+")",this).remove();
  6057. });
  6058. $(ftbl).width(1);
  6059. $($t.grid.fsDiv).append(ftbl);
  6060. }
  6061. $($t).bind('jqGridResizeStop.setFrozenColumns', function (e, w, index) {
  6062. var rhth = $(".ui-jqgrid-htable",$t.grid.fhDiv);
  6063. $("th:eq("+index+")",rhth).width( w );
  6064. var btd = $(".ui-jqgrid-btable",$t.grid.fbDiv);
  6065. $("tr:first td:eq("+index+")",btd).width( w );
  6066. if($t.p.footerrow) {
  6067. var ftd = $(".ui-jqgrid-ftable",$t.grid.fsDiv);
  6068. $("tr:first td:eq("+index+")",ftd).width( w );
  6069. }
  6070. });
  6071. // sorting stuff
  6072. $($t).bind('jqGridSortCol.setFrozenColumns', function (e, index, idxcol) {
  6073. 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);
  6074. $("span.ui-grid-ico-sort",previousSelectedTh).addClass('ui-state-disabled');
  6075. $(previousSelectedTh).attr("aria-selected","false");
  6076. $("span.ui-icon-"+$t.p.sortorder,newSelectedTh).removeClass('ui-state-disabled');
  6077. $(newSelectedTh).attr("aria-selected","true");
  6078. if(!$t.p.viewsortcols[0]) {
  6079. if($t.p.lastsort !== idxcol) {
  6080. $("span.s-ico",previousSelectedTh).hide();
  6081. $("span.s-ico",newSelectedTh).show();
  6082. }
  6083. }
  6084. });
  6085. // data stuff
  6086. //TODO support for setRowData
  6087. $("#gview_"+$.jgrid.jqID($t.p.id)).append($t.grid.fbDiv);
  6088. $($t.grid.bDiv).scroll(function () {
  6089. $($t.grid.fbDiv).scrollTop($(this).scrollTop());
  6090. });
  6091. if($t.p.hoverrows === true) {
  6092. $("#"+$.jgrid.jqID($t.p.id)).unbind('mouseover').unbind('mouseout');
  6093. }
  6094. $($t).bind('jqGridAfterGridComplete.setFrozenColumns', function () {
  6095. $("#"+$.jgrid.jqID($t.p.id)+"_frozen").remove();
  6096. $($t.grid.fbDiv).height($($t.grid.bDiv).height()-16);
  6097. var btbl = $("#"+$.jgrid.jqID($t.p.id)).clone(true);
  6098. $("tr[role=row]",btbl).each(function(){
  6099. $("td[role=gridcell]:gt("+maxfrozen+")",this).remove();
  6100. });
  6101. $(btbl).width(1).attr("id",$t.p.id+"_frozen");
  6102. $($t.grid.fbDiv).append(btbl);
  6103. if($t.p.hoverrows === true) {
  6104. $("tr.jqgrow", btbl).hover(
  6105. function(){ $(this).addClass("ui-state-hover"); $("#"+$.jgrid.jqID(this.id), "#"+$.jgrid.jqID($t.p.id)).addClass("ui-state-hover"); },
  6106. function(){ $(this).removeClass("ui-state-hover"); $("#"+$.jgrid.jqID(this.id), "#"+$.jgrid.jqID($t.p.id)).removeClass("ui-state-hover"); }
  6107. );
  6108. $("tr.jqgrow", "#"+$.jgrid.jqID($t.p.id)).hover(
  6109. function(){ $(this).addClass("ui-state-hover"); $("#"+$.jgrid.jqID(this.id), "#"+$.jgrid.jqID($t.p.id)+"_frozen").addClass("ui-state-hover");},
  6110. function(){ $(this).removeClass("ui-state-hover"); $("#"+$.jgrid.jqID(this.id), "#"+$.jgrid.jqID($t.p.id)+"_frozen").removeClass("ui-state-hover"); }
  6111. );
  6112. }
  6113. btbl=null;
  6114. });
  6115. if(!$t.grid.hDiv.loading) {
  6116. $($t).triggerHandler("jqGridAfterGridComplete");
  6117. }
  6118. $t.p.frozenColumns = true;
  6119. }
  6120. });
  6121. },
  6122. destroyFrozenColumns : function() {
  6123. return this.each(function() {
  6124. if ( !this.grid ) {return;}
  6125. if(this.p.frozenColumns === true) {
  6126. var $t = this;
  6127. $($t.grid.fhDiv).remove();
  6128. $($t.grid.fbDiv).remove();
  6129. $t.grid.fhDiv = null; $t.grid.fbDiv=null;
  6130. if($t.p.footerrow) {
  6131. $($t.grid.fsDiv).remove();
  6132. $t.grid.fsDiv = null;
  6133. }
  6134. $(this).unbind('.setFrozenColumns');
  6135. if($t.p.hoverrows === true) {
  6136. var ptr;
  6137. $("#"+$.jgrid.jqID($t.p.id)).bind('mouseover',function(e) {
  6138. ptr = $(e.target).closest("tr.jqgrow");
  6139. if($(ptr).attr("class") !== "ui-subgrid") {
  6140. $(ptr).addClass("ui-state-hover");
  6141. }
  6142. }).bind('mouseout',function(e) {
  6143. ptr = $(e.target).closest("tr.jqgrow");
  6144. $(ptr).removeClass("ui-state-hover");
  6145. });
  6146. }
  6147. this.p.frozenColumns = false;
  6148. }
  6149. });
  6150. }
  6151. });
  6152. })(jQuery);
  6153. /*
  6154. * jqFilter jQuery jqGrid filter addon.
  6155. * Copyright (c) 2011, Tony Tomov, tony@trirand.com
  6156. * Dual licensed under the MIT and GPL licenses
  6157. * http://www.opensource.org/licenses/mit-license.php
  6158. * http://www.gnu.org/licenses/gpl-2.0.html
  6159. *
  6160. * The work is inspired from this Stefan Pirvu
  6161. * http://www.codeproject.com/KB/scripting/json-filtering.aspx
  6162. *
  6163. * The filter uses JSON entities to hold filter rules and groups. Here is an example of a filter:
  6164. { "groupOp": "AND",
  6165. "groups" : [
  6166. { "groupOp": "OR",
  6167. "rules": [
  6168. { "field": "name", "op": "eq", "data": "England" },
  6169. { "field": "id", "op": "le", "data": "5"}
  6170. ]
  6171. }
  6172. ],
  6173. "rules": [
  6174. { "field": "name", "op": "eq", "data": "Romania" },
  6175. { "field": "id", "op": "le", "data": "1"}
  6176. ]
  6177. }
  6178. */
  6179. /*jshint eqeqeq:false, eqnull:true, devel:true */
  6180. /*global jQuery */
  6181. (function ($) {
  6182. "use strict";
  6183. $.fn.jqFilter = function( arg ) {
  6184. if (typeof arg === 'string') {
  6185. var fn = $.fn.jqFilter[arg];
  6186. if (!fn) {
  6187. throw ("jqFilter - No such method: " + arg);
  6188. }
  6189. var args = $.makeArray(arguments).slice(1);
  6190. return fn.apply(this,args);
  6191. }
  6192. var p = $.extend(true,{
  6193. filter: null,
  6194. columns: [],
  6195. onChange : null,
  6196. afterRedraw : null,
  6197. checkValues : null,
  6198. error: false,
  6199. errmsg : "",
  6200. errorcheck : true,
  6201. showQuery : true,
  6202. sopt : null,
  6203. ops : [],
  6204. operands : null,
  6205. numopts : ['eq','ne', 'lt', 'le', 'gt', 'ge', 'nu', 'nn', 'in', 'ni'],
  6206. stropts : ['eq', 'ne', 'bw', 'bn', 'ew', 'en', 'cn', 'nc', 'nu', 'nn', 'in', 'ni'],
  6207. strarr : ['text', 'string', 'blob'],
  6208. groupOps : [{ op: "AND", text: "AND" }, { op: "OR", text: "OR" }],
  6209. groupButton : true,
  6210. ruleButtons : true,
  6211. direction : "ltr"
  6212. }, $.jgrid.filter, arg || {});
  6213. return this.each( function() {
  6214. if (this.filter) {return;}
  6215. this.p = p;
  6216. // setup filter in case if they is not defined
  6217. if (this.p.filter === null || this.p.filter === undefined) {
  6218. this.p.filter = {
  6219. groupOp: this.p.groupOps[0].op,
  6220. rules: [],
  6221. groups: []
  6222. };
  6223. }
  6224. var i, len = this.p.columns.length, cl,
  6225. isIE = /msie/i.test(navigator.userAgent) && !window.opera;
  6226. // translating the options
  6227. this.p.initFilter = $.extend(true,{},this.p.filter);
  6228. // set default values for the columns if they are not set
  6229. if( !len ) {return;}
  6230. for(i=0; i < len; i++) {
  6231. cl = this.p.columns[i];
  6232. if( cl.stype ) {
  6233. // grid compatibility
  6234. cl.inputtype = cl.stype;
  6235. } else if(!cl.inputtype) {
  6236. cl.inputtype = 'text';
  6237. }
  6238. if( cl.sorttype ) {
  6239. // grid compatibility
  6240. cl.searchtype = cl.sorttype;
  6241. } else if (!cl.searchtype) {
  6242. cl.searchtype = 'string';
  6243. }
  6244. if(cl.hidden === undefined) {
  6245. // jqGrid compatibility
  6246. cl.hidden = false;
  6247. }
  6248. if(!cl.label) {
  6249. cl.label = cl.name;
  6250. }
  6251. if(cl.index) {
  6252. cl.name = cl.index;
  6253. }
  6254. if(!cl.hasOwnProperty('searchoptions')) {
  6255. cl.searchoptions = {};
  6256. }
  6257. if(!cl.hasOwnProperty('searchrules')) {
  6258. cl.searchrules = {};
  6259. }
  6260. }
  6261. if(this.p.showQuery) {
  6262. $(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>");
  6263. }
  6264. var getGrid = function () {
  6265. return $("#" + $.jgrid.jqID(p.id))[0] || null;
  6266. };
  6267. /*
  6268. *Perform checking.
  6269. *
  6270. */
  6271. var checkData = function(val, colModelItem) {
  6272. var ret = [true,""], $t = getGrid();
  6273. if($.isFunction(colModelItem.searchrules)) {
  6274. ret = colModelItem.searchrules.call($t, val, colModelItem);
  6275. } else if($.jgrid && $.jgrid.checkValues) {
  6276. try {
  6277. ret = $.jgrid.checkValues.call($t, val, -1, colModelItem.searchrules, colModelItem.label);
  6278. } catch (e) {}
  6279. }
  6280. if(ret && ret.length && ret[0] === false) {
  6281. p.error = !ret[0];
  6282. p.errmsg = ret[1];
  6283. }
  6284. };
  6285. /* moving to common
  6286. randId = function() {
  6287. return Math.floor(Math.random()*10000).toString();
  6288. };
  6289. */
  6290. this.onchange = function ( ){
  6291. // clear any error
  6292. this.p.error = false;
  6293. this.p.errmsg="";
  6294. return $.isFunction(this.p.onChange) ? this.p.onChange.call( this, this.p ) : false;
  6295. };
  6296. /*
  6297. * Redraw the filter every time when new field is added/deleted
  6298. * and field is changed
  6299. */
  6300. this.reDraw = function() {
  6301. $("table.group:first",this).remove();
  6302. var t = this.createTableForGroup(p.filter, null);
  6303. $(this).append(t);
  6304. if($.isFunction(this.p.afterRedraw) ) {
  6305. this.p.afterRedraw.call(this, this.p);
  6306. }
  6307. };
  6308. /*
  6309. * Creates a grouping data for the filter
  6310. * @param group - object
  6311. * @param parentgroup - object
  6312. */
  6313. this.createTableForGroup = function(group, parentgroup) {
  6314. var that = this, i;
  6315. // this table will hold all the group (tables) and rules (rows)
  6316. var table = $("<table class='group ui-widget ui-widget-content' style='border:0px none;'><tbody></tbody></table>"),
  6317. // create error message row
  6318. align = "left";
  6319. if(this.p.direction === "rtl") {
  6320. align = "right";
  6321. table.attr("dir","rtl");
  6322. }
  6323. if(parentgroup === null) {
  6324. table.append("<tr class='error' style='display:none;'><th colspan='5' class='ui-state-error' align='"+align+"'></th></tr>");
  6325. }
  6326. var tr = $("<tr></tr>");
  6327. table.append(tr);
  6328. // this header will hold the group operator type and group action buttons for
  6329. // creating subgroup "+ {}", creating rule "+" or deleting the group "-"
  6330. var th = $("<th colspan='5' align='"+align+"'></th>");
  6331. tr.append(th);
  6332. if(this.p.ruleButtons === true) {
  6333. // dropdown for: choosing group operator type
  6334. var groupOpSelect = $("<select class='opsel'></select>");
  6335. th.append(groupOpSelect);
  6336. // populate dropdown with all posible group operators: or, and
  6337. var str= "", selected;
  6338. for (i = 0; i < p.groupOps.length; i++) {
  6339. selected = group.groupOp === that.p.groupOps[i].op ? " selected='selected'" :"";
  6340. str += "<option value='"+that.p.groupOps[i].op+"'" + selected+">"+that.p.groupOps[i].text+"</option>";
  6341. }
  6342. groupOpSelect
  6343. .append(str)
  6344. .bind('change',function() {
  6345. group.groupOp = $(groupOpSelect).val();
  6346. that.onchange(); // signals that the filter has changed
  6347. });
  6348. }
  6349. // button for adding a new subgroup
  6350. var inputAddSubgroup ="<span></span>";
  6351. if(this.p.groupButton) {
  6352. inputAddSubgroup = $("<input type='button' value='+ {}' title='Add subgroup' class='add-group'/>");
  6353. inputAddSubgroup.bind('click',function() {
  6354. if (group.groups === undefined ) {
  6355. group.groups = [];
  6356. }
  6357. group.groups.push({
  6358. groupOp: p.groupOps[0].op,
  6359. rules: [],
  6360. groups: []
  6361. }); // adding a new group
  6362. that.reDraw(); // the html has changed, force reDraw
  6363. that.onchange(); // signals that the filter has changed
  6364. return false;
  6365. });
  6366. }
  6367. th.append(inputAddSubgroup);
  6368. if(this.p.ruleButtons === true) {
  6369. // button for adding a new rule
  6370. var inputAddRule = $("<input type='button' value='+' title='Add rule' class='add-rule ui-add'/>"), cm;
  6371. inputAddRule.bind('click',function() {
  6372. //if(!group) { group = {};}
  6373. if (group.rules === undefined) {
  6374. group.rules = [];
  6375. }
  6376. for (i = 0; i < that.p.columns.length; i++) {
  6377. // but show only serchable and serchhidden = true fields
  6378. var searchable = (that.p.columns[i].search === undefined) ? true: that.p.columns[i].search,
  6379. hidden = (that.p.columns[i].hidden === true),
  6380. ignoreHiding = (that.p.columns[i].searchoptions.searchhidden === true);
  6381. if ((ignoreHiding && searchable) || (searchable && !hidden)) {
  6382. cm = that.p.columns[i];
  6383. break;
  6384. }
  6385. }
  6386. var opr;
  6387. if( cm.searchoptions.sopt ) {opr = cm.searchoptions.sopt;}
  6388. else if(that.p.sopt) { opr= that.p.sopt; }
  6389. else if ( $.inArray(cm.searchtype, that.p.strarr) !== -1 ) {opr = that.p.stropts;}
  6390. else {opr = that.p.numopts;}
  6391. group.rules.push({
  6392. field: cm.name,
  6393. op: opr[0],
  6394. data: ""
  6395. }); // adding a new rule
  6396. that.reDraw(); // the html has changed, force reDraw
  6397. // for the moment no change have been made to the rule, so
  6398. // this will not trigger onchange event
  6399. return false;
  6400. });
  6401. th.append(inputAddRule);
  6402. }
  6403. // button for delete the group
  6404. if (parentgroup !== null) { // ignore the first group
  6405. var inputDeleteGroup = $("<input type='button' value='-' title='Delete group' class='delete-group'/>");
  6406. th.append(inputDeleteGroup);
  6407. inputDeleteGroup.bind('click',function() {
  6408. // remove group from parent
  6409. for (i = 0; i < parentgroup.groups.length; i++) {
  6410. if (parentgroup.groups[i] === group) {
  6411. parentgroup.groups.splice(i, 1);
  6412. break;
  6413. }
  6414. }
  6415. that.reDraw(); // the html has changed, force reDraw
  6416. that.onchange(); // signals that the filter has changed
  6417. return false;
  6418. });
  6419. }
  6420. // append subgroup rows
  6421. if (group.groups !== undefined) {
  6422. for (i = 0; i < group.groups.length; i++) {
  6423. var trHolderForSubgroup = $("<tr></tr>");
  6424. table.append(trHolderForSubgroup);
  6425. var tdFirstHolderForSubgroup = $("<td class='first'></td>");
  6426. trHolderForSubgroup.append(tdFirstHolderForSubgroup);
  6427. var tdMainHolderForSubgroup = $("<td colspan='4'></td>");
  6428. tdMainHolderForSubgroup.append(this.createTableForGroup(group.groups[i], group));
  6429. trHolderForSubgroup.append(tdMainHolderForSubgroup);
  6430. }
  6431. }
  6432. if(group.groupOp === undefined) {
  6433. group.groupOp = that.p.groupOps[0].op;
  6434. }
  6435. // append rules rows
  6436. if (group.rules !== undefined) {
  6437. for (i = 0; i < group.rules.length; i++) {
  6438. table.append(
  6439. this.createTableRowForRule(group.rules[i], group)
  6440. );
  6441. }
  6442. }
  6443. return table;
  6444. };
  6445. /*
  6446. * Create the rule data for the filter
  6447. */
  6448. this.createTableRowForRule = function(rule, group ) {
  6449. // save current entity in a variable so that it could
  6450. // be referenced in anonimous method calls
  6451. var that=this, $t = getGrid(), tr = $("<tr></tr>"),
  6452. //document.createElement("tr"),
  6453. // first column used for padding
  6454. //tdFirstHolderForRule = document.createElement("td"),
  6455. i, op, trpar, cm, str="", selected;
  6456. //tdFirstHolderForRule.setAttribute("class", "first");
  6457. tr.append("<td class='first'></td>");
  6458. // create field container
  6459. var ruleFieldTd = $("<td class='columns'></td>");
  6460. tr.append(ruleFieldTd);
  6461. // dropdown for: choosing field
  6462. var ruleFieldSelect = $("<select></select>"), ina, aoprs = [];
  6463. ruleFieldTd.append(ruleFieldSelect);
  6464. ruleFieldSelect.bind('change',function() {
  6465. rule.field = $(ruleFieldSelect).val();
  6466. trpar = $(this).parents("tr:first");
  6467. for (i=0;i<that.p.columns.length;i++) {
  6468. if(that.p.columns[i].name === rule.field) {
  6469. cm = that.p.columns[i];
  6470. break;
  6471. }
  6472. }
  6473. if(!cm) {return;}
  6474. cm.searchoptions.id = $.jgrid.randId();
  6475. if(isIE && cm.inputtype === "text") {
  6476. if(!cm.searchoptions.size) {
  6477. cm.searchoptions.size = 10;
  6478. }
  6479. }
  6480. var elm = $.jgrid.createEl.call($t, cm.inputtype,cm.searchoptions, "", true, that.p.ajaxSelectOptions || {}, true);
  6481. $(elm).addClass("input-elm");
  6482. //that.createElement(rule, "");
  6483. if( cm.searchoptions.sopt ) {op = cm.searchoptions.sopt;}
  6484. else if(that.p.sopt) { op= that.p.sopt; }
  6485. else if ($.inArray(cm.searchtype, that.p.strarr) !== -1) {op = that.p.stropts;}
  6486. else {op = that.p.numopts;}
  6487. // operators
  6488. var s ="", so = 0;
  6489. aoprs = [];
  6490. $.each(that.p.ops, function() { aoprs.push(this.oper); });
  6491. for ( i = 0 ; i < op.length; i++) {
  6492. ina = $.inArray(op[i],aoprs);
  6493. if(ina !== -1) {
  6494. if(so===0) {
  6495. rule.op = that.p.ops[ina].oper;
  6496. }
  6497. s += "<option value='"+that.p.ops[ina].oper+"'>"+that.p.ops[ina].text+"</option>";
  6498. so++;
  6499. }
  6500. }
  6501. $(".selectopts",trpar).empty().append( s );
  6502. $(".selectopts",trpar)[0].selectedIndex = 0;
  6503. if( $.jgrid.msie && $.jgrid.msiever() < 9) {
  6504. var sw = parseInt($("select.selectopts",trpar)[0].offsetWidth, 10) + 1;
  6505. $(".selectopts",trpar).width( sw );
  6506. $(".selectopts",trpar).css("width","auto");
  6507. }
  6508. // data
  6509. $(".data",trpar).empty().append( elm );
  6510. $.jgrid.bindEv.call($t, elm, cm.searchoptions);
  6511. $(".input-elm",trpar).bind('change',function( e ) {
  6512. var elem = e.target;
  6513. rule.data = elem.nodeName.toUpperCase() === "SPAN" && cm.searchoptions && $.isFunction(cm.searchoptions.custom_value) ?
  6514. cm.searchoptions.custom_value.call($t, $(elem).children(".customelement:first"), 'get') : elem.value;
  6515. that.onchange(); // signals that the filter has changed
  6516. });
  6517. setTimeout(function(){ //IE, Opera, Chrome
  6518. rule.data = $(elm).val();
  6519. that.onchange(); // signals that the filter has changed
  6520. }, 0);
  6521. });
  6522. // populate drop down with user provided column definitions
  6523. var j=0;
  6524. for (i = 0; i < that.p.columns.length; i++) {
  6525. // but show only serchable and serchhidden = true fields
  6526. var searchable = (that.p.columns[i].search === undefined) ? true: that.p.columns[i].search,
  6527. hidden = (that.p.columns[i].hidden === true),
  6528. ignoreHiding = (that.p.columns[i].searchoptions.searchhidden === true);
  6529. if ((ignoreHiding && searchable) || (searchable && !hidden)) {
  6530. selected = "";
  6531. if(rule.field === that.p.columns[i].name) {
  6532. selected = " selected='selected'";
  6533. j=i;
  6534. }
  6535. str += "<option value='"+that.p.columns[i].name+"'" +selected+">"+that.p.columns[i].label+"</option>";
  6536. }
  6537. }
  6538. ruleFieldSelect.append( str );
  6539. // create operator container
  6540. var ruleOperatorTd = $("<td class='operators'></td>");
  6541. tr.append(ruleOperatorTd);
  6542. cm = p.columns[j];
  6543. // create it here so it can be referentiated in the onchange event
  6544. //var RD = that.createElement(rule, rule.data);
  6545. cm.searchoptions.id = $.jgrid.randId();
  6546. if(isIE && cm.inputtype === "text") {
  6547. if(!cm.searchoptions.size) {
  6548. cm.searchoptions.size = 10;
  6549. }
  6550. }
  6551. var ruleDataInput = $.jgrid.createEl.call($t, cm.inputtype,cm.searchoptions, rule.data, true, that.p.ajaxSelectOptions || {}, true);
  6552. if(rule.op === 'nu' || rule.op === 'nn') {
  6553. $(ruleDataInput).attr('readonly','true');
  6554. $(ruleDataInput).attr('disabled','true');
  6555. } //retain the state of disabled text fields in case of null ops
  6556. // dropdown for: choosing operator
  6557. var ruleOperatorSelect = $("<select class='selectopts'></select>");
  6558. ruleOperatorTd.append(ruleOperatorSelect);
  6559. ruleOperatorSelect.bind('change',function() {
  6560. rule.op = $(ruleOperatorSelect).val();
  6561. trpar = $(this).parents("tr:first");
  6562. var rd = $(".input-elm",trpar)[0];
  6563. if (rule.op === "nu" || rule.op === "nn") { // disable for operator "is null" and "is not null"
  6564. rule.data = "";
  6565. if(rd.tagName.toUpperCase() !== 'SELECT') rd.value = "";
  6566. rd.setAttribute("readonly", "true");
  6567. rd.setAttribute("disabled", "true");
  6568. } else {
  6569. if(rd.tagName.toUpperCase() === 'SELECT') rule.data = rd.value;
  6570. rd.removeAttribute("readonly");
  6571. rd.removeAttribute("disabled");
  6572. }
  6573. that.onchange(); // signals that the filter has changed
  6574. });
  6575. // populate drop down with all available operators
  6576. if( cm.searchoptions.sopt ) {op = cm.searchoptions.sopt;}
  6577. else if(that.p.sopt) { op= that.p.sopt; }
  6578. else if ($.inArray(cm.searchtype, that.p.strarr) !== -1) {op = that.p.stropts;}
  6579. else {op = that.p.numopts;}
  6580. str="";
  6581. $.each(that.p.ops, function() { aoprs.push(this.oper); });
  6582. for ( i = 0; i < op.length; i++) {
  6583. ina = $.inArray(op[i],aoprs);
  6584. if(ina !== -1) {
  6585. selected = rule.op === that.p.ops[ina].oper ? " selected='selected'" : "";
  6586. str += "<option value='"+that.p.ops[ina].oper+"'"+selected+">"+that.p.ops[ina].text+"</option>";
  6587. }
  6588. }
  6589. ruleOperatorSelect.append( str );
  6590. // create data container
  6591. var ruleDataTd = $("<td class='data'></td>");
  6592. tr.append(ruleDataTd);
  6593. // textbox for: data
  6594. // is created previously
  6595. //ruleDataInput.setAttribute("type", "text");
  6596. ruleDataTd.append(ruleDataInput);
  6597. $.jgrid.bindEv.call($t, ruleDataInput, cm.searchoptions);
  6598. $(ruleDataInput)
  6599. .addClass("input-elm")
  6600. .bind('change', function() {
  6601. rule.data = cm.inputtype === 'custom' ? cm.searchoptions.custom_value.call($t, $(this).children(".customelement:first"),'get') : $(this).val();
  6602. that.onchange(); // signals that the filter has changed
  6603. });
  6604. // create action container
  6605. var ruleDeleteTd = $("<td></td>");
  6606. tr.append(ruleDeleteTd);
  6607. // create button for: delete rule
  6608. if(this.p.ruleButtons === true) {
  6609. var ruleDeleteInput = $("<input type='button' value='-' title='Delete rule' class='delete-rule ui-del'/>");
  6610. ruleDeleteTd.append(ruleDeleteInput);
  6611. //$(ruleDeleteInput).html("").height(20).width(30).button({icons: { primary: "ui-icon-minus", text:false}});
  6612. ruleDeleteInput.bind('click',function() {
  6613. // remove rule from group
  6614. for (i = 0; i < group.rules.length; i++) {
  6615. if (group.rules[i] === rule) {
  6616. group.rules.splice(i, 1);
  6617. break;
  6618. }
  6619. }
  6620. that.reDraw(); // the html has changed, force reDraw
  6621. that.onchange(); // signals that the filter has changed
  6622. return false;
  6623. });
  6624. }
  6625. return tr;
  6626. };
  6627. this.getStringForGroup = function(group) {
  6628. var s = "(", index;
  6629. if (group.groups !== undefined) {
  6630. for (index = 0; index < group.groups.length; index++) {
  6631. if (s.length > 1) {
  6632. s += " " + group.groupOp + " ";
  6633. }
  6634. try {
  6635. s += this.getStringForGroup(group.groups[index]);
  6636. } catch (eg) {alert(eg);}
  6637. }
  6638. }
  6639. if (group.rules !== undefined) {
  6640. try{
  6641. for (index = 0; index < group.rules.length; index++) {
  6642. if (s.length > 1) {
  6643. s += " " + group.groupOp + " ";
  6644. }
  6645. s += this.getStringForRule(group.rules[index]);
  6646. }
  6647. } catch (e) {alert(e);}
  6648. }
  6649. s += ")";
  6650. if (s === "()") {
  6651. return ""; // ignore groups that don't have rules
  6652. }
  6653. return s;
  6654. };
  6655. this.getStringForRule = function(rule) {
  6656. var opUF = "",opC="", i, cm, ret, val,
  6657. numtypes = ['int', 'integer', 'float', 'number', 'currency']; // jqGrid
  6658. for (i = 0; i < this.p.ops.length; i++) {
  6659. if (this.p.ops[i].oper === rule.op) {
  6660. opUF = this.p.operands.hasOwnProperty(rule.op) ? this.p.operands[rule.op] : "";
  6661. opC = this.p.ops[i].oper;
  6662. break;
  6663. }
  6664. }
  6665. for (i=0; i<this.p.columns.length; i++) {
  6666. if(this.p.columns[i].name === rule.field) {
  6667. cm = this.p.columns[i];
  6668. break;
  6669. }
  6670. }
  6671. if (cm == undefined) { return ""; }
  6672. val = rule.data;
  6673. if(opC === 'bw' || opC === 'bn') { val = val+"%"; }
  6674. if(opC === 'ew' || opC === 'en') { val = "%"+val; }
  6675. if(opC === 'cn' || opC === 'nc') { val = "%"+val+"%"; }
  6676. if(opC === 'in' || opC === 'ni') { val = " ("+val+")"; }
  6677. if(p.errorcheck) { checkData(rule.data, cm); }
  6678. if($.inArray(cm.searchtype, numtypes) !== -1 || opC === 'nn' || opC === 'nu') { ret = rule.field + " " + opUF + " " + val; }
  6679. else { ret = rule.field + " " + opUF + " \"" + val + "\""; }
  6680. return ret;
  6681. };
  6682. this.resetFilter = function () {
  6683. this.p.filter = $.extend(true,{},this.p.initFilter);
  6684. this.reDraw();
  6685. this.onchange();
  6686. };
  6687. this.hideError = function() {
  6688. $("th.ui-state-error", this).html("");
  6689. $("tr.error", this).hide();
  6690. };
  6691. this.showError = function() {
  6692. $("th.ui-state-error", this).html(this.p.errmsg);
  6693. $("tr.error", this).show();
  6694. };
  6695. this.toUserFriendlyString = function() {
  6696. return this.getStringForGroup(p.filter);
  6697. };
  6698. this.toString = function() {
  6699. // this will obtain a string that can be used to match an item.
  6700. var that = this;
  6701. function getStringRule(rule) {
  6702. if(that.p.errorcheck) {
  6703. var i, cm;
  6704. for (i=0; i<that.p.columns.length; i++) {
  6705. if(that.p.columns[i].name === rule.field) {
  6706. cm = that.p.columns[i];
  6707. break;
  6708. }
  6709. }
  6710. if(cm) {checkData(rule.data, cm);}
  6711. }
  6712. return rule.op + "(item." + rule.field + ",'" + rule.data + "')";
  6713. }
  6714. function getStringForGroup(group) {
  6715. var s = "(", index;
  6716. if (group.groups !== undefined) {
  6717. for (index = 0; index < group.groups.length; index++) {
  6718. if (s.length > 1) {
  6719. if (group.groupOp === "OR") {
  6720. s += " || ";
  6721. }
  6722. else {
  6723. s += " && ";
  6724. }
  6725. }
  6726. s += getStringForGroup(group.groups[index]);
  6727. }
  6728. }
  6729. if (group.rules !== undefined) {
  6730. for (index = 0; index < group.rules.length; index++) {
  6731. if (s.length > 1) {
  6732. if (group.groupOp === "OR") {
  6733. s += " || ";
  6734. }
  6735. else {
  6736. s += " && ";
  6737. }
  6738. }
  6739. s += getStringRule(group.rules[index]);
  6740. }
  6741. }
  6742. s += ")";
  6743. if (s === "()") {
  6744. return ""; // ignore groups that don't have rules
  6745. }
  6746. return s;
  6747. }
  6748. return getStringForGroup(this.p.filter);
  6749. };
  6750. // Here we init the filter
  6751. this.reDraw();
  6752. if(this.p.showQuery) {
  6753. this.onchange();
  6754. }
  6755. // mark is as created so that it will not be created twice on this element
  6756. this.filter = true;
  6757. });
  6758. };
  6759. $.extend($.fn.jqFilter,{
  6760. /*
  6761. * Return SQL like string. Can be used directly
  6762. */
  6763. toSQLString : function()
  6764. {
  6765. var s ="";
  6766. this.each(function(){
  6767. s = this.toUserFriendlyString();
  6768. });
  6769. return s;
  6770. },
  6771. /*
  6772. * Return filter data as object.
  6773. */
  6774. filterData : function()
  6775. {
  6776. var s;
  6777. this.each(function(){
  6778. s = this.p.filter;
  6779. });
  6780. return s;
  6781. },
  6782. getParameter : function (param) {
  6783. if(param !== undefined) {
  6784. if (this.p.hasOwnProperty(param) ) {
  6785. return this.p[param];
  6786. }
  6787. }
  6788. return this.p;
  6789. },
  6790. resetFilter: function() {
  6791. return this.each(function(){
  6792. this.resetFilter();
  6793. });
  6794. },
  6795. addFilter: function (pfilter) {
  6796. if (typeof pfilter === "string") {
  6797. pfilter = $.jgrid.parse( pfilter );
  6798. }
  6799. this.each(function(){
  6800. this.p.filter = pfilter;
  6801. this.reDraw();
  6802. this.onchange();
  6803. });
  6804. }
  6805. });
  6806. })(jQuery);
  6807. /*jshint eqeqeq:false, eqnull:true, devel:true */
  6808. /*global xmlJsonClass, jQuery */
  6809. (function($){
  6810. /**
  6811. * jqGrid extension for form editing Grid Data
  6812. * Tony Tomov tony@trirand.com
  6813. * http://trirand.com/blog/
  6814. * Dual licensed under the MIT and GPL licenses:
  6815. * http://www.opensource.org/licenses/mit-license.php
  6816. * http://www.gnu.org/licenses/gpl-2.0.html
  6817. **/
  6818. "use strict";
  6819. var rp_ge = {};
  6820. $.jgrid.extend({
  6821. searchGrid : function (p) {
  6822. p = $.extend(true, {
  6823. recreateFilter: false,
  6824. drag: true,
  6825. sField:'searchField',
  6826. sValue:'searchString',
  6827. sOper: 'searchOper',
  6828. sFilter: 'filters',
  6829. loadDefaults: true, // this options activates loading of default filters from grid's postData for Multipe Search only.
  6830. beforeShowSearch: null,
  6831. afterShowSearch : null,
  6832. onInitializeSearch: null,
  6833. afterRedraw : null,
  6834. afterChange: null,
  6835. closeAfterSearch : false,
  6836. closeAfterReset: false,
  6837. closeOnEscape : false,
  6838. searchOnEnter : false,
  6839. multipleSearch : false,
  6840. multipleGroup : false,
  6841. //cloneSearchRowOnAdd: true,
  6842. top : 0,
  6843. left: 0,
  6844. jqModal : true,
  6845. modal: false,
  6846. resize : true,
  6847. width: 450,
  6848. height: 'auto',
  6849. dataheight: 'auto',
  6850. showQuery: false,
  6851. errorcheck : true,
  6852. sopt: null,
  6853. stringResult: undefined,
  6854. onClose : null,
  6855. onSearch : null,
  6856. onReset : null,
  6857. toTop : true,
  6858. overlay : 30,
  6859. columns : [],
  6860. tmplNames : null,
  6861. tmplFilters : null,
  6862. tmplLabel : ' Template: ',
  6863. showOnLoad: false,
  6864. layer: null,
  6865. 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"}
  6866. }, $.jgrid.search, p || {});
  6867. return this.each(function() {
  6868. var $t = this;
  6869. if(!$t.grid) {return;}
  6870. var fid = "fbox_"+$t.p.id,
  6871. showFrm = true,
  6872. mustReload = true,
  6873. IDs = {themodal:'searchmod'+fid,modalhead:'searchhd'+fid,modalcontent:'searchcnt'+fid, scrollelm : fid},
  6874. defaultFilters = $t.p.postData[p.sFilter],
  6875. fl;
  6876. if(typeof defaultFilters === "string") {
  6877. defaultFilters = $.jgrid.parse( defaultFilters );
  6878. }
  6879. if(p.recreateFilter === true) {
  6880. $("#"+$.jgrid.jqID(IDs.themodal)).remove();
  6881. }
  6882. function showFilter(_filter) {
  6883. showFrm = $($t).triggerHandler("jqGridFilterBeforeShow", [_filter]);
  6884. if(showFrm === undefined) {
  6885. showFrm = true;
  6886. }
  6887. if(showFrm && $.isFunction(p.beforeShowSearch)) {
  6888. showFrm = p.beforeShowSearch.call($t,_filter);
  6889. }
  6890. if(showFrm) {
  6891. $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{gbox:"#gbox_"+$.jgrid.jqID(fid),jqm:p.jqModal, modal:p.modal, overlay: p.overlay, toTop: p.toTop});
  6892. $($t).triggerHandler("jqGridFilterAfterShow", [_filter]);
  6893. if($.isFunction(p.afterShowSearch)) {
  6894. p.afterShowSearch.call($t, _filter);
  6895. }
  6896. }
  6897. }
  6898. if ( $("#"+$.jgrid.jqID(IDs.themodal))[0] !== undefined ) {
  6899. showFilter($("#fbox_"+$.jgrid.jqID(+$t.p.id)));
  6900. } else {
  6901. var fil = $("<div><div id='"+fid+"' class='searchFilter' style='overflow:auto'></div></div>").insertBefore("#gview_"+$.jgrid.jqID($t.p.id)),
  6902. align = "left", butleft ="";
  6903. if($t.p.direction === "rtl") {
  6904. align = "right";
  6905. butleft = " style='text-align:left'";
  6906. fil.attr("dir","rtl");
  6907. }
  6908. var columns = $.extend([],$t.p.colModel),
  6909. 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>",
  6910. 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>",
  6911. bQ = "", tmpl="", colnm, found = false, bt, cmi=-1;
  6912. if(p.showQuery) {
  6913. 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>";
  6914. }
  6915. if(!p.columns.length) {
  6916. $.each(columns, function(i,n){
  6917. if(!n.label) {
  6918. n.label = $t.p.colNames[i];
  6919. }
  6920. // find first searchable column and set it if no default filter
  6921. if(!found) {
  6922. var searchable = (n.search === undefined) ? true: n.search ,
  6923. hidden = (n.hidden === true),
  6924. ignoreHiding = (n.searchoptions && n.searchoptions.searchhidden === true);
  6925. if ((ignoreHiding && searchable) || (searchable && !hidden)) {
  6926. found = true;
  6927. colnm = n.index || n.name;
  6928. cmi =i;
  6929. }
  6930. }
  6931. });
  6932. } else {
  6933. columns = p.columns;
  6934. cmi = 0;
  6935. colnm = columns[0].index || columns[0].name;
  6936. }
  6937. // old behaviour
  6938. if( (!defaultFilters && colnm) || p.multipleSearch === false ) {
  6939. var cmop = "eq";
  6940. if(cmi >=0 && columns[cmi].searchoptions && columns[cmi].searchoptions.sopt) {
  6941. cmop = columns[cmi].searchoptions.sopt[0];
  6942. } else if(p.sopt && p.sopt.length) {
  6943. cmop = p.sopt[0];
  6944. }
  6945. defaultFilters = {groupOp: "AND", rules: [{field: colnm, op: cmop, data: ""}]};
  6946. }
  6947. found = false;
  6948. if(p.tmplNames && p.tmplNames.length) {
  6949. found = true;
  6950. tmpl = p.tmplLabel;
  6951. tmpl += "<select class='ui-template'>";
  6952. tmpl += "<option value='default'>Default</option>";
  6953. $.each(p.tmplNames, function(i,n){
  6954. tmpl += "<option value='"+i+"'>"+n+"</option>";
  6955. });
  6956. tmpl += "</select>";
  6957. }
  6958. 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>";
  6959. fid = $.jgrid.jqID( fid);
  6960. $("#"+fid).jqFilter({
  6961. columns : columns,
  6962. filter: p.loadDefaults ? defaultFilters : null,
  6963. showQuery: p.showQuery,
  6964. errorcheck : p.errorcheck,
  6965. sopt: p.sopt,
  6966. groupButton : p.multipleGroup,
  6967. ruleButtons : p.multipleSearch,
  6968. afterRedraw : p.afterRedraw,
  6969. ops : p.odata,
  6970. operands : p.operands,
  6971. ajaxSelectOptions: $t.p.ajaxSelectOptions,
  6972. groupOps: p.groupOps,
  6973. onChange : function() {
  6974. if(this.p.showQuery) {
  6975. $('.query',this).html(this.toUserFriendlyString());
  6976. }
  6977. if ($.isFunction(p.afterChange)) {
  6978. p.afterChange.call($t, $("#"+fid), p);
  6979. }
  6980. },
  6981. direction : $t.p.direction,
  6982. id: $t.p.id
  6983. });
  6984. fil.append( bt );
  6985. if(found && p.tmplFilters && p.tmplFilters.length) {
  6986. $(".ui-template", fil).bind('change', function(){
  6987. var curtempl = $(this).val();
  6988. if(curtempl==="default") {
  6989. $("#"+fid).jqFilter('addFilter', defaultFilters);
  6990. } else {
  6991. $("#"+fid).jqFilter('addFilter', p.tmplFilters[parseInt(curtempl,10)]);
  6992. }
  6993. return false;
  6994. });
  6995. }
  6996. if(p.multipleGroup === true) {p.multipleSearch = true;}
  6997. $($t).triggerHandler("jqGridFilterInitialize", [$("#"+fid)]);
  6998. if($.isFunction(p.onInitializeSearch) ) {
  6999. p.onInitializeSearch.call($t, $("#"+fid));
  7000. }
  7001. p.gbox = "#gbox_"+fid;
  7002. if (p.layer) {
  7003. $.jgrid.createModal(IDs ,fil,p,"#gview_"+$.jgrid.jqID($t.p.id),$("#gbox_"+$.jgrid.jqID($t.p.id))[0], "#"+$.jgrid.jqID(p.layer), {position: "relative"});
  7004. } else {
  7005. $.jgrid.createModal(IDs ,fil,p,"#gview_"+$.jgrid.jqID($t.p.id),$("#gbox_"+$.jgrid.jqID($t.p.id))[0]);
  7006. }
  7007. if (p.searchOnEnter || p.closeOnEscape) {
  7008. $("#"+$.jgrid.jqID(IDs.themodal)).keydown(function (e) {
  7009. var $target = $(e.target);
  7010. if (p.searchOnEnter && e.which === 13 && // 13 === $.ui.keyCode.ENTER
  7011. !$target.hasClass('add-group') && !$target.hasClass('add-rule') &&
  7012. !$target.hasClass('delete-group') && !$target.hasClass('delete-rule') &&
  7013. (!$target.hasClass("fm-button") || !$target.is("[id$=_query]"))) {
  7014. $("#"+fid+"_search").click();
  7015. return false;
  7016. }
  7017. if (p.closeOnEscape && e.which === 27) { // 27 === $.ui.keyCode.ESCAPE
  7018. $("#"+$.jgrid.jqID(IDs.modalhead)).find(".ui-jqdialog-titlebar-close").click();
  7019. return false;
  7020. }
  7021. });
  7022. }
  7023. if(bQ) {
  7024. $("#"+fid+"_query").bind('click', function(){
  7025. $(".queryresult", fil).toggle();
  7026. return false;
  7027. });
  7028. }
  7029. if (p.stringResult===undefined) {
  7030. // to provide backward compatibility, inferring stringResult value from multipleSearch
  7031. p.stringResult = p.multipleSearch;
  7032. }
  7033. $("#"+fid+"_search").bind('click', function(){
  7034. var sdata={}, res, filters;
  7035. fl = $("#"+fid);
  7036. fl.find(".input-elm:focus").change();
  7037. filters = fl.jqFilter('filterData');
  7038. if(p.errorcheck) {
  7039. fl[0].hideError();
  7040. if(!p.showQuery) {fl.jqFilter('toSQLString');}
  7041. if(fl[0].p.error) {
  7042. fl[0].showError();
  7043. return false;
  7044. }
  7045. }
  7046. if(p.stringResult) {
  7047. try {
  7048. // xmlJsonClass or JSON.stringify
  7049. res = xmlJsonClass.toJson(filters, '', '', false);
  7050. } catch (e) {
  7051. try {
  7052. res = JSON.stringify(filters);
  7053. } catch (e2) { }
  7054. }
  7055. if(typeof res==="string") {
  7056. sdata[p.sFilter] = res;
  7057. $.each([p.sField,p.sValue, p.sOper], function() {sdata[this] = "";});
  7058. }
  7059. } else {
  7060. if(p.multipleSearch) {
  7061. sdata[p.sFilter] = filters;
  7062. $.each([p.sField,p.sValue, p.sOper], function() {sdata[this] = "";});
  7063. } else {
  7064. sdata[p.sField] = filters.rules[0].field;
  7065. sdata[p.sValue] = filters.rules[0].data;
  7066. sdata[p.sOper] = filters.rules[0].op;
  7067. sdata[p.sFilter] = "";
  7068. }
  7069. }
  7070. $t.p.search = true;
  7071. $.extend($t.p.postData,sdata);
  7072. mustReload = $($t).triggerHandler("jqGridFilterSearch");
  7073. if( mustReload === undefined) {
  7074. mustReload = true;
  7075. }
  7076. if(mustReload && $.isFunction(p.onSearch) ) {
  7077. mustReload = p.onSearch.call($t, $t.p.filters);
  7078. }
  7079. if (mustReload !== false) {
  7080. $($t).trigger("reloadGrid",[{page:1}]);
  7081. }
  7082. if(p.closeAfterSearch) {
  7083. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:p.jqModal,onClose: p.onClose});
  7084. }
  7085. return false;
  7086. });
  7087. $("#"+fid+"_reset").bind('click', function(){
  7088. var sdata={},
  7089. fl = $("#"+fid);
  7090. $t.p.search = false;
  7091. $t.p.resetsearch = true;
  7092. if(p.multipleSearch===false) {
  7093. sdata[p.sField] = sdata[p.sValue] = sdata[p.sOper] = "";
  7094. } else {
  7095. sdata[p.sFilter] = "";
  7096. }
  7097. fl[0].resetFilter();
  7098. if(found) {
  7099. $(".ui-template", fil).val("default");
  7100. }
  7101. $.extend($t.p.postData,sdata);
  7102. mustReload = $($t).triggerHandler("jqGridFilterReset");
  7103. if(mustReload === undefined) {
  7104. mustReload = true;
  7105. }
  7106. if(mustReload && $.isFunction(p.onReset) ) {
  7107. mustReload = p.onReset.call($t);
  7108. }
  7109. if(mustReload !== false) {
  7110. $($t).trigger("reloadGrid",[{page:1}]);
  7111. }
  7112. if (p.closeAfterReset) {
  7113. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:p.jqModal,onClose: p.onClose});
  7114. }
  7115. return false;
  7116. });
  7117. showFilter($("#"+fid));
  7118. $(".fm-button:not(.ui-state-disabled)",fil).hover(
  7119. function(){$(this).addClass('ui-state-hover');},
  7120. function(){$(this).removeClass('ui-state-hover');}
  7121. );
  7122. }
  7123. });
  7124. },
  7125. editGridRow : function(rowid, p){
  7126. p = $.extend(true, {
  7127. top : 0,
  7128. left: 0,
  7129. width: 300,
  7130. datawidth: 'auto',
  7131. height: 'auto',
  7132. dataheight: 'auto',
  7133. modal: false,
  7134. overlay : 30,
  7135. drag: true,
  7136. resize: true,
  7137. url: null,
  7138. mtype : "POST",
  7139. clearAfterAdd :true,
  7140. closeAfterEdit : false,
  7141. reloadAfterSubmit : true,
  7142. onInitializeForm: null,
  7143. beforeInitData: null,
  7144. beforeShowForm: null,
  7145. afterShowForm: null,
  7146. beforeSubmit: null,
  7147. afterSubmit: null,
  7148. onclickSubmit: null,
  7149. afterComplete: null,
  7150. onclickPgButtons : null,
  7151. afterclickPgButtons: null,
  7152. editData : {},
  7153. recreateForm : false,
  7154. jqModal : true,
  7155. closeOnEscape : false,
  7156. addedrow : "first",
  7157. topinfo : '',
  7158. bottominfo: '',
  7159. saveicon : [],
  7160. closeicon : [],
  7161. savekey: [false,13],
  7162. navkeys: [false,38,40],
  7163. checkOnSubmit : false,
  7164. checkOnUpdate : false,
  7165. _savedData : {},
  7166. processing : false,
  7167. onClose : null,
  7168. ajaxEditOptions : {},
  7169. serializeEditData : null,
  7170. viewPagerButtons : true,
  7171. overlayClass : 'ui-widget-overlay',
  7172. removemodal : true,
  7173. form: 'edit'
  7174. }, $.jgrid.edit, p || {});
  7175. rp_ge[$(this)[0].p.id] = p;
  7176. return this.each(function(){
  7177. var $t = this;
  7178. if (!$t.grid || !rowid) {return;}
  7179. var gID = $t.p.id,
  7180. frmgr = "FrmGrid_"+gID, frmtborg = "TblGrid_"+gID, frmtb = "#"+$.jgrid.jqID(frmtborg),
  7181. IDs = {themodal:'editmod'+gID,modalhead:'edithd'+gID,modalcontent:'editcnt'+gID, scrollelm : frmgr},
  7182. onBeforeShow = $.isFunction(rp_ge[$t.p.id].beforeShowForm) ? rp_ge[$t.p.id].beforeShowForm : false,
  7183. onAfterShow = $.isFunction(rp_ge[$t.p.id].afterShowForm) ? rp_ge[$t.p.id].afterShowForm : false,
  7184. onBeforeInit = $.isFunction(rp_ge[$t.p.id].beforeInitData) ? rp_ge[$t.p.id].beforeInitData : false,
  7185. onInitializeForm = $.isFunction(rp_ge[$t.p.id].onInitializeForm) ? rp_ge[$t.p.id].onInitializeForm : false,
  7186. showFrm = true,
  7187. maxCols = 1, maxRows=0, postdata, diff, frmoper;
  7188. frmgr = $.jgrid.jqID(frmgr);
  7189. if (rowid === "new") {
  7190. rowid = "_empty";
  7191. frmoper = "add";
  7192. p.caption=rp_ge[$t.p.id].addCaption;
  7193. } else {
  7194. p.caption=rp_ge[$t.p.id].editCaption;
  7195. frmoper = "edit";
  7196. }
  7197. if(!p.recreateForm) {
  7198. if( $($t).data("formProp") ) {
  7199. $.extend(rp_ge[$(this)[0].p.id], $($t).data("formProp"));
  7200. }
  7201. }
  7202. var closeovrl = true;
  7203. if(p.checkOnUpdate && p.jqModal && !p.modal) {
  7204. closeovrl = false;
  7205. }
  7206. function getFormData(){
  7207. $(frmtb+" > tbody > tr > td .FormElement").each(function() {
  7208. var celm = $(".customelement", this);
  7209. if (celm.length) {
  7210. var elem = celm[0], nm = $(elem).attr('name');
  7211. $.each($t.p.colModel, function(){
  7212. if(this.name === nm && this.editoptions && $.isFunction(this.editoptions.custom_value)) {
  7213. try {
  7214. postdata[nm] = this.editoptions.custom_value.call($t, $("#"+$.jgrid.jqID(nm),frmtb),'get');
  7215. if (postdata[nm] === undefined) {throw "e1";}
  7216. } catch (e) {
  7217. if (e==="e1") {$.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose);}
  7218. else {$.jgrid.info_dialog($.jgrid.errors.errcap,e.message,$.jgrid.edit.bClose);}
  7219. }
  7220. return true;
  7221. }
  7222. });
  7223. } else {
  7224. switch ($(this).get(0).type) {
  7225. case "checkbox":
  7226. if($(this).is(":checked")) {
  7227. postdata[this.name]= $(this).val();
  7228. }else {
  7229. var ofv = $(this).attr("offval");
  7230. postdata[this.name]= ofv;
  7231. }
  7232. break;
  7233. case "select-one":
  7234. postdata[this.name]= $("option:selected",this).val();
  7235. break;
  7236. case "select-multiple":
  7237. postdata[this.name]= $(this).val();
  7238. if(postdata[this.name]) {postdata[this.name] = postdata[this.name].join(",");}
  7239. else {postdata[this.name] ="";}
  7240. var selectedText = [];
  7241. $("option:selected",this).each(
  7242. function(i,selected){
  7243. selectedText[i] = $(selected).text();
  7244. }
  7245. );
  7246. break;
  7247. case "password":
  7248. case "text":
  7249. case "textarea":
  7250. case "button":
  7251. postdata[this.name] = $(this).val();
  7252. break;
  7253. }
  7254. if($t.p.autoencode) {postdata[this.name] = $.jgrid.htmlEncode(postdata[this.name]);}
  7255. }
  7256. });
  7257. return true;
  7258. }
  7259. function createData(rowid,obj,tb,maxcols){
  7260. var nm, hc,trdata, cnt=0,tmp, dc,elc, retpos=[], ind=false,
  7261. tdtmpl = "<td class='CaptionTD'>&#160;</td><td class='DataTD'>&#160;</td>", tmpl="", i; //*2
  7262. for (i =1; i<=maxcols;i++) {
  7263. tmpl += tdtmpl;
  7264. }
  7265. if(rowid !== '_empty') {
  7266. ind = $(obj).jqGrid("getInd",rowid);
  7267. }
  7268. $(obj.p.colModel).each( function(i) {
  7269. nm = this.name;
  7270. // hidden fields are included in the form
  7271. if(this.editrules && this.editrules.edithidden === true) {
  7272. hc = false;
  7273. } else {
  7274. hc = this.hidden === true ? true : false;
  7275. }
  7276. dc = hc ? "style='display:none'" : "";
  7277. if ( nm !== 'cb' && nm !== 'subgrid' && this.editable===true && nm !== 'rn') {
  7278. if(ind === false) {
  7279. tmp = "";
  7280. } else {
  7281. if(nm === obj.p.ExpandColumn && obj.p.treeGrid === true) {
  7282. tmp = $("td[role='gridcell']:eq("+i+")",obj.rows[ind]).text();
  7283. } else {
  7284. try {
  7285. tmp = $.unformat.call(obj, $("td[role='gridcell']:eq("+i+")",obj.rows[ind]),{rowId:rowid, colModel:this},i);
  7286. } catch (_) {
  7287. tmp = (this.edittype && this.edittype === "textarea") ? $("td[role='gridcell']:eq("+i+")",obj.rows[ind]).text() : $("td[role='gridcell']:eq("+i+")",obj.rows[ind]).html();
  7288. }
  7289. if(!tmp || tmp === "&nbsp;" || tmp === "&#160;" || (tmp.length===1 && tmp.charCodeAt(0)===160) ) {tmp='';}
  7290. }
  7291. }
  7292. var opt = $.extend({}, this.editoptions || {} ,{id:nm,name:nm, rowId: rowid}),
  7293. frmopt = $.extend({}, {elmprefix:'',elmsuffix:'',rowabove:false,rowcontent:''}, this.formoptions || {}),
  7294. rp = parseInt(frmopt.rowpos,10) || cnt+1,
  7295. cp = parseInt((parseInt(frmopt.colpos,10) || 1)*2,10);
  7296. if(rowid === "_empty" && opt.defaultValue ) {
  7297. tmp = $.isFunction(opt.defaultValue) ? opt.defaultValue.call($t) : opt.defaultValue;
  7298. }
  7299. if(!this.edittype) {this.edittype = "text";}
  7300. if($t.p.autoencode) {tmp = $.jgrid.htmlDecode(tmp);}
  7301. elc = $.jgrid.createEl.call($t,this.edittype,opt,tmp,false,$.extend({},$.jgrid.ajaxOptions,obj.p.ajaxSelectOptions || {}));
  7302. //if(tmp === "" && this.edittype == "checkbox") {tmp = $(elc).attr("offval");}
  7303. //if(tmp === "" && this.edittype == "select") {tmp = $("option:eq(0)",elc).text();}
  7304. if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {rp_ge[$t.p.id]._savedData[nm] = tmp;}
  7305. $(elc).addClass("FormElement");
  7306. if( $.inArray(this.edittype, ['text','textarea','password','select']) > -1) {
  7307. $(elc).addClass("ui-widget-content ui-corner-all");
  7308. }
  7309. trdata = $(tb).find("tr[rowpos="+rp+"]");
  7310. if(frmopt.rowabove) {
  7311. var newdata = $("<tr><td class='contentinfo' colspan='"+(maxcols*2)+"'>"+frmopt.rowcontent+"</td></tr>");
  7312. $(tb).append(newdata);
  7313. newdata[0].rp = rp;
  7314. }
  7315. if ( trdata.length===0 ) {
  7316. trdata = $("<tr "+dc+" rowpos='"+rp+"'></tr>").addClass("FormData").attr("id","tr_"+nm);
  7317. $(trdata).append(tmpl);
  7318. $(tb).append(trdata);
  7319. trdata[0].rp = rp;
  7320. }
  7321. $("td:eq("+(cp-2)+")",trdata[0]).html(frmopt.label === undefined ? obj.p.colNames[i]: frmopt.label);
  7322. $("td:eq("+(cp-1)+")",trdata[0]).append(frmopt.elmprefix).append(elc).append(frmopt.elmsuffix);
  7323. if(this.edittype==='custom' && $.isFunction(opt.custom_value) ) {
  7324. opt.custom_value.call($t, $("#"+nm,"#"+frmgr),'set',tmp);
  7325. }
  7326. $.jgrid.bindEv.call($t, elc, opt);
  7327. retpos[cnt] = i;
  7328. cnt++;
  7329. }
  7330. });
  7331. if( cnt > 0) {
  7332. 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>");
  7333. idrow[0].rp = cnt+999;
  7334. $(tb).append(idrow);
  7335. if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {rp_ge[$t.p.id]._savedData[obj.p.id+"_id"] = rowid;}
  7336. }
  7337. return retpos;
  7338. }
  7339. function fillData(rowid,obj,fmid){
  7340. var nm,cnt=0,tmp, fld,opt,vl,vlc;
  7341. 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;}
  7342. var cm = obj.p.colModel;
  7343. if(rowid === '_empty') {
  7344. $(cm).each(function(){
  7345. nm = this.name;
  7346. opt = $.extend({}, this.editoptions || {} );
  7347. fld = $("#"+$.jgrid.jqID(nm),"#"+fmid);
  7348. if(fld && fld.length && fld[0] !== null) {
  7349. vl = "";
  7350. if(this.edittype === 'custom' && $.isFunction(opt.custom_value)) {
  7351. opt.custom_value.call($t, $("#"+nm,"#"+fmid),'set',vl);
  7352. } else if(opt.defaultValue ) {
  7353. vl = $.isFunction(opt.defaultValue) ? opt.defaultValue.call($t) : opt.defaultValue;
  7354. if(fld[0].type==='checkbox') {
  7355. vlc = vl.toLowerCase();
  7356. if(vlc.search(/(false|f|0|no|n|off|undefined)/i)<0 && vlc!=="") {
  7357. fld[0].checked = true;
  7358. fld[0].defaultChecked = true;
  7359. fld[0].value = vl;
  7360. } else {
  7361. fld[0].checked = false;
  7362. fld[0].defaultChecked = false;
  7363. }
  7364. } else {fld.val(vl);}
  7365. } else {
  7366. if( fld[0].type==='checkbox' ) {
  7367. fld[0].checked = false;
  7368. fld[0].defaultChecked = false;
  7369. vl = $(fld).attr("offval");
  7370. } else if (fld[0].type && fld[0].type.substr(0,6)==='select') {
  7371. fld[0].selectedIndex = 0;
  7372. } else {
  7373. fld.val(vl);
  7374. }
  7375. }
  7376. if(rp_ge[$t.p.id].checkOnSubmit===true || rp_ge[$t.p.id].checkOnUpdate) {rp_ge[$t.p.id]._savedData[nm] = vl;}
  7377. }
  7378. });
  7379. $("#id_g","#"+fmid).val(rowid);
  7380. return;
  7381. }
  7382. var tre = $(obj).jqGrid("getInd",rowid,true);
  7383. if(!tre) {return;}
  7384. $('td[role="gridcell"]',tre).each( function(i) {
  7385. nm = cm[i].name;
  7386. // hidden fields are included in the form
  7387. if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn' && cm[i].editable===true) {
  7388. if(nm === obj.p.ExpandColumn && obj.p.treeGrid === true) {
  7389. tmp = $(this).text();
  7390. } else {
  7391. try {
  7392. tmp = $.unformat.call(obj, $(this),{rowId:rowid, colModel:cm[i]},i);
  7393. } catch (_) {
  7394. tmp = cm[i].edittype==="textarea" ? $(this).text() : $(this).html();
  7395. }
  7396. }
  7397. if($t.p.autoencode) {tmp = $.jgrid.htmlDecode(tmp);}
  7398. if(rp_ge[$t.p.id].checkOnSubmit===true || rp_ge[$t.p.id].checkOnUpdate) {rp_ge[$t.p.id]._savedData[nm] = tmp;}
  7399. nm = $.jgrid.jqID(nm);
  7400. switch (cm[i].edittype) {
  7401. case "password":
  7402. case "text":
  7403. case "button" :
  7404. case "image":
  7405. case "textarea":
  7406. if(tmp === "&nbsp;" || tmp === "&#160;" || (tmp.length===1 && tmp.charCodeAt(0)===160) ) {tmp='';}
  7407. $("#"+nm,"#"+fmid).val(tmp);
  7408. break;
  7409. case "select":
  7410. var opv = tmp.split(",");
  7411. opv = $.map(opv,function(n){return $.trim(n);});
  7412. $("#"+nm+" option","#"+fmid).each(function(){
  7413. if (!cm[i].editoptions.multiple && ($.trim(tmp) === $.trim($(this).text()) || opv[0] === $.trim($(this).text()) || opv[0] === $.trim($(this).val())) ){
  7414. this.selected= true;
  7415. } else if (cm[i].editoptions.multiple){
  7416. if( $.inArray($.trim($(this).text()), opv ) > -1 || $.inArray($.trim($(this).val()), opv ) > -1 ){
  7417. this.selected = true;
  7418. }else{
  7419. this.selected = false;
  7420. }
  7421. } else {
  7422. this.selected = false;
  7423. }
  7424. });
  7425. break;
  7426. case "checkbox":
  7427. tmp = String(tmp);
  7428. if(cm[i].editoptions && cm[i].editoptions.value) {
  7429. var cb = cm[i].editoptions.value.split(":");
  7430. if(cb[0] === tmp) {
  7431. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']({"checked":true, "defaultChecked" : true});
  7432. } else {
  7433. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']({"checked":false, "defaultChecked" : false});
  7434. }
  7435. } else {
  7436. tmp = tmp.toLowerCase();
  7437. if(tmp.search(/(false|f|0|no|n|off|undefined)/i)<0 && tmp!=="") {
  7438. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("checked",true);
  7439. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("defaultChecked",true); //ie
  7440. } else {
  7441. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("checked", false);
  7442. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("defaultChecked", false); //ie
  7443. }
  7444. }
  7445. break;
  7446. case 'custom' :
  7447. try {
  7448. if(cm[i].editoptions && $.isFunction(cm[i].editoptions.custom_value)) {
  7449. cm[i].editoptions.custom_value.call($t, $("#"+nm,"#"+fmid),'set',tmp);
  7450. } else {throw "e1";}
  7451. } catch (e) {
  7452. if (e==="e1") {$.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.nodefined,$.jgrid.edit.bClose);}
  7453. else {$.jgrid.info_dialog($.jgrid.errors.errcap,e.message,$.jgrid.edit.bClose);}
  7454. }
  7455. break;
  7456. }
  7457. cnt++;
  7458. }
  7459. });
  7460. if(cnt>0) {$("#id_g",frmtb).val(rowid);}
  7461. }
  7462. function setNulls() {
  7463. $.each($t.p.colModel, function(i,n){
  7464. if(n.editoptions && n.editoptions.NullIfEmpty === true) {
  7465. if(postdata.hasOwnProperty(n.name) && postdata[n.name] === "") {
  7466. postdata[n.name] = 'null';
  7467. }
  7468. }
  7469. });
  7470. }
  7471. function postIt() {
  7472. var copydata, ret=[true,"",""], onCS = {}, opers = $t.p.prmNames, idname, oper, key, selr, i, url;
  7473. var retvals = $($t).triggerHandler("jqGridAddEditBeforeCheckValues", [$("#"+frmgr), frmoper]);
  7474. if(retvals && typeof retvals === 'object') {postdata = retvals;}
  7475. if($.isFunction(rp_ge[$t.p.id].beforeCheckValues)) {
  7476. retvals = rp_ge[$t.p.id].beforeCheckValues.call($t, postdata,$("#"+frmgr),frmoper);
  7477. if(retvals && typeof retvals === 'object') {postdata = retvals;}
  7478. }
  7479. for( key in postdata ){
  7480. if(postdata.hasOwnProperty(key)) {
  7481. ret = $.jgrid.checkValues.call($t,postdata[key],key);
  7482. if(ret[0] === false) {break;}
  7483. }
  7484. }
  7485. setNulls();
  7486. if(ret[0]) {
  7487. onCS = $($t).triggerHandler("jqGridAddEditClickSubmit", [rp_ge[$t.p.id], postdata, frmoper]);
  7488. if( onCS === undefined && $.isFunction( rp_ge[$t.p.id].onclickSubmit)) {
  7489. onCS = rp_ge[$t.p.id].onclickSubmit.call($t, rp_ge[$t.p.id], postdata, frmoper) || {};
  7490. }
  7491. ret = $($t).triggerHandler("jqGridAddEditBeforeSubmit", [postdata, $("#"+frmgr), frmoper]);
  7492. if(ret === undefined) {
  7493. ret = [true,"",""];
  7494. }
  7495. if( ret[0] && $.isFunction(rp_ge[$t.p.id].beforeSubmit)) {
  7496. ret = rp_ge[$t.p.id].beforeSubmit.call($t,postdata,$("#"+frmgr), frmoper);
  7497. }
  7498. }
  7499. if(ret[0] && !rp_ge[$t.p.id].processing) {
  7500. rp_ge[$t.p.id].processing = true;
  7501. $("#sData", frmtb+"_2").addClass('ui-state-active');
  7502. url = rp_ge[$t.p.id].url || $($t).jqGrid('getGridParam','editurl');
  7503. oper = opers.oper;
  7504. idname = url === 'clientArray' ? $t.p.keyName : opers.id;
  7505. // we add to pos data array the action - the name is oper
  7506. postdata[oper] = ($.trim(postdata[$t.p.id+"_id"]) === "_empty") ? opers.addoper : opers.editoper;
  7507. if(postdata[oper] !== opers.addoper) {
  7508. postdata[idname] = postdata[$t.p.id+"_id"];
  7509. } else {
  7510. // check to see if we have allredy this field in the form and if yes lieve it
  7511. if( postdata[idname] === undefined ) {postdata[idname] = postdata[$t.p.id+"_id"];}
  7512. }
  7513. delete postdata[$t.p.id+"_id"];
  7514. postdata = $.extend(postdata,rp_ge[$t.p.id].editData,onCS);
  7515. if($t.p.treeGrid === true) {
  7516. if(postdata[oper] === opers.addoper) {
  7517. selr = $($t).jqGrid("getGridParam", 'selrow');
  7518. var tr_par_id = $t.p.treeGridModel === 'adjacency' ? $t.p.treeReader.parent_id_field : 'parent_id';
  7519. postdata[tr_par_id] = selr;
  7520. }
  7521. for(i in $t.p.treeReader){
  7522. if($t.p.treeReader.hasOwnProperty(i)) {
  7523. var itm = $t.p.treeReader[i];
  7524. if(postdata.hasOwnProperty(itm)) {
  7525. if(postdata[oper] === opers.addoper && i === 'parent_id_field') {continue;}
  7526. delete postdata[itm];
  7527. }
  7528. }
  7529. }
  7530. }
  7531. postdata[idname] = $.jgrid.stripPref($t.p.idPrefix, postdata[idname]);
  7532. var ajaxOptions = $.extend({
  7533. url: url,
  7534. type: rp_ge[$t.p.id].mtype,
  7535. data: $.isFunction(rp_ge[$t.p.id].serializeEditData) ? rp_ge[$t.p.id].serializeEditData.call($t,postdata) : postdata,
  7536. complete:function(data,status){
  7537. var key;
  7538. $("#sData", frmtb+"_2").removeClass('ui-state-active');
  7539. postdata[idname] = $t.p.idPrefix + postdata[idname];
  7540. if(data.status >= 300 && data.status !== 304) {
  7541. ret[0] = false;
  7542. ret[1] = $($t).triggerHandler("jqGridAddEditErrorTextFormat", [data, frmoper]);
  7543. if ($.isFunction(rp_ge[$t.p.id].errorTextFormat)) {
  7544. ret[1] = rp_ge[$t.p.id].errorTextFormat.call($t, data, frmoper);
  7545. } else {
  7546. ret[1] = status + " Status: '" + data.statusText + "'. Error code: " + data.status;
  7547. }
  7548. } else {
  7549. // data is posted successful
  7550. // execute aftersubmit with the returned data from server
  7551. ret = $($t).triggerHandler("jqGridAddEditAfterSubmit", [data, postdata, frmoper]);
  7552. if(ret === undefined) {
  7553. ret = [true,"",""];
  7554. }
  7555. if( ret[0] && $.isFunction(rp_ge[$t.p.id].afterSubmit) ) {
  7556. ret = rp_ge[$t.p.id].afterSubmit.call($t, data,postdata, frmoper);
  7557. }
  7558. }
  7559. if(ret[0] === false) {
  7560. $("#FormError>td",frmtb).html(ret[1]);
  7561. $("#FormError",frmtb).show();
  7562. } else {
  7563. if($t.p.autoencode) {
  7564. $.each(postdata,function(n,v){
  7565. postdata[n] = $.jgrid.htmlDecode(v);
  7566. });
  7567. }
  7568. //rp_ge[$t.p.id].reloadAfterSubmit = rp_ge[$t.p.id].reloadAfterSubmit && $t.p.datatype != "local";
  7569. // the action is add
  7570. if(postdata[oper] === opers.addoper ) {
  7571. //id processing
  7572. // user not set the id ret[2]
  7573. if(!ret[2]) {ret[2] = $.jgrid.randId();}
  7574. if(postdata[idname] == null){
  7575. postdata[idname] = ret[2];
  7576. } else {
  7577. ret[2] = postdata[idname];
  7578. }
  7579. if(rp_ge[$t.p.id].reloadAfterSubmit) {
  7580. $($t).trigger("reloadGrid");
  7581. } else {
  7582. if($t.p.treeGrid === true){
  7583. $($t).jqGrid("addChildNode",ret[2],selr,postdata );
  7584. } else {
  7585. $($t).jqGrid("addRowData",ret[2],postdata,p.addedrow);
  7586. }
  7587. }
  7588. if(rp_ge[$t.p.id].closeAfterAdd) {
  7589. if($t.p.treeGrid !== true){
  7590. $($t).jqGrid("setSelection",ret[2]);
  7591. }
  7592. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose, removemodal: rp_ge[$t.p.id].removemodal, formprop: !rp_ge[$t.p.id].recreateForm, form: rp_ge[$t.p.id].form});
  7593. } else if (rp_ge[$t.p.id].clearAfterAdd) {
  7594. fillData("_empty",$t,frmgr);
  7595. }
  7596. } else {
  7597. // the action is update
  7598. if(rp_ge[$t.p.id].reloadAfterSubmit) {
  7599. $($t).trigger("reloadGrid");
  7600. if( !rp_ge[$t.p.id].closeAfterEdit ) {setTimeout(function(){$($t).jqGrid("setSelection",postdata[idname]);},1000);}
  7601. } else {
  7602. if($t.p.treeGrid === true) {
  7603. $($t).jqGrid("setTreeRow", postdata[idname],postdata);
  7604. } else {
  7605. $($t).jqGrid("setRowData", postdata[idname],postdata);
  7606. }
  7607. }
  7608. if(rp_ge[$t.p.id].closeAfterEdit) {$.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose, removemodal: rp_ge[$t.p.id].removemodal, formprop: !rp_ge[$t.p.id].recreateForm, form: rp_ge[$t.p.id].form});}
  7609. }
  7610. if($.isFunction(rp_ge[$t.p.id].afterComplete)) {
  7611. copydata = data;
  7612. setTimeout(function(){
  7613. $($t).triggerHandler("jqGridAddEditAfterComplete", [copydata, postdata, $("#"+frmgr), frmoper]);
  7614. rp_ge[$t.p.id].afterComplete.call($t, copydata, postdata, $("#"+frmgr), frmoper);
  7615. copydata=null;
  7616. },500);
  7617. }
  7618. if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {
  7619. $("#"+frmgr).data("disabled",false);
  7620. if(rp_ge[$t.p.id]._savedData[$t.p.id+"_id"] !== "_empty"){
  7621. for(key in rp_ge[$t.p.id]._savedData) {
  7622. if(rp_ge[$t.p.id]._savedData.hasOwnProperty(key) && postdata[key]) {
  7623. rp_ge[$t.p.id]._savedData[key] = postdata[key];
  7624. }
  7625. }
  7626. }
  7627. }
  7628. }
  7629. rp_ge[$t.p.id].processing=false;
  7630. try{$(':input:visible',"#"+frmgr)[0].focus();} catch (e){}
  7631. }
  7632. }, $.jgrid.ajaxOptions, rp_ge[$t.p.id].ajaxEditOptions );
  7633. if (!ajaxOptions.url && !rp_ge[$t.p.id].useDataProxy) {
  7634. if ($.isFunction($t.p.dataProxy)) {
  7635. rp_ge[$t.p.id].useDataProxy = true;
  7636. } else {
  7637. ret[0]=false;ret[1] += " "+$.jgrid.errors.nourl;
  7638. }
  7639. }
  7640. if (ret[0]) {
  7641. if (rp_ge[$t.p.id].useDataProxy) {
  7642. var dpret = $t.p.dataProxy.call($t, ajaxOptions, "set_"+$t.p.id);
  7643. if(dpret === undefined) {
  7644. dpret = [true, ""];
  7645. }
  7646. if(dpret[0] === false ) {
  7647. ret[0] = false;
  7648. ret[1] = dpret[1] || "Error deleting the selected row!" ;
  7649. } else {
  7650. if(ajaxOptions.data.oper === opers.addoper && rp_ge[$t.p.id].closeAfterAdd ) {
  7651. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose, removemodal: rp_ge[$t.p.id].removemodal, formprop: !rp_ge[$t.p.id].recreateForm, form: rp_ge[$t.p.id].form});
  7652. }
  7653. if(ajaxOptions.data.oper === opers.editoper && rp_ge[$t.p.id].closeAfterEdit ) {
  7654. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose, removemodal: rp_ge[$t.p.id].removemodal, formprop: !rp_ge[$t.p.id].recreateForm, form: rp_ge[$t.p.id].form});
  7655. }
  7656. }
  7657. } else {
  7658. if(ajaxOptions.url === "clientArray") {
  7659. rp_ge[$t.p.id].reloadAfterSubmit = false;
  7660. postdata = ajaxOptions.data;
  7661. ajaxOptions.complete({status:200, statusText:''},'');
  7662. } else {
  7663. $.ajax(ajaxOptions);
  7664. }
  7665. }
  7666. }
  7667. }
  7668. if(ret[0] === false) {
  7669. $("#FormError>td",frmtb).html(ret[1]);
  7670. $("#FormError",frmtb).show();
  7671. // return;
  7672. }
  7673. }
  7674. function compareData(nObj, oObj ) {
  7675. var ret = false,key;
  7676. for (key in nObj) {
  7677. if(nObj.hasOwnProperty(key) && nObj[key] != oObj[key]) {
  7678. ret = true;
  7679. break;
  7680. }
  7681. }
  7682. return ret;
  7683. }
  7684. function checkUpdates () {
  7685. var stat = true;
  7686. $("#FormError",frmtb).hide();
  7687. if(rp_ge[$t.p.id].checkOnUpdate) {
  7688. postdata = {};
  7689. getFormData();
  7690. diff = compareData(postdata,rp_ge[$t.p.id]._savedData);
  7691. if(diff) {
  7692. $("#"+frmgr).data("disabled",true);
  7693. $(".confirm","#"+IDs.themodal).show();
  7694. stat = false;
  7695. }
  7696. }
  7697. return stat;
  7698. }
  7699. function restoreInline()
  7700. {
  7701. var i;
  7702. if (rowid !== "_empty" && $t.p.savedRow !== undefined && $t.p.savedRow.length > 0 && $.isFunction($.fn.jqGrid.restoreRow)) {
  7703. for (i=0;i<$t.p.savedRow.length;i++) {
  7704. if ($t.p.savedRow[i].id == rowid) {
  7705. $($t).jqGrid('restoreRow',rowid);
  7706. break;
  7707. }
  7708. }
  7709. }
  7710. }
  7711. function updateNav(cr, posarr){
  7712. var totr = posarr[1].length-1;
  7713. if (cr===0) {
  7714. $("#pData",frmtb+"_2").addClass('ui-state-disabled');
  7715. } else if( posarr[1][cr-1] !== undefined && $("#"+$.jgrid.jqID(posarr[1][cr-1])).hasClass('ui-state-disabled')) {
  7716. $("#pData",frmtb+"_2").addClass('ui-state-disabled');
  7717. } else {
  7718. $("#pData",frmtb+"_2").removeClass('ui-state-disabled');
  7719. }
  7720. if (cr===totr) {
  7721. $("#nData",frmtb+"_2").addClass('ui-state-disabled');
  7722. } else if( posarr[1][cr+1] !== undefined && $("#"+$.jgrid.jqID(posarr[1][cr+1])).hasClass('ui-state-disabled')) {
  7723. $("#nData",frmtb+"_2").addClass('ui-state-disabled');
  7724. } else {
  7725. $("#nData",frmtb+"_2").removeClass('ui-state-disabled');
  7726. }
  7727. }
  7728. function getCurrPos() {
  7729. var rowsInGrid = $($t).jqGrid("getDataIDs"),
  7730. selrow = $("#id_g",frmtb).val(),
  7731. pos = $.inArray(selrow,rowsInGrid);
  7732. return [pos,rowsInGrid];
  7733. }
  7734. 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",
  7735. dw = isNaN(rp_ge[$(this)[0].p.id].datawidth) ? rp_ge[$(this)[0].p.id].datawidth : rp_ge[$(this)[0].p.id].datawidth+"px",
  7736. frm = $("<form name='FormPost' id='"+frmgr+"' class='FormGrid' onSubmit='return false;' style='width:"+dw+";overflow:auto;position:relative;height:"+dh+";'></form>").data("disabled",false),
  7737. tbl = $("<table id='"+frmtborg+"' class='EditTable' cellspacing='0' cellpadding='0' border='0'><tbody></tbody></table>");
  7738. $($t.p.colModel).each( function() {
  7739. var fmto = this.formoptions;
  7740. maxCols = Math.max(maxCols, fmto ? fmto.colpos || 0 : 0 );
  7741. maxRows = Math.max(maxRows, fmto ? fmto.rowpos || 0 : 0 );
  7742. });
  7743. $(frm).append(tbl);
  7744. var flr = $("<tr id='FormError' style='display:none'><td class='ui-state-error' colspan='"+(maxCols*2)+"'></td></tr>");
  7745. flr[0].rp = 0;
  7746. $(tbl).append(flr);
  7747. //topinfo
  7748. flr = $("<tr style='display:none' class='tinfo'><td class='topinfo' colspan='"+(maxCols*2)+"'>"+rp_ge[$t.p.id].topinfo+"</td></tr>");
  7749. flr[0].rp = 0;
  7750. $(tbl).append(flr);
  7751. showFrm = $($t).triggerHandler("jqGridAddEditBeforeInitData", [frm, frmoper]);
  7752. if(showFrm === undefined) {
  7753. showFrm = true;
  7754. }
  7755. if(showFrm && onBeforeInit) {
  7756. showFrm = onBeforeInit.call($t,frm, frmoper);
  7757. }
  7758. if(showFrm === false) {return;}
  7759. restoreInline();
  7760. // set the id.
  7761. // use carefull only to change here colproperties.
  7762. // create data
  7763. var rtlb = $t.p.direction === "rtl" ? true :false,
  7764. bp = rtlb ? "nData" : "pData",
  7765. bn = rtlb ? "pData" : "nData";
  7766. createData(rowid,$t,tbl,maxCols);
  7767. // buttons at footer
  7768. 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>",
  7769. bN = "<a id='"+bn+"' class='fm-button ui-state-default ui-corner-right'><span class='ui-icon ui-icon-triangle-1-e'></span></a>",
  7770. bS ="<a id='sData' class='fm-button ui-state-default ui-corner-all'>"+p.bSubmit+"</a>",
  7771. bC ="<a id='cData' class='fm-button ui-state-default ui-corner-all'>"+p.bCancel+"</a>";
  7772. 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>";
  7773. bt += "<tr style='display:none' class='binfo'><td class='bottominfo' colspan='2'>"+rp_ge[$t.p.id].bottominfo+"</td></tr>";
  7774. bt += "</tbody></table>";
  7775. if(maxRows > 0) {
  7776. var sd=[];
  7777. $.each($(tbl)[0].rows,function(i,r){
  7778. sd[i] = r;
  7779. });
  7780. sd.sort(function(a,b){
  7781. if(a.rp > b.rp) {return 1;}
  7782. if(a.rp < b.rp) {return -1;}
  7783. return 0;
  7784. });
  7785. $.each(sd, function(index, row) {
  7786. $('tbody',tbl).append(row);
  7787. });
  7788. }
  7789. p.gbox = "#gbox_"+$.jgrid.jqID(gID);
  7790. var cle = false;
  7791. if(p.closeOnEscape===true){
  7792. p.closeOnEscape = false;
  7793. cle = true;
  7794. }
  7795. var tms = $("<div></div>").append(frm).append(bt);
  7796. $.jgrid.createModal(IDs,tms, rp_ge[$(this)[0].p.id] ,"#gview_"+$.jgrid.jqID($t.p.id),$("#gbox_"+$.jgrid.jqID($t.p.id))[0]);
  7797. if(rtlb) {
  7798. $("#pData, #nData",frmtb+"_2").css("float","right");
  7799. $(".EditButton",frmtb+"_2").css("text-align","left");
  7800. }
  7801. if(rp_ge[$t.p.id].topinfo) {$(".tinfo",frmtb).show();}
  7802. if(rp_ge[$t.p.id].bottominfo) {$(".binfo",frmtb+"_2").show();}
  7803. tms = null;bt=null;
  7804. $("#"+$.jgrid.jqID(IDs.themodal)).keydown( function( e ) {
  7805. var wkey = e.target;
  7806. if ($("#"+frmgr).data("disabled")===true ) {return false;}//??
  7807. if(rp_ge[$t.p.id].savekey[0] === true && e.which === rp_ge[$t.p.id].savekey[1]) { // save
  7808. if(wkey.tagName !== "TEXTAREA") {
  7809. $("#sData", frmtb+"_2").trigger("click");
  7810. return false;
  7811. }
  7812. }
  7813. if(e.which === 27) {
  7814. if(!checkUpdates()) {return false;}
  7815. if(cle) {$.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:p.gbox,jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose, removemodal: rp_ge[$t.p.id].removemodal, formprop: !rp_ge[$t.p.id].recreateForm, form: rp_ge[$t.p.id].form});}
  7816. return false;
  7817. }
  7818. if(rp_ge[$t.p.id].navkeys[0]===true) {
  7819. if($("#id_g",frmtb).val() === "_empty") {return true;}
  7820. if(e.which === rp_ge[$t.p.id].navkeys[1]){ //up
  7821. $("#pData", frmtb+"_2").trigger("click");
  7822. return false;
  7823. }
  7824. if(e.which === rp_ge[$t.p.id].navkeys[2]){ //down
  7825. $("#nData", frmtb+"_2").trigger("click");
  7826. return false;
  7827. }
  7828. }
  7829. });
  7830. if(p.checkOnUpdate) {
  7831. $("a.ui-jqdialog-titlebar-close span","#"+$.jgrid.jqID(IDs.themodal)).removeClass("jqmClose");
  7832. $("a.ui-jqdialog-titlebar-close","#"+$.jgrid.jqID(IDs.themodal)).unbind("click")
  7833. .click(function(){
  7834. if(!checkUpdates()) {return false;}
  7835. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose, removemodal: rp_ge[$t.p.id].removemodal, formprop: !rp_ge[$t.p.id].recreateForm, form: rp_ge[$t.p.id].form});
  7836. return false;
  7837. });
  7838. }
  7839. p.saveicon = $.extend([true,"left","ui-icon-disk"],p.saveicon);
  7840. p.closeicon = $.extend([true,"left","ui-icon-close"],p.closeicon);
  7841. // beforeinitdata after creation of the form
  7842. if(p.saveicon[0]===true) {
  7843. $("#sData",frmtb+"_2").addClass(p.saveicon[1] === "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  7844. .append("<span class='ui-icon "+p.saveicon[2]+"'></span>");
  7845. }
  7846. if(p.closeicon[0]===true) {
  7847. $("#cData",frmtb+"_2").addClass(p.closeicon[1] === "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  7848. .append("<span class='ui-icon "+p.closeicon[2]+"'></span>");
  7849. }
  7850. if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {
  7851. bS ="<a id='sNew' class='fm-button ui-state-default ui-corner-all' style='z-index:1002'>"+p.bYes+"</a>";
  7852. bN ="<a id='nNew' class='fm-button ui-state-default ui-corner-all' style='z-index:1002'>"+p.bNo+"</a>";
  7853. bC ="<a id='cNew' class='fm-button ui-state-default ui-corner-all' style='z-index:1002'>"+p.bExit+"</a>";
  7854. var zI = p.zIndex || 999;zI ++;
  7855. $("<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);
  7856. $("#sNew","#"+$.jgrid.jqID(IDs.themodal)).click(function(){
  7857. postIt();
  7858. $("#"+frmgr).data("disabled",false);
  7859. $(".confirm","#"+$.jgrid.jqID(IDs.themodal)).hide();
  7860. return false;
  7861. });
  7862. $("#nNew","#"+$.jgrid.jqID(IDs.themodal)).click(function(){
  7863. $(".confirm","#"+$.jgrid.jqID(IDs.themodal)).hide();
  7864. $("#"+frmgr).data("disabled",false);
  7865. setTimeout(function(){$(":input:visible","#"+frmgr)[0].focus();},0);
  7866. return false;
  7867. });
  7868. $("#cNew","#"+$.jgrid.jqID(IDs.themodal)).click(function(){
  7869. $(".confirm","#"+$.jgrid.jqID(IDs.themodal)).hide();
  7870. $("#"+frmgr).data("disabled",false);
  7871. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose, removemodal: rp_ge[$t.p.id].removemodal, formprop: !rp_ge[$t.p.id].recreateForm, form: rp_ge[$t.p.id].form});
  7872. return false;
  7873. });
  7874. }
  7875. // here initform - only once
  7876. $($t).triggerHandler("jqGridAddEditInitializeForm", [$("#"+frmgr), frmoper]);
  7877. if(onInitializeForm) {onInitializeForm.call($t,$("#"+frmgr), frmoper);}
  7878. if(rowid==="_empty" || !rp_ge[$t.p.id].viewPagerButtons) {$("#pData,#nData",frmtb+"_2").hide();} else {$("#pData,#nData",frmtb+"_2").show();}
  7879. $($t).triggerHandler("jqGridAddEditBeforeShowForm", [$("#"+frmgr), frmoper]);
  7880. if(onBeforeShow) { onBeforeShow.call($t, $("#"+frmgr), frmoper);}
  7881. $("#"+$.jgrid.jqID(IDs.themodal)).data("onClose",rp_ge[$t.p.id].onClose);
  7882. $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{
  7883. gbox:"#gbox_"+$.jgrid.jqID(gID),
  7884. jqm:p.jqModal,
  7885. overlay: p.overlay,
  7886. modal:p.modal,
  7887. overlayClass: p.overlayClass,
  7888. onHide : function(h) {
  7889. var fh = $('#editmod'+gID)[0].style.height;
  7890. if(fh.indexOf("px") > -1 ) {
  7891. fh = parseFloat(fh);
  7892. }
  7893. $($t).data("formProp", {
  7894. top:parseFloat($(h.w).css("top")),
  7895. left : parseFloat($(h.w).css("left")),
  7896. width : $(h.w).width(),
  7897. height : fh,
  7898. dataheight : $("#"+frmgr).height(),
  7899. datawidth: $("#"+frmgr).width()
  7900. });
  7901. h.w.remove();
  7902. if(h.o) {h.o.remove();}
  7903. }
  7904. });
  7905. if(!closeovrl) {
  7906. $("." + $.jgrid.jqID(p.overlayClass)).click(function(){
  7907. if(!checkUpdates()) {return false;}
  7908. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose, removemodal: rp_ge[$t.p.id].removemodal, formprop: !rp_ge[$t.p.id].recreateForm, form: rp_ge[$t.p.id].form});
  7909. return false;
  7910. });
  7911. }
  7912. $(".fm-button","#"+$.jgrid.jqID(IDs.themodal)).hover(
  7913. function(){$(this).addClass('ui-state-hover');},
  7914. function(){$(this).removeClass('ui-state-hover');}
  7915. );
  7916. $("#sData", frmtb+"_2").click(function(){
  7917. postdata = {};
  7918. $("#FormError",frmtb).hide();
  7919. // all depend on ret array
  7920. //ret[0] - succes
  7921. //ret[1] - msg if not succes
  7922. //ret[2] - the id that will be set if reload after submit false
  7923. getFormData();
  7924. if(postdata[$t.p.id+"_id"] === "_empty") {postIt();}
  7925. else if(p.checkOnSubmit===true ) {
  7926. diff = compareData(postdata,rp_ge[$t.p.id]._savedData);
  7927. if(diff) {
  7928. $("#"+frmgr).data("disabled",true);
  7929. $(".confirm","#"+$.jgrid.jqID(IDs.themodal)).show();
  7930. } else {
  7931. postIt();
  7932. }
  7933. } else {
  7934. postIt();
  7935. }
  7936. return false;
  7937. });
  7938. $("#cData", frmtb+"_2").click(function(){
  7939. if(!checkUpdates()) {return false;}
  7940. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose, removemodal: rp_ge[$t.p.id].removemodal, formprop: !rp_ge[$t.p.id].recreateForm, form: rp_ge[$t.p.id].form});
  7941. return false;
  7942. });
  7943. $("#nData", frmtb+"_2").click(function(){
  7944. if(!checkUpdates()) {return false;}
  7945. $("#FormError",frmtb).hide();
  7946. var npos = getCurrPos();
  7947. npos[0] = parseInt(npos[0],10);
  7948. if(npos[0] !== -1 && npos[1][npos[0]+1]) {
  7949. $($t).triggerHandler("jqGridAddEditClickPgButtons", ['next',$("#"+frmgr),npos[1][npos[0]]]);
  7950. var nposret;
  7951. if($.isFunction(p.onclickPgButtons)) {
  7952. nposret = p.onclickPgButtons.call($t, 'next',$("#"+frmgr),npos[1][npos[0]]);
  7953. if( nposret !== undefined && nposret === false ) {return false;}
  7954. }
  7955. if( $("#"+$.jgrid.jqID(npos[1][npos[0]+1])).hasClass('ui-state-disabled')) {return false;}
  7956. fillData(npos[1][npos[0]+1],$t,frmgr);
  7957. $($t).jqGrid("setSelection",npos[1][npos[0]+1]);
  7958. $($t).triggerHandler("jqGridAddEditAfterClickPgButtons", ['next',$("#"+frmgr),npos[1][npos[0]]]);
  7959. if($.isFunction(p.afterclickPgButtons)) {
  7960. p.afterclickPgButtons.call($t, 'next',$("#"+frmgr),npos[1][npos[0]+1]);
  7961. }
  7962. updateNav(npos[0]+1,npos);
  7963. }
  7964. return false;
  7965. });
  7966. $("#pData", frmtb+"_2").click(function(){
  7967. if(!checkUpdates()) {return false;}
  7968. $("#FormError",frmtb).hide();
  7969. var ppos = getCurrPos();
  7970. if(ppos[0] !== -1 && ppos[1][ppos[0]-1]) {
  7971. $($t).triggerHandler("jqGridAddEditClickPgButtons", ['prev',$("#"+frmgr),ppos[1][ppos[0]]]);
  7972. var pposret;
  7973. if($.isFunction(p.onclickPgButtons)) {
  7974. pposret = p.onclickPgButtons.call($t, 'prev',$("#"+frmgr),ppos[1][ppos[0]]);
  7975. if( pposret !== undefined && pposret === false ) {return false;}
  7976. }
  7977. if( $("#"+$.jgrid.jqID(ppos[1][ppos[0]-1])).hasClass('ui-state-disabled')) {return false;}
  7978. fillData(ppos[1][ppos[0]-1],$t,frmgr);
  7979. $($t).jqGrid("setSelection",ppos[1][ppos[0]-1]);
  7980. $($t).triggerHandler("jqGridAddEditAfterClickPgButtons", ['prev',$("#"+frmgr),ppos[1][ppos[0]]]);
  7981. if($.isFunction(p.afterclickPgButtons)) {
  7982. p.afterclickPgButtons.call($t, 'prev',$("#"+frmgr),ppos[1][ppos[0]-1]);
  7983. }
  7984. updateNav(ppos[0]-1,ppos);
  7985. }
  7986. return false;
  7987. });
  7988. $($t).triggerHandler("jqGridAddEditAfterShowForm", [$("#"+frmgr), frmoper]);
  7989. if(onAfterShow) { onAfterShow.call($t, $("#"+frmgr), frmoper); }
  7990. var posInit =getCurrPos();
  7991. updateNav(posInit[0],posInit);
  7992. });
  7993. },
  7994. viewGridRow : function(rowid, p){
  7995. p = $.extend(true, {
  7996. top : 0,
  7997. left: 0,
  7998. width: 0,
  7999. datawidth: 'auto',
  8000. height: 'auto',
  8001. dataheight: 'auto',
  8002. modal: false,
  8003. overlay: 30,
  8004. drag: true,
  8005. resize: true,
  8006. jqModal: true,
  8007. closeOnEscape : false,
  8008. labelswidth: '30%',
  8009. closeicon: [],
  8010. navkeys: [false,38,40],
  8011. onClose: null,
  8012. beforeShowForm : null,
  8013. beforeInitData : null,
  8014. viewPagerButtons : true,
  8015. recreateForm : false,
  8016. removemodal: true,
  8017. form: 'view'
  8018. }, $.jgrid.view, p || {});
  8019. rp_ge[$(this)[0].p.id] = p;
  8020. return this.each(function(){
  8021. var $t = this;
  8022. if (!$t.grid || !rowid) {return;}
  8023. var gID = $t.p.id,
  8024. frmgr = "ViewGrid_"+$.jgrid.jqID( gID ), frmtb = "ViewTbl_" + $.jgrid.jqID( gID ),
  8025. frmgr_id = "ViewGrid_"+gID, frmtb_id = "ViewTbl_"+gID,
  8026. IDs = {themodal:'viewmod'+gID,modalhead:'viewhd'+gID,modalcontent:'viewcnt'+gID, scrollelm : frmgr},
  8027. onBeforeInit = $.isFunction(rp_ge[$t.p.id].beforeInitData) ? rp_ge[$t.p.id].beforeInitData : false,
  8028. showFrm = true,
  8029. maxCols = 1, maxRows=0;
  8030. if(!p.recreateForm) {
  8031. if( $($t).data("viewProp") ) {
  8032. $.extend(rp_ge[$(this)[0].p.id], $($t).data("viewProp"));
  8033. }
  8034. }
  8035. function focusaref(){ //Sfari 3 issues
  8036. if(rp_ge[$t.p.id].closeOnEscape===true || rp_ge[$t.p.id].navkeys[0]===true) {
  8037. setTimeout(function(){$(".ui-jqdialog-titlebar-close","#"+$.jgrid.jqID(IDs.modalhead)).attr("tabindex", "-1").focus();},0);
  8038. }
  8039. }
  8040. function createData(rowid,obj,tb,maxcols){
  8041. var nm, hc,trdata, cnt=0,tmp, dc, retpos=[], ind=false, i,
  8042. 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="",
  8043. tdtmpl2 = "<td class='CaptionTD form-view-label ui-widget-content'>&#160;</td><td class='DataTD form-view-data ui-widget-content'>&#160;</td>",
  8044. fmtnum = ['integer','number','currency'],max1 =0, max2=0 ,maxw,setme, viewfld;
  8045. for (i=1;i<=maxcols;i++) {
  8046. tmpl += i === 1 ? tdtmpl : tdtmpl2;
  8047. }
  8048. // find max number align rigth with property formatter
  8049. $(obj.p.colModel).each( function() {
  8050. if(this.editrules && this.editrules.edithidden === true) {
  8051. hc = false;
  8052. } else {
  8053. hc = this.hidden === true ? true : false;
  8054. }
  8055. if(!hc && this.align==='right') {
  8056. if(this.formatter && $.inArray(this.formatter,fmtnum) !== -1 ) {
  8057. max1 = Math.max(max1,parseInt(this.width,10));
  8058. } else {
  8059. max2 = Math.max(max2,parseInt(this.width,10));
  8060. }
  8061. }
  8062. });
  8063. maxw = max1 !==0 ? max1 : max2 !==0 ? max2 : 0;
  8064. ind = $(obj).jqGrid("getInd",rowid);
  8065. $(obj.p.colModel).each( function(i) {
  8066. nm = this.name;
  8067. setme = false;
  8068. // hidden fields are included in the form
  8069. if(this.editrules && this.editrules.edithidden === true) {
  8070. hc = false;
  8071. } else {
  8072. hc = this.hidden === true ? true : false;
  8073. }
  8074. dc = hc ? "style='display:none'" : "";
  8075. viewfld = (typeof this.viewable !== 'boolean') ? true : this.viewable;
  8076. if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn' && viewfld) {
  8077. if(ind === false) {
  8078. tmp = "";
  8079. } else {
  8080. if(nm === obj.p.ExpandColumn && obj.p.treeGrid === true) {
  8081. tmp = $("td:eq("+i+")",obj.rows[ind]).text();
  8082. } else {
  8083. tmp = $("td:eq("+i+")",obj.rows[ind]).html();
  8084. }
  8085. }
  8086. setme = this.align === 'right' && maxw !==0 ? true : false;
  8087. var frmopt = $.extend({},{rowabove:false,rowcontent:''}, this.formoptions || {}),
  8088. rp = parseInt(frmopt.rowpos,10) || cnt+1,
  8089. cp = parseInt((parseInt(frmopt.colpos,10) || 1)*2,10);
  8090. if(frmopt.rowabove) {
  8091. var newdata = $("<tr><td class='contentinfo' colspan='"+(maxcols*2)+"'>"+frmopt.rowcontent+"</td></tr>");
  8092. $(tb).append(newdata);
  8093. newdata[0].rp = rp;
  8094. }
  8095. trdata = $(tb).find("tr[rowpos="+rp+"]");
  8096. if ( trdata.length===0 ) {
  8097. trdata = $("<tr "+dc+" rowpos='"+rp+"'></tr>").addClass("FormData").attr("id","trv_"+nm);
  8098. $(trdata).append(tmpl);
  8099. $(tb).append(trdata);
  8100. trdata[0].rp = rp;
  8101. }
  8102. $("td:eq("+(cp-2)+")",trdata[0]).html('<b>'+ (frmopt.label === undefined ? obj.p.colNames[i]: frmopt.label)+'</b>');
  8103. $("td:eq("+(cp-1)+")",trdata[0]).append("<span>"+tmp+"</span>").attr("id","v_"+nm);
  8104. if(setme){
  8105. $("td:eq("+(cp-1)+") span",trdata[0]).css({'text-align':'right',width:maxw+"px"});
  8106. }
  8107. retpos[cnt] = i;
  8108. cnt++;
  8109. }
  8110. });
  8111. if( cnt > 0) {
  8112. 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>");
  8113. idrow[0].rp = cnt+99;
  8114. $(tb).append(idrow);
  8115. }
  8116. return retpos;
  8117. }
  8118. function fillData(rowid,obj){
  8119. var nm, hc,cnt=0,tmp,trv;
  8120. trv = $(obj).jqGrid("getInd",rowid,true);
  8121. if(!trv) {return;}
  8122. $('td',trv).each( function(i) {
  8123. nm = obj.p.colModel[i].name;
  8124. // hidden fields are included in the form
  8125. if(obj.p.colModel[i].editrules && obj.p.colModel[i].editrules.edithidden === true) {
  8126. hc = false;
  8127. } else {
  8128. hc = obj.p.colModel[i].hidden === true ? true : false;
  8129. }
  8130. if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn') {
  8131. if(nm === obj.p.ExpandColumn && obj.p.treeGrid === true) {
  8132. tmp = $(this).text();
  8133. } else {
  8134. tmp = $(this).html();
  8135. }
  8136. nm = $.jgrid.jqID("v_"+nm);
  8137. $("#"+nm+" span","#"+frmtb).html(tmp);
  8138. if (hc) {$("#"+nm,"#"+frmtb).parents("tr:first").hide();}
  8139. cnt++;
  8140. }
  8141. });
  8142. if(cnt>0) {$("#id_g","#"+frmtb).val(rowid);}
  8143. }
  8144. function updateNav(cr,posarr){
  8145. var totr = posarr[1].length-1;
  8146. if (cr===0) {
  8147. $("#pData","#"+frmtb+"_2").addClass('ui-state-disabled');
  8148. } else if( posarr[1][cr-1] !== undefined && $("#"+$.jgrid.jqID(posarr[1][cr-1])).hasClass('ui-state-disabled')) {
  8149. $("#pData",frmtb+"_2").addClass('ui-state-disabled');
  8150. } else {
  8151. $("#pData","#"+frmtb+"_2").removeClass('ui-state-disabled');
  8152. }
  8153. if (cr===totr) {
  8154. $("#nData","#"+frmtb+"_2").addClass('ui-state-disabled');
  8155. } else if( posarr[1][cr+1] !== undefined && $("#"+$.jgrid.jqID(posarr[1][cr+1])).hasClass('ui-state-disabled')) {
  8156. $("#nData",frmtb+"_2").addClass('ui-state-disabled');
  8157. } else {
  8158. $("#nData","#"+frmtb+"_2").removeClass('ui-state-disabled');
  8159. }
  8160. }
  8161. function getCurrPos() {
  8162. var rowsInGrid = $($t).jqGrid("getDataIDs"),
  8163. selrow = $("#id_g","#"+frmtb).val(),
  8164. pos = $.inArray(selrow,rowsInGrid);
  8165. return [pos,rowsInGrid];
  8166. }
  8167. 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",
  8168. dw = isNaN(rp_ge[$(this)[0].p.id].datawidth) ? rp_ge[$(this)[0].p.id].datawidth : rp_ge[$(this)[0].p.id].datawidth+"px",
  8169. frm = $("<form name='FormPost' id='"+frmgr_id+"' class='FormGrid' style='width:"+dw+";overflow:auto;position:relative;height:"+dh+";'></form>"),
  8170. tbl =$("<table id='"+frmtb_id+"' class='EditTable' cellspacing='1' cellpadding='2' border='0' style='table-layout:fixed'><tbody></tbody></table>");
  8171. $($t.p.colModel).each( function() {
  8172. var fmto = this.formoptions;
  8173. maxCols = Math.max(maxCols, fmto ? fmto.colpos || 0 : 0 );
  8174. maxRows = Math.max(maxRows, fmto ? fmto.rowpos || 0 : 0 );
  8175. });
  8176. // set the id.
  8177. $(frm).append(tbl);
  8178. if(onBeforeInit) {
  8179. showFrm = onBeforeInit.call($t, frm );
  8180. if(showFrm === undefined) {
  8181. showFrm = true;
  8182. }
  8183. }
  8184. if(showFrm === false) {return;}
  8185. createData(rowid, $t, tbl, maxCols);
  8186. var rtlb = $t.p.direction === "rtl" ? true :false,
  8187. bp = rtlb ? "nData" : "pData",
  8188. bn = rtlb ? "pData" : "nData",
  8189. // buttons at footer
  8190. bP = "<a id='"+bp+"' class='fm-button ui-state-default ui-corner-left'><span class='ui-icon ui-icon-triangle-1-w'></span></a>",
  8191. bN = "<a id='"+bn+"' class='fm-button ui-state-default ui-corner-right'><span class='ui-icon ui-icon-triangle-1-e'></span></a>",
  8192. bC ="<a id='cData' class='fm-button ui-state-default ui-corner-all'>"+p.bClose+"</a>";
  8193. if(maxRows > 0) {
  8194. var sd=[];
  8195. $.each($(tbl)[0].rows,function(i,r){
  8196. sd[i] = r;
  8197. });
  8198. sd.sort(function(a,b){
  8199. if(a.rp > b.rp) {return 1;}
  8200. if(a.rp < b.rp) {return -1;}
  8201. return 0;
  8202. });
  8203. $.each(sd, function(index, row) {
  8204. $('tbody',tbl).append(row);
  8205. });
  8206. }
  8207. p.gbox = "#gbox_"+$.jgrid.jqID(gID);
  8208. 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>");
  8209. $.jgrid.createModal(IDs,bt,p,"#gview_"+$.jgrid.jqID($t.p.id),$("#gview_"+$.jgrid.jqID($t.p.id))[0]);
  8210. if(rtlb) {
  8211. $("#pData, #nData","#"+frmtb+"_2").css("float","right");
  8212. $(".EditButton","#"+frmtb+"_2").css("text-align","left");
  8213. }
  8214. if(!p.viewPagerButtons) {$("#pData, #nData","#"+frmtb+"_2").hide();}
  8215. bt = null;
  8216. $("#"+IDs.themodal).keydown( function( e ) {
  8217. if(e.which === 27) {
  8218. if(rp_ge[$t.p.id].closeOnEscape) {$.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:p.gbox,jqm:p.jqModal, onClose: p.onClose, removemodal: rp_ge[$t.p.id].removemodal, formprop: !rp_ge[$t.p.id].recreateForm, form: rp_ge[$t.p.id].form});}
  8219. return false;
  8220. }
  8221. if(p.navkeys[0]===true) {
  8222. if(e.which === p.navkeys[1]){ //up
  8223. $("#pData", "#"+frmtb+"_2").trigger("click");
  8224. return false;
  8225. }
  8226. if(e.which === p.navkeys[2]){ //down
  8227. $("#nData", "#"+frmtb+"_2").trigger("click");
  8228. return false;
  8229. }
  8230. }
  8231. });
  8232. p.closeicon = $.extend([true,"left","ui-icon-close"],p.closeicon);
  8233. if(p.closeicon[0]===true) {
  8234. $("#cData","#"+frmtb+"_2").addClass(p.closeicon[1] === "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  8235. .append("<span class='ui-icon "+p.closeicon[2]+"'></span>");
  8236. }
  8237. if($.isFunction(p.beforeShowForm)) {p.beforeShowForm.call($t,$("#"+frmgr));}
  8238. $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{
  8239. gbox:"#gbox_"+$.jgrid.jqID(gID),
  8240. jqm:p.jqModal,
  8241. overlay: p.overlay,
  8242. modal:p.modal,
  8243. onHide : function(h) {
  8244. $($t).data("viewProp", {
  8245. top:parseFloat($(h.w).css("top")),
  8246. left : parseFloat($(h.w).css("left")),
  8247. width : $(h.w).width(),
  8248. height : $(h.w).height(),
  8249. dataheight : $("#"+frmgr).height(),
  8250. datawidth: $("#"+frmgr).width()
  8251. });
  8252. h.w.remove();
  8253. if(h.o) {h.o.remove();}
  8254. }
  8255. });
  8256. $(".fm-button:not(.ui-state-disabled)","#"+frmtb+"_2").hover(
  8257. function(){$(this).addClass('ui-state-hover');},
  8258. function(){$(this).removeClass('ui-state-hover');}
  8259. );
  8260. focusaref();
  8261. $("#cData", "#"+frmtb+"_2").click(function(){
  8262. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: p.onClose, removemodal: rp_ge[$t.p.id].removemodal, formprop: !rp_ge[$t.p.id].recreateForm, form: rp_ge[$t.p.id].form});
  8263. return false;
  8264. });
  8265. $("#nData", "#"+frmtb+"_2").click(function(){
  8266. $("#FormError","#"+frmtb).hide();
  8267. var npos = getCurrPos();
  8268. npos[0] = parseInt(npos[0],10);
  8269. if(npos[0] !== -1 && npos[1][npos[0]+1]) {
  8270. if($.isFunction(p.onclickPgButtons)) {
  8271. p.onclickPgButtons.call($t,'next',$("#"+frmgr),npos[1][npos[0]]);
  8272. }
  8273. fillData(npos[1][npos[0]+1],$t);
  8274. $($t).jqGrid("setSelection",npos[1][npos[0]+1]);
  8275. if($.isFunction(p.afterclickPgButtons)) {
  8276. p.afterclickPgButtons.call($t,'next',$("#"+frmgr),npos[1][npos[0]+1]);
  8277. }
  8278. updateNav(npos[0]+1,npos);
  8279. }
  8280. focusaref();
  8281. return false;
  8282. });
  8283. $("#pData", "#"+frmtb+"_2").click(function(){
  8284. $("#FormError","#"+frmtb).hide();
  8285. var ppos = getCurrPos();
  8286. if(ppos[0] !== -1 && ppos[1][ppos[0]-1]) {
  8287. if($.isFunction(p.onclickPgButtons)) {
  8288. p.onclickPgButtons.call($t,'prev',$("#"+frmgr),ppos[1][ppos[0]]);
  8289. }
  8290. fillData(ppos[1][ppos[0]-1],$t);
  8291. $($t).jqGrid("setSelection",ppos[1][ppos[0]-1]);
  8292. if($.isFunction(p.afterclickPgButtons)) {
  8293. p.afterclickPgButtons.call($t,'prev',$("#"+frmgr),ppos[1][ppos[0]-1]);
  8294. }
  8295. updateNav(ppos[0]-1,ppos);
  8296. }
  8297. focusaref();
  8298. return false;
  8299. });
  8300. var posInit =getCurrPos();
  8301. updateNav(posInit[0],posInit);
  8302. });
  8303. },
  8304. delGridRow : function(rowids,p) {
  8305. p = $.extend(true, {
  8306. top : 0,
  8307. left: 0,
  8308. width: 240,
  8309. height: 'auto',
  8310. dataheight : 'auto',
  8311. modal: false,
  8312. overlay: 30,
  8313. drag: true,
  8314. resize: true,
  8315. url : '',
  8316. mtype : "POST",
  8317. reloadAfterSubmit: true,
  8318. beforeShowForm: null,
  8319. beforeInitData : null,
  8320. afterShowForm: null,
  8321. beforeSubmit: null,
  8322. onclickSubmit: null,
  8323. afterSubmit: null,
  8324. jqModal : true,
  8325. closeOnEscape : false,
  8326. delData: {},
  8327. delicon : [],
  8328. cancelicon : [],
  8329. onClose : null,
  8330. ajaxDelOptions : {},
  8331. processing : false,
  8332. serializeDelData : null,
  8333. useDataProxy : false
  8334. }, $.jgrid.del, p ||{});
  8335. rp_ge[$(this)[0].p.id] = p;
  8336. return this.each(function(){
  8337. var $t = this;
  8338. if (!$t.grid ) {return;}
  8339. if(!rowids) {return;}
  8340. var onBeforeShow = $.isFunction( rp_ge[$t.p.id].beforeShowForm ),
  8341. onAfterShow = $.isFunction( rp_ge[$t.p.id].afterShowForm ),
  8342. onBeforeInit = $.isFunction(rp_ge[$t.p.id].beforeInitData) ? rp_ge[$t.p.id].beforeInitData : false,
  8343. gID = $t.p.id, onCS = {},
  8344. showFrm = true,
  8345. dtbl = "DelTbl_"+$.jgrid.jqID(gID),postd, idname, opers, oper,
  8346. dtbl_id = "DelTbl_" + gID,
  8347. IDs = {themodal:'delmod'+gID,modalhead:'delhd'+gID,modalcontent:'delcnt'+gID, scrollelm: dtbl};
  8348. if ($.isArray(rowids)) {rowids = rowids.join();}
  8349. if ( $("#"+$.jgrid.jqID(IDs.themodal))[0] !== undefined ) {
  8350. if(onBeforeInit) {
  8351. showFrm = onBeforeInit.call($t,$("#"+dtbl));
  8352. if(showFrm === undefined) {
  8353. showFrm = true;
  8354. }
  8355. }
  8356. if(showFrm === false) {return;}
  8357. $("#DelData>td","#"+dtbl).text(rowids);
  8358. $("#DelError","#"+dtbl).hide();
  8359. if( rp_ge[$t.p.id].processing === true) {
  8360. rp_ge[$t.p.id].processing=false;
  8361. $("#dData", "#"+dtbl).removeClass('ui-state-active');
  8362. }
  8363. if(onBeforeShow) {rp_ge[$t.p.id].beforeShowForm.call($t,$("#"+dtbl));}
  8364. $.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});
  8365. if(onAfterShow) {rp_ge[$t.p.id].afterShowForm.call($t,$("#"+dtbl));}
  8366. } else {
  8367. var dh = isNaN(rp_ge[$t.p.id].dataheight) ? rp_ge[$t.p.id].dataheight : rp_ge[$t.p.id].dataheight+"px",
  8368. dw = isNaN(p.datawidth) ? p.datawidth : p.datawidth+"px",
  8369. tbl = "<div id='"+dtbl_id+"' class='formdata' style='width:"+dw+";overflow:auto;position:relative;height:"+dh+";'>";
  8370. tbl += "<table class='DelTable'><tbody>";
  8371. // error data
  8372. tbl += "<tr id='DelError' style='display:none'><td class='ui-state-error'></td></tr>";
  8373. tbl += "<tr id='DelData' style='display:none'><td >"+rowids+"</td></tr>";
  8374. tbl += "<tr><td class=\"delmsg\" style=\"white-space:pre;\">"+rp_ge[$t.p.id].msg+"</td></tr><tr><td >&#160;</td></tr>";
  8375. // buttons at footer
  8376. tbl += "</tbody></table></div>";
  8377. var bS = "<a id='dData' class='fm-button ui-state-default ui-corner-all'>"+p.bSubmit+"</a>",
  8378. bC = "<a id='eData' class='fm-button ui-state-default ui-corner-all'>"+p.bCancel+"</a>";
  8379. 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>";
  8380. p.gbox = "#gbox_"+$.jgrid.jqID(gID);
  8381. $.jgrid.createModal(IDs,tbl,p,"#gview_"+$.jgrid.jqID($t.p.id),$("#gview_"+$.jgrid.jqID($t.p.id))[0]);
  8382. if(onBeforeInit) {
  8383. showFrm = onBeforeInit.call($t,$(tbl));
  8384. if(showFrm === undefined) {
  8385. showFrm = true;
  8386. }
  8387. }
  8388. if(showFrm === false) {return;}
  8389. $(".fm-button","#"+dtbl+"_2").hover(
  8390. function(){$(this).addClass('ui-state-hover');},
  8391. function(){$(this).removeClass('ui-state-hover');}
  8392. );
  8393. p.delicon = $.extend([true,"left","ui-icon-scissors"],rp_ge[$t.p.id].delicon);
  8394. p.cancelicon = $.extend([true,"left","ui-icon-cancel"],rp_ge[$t.p.id].cancelicon);
  8395. if(p.delicon[0]===true) {
  8396. $("#dData","#"+dtbl+"_2").addClass(p.delicon[1] === "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  8397. .append("<span class='ui-icon "+p.delicon[2]+"'></span>");
  8398. }
  8399. if(p.cancelicon[0]===true) {
  8400. $("#eData","#"+dtbl+"_2").addClass(p.cancelicon[1] === "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  8401. .append("<span class='ui-icon "+p.cancelicon[2]+"'></span>");
  8402. }
  8403. $("#dData","#"+dtbl+"_2").click(function(){
  8404. var ret=[true,""], pk,
  8405. postdata = $("#DelData>td","#"+dtbl).text(); //the pair is name=val1,val2,...
  8406. onCS = {};
  8407. if( $.isFunction( rp_ge[$t.p.id].onclickSubmit ) ) {onCS = rp_ge[$t.p.id].onclickSubmit.call($t,rp_ge[$t.p.id], postdata) || {};}
  8408. if( $.isFunction( rp_ge[$t.p.id].beforeSubmit ) ) {ret = rp_ge[$t.p.id].beforeSubmit.call($t,postdata);}
  8409. if(ret[0] && !rp_ge[$t.p.id].processing) {
  8410. rp_ge[$t.p.id].processing = true;
  8411. opers = $t.p.prmNames;
  8412. postd = $.extend({},rp_ge[$t.p.id].delData, onCS);
  8413. oper = opers.oper;
  8414. postd[oper] = opers.deloper;
  8415. idname = opers.id;
  8416. postdata = String(postdata).split(",");
  8417. if(!postdata.length) { return false; }
  8418. for(pk in postdata) {
  8419. if(postdata.hasOwnProperty(pk)) {
  8420. postdata[pk] = $.jgrid.stripPref($t.p.idPrefix, postdata[pk]);
  8421. }
  8422. }
  8423. postd[idname] = postdata.join();
  8424. $(this).addClass('ui-state-active');
  8425. var ajaxOptions = $.extend({
  8426. url: rp_ge[$t.p.id].url || $($t).jqGrid('getGridParam','editurl'),
  8427. type: rp_ge[$t.p.id].mtype,
  8428. data: $.isFunction(rp_ge[$t.p.id].serializeDelData) ? rp_ge[$t.p.id].serializeDelData.call($t,postd) : postd,
  8429. complete:function(data,status){
  8430. var i;
  8431. $("#dData", "#"+dtbl+"_2").removeClass('ui-state-active');
  8432. if(data.status >= 300 && data.status !== 304) {
  8433. ret[0] = false;
  8434. if ($.isFunction(rp_ge[$t.p.id].errorTextFormat)) {
  8435. ret[1] = rp_ge[$t.p.id].errorTextFormat.call($t,data);
  8436. } else {
  8437. ret[1] = status + " Status: '" + data.statusText + "'. Error code: " + data.status;
  8438. }
  8439. } else {
  8440. // data is posted successful
  8441. // execute aftersubmit with the returned data from server
  8442. if( $.isFunction( rp_ge[$t.p.id].afterSubmit ) ) {
  8443. ret = rp_ge[$t.p.id].afterSubmit.call($t,data,postd);
  8444. }
  8445. }
  8446. if(ret[0] === false) {
  8447. $("#DelError>td","#"+dtbl).html(ret[1]);
  8448. $("#DelError","#"+dtbl).show();
  8449. } else {
  8450. if(rp_ge[$t.p.id].reloadAfterSubmit && $t.p.datatype !== "local") {
  8451. $($t).trigger("reloadGrid");
  8452. } else {
  8453. if($t.p.treeGrid===true){
  8454. try {$($t).jqGrid("delTreeNode",$t.p.idPrefix+postdata[0]);} catch(e){}
  8455. } else {
  8456. for(i=0;i<postdata.length;i++) {
  8457. $($t).jqGrid("delRowData",$t.p.idPrefix+ postdata[i]);
  8458. }
  8459. }
  8460. $t.p.selrow = null;
  8461. $t.p.selarrrow = [];
  8462. }
  8463. if($.isFunction(rp_ge[$t.p.id].afterComplete)) {
  8464. setTimeout(function(){rp_ge[$t.p.id].afterComplete.call($t,data,postdata);},500);
  8465. }
  8466. }
  8467. rp_ge[$t.p.id].processing=false;
  8468. if(ret[0]) {$.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});}
  8469. }
  8470. }, $.jgrid.ajaxOptions, rp_ge[$t.p.id].ajaxDelOptions);
  8471. if (!ajaxOptions.url && !rp_ge[$t.p.id].useDataProxy) {
  8472. if ($.isFunction($t.p.dataProxy)) {
  8473. rp_ge[$t.p.id].useDataProxy = true;
  8474. } else {
  8475. ret[0]=false;ret[1] += " "+$.jgrid.errors.nourl;
  8476. }
  8477. }
  8478. if (ret[0]) {
  8479. if (rp_ge[$t.p.id].useDataProxy) {
  8480. var dpret = $t.p.dataProxy.call($t, ajaxOptions, "del_"+$t.p.id);
  8481. if(dpret === undefined) {
  8482. dpret = [true, ""];
  8483. }
  8484. if(dpret[0] === false ) {
  8485. ret[0] = false;
  8486. ret[1] = dpret[1] || "Error deleting the selected row!" ;
  8487. } else {
  8488. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});
  8489. }
  8490. }
  8491. else {
  8492. if(ajaxOptions.url === "clientArray") {
  8493. postd = ajaxOptions.data;
  8494. ajaxOptions.complete({status:200, statusText:''},'');
  8495. } else {
  8496. $.ajax(ajaxOptions);
  8497. }
  8498. }
  8499. }
  8500. }
  8501. if(ret[0] === false) {
  8502. $("#DelError>td","#"+dtbl).html(ret[1]);
  8503. $("#DelError","#"+dtbl).show();
  8504. }
  8505. return false;
  8506. });
  8507. $("#eData", "#"+dtbl+"_2").click(function(){
  8508. $.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});
  8509. return false;
  8510. });
  8511. if(onBeforeShow) {rp_ge[$t.p.id].beforeShowForm.call($t,$("#"+dtbl));}
  8512. $.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});
  8513. if(onAfterShow) {rp_ge[$t.p.id].afterShowForm.call($t,$("#"+dtbl));}
  8514. }
  8515. if(rp_ge[$t.p.id].closeOnEscape===true) {
  8516. setTimeout(function(){$(".ui-jqdialog-titlebar-close","#"+$.jgrid.jqID(IDs.modalhead)).attr("tabindex","-1").focus();},0);
  8517. }
  8518. });
  8519. },
  8520. navGrid : function (elem, o, pEdit,pAdd,pDel,pSearch, pView) {
  8521. o = $.extend({
  8522. edit: true,
  8523. editicon: "ui-icon-pencil",
  8524. add: true,
  8525. addicon:"ui-icon-plus",
  8526. del: true,
  8527. delicon:"ui-icon-trash",
  8528. search: true,
  8529. searchicon:"ui-icon-search",
  8530. refresh: true,
  8531. refreshicon:"ui-icon-refresh",
  8532. refreshstate: 'firstpage',
  8533. view: false,
  8534. viewicon : "ui-icon-document",
  8535. position : "left",
  8536. closeOnEscape : true,
  8537. beforeRefresh : null,
  8538. afterRefresh : null,
  8539. cloneToTop : false,
  8540. alertwidth : 200,
  8541. alertheight : 'auto',
  8542. alerttop: null,
  8543. alertleft: null,
  8544. alertzIndex : null
  8545. }, $.jgrid.nav, o ||{});
  8546. return this.each(function() {
  8547. if(this.nav) {return;}
  8548. var alertIDs = {themodal: 'alertmod_' + this.p.id, modalhead: 'alerthd_' + this.p.id,modalcontent: 'alertcnt_' + this.p.id},
  8549. $t = this, twd, tdw;
  8550. if(!$t.grid || typeof elem !== 'string') {return;}
  8551. if ($("#"+alertIDs.themodal)[0] === undefined) {
  8552. if(!o.alerttop && !o.alertleft) {
  8553. if (window.innerWidth !== undefined) {
  8554. o.alertleft = window.innerWidth;
  8555. o.alerttop = window.innerHeight;
  8556. } else if (document.documentElement !== undefined && document.documentElement.clientWidth !== undefined && document.documentElement.clientWidth !== 0) {
  8557. o.alertleft = document.documentElement.clientWidth;
  8558. o.alerttop = document.documentElement.clientHeight;
  8559. } else {
  8560. o.alertleft=1024;
  8561. o.alerttop=768;
  8562. }
  8563. o.alertleft = o.alertleft/2 - parseInt(o.alertwidth,10)/2;
  8564. o.alerttop = o.alerttop/2-25;
  8565. }
  8566. $.jgrid.createModal(alertIDs,
  8567. "<div>"+o.alerttext+"</div><span tabindex='0'><span tabindex='-1' id='jqg_alrt'></span></span>",
  8568. {
  8569. gbox:"#gbox_"+$.jgrid.jqID($t.p.id),
  8570. jqModal:true,
  8571. drag:true,
  8572. resize:true,
  8573. caption:o.alertcap,
  8574. top:o.alerttop,
  8575. left:o.alertleft,
  8576. width:o.alertwidth,
  8577. height: o.alertheight,
  8578. closeOnEscape:o.closeOnEscape,
  8579. zIndex: o.alertzIndex
  8580. },
  8581. "#gview_"+$.jgrid.jqID($t.p.id),
  8582. $("#gbox_"+$.jgrid.jqID($t.p.id))[0],
  8583. true
  8584. );
  8585. }
  8586. var clone = 1, i,
  8587. onHoverIn = function () {
  8588. if (!$(this).hasClass('ui-state-disabled')) {
  8589. $(this).addClass("ui-state-hover");
  8590. }
  8591. },
  8592. onHoverOut = function () {
  8593. $(this).removeClass("ui-state-hover");
  8594. };
  8595. if(o.cloneToTop && $t.p.toppager) {clone = 2;}
  8596. for(i = 0; i<clone; i++) {
  8597. var tbd,
  8598. navtbl = $("<table cellspacing='0' cellpadding='0' border='0' class='ui-pg-table navtable' style='float:left;table-layout:auto;'><tbody><tr></tr></tbody></table>"),
  8599. sep = "<td class='ui-pg-button ui-state-disabled' style='width:4px;'><span class='ui-separator'></span></td>",
  8600. pgid, elemids;
  8601. if(i===0) {
  8602. pgid = elem;
  8603. elemids = $t.p.id;
  8604. if(pgid === $t.p.toppager) {
  8605. elemids += "_top";
  8606. clone = 1;
  8607. }
  8608. } else {
  8609. pgid = $t.p.toppager;
  8610. elemids = $t.p.id+"_top";
  8611. }
  8612. if($t.p.direction === "rtl") {$(navtbl).attr("dir","rtl").css("float","right");}
  8613. if (o.add) {
  8614. pAdd = pAdd || {};
  8615. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  8616. $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.addicon+"'></span>"+o.addtext+"</div>");
  8617. $("tr",navtbl).append(tbd);
  8618. $(tbd,navtbl)
  8619. .attr({"title":o.addtitle || "",id : pAdd.id || "add_"+elemids})
  8620. .click(function(){
  8621. if (!$(this).hasClass('ui-state-disabled')) {
  8622. if ($.isFunction( o.addfunc )) {
  8623. o.addfunc.call($t);
  8624. } else {
  8625. $($t).jqGrid("editGridRow","new",pAdd);
  8626. }
  8627. }
  8628. return false;
  8629. }).hover(onHoverIn, onHoverOut);
  8630. tbd = null;
  8631. }
  8632. if (o.edit) {
  8633. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  8634. pEdit = pEdit || {};
  8635. $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.editicon+"'></span>"+o.edittext+"</div>");
  8636. $("tr",navtbl).append(tbd);
  8637. $(tbd,navtbl)
  8638. .attr({"title":o.edittitle || "",id: pEdit.id || "edit_"+elemids})
  8639. .click(function(){
  8640. if (!$(this).hasClass('ui-state-disabled')) {
  8641. var sr = $t.p.selrow;
  8642. if (sr) {
  8643. if($.isFunction( o.editfunc ) ) {
  8644. o.editfunc.call($t, sr);
  8645. } else {
  8646. $($t).jqGrid("editGridRow",sr,pEdit);
  8647. }
  8648. } else {
  8649. $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:true});
  8650. $("#jqg_alrt").focus();
  8651. }
  8652. }
  8653. return false;
  8654. }).hover(onHoverIn, onHoverOut);
  8655. tbd = null;
  8656. }
  8657. if (o.view) {
  8658. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  8659. pView = pView || {};
  8660. $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.viewicon+"'></span>"+o.viewtext+"</div>");
  8661. $("tr",navtbl).append(tbd);
  8662. $(tbd,navtbl)
  8663. .attr({"title":o.viewtitle || "",id: pView.id || "view_"+elemids})
  8664. .click(function(){
  8665. if (!$(this).hasClass('ui-state-disabled')) {
  8666. var sr = $t.p.selrow;
  8667. if (sr) {
  8668. if($.isFunction( o.viewfunc ) ) {
  8669. o.viewfunc.call($t, sr);
  8670. } else {
  8671. $($t).jqGrid("viewGridRow",sr,pView);
  8672. }
  8673. } else {
  8674. $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:true});
  8675. $("#jqg_alrt").focus();
  8676. }
  8677. }
  8678. return false;
  8679. }).hover(onHoverIn, onHoverOut);
  8680. tbd = null;
  8681. }
  8682. if (o.del) {
  8683. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  8684. pDel = pDel || {};
  8685. $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.delicon+"'></span>"+o.deltext+"</div>");
  8686. $("tr",navtbl).append(tbd);
  8687. $(tbd,navtbl)
  8688. .attr({"title":o.deltitle || "",id: pDel.id || "del_"+elemids})
  8689. .click(function(){
  8690. if (!$(this).hasClass('ui-state-disabled')) {
  8691. var dr;
  8692. if($t.p.multiselect) {
  8693. dr = $t.p.selarrrow;
  8694. if(dr.length===0) {dr = null;}
  8695. } else {
  8696. dr = $t.p.selrow;
  8697. }
  8698. if(dr){
  8699. if($.isFunction( o.delfunc )){
  8700. o.delfunc.call($t, dr);
  8701. }else{
  8702. $($t).jqGrid("delGridRow",dr,pDel);
  8703. }
  8704. } else {
  8705. $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:true});$("#jqg_alrt").focus();
  8706. }
  8707. }
  8708. return false;
  8709. }).hover(onHoverIn, onHoverOut);
  8710. tbd = null;
  8711. }
  8712. if(o.add || o.edit || o.del || o.view) {$("tr",navtbl).append(sep);}
  8713. if (o.search) {
  8714. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  8715. pSearch = pSearch || {};
  8716. $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.searchicon+"'></span>"+o.searchtext+"</div>");
  8717. $("tr",navtbl).append(tbd);
  8718. $(tbd,navtbl)
  8719. .attr({"title":o.searchtitle || "",id:pSearch.id || "search_"+elemids})
  8720. .click(function(){
  8721. if (!$(this).hasClass('ui-state-disabled')) {
  8722. if($.isFunction( o.searchfunc )) {
  8723. o.searchfunc.call($t, pSearch);
  8724. } else {
  8725. $($t).jqGrid("searchGrid",pSearch);
  8726. }
  8727. }
  8728. return false;
  8729. }).hover(onHoverIn, onHoverOut);
  8730. if (pSearch.showOnLoad && pSearch.showOnLoad === true) {
  8731. $(tbd,navtbl).click();
  8732. }
  8733. tbd = null;
  8734. }
  8735. if (o.refresh) {
  8736. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  8737. $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.refreshicon+"'></span>"+o.refreshtext+"</div>");
  8738. $("tr",navtbl).append(tbd);
  8739. $(tbd,navtbl)
  8740. .attr({"title":o.refreshtitle || "",id: "refresh_"+elemids})
  8741. .click(function(){
  8742. if (!$(this).hasClass('ui-state-disabled')) {
  8743. if($.isFunction(o.beforeRefresh)) {o.beforeRefresh.call($t);}
  8744. $t.p.search = false;
  8745. $t.p.resetsearch = true;
  8746. try {
  8747. if( o.refreshstate !== 'currentfilter') {
  8748. var gID = $t.p.id;
  8749. $t.p.postData.filters ="";
  8750. try {
  8751. $("#fbox_"+$.jgrid.jqID(gID)).jqFilter('resetFilter');
  8752. } catch(ef) {}
  8753. if($.isFunction($t.clearToolbar)) {$t.clearToolbar.call($t,false);}
  8754. }
  8755. } catch (e) {}
  8756. switch (o.refreshstate) {
  8757. case 'firstpage':
  8758. $($t).trigger("reloadGrid", [{page:1}]);
  8759. break;
  8760. case 'current':
  8761. case 'currentfilter':
  8762. $($t).trigger("reloadGrid", [{current:true}]);
  8763. break;
  8764. }
  8765. if($.isFunction(o.afterRefresh)) {o.afterRefresh.call($t);}
  8766. }
  8767. return false;
  8768. }).hover(onHoverIn, onHoverOut);
  8769. tbd = null;
  8770. }
  8771. tdw = $(".ui-jqgrid").css("font-size") || "11px";
  8772. $('body').append("<div id='testpg2' class='ui-jqgrid ui-widget ui-widget-content' style='font-size:"+tdw+";visibility:hidden;' ></div>");
  8773. twd = $(navtbl).clone().appendTo("#testpg2").width();
  8774. $("#testpg2").remove();
  8775. $(pgid+"_"+o.position,pgid).append(navtbl);
  8776. if($t.p._nvtd) {
  8777. if(twd > $t.p._nvtd[0] ) {
  8778. $(pgid+"_"+o.position,pgid).width(twd);
  8779. $t.p._nvtd[0] = twd;
  8780. }
  8781. $t.p._nvtd[1] = twd;
  8782. }
  8783. tdw =null;twd=null;navtbl =null;
  8784. this.nav = true;
  8785. }
  8786. });
  8787. },
  8788. navButtonAdd : function (elem, p) {
  8789. p = $.extend({
  8790. caption : "newButton",
  8791. title: '',
  8792. buttonicon : 'ui-icon-newwin',
  8793. onClickButton: null,
  8794. position : "last",
  8795. cursor : 'pointer'
  8796. }, p ||{});
  8797. return this.each(function() {
  8798. if( !this.grid) {return;}
  8799. if( typeof elem === "string" && elem.indexOf("#") !== 0) {elem = "#"+$.jgrid.jqID(elem);}
  8800. var findnav = $(".navtable",elem)[0], $t = this;
  8801. if (findnav) {
  8802. if( p.id && $("#"+$.jgrid.jqID(p.id), findnav)[0] !== undefined ) {return;}
  8803. var tbd = $("<td></td>");
  8804. if(p.buttonicon.toString().toUpperCase() === "NONE") {
  8805. $(tbd).addClass('ui-pg-button ui-corner-all').append("<div class='ui-pg-div'>"+p.caption+"</div>");
  8806. } else {
  8807. $(tbd).addClass('ui-pg-button ui-corner-all').append("<div class='ui-pg-div'><span class='ui-icon "+p.buttonicon+"'></span>"+p.caption+"</div>");
  8808. }
  8809. if(p.id) {$(tbd).attr("id",p.id);}
  8810. if(p.position==='first'){
  8811. if(findnav.rows[0].cells.length ===0 ) {
  8812. $("tr",findnav).append(tbd);
  8813. } else {
  8814. $("tr td:eq(0)",findnav).before(tbd);
  8815. }
  8816. } else {
  8817. $("tr",findnav).append(tbd);
  8818. }
  8819. $(tbd,findnav)
  8820. .attr("title",p.title || "")
  8821. .click(function(e){
  8822. if (!$(this).hasClass('ui-state-disabled')) {
  8823. if ($.isFunction(p.onClickButton) ) {p.onClickButton.call($t,e);}
  8824. }
  8825. return false;
  8826. })
  8827. .hover(
  8828. function () {
  8829. if (!$(this).hasClass('ui-state-disabled')) {
  8830. $(this).addClass('ui-state-hover');
  8831. }
  8832. },
  8833. function () {$(this).removeClass("ui-state-hover");}
  8834. );
  8835. }
  8836. });
  8837. },
  8838. navSeparatorAdd:function (elem,p) {
  8839. p = $.extend({
  8840. sepclass : "ui-separator",
  8841. sepcontent: '',
  8842. position : "last"
  8843. }, p ||{});
  8844. return this.each(function() {
  8845. if( !this.grid) {return;}
  8846. if( typeof elem === "string" && elem.indexOf("#") !== 0) {elem = "#"+$.jgrid.jqID(elem);}
  8847. var findnav = $(".navtable",elem)[0];
  8848. if(findnav) {
  8849. var sep = "<td class='ui-pg-button ui-state-disabled' style='width:4px;'><span class='"+p.sepclass+"'></span>"+p.sepcontent+"</td>";
  8850. if (p.position === 'first') {
  8851. if (findnav.rows[0].cells.length === 0) {
  8852. $("tr", findnav).append(sep);
  8853. } else {
  8854. $("tr td:eq(0)", findnav).before(sep);
  8855. }
  8856. } else {
  8857. $("tr", findnav).append(sep);
  8858. }
  8859. }
  8860. });
  8861. },
  8862. GridToForm : function( rowid, formid ) {
  8863. return this.each(function(){
  8864. var $t = this, i;
  8865. if (!$t.grid) {return;}
  8866. var rowdata = $($t).jqGrid("getRowData",rowid);
  8867. if (rowdata) {
  8868. for(i in rowdata) {
  8869. if(rowdata.hasOwnProperty(i)) {
  8870. if ( $("[name="+$.jgrid.jqID(i)+"]",formid).is("input:radio") || $("[name="+$.jgrid.jqID(i)+"]",formid).is("input:checkbox")) {
  8871. $("[name="+$.jgrid.jqID(i)+"]",formid).each( function() {
  8872. if( $(this).val() == rowdata[i] ) {
  8873. $(this)[$t.p.useProp ? 'prop': 'attr']("checked",true);
  8874. } else {
  8875. $(this)[$t.p.useProp ? 'prop': 'attr']("checked", false);
  8876. }
  8877. });
  8878. } else {
  8879. // this is very slow on big table and form.
  8880. $("[name="+$.jgrid.jqID(i)+"]",formid).val(rowdata[i]);
  8881. }
  8882. }
  8883. }
  8884. }
  8885. });
  8886. },
  8887. FormToGrid : function(rowid, formid, mode, position){
  8888. return this.each(function() {
  8889. var $t = this;
  8890. if(!$t.grid) {return;}
  8891. if(!mode) {mode = 'set';}
  8892. if(!position) {position = 'first';}
  8893. var fields = $(formid).serializeArray();
  8894. var griddata = {};
  8895. $.each(fields, function(i, field){
  8896. griddata[field.name] = field.value;
  8897. });
  8898. if(mode==='add') {$($t).jqGrid("addRowData",rowid,griddata, position);}
  8899. else if(mode==='set') {$($t).jqGrid("setRowData",rowid,griddata);}
  8900. });
  8901. }
  8902. });
  8903. })(jQuery);
  8904. /*jshint eqeqeq:false, eqnull:true */
  8905. /*global jQuery */
  8906. // Grouping module
  8907. (function($){
  8908. "use strict";
  8909. $.extend($.jgrid,{
  8910. template : function(format){ //jqgformat
  8911. var args = $.makeArray(arguments).slice(1), j, al = args.length;
  8912. if(format==null) { format = ""; }
  8913. return format.replace(/\{([\w\-]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g, function(m,i){
  8914. if(!isNaN(parseInt(i,10))) {
  8915. return args[parseInt(i,10)];
  8916. }
  8917. for(j=0; j < al;j++) {
  8918. if($.isArray(args[j])) {
  8919. var nmarr = args[ j ],
  8920. k = nmarr.length;
  8921. while(k--) {
  8922. if(i===nmarr[k].nm) {
  8923. return nmarr[k].v;
  8924. }
  8925. }
  8926. }
  8927. }
  8928. });
  8929. }
  8930. });
  8931. $.jgrid.extend({
  8932. groupingSetup : function () {
  8933. return this.each(function (){
  8934. var $t = this, i, j, cml, cm = $t.p.colModel, grp = $t.p.groupingView;
  8935. if(grp !== null && ( (typeof grp === 'object') || $.isFunction(grp) ) ) {
  8936. if(!grp.groupField.length) {
  8937. $t.p.grouping = false;
  8938. } else {
  8939. if (grp.visibiltyOnNextGrouping === undefined) {
  8940. grp.visibiltyOnNextGrouping = [];
  8941. }
  8942. grp.lastvalues=[];
  8943. if(!grp._locgr) {
  8944. grp.groups =[];
  8945. }
  8946. grp.counters =[];
  8947. for(i=0;i<grp.groupField.length;i++) {
  8948. if(!grp.groupOrder[i]) {
  8949. grp.groupOrder[i] = 'asc';
  8950. }
  8951. if(!grp.groupText[i]) {
  8952. grp.groupText[i] = '{0}';
  8953. }
  8954. if( typeof grp.groupColumnShow[i] !== 'boolean') {
  8955. grp.groupColumnShow[i] = true;
  8956. }
  8957. if( typeof grp.groupSummary[i] !== 'boolean') {
  8958. grp.groupSummary[i] = false;
  8959. }
  8960. if( !grp.groupSummaryPos[i]) {
  8961. grp.groupSummaryPos[i] = 'footer';
  8962. }
  8963. if(grp.groupColumnShow[i] === true) {
  8964. grp.visibiltyOnNextGrouping[i] = true;
  8965. $($t).jqGrid('showCol',grp.groupField[i]);
  8966. } else {
  8967. grp.visibiltyOnNextGrouping[i] = $("#"+$.jgrid.jqID($t.p.id+"_"+grp.groupField[i])).is(":visible");
  8968. $($t).jqGrid('hideCol',grp.groupField[i]);
  8969. }
  8970. }
  8971. grp.summary =[];
  8972. if(grp.hideFirstGroupCol) {
  8973. grp.formatDisplayField[0] = function (v) { return v;};
  8974. }
  8975. for(j=0, cml = cm.length; j < cml; j++) {
  8976. if(grp.hideFirstGroupCol) {
  8977. if(!cm[j].hidden && grp.groupField[0] === cm[j].name) {
  8978. cm[j].formatter = function(){return '';};
  8979. }
  8980. }
  8981. if(cm[j].summaryType ) {
  8982. if(cm[j].summaryDivider) {
  8983. 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'});
  8984. } else {
  8985. grp.summary.push({nm:cm[j].name,st:cm[j].summaryType, v: '', sr: cm[j].summaryRound, srt: cm[j].summaryRoundType || 'round'});
  8986. }
  8987. }
  8988. }
  8989. }
  8990. } else {
  8991. $t.p.grouping = false;
  8992. }
  8993. });
  8994. },
  8995. groupingPrepare : function ( record, irow ) {
  8996. this.each(function(){
  8997. var grp = this.p.groupingView, $t= this, i,
  8998. grlen = grp.groupField.length,
  8999. fieldName,
  9000. v,
  9001. displayName,
  9002. displayValue,
  9003. changed = 0;
  9004. for(i=0;i<grlen;i++) {
  9005. fieldName = grp.groupField[i];
  9006. displayName = grp.displayField[i];
  9007. v = record[fieldName];
  9008. displayValue = displayName == null ? null : record[displayName];
  9009. if( displayValue == null ) {
  9010. displayValue = v;
  9011. }
  9012. if( v !== undefined ) {
  9013. if(irow === 0 ) {
  9014. // First record always starts a new group
  9015. grp.groups.push({idx:i,dataIndex:fieldName,value:v, displayValue: displayValue, startRow: irow, cnt:1, summary : [] } );
  9016. grp.lastvalues[i] = v;
  9017. grp.counters[i] = {cnt:1, pos:grp.groups.length-1, summary: $.extend(true,[],grp.summary)};
  9018. $.each(grp.counters[i].summary,function() {
  9019. if ($.isFunction(this.st)) {
  9020. this.v = this.st.call($t, this.v, this.nm, record);
  9021. } else {
  9022. this.v = $($t).jqGrid('groupingCalculations.handler',this.st, this.v, this.nm, this.sr, this.srt, record);
  9023. if(this.st.toLowerCase() === 'avg' && this.sd) {
  9024. this.vd = $($t).jqGrid('groupingCalculations.handler',this.st, this.vd, this.sd, this.sr, this.srt, record);
  9025. }
  9026. }
  9027. });
  9028. grp.groups[grp.counters[i].pos].summary = grp.counters[i].summary;
  9029. } else {
  9030. 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)) {
  9031. // This record is not in same group as previous one
  9032. grp.groups.push({idx:i,dataIndex:fieldName,value:v, displayValue: displayValue, startRow: irow, cnt:1, summary : [] } );
  9033. grp.lastvalues[i] = v;
  9034. changed = 1;
  9035. grp.counters[i] = {cnt:1, pos:grp.groups.length-1, summary: $.extend(true,[],grp.summary)};
  9036. $.each(grp.counters[i].summary,function() {
  9037. if ($.isFunction(this.st)) {
  9038. this.v = this.st.call($t, this.v, this.nm, record);
  9039. } else {
  9040. this.v = $($t).jqGrid('groupingCalculations.handler',this.st, this.v, this.nm, this.sr, this.srt, record);
  9041. if(this.st.toLowerCase() === 'avg' && this.sd) {
  9042. this.vd = $($t).jqGrid('groupingCalculations.handler',this.st, this.vd, this.sd, this.sr, this.srt, record);
  9043. }
  9044. }
  9045. });
  9046. grp.groups[grp.counters[i].pos].summary = grp.counters[i].summary;
  9047. } else {
  9048. if (changed === 1) {
  9049. // This group has changed because an earlier group changed.
  9050. grp.groups.push({idx:i,dataIndex:fieldName,value:v, displayValue: displayValue, startRow: irow, cnt:1, summary : [] } );
  9051. grp.lastvalues[i] = v;
  9052. grp.counters[i] = {cnt:1, pos:grp.groups.length-1, summary: $.extend(true,[],grp.summary)};
  9053. $.each(grp.counters[i].summary,function() {
  9054. if ($.isFunction(this.st)) {
  9055. this.v = this.st.call($t, this.v, this.nm, record);
  9056. } else {
  9057. this.v = $($t).jqGrid('groupingCalculations.handler',this.st, this.v, this.nm, this.sr, this.srt, record);
  9058. if(this.st.toLowerCase() === 'avg' && this.sd) {
  9059. this.vd = $($t).jqGrid('groupingCalculations.handler',this.st, this.vd, this.sd, this.sr, this.srt, record);
  9060. }
  9061. }
  9062. });
  9063. grp.groups[grp.counters[i].pos].summary = grp.counters[i].summary;
  9064. } else {
  9065. grp.counters[i].cnt += 1;
  9066. grp.groups[grp.counters[i].pos].cnt = grp.counters[i].cnt;
  9067. $.each(grp.counters[i].summary,function() {
  9068. if ($.isFunction(this.st)) {
  9069. this.v = this.st.call($t, this.v, this.nm, record);
  9070. } else {
  9071. this.v = $($t).jqGrid('groupingCalculations.handler',this.st, this.v, this.nm, this.sr, this.srt, record);
  9072. if(this.st.toLowerCase() === 'avg' && this.sd) {
  9073. this.vd = $($t).jqGrid('groupingCalculations.handler',this.st, this.vd, this.sd, this.sr, this.srt, record);
  9074. }
  9075. }
  9076. });
  9077. grp.groups[grp.counters[i].pos].summary = grp.counters[i].summary;
  9078. }
  9079. }
  9080. }
  9081. }
  9082. }
  9083. //gdata.push( rData );
  9084. });
  9085. return this;
  9086. },
  9087. groupingToggle : function(hid){
  9088. this.each(function(){
  9089. var $t = this,
  9090. grp = $t.p.groupingView,
  9091. strpos = hid.split('_'),
  9092. num = parseInt(strpos[strpos.length-2], 10);
  9093. strpos.splice(strpos.length-2,2);
  9094. var uid = strpos.join("_"),
  9095. minus = grp.minusicon,
  9096. plus = grp.plusicon,
  9097. tar = $("#"+$.jgrid.jqID(hid)),
  9098. r = tar.length ? tar[0].nextSibling : null,
  9099. tarspan = $("#"+$.jgrid.jqID(hid)+" span."+"tree-wrap-"+$t.p.direction),
  9100. getGroupingLevelFromClass = function (className) {
  9101. var nums = $.map(className.split(" "), function (item) {
  9102. if (item.substring(0, uid.length + 1) === uid + "_") {
  9103. return parseInt(item.substring(uid.length + 1), 10);
  9104. }
  9105. });
  9106. return nums.length > 0 ? nums[0] : undefined;
  9107. },
  9108. itemGroupingLevel,
  9109. showData,
  9110. collapsed = false,
  9111. frz = $t.p.frozenColumns ? $t.p.id+"_frozen" : false,
  9112. tar2 = frz ? $("#"+$.jgrid.jqID(hid), "#"+$.jgrid.jqID(frz) ) : false,
  9113. r2 = (tar2 && tar2.length) ? tar2[0].nextSibling : null;
  9114. if( tarspan.hasClass(minus) ) {
  9115. if(grp.showSummaryOnHide) {
  9116. if(r){
  9117. while(r) {
  9118. itemGroupingLevel = getGroupingLevelFromClass(r.className);
  9119. if (itemGroupingLevel !== undefined && itemGroupingLevel <= num) {
  9120. break;
  9121. }
  9122. $(r).hide();
  9123. r = r.nextSibling;
  9124. if(frz) {
  9125. $(r2).hide();
  9126. r2 = r2.nextSibling;
  9127. }
  9128. }
  9129. }
  9130. } else {
  9131. if(r){
  9132. while(r) {
  9133. itemGroupingLevel = getGroupingLevelFromClass(r.className);
  9134. if (itemGroupingLevel !== undefined && itemGroupingLevel <= num) {
  9135. break;
  9136. }
  9137. $(r).hide();
  9138. r = r.nextSibling;
  9139. if(frz) {
  9140. $(r2).hide();
  9141. r2 = r2.nextSibling;
  9142. }
  9143. }
  9144. }
  9145. }
  9146. tarspan.removeClass(minus).addClass(plus);
  9147. collapsed = true;
  9148. } else {
  9149. if(r){
  9150. showData = undefined;
  9151. while(r) {
  9152. itemGroupingLevel = getGroupingLevelFromClass(r.className);
  9153. if (showData === undefined) {
  9154. showData = itemGroupingLevel === undefined; // if the first row after the opening group is data row then show the data rows
  9155. }
  9156. if (itemGroupingLevel !== undefined) {
  9157. if (itemGroupingLevel <= num) {
  9158. break;// next item of the same lever are found
  9159. }
  9160. if (itemGroupingLevel === num + 1) {
  9161. $(r).show().find(">td>span."+"tree-wrap-"+$t.p.direction).removeClass(minus).addClass(plus);
  9162. if(frz) {
  9163. $(r2).show().find(">td>span."+"tree-wrap-"+$t.p.direction).removeClass(minus).addClass(plus);
  9164. }
  9165. }
  9166. } else if (showData) {
  9167. $(r).show();
  9168. if(frz) {
  9169. $(r2).show();
  9170. }
  9171. }
  9172. r = r.nextSibling;
  9173. if(frz) {
  9174. r2 = r2.nextSibling;
  9175. }
  9176. }
  9177. }
  9178. tarspan.removeClass(plus).addClass(minus);
  9179. }
  9180. $($t).triggerHandler("jqGridGroupingClickGroup", [hid , collapsed]);
  9181. if( $.isFunction($t.p.onClickGroup)) { $t.p.onClickGroup.call($t, hid , collapsed); }
  9182. });
  9183. return false;
  9184. },
  9185. groupingRender : function (grdata, colspans, page, rn ) {
  9186. return this.each(function(){
  9187. var $t = this,
  9188. grp = $t.p.groupingView,
  9189. str = "", icon = "", hid, clid, pmrtl = grp.groupCollapse ? grp.plusicon : grp.minusicon, gv, cp=[], len =grp.groupField.length;
  9190. pmrtl += " tree-wrap-"+$t.p.direction;
  9191. $.each($t.p.colModel, function (i,n){
  9192. var ii;
  9193. for(ii=0;ii<len;ii++) {
  9194. if(grp.groupField[ii] === n.name ) {
  9195. cp[ii] = i;
  9196. break;
  9197. }
  9198. }
  9199. });
  9200. var toEnd = 0;
  9201. function findGroupIdx( ind , offset, grp) {
  9202. var ret = false, i;
  9203. if(offset===0) {
  9204. ret = grp[ind];
  9205. } else {
  9206. var id = grp[ind].idx;
  9207. if(id===0) {
  9208. ret = grp[ind];
  9209. } else {
  9210. for(i=ind;i >= 0; i--) {
  9211. if(grp[i].idx === id-offset) {
  9212. ret = grp[i];
  9213. break;
  9214. }
  9215. }
  9216. }
  9217. }
  9218. return ret;
  9219. }
  9220. function buildSummaryTd(i, ik, grp, foffset) {
  9221. var fdata = findGroupIdx(i, ik, grp),
  9222. cm = $t.p.colModel,
  9223. vv, grlen = fdata.cnt, str="", k;
  9224. for(k=foffset; k<colspans;k++) {
  9225. var tmpdata = "<td "+$t.formatCol(k,1,'')+">&#160;</td>",
  9226. tplfld = "{0}";
  9227. $.each(fdata.summary,function(){
  9228. if(this.nm === cm[k].name) {
  9229. if(cm[k].summaryTpl) {
  9230. tplfld = cm[k].summaryTpl;
  9231. }
  9232. if(typeof this.st === 'string' && this.st.toLowerCase() === 'avg') {
  9233. if(this.sd && this.vd) {
  9234. this.v = (this.v/this.vd);
  9235. } else if(this.v && grlen > 0) {
  9236. this.v = (this.v/grlen);
  9237. }
  9238. }
  9239. try {
  9240. this.groupCount = fdata.cnt;
  9241. this.groupIndex = fdata.dataIndex;
  9242. this.groupValue = fdata.value;
  9243. vv = $t.formatter('', this.v, k, this);
  9244. } catch (ef) {
  9245. vv = this.v;
  9246. }
  9247. tmpdata= "<td "+$t.formatCol(k,1,'')+">"+$.jgrid.format(tplfld,vv)+ "</td>";
  9248. return false;
  9249. }
  9250. });
  9251. str += tmpdata;
  9252. }
  9253. return str;
  9254. }
  9255. var sumreverse = $.makeArray(grp.groupSummary), mul;
  9256. sumreverse.reverse();
  9257. mul = $t.p.multiselect ? " colspan=\"2\"" : "";
  9258. $.each(grp.groups,function(i,n){
  9259. if(grp._locgr) {
  9260. if( !(n.startRow +n.cnt > (page-1)*rn && n.startRow < page*rn)) {
  9261. return true;
  9262. }
  9263. }
  9264. toEnd++;
  9265. clid = $t.p.id+"ghead_"+n.idx;
  9266. hid = clid+"_"+i;
  9267. icon = "<span style='cursor:pointer;' class='ui-icon "+pmrtl+"' onclick=\"jQuery('#"+$.jgrid.jqID($t.p.id)+"').jqGrid('groupingToggle','"+hid+"');return false;\"></span>";
  9268. try {
  9269. if ($.isArray(grp.formatDisplayField) && $.isFunction(grp.formatDisplayField[n.idx])) {
  9270. n.displayValue = grp.formatDisplayField[n.idx].call($t, n.displayValue, n.value, $t.p.colModel[cp[n.idx]], n.idx, grp);
  9271. gv = n.displayValue;
  9272. } else {
  9273. gv = $t.formatter(hid, n.displayValue, cp[n.idx], n.value );
  9274. }
  9275. } catch (egv) {
  9276. gv = n.displayValue;
  9277. }
  9278. if(grp.groupSummaryPos[n.idx] === 'header') {
  9279. 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>";
  9280. str += buildSummaryTd(i, 0, grp.groups, grp.groupColumnShow[n.idx] === false ? (mul ==="" ? 2 : 3) : ((mul ==="") ? 1 : 2) );
  9281. str += "</tr>";
  9282. } else {
  9283. 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=\""+(grp.groupColumnShow[n.idx] === false ? colspans-1 : colspans)+"\">"+icon+$.jgrid.template(grp.groupText[n.idx], gv, n.cnt, n.summary)+"</td></tr>";
  9284. }
  9285. var leaf = len-1 === n.idx;
  9286. if( leaf ) {
  9287. var gg = grp.groups[i+1], kk, ik, offset = 0, sgr = n.startRow,
  9288. end = gg !== undefined ? gg.startRow : grp.groups[i].startRow + grp.groups[i].cnt;
  9289. if(grp._locgr) {
  9290. offset = (page-1)*rn;
  9291. if(offset > n.startRow) {
  9292. sgr = offset;
  9293. }
  9294. }
  9295. for(kk=sgr;kk<end;kk++) {
  9296. if(!grdata[kk - offset]) { break; }
  9297. str += grdata[kk - offset].join('');
  9298. }
  9299. if(grp.groupSummaryPos[n.idx] !== 'header') {
  9300. var jj;
  9301. if (gg !== undefined) {
  9302. for (jj = 0; jj < grp.groupField.length; jj++) {
  9303. if (gg.dataIndex === grp.groupField[jj]) {
  9304. break;
  9305. }
  9306. }
  9307. toEnd = grp.groupField.length - jj;
  9308. }
  9309. for (ik = 0; ik < toEnd; ik++) {
  9310. if(!sumreverse[ik]) { continue; }
  9311. var hhdr = "";
  9312. if(grp.groupCollapse && !grp.showSummaryOnHide) {
  9313. hhdr = " style=\"display:none;\"";
  9314. }
  9315. str += "<tr"+hhdr+" jqfootlevel=\""+(n.idx-ik)+"\" role=\"row\" class=\"ui-widget-content jqfoot ui-row-"+$t.p.direction+"\">";
  9316. str += buildSummaryTd(i, ik, grp.groups, 0);
  9317. str += "</tr>";
  9318. }
  9319. toEnd = jj;
  9320. }
  9321. }
  9322. });
  9323. $("#"+$.jgrid.jqID($t.p.id)+" tbody:first").append(str);
  9324. // free up memory
  9325. str = null;
  9326. });
  9327. },
  9328. groupingGroupBy : function (name, options ) {
  9329. return this.each(function(){
  9330. var $t = this;
  9331. if(typeof name === "string") {
  9332. name = [name];
  9333. }
  9334. var grp = $t.p.groupingView;
  9335. $t.p.grouping = true;
  9336. grp._locgr = false;
  9337. //Set default, in case visibilityOnNextGrouping is undefined
  9338. if (grp.visibiltyOnNextGrouping === undefined) {
  9339. grp.visibiltyOnNextGrouping = [];
  9340. }
  9341. var i;
  9342. // show previous hidden groups if they are hidden and weren't removed yet
  9343. for(i=0;i<grp.groupField.length;i++) {
  9344. if(!grp.groupColumnShow[i] && grp.visibiltyOnNextGrouping[i]) {
  9345. $($t).jqGrid('showCol',grp.groupField[i]);
  9346. }
  9347. }
  9348. // set visibility status of current group columns on next grouping
  9349. for(i=0;i<name.length;i++) {
  9350. grp.visibiltyOnNextGrouping[i] = $("#"+$.jgrid.jqID($t.p.id)+"_"+$.jgrid.jqID(name[i])).is(":visible");
  9351. }
  9352. $t.p.groupingView = $.extend($t.p.groupingView, options || {});
  9353. grp.groupField = name;
  9354. $($t).trigger("reloadGrid");
  9355. });
  9356. },
  9357. groupingRemove : function (current) {
  9358. return this.each(function(){
  9359. var $t = this;
  9360. if(current === undefined) {
  9361. current = true;
  9362. }
  9363. $t.p.grouping = false;
  9364. if(current===true) {
  9365. var grp = $t.p.groupingView, i;
  9366. // show previous hidden groups if they are hidden and weren't removed yet
  9367. for(i=0;i<grp.groupField.length;i++) {
  9368. if (!grp.groupColumnShow[i] && grp.visibiltyOnNextGrouping[i]) {
  9369. $($t).jqGrid('showCol', grp.groupField);
  9370. }
  9371. }
  9372. $("tr.jqgroup, tr.jqfoot","#"+$.jgrid.jqID($t.p.id)+" tbody:first").remove();
  9373. $("tr.jqgrow:hidden","#"+$.jgrid.jqID($t.p.id)+" tbody:first").show();
  9374. } else {
  9375. $($t).trigger("reloadGrid");
  9376. }
  9377. });
  9378. },
  9379. groupingCalculations : {
  9380. handler: function(fn, v, field, round, roundType, rc) {
  9381. var funcs = {
  9382. sum: function() {
  9383. return parseFloat(v||0) + parseFloat((rc[field]||0));
  9384. },
  9385. min: function() {
  9386. if(v==="") {
  9387. return parseFloat(rc[field]||0);
  9388. }
  9389. return Math.min(parseFloat(v),parseFloat(rc[field]||0));
  9390. },
  9391. max: function() {
  9392. if(v==="") {
  9393. return parseFloat(rc[field]||0);
  9394. }
  9395. return Math.max(parseFloat(v),parseFloat(rc[field]||0));
  9396. },
  9397. count: function() {
  9398. if(v==="") {v=0;}
  9399. if(rc.hasOwnProperty(field)) {
  9400. return v+1;
  9401. }
  9402. return 0;
  9403. },
  9404. avg: function() {
  9405. // the same as sum, but at end we divide it
  9406. // so use sum instead of duplicating the code (?)
  9407. return funcs.sum();
  9408. }
  9409. };
  9410. if(!funcs[fn]) {
  9411. throw ("jqGrid Grouping No such method: " + fn);
  9412. }
  9413. var res = funcs[fn]();
  9414. if (round != null) {
  9415. if (roundType === 'fixed') {
  9416. res = res.toFixed(round);
  9417. } else {
  9418. var mul = Math.pow(10, round);
  9419. res = Math.round(res * mul) / mul;
  9420. }
  9421. }
  9422. return res;
  9423. }
  9424. }
  9425. });
  9426. })(jQuery);
  9427. /*jshint eqeqeq:false, eqnull:true, devel:true */
  9428. /*global jQuery, xmlJsonClass */
  9429. (function($){
  9430. /*
  9431. * jqGrid extension for constructing Grid Data from external file
  9432. * Tony Tomov tony@trirand.com
  9433. * http://trirand.com/blog/
  9434. * Dual licensed under the MIT and GPL licenses:
  9435. * http://www.opensource.org/licenses/mit-license.php
  9436. * http://www.gnu.org/licenses/gpl-2.0.html
  9437. **/
  9438. "use strict";
  9439. $.jgrid.extend({
  9440. jqGridImport : function(o) {
  9441. o = $.extend({
  9442. imptype : "xml", // xml, json, xmlstring, jsonstring
  9443. impstring: "",
  9444. impurl: "",
  9445. mtype: "GET",
  9446. impData : {},
  9447. xmlGrid :{
  9448. config : "roots>grid",
  9449. data: "roots>rows"
  9450. },
  9451. jsonGrid :{
  9452. config : "grid",
  9453. data: "data"
  9454. },
  9455. ajaxOptions :{}
  9456. }, o || {});
  9457. return this.each(function(){
  9458. var $t = this;
  9459. var xmlConvert = function (xml,o) {
  9460. var cnfg = $(o.xmlGrid.config,xml)[0];
  9461. var xmldata = $(o.xmlGrid.data,xml)[0], jstr, jstr1, key;
  9462. if(xmlJsonClass.xml2json && $.jgrid.parse) {
  9463. jstr = xmlJsonClass.xml2json(cnfg," ");
  9464. jstr = $.jgrid.parse(jstr);
  9465. for(key in jstr) {
  9466. if(jstr.hasOwnProperty(key)) {
  9467. jstr1=jstr[key];
  9468. }
  9469. }
  9470. if(xmldata) {
  9471. // save the datatype
  9472. var svdatatype = jstr.grid.datatype;
  9473. jstr.grid.datatype = 'xmlstring';
  9474. jstr.grid.datastr = xml;
  9475. $($t).jqGrid( jstr1 ).jqGrid("setGridParam",{datatype:svdatatype});
  9476. } else {
  9477. $($t).jqGrid( jstr1 );
  9478. }
  9479. jstr = null;jstr1=null;
  9480. } else {
  9481. alert("xml2json or parse are not present");
  9482. }
  9483. };
  9484. var jsonConvert = function (jsonstr,o){
  9485. if (jsonstr && typeof jsonstr === 'string') {
  9486. var _jsonparse = false;
  9487. if($.jgrid.useJSON) {
  9488. $.jgrid.useJSON = false;
  9489. _jsonparse = true;
  9490. }
  9491. var json = $.jgrid.parse(jsonstr);
  9492. if(_jsonparse) { $.jgrid.useJSON = true; }
  9493. var gprm = json[o.jsonGrid.config];
  9494. var jdata = json[o.jsonGrid.data];
  9495. if(jdata) {
  9496. var svdatatype = gprm.datatype;
  9497. gprm.datatype = 'jsonstring';
  9498. gprm.datastr = jdata;
  9499. $($t).jqGrid( gprm ).jqGrid("setGridParam",{datatype:svdatatype});
  9500. } else {
  9501. $($t).jqGrid( gprm );
  9502. }
  9503. }
  9504. };
  9505. switch (o.imptype){
  9506. case 'xml':
  9507. $.ajax($.extend({
  9508. url:o.impurl,
  9509. type:o.mtype,
  9510. data: o.impData,
  9511. dataType:"xml",
  9512. complete: function(xml,stat) {
  9513. if(stat === 'success') {
  9514. xmlConvert(xml.responseXML,o);
  9515. $($t).triggerHandler("jqGridImportComplete", [xml, o]);
  9516. if($.isFunction(o.importComplete)) {
  9517. o.importComplete(xml);
  9518. }
  9519. }
  9520. xml=null;
  9521. }
  9522. }, o.ajaxOptions));
  9523. break;
  9524. case 'xmlstring' :
  9525. // we need to make just the conversion and use the same code as xml
  9526. if(o.impstring && typeof o.impstring === 'string') {
  9527. var xmld = $.parseXML(o.impstring);
  9528. if(xmld) {
  9529. xmlConvert(xmld,o);
  9530. $($t).triggerHandler("jqGridImportComplete", [xmld, o]);
  9531. if($.isFunction(o.importComplete)) {
  9532. o.importComplete(xmld);
  9533. }
  9534. o.impstring = null;
  9535. }
  9536. xmld = null;
  9537. }
  9538. break;
  9539. case 'json':
  9540. $.ajax($.extend({
  9541. url:o.impurl,
  9542. type:o.mtype,
  9543. data: o.impData,
  9544. dataType:"json",
  9545. complete: function(json) {
  9546. try {
  9547. jsonConvert(json.responseText,o );
  9548. $($t).triggerHandler("jqGridImportComplete", [json, o]);
  9549. if($.isFunction(o.importComplete)) {
  9550. o.importComplete(json);
  9551. }
  9552. } catch (ee){}
  9553. json=null;
  9554. }
  9555. }, o.ajaxOptions ));
  9556. break;
  9557. case 'jsonstring' :
  9558. if(o.impstring && typeof o.impstring === 'string') {
  9559. jsonConvert(o.impstring,o );
  9560. $($t).triggerHandler("jqGridImportComplete", [o.impstring, o]);
  9561. if($.isFunction(o.importComplete)) {
  9562. o.importComplete(o.impstring);
  9563. }
  9564. o.impstring = null;
  9565. }
  9566. break;
  9567. }
  9568. });
  9569. },
  9570. jqGridExport : function(o) {
  9571. o = $.extend({
  9572. exptype : "xmlstring",
  9573. root: "grid",
  9574. ident: "\t"
  9575. }, o || {});
  9576. var ret = null;
  9577. this.each(function () {
  9578. if(!this.grid) { return;}
  9579. var key, gprm = $.extend(true, {},$(this).jqGrid("getGridParam"));
  9580. // we need to check for:
  9581. // 1.multiselect, 2.subgrid 3. treegrid and remove the unneded columns from colNames
  9582. if(gprm.rownumbers) {
  9583. gprm.colNames.splice(0,1);
  9584. gprm.colModel.splice(0,1);
  9585. }
  9586. if(gprm.multiselect) {
  9587. gprm.colNames.splice(0,1);
  9588. gprm.colModel.splice(0,1);
  9589. }
  9590. if(gprm.subGrid) {
  9591. gprm.colNames.splice(0,1);
  9592. gprm.colModel.splice(0,1);
  9593. }
  9594. gprm.knv = null;
  9595. if(gprm.treeGrid) {
  9596. for (key in gprm.treeReader) {
  9597. if(gprm.treeReader.hasOwnProperty(key)) {
  9598. gprm.colNames.splice(gprm.colNames.length-1);
  9599. gprm.colModel.splice(gprm.colModel.length-1);
  9600. }
  9601. }
  9602. }
  9603. switch (o.exptype) {
  9604. case 'xmlstring' :
  9605. ret = "<"+o.root+">"+xmlJsonClass.json2xml(gprm,o.ident)+"</"+o.root+">";
  9606. break;
  9607. case 'jsonstring' :
  9608. ret = "{"+ xmlJsonClass.toJson(gprm,o.root,o.ident,false)+"}";
  9609. if(gprm.postData.filters !== undefined) {
  9610. ret=ret.replace(/filters":"/,'filters":');
  9611. ret=ret.replace(/}]}"/,'}]}');
  9612. }
  9613. break;
  9614. }
  9615. });
  9616. return ret;
  9617. },
  9618. excelExport : function(o) {
  9619. o = $.extend({
  9620. exptype : "remote",
  9621. url : null,
  9622. oper: "oper",
  9623. tag: "excel",
  9624. exportOptions : {}
  9625. }, o || {});
  9626. return this.each(function(){
  9627. if(!this.grid) { return;}
  9628. var url;
  9629. if(o.exptype === "remote") {
  9630. var pdata = $.extend({},this.p.postData);
  9631. pdata[o.oper] = o.tag;
  9632. var params = jQuery.param(pdata);
  9633. if(o.url.indexOf("?") !== -1) { url = o.url+"&"+params; }
  9634. else { url = o.url+"?"+params; }
  9635. window.location = url;
  9636. }
  9637. });
  9638. }
  9639. });
  9640. })(jQuery);
  9641. /*jshint eqeqeq:false, eqnull:true, devel:true */
  9642. /*global jQuery */
  9643. (function($){
  9644. /**
  9645. * jqGrid extension for manipulating Grid Data
  9646. * Tony Tomov tony@trirand.com
  9647. * http://trirand.com/blog/
  9648. * Dual licensed under the MIT and GPL licenses:
  9649. * http://www.opensource.org/licenses/mit-license.php
  9650. * http://www.gnu.org/licenses/gpl-2.0.html
  9651. **/
  9652. "use strict";
  9653. $.jgrid.inlineEdit = $.jgrid.inlineEdit || {};
  9654. $.jgrid.extend({
  9655. //Editing
  9656. editRow : function(rowid,keys,oneditfunc,successfunc, url, extraparam, aftersavefunc,errorfunc, afterrestorefunc) {
  9657. // Compatible mode old versions
  9658. var o={}, args = $.makeArray(arguments).slice(1);
  9659. if( $.type(args[0]) === "object" ) {
  9660. o = args[0];
  9661. } else {
  9662. if (keys !== undefined) { o.keys = keys; }
  9663. if ($.isFunction(oneditfunc)) { o.oneditfunc = oneditfunc; }
  9664. if ($.isFunction(successfunc)) { o.successfunc = successfunc; }
  9665. if (url !== undefined) { o.url = url; }
  9666. if (extraparam !== undefined) { o.extraparam = extraparam; }
  9667. if ($.isFunction(aftersavefunc)) { o.aftersavefunc = aftersavefunc; }
  9668. if ($.isFunction(errorfunc)) { o.errorfunc = errorfunc; }
  9669. if ($.isFunction(afterrestorefunc)) { o.afterrestorefunc = afterrestorefunc; }
  9670. // last two not as param, but as object (sorry)
  9671. //if (restoreAfterError !== undefined) { o.restoreAfterError = restoreAfterError; }
  9672. //if (mtype !== undefined) { o.mtype = mtype || "POST"; }
  9673. }
  9674. o = $.extend(true, {
  9675. keys : false,
  9676. oneditfunc: null,
  9677. successfunc: null,
  9678. url: null,
  9679. extraparam: {},
  9680. aftersavefunc: null,
  9681. errorfunc: null,
  9682. afterrestorefunc: null,
  9683. restoreAfterError: true,
  9684. mtype: "POST",
  9685. focusField : true
  9686. }, $.jgrid.inlineEdit, o );
  9687. // End compatible
  9688. return this.each(function(){
  9689. var $t = this, nm, tmp, editable, cnt=0, focus=null, svr={}, ind,cm, bfer;
  9690. if (!$t.grid ) { return; }
  9691. ind = $($t).jqGrid("getInd",rowid,true);
  9692. if( ind === false ) {return;}
  9693. bfer = $.isFunction( o.beforeEditRow ) ? o.beforeEditRow.call($t,o, rowid) : undefined;
  9694. if( bfer === undefined ) {
  9695. bfer = true;
  9696. }
  9697. if(!bfer) { return; }
  9698. editable = $(ind).attr("editable") || "0";
  9699. if (editable === "0" && !$(ind).hasClass("not-editable-row")) {
  9700. cm = $t.p.colModel;
  9701. $('td[role="gridcell"]',ind).each( function(i) {
  9702. nm = cm[i].name;
  9703. var treeg = $t.p.treeGrid===true && nm === $t.p.ExpandColumn;
  9704. if(treeg) { tmp = $("span:first",this).html();}
  9705. else {
  9706. try {
  9707. tmp = $.unformat.call($t,this,{rowId:rowid, colModel:cm[i]},i);
  9708. } catch (_) {
  9709. tmp = ( cm[i].edittype && cm[i].edittype === 'textarea' ) ? $(this).text() : $(this).html();
  9710. }
  9711. }
  9712. if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn') {
  9713. if($t.p.autoencode) { tmp = $.jgrid.htmlDecode(tmp); }
  9714. svr[nm]=tmp;
  9715. if(cm[i].editable===true) {
  9716. if(focus===null) { focus = i; }
  9717. if (treeg) { $("span:first",this).html(""); }
  9718. else { $(this).html(""); }
  9719. var opt = $.extend({},cm[i].editoptions || {},{id:rowid+"_"+nm,name:nm,rowId:rowid});
  9720. if(!cm[i].edittype) { cm[i].edittype = "text"; }
  9721. if(tmp === "&nbsp;" || tmp === "&#160;" || (tmp.length===1 && tmp.charCodeAt(0)===160) ) {tmp='';}
  9722. var elc = $.jgrid.createEl.call($t,cm[i].edittype,opt,tmp,true,$.extend({},$.jgrid.ajaxOptions,$t.p.ajaxSelectOptions || {}));
  9723. $(elc).addClass("editable");
  9724. if(treeg) { $("span:first",this).append(elc); }
  9725. else { $(this).append(elc); }
  9726. $.jgrid.bindEv.call($t, elc, opt);
  9727. //Again IE
  9728. if(cm[i].edittype === "select" && cm[i].editoptions!==undefined && cm[i].editoptions.multiple===true && cm[i].editoptions.dataUrl===undefined && $.jgrid.msie) {
  9729. $(elc).width($(elc).width());
  9730. }
  9731. cnt++;
  9732. }
  9733. }
  9734. });
  9735. if(cnt > 0) {
  9736. svr.id = rowid; $t.p.savedRow.push(svr);
  9737. $(ind).attr("editable","1");
  9738. if(o.focusField ) {
  9739. if(typeof o.focusField === 'number' && parseInt(o.focusField,10) <= cm.length) {
  9740. focus = o.focusField;
  9741. }
  9742. setTimeout(function(){
  9743. var fe = $("td:eq("+focus+") :input:visible",ind).not(":disabled");
  9744. if(fe.length > 0) {
  9745. fe.focus();
  9746. }
  9747. },0);
  9748. }
  9749. if(o.keys===true) {
  9750. $(ind).bind("keydown",function(e) {
  9751. if (e.keyCode === 27) {
  9752. $($t).jqGrid("restoreRow",rowid, o.afterrestorefunc);
  9753. if($t.p._inlinenav) {
  9754. try {
  9755. $($t).jqGrid('showAddEditButtons');
  9756. } catch (eer1) {}
  9757. }
  9758. return false;
  9759. }
  9760. if (e.keyCode === 13) {
  9761. var ta = e.target;
  9762. if(ta.tagName === 'TEXTAREA') { return true; }
  9763. if( $($t).jqGrid("saveRow", rowid, o ) ) {
  9764. if($t.p._inlinenav) {
  9765. try {
  9766. $($t).jqGrid('showAddEditButtons');
  9767. } catch (eer2) {}
  9768. }
  9769. }
  9770. return false;
  9771. }
  9772. });
  9773. }
  9774. $($t).triggerHandler("jqGridInlineEditRow", [rowid, o]);
  9775. if( $.isFunction(o.oneditfunc)) { o.oneditfunc.call($t, rowid); }
  9776. }
  9777. }
  9778. });
  9779. },
  9780. saveRow : function(rowid, successfunc, url, extraparam, aftersavefunc,errorfunc, afterrestorefunc) {
  9781. // Compatible mode old versions
  9782. var args = $.makeArray(arguments).slice(1), o = {};
  9783. if( $.type(args[0]) === "object" ) {
  9784. o = args[0];
  9785. } else {
  9786. if ($.isFunction(successfunc)) { o.successfunc = successfunc; }
  9787. if (url !== undefined) { o.url = url; }
  9788. if (extraparam !== undefined) { o.extraparam = extraparam; }
  9789. if ($.isFunction(aftersavefunc)) { o.aftersavefunc = aftersavefunc; }
  9790. if ($.isFunction(errorfunc)) { o.errorfunc = errorfunc; }
  9791. if ($.isFunction(afterrestorefunc)) { o.afterrestorefunc = afterrestorefunc; }
  9792. }
  9793. o = $.extend(true, {
  9794. successfunc: null,
  9795. url: null,
  9796. extraparam: {},
  9797. aftersavefunc: null,
  9798. errorfunc: null,
  9799. afterrestorefunc: null,
  9800. restoreAfterError: true,
  9801. mtype: "POST",
  9802. saveui : "enable",
  9803. savetext : $.jgrid.defaults.savetext || "Saving..."
  9804. }, $.jgrid.inlineEdit, o );
  9805. // End compatible
  9806. var success = false;
  9807. var $t = this[0], nm, tmp={}, tmp2={}, tmp3= {}, editable, fr, cv, ind;
  9808. if (!$t.grid ) { return success; }
  9809. ind = $($t).jqGrid("getInd",rowid,true);
  9810. if(ind === false) {return success;}
  9811. var bfsr = $.isFunction( o.beforeSaveRow ) ? o.beforeSaveRow.call($t,o, rowid) : undefined;
  9812. if( bfsr === undefined ) {
  9813. bfsr = true;
  9814. }
  9815. if(!bfsr) { return; }
  9816. editable = $(ind).attr("editable");
  9817. o.url = o.url || $t.p.editurl;
  9818. if (editable==="1") {
  9819. var cm;
  9820. $('td[role="gridcell"]',ind).each(function(i) {
  9821. cm = $t.p.colModel[i];
  9822. nm = cm.name;
  9823. if ( nm !== 'cb' && nm !== 'subgrid' && cm.editable===true && nm !== 'rn' && !$(this).hasClass('not-editable-cell')) {
  9824. switch (cm.edittype) {
  9825. case "checkbox":
  9826. var cbv = ["Yes","No"];
  9827. if(cm.editoptions ) {
  9828. cbv = cm.editoptions.value.split(":");
  9829. }
  9830. tmp[nm]= $("input",this).is(":checked") ? cbv[0] : cbv[1];
  9831. break;
  9832. case 'text':
  9833. case 'password':
  9834. case 'textarea':
  9835. case "button" :
  9836. tmp[nm]=$("input, textarea",this).val();
  9837. break;
  9838. case 'select':
  9839. if(!cm.editoptions.multiple) {
  9840. tmp[nm] = $("select option:selected",this).val();
  9841. tmp2[nm] = $("select option:selected", this).text();
  9842. } else {
  9843. var sel = $("select",this), selectedText = [];
  9844. tmp[nm] = $(sel).val();
  9845. if(tmp[nm]) { tmp[nm]= tmp[nm].join(","); } else { tmp[nm] =""; }
  9846. $("select option:selected",this).each(
  9847. function(i,selected){
  9848. selectedText[i] = $(selected).text();
  9849. }
  9850. );
  9851. tmp2[nm] = selectedText.join(",");
  9852. }
  9853. if(cm.formatter && cm.formatter === 'select') { tmp2={}; }
  9854. break;
  9855. case 'custom' :
  9856. try {
  9857. if(cm.editoptions && $.isFunction(cm.editoptions.custom_value)) {
  9858. tmp[nm] = cm.editoptions.custom_value.call($t, $(".customelement",this),'get');
  9859. if (tmp[nm] === undefined) { throw "e2"; }
  9860. } else { throw "e1"; }
  9861. } catch (e) {
  9862. if (e==="e1") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.nodefined,$.jgrid.edit.bClose); }
  9863. if (e==="e2") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose); }
  9864. else { $.jgrid.info_dialog($.jgrid.errors.errcap,e.message,$.jgrid.edit.bClose); }
  9865. }
  9866. break;
  9867. }
  9868. cv = $.jgrid.checkValues.call($t,tmp[nm],i);
  9869. if(cv[0] === false) {
  9870. return false;
  9871. }
  9872. if($t.p.autoencode) { tmp[nm] = $.jgrid.htmlEncode(tmp[nm]); }
  9873. if(o.url !== 'clientArray' && cm.editoptions && cm.editoptions.NullIfEmpty === true) {
  9874. if(tmp[nm] === "") {
  9875. tmp3[nm] = 'null';
  9876. }
  9877. }
  9878. }
  9879. });
  9880. if (cv[0] === false){
  9881. try {
  9882. var tr = $($t).jqGrid('getGridRowById', rowid), positions = $.jgrid.findPos(tr);
  9883. $.jgrid.info_dialog($.jgrid.errors.errcap,cv[1],$.jgrid.edit.bClose,{left:positions[0],top:positions[1]+$(tr).outerHeight()});
  9884. } catch (e) {
  9885. alert(cv[1]);
  9886. }
  9887. return success;
  9888. }
  9889. var idname, opers = $t.p.prmNames, oldRowId = rowid;
  9890. if ($t.p.keyName === false) {
  9891. idname = opers.id;
  9892. } else {
  9893. idname = $t.p.keyName;
  9894. }
  9895. if(tmp) {
  9896. tmp[opers.oper] = opers.editoper;
  9897. if (tmp[idname] === undefined || tmp[idname]==="") {
  9898. tmp[idname] = rowid;
  9899. } else if (ind.id !== $t.p.idPrefix + tmp[idname]) {
  9900. // rename rowid
  9901. var oldid = $.jgrid.stripPref($t.p.idPrefix, rowid);
  9902. if ($t.p._index[oldid] !== undefined) {
  9903. $t.p._index[tmp[idname]] = $t.p._index[oldid];
  9904. delete $t.p._index[oldid];
  9905. }
  9906. rowid = $t.p.idPrefix + tmp[idname];
  9907. $(ind).attr("id", rowid);
  9908. if ($t.p.selrow === oldRowId) {
  9909. $t.p.selrow = rowid;
  9910. }
  9911. if ($.isArray($t.p.selarrrow)) {
  9912. var i = $.inArray(oldRowId, $t.p.selarrrow);
  9913. if (i>=0) {
  9914. $t.p.selarrrow[i] = rowid;
  9915. }
  9916. }
  9917. if ($t.p.multiselect) {
  9918. var newCboxId = "jqg_" + $t.p.id + "_" + rowid;
  9919. $("input.cbox",ind)
  9920. .attr("id", newCboxId)
  9921. .attr("name", newCboxId);
  9922. }
  9923. // TODO: to test the case of frozen columns
  9924. }
  9925. if($t.p.inlineData === undefined) { $t.p.inlineData ={}; }
  9926. tmp = $.extend({},tmp,$t.p.inlineData,o.extraparam);
  9927. }
  9928. if (o.url === 'clientArray') {
  9929. tmp = $.extend({},tmp, tmp2);
  9930. if($t.p.autoencode) {
  9931. $.each(tmp,function(n,v){
  9932. tmp[n] = $.jgrid.htmlDecode(v);
  9933. });
  9934. }
  9935. var k, resp = $($t).jqGrid("setRowData",rowid,tmp);
  9936. $(ind).attr("editable","0");
  9937. for(k=0;k<$t.p.savedRow.length;k++) {
  9938. if( String($t.p.savedRow[k].id) === String(oldRowId)) {fr = k; break;}
  9939. }
  9940. if(fr >= 0) { $t.p.savedRow.splice(fr,1); }
  9941. $($t).triggerHandler("jqGridInlineAfterSaveRow", [rowid, resp, tmp, o]);
  9942. if( $.isFunction(o.aftersavefunc) ) { o.aftersavefunc.call($t, rowid, resp, tmp, o); }
  9943. success = true;
  9944. $(ind).removeClass("jqgrid-new-row").unbind("keydown");
  9945. } else {
  9946. $($t).jqGrid("progressBar", {method:"show", loadtype : o.saveui, htmlcontent: o.savetext });
  9947. tmp3 = $.extend({},tmp,tmp3);
  9948. tmp3[idname] = $.jgrid.stripPref($t.p.idPrefix, tmp3[idname]);
  9949. $.ajax($.extend({
  9950. url:o.url,
  9951. data: $.isFunction($t.p.serializeRowData) ? $t.p.serializeRowData.call($t, tmp3) : tmp3,
  9952. type: o.mtype,
  9953. async : false, //?!?
  9954. complete: function(res,stat){
  9955. $($t).jqGrid("progressBar", {method:"hide", loadtype : o.saveui, htmlcontent: o.savetext});
  9956. if (stat === "success"){
  9957. var ret = true, sucret, k;
  9958. sucret = $($t).triggerHandler("jqGridInlineSuccessSaveRow", [res, rowid, o]);
  9959. if (!$.isArray(sucret)) {sucret = [true, tmp];}
  9960. if (sucret[0] && $.isFunction(o.successfunc)) {sucret = o.successfunc.call($t, res);}
  9961. if($.isArray(sucret)) {
  9962. // expect array - status, data, rowid
  9963. ret = sucret[0];
  9964. tmp = sucret[1] || tmp;
  9965. } else {
  9966. ret = sucret;
  9967. }
  9968. if (ret===true) {
  9969. if($t.p.autoencode) {
  9970. $.each(tmp,function(n,v){
  9971. tmp[n] = $.jgrid.htmlDecode(v);
  9972. });
  9973. }
  9974. tmp = $.extend({},tmp, tmp2);
  9975. $($t).jqGrid("setRowData",rowid,tmp);
  9976. $(ind).attr("editable","0");
  9977. for(k=0;k<$t.p.savedRow.length;k++) {
  9978. if( String($t.p.savedRow[k].id) === String(rowid)) {fr = k; break;}
  9979. }
  9980. if(fr >= 0) { $t.p.savedRow.splice(fr,1); }
  9981. $($t).triggerHandler("jqGridInlineAfterSaveRow", [rowid, res, tmp, o]);
  9982. if( $.isFunction(o.aftersavefunc) ) { o.aftersavefunc.call($t, rowid, res, tmp, o); }
  9983. success = true;
  9984. $(ind).removeClass("jqgrid-new-row").unbind("keydown");
  9985. } else {
  9986. $($t).triggerHandler("jqGridInlineErrorSaveRow", [rowid, res, stat, null, o]);
  9987. if($.isFunction(o.errorfunc) ) {
  9988. o.errorfunc.call($t, rowid, res, stat, null);
  9989. }
  9990. if(o.restoreAfterError === true) {
  9991. $($t).jqGrid("restoreRow",rowid, o.afterrestorefunc);
  9992. }
  9993. }
  9994. }
  9995. },
  9996. error:function(res,stat,err){
  9997. $("#lui_"+$.jgrid.jqID($t.p.id)).hide();
  9998. $($t).triggerHandler("jqGridInlineErrorSaveRow", [rowid, res, stat, err, o]);
  9999. if($.isFunction(o.errorfunc) ) {
  10000. o.errorfunc.call($t, rowid, res, stat, err);
  10001. } else {
  10002. var rT = res.responseText || res.statusText;
  10003. try {
  10004. $.jgrid.info_dialog($.jgrid.errors.errcap,'<div class="ui-state-error">'+ rT +'</div>', $.jgrid.edit.bClose,{buttonalign:'right'});
  10005. } catch(e) {
  10006. alert(rT);
  10007. }
  10008. }
  10009. if(o.restoreAfterError === true) {
  10010. $($t).jqGrid("restoreRow",rowid, o.afterrestorefunc);
  10011. }
  10012. }
  10013. }, $.jgrid.ajaxOptions, $t.p.ajaxRowOptions || {}));
  10014. }
  10015. }
  10016. return success;
  10017. },
  10018. restoreRow : function(rowid, afterrestorefunc) {
  10019. // Compatible mode old versions
  10020. var args = $.makeArray(arguments).slice(1), o={};
  10021. if( $.type(args[0]) === "object" ) {
  10022. o = args[0];
  10023. } else {
  10024. if ($.isFunction(afterrestorefunc)) { o.afterrestorefunc = afterrestorefunc; }
  10025. }
  10026. o = $.extend(true, {}, $.jgrid.inlineEdit, o );
  10027. // End compatible
  10028. return this.each(function(){
  10029. var $t= this, fr=-1, ind, ares={}, k;
  10030. if (!$t.grid ) { return; }
  10031. ind = $($t).jqGrid("getInd",rowid,true);
  10032. if(ind === false) {return;}
  10033. var bfcr = $.isFunction( o.beforeCancelRow ) ? o.beforeCancelRow.call($t, o, rowid) : undefined;
  10034. if( bfcr === undefined ) {
  10035. bfcr = true;
  10036. }
  10037. if(!bfcr) { return; }
  10038. for(k=0;k<$t.p.savedRow.length;k++) {
  10039. if( String($t.p.savedRow[k].id) === String(rowid)) {fr = k; break;}
  10040. }
  10041. if(fr >= 0) {
  10042. if($.isFunction($.fn.datepicker)) {
  10043. try {
  10044. $("input.hasDatepicker","#"+$.jgrid.jqID(ind.id)).datepicker('hide');
  10045. } catch (e) {}
  10046. }
  10047. $.each($t.p.colModel, function(){
  10048. if(this.editable === true && $t.p.savedRow[fr].hasOwnProperty(this.name)) {
  10049. ares[this.name] = $t.p.savedRow[fr][this.name];
  10050. }
  10051. });
  10052. $($t).jqGrid("setRowData",rowid,ares);
  10053. $(ind).attr("editable","0").unbind("keydown");
  10054. $t.p.savedRow.splice(fr,1);
  10055. if($("#"+$.jgrid.jqID(rowid), "#"+$.jgrid.jqID($t.p.id)).hasClass("jqgrid-new-row")){
  10056. setTimeout(function(){
  10057. $($t).jqGrid("delRowData",rowid);
  10058. $($t).jqGrid('showAddEditButtons');
  10059. },0);
  10060. }
  10061. }
  10062. $($t).triggerHandler("jqGridInlineAfterRestoreRow", [rowid]);
  10063. if ($.isFunction(o.afterrestorefunc))
  10064. {
  10065. o.afterrestorefunc.call($t, rowid);
  10066. }
  10067. });
  10068. },
  10069. addRow : function ( p ) {
  10070. p = $.extend(true, {
  10071. rowID : null,
  10072. initdata : {},
  10073. position :"first",
  10074. useDefValues : true,
  10075. useFormatter : false,
  10076. addRowParams : {extraparam:{}}
  10077. },p || {});
  10078. return this.each(function(){
  10079. if (!this.grid ) { return; }
  10080. var $t = this;
  10081. var bfar = $.isFunction( p.beforeAddRow ) ? p.beforeAddRow.call($t,p.addRowParams) : undefined;
  10082. if( bfar === undefined ) {
  10083. bfar = true;
  10084. }
  10085. if(!bfar) { return; }
  10086. p.rowID = $.isFunction(p.rowID) ? p.rowID.call($t, p) : ( (p.rowID != null) ? p.rowID : $.jgrid.randId());
  10087. if(p.useDefValues === true) {
  10088. $($t.p.colModel).each(function(){
  10089. if( this.editoptions && this.editoptions.defaultValue ) {
  10090. var opt = this.editoptions.defaultValue,
  10091. tmp = $.isFunction(opt) ? opt.call($t) : opt;
  10092. p.initdata[this.name] = tmp;
  10093. }
  10094. });
  10095. }
  10096. $($t).jqGrid('addRowData', p.rowID, p.initdata, p.position);
  10097. p.rowID = $t.p.idPrefix + p.rowID;
  10098. $("#"+$.jgrid.jqID(p.rowID), "#"+$.jgrid.jqID($t.p.id)).addClass("jqgrid-new-row");
  10099. if(p.useFormatter) {
  10100. $("#"+$.jgrid.jqID(p.rowID)+" .ui-inline-edit", "#"+$.jgrid.jqID($t.p.id)).click();
  10101. } else {
  10102. var opers = $t.p.prmNames,
  10103. oper = opers.oper;
  10104. p.addRowParams.extraparam[oper] = opers.addoper;
  10105. $($t).jqGrid('editRow', p.rowID, p.addRowParams);
  10106. $($t).jqGrid('setSelection', p.rowID);
  10107. }
  10108. });
  10109. },
  10110. inlineNav : function (elem, o) {
  10111. o = $.extend(true,{
  10112. edit: true,
  10113. editicon: "ui-icon-pencil",
  10114. add: true,
  10115. addicon:"ui-icon-plus",
  10116. save: true,
  10117. saveicon:"ui-icon-disk",
  10118. cancel: true,
  10119. cancelicon:"ui-icon-cancel",
  10120. addParams : {addRowParams: {extraparam: {}}},
  10121. editParams : {},
  10122. restoreAfterSelect : true
  10123. }, $.jgrid.nav, o ||{});
  10124. return this.each(function(){
  10125. if (!this.grid ) { return; }
  10126. var $t = this, onSelect, gID = $.jgrid.jqID($t.p.id);
  10127. $t.p._inlinenav = true;
  10128. // detect the formatactions column
  10129. if(o.addParams.useFormatter === true) {
  10130. var cm = $t.p.colModel,i;
  10131. for (i = 0; i<cm.length; i++) {
  10132. if(cm[i].formatter && cm[i].formatter === "actions" ) {
  10133. if(cm[i].formatoptions) {
  10134. var defaults = {
  10135. keys:false,
  10136. onEdit : null,
  10137. onSuccess: null,
  10138. afterSave:null,
  10139. onError: null,
  10140. afterRestore: null,
  10141. extraparam: {},
  10142. url: null
  10143. },
  10144. ap = $.extend( defaults, cm[i].formatoptions );
  10145. o.addParams.addRowParams = {
  10146. "keys" : ap.keys,
  10147. "oneditfunc" : ap.onEdit,
  10148. "successfunc" : ap.onSuccess,
  10149. "url" : ap.url,
  10150. "extraparam" : ap.extraparam,
  10151. "aftersavefunc" : ap.afterSave,
  10152. "errorfunc": ap.onError,
  10153. "afterrestorefunc" : ap.afterRestore
  10154. };
  10155. }
  10156. break;
  10157. }
  10158. }
  10159. }
  10160. if(o.add) {
  10161. $($t).jqGrid('navButtonAdd', elem,{
  10162. caption : o.addtext,
  10163. title : o.addtitle,
  10164. buttonicon : o.addicon,
  10165. id : $t.p.id+"_iladd",
  10166. onClickButton : function () {
  10167. $($t).jqGrid('addRow', o.addParams);
  10168. if(!o.addParams.useFormatter) {
  10169. $("#"+gID+"_ilsave").removeClass('ui-state-disabled');
  10170. $("#"+gID+"_ilcancel").removeClass('ui-state-disabled');
  10171. $("#"+gID+"_iladd").addClass('ui-state-disabled');
  10172. $("#"+gID+"_iledit").addClass('ui-state-disabled');
  10173. }
  10174. }
  10175. });
  10176. }
  10177. if(o.edit) {
  10178. $($t).jqGrid('navButtonAdd', elem,{
  10179. caption : o.edittext,
  10180. title : o.edittitle,
  10181. buttonicon : o.editicon,
  10182. id : $t.p.id+"_iledit",
  10183. onClickButton : function () {
  10184. var sr = $($t).jqGrid('getGridParam','selrow');
  10185. if(sr) {
  10186. $($t).jqGrid('editRow', sr, o.editParams);
  10187. $("#"+gID+"_ilsave").removeClass('ui-state-disabled');
  10188. $("#"+gID+"_ilcancel").removeClass('ui-state-disabled');
  10189. $("#"+gID+"_iladd").addClass('ui-state-disabled');
  10190. $("#"+gID+"_iledit").addClass('ui-state-disabled');
  10191. } else {
  10192. $.jgrid.viewModal("#alertmod",{gbox:"#gbox_"+gID,jqm:true});$("#jqg_alrt").focus();
  10193. }
  10194. }
  10195. });
  10196. }
  10197. if(o.save) {
  10198. $($t).jqGrid('navButtonAdd', elem,{
  10199. caption : o.savetext || '',
  10200. title : o.savetitle || 'Save row',
  10201. buttonicon : o.saveicon,
  10202. id : $t.p.id+"_ilsave",
  10203. onClickButton : function () {
  10204. var sr = $t.p.savedRow[0].id;
  10205. if(sr) {
  10206. var opers = $t.p.prmNames,
  10207. oper = opers.oper, tmpParams = o.editParams;
  10208. if($("#"+$.jgrid.jqID(sr), "#"+gID ).hasClass("jqgrid-new-row")) {
  10209. o.addParams.addRowParams.extraparam[oper] = opers.addoper;
  10210. tmpParams = o.addParams.addRowParams;
  10211. } else {
  10212. if(!o.editParams.extraparam) {
  10213. o.editParams.extraparam = {};
  10214. }
  10215. o.editParams.extraparam[oper] = opers.editoper;
  10216. }
  10217. if( $($t).jqGrid('saveRow', sr, tmpParams) ) {
  10218. $($t).jqGrid('showAddEditButtons');
  10219. }
  10220. } else {
  10221. $.jgrid.viewModal("#alertmod",{gbox:"#gbox_"+gID,jqm:true});$("#jqg_alrt").focus();
  10222. }
  10223. }
  10224. });
  10225. $("#"+gID+"_ilsave").addClass('ui-state-disabled');
  10226. }
  10227. if(o.cancel) {
  10228. $($t).jqGrid('navButtonAdd', elem,{
  10229. caption : o.canceltext || '',
  10230. title : o.canceltitle || 'Cancel row editing',
  10231. buttonicon : o.cancelicon,
  10232. id : $t.p.id+"_ilcancel",
  10233. onClickButton : function () {
  10234. var sr = $t.p.savedRow[0].id, cancelPrm = o.editParams;
  10235. if(sr) {
  10236. if($("#"+$.jgrid.jqID(sr), "#"+gID ).hasClass("jqgrid-new-row")) {
  10237. cancelPrm = o.addParams.addRowParams;
  10238. }
  10239. $($t).jqGrid('restoreRow', sr, cancelPrm);
  10240. $($t).jqGrid('showAddEditButtons');
  10241. } else {
  10242. $.jgrid.viewModal("#alertmod",{gbox:"#gbox_"+gID,jqm:true});$("#jqg_alrt").focus();
  10243. }
  10244. }
  10245. });
  10246. $("#"+gID+"_ilcancel").addClass('ui-state-disabled');
  10247. }
  10248. if(o.restoreAfterSelect === true) {
  10249. if($.isFunction($t.p.beforeSelectRow)) {
  10250. onSelect = $t.p.beforeSelectRow;
  10251. } else {
  10252. onSelect = false;
  10253. }
  10254. $t.p.beforeSelectRow = function(id, stat) {
  10255. var ret = true;
  10256. if($t.p.savedRow.length > 0 && $t.p._inlinenav===true && ( id !== $t.p.selrow && $t.p.selrow !==null) ) {
  10257. if($t.p.selrow === o.addParams.rowID ) {
  10258. $($t).jqGrid('delRowData', $t.p.selrow);
  10259. } else {
  10260. $($t).jqGrid('restoreRow', $t.p.selrow, o.editParams);
  10261. }
  10262. $($t).jqGrid('showAddEditButtons');
  10263. }
  10264. if(onSelect) {
  10265. ret = onSelect.call($t, id, stat);
  10266. }
  10267. return ret;
  10268. };
  10269. }
  10270. });
  10271. },
  10272. showAddEditButtons : function() {
  10273. return this.each(function(){
  10274. if (!this.grid ) { return; }
  10275. var gID = $.jgrid.jqID(this.p.id);
  10276. $("#"+gID+"_ilsave").addClass('ui-state-disabled');
  10277. $("#"+gID+"_ilcancel").addClass('ui-state-disabled');
  10278. $("#"+gID+"_iladd").removeClass('ui-state-disabled');
  10279. $("#"+gID+"_iledit").removeClass('ui-state-disabled');
  10280. });
  10281. }
  10282. //end inline edit
  10283. });
  10284. })(jQuery);
  10285. /*jshint evil:true, eqeqeq:false, eqnull:true, devel:true */
  10286. /*global jQuery */
  10287. (function($){
  10288. /*
  10289. **
  10290. * jqGrid addons using jQuery UI
  10291. * Author: Mark Williams
  10292. * Dual licensed under the MIT and GPL licenses:
  10293. * http://www.opensource.org/licenses/mit-license.php
  10294. * http://www.gnu.org/licenses/gpl-2.0.html
  10295. * depends on jQuery UI
  10296. **/
  10297. "use strict";
  10298. if ($.jgrid.msie && $.jgrid.msiever()===8) {
  10299. $.expr[":"].hidden = function(elem) {
  10300. return elem.offsetWidth === 0 || elem.offsetHeight === 0 ||
  10301. elem.style.display === "none";
  10302. };
  10303. }
  10304. // requiere load multiselect before grid
  10305. $.jgrid._multiselect = false;
  10306. if($.ui) {
  10307. if ($.ui.multiselect ) {
  10308. if($.ui.multiselect.prototype._setSelected) {
  10309. var setSelected = $.ui.multiselect.prototype._setSelected;
  10310. $.ui.multiselect.prototype._setSelected = function(item,selected) {
  10311. var ret = setSelected.call(this,item,selected);
  10312. if (selected && this.selectedList) {
  10313. var elt = this.element;
  10314. this.selectedList.find('li').each(function() {
  10315. if ($(this).data('optionLink')) {
  10316. $(this).data('optionLink').remove().appendTo(elt);
  10317. }
  10318. });
  10319. }
  10320. return ret;
  10321. };
  10322. }
  10323. if($.ui.multiselect.prototype.destroy) {
  10324. $.ui.multiselect.prototype.destroy = function() {
  10325. this.element.show();
  10326. this.container.remove();
  10327. if ($.Widget === undefined) {
  10328. $.widget.prototype.destroy.apply(this, arguments);
  10329. } else {
  10330. $.Widget.prototype.destroy.apply(this, arguments);
  10331. }
  10332. };
  10333. }
  10334. $.jgrid._multiselect = true;
  10335. }
  10336. }
  10337. $.jgrid.extend({
  10338. sortableColumns : function (tblrow)
  10339. {
  10340. return this.each(function (){
  10341. var ts = this, tid= $.jgrid.jqID( ts.p.id );
  10342. function start() {ts.p.disableClick = true;}
  10343. var sortable_opts = {
  10344. "tolerance" : "pointer",
  10345. "axis" : "x",
  10346. "scrollSensitivity": "1",
  10347. "items": '>th:not(:has(#jqgh_'+tid+'_cb'+',#jqgh_'+tid+'_rn'+',#jqgh_'+tid+'_subgrid),:hidden)',
  10348. "placeholder": {
  10349. element: function(item) {
  10350. var el = $(document.createElement(item[0].nodeName))
  10351. .addClass(item[0].className+" ui-sortable-placeholder ui-state-highlight")
  10352. .removeClass("ui-sortable-helper")[0];
  10353. return el;
  10354. },
  10355. update: function(self, p) {
  10356. p.height(self.currentItem.innerHeight() - parseInt(self.currentItem.css('paddingTop')||0, 10) - parseInt(self.currentItem.css('paddingBottom')||0, 10));
  10357. p.width(self.currentItem.innerWidth() - parseInt(self.currentItem.css('paddingLeft')||0, 10) - parseInt(self.currentItem.css('paddingRight')||0, 10));
  10358. }
  10359. },
  10360. "update": function(event, ui) {
  10361. var p = $(ui.item).parent(),
  10362. th = $(">th", p),
  10363. colModel = ts.p.colModel,
  10364. cmMap = {}, tid= ts.p.id+"_";
  10365. $.each(colModel, function(i) { cmMap[this.name]=i; });
  10366. var permutation = [];
  10367. th.each(function() {
  10368. var id = $(">div", this).get(0).id.replace(/^jqgh_/, "").replace(tid,"");
  10369. if (cmMap.hasOwnProperty(id)) {
  10370. permutation.push(cmMap[id]);
  10371. }
  10372. });
  10373. $(ts).jqGrid("remapColumns",permutation, true, true);
  10374. if ($.isFunction(ts.p.sortable.update)) {
  10375. ts.p.sortable.update(permutation);
  10376. }
  10377. setTimeout(function(){ts.p.disableClick=false;}, 50);
  10378. }
  10379. };
  10380. if (ts.p.sortable.options) {
  10381. $.extend(sortable_opts, ts.p.sortable.options);
  10382. } else if ($.isFunction(ts.p.sortable)) {
  10383. ts.p.sortable = { "update" : ts.p.sortable };
  10384. }
  10385. if (sortable_opts.start) {
  10386. var s = sortable_opts.start;
  10387. sortable_opts.start = function(e,ui) {
  10388. start();
  10389. s.call(this,e,ui);
  10390. };
  10391. } else {
  10392. sortable_opts.start = start;
  10393. }
  10394. if (ts.p.sortable.exclude) {
  10395. sortable_opts.items += ":not("+ts.p.sortable.exclude+")";
  10396. }
  10397. var $e = tblrow.sortable(sortable_opts), dataObj = $e.data("sortable") || $e.data("uiSortable");
  10398. if (dataObj != null) {
  10399. dataObj.data("sortable").floating = true;
  10400. }
  10401. });
  10402. },
  10403. columnChooser : function(opts) {
  10404. var self = this, selector, select, colMap = {}, fixedCols = [], dopts, mopts, $dialogContent, multiselectData, listHeight,
  10405. colModel = self.jqGrid("getGridParam", "colModel"),
  10406. colNames = self.jqGrid("getGridParam", "colNames"),
  10407. getMultiselectWidgetData = function ($elem) {
  10408. return ($.ui.multiselect.prototype && $elem.data($.ui.multiselect.prototype.widgetFullName || $.ui.multiselect.prototype.widgetName)) ||
  10409. $elem.data("ui-multiselect") || $elem.data("multiselect");
  10410. };
  10411. if ($("#colchooser_" + $.jgrid.jqID(self[0].p.id)).length) { return; }
  10412. selector = $('<div id="colchooser_'+self[0].p.id+'" style="position:relative;overflow:hidden"><div><select multiple="multiple"></select></div></div>');
  10413. select = $('select', selector);
  10414. function insert(perm,i,v) {
  10415. var a, b;
  10416. if(i>=0){
  10417. a = perm.slice();
  10418. b = a.splice(i,Math.max(perm.length-i,i));
  10419. if(i>perm.length) { i = perm.length; }
  10420. a[i] = v;
  10421. return a.concat(b);
  10422. }
  10423. return perm;
  10424. }
  10425. function call(fn, obj) {
  10426. if (!fn) { return; }
  10427. if (typeof fn === 'string') {
  10428. if ($.fn[fn]) {
  10429. $.fn[fn].apply(obj, $.makeArray(arguments).slice(2));
  10430. }
  10431. } else if ($.isFunction(fn)) {
  10432. fn.apply(obj, $.makeArray(arguments).slice(2));
  10433. }
  10434. }
  10435. opts = $.extend({
  10436. width : 400,
  10437. height : 240,
  10438. classname : null,
  10439. done : function(perm) { if (perm) { self.jqGrid("remapColumns", perm, true); } },
  10440. /* msel is either the name of a ui widget class that
  10441. extends a multiselect, or a function that supports
  10442. creating a multiselect object (with no argument,
  10443. or when passed an object), and destroying it (when
  10444. passed the string "destroy"). */
  10445. msel : "multiselect",
  10446. /* "msel_opts" : {}, */
  10447. /* dlog is either the name of a ui widget class that
  10448. behaves in a dialog-like way, or a function, that
  10449. supports creating a dialog (when passed dlog_opts)
  10450. or destroying a dialog (when passed the string
  10451. "destroy")
  10452. */
  10453. dlog : "dialog",
  10454. dialog_opts : {
  10455. minWidth: 470,
  10456. dialogClass: "ui-jqdialog"
  10457. },
  10458. /* dlog_opts is either an option object to be passed
  10459. to "dlog", or (more likely) a function that creates
  10460. the options object.
  10461. The default produces a suitable options object for
  10462. ui.dialog */
  10463. dlog_opts : function(options) {
  10464. var buttons = {};
  10465. buttons[options.bSubmit] = function() {
  10466. options.apply_perm();
  10467. options.cleanup(false);
  10468. };
  10469. buttons[options.bCancel] = function() {
  10470. options.cleanup(true);
  10471. };
  10472. return $.extend(true, {
  10473. buttons: buttons,
  10474. close: function() {
  10475. options.cleanup(true);
  10476. },
  10477. modal: options.modal || false,
  10478. resizable: options.resizable || true,
  10479. width: options.width + 70,
  10480. resize: function () {
  10481. var widgetData = getMultiselectWidgetData(select),
  10482. $thisDialogContent = widgetData.container.closest(".ui-dialog-content");
  10483. if ($thisDialogContent.length > 0 && typeof $thisDialogContent[0].style === "object") {
  10484. $thisDialogContent[0].style.width = "";
  10485. } else {
  10486. $thisDialogContent.css("width", ""); // or just remove width style
  10487. }
  10488. widgetData.selectedList.height(Math.max(widgetData.selectedContainer.height() - widgetData.selectedActions.outerHeight() - 1, 1));
  10489. widgetData.availableList.height(Math.max(widgetData.availableContainer.height() - widgetData.availableActions.outerHeight() - 1, 1));
  10490. }
  10491. }, options.dialog_opts || {});
  10492. },
  10493. /* Function to get the permutation array, and pass it to the
  10494. "done" function */
  10495. apply_perm : function() {
  10496. var perm = [];
  10497. $('option',select).each(function() {
  10498. if ($(this).is("[selected]")) {
  10499. self.jqGrid("showCol", colModel[this.value].name);
  10500. } else {
  10501. self.jqGrid("hideCol", colModel[this.value].name);
  10502. }
  10503. });
  10504. //fixedCols.slice(0);
  10505. $('option[selected]',select).each(function() { perm.push(parseInt(this.value,10)); });
  10506. $.each(perm, function() { delete colMap[colModel[parseInt(this,10)].name]; });
  10507. $.each(colMap, function() {
  10508. var ti = parseInt(this,10);
  10509. perm = insert(perm,ti,ti);
  10510. });
  10511. if (opts.done) {
  10512. opts.done.call(self, perm);
  10513. }
  10514. self.jqGrid("setGridWidth", self[0].p.tblwidth, self[0].p.shrinkToFit);
  10515. },
  10516. /* Function to cleanup the dialog, and select. Also calls the
  10517. done function with no permutation (to indicate that the
  10518. columnChooser was aborted */
  10519. cleanup : function(calldone) {
  10520. call(opts.dlog, selector, 'destroy');
  10521. call(opts.msel, select, 'destroy');
  10522. selector.remove();
  10523. if (calldone && opts.done) {
  10524. opts.done.call(self);
  10525. }
  10526. },
  10527. msel_opts : {}
  10528. }, $.jgrid.col, opts || {});
  10529. if($.ui) {
  10530. if ($.ui.multiselect && $.ui.multiselect.defaults) {
  10531. if (!$.jgrid._multiselect) {
  10532. // should be in language file
  10533. alert("Multiselect plugin loaded after jqGrid. Please load the plugin before the jqGrid!");
  10534. return;
  10535. }
  10536. // ??? the next line uses $.ui.multiselect.defaults which will be typically undefined
  10537. opts.msel_opts = $.extend($.ui.multiselect.defaults, opts.msel_opts);
  10538. }
  10539. }
  10540. if (opts.caption) {
  10541. selector.attr("title", opts.caption);
  10542. }
  10543. if (opts.classname) {
  10544. selector.addClass(opts.classname);
  10545. select.addClass(opts.classname);
  10546. }
  10547. if (opts.width) {
  10548. $(">div",selector).css({width: opts.width,margin:"0 auto"});
  10549. select.css("width", opts.width);
  10550. }
  10551. if (opts.height) {
  10552. $(">div",selector).css("height", opts.height);
  10553. select.css("height", opts.height - 10);
  10554. }
  10555. select.empty();
  10556. $.each(colModel, function(i) {
  10557. colMap[this.name] = i;
  10558. if (this.hidedlg) {
  10559. if (!this.hidden) {
  10560. fixedCols.push(i);
  10561. }
  10562. return;
  10563. }
  10564. select.append("<option value='"+i+"' "+
  10565. (this.hidden?"":"selected='selected'")+">"+$.jgrid.stripHtml(colNames[i])+"</option>");
  10566. });
  10567. dopts = $.isFunction(opts.dlog_opts) ? opts.dlog_opts.call(self, opts) : opts.dlog_opts;
  10568. call(opts.dlog, selector, dopts);
  10569. mopts = $.isFunction(opts.msel_opts) ? opts.msel_opts.call(self, opts) : opts.msel_opts;
  10570. call(opts.msel, select, mopts);
  10571. // fix height of elements of the multiselect widget
  10572. $dialogContent = $("#colchooser_" + $.jgrid.jqID(self[0].p.id));
  10573. $dialogContent.css({ margin: "auto" });
  10574. $dialogContent.find(">div").css({ width: "100%", height: "100%", margin: "auto" });
  10575. multiselectData = getMultiselectWidgetData(select);
  10576. multiselectData.container.css({ width: "100%", height: "100%", margin: "auto" });
  10577. multiselectData.selectedContainer.css({ width: multiselectData.options.dividerLocation * 100 + "%", height: "100%", margin: "auto", boxSizing: "border-box" });
  10578. multiselectData.availableContainer.css({ width: (100 - multiselectData.options.dividerLocation * 100) + "%", height: "100%", margin: "auto", boxSizing: "border-box" });
  10579. // set height for both selectedList and availableList
  10580. multiselectData.selectedList.css("height", "auto");
  10581. multiselectData.availableList.css("height", "auto");
  10582. listHeight = Math.max(multiselectData.selectedList.height(), multiselectData.availableList.height());
  10583. listHeight = Math.min(listHeight, $(window).height());
  10584. multiselectData.selectedList.css("height", listHeight);
  10585. multiselectData.availableList.css("height", listHeight);
  10586. },
  10587. sortableRows : function (opts) {
  10588. // Can accept all sortable options and events
  10589. return this.each(function(){
  10590. var $t = this;
  10591. if(!$t.grid) { return; }
  10592. // Currently we disable a treeGrid sortable
  10593. if($t.p.treeGrid) { return; }
  10594. if($.fn.sortable) {
  10595. opts = $.extend({
  10596. "cursor":"move",
  10597. "axis" : "y",
  10598. "items": ".jqgrow"
  10599. },
  10600. opts || {});
  10601. if(opts.start && $.isFunction(opts.start)) {
  10602. opts._start_ = opts.start;
  10603. delete opts.start;
  10604. } else {opts._start_=false;}
  10605. if(opts.update && $.isFunction(opts.update)) {
  10606. opts._update_ = opts.update;
  10607. delete opts.update;
  10608. } else {opts._update_ = false;}
  10609. opts.start = function(ev,ui) {
  10610. $(ui.item).css("border-width","0");
  10611. $("td",ui.item).each(function(i){
  10612. this.style.width = $t.grid.cols[i].style.width;
  10613. });
  10614. if($t.p.subGrid) {
  10615. var subgid = $(ui.item).attr("id");
  10616. try {
  10617. $($t).jqGrid('collapseSubGridRow',subgid);
  10618. } catch (e) {}
  10619. }
  10620. if(opts._start_) {
  10621. opts._start_.apply(this,[ev,ui]);
  10622. }
  10623. };
  10624. opts.update = function (ev,ui) {
  10625. $(ui.item).css("border-width","");
  10626. if($t.p.rownumbers === true) {
  10627. $("td.jqgrid-rownum",$t.rows).each(function( i ){
  10628. $(this).html( i+1+(parseInt($t.p.page,10)-1)*parseInt($t.p.rowNum,10) );
  10629. });
  10630. }
  10631. if(opts._update_) {
  10632. opts._update_.apply(this,[ev,ui]);
  10633. }
  10634. };
  10635. $("tbody:first",$t).sortable(opts);
  10636. $("tbody:first",$t).disableSelection();
  10637. }
  10638. });
  10639. },
  10640. gridDnD : function(opts) {
  10641. return this.each(function(){
  10642. var $t = this, i, cn;
  10643. if(!$t.grid) { return; }
  10644. // Currently we disable a treeGrid drag and drop
  10645. if($t.p.treeGrid) { return; }
  10646. if(!$.fn.draggable || !$.fn.droppable) { return; }
  10647. function updateDnD ()
  10648. {
  10649. var datadnd = $.data($t,"dnd");
  10650. $("tr.jqgrow:not(.ui-draggable)",$t).draggable($.isFunction(datadnd.drag) ? datadnd.drag.call($($t),datadnd) : datadnd.drag);
  10651. }
  10652. var appender = "<table id='jqgrid_dnd' class='ui-jqgrid-dnd'></table>";
  10653. if($("#jqgrid_dnd")[0] === undefined) {
  10654. $('body').append(appender);
  10655. }
  10656. if(typeof opts === 'string' && opts === 'updateDnD' && $t.p.jqgdnd===true) {
  10657. updateDnD();
  10658. return;
  10659. }
  10660. opts = $.extend({
  10661. "drag" : function (opts) {
  10662. return $.extend({
  10663. start : function (ev, ui) {
  10664. var i, subgid;
  10665. // if we are in subgrid mode try to collapse the node
  10666. if($t.p.subGrid) {
  10667. subgid = $(ui.helper).attr("id");
  10668. try {
  10669. $($t).jqGrid('collapseSubGridRow',subgid);
  10670. } catch (e) {}
  10671. }
  10672. // hack
  10673. // drag and drop does not insert tr in table, when the table has no rows
  10674. // we try to insert new empty row on the target(s)
  10675. for (i=0;i<$.data($t,"dnd").connectWith.length;i++){
  10676. if($($.data($t,"dnd").connectWith[i]).jqGrid('getGridParam','reccount') === 0 ){
  10677. $($.data($t,"dnd").connectWith[i]).jqGrid('addRowData','jqg_empty_row',{});
  10678. }
  10679. }
  10680. ui.helper.addClass("ui-state-highlight");
  10681. $("td",ui.helper).each(function(i) {
  10682. this.style.width = $t.grid.headers[i].width+"px";
  10683. });
  10684. if(opts.onstart && $.isFunction(opts.onstart) ) { opts.onstart.call($($t),ev,ui); }
  10685. },
  10686. stop :function(ev,ui) {
  10687. var i, ids;
  10688. if(ui.helper.dropped && !opts.dragcopy) {
  10689. ids = $(ui.helper).attr("id");
  10690. if(ids === undefined) { ids = $(this).attr("id"); }
  10691. $($t).jqGrid('delRowData',ids );
  10692. }
  10693. // if we have a empty row inserted from start event try to delete it
  10694. for (i=0;i<$.data($t,"dnd").connectWith.length;i++){
  10695. $($.data($t,"dnd").connectWith[i]).jqGrid('delRowData','jqg_empty_row');
  10696. }
  10697. if(opts.onstop && $.isFunction(opts.onstop) ) { opts.onstop.call($($t),ev,ui); }
  10698. }
  10699. },opts.drag_opts || {});
  10700. },
  10701. "drop" : function (opts) {
  10702. return $.extend({
  10703. accept: function(d) {
  10704. if (!$(d).hasClass('jqgrow')) { return d;}
  10705. var tid = $(d).closest("table.ui-jqgrid-btable");
  10706. if(tid.length > 0 && $.data(tid[0],"dnd") !== undefined) {
  10707. var cn = $.data(tid[0],"dnd").connectWith;
  10708. return $.inArray('#'+$.jgrid.jqID(this.id),cn) !== -1 ? true : false;
  10709. }
  10710. return false;
  10711. },
  10712. drop: function(ev, ui) {
  10713. if (!$(ui.draggable).hasClass('jqgrow')) { return; }
  10714. var accept = $(ui.draggable).attr("id");
  10715. var getdata = ui.draggable.parent().parent().jqGrid('getRowData',accept);
  10716. if(!opts.dropbyname) {
  10717. var j =0, tmpdata = {}, nm, key;
  10718. var dropmodel = $("#"+$.jgrid.jqID(this.id)).jqGrid('getGridParam','colModel');
  10719. try {
  10720. for (key in getdata) {
  10721. if (getdata.hasOwnProperty(key)) {
  10722. nm = dropmodel[j].name;
  10723. if( !(nm === 'cb' || nm === 'rn' || nm === 'subgrid' )) {
  10724. if(getdata.hasOwnProperty(key) && dropmodel[j]) {
  10725. tmpdata[nm] = getdata[key];
  10726. }
  10727. }
  10728. j++;
  10729. }
  10730. }
  10731. getdata = tmpdata;
  10732. } catch (e) {}
  10733. }
  10734. ui.helper.dropped = true;
  10735. if(opts.beforedrop && $.isFunction(opts.beforedrop) ) {
  10736. //parameters to this callback - event, element, data to be inserted, sender, reciever
  10737. // should return object which will be inserted into the reciever
  10738. var datatoinsert = opts.beforedrop.call(this,ev,ui,getdata,$('#'+$.jgrid.jqID($t.p.id)),$(this));
  10739. if (datatoinsert !== undefined && datatoinsert !== null && typeof datatoinsert === "object") { getdata = datatoinsert; }
  10740. }
  10741. if(ui.helper.dropped) {
  10742. var grid;
  10743. if(opts.autoid) {
  10744. if($.isFunction(opts.autoid)) {
  10745. grid = opts.autoid.call(this,getdata);
  10746. } else {
  10747. grid = Math.ceil(Math.random()*1000);
  10748. grid = opts.autoidprefix+grid;
  10749. }
  10750. }
  10751. // NULL is interpreted as undefined while null as object
  10752. $("#"+$.jgrid.jqID(this.id)).jqGrid('addRowData',grid,getdata,opts.droppos);
  10753. }
  10754. if(opts.ondrop && $.isFunction(opts.ondrop) ) { opts.ondrop.call(this,ev,ui, getdata); }
  10755. }}, opts.drop_opts || {});
  10756. },
  10757. "onstart" : null,
  10758. "onstop" : null,
  10759. "beforedrop": null,
  10760. "ondrop" : null,
  10761. "drop_opts" : {
  10762. "activeClass": "ui-state-active",
  10763. "hoverClass": "ui-state-hover"
  10764. },
  10765. "drag_opts" : {
  10766. "revert": "invalid",
  10767. "helper": "clone",
  10768. "cursor": "move",
  10769. "appendTo" : "#jqgrid_dnd",
  10770. "zIndex": 5000
  10771. },
  10772. "dragcopy": false,
  10773. "dropbyname" : false,
  10774. "droppos" : "first",
  10775. "autoid" : true,
  10776. "autoidprefix" : "dnd_"
  10777. }, opts || {});
  10778. if(!opts.connectWith) { return; }
  10779. opts.connectWith = opts.connectWith.split(",");
  10780. opts.connectWith = $.map(opts.connectWith,function(n){return $.trim(n);});
  10781. $.data($t,"dnd",opts);
  10782. if($t.p.reccount !== 0 && !$t.p.jqgdnd) {
  10783. updateDnD();
  10784. }
  10785. $t.p.jqgdnd = true;
  10786. for (i=0;i<opts.connectWith.length;i++){
  10787. cn =opts.connectWith[i];
  10788. $(cn).droppable($.isFunction(opts.drop) ? opts.drop.call($($t),opts) : opts.drop);
  10789. }
  10790. });
  10791. },
  10792. gridResize : function(opts) {
  10793. return this.each(function(){
  10794. var $t = this, gID = $.jgrid.jqID($t.p.id);
  10795. if(!$t.grid || !$.fn.resizable) { return; }
  10796. opts = $.extend({}, opts || {});
  10797. if(opts.alsoResize ) {
  10798. opts._alsoResize_ = opts.alsoResize;
  10799. delete opts.alsoResize;
  10800. } else {
  10801. opts._alsoResize_ = false;
  10802. }
  10803. if(opts.stop && $.isFunction(opts.stop)) {
  10804. opts._stop_ = opts.stop;
  10805. delete opts.stop;
  10806. } else {
  10807. opts._stop_ = false;
  10808. }
  10809. opts.stop = function (ev, ui) {
  10810. $($t).jqGrid('setGridParam',{height:$("#gview_"+gID+" .ui-jqgrid-bdiv").height()});
  10811. $($t).jqGrid('setGridWidth',ui.size.width,opts.shrinkToFit);
  10812. if(opts._stop_) { opts._stop_.call($t,ev,ui); }
  10813. };
  10814. if(opts._alsoResize_) {
  10815. var optstest = "{\'#gview_"+gID+" .ui-jqgrid-bdiv\':true,'" +opts._alsoResize_+"':true}";
  10816. opts.alsoResize = eval('('+optstest+')'); // the only way that I found to do this
  10817. } else {
  10818. opts.alsoResize = $(".ui-jqgrid-bdiv","#gview_"+gID);
  10819. }
  10820. delete opts._alsoResize_;
  10821. $("#gbox_"+gID).resizable(opts);
  10822. });
  10823. }
  10824. });
  10825. })(jQuery);
  10826. /*jshint eqeqeq:false */
  10827. /*global jQuery */
  10828. (function($){
  10829. /**
  10830. * jqGrid pivot functions
  10831. * Tony Tomov tony@trirand.com
  10832. * http://trirand.com/blog/
  10833. * Dual licensed under the MIT and GPL licenses:
  10834. * http://www.opensource.org/licenses/mit-license.php
  10835. * http://www.gnu.org/licenses/gpl-2.0.html
  10836. */
  10837. "use strict";
  10838. // To optimize the search we need custom array filter
  10839. // This code is taken from
  10840. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter
  10841. function _pivotfilter (fn, context) {
  10842. var i,
  10843. value,
  10844. result = [],
  10845. length;
  10846. if (!this || typeof fn !== 'function' || (fn instanceof RegExp)) {
  10847. throw new TypeError();
  10848. }
  10849. length = this.length;
  10850. for (i = 0; i < length; i++) {
  10851. if (this.hasOwnProperty(i)) {
  10852. value = this[i];
  10853. if (fn.call(context, value, i, this)) {
  10854. result.push(value);
  10855. // We need break in order to cancel loop
  10856. // in case the row is found
  10857. break;
  10858. }
  10859. }
  10860. }
  10861. return result;
  10862. }
  10863. $.assocArraySize = function(obj) {
  10864. // http://stackoverflow.com/a/6700/11236
  10865. var size = 0, key;
  10866. for (key in obj) {
  10867. if (obj.hasOwnProperty(key)) {
  10868. size++;
  10869. }
  10870. }
  10871. return size;
  10872. };
  10873. $.jgrid.extend({
  10874. pivotSetup : function( data, options ){
  10875. // data should come in json format
  10876. // The function return the new colModel and the transformed data
  10877. // again with group setup options which then will be passed to the grid
  10878. var columns =[],
  10879. pivotrows =[],
  10880. summaries = [],
  10881. member=[],
  10882. labels=[],
  10883. groupOptions = {
  10884. grouping : true,
  10885. groupingView : {
  10886. groupField : [],
  10887. groupSummary: [],
  10888. groupSummaryPos:[]
  10889. }
  10890. },
  10891. headers = [],
  10892. o = $.extend ( {
  10893. rowTotals : false,
  10894. rowTotalsText : 'Total',
  10895. // summary columns
  10896. colTotals : false,
  10897. groupSummary : true,
  10898. groupSummaryPos : 'header',
  10899. frozenStaticCols : false
  10900. }, options || {});
  10901. this.each(function(){
  10902. var
  10903. row,
  10904. rowindex,
  10905. i,
  10906. rowlen = data.length,
  10907. xlen, ylen, aggrlen,
  10908. tmp,
  10909. newObj,
  10910. r=0;
  10911. // utility funcs
  10912. /*
  10913. * Filter the data to a given criteria. Return the firt occurance
  10914. */
  10915. function find(ar, fun, extra) {
  10916. var res;
  10917. res = _pivotfilter.call(ar, fun, extra);
  10918. return res.length > 0 ? res[0] : null;
  10919. }
  10920. /*
  10921. * Check if the grouped row column exist (See find)
  10922. * If the row is not find in pivot rows retun null,
  10923. * otherviese the column
  10924. */
  10925. function findGroup(item, index) {
  10926. var j = 0, ret = true, i;
  10927. for(i in item) {
  10928. if(item[i] != this[j]) {
  10929. ret = false;
  10930. break;
  10931. }
  10932. j++;
  10933. if(j>=this.length) {
  10934. break;
  10935. }
  10936. }
  10937. if(ret) {
  10938. rowindex = index;
  10939. }
  10940. return ret;
  10941. }
  10942. /*
  10943. * Perform calculations of the pivot values.
  10944. */
  10945. function calculation(oper, v, field, rc) {
  10946. var ret;
  10947. switch (oper) {
  10948. case "sum" :
  10949. ret = parseFloat(v||0) + parseFloat((rc[field]||0));
  10950. break;
  10951. case "count" :
  10952. if(v==="" || v == null) {
  10953. v=0;
  10954. }
  10955. if(rc.hasOwnProperty(field)) {
  10956. ret = v+1;
  10957. } else {
  10958. ret = 0;
  10959. }
  10960. break;
  10961. case "min" :
  10962. if(v==="" || v == null) {
  10963. ret = parseFloat(rc[field]||0);
  10964. } else {
  10965. ret =Math.min(parseFloat(v),parseFloat(rc[field]||0));
  10966. }
  10967. break;
  10968. case "max" :
  10969. if(v==="" || v == null) {
  10970. ret = parseFloat(rc[field]||0);
  10971. } else {
  10972. ret = Math.max(parseFloat(v),parseFloat(rc[field]||0));
  10973. }
  10974. break;
  10975. }
  10976. return ret;
  10977. }
  10978. /*
  10979. * The function agragates the values of the pivot grid.
  10980. * Return the current row with pivot summary values
  10981. */
  10982. function agregateFunc ( row, aggr, value, curr) {
  10983. // default is sum
  10984. var arrln = aggr.length, i, label, j, jv, mainval="",swapvals=[];
  10985. if($.isArray(value)) {
  10986. jv = value.length;
  10987. swapvals = value;
  10988. } else {
  10989. jv = 1;
  10990. swapvals[0]=value;
  10991. }
  10992. member = [];
  10993. labels = [];
  10994. member.root = 0;
  10995. for(j=0;j<jv;j++) {
  10996. var tmpmember = [], vl;
  10997. for(i=0; i < arrln; i++) {
  10998. if(value == null) {
  10999. label = $.trim(aggr[i].member)+"_"+aggr[i].aggregator;
  11000. vl = label;
  11001. swapvals[0]= vl;
  11002. } else {
  11003. vl = value[j].replace(/\s+/g, '');
  11004. try {
  11005. label = (arrln === 1 ? mainval + vl : mainval + vl+"_"+aggr[i].aggregator+"_" + String(i));
  11006. } catch(e) {}
  11007. }
  11008. label = !isNaN(parseInt(label,10)) ? label + " " : label;
  11009. curr[label] = tmpmember[label] = calculation( aggr[i].aggregator, curr[label], aggr[i].member, row);
  11010. if(j<=1 && vl !== '_r_Totals' && mainval === "") { // this does not fix full the problem
  11011. mainval = vl;
  11012. }
  11013. }
  11014. //vl = !isNaN(parseInt(vl,10)) ? vl + " " : vl;
  11015. member[label] = tmpmember;
  11016. labels[label] = swapvals[j];
  11017. }
  11018. return curr;
  11019. }
  11020. // Making the row totals without to add in yDimension
  11021. if(o.rowTotals && o.yDimension.length > 0) {
  11022. var dn = o.yDimension[0].dataName;
  11023. o.yDimension.splice(0,0,{dataName:dn});
  11024. o.yDimension[0].converter = function(){ return '_r_Totals'; };
  11025. }
  11026. // build initial columns (colModel) from xDimension
  11027. xlen = $.isArray(o.xDimension) ? o.xDimension.length : 0;
  11028. ylen = o.yDimension.length;
  11029. aggrlen = $.isArray(o.aggregates) ? o.aggregates.length : 0;
  11030. if(xlen === 0 || aggrlen === 0) {
  11031. throw("xDimension or aggregates optiona are not set!");
  11032. }
  11033. var colc;
  11034. for(i = 0; i< xlen; i++) {
  11035. colc = {name:o.xDimension[i].dataName, frozen: o.frozenStaticCols};
  11036. if(o.xDimension[i].isGroupField == null) {
  11037. o.xDimension[i].isGroupField = true;
  11038. }
  11039. colc = $.extend(true, colc, o.xDimension[i]);
  11040. columns.push( colc );
  11041. }
  11042. var groupfields = xlen - 1, tree={};
  11043. //tree = { text: 'root', leaf: false, children: [] };
  11044. //loop over alll the source data
  11045. while( r < rowlen ) {
  11046. row = data[r];
  11047. var xValue = [];
  11048. var yValue = [];
  11049. tmp = {};
  11050. i = 0;
  11051. // build the data from xDimension
  11052. do {
  11053. xValue[i] = $.trim(row[o.xDimension[i].dataName]);
  11054. tmp[o.xDimension[i].dataName] = xValue[i];
  11055. i++;
  11056. } while( i < xlen );
  11057. var k = 0;
  11058. rowindex = -1;
  11059. // check to see if the row is in our new pivotrow set
  11060. newObj = find(pivotrows, findGroup, xValue);
  11061. if(!newObj) {
  11062. // if the row is not in our set
  11063. k = 0;
  11064. // if yDimension is set
  11065. if(ylen>=1) {
  11066. // build the cols set in yDimension
  11067. for(k=0;k<ylen;k++) {
  11068. yValue[k] = $.trim(row[o.yDimension[k].dataName]);
  11069. // Check to see if we have user defined conditions
  11070. if(o.yDimension[k].converter && $.isFunction(o.yDimension[k].converter)) {
  11071. yValue[k] = o.yDimension[k].converter.call(this, yValue[k], xValue, yValue);
  11072. }
  11073. }
  11074. // make the colums based on aggregates definition
  11075. // and return the members for late calculation
  11076. tmp = agregateFunc( row, o.aggregates, yValue, tmp );
  11077. } else if( ylen === 0 ) {
  11078. // if not set use direct the aggregates
  11079. tmp = agregateFunc( row, o.aggregates, null, tmp );
  11080. }
  11081. // add the result in pivot rows
  11082. pivotrows.push( tmp );
  11083. } else {
  11084. // the pivot exists
  11085. if( rowindex >= 0) {
  11086. k = 0;
  11087. // make the recalculations
  11088. if(ylen>=1) {
  11089. for(k=0;k<ylen;k++) {
  11090. yValue[k] = $.trim(row[o.yDimension[k].dataName]);
  11091. if(o.yDimension[k].converter && $.isFunction(o.yDimension[k].converter)) {
  11092. yValue[k] = o.yDimension[k].converter.call(this, yValue[k], xValue, yValue);
  11093. }
  11094. }
  11095. newObj = agregateFunc( row, o.aggregates, yValue, newObj );
  11096. } else if( ylen === 0 ) {
  11097. newObj = agregateFunc( row, o.aggregates, null, newObj );
  11098. }
  11099. // update the row
  11100. pivotrows[rowindex] = newObj;
  11101. }
  11102. }
  11103. var kj=0, current = null,existing = null, kk;
  11104. // Build a JSON tree from the member (see aggregateFunc)
  11105. // to make later the columns
  11106. //
  11107. for (kk in member) {
  11108. if(member.hasOwnProperty( kk )) {
  11109. if(kj === 0) {
  11110. if (!tree.children||tree.children === undefined){
  11111. tree = { text: kk, level : 0, children: [], label: kk };
  11112. }
  11113. current = tree.children;
  11114. } else {
  11115. existing = null;
  11116. for (i=0; i < current.length; i++) {
  11117. if (current[i].text === kk) {
  11118. //current[i].fields=member[kk];
  11119. existing = current[i];
  11120. break;
  11121. }
  11122. }
  11123. if (existing) {
  11124. current = existing.children;
  11125. } else {
  11126. current.push({ children: [], text: kk, level: kj, fields: member[kk], label: labels[kk] });
  11127. current = current[current.length - 1].children;
  11128. }
  11129. }
  11130. kj++;
  11131. }
  11132. }
  11133. r++;
  11134. }
  11135. var lastval=[], initColLen = columns.length, swaplen = initColLen;
  11136. if(ylen>0) {
  11137. headers[ylen-1] = { useColSpanStyle: false, groupHeaders: []};
  11138. }
  11139. /*
  11140. * Recursive function which uses the tree to build the
  11141. * columns from the pivot values and set the group Headers
  11142. */
  11143. function list(items) {
  11144. var l, j, key, k, col;
  11145. for (key in items) { // iterate
  11146. if (items.hasOwnProperty(key)) {
  11147. // write amount of spaces according to level
  11148. // and write name and newline
  11149. if(typeof items[key] !== "object") {
  11150. // If not a object build the header of the appropriate level
  11151. if( key === 'level') {
  11152. if(lastval[items.level] === undefined) {
  11153. lastval[items.level] ='';
  11154. if(items.level>0 && items.text !== '_r_Totals') {
  11155. headers[items.level-1] = {
  11156. useColSpanStyle: false,
  11157. groupHeaders: []
  11158. };
  11159. }
  11160. }
  11161. if(lastval[items.level] !== items.text && items.children.length && items.text !== '_r_Totals') {
  11162. if(items.level>0) {
  11163. headers[items.level-1].groupHeaders.push({
  11164. titleText: items.label,
  11165. numberOfColumns : 0
  11166. });
  11167. var collen = headers[items.level-1].groupHeaders.length-1,
  11168. colpos = collen === 0 ? swaplen : initColLen+aggrlen;
  11169. if(items.level-1=== (o.rowTotals ? 1 : 0)) {
  11170. if(collen>0) {
  11171. var l1 = headers[items.level-1].groupHeaders[collen-1].numberOfColumns;
  11172. if(l1) {
  11173. colpos = l1 + 1 + o.aggregates.length;
  11174. }
  11175. }
  11176. }
  11177. headers[items.level-1].groupHeaders[collen].startColumnName = columns[colpos].name;
  11178. headers[items.level-1].groupHeaders[collen].numberOfColumns = columns.length - colpos;
  11179. initColLen = columns.length;
  11180. }
  11181. }
  11182. lastval[items.level] = items.text;
  11183. }
  11184. // This is in case when the member contain more than one summary item
  11185. if(items.level === ylen && key==='level' && ylen >0) {
  11186. if( aggrlen > 1){
  11187. var ll=1;
  11188. for( l in items.fields) {
  11189. if(ll===1) {
  11190. headers[ylen-1].groupHeaders.push({startColumnName: l, numberOfColumns: 1, titleText: items.text});
  11191. }
  11192. ll++;
  11193. }
  11194. headers[ylen-1].groupHeaders[headers[ylen-1].groupHeaders.length-1].numberOfColumns = ll-1;
  11195. } else {
  11196. headers.splice(ylen-1,1);
  11197. }
  11198. }
  11199. }
  11200. // if object, call recursively
  11201. if (items[key] != null && typeof items[key] === "object") {
  11202. list(items[key]);
  11203. }
  11204. // Finally build the coulumns
  11205. if( key === 'level') {
  11206. if(items.level >0){
  11207. j=0;
  11208. for(l in items.fields) {
  11209. if(items.fields.hasOwnProperty( l )) {
  11210. col = {};
  11211. for(k in o.aggregates[j]) {
  11212. if(o.aggregates[j].hasOwnProperty(k)) {
  11213. switch( k ) {
  11214. case 'member':
  11215. case 'label':
  11216. case 'aggregator':
  11217. break;
  11218. default:
  11219. col[k] = o.aggregates[j][k];
  11220. }
  11221. }
  11222. }
  11223. if(aggrlen>1) {
  11224. col.name = l;
  11225. col.label = o.aggregates[j].label || items.label;
  11226. } else {
  11227. col.name = items.text;
  11228. col.label = items.text==='_r_Totals' ? o.rowTotalsText : items.label;
  11229. }
  11230. columns.push (col);
  11231. j++;
  11232. }
  11233. }
  11234. }
  11235. }
  11236. }
  11237. }
  11238. }
  11239. list( tree );
  11240. var nm;
  11241. // loop again trougth the pivot rows in order to build grand total
  11242. if(o.colTotals) {
  11243. var plen = pivotrows.length;
  11244. while(plen--) {
  11245. for(i=xlen;i<columns.length;i++) {
  11246. nm = columns[i].name;
  11247. if(!summaries[nm]) {
  11248. summaries[nm] = parseFloat(pivotrows[plen][nm] || 0);
  11249. } else {
  11250. summaries[nm] += parseFloat(pivotrows[plen][nm] || 0);
  11251. }
  11252. }
  11253. }
  11254. }
  11255. // based on xDimension levels build grouping
  11256. if( groupfields > 0) {
  11257. for(i=0;i<groupfields;i++) {
  11258. if(columns[i].isGroupField) {
  11259. groupOptions.groupingView.groupField.push(columns[i].name);
  11260. groupOptions.groupingView.groupSummary.push(o.groupSummary);
  11261. groupOptions.groupingView.groupSummaryPos.push(o.groupSummaryPos);
  11262. }
  11263. }
  11264. } else {
  11265. // no grouping is needed
  11266. groupOptions.grouping = false;
  11267. }
  11268. groupOptions.sortname = columns[groupfields].name;
  11269. groupOptions.groupingView.hideFirstGroupCol = true;
  11270. });
  11271. // return the final result.
  11272. return { "colModel" : columns, "rows": pivotrows, "groupOptions" : groupOptions, "groupHeaders" : headers, summary : summaries };
  11273. },
  11274. jqPivot : function( data, pivotOpt, gridOpt, ajaxOpt) {
  11275. return this.each(function(){
  11276. var $t = this;
  11277. function pivot( data) {
  11278. var pivotGrid = jQuery($t).jqGrid('pivotSetup',data, pivotOpt),
  11279. footerrow = $.assocArraySize(pivotGrid.summary) > 0 ? true : false,
  11280. query= $.jgrid.from(pivotGrid.rows), i;
  11281. for(i=0; i< pivotGrid.groupOptions.groupingView.groupField.length; i++) {
  11282. query.orderBy(pivotGrid.groupOptions.groupingView.groupField[i], "a", 'text', '');
  11283. }
  11284. jQuery($t).jqGrid($.extend(true, {
  11285. datastr: $.extend(query.select(),footerrow ? {userdata:pivotGrid.summary} : {}),
  11286. datatype: "jsonstring",
  11287. footerrow : footerrow,
  11288. userDataOnFooter: footerrow,
  11289. colModel: pivotGrid.colModel,
  11290. viewrecords: true,
  11291. sortname: pivotOpt.xDimension[0].dataName // ?????
  11292. }, pivotGrid.groupOptions, gridOpt || {}));
  11293. var gHead = pivotGrid.groupHeaders;
  11294. if(gHead.length) {
  11295. for( i = 0;i < gHead.length ; i++) {
  11296. if(gHead[i] && gHead[i].groupHeaders.length) {
  11297. jQuery($t).jqGrid('setGroupHeaders',gHead[i]);
  11298. }
  11299. }
  11300. }
  11301. if(pivotOpt.frozenStaticCols) {
  11302. jQuery($t).jqGrid("setFrozenColumns");
  11303. }
  11304. }
  11305. if(typeof data === "string") {
  11306. $.ajax($.extend({
  11307. url : data,
  11308. dataType: 'json',
  11309. success : function(response) {
  11310. pivot($.jgrid.getAccessor(response, ajaxOpt && ajaxOpt.reader ? ajaxOpt.reader: 'rows') );
  11311. }
  11312. }, ajaxOpt || {}) );
  11313. } else {
  11314. pivot( data );
  11315. }
  11316. });
  11317. }
  11318. });
  11319. })(jQuery);
  11320. /*jshint eqeqeq:false */
  11321. /*global jQuery */
  11322. (function($){
  11323. /**
  11324. * jqGrid extension for SubGrid Data
  11325. * Tony Tomov tony@trirand.com
  11326. * http://trirand.com/blog/
  11327. * Dual licensed under the MIT and GPL licenses:
  11328. * http://www.opensource.org/licenses/mit-license.php
  11329. * http://www.gnu.org/licenses/gpl-2.0.html
  11330. **/
  11331. "use strict";
  11332. $.jgrid.extend({
  11333. setSubGrid : function () {
  11334. return this.each(function (){
  11335. var $t = this, cm, i,
  11336. suboptions = {
  11337. plusicon : "ui-icon-plus",
  11338. minusicon : "ui-icon-minus",
  11339. openicon: "ui-icon-carat-1-sw",
  11340. expandOnLoad: false,
  11341. delayOnLoad : 50,
  11342. selectOnExpand : false,
  11343. selectOnCollapse : false,
  11344. reloadOnExpand : true
  11345. };
  11346. $t.p.subGridOptions = $.extend(suboptions, $t.p.subGridOptions || {});
  11347. $t.p.colNames.unshift("");
  11348. $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});
  11349. cm = $t.p.subGridModel;
  11350. if(cm[0]) {
  11351. cm[0].align = $.extend([],cm[0].align || []);
  11352. for(i=0;i<cm[0].name.length;i++) { cm[0].align[i] = cm[0].align[i] || 'left';}
  11353. }
  11354. });
  11355. },
  11356. addSubGridCell :function (pos,iRow) {
  11357. var prp='',ic,sid;
  11358. this.each(function(){
  11359. prp = this.formatCol(pos,iRow);
  11360. sid= this.p.id;
  11361. ic = this.p.subGridOptions.plusicon;
  11362. });
  11363. 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>";
  11364. },
  11365. addSubGrid : function( pos, sind ) {
  11366. return this.each(function(){
  11367. var ts = this;
  11368. if (!ts.grid ) { return; }
  11369. //-------------------------
  11370. var subGridCell = function(trdiv,cell,pos)
  11371. {
  11372. var tddiv = $("<td align='"+ts.p.subGridModel[0].align[pos]+"'></td>").html(cell);
  11373. $(trdiv).append(tddiv);
  11374. };
  11375. var subGridXml = function(sjxml, sbid){
  11376. var tddiv, i, sgmap,
  11377. dummy = $("<table cellspacing='0' cellpadding='0' border='0'><tbody></tbody></table>"),
  11378. trdiv = $("<tr></tr>");
  11379. for (i = 0; i<ts.p.subGridModel[0].name.length; i++) {
  11380. tddiv = $("<th class='ui-state-default ui-th-subgrid ui-th-column ui-th-"+ts.p.direction+"'></th>");
  11381. $(tddiv).html(ts.p.subGridModel[0].name[i]);
  11382. $(tddiv).width( ts.p.subGridModel[0].width[i]);
  11383. $(trdiv).append(tddiv);
  11384. }
  11385. $(dummy).append(trdiv);
  11386. if (sjxml){
  11387. sgmap = ts.p.xmlReader.subgrid;
  11388. $(sgmap.root+" "+sgmap.row, sjxml).each( function(){
  11389. trdiv = $("<tr class='ui-widget-content ui-subtblcell'></tr>");
  11390. if(sgmap.repeatitems === true) {
  11391. $(sgmap.cell,this).each( function(i) {
  11392. subGridCell(trdiv, $(this).text() || '&#160;',i);
  11393. });
  11394. } else {
  11395. var f = ts.p.subGridModel[0].mapping || ts.p.subGridModel[0].name;
  11396. if (f) {
  11397. for (i=0;i<f.length;i++) {
  11398. subGridCell(trdiv, $(f[i],this).text() || '&#160;',i);
  11399. }
  11400. }
  11401. }
  11402. $(dummy).append(trdiv);
  11403. });
  11404. }
  11405. var pID = $("table:first",ts.grid.bDiv).attr("id")+"_";
  11406. $("#"+$.jgrid.jqID(pID+sbid)).append(dummy);
  11407. ts.grid.hDiv.loading = false;
  11408. $("#load_"+$.jgrid.jqID(ts.p.id)).hide();
  11409. return false;
  11410. };
  11411. var subGridJson = function(sjxml, sbid){
  11412. var tddiv,result,i,cur, sgmap,j,
  11413. dummy = $("<table cellspacing='0' cellpadding='0' border='0'><tbody></tbody></table>"),
  11414. trdiv = $("<tr></tr>");
  11415. for (i = 0; i<ts.p.subGridModel[0].name.length; i++) {
  11416. tddiv = $("<th class='ui-state-default ui-th-subgrid ui-th-column ui-th-"+ts.p.direction+"'></th>");
  11417. $(tddiv).html(ts.p.subGridModel[0].name[i]);
  11418. $(tddiv).width( ts.p.subGridModel[0].width[i]);
  11419. $(trdiv).append(tddiv);
  11420. }
  11421. $(dummy).append(trdiv);
  11422. if (sjxml){
  11423. sgmap = ts.p.jsonReader.subgrid;
  11424. result = $.jgrid.getAccessor(sjxml, sgmap.root);
  11425. if ( result !== undefined ) {
  11426. for (i=0;i<result.length;i++) {
  11427. cur = result[i];
  11428. trdiv = $("<tr class='ui-widget-content ui-subtblcell'></tr>");
  11429. if(sgmap.repeatitems === true) {
  11430. if(sgmap.cell) { cur=cur[sgmap.cell]; }
  11431. for (j=0;j<cur.length;j++) {
  11432. subGridCell(trdiv, cur[j] || '&#160;',j);
  11433. }
  11434. } else {
  11435. var f = ts.p.subGridModel[0].mapping || ts.p.subGridModel[0].name;
  11436. if(f.length) {
  11437. for (j=0;j<f.length;j++) {
  11438. subGridCell(trdiv, cur[f[j]] || '&#160;',j);
  11439. }
  11440. }
  11441. }
  11442. $(dummy).append(trdiv);
  11443. }
  11444. }
  11445. }
  11446. var pID = $("table:first",ts.grid.bDiv).attr("id")+"_";
  11447. $("#"+$.jgrid.jqID(pID+sbid)).append(dummy);
  11448. ts.grid.hDiv.loading = false;
  11449. $("#load_"+$.jgrid.jqID(ts.p.id)).hide();
  11450. return false;
  11451. };
  11452. var populatesubgrid = function( rd )
  11453. {
  11454. var sid,dp, i, j;
  11455. sid = $(rd).attr("id");
  11456. dp = {nd_: (new Date().getTime())};
  11457. dp[ts.p.prmNames.subgridid]=sid;
  11458. if(!ts.p.subGridModel[0]) { return false; }
  11459. if(ts.p.subGridModel[0].params) {
  11460. for(j=0; j < ts.p.subGridModel[0].params.length; j++) {
  11461. for(i=0; i<ts.p.colModel.length; i++) {
  11462. if(ts.p.colModel[i].name === ts.p.subGridModel[0].params[j]) {
  11463. dp[ts.p.colModel[i].name]= $("td:eq("+i+")",rd).text().replace(/\&#160\;/ig,'');
  11464. }
  11465. }
  11466. }
  11467. }
  11468. if(!ts.grid.hDiv.loading) {
  11469. ts.grid.hDiv.loading = true;
  11470. $("#load_"+$.jgrid.jqID(ts.p.id)).show();
  11471. if(!ts.p.subgridtype) { ts.p.subgridtype = ts.p.datatype; }
  11472. if($.isFunction(ts.p.subgridtype)) {
  11473. ts.p.subgridtype.call(ts, dp);
  11474. } else {
  11475. ts.p.subgridtype = ts.p.subgridtype.toLowerCase();
  11476. }
  11477. switch(ts.p.subgridtype) {
  11478. case "xml":
  11479. case "json":
  11480. $.ajax($.extend({
  11481. type:ts.p.mtype,
  11482. url: $.isFunction(ts.p.subGridUrl) ? ts.p.subGridUrl.call(ts, dp) : ts.p.subGridUrl,
  11483. dataType:ts.p.subgridtype,
  11484. data: $.isFunction(ts.p.serializeSubGridData)? ts.p.serializeSubGridData.call(ts, dp) : dp,
  11485. complete: function(sxml) {
  11486. if(ts.p.subgridtype === "xml") {
  11487. subGridXml(sxml.responseXML, sid);
  11488. } else {
  11489. subGridJson($.jgrid.parse(sxml.responseText),sid);
  11490. }
  11491. sxml=null;
  11492. }
  11493. }, $.jgrid.ajaxOptions, ts.p.ajaxSubgridOptions || {}));
  11494. break;
  11495. }
  11496. }
  11497. return false;
  11498. };
  11499. var _id, pID,atd, nhc=0, bfsc, r;
  11500. $.each(ts.p.colModel,function(){
  11501. if(this.hidden === true || this.name === 'rn' || this.name === 'cb') {
  11502. nhc++;
  11503. }
  11504. });
  11505. var len = ts.rows.length, i=1;
  11506. if( sind !== undefined && sind > 0) {
  11507. i = sind;
  11508. len = sind+1;
  11509. }
  11510. while(i < len) {
  11511. if($(ts.rows[i]).hasClass('jqgrow')) {
  11512. if(ts.p.scroll) {
  11513. $(ts.rows[i].cells[pos]).unbind('click');
  11514. }
  11515. $(ts.rows[i].cells[pos]).bind('click', function() {
  11516. var tr = $(this).parent("tr")[0];
  11517. r = tr.nextSibling;
  11518. if($(this).hasClass("sgcollapsed")) {
  11519. pID = ts.p.id;
  11520. _id = tr.id;
  11521. if(ts.p.subGridOptions.reloadOnExpand === true || ( ts.p.subGridOptions.reloadOnExpand === false && !$(r).hasClass('ui-subgrid') ) ) {
  11522. atd = pos >=1 ? "<td colspan='"+pos+"'>&#160;</td>":"";
  11523. bfsc = $(ts).triggerHandler("jqGridSubGridBeforeExpand", [pID + "_" + _id, _id]);
  11524. bfsc = (bfsc === false || bfsc === 'stop') ? false : true;
  11525. if(bfsc && $.isFunction(ts.p.subGridBeforeExpand)) {
  11526. bfsc = ts.p.subGridBeforeExpand.call(ts, pID+"_"+_id,_id);
  11527. }
  11528. if(bfsc === false) {return false;}
  11529. $(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>" );
  11530. $(ts).triggerHandler("jqGridSubGridRowExpanded", [pID + "_" + _id, _id]);
  11531. if( $.isFunction(ts.p.subGridRowExpanded)) {
  11532. ts.p.subGridRowExpanded.call(ts, pID+"_"+ _id,_id);
  11533. } else {
  11534. populatesubgrid(tr);
  11535. }
  11536. } else {
  11537. $(r).show();
  11538. }
  11539. $(this).html("<a style='cursor:pointer;'><span class='ui-icon "+ts.p.subGridOptions.minusicon+"'></span></a>").removeClass("sgcollapsed").addClass("sgexpanded");
  11540. if(ts.p.subGridOptions.selectOnExpand) {
  11541. $(ts).jqGrid('setSelection',_id);
  11542. }
  11543. } else if($(this).hasClass("sgexpanded")) {
  11544. bfsc = $(ts).triggerHandler("jqGridSubGridRowColapsed", [pID + "_" + _id, _id]);
  11545. bfsc = (bfsc === false || bfsc === 'stop') ? false : true;
  11546. _id = tr.id;
  11547. if( bfsc && $.isFunction(ts.p.subGridRowColapsed)) {
  11548. bfsc = ts.p.subGridRowColapsed.call(ts, pID+"_"+_id,_id );
  11549. }
  11550. if(bfsc===false) {return false;}
  11551. if(ts.p.subGridOptions.reloadOnExpand === true) {
  11552. $(r).remove(".ui-subgrid");
  11553. } else if($(r).hasClass('ui-subgrid')) { // incase of dynamic deleting
  11554. $(r).hide();
  11555. }
  11556. $(this).html("<a style='cursor:pointer;'><span class='ui-icon "+ts.p.subGridOptions.plusicon+"'></span></a>").removeClass("sgexpanded").addClass("sgcollapsed");
  11557. if(ts.p.subGridOptions.selectOnCollapse) {
  11558. $(ts).jqGrid('setSelection',_id);
  11559. }
  11560. }
  11561. return false;
  11562. });
  11563. }
  11564. i++;
  11565. }
  11566. if(ts.p.subGridOptions.expandOnLoad === true) {
  11567. $(ts.rows).filter('.jqgrow').each(function(index,row){
  11568. $(row.cells[0]).click();
  11569. });
  11570. }
  11571. ts.subGridXml = function(xml,sid) {subGridXml(xml,sid);};
  11572. ts.subGridJson = function(json,sid) {subGridJson(json,sid);};
  11573. });
  11574. },
  11575. expandSubGridRow : function(rowid) {
  11576. return this.each(function () {
  11577. var $t = this;
  11578. if(!$t.grid && !rowid) {return;}
  11579. if($t.p.subGrid===true) {
  11580. var rc = $(this).jqGrid("getInd",rowid,true);
  11581. if(rc) {
  11582. var sgc = $("td.sgcollapsed",rc)[0];
  11583. if(sgc) {
  11584. $(sgc).trigger("click");
  11585. }
  11586. }
  11587. }
  11588. });
  11589. },
  11590. collapseSubGridRow : function(rowid) {
  11591. return this.each(function () {
  11592. var $t = this;
  11593. if(!$t.grid && !rowid) {return;}
  11594. if($t.p.subGrid===true) {
  11595. var rc = $(this).jqGrid("getInd",rowid,true);
  11596. if(rc) {
  11597. var sgc = $("td.sgexpanded",rc)[0];
  11598. if(sgc) {
  11599. $(sgc).trigger("click");
  11600. }
  11601. }
  11602. }
  11603. });
  11604. },
  11605. toggleSubGridRow : function(rowid) {
  11606. return this.each(function () {
  11607. var $t = this;
  11608. if(!$t.grid && !rowid) {return;}
  11609. if($t.p.subGrid===true) {
  11610. var rc = $(this).jqGrid("getInd",rowid,true);
  11611. if(rc) {
  11612. var sgc = $("td.sgcollapsed",rc)[0];
  11613. if(sgc) {
  11614. $(sgc).trigger("click");
  11615. } else {
  11616. sgc = $("td.sgexpanded",rc)[0];
  11617. if(sgc) {
  11618. $(sgc).trigger("click");
  11619. }
  11620. }
  11621. }
  11622. }
  11623. });
  11624. }
  11625. });
  11626. })(jQuery);
  11627. /*
  11628. Transform a table to a jqGrid.
  11629. Peter Romianowski <peter.romianowski@optivo.de>
  11630. If the first column of the table contains checkboxes or
  11631. radiobuttons then the jqGrid is made selectable.
  11632. */
  11633. // Addition - selector can be a class or id
  11634. function tableToGrid(selector, options) {
  11635. jQuery(selector).each(function() {
  11636. if(this.grid) {return;} //Adedd from Tony Tomov
  11637. // This is a small "hack" to make the width of the jqGrid 100%
  11638. jQuery(this).width("99%");
  11639. var w = jQuery(this).width();
  11640. // Text whether we have single or multi select
  11641. var inputCheckbox = jQuery('tr td:first-child input[type=checkbox]:first', jQuery(this));
  11642. var inputRadio = jQuery('tr td:first-child input[type=radio]:first', jQuery(this));
  11643. var selectMultiple = inputCheckbox.length > 0;
  11644. var selectSingle = !selectMultiple && inputRadio.length > 0;
  11645. var selectable = selectMultiple || selectSingle;
  11646. //var inputName = inputCheckbox.attr("name") || inputRadio.attr("name");
  11647. // Build up the columnModel and the data
  11648. var colModel = [];
  11649. var colNames = [];
  11650. jQuery('th', jQuery(this)).each(function() {
  11651. if (colModel.length === 0 && selectable) {
  11652. colModel.push({
  11653. name: '__selection__',
  11654. index: '__selection__',
  11655. width: 0,
  11656. hidden: true
  11657. });
  11658. colNames.push('__selection__');
  11659. } else {
  11660. colModel.push({
  11661. name: jQuery(this).attr("id") || jQuery.trim(jQuery.jgrid.stripHtml(jQuery(this).html())).split(' ').join('_'),
  11662. index: jQuery(this).attr("id") || jQuery.trim(jQuery.jgrid.stripHtml(jQuery(this).html())).split(' ').join('_'),
  11663. width: jQuery(this).width() || 150
  11664. });
  11665. colNames.push(jQuery(this).html());
  11666. }
  11667. });
  11668. var data = [];
  11669. var rowIds = [];
  11670. var rowChecked = [];
  11671. jQuery('tbody > tr', jQuery(this)).each(function() {
  11672. var row = {};
  11673. var rowPos = 0;
  11674. jQuery('td', jQuery(this)).each(function() {
  11675. if (rowPos === 0 && selectable) {
  11676. var input = jQuery('input', jQuery(this));
  11677. var rowId = input.attr("value");
  11678. rowIds.push(rowId || data.length);
  11679. if (input.is(":checked")) {
  11680. rowChecked.push(rowId);
  11681. }
  11682. row[colModel[rowPos].name] = input.attr("value");
  11683. } else {
  11684. row[colModel[rowPos].name] = jQuery(this).html();
  11685. }
  11686. rowPos++;
  11687. });
  11688. if(rowPos >0) { data.push(row); }
  11689. });
  11690. // Clear the original HTML table
  11691. jQuery(this).empty();
  11692. // Mark it as jqGrid
  11693. jQuery(this).addClass("scroll");
  11694. jQuery(this).jqGrid(jQuery.extend({
  11695. datatype: "local",
  11696. width: w,
  11697. colNames: colNames,
  11698. colModel: colModel,
  11699. multiselect: selectMultiple
  11700. //inputName: inputName,
  11701. //inputValueCol: imputName != null ? "__selection__" : null
  11702. }, options || {}));
  11703. // Add data
  11704. var a;
  11705. for (a = 0; a < data.length; a++) {
  11706. var id = null;
  11707. if (rowIds.length > 0) {
  11708. id = rowIds[a];
  11709. if (id && id.replace) {
  11710. // We have to do this since the value of a checkbox
  11711. // or radio button can be anything
  11712. id = encodeURIComponent(id).replace(/[.\-%]/g, "_");
  11713. }
  11714. }
  11715. if (id === null) {
  11716. id = a + 1;
  11717. }
  11718. jQuery(this).jqGrid("addRowData",id, data[a]);
  11719. }
  11720. // Set the selection
  11721. for (a = 0; a < rowChecked.length; a++) {
  11722. jQuery(this).jqGrid("setSelection",rowChecked[a]);
  11723. }
  11724. });
  11725. };
  11726. /**
  11727. * jqGrid extension - Tree Grid
  11728. * Tony Tomov tony@trirand.com
  11729. * http://trirand.com/blog/
  11730. * Dual licensed under the MIT and GPL licenses:
  11731. * http://www.opensource.org/licenses/mit-license.php
  11732. * http://www.gnu.org/licenses/gpl.html
  11733. **/
  11734. /*jshint eqeqeq:false */
  11735. /*global jQuery */
  11736. (function($) {
  11737. "use strict";
  11738. $.jgrid.extend({
  11739. setTreeNode : function(i, len){
  11740. return this.each(function(){
  11741. var $t = this;
  11742. if( !$t.grid || !$t.p.treeGrid ) {return;}
  11743. var expCol = $t.p.expColInd,
  11744. expanded = $t.p.treeReader.expanded_field,
  11745. isLeaf = $t.p.treeReader.leaf_field,
  11746. level = $t.p.treeReader.level_field,
  11747. icon = $t.p.treeReader.icon_field,
  11748. loaded = $t.p.treeReader.loaded, lft, rgt, curLevel, ident,lftpos, twrap,
  11749. ldat, lf;
  11750. while(i<len) {
  11751. var ind = $.jgrid.stripPref($t.p.idPrefix, $t.rows[i].id), dind = $t.p._index[ind], expan;
  11752. ldat = $t.p.data[dind];
  11753. //$t.rows[i].level = ldat[level];
  11754. if($t.p.treeGridModel === 'nested') {
  11755. if(!ldat[isLeaf]) {
  11756. lft = parseInt(ldat[$t.p.treeReader.left_field],10);
  11757. rgt = parseInt(ldat[$t.p.treeReader.right_field],10);
  11758. // NS Model
  11759. ldat[isLeaf] = (rgt === lft+1) ? 'true' : 'false';
  11760. $t.rows[i].cells[$t.p._treeleafpos].innerHTML = ldat[isLeaf];
  11761. }
  11762. }
  11763. //else {
  11764. //row.parent_id = rd[$t.p.treeReader.parent_id_field];
  11765. //}
  11766. curLevel = parseInt(ldat[level],10);
  11767. if($t.p.tree_root_level === 0) {
  11768. ident = curLevel+1;
  11769. lftpos = curLevel;
  11770. } else {
  11771. ident = curLevel;
  11772. lftpos = curLevel -1;
  11773. }
  11774. twrap = "<div class='tree-wrap tree-wrap-"+$t.p.direction+"' style='width:"+(ident*18)+"px;'>";
  11775. twrap += "<div style='"+($t.p.direction==="rtl" ? "right:" : "left:")+(lftpos*18)+"px;' class='ui-icon ";
  11776. if(ldat[loaded] !== undefined) {
  11777. if(ldat[loaded]==="true" || ldat[loaded]===true) {
  11778. ldat[loaded] = true;
  11779. } else {
  11780. ldat[loaded] = false;
  11781. }
  11782. }
  11783. if(ldat[isLeaf] === "true" || ldat[isLeaf] === true) {
  11784. twrap += ((ldat[icon] !== undefined && ldat[icon] !== "") ? ldat[icon] : $t.p.treeIcons.leaf)+" tree-leaf treeclick";
  11785. ldat[isLeaf] = true;
  11786. lf="leaf";
  11787. } else {
  11788. ldat[isLeaf] = false;
  11789. lf="";
  11790. }
  11791. ldat[expanded] = ((ldat[expanded] === "true" || ldat[expanded] === true) ? true : false) && (ldat[loaded] || ldat[loaded] === undefined);
  11792. if(ldat[expanded] === false) {
  11793. twrap += ((ldat[isLeaf] === true) ? "'" : $t.p.treeIcons.plus+" tree-plus treeclick'");
  11794. } else {
  11795. twrap += ((ldat[isLeaf] === true) ? "'" : $t.p.treeIcons.minus+" tree-minus treeclick'");
  11796. }
  11797. twrap += "></div></div>";
  11798. $($t.rows[i].cells[expCol]).wrapInner("<span class='cell-wrapper"+lf+"'></span>").prepend(twrap);
  11799. if(curLevel !== parseInt($t.p.tree_root_level,10)) {
  11800. var pn = $($t).jqGrid('getNodeParent',ldat);
  11801. expan = pn && pn.hasOwnProperty(expanded) ? pn[expanded] : true;
  11802. if( !expan ){
  11803. $($t.rows[i]).css("display","none");
  11804. }
  11805. }
  11806. $($t.rows[i].cells[expCol])
  11807. .find("div.treeclick")
  11808. .bind("click",function(e){
  11809. var target = e.target || e.srcElement,
  11810. ind2 =$.jgrid.stripPref($t.p.idPrefix,$(target,$t.rows).closest("tr.jqgrow")[0].id),
  11811. pos = $t.p._index[ind2];
  11812. if(!$t.p.data[pos][isLeaf]){
  11813. if($t.p.data[pos][expanded]){
  11814. $($t).jqGrid("collapseRow",$t.p.data[pos]);
  11815. $($t).jqGrid("collapseNode",$t.p.data[pos]);
  11816. } else {
  11817. $($t).jqGrid("expandRow",$t.p.data[pos]);
  11818. $($t).jqGrid("expandNode",$t.p.data[pos]);
  11819. }
  11820. }
  11821. return false;
  11822. });
  11823. if($t.p.ExpandColClick === true) {
  11824. $($t.rows[i].cells[expCol])
  11825. .find("span.cell-wrapper")
  11826. .css("cursor","pointer")
  11827. .bind("click",function(e) {
  11828. var target = e.target || e.srcElement,
  11829. ind2 =$.jgrid.stripPref($t.p.idPrefix,$(target,$t.rows).closest("tr.jqgrow")[0].id),
  11830. pos = $t.p._index[ind2];
  11831. if(!$t.p.data[pos][isLeaf]){
  11832. if($t.p.data[pos][expanded]){
  11833. $($t).jqGrid("collapseRow",$t.p.data[pos]);
  11834. $($t).jqGrid("collapseNode",$t.p.data[pos]);
  11835. } else {
  11836. $($t).jqGrid("expandRow",$t.p.data[pos]);
  11837. $($t).jqGrid("expandNode",$t.p.data[pos]);
  11838. }
  11839. }
  11840. $($t).jqGrid("setSelection",ind2);
  11841. return false;
  11842. });
  11843. }
  11844. i++;
  11845. }
  11846. });
  11847. },
  11848. setTreeGrid : function() {
  11849. return this.each(function (){
  11850. var $t = this, i=0, pico, ecol = false, nm, key, tkey, dupcols=[];
  11851. if(!$t.p.treeGrid) {return;}
  11852. if(!$t.p.treedatatype ) {$.extend($t.p,{treedatatype: $t.p.datatype});}
  11853. $t.p.subGrid = false;$t.p.altRows =false;
  11854. $t.p.pgbuttons = false;$t.p.pginput = false;
  11855. $t.p.gridview = true;
  11856. if($t.p.rowTotal === null ) { $t.p.rowNum = 10000; }
  11857. $t.p.multiselect = false;$t.p.rowList = [];
  11858. $t.p.expColInd = 0;
  11859. pico = 'ui-icon-triangle-1-' + ($t.p.direction==="rtl" ? 'w' : 'e');
  11860. $t.p.treeIcons = $.extend({plus:pico,minus:'ui-icon-triangle-1-s',leaf:'ui-icon-radio-off'},$t.p.treeIcons || {});
  11861. if($t.p.treeGridModel === 'nested') {
  11862. $t.p.treeReader = $.extend({
  11863. level_field: "level",
  11864. left_field:"lft",
  11865. right_field: "rgt",
  11866. leaf_field: "isLeaf",
  11867. expanded_field: "expanded",
  11868. loaded: "loaded",
  11869. icon_field: "icon"
  11870. },$t.p.treeReader);
  11871. } else if($t.p.treeGridModel === 'adjacency') {
  11872. $t.p.treeReader = $.extend({
  11873. level_field: "level",
  11874. parent_id_field: "parent",
  11875. leaf_field: "isLeaf",
  11876. expanded_field: "expanded",
  11877. loaded: "loaded",
  11878. icon_field: "icon"
  11879. },$t.p.treeReader );
  11880. }
  11881. for ( key in $t.p.colModel){
  11882. if($t.p.colModel.hasOwnProperty(key)) {
  11883. nm = $t.p.colModel[key].name;
  11884. if( nm === $t.p.ExpandColumn && !ecol ) {
  11885. ecol = true;
  11886. $t.p.expColInd = i;
  11887. }
  11888. i++;
  11889. //
  11890. for(tkey in $t.p.treeReader) {
  11891. if($t.p.treeReader.hasOwnProperty(tkey) && $t.p.treeReader[tkey] === nm) {
  11892. dupcols.push(nm);
  11893. }
  11894. }
  11895. }
  11896. }
  11897. $.each($t.p.treeReader,function(j,n){
  11898. if(n && $.inArray(n, dupcols) === -1){
  11899. if(j==='leaf_field') { $t.p._treeleafpos= i; }
  11900. i++;
  11901. $t.p.colNames.push(n);
  11902. $t.p.colModel.push({name:n,width:1,hidden:true,sortable:false,resizable:false,hidedlg:true,editable:true,search:false});
  11903. }
  11904. });
  11905. });
  11906. },
  11907. expandRow: function (record){
  11908. this.each(function(){
  11909. var $t = this;
  11910. if(!$t.grid || !$t.p.treeGrid) {return;}
  11911. var childern = $($t).jqGrid("getNodeChildren",record),
  11912. //if ($($t).jqGrid("isVisibleNode",record)) {
  11913. expanded = $t.p.treeReader.expanded_field;
  11914. $(childern).each(function(){
  11915. var id = $t.p.idPrefix + $.jgrid.getAccessor(this,$t.p.localReader.id);
  11916. $($($t).jqGrid('getGridRowById', id)).css("display","");
  11917. if(this[expanded]) {
  11918. $($t).jqGrid("expandRow",this);
  11919. }
  11920. });
  11921. //}
  11922. });
  11923. },
  11924. collapseRow : function (record) {
  11925. this.each(function(){
  11926. var $t = this;
  11927. if(!$t.grid || !$t.p.treeGrid) {return;}
  11928. var childern = $($t).jqGrid("getNodeChildren",record),
  11929. expanded = $t.p.treeReader.expanded_field;
  11930. $(childern).each(function(){
  11931. var id = $t.p.idPrefix + $.jgrid.getAccessor(this,$t.p.localReader.id);
  11932. $($($t).jqGrid('getGridRowById', id)).css("display","none");
  11933. if(this[expanded]){
  11934. $($t).jqGrid("collapseRow",this);
  11935. }
  11936. });
  11937. });
  11938. },
  11939. // NS ,adjacency models
  11940. getRootNodes : function() {
  11941. var result = [];
  11942. this.each(function(){
  11943. var $t = this;
  11944. if(!$t.grid || !$t.p.treeGrid) {return;}
  11945. switch ($t.p.treeGridModel) {
  11946. case 'nested' :
  11947. var level = $t.p.treeReader.level_field;
  11948. $($t.p.data).each(function(){
  11949. if(parseInt(this[level],10) === parseInt($t.p.tree_root_level,10)) {
  11950. result.push(this);
  11951. }
  11952. });
  11953. break;
  11954. case 'adjacency' :
  11955. var parent_id = $t.p.treeReader.parent_id_field;
  11956. $($t.p.data).each(function(){
  11957. if(this[parent_id] === null || String(this[parent_id]).toLowerCase() === "null") {
  11958. result.push(this);
  11959. }
  11960. });
  11961. break;
  11962. }
  11963. });
  11964. return result;
  11965. },
  11966. getNodeDepth : function(rc) {
  11967. var ret = null;
  11968. this.each(function(){
  11969. if(!this.grid || !this.p.treeGrid) {return;}
  11970. var $t = this;
  11971. switch ($t.p.treeGridModel) {
  11972. case 'nested' :
  11973. var level = $t.p.treeReader.level_field;
  11974. ret = parseInt(rc[level],10) - parseInt($t.p.tree_root_level,10);
  11975. break;
  11976. case 'adjacency' :
  11977. ret = $($t).jqGrid("getNodeAncestors",rc).length;
  11978. break;
  11979. }
  11980. });
  11981. return ret;
  11982. },
  11983. getNodeParent : function(rc) {
  11984. var result = null;
  11985. this.each(function(){
  11986. var $t = this;
  11987. if(!$t.grid || !$t.p.treeGrid) {return;}
  11988. switch ($t.p.treeGridModel) {
  11989. case 'nested' :
  11990. var lftc = $t.p.treeReader.left_field,
  11991. rgtc = $t.p.treeReader.right_field,
  11992. levelc = $t.p.treeReader.level_field,
  11993. lft = parseInt(rc[lftc],10), rgt = parseInt(rc[rgtc],10), level = parseInt(rc[levelc],10);
  11994. $(this.p.data).each(function(){
  11995. if(parseInt(this[levelc],10) === level-1 && parseInt(this[lftc],10) < lft && parseInt(this[rgtc],10) > rgt) {
  11996. result = this;
  11997. return false;
  11998. }
  11999. });
  12000. break;
  12001. case 'adjacency' :
  12002. var parent_id = $t.p.treeReader.parent_id_field,
  12003. dtid = $t.p.localReader.id,
  12004. ind = rc[dtid], pos = $t.p._index[ind];
  12005. while(pos--) {
  12006. if($t.p.data[pos][dtid] === $.jgrid.stripPref($t.p.idPrefix, rc[parent_id])) {
  12007. result = $t.p.data[pos];
  12008. break;
  12009. }
  12010. }
  12011. break;
  12012. }
  12013. });
  12014. return result;
  12015. },
  12016. getNodeChildren : function(rc) {
  12017. var result = [];
  12018. this.each(function(){
  12019. var $t = this;
  12020. if(!$t.grid || !$t.p.treeGrid) {return;}
  12021. switch ($t.p.treeGridModel) {
  12022. case 'nested' :
  12023. var lftc = $t.p.treeReader.left_field,
  12024. rgtc = $t.p.treeReader.right_field,
  12025. levelc = $t.p.treeReader.level_field,
  12026. lft = parseInt(rc[lftc],10), rgt = parseInt(rc[rgtc],10), level = parseInt(rc[levelc],10);
  12027. $(this.p.data).each(function(){
  12028. if(parseInt(this[levelc],10) === level+1 && parseInt(this[lftc],10) > lft && parseInt(this[rgtc],10) < rgt) {
  12029. result.push(this);
  12030. }
  12031. });
  12032. break;
  12033. case 'adjacency' :
  12034. var parent_id = $t.p.treeReader.parent_id_field,
  12035. dtid = $t.p.localReader.id;
  12036. $(this.p.data).each(function(){
  12037. if(this[parent_id] == $.jgrid.stripPref($t.p.idPrefix, rc[dtid])) {
  12038. result.push(this);
  12039. }
  12040. });
  12041. break;
  12042. }
  12043. });
  12044. return result;
  12045. },
  12046. getFullTreeNode : function(rc) {
  12047. var result = [];
  12048. this.each(function(){
  12049. var $t = this, len;
  12050. if(!$t.grid || !$t.p.treeGrid) {return;}
  12051. switch ($t.p.treeGridModel) {
  12052. case 'nested' :
  12053. var lftc = $t.p.treeReader.left_field,
  12054. rgtc = $t.p.treeReader.right_field,
  12055. levelc = $t.p.treeReader.level_field,
  12056. lft = parseInt(rc[lftc],10), rgt = parseInt(rc[rgtc],10), level = parseInt(rc[levelc],10);
  12057. $(this.p.data).each(function(){
  12058. if(parseInt(this[levelc],10) >= level && parseInt(this[lftc],10) >= lft && parseInt(this[lftc],10) <= rgt) {
  12059. result.push(this);
  12060. }
  12061. });
  12062. break;
  12063. case 'adjacency' :
  12064. if(rc) {
  12065. result.push(rc);
  12066. var parent_id = $t.p.treeReader.parent_id_field,
  12067. dtid = $t.p.localReader.id;
  12068. $(this.p.data).each(function(i){
  12069. len = result.length;
  12070. for (i = 0; i < len; i++) {
  12071. if ($.jgrid.stripPref($t.p.idPrefix, result[i][dtid]) === this[parent_id]) {
  12072. result.push(this);
  12073. break;
  12074. }
  12075. }
  12076. });
  12077. }
  12078. break;
  12079. }
  12080. });
  12081. return result;
  12082. },
  12083. // End NS, adjacency Model
  12084. getNodeAncestors : function(rc) {
  12085. var ancestors = [];
  12086. this.each(function(){
  12087. if(!this.grid || !this.p.treeGrid) {return;}
  12088. var parent = $(this).jqGrid("getNodeParent",rc);
  12089. while (parent) {
  12090. ancestors.push(parent);
  12091. parent = $(this).jqGrid("getNodeParent",parent);
  12092. }
  12093. });
  12094. return ancestors;
  12095. },
  12096. isVisibleNode : function(rc) {
  12097. var result = true;
  12098. this.each(function(){
  12099. var $t = this;
  12100. if(!$t.grid || !$t.p.treeGrid) {return;}
  12101. var ancestors = $($t).jqGrid("getNodeAncestors",rc),
  12102. expanded = $t.p.treeReader.expanded_field;
  12103. $(ancestors).each(function(){
  12104. result = result && this[expanded];
  12105. if(!result) {return false;}
  12106. });
  12107. });
  12108. return result;
  12109. },
  12110. isNodeLoaded : function(rc) {
  12111. var result;
  12112. this.each(function(){
  12113. var $t = this;
  12114. if(!$t.grid || !$t.p.treeGrid) {return;}
  12115. var isLeaf = $t.p.treeReader.leaf_field,
  12116. loaded = $t.p.treeReader.loaded;
  12117. if(rc !== undefined ) {
  12118. if(rc[loaded] !== undefined) {
  12119. result = rc[loaded];
  12120. } else if( rc[isLeaf] || $($t).jqGrid("getNodeChildren",rc).length > 0){
  12121. result = true;
  12122. } else {
  12123. result = false;
  12124. }
  12125. } else {
  12126. result = false;
  12127. }
  12128. });
  12129. return result;
  12130. },
  12131. expandNode : function(rc) {
  12132. return this.each(function(){
  12133. if(!this.grid || !this.p.treeGrid) {return;}
  12134. var expanded = this.p.treeReader.expanded_field,
  12135. parent = this.p.treeReader.parent_id_field,
  12136. loaded = this.p.treeReader.loaded,
  12137. level = this.p.treeReader.level_field,
  12138. lft = this.p.treeReader.left_field,
  12139. rgt = this.p.treeReader.right_field;
  12140. if(!rc[expanded]) {
  12141. var id = $.jgrid.getAccessor(rc,this.p.localReader.id);
  12142. var rc1 = $("#" + this.p.idPrefix + $.jgrid.jqID(id),this.grid.bDiv)[0];
  12143. var position = this.p._index[id];
  12144. if( $(this).jqGrid("isNodeLoaded",this.p.data[position]) ) {
  12145. rc[expanded] = true;
  12146. $("div.treeclick",rc1).removeClass(this.p.treeIcons.plus+" tree-plus").addClass(this.p.treeIcons.minus+" tree-minus");
  12147. } else if (!this.grid.hDiv.loading) {
  12148. rc[expanded] = true;
  12149. $("div.treeclick",rc1).removeClass(this.p.treeIcons.plus+" tree-plus").addClass(this.p.treeIcons.minus+" tree-minus");
  12150. this.p.treeANode = rc1.rowIndex;
  12151. this.p.datatype = this.p.treedatatype;
  12152. if(this.p.treeGridModel === 'nested') {
  12153. $(this).jqGrid("setGridParam",{postData:{nodeid:id,n_left:rc[lft],n_right:rc[rgt],n_level:rc[level]}});
  12154. } else {
  12155. $(this).jqGrid("setGridParam",{postData:{nodeid:id,parentid:rc[parent],n_level:rc[level]}} );
  12156. }
  12157. $(this).trigger("reloadGrid");
  12158. rc[loaded] = true;
  12159. if(this.p.treeGridModel === 'nested') {
  12160. $(this).jqGrid("setGridParam",{postData:{nodeid:'',n_left:'',n_right:'',n_level:''}});
  12161. } else {
  12162. $(this).jqGrid("setGridParam",{postData:{nodeid:'',parentid:'',n_level:''}});
  12163. }
  12164. }
  12165. }
  12166. });
  12167. },
  12168. collapseNode : function(rc) {
  12169. return this.each(function(){
  12170. if(!this.grid || !this.p.treeGrid) {return;}
  12171. var expanded = this.p.treeReader.expanded_field;
  12172. if(rc[expanded]) {
  12173. rc[expanded] = false;
  12174. var id = $.jgrid.getAccessor(rc,this.p.localReader.id);
  12175. var rc1 = $("#" + this.p.idPrefix + $.jgrid.jqID(id),this.grid.bDiv)[0];
  12176. $("div.treeclick",rc1).removeClass(this.p.treeIcons.minus+" tree-minus").addClass(this.p.treeIcons.plus+" tree-plus");
  12177. }
  12178. });
  12179. },
  12180. SortTree : function( sortname, newDir, st, datefmt) {
  12181. return this.each(function(){
  12182. if(!this.grid || !this.p.treeGrid) {return;}
  12183. var i, len,
  12184. rec, records = [], $t = this, query, roots,
  12185. rt = $(this).jqGrid("getRootNodes");
  12186. // Sorting roots
  12187. query = $.jgrid.from(rt);
  12188. query.orderBy(sortname,newDir,st, datefmt);
  12189. roots = query.select();
  12190. // Sorting children
  12191. for (i = 0, len = roots.length; i < len; i++) {
  12192. rec = roots[i];
  12193. records.push(rec);
  12194. $(this).jqGrid("collectChildrenSortTree",records, rec, sortname, newDir,st, datefmt);
  12195. }
  12196. $.each(records, function(index) {
  12197. var id = $.jgrid.getAccessor(this,$t.p.localReader.id);
  12198. $('#'+$.jgrid.jqID($t.p.id)+ ' tbody tr:eq('+index+')').after($('tr#'+$.jgrid.jqID(id),$t.grid.bDiv));
  12199. });
  12200. query = null;roots=null;records=null;
  12201. });
  12202. },
  12203. collectChildrenSortTree : function(records, rec, sortname, newDir,st, datefmt) {
  12204. return this.each(function(){
  12205. if(!this.grid || !this.p.treeGrid) {return;}
  12206. var i, len,
  12207. child, ch, query, children;
  12208. ch = $(this).jqGrid("getNodeChildren",rec);
  12209. query = $.jgrid.from(ch);
  12210. query.orderBy(sortname, newDir, st, datefmt);
  12211. children = query.select();
  12212. for (i = 0, len = children.length; i < len; i++) {
  12213. child = children[i];
  12214. records.push(child);
  12215. $(this).jqGrid("collectChildrenSortTree",records, child, sortname, newDir, st, datefmt);
  12216. }
  12217. });
  12218. },
  12219. // experimental
  12220. setTreeRow : function(rowid, data) {
  12221. var success=false;
  12222. this.each(function(){
  12223. var t = this;
  12224. if(!t.grid || !t.p.treeGrid) {return;}
  12225. success = $(t).jqGrid("setRowData",rowid,data);
  12226. });
  12227. return success;
  12228. },
  12229. delTreeNode : function (rowid) {
  12230. return this.each(function () {
  12231. var $t = this, rid = $t.p.localReader.id, i,
  12232. left = $t.p.treeReader.left_field,
  12233. right = $t.p.treeReader.right_field, myright, width, res, key;
  12234. if(!$t.grid || !$t.p.treeGrid) {return;}
  12235. var rc = $t.p._index[rowid];
  12236. if (rc !== undefined) {
  12237. // nested
  12238. myright = parseInt($t.p.data[rc][right],10);
  12239. width = myright - parseInt($t.p.data[rc][left],10) + 1;
  12240. var dr = $($t).jqGrid("getFullTreeNode",$t.p.data[rc]);
  12241. if(dr.length>0){
  12242. for (i=0;i<dr.length;i++){
  12243. $($t).jqGrid("delRowData",dr[i][rid]);
  12244. }
  12245. }
  12246. if( $t.p.treeGridModel === "nested") {
  12247. // ToDo - update grid data
  12248. res = $.jgrid.from($t.p.data)
  12249. .greater(left,myright,{stype:'integer'})
  12250. .select();
  12251. if(res.length) {
  12252. for( key in res) {
  12253. if(res.hasOwnProperty(key)) {
  12254. res[key][left] = parseInt(res[key][left],10) - width ;
  12255. }
  12256. }
  12257. }
  12258. res = $.jgrid.from($t.p.data)
  12259. .greater(right,myright,{stype:'integer'})
  12260. .select();
  12261. if(res.length) {
  12262. for( key in res) {
  12263. if(res.hasOwnProperty(key)) {
  12264. res[key][right] = parseInt(res[key][right],10) - width ;
  12265. }
  12266. }
  12267. }
  12268. }
  12269. }
  12270. });
  12271. },
  12272. addChildNode : function( nodeid, parentid, data, expandData ) {
  12273. //return this.each(function(){
  12274. var $t = this[0];
  12275. if(data) {
  12276. // we suppose tha the id is autoincremet and
  12277. var expanded = $t.p.treeReader.expanded_field,
  12278. isLeaf = $t.p.treeReader.leaf_field,
  12279. level = $t.p.treeReader.level_field,
  12280. //icon = $t.p.treeReader.icon_field,
  12281. parent = $t.p.treeReader.parent_id_field,
  12282. left = $t.p.treeReader.left_field,
  12283. right = $t.p.treeReader.right_field,
  12284. loaded = $t.p.treeReader.loaded,
  12285. method, parentindex, parentdata, parentlevel, i, len, max=0, rowind = parentid, leaf, maxright;
  12286. if(expandData===undefined) {expandData = false;}
  12287. if ( nodeid === undefined || nodeid === null ) {
  12288. i = $t.p.data.length-1;
  12289. if( i>= 0 ) {
  12290. while(i>=0){max = Math.max(max, parseInt($t.p.data[i][$t.p.localReader.id],10)); i--;}
  12291. }
  12292. nodeid = max+1;
  12293. }
  12294. var prow = $($t).jqGrid('getInd', parentid);
  12295. leaf = false;
  12296. // if not a parent we assume root
  12297. if ( parentid === undefined || parentid === null || parentid==="") {
  12298. parentid = null;
  12299. rowind = null;
  12300. method = 'last';
  12301. parentlevel = $t.p.tree_root_level;
  12302. i = $t.p.data.length+1;
  12303. } else {
  12304. method = 'after';
  12305. parentindex = $t.p._index[parentid];
  12306. parentdata = $t.p.data[parentindex];
  12307. parentid = parentdata[$t.p.localReader.id];
  12308. parentlevel = parseInt(parentdata[level],10)+1;
  12309. var childs = $($t).jqGrid('getFullTreeNode', parentdata);
  12310. // if there are child nodes get the last index of it
  12311. if(childs.length) {
  12312. i = childs[childs.length-1][$t.p.localReader.id];
  12313. rowind = i;
  12314. i = $($t).jqGrid('getInd',rowind)+1;
  12315. } else {
  12316. i = $($t).jqGrid('getInd', parentid)+1;
  12317. }
  12318. // if the node is leaf
  12319. if(parentdata[isLeaf]) {
  12320. leaf = true;
  12321. parentdata[expanded] = true;
  12322. //var prow = $($t).jqGrid('getInd', parentid);
  12323. $($t.rows[prow])
  12324. .find("span.cell-wrapperleaf").removeClass("cell-wrapperleaf").addClass("cell-wrapper")
  12325. .end()
  12326. .find("div.tree-leaf").removeClass($t.p.treeIcons.leaf+" tree-leaf").addClass($t.p.treeIcons.minus+" tree-minus");
  12327. $t.p.data[parentindex][isLeaf] = false;
  12328. parentdata[loaded] = true;
  12329. }
  12330. }
  12331. len = i+1;
  12332. if( data[expanded]===undefined) {data[expanded]= false;}
  12333. if( data[loaded]===undefined ) { data[loaded] = false;}
  12334. data[level] = parentlevel;
  12335. if( data[isLeaf]===undefined) {data[isLeaf]= true;}
  12336. if( $t.p.treeGridModel === "adjacency") {
  12337. data[parent] = parentid;
  12338. }
  12339. if( $t.p.treeGridModel === "nested") {
  12340. // this method requiere more attention
  12341. var query, res, key;
  12342. //maxright = parseInt(maxright,10);
  12343. // ToDo - update grid data
  12344. if(parentid !== null) {
  12345. maxright = parseInt(parentdata[right],10);
  12346. query = $.jgrid.from($t.p.data);
  12347. query = query.greaterOrEquals(right,maxright,{stype:'integer'});
  12348. res = query.select();
  12349. if(res.length) {
  12350. for( key in res) {
  12351. if(res.hasOwnProperty(key)) {
  12352. res[key][left] = res[key][left] > maxright ? parseInt(res[key][left],10) +2 : res[key][left];
  12353. res[key][right] = res[key][right] >= maxright ? parseInt(res[key][right],10) +2 : res[key][right];
  12354. }
  12355. }
  12356. }
  12357. data[left] = maxright;
  12358. data[right]= maxright+1;
  12359. } else {
  12360. maxright = parseInt( $($t).jqGrid('getCol', right, false, 'max'), 10);
  12361. res = $.jgrid.from($t.p.data)
  12362. .greater(left,maxright,{stype:'integer'})
  12363. .select();
  12364. if(res.length) {
  12365. for( key in res) {
  12366. if(res.hasOwnProperty(key)) {
  12367. res[key][left] = parseInt(res[key][left],10) +2 ;
  12368. }
  12369. }
  12370. }
  12371. res = $.jgrid.from($t.p.data)
  12372. .greater(right,maxright,{stype:'integer'})
  12373. .select();
  12374. if(res.length) {
  12375. for( key in res) {
  12376. if(res.hasOwnProperty(key)) {
  12377. res[key][right] = parseInt(res[key][right],10) +2 ;
  12378. }
  12379. }
  12380. }
  12381. data[left] = maxright+1;
  12382. data[right] = maxright + 2;
  12383. }
  12384. }
  12385. if( parentid === null || $($t).jqGrid("isNodeLoaded",parentdata) || leaf ) {
  12386. $($t).jqGrid('addRowData', nodeid, data, method, rowind);
  12387. $($t).jqGrid('setTreeNode', i, len);
  12388. }
  12389. if(parentdata && !parentdata[expanded] && expandData) {
  12390. $($t.rows[prow])
  12391. .find("div.treeclick")
  12392. .click();
  12393. }
  12394. }
  12395. //});
  12396. }
  12397. });
  12398. })(jQuery);
  12399. /*
  12400. * jqDnR - Minimalistic Drag'n'Resize for jQuery.
  12401. *
  12402. * Copyright (c) 2007 Brice Burgess <bhb@iceburg.net>, http://www.iceburg.net
  12403. * Licensed under the MIT License:
  12404. * http://www.opensource.org/licenses/mit-license.php
  12405. *
  12406. * $Version: 2007.08.19 +r2
  12407. */
  12408. (function($){
  12409. $.fn.jqDrag=function(h){return i(this,h,'d');};
  12410. $.fn.jqResize=function(h,ar){return i(this,h,'r',ar);};
  12411. $.jqDnR={
  12412. dnr:{},
  12413. e:0,
  12414. drag:function(v){
  12415. if(M.k == 'd'){E.css({left:M.X+v.pageX-M.pX,top:M.Y+v.pageY-M.pY});}
  12416. else {
  12417. E.css({width:Math.max(v.pageX-M.pX+M.W,0),height:Math.max(v.pageY-M.pY+M.H,0)});
  12418. if(M1){E1.css({width:Math.max(v.pageX-M1.pX+M1.W,0),height:Math.max(v.pageY-M1.pY+M1.H,0)});}
  12419. }
  12420. return false;
  12421. },
  12422. stop:function(){
  12423. //E.css('opacity',M.o);
  12424. $(document).unbind('mousemove',J.drag).unbind('mouseup',J.stop);
  12425. }
  12426. };
  12427. var J=$.jqDnR,M=J.dnr,E=J.e,E1,M1,
  12428. i=function(e,h,k,aR){
  12429. return e.each(function(){
  12430. h=(h)?$(h,e):e;
  12431. h.bind('mousedown',{e:e,k:k},function(v){
  12432. var d=v.data,p={};E=d.e;E1 = aR ? $(aR) : false;
  12433. // attempt utilization of dimensions plugin to fix IE issues
  12434. if(E.css('position') != 'relative'){try{E.position(p);}catch(e){}}
  12435. M={
  12436. X:p.left||f('left')||0,
  12437. Y:p.top||f('top')||0,
  12438. W:f('width')||E[0].scrollWidth||0,
  12439. H:f('height')||E[0].scrollHeight||0,
  12440. pX:v.pageX,
  12441. pY:v.pageY,
  12442. k:d.k
  12443. //o:E.css('opacity')
  12444. };
  12445. // also resize
  12446. if(E1 && d.k != 'd'){
  12447. M1={
  12448. X:p.left||f1('left')||0,
  12449. Y:p.top||f1('top')||0,
  12450. W:E1[0].offsetWidth||f1('width')||0,
  12451. H:E1[0].offsetHeight||f1('height')||0,
  12452. pX:v.pageX,
  12453. pY:v.pageY,
  12454. k:d.k
  12455. };
  12456. } else {M1 = false;}
  12457. //E.css({opacity:0.8});
  12458. if($("input.hasDatepicker",E[0])[0]) {
  12459. try {$("input.hasDatepicker",E[0]).datepicker('hide');}catch (dpe){}
  12460. }
  12461. $(document).mousemove($.jqDnR.drag).mouseup($.jqDnR.stop);
  12462. return false;
  12463. });
  12464. });
  12465. },
  12466. f=function(k){return parseInt(E.css(k),10)||false;},
  12467. f1=function(k){return parseInt(E1.css(k),10)||false;};
  12468. })(jQuery);/*
  12469. * jqModal - Minimalist Modaling with jQuery
  12470. * (http://dev.iceburg.net/jquery/jqmodal/)
  12471. *
  12472. * Copyright (c) 2007,2008 Brice Burgess <bhb@iceburg.net>
  12473. * Dual licensed under the MIT and GPL licenses:
  12474. * http://www.opensource.org/licenses/mit-license.php
  12475. * http://www.gnu.org/licenses/gpl.html
  12476. *
  12477. * $Version: 07/06/2008 +r13
  12478. */
  12479. (function($) {
  12480. $.fn.jqm=function(o){
  12481. var p={
  12482. overlay: 50,
  12483. closeoverlay : true,
  12484. overlayClass: 'jqmOverlay',
  12485. closeClass: 'jqmClose',
  12486. trigger: '.jqModal',
  12487. ajax: F,
  12488. ajaxText: '',
  12489. target: F,
  12490. modal: F,
  12491. toTop: F,
  12492. onShow: F,
  12493. onHide: F,
  12494. onLoad: F
  12495. };
  12496. return this.each(function(){if(this._jqm)return H[this._jqm].c=$.extend({},H[this._jqm].c,o);s++;this._jqm=s;
  12497. H[s]={c:$.extend(p,$.jqm.params,o),a:F,w:$(this).addClass('jqmID'+s),s:s};
  12498. if(p.trigger)$(this).jqmAddTrigger(p.trigger);
  12499. });};
  12500. $.fn.jqmAddClose=function(e){return hs(this,e,'jqmHide');};
  12501. $.fn.jqmAddTrigger=function(e){return hs(this,e,'jqmShow');};
  12502. $.fn.jqmShow=function(t){return this.each(function(){$.jqm.open(this._jqm,t);});};
  12503. $.fn.jqmHide=function(t){return this.each(function(){$.jqm.close(this._jqm,t)});};
  12504. $.jqm = {
  12505. hash:{},
  12506. 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);
  12507. if(c.modal) {if(!A[0])setTimeout(function(){L('bind');},1);A.push(s);}
  12508. else if(c.overlay > 0) {if(c.closeoverlay) h.w.jqmAddClose(o);}
  12509. else o=F;
  12510. h.o=(o)?o.addClass(c.overlayClass).prependTo('body'):F;
  12511. 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;
  12512. 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);});}
  12513. else if(cc)h.w.jqmAddClose($(cc,h.w));
  12514. if(c.toTop&&h.o)h.w.before('<span id="jqmP'+h.w[0]._jqm+'"></span>').insertAfter(h.o);
  12515. (c.onShow)?c.onShow(h):h.w.show();e(h);return F;
  12516. },
  12517. close:function(s){var h=H[s];if(!h.a)return F;h.a=F;
  12518. if(A[0]){A.pop();if(!A[0])L('unbind');}
  12519. if(h.c.toTop&&h.o)$('#jqmP'+h.w[0]._jqm).after(h.w).remove();
  12520. if(h.c.onHide)h.c.onHide(h);else{h.w.hide();if(h.o)h.o.remove();} return F;
  12521. },
  12522. params:{}};
  12523. var s=0,H=$.jqm.hash,A=[],F=false,
  12524. e=function(h){f(h);},
  12525. f=function(h){try{$(':input:visible',h.w)[0].focus();}catch(_){}},
  12526. L=function(t){$(document)[t]("keypress",m)[t]("keydown",m)[t]("mousedown",m);},
  12527. 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;},
  12528. hs=function(w,t,c){return w.each(function(){var s=this._jqm;$(t).each(function() {
  12529. 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);});});};
  12530. })(jQuery);/*
  12531. **
  12532. * formatter for values but most of the values if for jqGrid
  12533. * Some of this was inspired and based on how YUI does the table datagrid but in jQuery fashion
  12534. * we are trying to keep it as light as possible
  12535. * Joshua Burnett josh@9ci.com
  12536. * http://www.greenbill.com
  12537. *
  12538. * Changes from Tony Tomov tony@trirand.com
  12539. * Dual licensed under the MIT and GPL licenses:
  12540. * http://www.opensource.org/licenses/mit-license.php
  12541. * http://www.gnu.org/licenses/gpl-2.0.html
  12542. *
  12543. **/
  12544. /*jshint eqeqeq:false */
  12545. /*global jQuery */
  12546. (function($) {
  12547. "use strict";
  12548. $.fmatter = {};
  12549. //opts can be id:row id for the row, rowdata:the data for the row, colmodel:the column model for this column
  12550. //example {id:1234,}
  12551. $.extend($.fmatter,{
  12552. isBoolean : function(o) {
  12553. return typeof o === 'boolean';
  12554. },
  12555. isObject : function(o) {
  12556. return (o && (typeof o === 'object' || $.isFunction(o))) || false;
  12557. },
  12558. isString : function(o) {
  12559. return typeof o === 'string';
  12560. },
  12561. isNumber : function(o) {
  12562. return typeof o === 'number' && isFinite(o);
  12563. },
  12564. isValue : function (o) {
  12565. return (this.isObject(o) || this.isString(o) || this.isNumber(o) || this.isBoolean(o));
  12566. },
  12567. isEmpty : function(o) {
  12568. if(!this.isString(o) && this.isValue(o)) {
  12569. return false;
  12570. }
  12571. if (!this.isValue(o)){
  12572. return true;
  12573. }
  12574. o = $.trim(o).replace(/\&nbsp\;/ig,'').replace(/\&#160\;/ig,'');
  12575. return o==="";
  12576. }
  12577. });
  12578. $.fn.fmatter = function(formatType, cellval, opts, rwd, act) {
  12579. // build main options before element iteration
  12580. var v=cellval;
  12581. opts = $.extend({}, $.jgrid.formatter, opts);
  12582. try {
  12583. v = $.fn.fmatter[formatType].call(this, cellval, opts, rwd, act);
  12584. } catch(fe){}
  12585. return v;
  12586. };
  12587. $.fmatter.util = {
  12588. // Taken from YAHOO utils
  12589. NumberFormat : function(nData,opts) {
  12590. if(!$.fmatter.isNumber(nData)) {
  12591. nData *= 1;
  12592. }
  12593. if($.fmatter.isNumber(nData)) {
  12594. var bNegative = (nData < 0);
  12595. var sOutput = String(nData);
  12596. var sDecimalSeparator = opts.decimalSeparator || ".";
  12597. var nDotIndex;
  12598. if($.fmatter.isNumber(opts.decimalPlaces)) {
  12599. // Round to the correct decimal place
  12600. var nDecimalPlaces = opts.decimalPlaces;
  12601. var nDecimal = Math.pow(10, nDecimalPlaces);
  12602. sOutput = String(Math.round(nData*nDecimal)/nDecimal);
  12603. nDotIndex = sOutput.lastIndexOf(".");
  12604. if(nDecimalPlaces > 0) {
  12605. // Add the decimal separator
  12606. if(nDotIndex < 0) {
  12607. sOutput += sDecimalSeparator;
  12608. nDotIndex = sOutput.length-1;
  12609. }
  12610. // Replace the "."
  12611. else if(sDecimalSeparator !== "."){
  12612. sOutput = sOutput.replace(".",sDecimalSeparator);
  12613. }
  12614. // Add missing zeros
  12615. while((sOutput.length - 1 - nDotIndex) < nDecimalPlaces) {
  12616. sOutput += "0";
  12617. }
  12618. }
  12619. }
  12620. if(opts.thousandsSeparator) {
  12621. var sThousandsSeparator = opts.thousandsSeparator;
  12622. nDotIndex = sOutput.lastIndexOf(sDecimalSeparator);
  12623. nDotIndex = (nDotIndex > -1) ? nDotIndex : sOutput.length;
  12624. var sNewOutput = sOutput.substring(nDotIndex);
  12625. var nCount = -1, i;
  12626. for (i=nDotIndex; i>0; i--) {
  12627. nCount++;
  12628. if ((nCount%3 === 0) && (i !== nDotIndex) && (!bNegative || (i > 1))) {
  12629. sNewOutput = sThousandsSeparator + sNewOutput;
  12630. }
  12631. sNewOutput = sOutput.charAt(i-1) + sNewOutput;
  12632. }
  12633. sOutput = sNewOutput;
  12634. }
  12635. // Prepend prefix
  12636. sOutput = (opts.prefix) ? opts.prefix + sOutput : sOutput;
  12637. // Append suffix
  12638. sOutput = (opts.suffix) ? sOutput + opts.suffix : sOutput;
  12639. return sOutput;
  12640. }
  12641. return nData;
  12642. }
  12643. };
  12644. $.fn.fmatter.defaultFormat = function(cellval, opts) {
  12645. return ($.fmatter.isValue(cellval) && cellval!=="" ) ? cellval : opts.defaultValue || "&#160;";
  12646. };
  12647. $.fn.fmatter.email = function(cellval, opts) {
  12648. if(!$.fmatter.isEmpty(cellval)) {
  12649. return "<a href=\"mailto:" + cellval + "\">" + cellval + "</a>";
  12650. }
  12651. return $.fn.fmatter.defaultFormat(cellval,opts );
  12652. };
  12653. $.fn.fmatter.checkbox =function(cval, opts) {
  12654. var op = $.extend({},opts.checkbox), ds;
  12655. if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
  12656. op = $.extend({},op,opts.colModel.formatoptions);
  12657. }
  12658. if(op.disabled===true) {ds = "disabled=\"disabled\"";} else {ds="";}
  12659. if($.fmatter.isEmpty(cval) || cval === undefined ) {cval = $.fn.fmatter.defaultFormat(cval,op);}
  12660. cval=String(cval);
  12661. cval=(cval+"").toLowerCase();
  12662. var bchk = cval.search(/(false|f|0|no|n|off|undefined)/i)<0 ? " checked='checked' " : "";
  12663. return "<input type=\"checkbox\" " + bchk + " value=\""+ cval+"\" offval=\"no\" "+ds+ "/>";
  12664. };
  12665. $.fn.fmatter.link = function(cellval, opts) {
  12666. var op = {target:opts.target};
  12667. var target = "";
  12668. if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
  12669. op = $.extend({},op,opts.colModel.formatoptions);
  12670. }
  12671. if(op.target) {target = 'target=' + op.target;}
  12672. if(!$.fmatter.isEmpty(cellval)) {
  12673. return "<a "+target+" href=\"" + cellval + "\">" + cellval + "</a>";
  12674. }
  12675. return $.fn.fmatter.defaultFormat(cellval,opts);
  12676. };
  12677. $.fn.fmatter.showlink = function(cellval, opts) {
  12678. var op = {baseLinkUrl: opts.baseLinkUrl,showAction:opts.showAction, addParam: opts.addParam || "", target: opts.target, idName: opts.idName},
  12679. target = "", idUrl;
  12680. if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
  12681. op = $.extend({},op,opts.colModel.formatoptions);
  12682. }
  12683. if(op.target) {target = 'target=' + op.target;}
  12684. idUrl = op.baseLinkUrl+op.showAction + '?'+ op.idName+'='+opts.rowId+op.addParam;
  12685. if($.fmatter.isString(cellval) || $.fmatter.isNumber(cellval)) { //add this one even if its blank string
  12686. return "<a "+target+" href=\"" + idUrl + "\">" + cellval + "</a>";
  12687. }
  12688. return $.fn.fmatter.defaultFormat(cellval,opts);
  12689. };
  12690. $.fn.fmatter.integer = function(cellval, opts) {
  12691. var op = $.extend({},opts.integer);
  12692. if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
  12693. op = $.extend({},op,opts.colModel.formatoptions);
  12694. }
  12695. if($.fmatter.isEmpty(cellval)) {
  12696. return op.defaultValue;
  12697. }
  12698. return $.fmatter.util.NumberFormat(cellval,op);
  12699. };
  12700. $.fn.fmatter.number = function (cellval, opts) {
  12701. var op = $.extend({},opts.number);
  12702. if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
  12703. op = $.extend({},op,opts.colModel.formatoptions);
  12704. }
  12705. if($.fmatter.isEmpty(cellval)) {
  12706. return op.defaultValue;
  12707. }
  12708. return $.fmatter.util.NumberFormat(cellval,op);
  12709. };
  12710. $.fn.fmatter.currency = function (cellval, opts) {
  12711. var op = $.extend({},opts.currency);
  12712. if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
  12713. op = $.extend({},op,opts.colModel.formatoptions);
  12714. }
  12715. if($.fmatter.isEmpty(cellval)) {
  12716. return op.defaultValue;
  12717. }
  12718. return $.fmatter.util.NumberFormat(cellval,op);
  12719. };
  12720. $.fn.fmatter.date = function (cellval, opts, rwd, act) {
  12721. var op = $.extend({},opts.date);
  12722. if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
  12723. op = $.extend({},op,opts.colModel.formatoptions);
  12724. }
  12725. if(!op.reformatAfterEdit && act === 'edit'){
  12726. return $.fn.fmatter.defaultFormat(cellval, opts);
  12727. }
  12728. if(!$.fmatter.isEmpty(cellval)) {
  12729. return $.jgrid.parseDate(op.srcformat,cellval,op.newformat,op);
  12730. }
  12731. return $.fn.fmatter.defaultFormat(cellval, opts);
  12732. };
  12733. $.fn.fmatter.select = function (cellval,opts) {
  12734. // jqGrid specific
  12735. cellval = String(cellval);
  12736. var oSelect = false, ret=[], sep, delim;
  12737. if(opts.colModel.formatoptions !== undefined){
  12738. oSelect= opts.colModel.formatoptions.value;
  12739. sep = opts.colModel.formatoptions.separator === undefined ? ":" : opts.colModel.formatoptions.separator;
  12740. delim = opts.colModel.formatoptions.delimiter === undefined ? ";" : opts.colModel.formatoptions.delimiter;
  12741. } else if(opts.colModel.editoptions !== undefined){
  12742. oSelect= opts.colModel.editoptions.value;
  12743. sep = opts.colModel.editoptions.separator === undefined ? ":" : opts.colModel.editoptions.separator;
  12744. delim = opts.colModel.editoptions.delimiter === undefined ? ";" : opts.colModel.editoptions.delimiter;
  12745. }
  12746. if (oSelect) {
  12747. var msl = (opts.colModel.editoptions != null && opts.colModel.editoptions.multiple === true) === true ? true : false,
  12748. scell = [], sv;
  12749. if(msl) {scell = cellval.split(",");scell = $.map(scell,function(n){return $.trim(n);});}
  12750. if ($.fmatter.isString(oSelect)) {
  12751. // mybe here we can use some caching with care ????
  12752. var so = oSelect.split(delim), j=0, i;
  12753. for(i=0; i<so.length;i++){
  12754. sv = so[i].split(sep);
  12755. if(sv.length > 2 ) {
  12756. sv[1] = $.map(sv,function(n,i){if(i>0) {return n;}}).join(sep);
  12757. }
  12758. if(msl) {
  12759. if($.inArray(sv[0],scell)>-1) {
  12760. ret[j] = sv[1];
  12761. j++;
  12762. }
  12763. } else if($.trim(sv[0]) === $.trim(cellval)) {
  12764. ret[0] = sv[1];
  12765. break;
  12766. }
  12767. }
  12768. } else if($.fmatter.isObject(oSelect)) {
  12769. // this is quicker
  12770. if(msl) {
  12771. ret = $.map(scell, function(n){
  12772. return oSelect[n];
  12773. });
  12774. } else {
  12775. ret[0] = oSelect[cellval] || "";
  12776. }
  12777. }
  12778. }
  12779. cellval = ret.join(", ");
  12780. return cellval === "" ? $.fn.fmatter.defaultFormat(cellval,opts) : cellval;
  12781. };
  12782. $.fn.fmatter.rowactions = function(act) {
  12783. var $tr = $(this).closest("tr.jqgrow"),
  12784. rid = $tr.attr("id"),
  12785. $id = $(this).closest("table.ui-jqgrid-btable").attr('id').replace(/_frozen([^_]*)$/,'$1'),
  12786. $grid = $("#"+$id),
  12787. $t = $grid[0],
  12788. p = $t.p,
  12789. cm = p.colModel[$.jgrid.getCellIndex(this)],
  12790. $actionsDiv = cm.frozen ? $("tr#"+rid+" td:eq("+$.jgrid.getCellIndex(this)+") > div",$grid) :$(this).parent(),
  12791. op = {
  12792. extraparam: {}
  12793. },
  12794. saverow = function(rowid, res) {
  12795. if($.isFunction(op.afterSave)) { op.afterSave.call($t, rowid, res); }
  12796. $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show();
  12797. $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide();
  12798. },
  12799. restorerow = function(rowid) {
  12800. if($.isFunction(op.afterRestore)) { op.afterRestore.call($t, rowid); }
  12801. $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show();
  12802. $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide();
  12803. };
  12804. if (cm.formatoptions !== undefined) {
  12805. op = $.extend(op,cm.formatoptions);
  12806. }
  12807. if (p.editOptions !== undefined) {
  12808. op.editOptions = p.editOptions;
  12809. }
  12810. if (p.delOptions !== undefined) {
  12811. op.delOptions = p.delOptions;
  12812. }
  12813. if ($tr.hasClass("jqgrid-new-row")){
  12814. op.extraparam[p.prmNames.oper] = p.prmNames.addoper;
  12815. }
  12816. var actop = {
  12817. keys: op.keys,
  12818. oneditfunc: op.onEdit,
  12819. successfunc: op.onSuccess,
  12820. url: op.url,
  12821. extraparam: op.extraparam,
  12822. aftersavefunc: saverow,
  12823. errorfunc: op.onError,
  12824. afterrestorefunc: restorerow,
  12825. restoreAfterError: op.restoreAfterError,
  12826. mtype: op.mtype
  12827. };
  12828. switch(act)
  12829. {
  12830. case 'edit':
  12831. $grid.jqGrid('editRow', rid, actop);
  12832. $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").hide();
  12833. $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").show();
  12834. $grid.triggerHandler("jqGridAfterGridComplete");
  12835. break;
  12836. case 'save':
  12837. if ($grid.jqGrid('saveRow', rid, actop)) {
  12838. $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show();
  12839. $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide();
  12840. $grid.triggerHandler("jqGridAfterGridComplete");
  12841. }
  12842. break;
  12843. case 'cancel' :
  12844. $grid.jqGrid('restoreRow', rid, restorerow);
  12845. $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show();
  12846. $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide();
  12847. $grid.triggerHandler("jqGridAfterGridComplete");
  12848. break;
  12849. case 'del':
  12850. $grid.jqGrid('delGridRow', rid, op.delOptions);
  12851. break;
  12852. case 'formedit':
  12853. $grid.jqGrid('setSelection', rid);
  12854. $grid.jqGrid('editGridRow', rid, op.editOptions);
  12855. break;
  12856. }
  12857. };
  12858. $.fn.fmatter.actions = function(cellval,opts) {
  12859. var op={keys:false, editbutton:true, delbutton:true, editformbutton: false},
  12860. rowid=opts.rowId, str="",ocl;
  12861. if(opts.colModel.formatoptions !== undefined) {
  12862. op = $.extend(op,opts.colModel.formatoptions);
  12863. }
  12864. if(rowid === undefined || $.fmatter.isEmpty(rowid)) {return "";}
  12865. if(op.editformbutton){
  12866. 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'); ";
  12867. 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>";
  12868. } else if(op.editbutton){
  12869. 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') ";
  12870. 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>";
  12871. }
  12872. if(op.delbutton) {
  12873. 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'); ";
  12874. 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>";
  12875. }
  12876. 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'); ";
  12877. 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>";
  12878. 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'); ";
  12879. 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>";
  12880. return "<div style='margin-left:8px;'>" + str + "</div>";
  12881. };
  12882. $.unformat = function (cellval,options,pos,cnt) {
  12883. // specific for jqGrid only
  12884. var ret, formatType = options.colModel.formatter,
  12885. op =options.colModel.formatoptions || {}, sep,
  12886. re = /([\.\*\_\'\(\)\{\}\+\?\\])/g,
  12887. unformatFunc = options.colModel.unformat||($.fn.fmatter[formatType] && $.fn.fmatter[formatType].unformat);
  12888. if(unformatFunc !== undefined && $.isFunction(unformatFunc) ) {
  12889. ret = unformatFunc.call(this, $(cellval).text(), options, cellval);
  12890. } else if(formatType !== undefined && $.fmatter.isString(formatType) ) {
  12891. var opts = $.jgrid.formatter || {}, stripTag;
  12892. switch(formatType) {
  12893. case 'integer' :
  12894. op = $.extend({},opts.integer,op);
  12895. sep = op.thousandsSeparator.replace(re,"\\$1");
  12896. stripTag = new RegExp(sep, "g");
  12897. ret = $(cellval).text().replace(stripTag,'');
  12898. break;
  12899. case 'number' :
  12900. op = $.extend({},opts.number,op);
  12901. sep = op.thousandsSeparator.replace(re,"\\$1");
  12902. stripTag = new RegExp(sep, "g");
  12903. ret = $(cellval).text().replace(stripTag,"").replace(op.decimalSeparator,'.');
  12904. break;
  12905. case 'currency':
  12906. op = $.extend({},opts.currency,op);
  12907. sep = op.thousandsSeparator.replace(re,"\\$1");
  12908. stripTag = new RegExp(sep, "g");
  12909. ret = $(cellval).text();
  12910. if (op.prefix && op.prefix.length) {
  12911. ret = ret.substr(op.prefix.length);
  12912. }
  12913. if (op.suffix && op.suffix.length) {
  12914. ret = ret.substr(0, ret.length - op.suffix.length);
  12915. }
  12916. ret = ret.replace(stripTag,'').replace(op.decimalSeparator,'.');
  12917. break;
  12918. case 'checkbox':
  12919. var cbv = (options.colModel.editoptions) ? options.colModel.editoptions.value.split(":") : ["Yes","No"];
  12920. ret = $('input',cellval).is(":checked") ? cbv[0] : cbv[1];
  12921. break;
  12922. case 'select' :
  12923. ret = $.unformat.select(cellval,options,pos,cnt);
  12924. break;
  12925. case 'actions':
  12926. return "";
  12927. default:
  12928. ret= $(cellval).text();
  12929. }
  12930. }
  12931. return ret !== undefined ? ret : cnt===true ? $(cellval).text() : $.jgrid.htmlDecode($(cellval).html());
  12932. };
  12933. $.unformat.select = function (cellval,options,pos,cnt) {
  12934. // Spacial case when we have local data and perform a sort
  12935. // cnt is set to true only in sortDataArray
  12936. var ret = [];
  12937. var cell = $(cellval).text();
  12938. if(cnt===true) {return cell;}
  12939. var op = $.extend({}, options.colModel.formatoptions !== undefined ? options.colModel.formatoptions: options.colModel.editoptions),
  12940. sep = op.separator === undefined ? ":" : op.separator,
  12941. delim = op.delimiter === undefined ? ";" : op.delimiter;
  12942. if(op.value){
  12943. var oSelect = op.value,
  12944. msl = op.multiple === true ? true : false,
  12945. scell = [], sv;
  12946. if(msl) {scell = cell.split(",");scell = $.map(scell,function(n){return $.trim(n);});}
  12947. if ($.fmatter.isString(oSelect)) {
  12948. var so = oSelect.split(delim), j=0, i;
  12949. for(i=0; i<so.length;i++){
  12950. sv = so[i].split(sep);
  12951. if(sv.length > 2 ) {
  12952. sv[1] = $.map(sv,function(n,i){if(i>0) {return n;}}).join(sep);
  12953. }
  12954. if(msl) {
  12955. if($.inArray(sv[1],scell)>-1) {
  12956. ret[j] = sv[0];
  12957. j++;
  12958. }
  12959. } else if($.trim(sv[1]) === $.trim(cell)) {
  12960. ret[0] = sv[0];
  12961. break;
  12962. }
  12963. }
  12964. } else if($.fmatter.isObject(oSelect) || $.isArray(oSelect) ){
  12965. if(!msl) {scell[0] = cell;}
  12966. ret = $.map(scell, function(n){
  12967. var rv;
  12968. $.each(oSelect, function(i,val){
  12969. if (val === n) {
  12970. rv = i;
  12971. return false;
  12972. }
  12973. });
  12974. if( rv !== undefined ) {return rv;}
  12975. });
  12976. }
  12977. return ret.join(", ");
  12978. }
  12979. return cell || "";
  12980. };
  12981. $.unformat.date = function (cellval, opts) {
  12982. var op = $.jgrid.formatter.date || {};
  12983. if(opts.formatoptions !== undefined) {
  12984. op = $.extend({},op,opts.formatoptions);
  12985. }
  12986. if(!$.fmatter.isEmpty(cellval)) {
  12987. return $.jgrid.parseDate(op.newformat,cellval,op.srcformat,op);
  12988. }
  12989. return $.fn.fmatter.defaultFormat(cellval, opts);
  12990. };
  12991. })(jQuery);
  12992. /*
  12993. The below work is licensed under Creative Commons GNU LGPL License.
  12994. Original work:
  12995. License: http://creativecommons.org/licenses/LGPL/2.1/
  12996. Author: Stefan Goessner/2006
  12997. Web: http://goessner.net/
  12998. Modifications made:
  12999. Version: 0.9-p5
  13000. Description: Restructured code, JSLint validated (no strict whitespaces),
  13001. added handling of empty arrays, empty strings, and int/floats values.
  13002. Author: Michael Schøler/2008-01-29
  13003. Web: http://michael.hinnerup.net/blog/2008/01/26/converting-json-to-xml-and-xml-to-json/
  13004. Description: json2xml added support to convert functions as CDATA
  13005. so it will be easy to write characters that cause some problems when convert
  13006. Author: Tony Tomov
  13007. */
  13008. /*global alert */
  13009. var xmlJsonClass = {
  13010. // Param "xml": Element or document DOM node.
  13011. // Param "tab": Tab or indent string for pretty output formatting omit or use empty string "" to supress.
  13012. // Returns: JSON string
  13013. xml2json: function(xml, tab) {
  13014. if (xml.nodeType === 9) {
  13015. // document node
  13016. xml = xml.documentElement;
  13017. }
  13018. var nws = this.removeWhite(xml);
  13019. var obj = this.toObj(nws);
  13020. var json = this.toJson(obj, xml.nodeName, "\t");
  13021. return "{\n" + tab + (tab ? json.replace(/\t/g, tab) : json.replace(/\t|\n/g, "")) + "\n}";
  13022. },
  13023. // Param "o": JavaScript object
  13024. // Param "tab": tab or indent string for pretty output formatting omit or use empty string "" to supress.
  13025. // Returns: XML string
  13026. json2xml: function(o, tab) {
  13027. var toXml = function(v, name, ind) {
  13028. var xml = "";
  13029. var i, n;
  13030. if (v instanceof Array) {
  13031. if (v.length === 0) {
  13032. xml += ind + "<"+name+">__EMPTY_ARRAY_</"+name+">\n";
  13033. }
  13034. else {
  13035. for (i = 0, n = v.length; i < n; i += 1) {
  13036. var sXml = ind + toXml(v[i], name, ind+"\t") + "\n";
  13037. xml += sXml;
  13038. }
  13039. }
  13040. }
  13041. else if (typeof(v) === "object") {
  13042. var hasChild = false;
  13043. xml += ind + "<" + name;
  13044. var m;
  13045. for (m in v) if (v.hasOwnProperty(m)) {
  13046. if (m.charAt(0) === "@") {
  13047. xml += " " + m.substr(1) + "=\"" + v[m].toString() + "\"";
  13048. }
  13049. else {
  13050. hasChild = true;
  13051. }
  13052. }
  13053. xml += hasChild ? ">" : "/>";
  13054. if (hasChild) {
  13055. for (m in v) if (v.hasOwnProperty(m)) {
  13056. if (m === "#text") {
  13057. xml += v[m];
  13058. }
  13059. else if (m === "#cdata") {
  13060. xml += "<![CDATA[" + v[m] + "]]>";
  13061. }
  13062. else if (m.charAt(0) !== "@") {
  13063. xml += toXml(v[m], m, ind+"\t");
  13064. }
  13065. }
  13066. xml += (xml.charAt(xml.length - 1) === "\n" ? ind : "") + "</" + name + ">";
  13067. }
  13068. }
  13069. else if (typeof(v) === "function") {
  13070. xml += ind + "<" + name + ">" + "<![CDATA[" + v + "]]>" + "</" + name + ">";
  13071. }
  13072. else {
  13073. if (v === undefined ) { v = ""; }
  13074. if (v.toString() === "\"\"" || v.toString().length === 0) {
  13075. xml += ind + "<" + name + ">__EMPTY_STRING_</" + name + ">";
  13076. }
  13077. else {
  13078. xml += ind + "<" + name + ">" + v.toString() + "</" + name + ">";
  13079. }
  13080. }
  13081. return xml;
  13082. };
  13083. var xml = "";
  13084. var m;
  13085. for (m in o) if (o.hasOwnProperty(m)) {
  13086. xml += toXml(o[m], m, "");
  13087. }
  13088. return tab ? xml.replace(/\t/g, tab) : xml.replace(/\t|\n/g, "");
  13089. },
  13090. // Internal methods
  13091. toObj: function(xml) {
  13092. var o = {};
  13093. var FuncTest = /function/i;
  13094. if (xml.nodeType === 1) {
  13095. // element node ..
  13096. if (xml.attributes.length) {
  13097. // element with attributes ..
  13098. var i;
  13099. for (i = 0; i < xml.attributes.length; i += 1) {
  13100. o["@" + xml.attributes[i].nodeName] = (xml.attributes[i].nodeValue || "").toString();
  13101. }
  13102. }
  13103. if (xml.firstChild) {
  13104. // element has child nodes ..
  13105. var textChild = 0, cdataChild = 0, hasElementChild = false;
  13106. var n;
  13107. for (n = xml.firstChild; n; n = n.nextSibling) {
  13108. if (n.nodeType === 1) {
  13109. hasElementChild = true;
  13110. }
  13111. else if (n.nodeType === 3 && n.nodeValue.match(/[^ \f\n\r\t\v]/)) {
  13112. // non-whitespace text
  13113. textChild += 1;
  13114. }
  13115. else if (n.nodeType === 4) {
  13116. // cdata section node
  13117. cdataChild += 1;
  13118. }
  13119. }
  13120. if (hasElementChild) {
  13121. if (textChild < 2 && cdataChild < 2) {
  13122. // structured element with evtl. a single text or/and cdata node ..
  13123. this.removeWhite(xml);
  13124. for (n = xml.firstChild; n; n = n.nextSibling) {
  13125. if (n.nodeType === 3) {
  13126. // text node
  13127. o["#text"] = this.escape(n.nodeValue);
  13128. }
  13129. else if (n.nodeType === 4) {
  13130. // cdata node
  13131. if (FuncTest.test(n.nodeValue)) {
  13132. o[n.nodeName] = [o[n.nodeName], n.nodeValue];
  13133. } else {
  13134. o["#cdata"] = this.escape(n.nodeValue);
  13135. }
  13136. }
  13137. else if (o[n.nodeName]) {
  13138. // multiple occurence of element ..
  13139. if (o[n.nodeName] instanceof Array) {
  13140. o[n.nodeName][o[n.nodeName].length] = this.toObj(n);
  13141. }
  13142. else {
  13143. o[n.nodeName] = [o[n.nodeName], this.toObj(n)];
  13144. }
  13145. }
  13146. else {
  13147. // first occurence of element ..
  13148. o[n.nodeName] = this.toObj(n);
  13149. }
  13150. }
  13151. }
  13152. else {
  13153. // mixed content
  13154. if (!xml.attributes.length) {
  13155. o = this.escape(this.innerXml(xml));
  13156. }
  13157. else {
  13158. o["#text"] = this.escape(this.innerXml(xml));
  13159. }
  13160. }
  13161. }
  13162. else if (textChild) {
  13163. // pure text
  13164. if (!xml.attributes.length) {
  13165. o = this.escape(this.innerXml(xml));
  13166. if (o === "__EMPTY_ARRAY_") {
  13167. o = "[]";
  13168. } else if (o === "__EMPTY_STRING_") {
  13169. o = "";
  13170. }
  13171. }
  13172. else {
  13173. o["#text"] = this.escape(this.innerXml(xml));
  13174. }
  13175. }
  13176. else if (cdataChild) {
  13177. // cdata
  13178. if (cdataChild > 1) {
  13179. o = this.escape(this.innerXml(xml));
  13180. }
  13181. else {
  13182. for (n = xml.firstChild; n; n = n.nextSibling) {
  13183. if(FuncTest.test(xml.firstChild.nodeValue)) {
  13184. o = xml.firstChild.nodeValue;
  13185. break;
  13186. } else {
  13187. o["#cdata"] = this.escape(n.nodeValue);
  13188. }
  13189. }
  13190. }
  13191. }
  13192. }
  13193. if (!xml.attributes.length && !xml.firstChild) {
  13194. o = null;
  13195. }
  13196. }
  13197. else if (xml.nodeType === 9) {
  13198. // document.node
  13199. o = this.toObj(xml.documentElement);
  13200. }
  13201. else {
  13202. alert("unhandled node type: " + xml.nodeType);
  13203. }
  13204. return o;
  13205. },
  13206. toJson: function(o, name, ind, wellform) {
  13207. if(wellform === undefined) wellform = true;
  13208. var json = name ? ("\"" + name + "\"") : "", tab = "\t", newline = "\n";
  13209. if(!wellform) {
  13210. tab= ""; newline= "";
  13211. }
  13212. if (o === "[]") {
  13213. json += (name ? ":[]" : "[]");
  13214. }
  13215. else if (o instanceof Array) {
  13216. var n, i, ar=[];
  13217. for (i = 0, n = o.length; i < n; i += 1) {
  13218. ar[i] = this.toJson(o[i], "", ind + tab, wellform);
  13219. }
  13220. json += (name ? ":[" : "[") + (ar.length > 1 ? (newline + ind + tab + ar.join(","+newline + ind + tab) + newline + ind) : ar.join("")) + "]";
  13221. }
  13222. else if (o === null) {
  13223. json += (name && ":") + "null";
  13224. }
  13225. else if (typeof(o) === "object") {
  13226. var arr = [], m;
  13227. for (m in o) {
  13228. if (o.hasOwnProperty(m)) {
  13229. arr[arr.length] = this.toJson(o[m], m, ind + tab, wellform);
  13230. }
  13231. }
  13232. json += (name ? ":{" : "{") + (arr.length > 1 ? (newline + ind + tab + arr.join(","+newline + ind + tab) + newline + ind) : arr.join("")) + "}";
  13233. }
  13234. else if (typeof(o) === "string") {
  13235. /*
  13236. var objRegExp = /(^-?\d+\.?\d*$)/;
  13237. var FuncTest = /function/i;
  13238. var os = o.toString();
  13239. if (objRegExp.test(os) || FuncTest.test(os) || os==="false" || os==="true") {
  13240. // int or float
  13241. json += (name && ":") + "\"" +os + "\"";
  13242. }
  13243. else {
  13244. */
  13245. json += (name && ":") + "\"" + o.replace(/\\/g,'\\\\').replace(/\"/g,'\\"') + "\"";
  13246. //}
  13247. }
  13248. else {
  13249. json += (name && ":") + o.toString();
  13250. }
  13251. return json;
  13252. },
  13253. innerXml: function(node) {
  13254. var s = "";
  13255. if ("innerHTML" in node) {
  13256. s = node.innerHTML;
  13257. }
  13258. else {
  13259. var asXml = function(n) {
  13260. var s = "", i;
  13261. if (n.nodeType === 1) {
  13262. s += "<" + n.nodeName;
  13263. for (i = 0; i < n.attributes.length; i += 1) {
  13264. s += " " + n.attributes[i].nodeName + "=\"" + (n.attributes[i].nodeValue || "").toString() + "\"";
  13265. }
  13266. if (n.firstChild) {
  13267. s += ">";
  13268. for (var c = n.firstChild; c; c = c.nextSibling) {
  13269. s += asXml(c);
  13270. }
  13271. s += "</" + n.nodeName + ">";
  13272. }
  13273. else {
  13274. s += "/>";
  13275. }
  13276. }
  13277. else if (n.nodeType === 3) {
  13278. s += n.nodeValue;
  13279. }
  13280. else if (n.nodeType === 4) {
  13281. s += "<![CDATA[" + n.nodeValue + "]]>";
  13282. }
  13283. return s;
  13284. };
  13285. for (var c = node.firstChild; c; c = c.nextSibling) {
  13286. s += asXml(c);
  13287. }
  13288. }
  13289. return s;
  13290. },
  13291. escape: function(txt) {
  13292. return txt.replace(/[\\]/g, "\\\\").replace(/[\"]/g, '\\"').replace(/[\n]/g, '\\n').replace(/[\r]/g, '\\r');
  13293. },
  13294. removeWhite: function(e) {
  13295. e.normalize();
  13296. var n;
  13297. for (n = e.firstChild; n; ) {
  13298. if (n.nodeType === 3) {
  13299. // text node
  13300. if (!n.nodeValue.match(/[^ \f\n\r\t\v]/)) {
  13301. // pure whitespace text node
  13302. var nxt = n.nextSibling;
  13303. e.removeChild(n);
  13304. n = nxt;
  13305. }
  13306. else {
  13307. n = n.nextSibling;
  13308. }
  13309. }
  13310. else if (n.nodeType === 1) {
  13311. // element node
  13312. this.removeWhite(n);
  13313. n = n.nextSibling;
  13314. }
  13315. else {
  13316. // any other node
  13317. n = n.nextSibling;
  13318. }
  13319. }
  13320. return e;
  13321. }
  13322. };