jquery.jqGrid.src.js 429 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554
  1. // ==ClosureCompiler==
  2. // @compilation_level SIMPLE_OPTIMIZATIONS
  3. /**
  4. * @license jqGrid 4.5.2 - jQuery Grid
  5. * Copyright (c) 2008, Tony Tomov, tony@trirand.com
  6. * Dual licensed under the MIT and GPL licenses
  7. * http://www.opensource.org/licenses/mit-license.php
  8. * http://www.gnu.org/licenses/gpl-2.0.html
  9. * Date: 2013-05-21
  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.5.2",
  19. htmlDecode : function(value){
  20. if(value && (value===' ' || value===' ' || (value.length===1 && value.charCodeAt(0)===160))) { return "";}
  21. return !value ? value : String(value).replace(/&gt;/g, ">").replace(/&lt;/g, "<").replace(/&quot;/g, '"').replace(/&amp;/g, "&");
  22. },
  23. htmlEncode : function (value){
  24. return !value ? value : String(value).replace(/&/g, "&amp;").replace(/\"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
  25. },
  26. format : function(format){ //jqgformat
  27. var args = $.makeArray(arguments).slice(1);
  28. if(format==null) { format = ""; }
  29. return format.replace(/\{(\d+)\}/g, function(m, i){
  30. return args[i];
  31. });
  32. },
  33. msie : navigator.appName === 'Microsoft Internet Explorer',
  34. msiever : function () {
  35. var rv = -1;
  36. var ua = navigator.userAgent;
  37. var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
  38. if (re.exec(ua) != null) {
  39. rv = parseFloat( RegExp.$1 );
  40. }
  41. return rv;
  42. },
  43. getCellIndex : function (cell) {
  44. var c = $(cell);
  45. if (c.is('tr')) { return -1; }
  46. c = (!c.is('td') && !c.is('th') ? c.closest("td,th") : c)[0];
  47. if ($.jgrid.msie) { return $.inArray(c, c.parentNode.cells); }
  48. return c.cellIndex;
  49. },
  50. stripHtml : function(v) {
  51. v = String(v);
  52. var regexp = /<("[^"]*"|'[^']*'|[^'">])*>/gi;
  53. if (v) {
  54. v = v.replace(regexp,"");
  55. return (v && v !== '&nbsp;' && v !== '&#160;') ? v.replace(/\"/g,"'") : "";
  56. }
  57. return v;
  58. },
  59. stripPref : function (pref, id) {
  60. var obj = $.type( pref );
  61. if( obj === "string" || obj === "number") {
  62. pref = String(pref);
  63. id = pref !== "" ? String(id).replace(String(pref), "") : id;
  64. }
  65. return id;
  66. },
  67. parse : function(jsonString) {
  68. var js = jsonString;
  69. if (js.substr(0,9) === "while(1);") { js = js.substr(9); }
  70. if (js.substr(0,2) === "/*") { js = js.substr(2,js.length-4); }
  71. if(!js) { js = "{}"; }
  72. return ($.jgrid.useJSON===true && typeof JSON === 'object' && typeof JSON.parse === 'function') ?
  73. JSON.parse(js) :
  74. eval('(' + js + ')');
  75. },
  76. parseDate : function(format, date, newformat, opts) {
  77. var token = /\\.|[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]/g,
  78. timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
  79. timezoneClip = /[^-+\dA-Z]/g,
  80. msDateRegExp = new RegExp("^\/Date\\((([-+])?[0-9]+)(([-+])([0-9]{2})([0-9]{2}))?\\)\/$"),
  81. msMatch = ((typeof date === 'string') ? date.match(msDateRegExp): null),
  82. pad = function (value, length) {
  83. value = String(value);
  84. length = parseInt(length,10) || 2;
  85. while (value.length < length) { value = '0' + value; }
  86. return value;
  87. },
  88. ts = {m : 1, d : 1, y : 1970, h : 0, i : 0, s : 0, u:0},
  89. timestamp=0, dM, k,hl,
  90. h12to24 = function(ampm, h){
  91. if (ampm === 0){ if (h === 12) { h = 0;} }
  92. else { if (h !== 12) { h += 12; } }
  93. return h;
  94. };
  95. if(opts === undefined) {
  96. opts = $.jgrid.formatter.date;
  97. }
  98. // old lang files
  99. if(opts.parseRe === undefined ) {
  100. opts.parseRe = /[Tt\\\/:_;.,\t\s-]/;
  101. }
  102. if( opts.masks.hasOwnProperty(format) ) { format = opts.masks[format]; }
  103. if(date && date != null) {
  104. if( !isNaN( date - 0 ) && String(format).toLowerCase() === "u") {
  105. //Unix timestamp
  106. timestamp = new Date( parseFloat(date)*1000 );
  107. } else if(date.constructor === Date) {
  108. timestamp = date;
  109. // Microsoft date format support
  110. } else if( msMatch !== null ) {
  111. timestamp = new Date(parseInt(msMatch[1], 10));
  112. if (msMatch[3]) {
  113. var offset = Number(msMatch[5]) * 60 + Number(msMatch[6]);
  114. offset *= ((msMatch[4] === '-') ? 1 : -1);
  115. offset -= timestamp.getTimezoneOffset();
  116. timestamp.setTime(Number(Number(timestamp) + (offset * 60 * 1000)));
  117. }
  118. } else {
  119. date = String(date).replace(/\\T/g,"T").replace(/\\t/,"t").split(opts.parseRe);
  120. format = format.replace(/\\T/g,"T").replace(/\\t/,"t").split(opts.parseRe);
  121. // parsing for month names
  122. for(k=0,hl=format.length;k<hl;k++){
  123. if(format[k] === 'M') {
  124. dM = $.inArray(date[k],opts.monthNames);
  125. if(dM !== -1 && dM < 12){date[k] = dM+1; ts.m = date[k];}
  126. }
  127. if(format[k] === 'F') {
  128. dM = $.inArray(date[k],opts.monthNames,12);
  129. if(dM !== -1 && dM > 11){date[k] = dM+1-12; ts.m = date[k];}
  130. }
  131. if(format[k] === 'a') {
  132. dM = $.inArray(date[k],opts.AmPm);
  133. if(dM !== -1 && dM < 2 && date[k] === opts.AmPm[dM]){
  134. date[k] = dM;
  135. ts.h = h12to24(date[k], ts.h);
  136. }
  137. }
  138. if(format[k] === 'A') {
  139. dM = $.inArray(date[k],opts.AmPm);
  140. if(dM !== -1 && dM > 1 && date[k] === opts.AmPm[dM]){
  141. date[k] = dM-2;
  142. ts.h = h12to24(date[k], ts.h);
  143. }
  144. }
  145. if (format[k] === 'g') {
  146. ts.h = parseInt(date[k], 10);
  147. }
  148. if(date[k] !== undefined) {
  149. ts[format[k].toLowerCase()] = parseInt(date[k],10);
  150. }
  151. }
  152. if(ts.f) {ts.m = ts.f;}
  153. if( ts.m === 0 && ts.y === 0 && ts.d === 0) {
  154. return "&#160;" ;
  155. }
  156. ts.m = parseInt(ts.m,10)-1;
  157. var ty = ts.y;
  158. if (ty >= 70 && ty <= 99) {ts.y = 1900+ts.y;}
  159. else if (ty >=0 && ty <=69) {ts.y= 2000+ts.y;}
  160. timestamp = new Date(ts.y, ts.m, ts.d, ts.h, ts.i, ts.s, ts.u);
  161. }
  162. } else {
  163. timestamp = new Date(ts.y, ts.m, ts.d, ts.h, ts.i, ts.s, ts.u);
  164. }
  165. if( newformat === undefined ) {
  166. return timestamp;
  167. }
  168. if( opts.masks.hasOwnProperty(newformat) ) {
  169. newformat = opts.masks[newformat];
  170. } else if ( !newformat ) {
  171. newformat = 'Y-m-d';
  172. }
  173. var
  174. G = timestamp.getHours(),
  175. i = timestamp.getMinutes(),
  176. j = timestamp.getDate(),
  177. n = timestamp.getMonth() + 1,
  178. o = timestamp.getTimezoneOffset(),
  179. s = timestamp.getSeconds(),
  180. u = timestamp.getMilliseconds(),
  181. w = timestamp.getDay(),
  182. Y = timestamp.getFullYear(),
  183. N = (w + 6) % 7 + 1,
  184. z = (new Date(Y, n - 1, j) - new Date(Y, 0, 1)) / 86400000,
  185. flags = {
  186. // Day
  187. d: pad(j),
  188. D: opts.dayNames[w],
  189. j: j,
  190. l: opts.dayNames[w + 7],
  191. N: N,
  192. S: opts.S(j),
  193. //j < 11 || j > 13 ? ['st', 'nd', 'rd', 'th'][Math.min((j - 1) % 10, 3)] : 'th',
  194. w: w,
  195. z: z,
  196. // Week
  197. 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),
  198. // Month
  199. F: opts.monthNames[n - 1 + 12],
  200. m: pad(n),
  201. M: opts.monthNames[n - 1],
  202. n: n,
  203. t: '?',
  204. // Year
  205. L: '?',
  206. o: '?',
  207. Y: Y,
  208. y: String(Y).substring(2),
  209. // Time
  210. a: G < 12 ? opts.AmPm[0] : opts.AmPm[1],
  211. A: G < 12 ? opts.AmPm[2] : opts.AmPm[3],
  212. B: '?',
  213. g: G % 12 || 12,
  214. G: G,
  215. h: pad(G % 12 || 12),
  216. H: pad(G),
  217. i: pad(i),
  218. s: pad(s),
  219. u: u,
  220. // Timezone
  221. e: '?',
  222. I: '?',
  223. O: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
  224. P: '?',
  225. T: (String(timestamp).match(timezone) || [""]).pop().replace(timezoneClip, ""),
  226. Z: '?',
  227. // Full Date/Time
  228. c: '?',
  229. r: '?',
  230. U: Math.floor(timestamp / 1000)
  231. };
  232. return newformat.replace(token, function ($0) {
  233. return flags.hasOwnProperty($0) ? flags[$0] : $0.substring(1);
  234. });
  235. },
  236. jqID : function(sid){
  237. return String(sid).replace(/[!"#$%&'()*+,.\/:; <=>?@\[\\\]\^`{|}~]/g,"\\$&");
  238. },
  239. guid : 1,
  240. uidPref: 'jqg',
  241. randId : function( prefix ) {
  242. return (prefix || $.jgrid.uidPref) + ($.jgrid.guid++);
  243. },
  244. getAccessor : function(obj, expr) {
  245. var ret,p,prm = [], i;
  246. if( typeof expr === 'function') { return expr(obj); }
  247. ret = obj[expr];
  248. if(ret===undefined) {
  249. try {
  250. if ( typeof expr === 'string' ) {
  251. prm = expr.split('.');
  252. }
  253. i = prm.length;
  254. if( i ) {
  255. ret = obj;
  256. while (ret && i--) {
  257. p = prm.shift();
  258. ret = ret[p];
  259. }
  260. }
  261. } catch (e) {}
  262. }
  263. return ret;
  264. },
  265. getXmlData: function (obj, expr, returnObj) {
  266. var ret, m = typeof expr === 'string' ? expr.match(/^(.*)\[(\w+)\]$/) : null;
  267. if (typeof expr === 'function') { return expr(obj); }
  268. if (m && m[2]) {
  269. // m[2] is the attribute selector
  270. // m[1] is an optional element selector
  271. // examples: "[id]", "rows[page]"
  272. return m[1] ? $(m[1], obj).attr(m[2]) : $(obj).attr(m[2]);
  273. }
  274. ret = $(expr, obj);
  275. if (returnObj) { return ret; }
  276. //$(expr, obj).filter(':last'); // we use ':last' to be more compatible with old version of jqGrid
  277. return ret.length > 0 ? $(ret).text() : undefined;
  278. },
  279. cellWidth : function () {
  280. var $testDiv = $("<div class='ui-jqgrid' style='left:10000px'><table class='ui-jqgrid-btable' style='width:5px;'><tr class='jqgrow'><td style='width:5px;'></td></tr></table></div>"),
  281. testCell = $testDiv.appendTo("body")
  282. .find("td")
  283. .width();
  284. $testDiv.remove();
  285. return testCell !== 5;
  286. },
  287. cell_width : true,
  288. ajaxOptions: {},
  289. from : function(source){
  290. // Original Author Hugo Bonacci
  291. // License MIT http://jlinq.codeplex.com/license
  292. var QueryObject=function(d,q){
  293. if(typeof d==="string"){
  294. d=$.data(d);
  295. }
  296. var self=this,
  297. _data=d,
  298. _usecase=true,
  299. _trim=false,
  300. _query=q,
  301. _stripNum = /[\$,%]/g,
  302. _lastCommand=null,
  303. _lastField=null,
  304. _orDepth=0,
  305. _negate=false,
  306. _queuedOperator="",
  307. _sorting=[],
  308. _useProperties=true;
  309. if(typeof d==="object"&&d.push) {
  310. if(d.length>0){
  311. if(typeof d[0]!=="object"){
  312. _useProperties=false;
  313. }else{
  314. _useProperties=true;
  315. }
  316. }
  317. }else{
  318. throw "data provides is not an array";
  319. }
  320. this._hasData=function(){
  321. return _data===null?false:_data.length===0?false:true;
  322. };
  323. this._getStr=function(s){
  324. var phrase=[];
  325. if(_trim){
  326. phrase.push("jQuery.trim(");
  327. }
  328. phrase.push("String("+s+")");
  329. if(_trim){
  330. phrase.push(")");
  331. }
  332. if(!_usecase){
  333. phrase.push(".toLowerCase()");
  334. }
  335. return phrase.join("");
  336. };
  337. this._strComp=function(val){
  338. if(typeof val==="string"){
  339. return".toString()";
  340. }
  341. return"";
  342. };
  343. this._group=function(f,u){
  344. return({field:f.toString(),unique:u,items:[]});
  345. };
  346. this._toStr=function(phrase){
  347. if(_trim){
  348. phrase=$.trim(phrase);
  349. }
  350. phrase=phrase.toString().replace(/\\/g,'\\\\').replace(/\"/g,'\\"');
  351. return _usecase ? phrase : phrase.toLowerCase();
  352. };
  353. this._funcLoop=function(func){
  354. var results=[];
  355. $.each(_data,function(i,v){
  356. results.push(func(v));
  357. });
  358. return results;
  359. };
  360. this._append=function(s){
  361. var i;
  362. if(_query===null){
  363. _query="";
  364. } else {
  365. _query+=_queuedOperator === "" ? " && " :_queuedOperator;
  366. }
  367. for (i=0;i<_orDepth;i++){
  368. _query+="(";
  369. }
  370. if(_negate){
  371. _query+="!";
  372. }
  373. _query+="("+s+")";
  374. _negate=false;
  375. _queuedOperator="";
  376. _orDepth=0;
  377. };
  378. this._setCommand=function(f,c){
  379. _lastCommand=f;
  380. _lastField=c;
  381. };
  382. this._resetNegate=function(){
  383. _negate=false;
  384. };
  385. this._repeatCommand=function(f,v){
  386. if(_lastCommand===null){
  387. return self;
  388. }
  389. if(f!==null&&v!==null){
  390. return _lastCommand(f,v);
  391. }
  392. if(_lastField===null){
  393. return _lastCommand(f);
  394. }
  395. if(!_useProperties){
  396. return _lastCommand(f);
  397. }
  398. return _lastCommand(_lastField,f);
  399. };
  400. this._equals=function(a,b){
  401. return(self._compare(a,b,1)===0);
  402. };
  403. this._compare=function(a,b,d){
  404. var toString = Object.prototype.toString;
  405. if( d === undefined) { d = 1; }
  406. if(a===undefined) { a = null; }
  407. if(b===undefined) { b = null; }
  408. if(a===null && b===null){
  409. return 0;
  410. }
  411. if(a===null&&b!==null){
  412. return 1;
  413. }
  414. if(a!==null&&b===null){
  415. return -1;
  416. }
  417. if (toString.call(a) === '[object Date]' && toString.call(b) === '[object Date]') {
  418. if (a < b) { return -d; }
  419. if (a > b) { return d; }
  420. return 0;
  421. }
  422. if(!_usecase && typeof a !== "number" && typeof b !== "number" ) {
  423. a=String(a);
  424. b=String(b);
  425. }
  426. if(a<b){return -d;}
  427. if(a>b){return d;}
  428. return 0;
  429. };
  430. this._performSort=function(){
  431. if(_sorting.length===0){return;}
  432. _data=self._doSort(_data,0);
  433. };
  434. this._doSort=function(d,q){
  435. var by=_sorting[q].by,
  436. dir=_sorting[q].dir,
  437. type = _sorting[q].type,
  438. dfmt = _sorting[q].datefmt;
  439. if(q===_sorting.length-1){
  440. return self._getOrder(d, by, dir, type, dfmt);
  441. }
  442. q++;
  443. var values=self._getGroup(d,by,dir,type,dfmt), results=[], i, j, sorted;
  444. for(i=0;i<values.length;i++){
  445. sorted=self._doSort(values[i].items,q);
  446. for(j=0;j<sorted.length;j++){
  447. results.push(sorted[j]);
  448. }
  449. }
  450. return results;
  451. };
  452. this._getOrder=function(data,by,dir,type, dfmt){
  453. var sortData=[],_sortData=[], newDir = dir==="a" ? 1 : -1, i,ab,j,
  454. findSortKey;
  455. if(type === undefined ) { type = "text"; }
  456. if (type === 'float' || type=== 'number' || type=== 'currency' || type=== 'numeric') {
  457. findSortKey = function($cell) {
  458. var key = parseFloat( String($cell).replace(_stripNum, ''));
  459. return isNaN(key) ? 0.00 : key;
  460. };
  461. } else if (type==='int' || type==='integer') {
  462. findSortKey = function($cell) {
  463. return $cell ? parseFloat(String($cell).replace(_stripNum, '')) : 0;
  464. };
  465. } else if(type === 'date' || type === 'datetime') {
  466. findSortKey = function($cell) {
  467. return $.jgrid.parseDate(dfmt,$cell).getTime();
  468. };
  469. } else if($.isFunction(type)) {
  470. findSortKey = type;
  471. } else {
  472. findSortKey = function($cell) {
  473. $cell = $cell ? $.trim(String($cell)) : "";
  474. return _usecase ? $cell : $cell.toLowerCase();
  475. };
  476. }
  477. $.each(data,function(i,v){
  478. ab = by!=="" ? $.jgrid.getAccessor(v,by) : v;
  479. if(ab === undefined) { ab = ""; }
  480. ab = findSortKey(ab, v);
  481. _sortData.push({ 'vSort': ab,'index':i});
  482. });
  483. _sortData.sort(function(a,b){
  484. a = a.vSort;
  485. b = b.vSort;
  486. return self._compare(a,b,newDir);
  487. });
  488. j=0;
  489. var nrec= data.length;
  490. // overhead, but we do not change the original data.
  491. while(j<nrec) {
  492. i = _sortData[j].index;
  493. sortData.push(data[i]);
  494. j++;
  495. }
  496. return sortData;
  497. };
  498. this._getGroup=function(data,by,dir,type, dfmt){
  499. var results=[],
  500. group=null,
  501. last=null, val;
  502. $.each(self._getOrder(data,by,dir,type, dfmt),function(i,v){
  503. val = $.jgrid.getAccessor(v, by);
  504. if(val == null) { val = ""; }
  505. if(!self._equals(last,val)){
  506. last=val;
  507. if(group !== null){
  508. results.push(group);
  509. }
  510. group=self._group(by,val);
  511. }
  512. group.items.push(v);
  513. });
  514. if(group !== null){
  515. results.push(group);
  516. }
  517. return results;
  518. };
  519. this.ignoreCase=function(){
  520. _usecase=false;
  521. return self;
  522. };
  523. this.useCase=function(){
  524. _usecase=true;
  525. return self;
  526. };
  527. this.trim=function(){
  528. _trim=true;
  529. return self;
  530. };
  531. this.noTrim=function(){
  532. _trim=false;
  533. return self;
  534. };
  535. this.execute=function(){
  536. var match=_query, results=[];
  537. if(match === null){
  538. return self;
  539. }
  540. $.each(_data,function(){
  541. if(eval(match)){results.push(this);}
  542. });
  543. _data=results;
  544. return self;
  545. };
  546. this.data=function(){
  547. return _data;
  548. };
  549. this.select=function(f){
  550. self._performSort();
  551. if(!self._hasData()){ return[]; }
  552. self.execute();
  553. if($.isFunction(f)){
  554. var results=[];
  555. $.each(_data,function(i,v){
  556. results.push(f(v));
  557. });
  558. return results;
  559. }
  560. return _data;
  561. };
  562. this.hasMatch=function(){
  563. if(!self._hasData()) { return false; }
  564. self.execute();
  565. return _data.length>0;
  566. };
  567. this.andNot=function(f,v,x){
  568. _negate=!_negate;
  569. return self.and(f,v,x);
  570. };
  571. this.orNot=function(f,v,x){
  572. _negate=!_negate;
  573. return self.or(f,v,x);
  574. };
  575. this.not=function(f,v,x){
  576. return self.andNot(f,v,x);
  577. };
  578. this.and=function(f,v,x){
  579. _queuedOperator=" && ";
  580. if(f===undefined){
  581. return self;
  582. }
  583. return self._repeatCommand(f,v,x);
  584. };
  585. this.or=function(f,v,x){
  586. _queuedOperator=" || ";
  587. if(f===undefined) { return self; }
  588. return self._repeatCommand(f,v,x);
  589. };
  590. this.orBegin=function(){
  591. _orDepth++;
  592. return self;
  593. };
  594. this.orEnd=function(){
  595. if (_query !== null){
  596. _query+=")";
  597. }
  598. return self;
  599. };
  600. this.isNot=function(f){
  601. _negate=!_negate;
  602. return self.is(f);
  603. };
  604. this.is=function(f){
  605. self._append('this.'+f);
  606. self._resetNegate();
  607. return self;
  608. };
  609. this._compareValues=function(func,f,v,how,t){
  610. var fld;
  611. if(_useProperties){
  612. fld='jQuery.jgrid.getAccessor(this,\''+f+'\')';
  613. }else{
  614. fld='this';
  615. }
  616. if(v===undefined) { v = null; }
  617. //var val=v===null?f:v,
  618. var val =v,
  619. swst = t.stype === undefined ? "text" : t.stype;
  620. if(v !== null) {
  621. switch(swst) {
  622. case 'int':
  623. case 'integer':
  624. val = (isNaN(Number(val)) || val==="") ? '0' : val; // To be fixed with more inteligent code
  625. fld = 'parseInt('+fld+',10)';
  626. val = 'parseInt('+val+',10)';
  627. break;
  628. case 'float':
  629. case 'number':
  630. case 'numeric':
  631. val = String(val).replace(_stripNum, '');
  632. val = (isNaN(Number(val)) || val==="") ? '0' : val; // To be fixed with more inteligent code
  633. fld = 'parseFloat('+fld+')';
  634. val = 'parseFloat('+val+')';
  635. break;
  636. case 'date':
  637. case 'datetime':
  638. val = String($.jgrid.parseDate(t.newfmt || 'Y-m-d',val).getTime());
  639. fld = 'jQuery.jgrid.parseDate("'+t.srcfmt+'",'+fld+').getTime()';
  640. break;
  641. default :
  642. fld=self._getStr(fld);
  643. val=self._getStr('"'+self._toStr(val)+'"');
  644. }
  645. }
  646. self._append(fld+' '+how+' '+val);
  647. self._setCommand(func,f);
  648. self._resetNegate();
  649. return self;
  650. };
  651. this.equals=function(f,v,t){
  652. return self._compareValues(self.equals,f,v,"==",t);
  653. };
  654. this.notEquals=function(f,v,t){
  655. return self._compareValues(self.equals,f,v,"!==",t);
  656. };
  657. this.isNull = function(f,v,t){
  658. return self._compareValues(self.equals,f,null,"===",t);
  659. };
  660. this.greater=function(f,v,t){
  661. return self._compareValues(self.greater,f,v,">",t);
  662. };
  663. this.less=function(f,v,t){
  664. return self._compareValues(self.less,f,v,"<",t);
  665. };
  666. this.greaterOrEquals=function(f,v,t){
  667. return self._compareValues(self.greaterOrEquals,f,v,">=",t);
  668. };
  669. this.lessOrEquals=function(f,v,t){
  670. return self._compareValues(self.lessOrEquals,f,v,"<=",t);
  671. };
  672. this.startsWith=function(f,v){
  673. var val = (v==null) ? f: v,
  674. length=_trim ? $.trim(val.toString()).length : val.toString().length;
  675. if(_useProperties){
  676. self._append(self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.substr(0,'+length+') == '+self._getStr('"'+self._toStr(v)+'"'));
  677. }else{
  678. length=_trim?$.trim(v.toString()).length:v.toString().length;
  679. self._append(self._getStr('this')+'.substr(0,'+length+') == '+self._getStr('"'+self._toStr(f)+'"'));
  680. }
  681. self._setCommand(self.startsWith,f);
  682. self._resetNegate();
  683. return self;
  684. };
  685. this.endsWith=function(f,v){
  686. var val = (v==null) ? f: v,
  687. length=_trim ? $.trim(val.toString()).length:val.toString().length;
  688. if(_useProperties){
  689. self._append(self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.substr('+self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.length-'+length+','+length+') == "'+self._toStr(v)+'"');
  690. } else {
  691. self._append(self._getStr('this')+'.substr('+self._getStr('this')+'.length-"'+self._toStr(f)+'".length,"'+self._toStr(f)+'".length) == "'+self._toStr(f)+'"');
  692. }
  693. self._setCommand(self.endsWith,f);self._resetNegate();
  694. return self;
  695. };
  696. this.contains=function(f,v){
  697. if(_useProperties){
  698. self._append(self._getStr('jQuery.jgrid.getAccessor(this,\''+f+'\')')+'.indexOf("'+self._toStr(v)+'",0) > -1');
  699. }else{
  700. self._append(self._getStr('this')+'.indexOf("'+self._toStr(f)+'",0) > -1');
  701. }
  702. self._setCommand(self.contains,f);
  703. self._resetNegate();
  704. return self;
  705. };
  706. this.groupBy=function(by,dir,type, datefmt){
  707. if(!self._hasData()){
  708. return null;
  709. }
  710. return self._getGroup(_data,by,dir,type, datefmt);
  711. };
  712. this.orderBy=function(by,dir,stype, dfmt){
  713. dir = dir == null ? "a" :$.trim(dir.toString().toLowerCase());
  714. if(stype == null) { stype = "text"; }
  715. if(dfmt == null) { dfmt = "Y-m-d"; }
  716. if(dir==="desc"||dir==="descending"){dir="d";}
  717. if(dir==="asc"||dir==="ascending"){dir="a";}
  718. _sorting.push({by:by,dir:dir,type:stype, datefmt: dfmt});
  719. return self;
  720. };
  721. return self;
  722. };
  723. return new QueryObject(source,null);
  724. },
  725. getMethod: function (name) {
  726. return this.getAccessor($.fn.jqGrid, name);
  727. },
  728. extend : function(methods) {
  729. $.extend($.fn.jqGrid,methods);
  730. if (!this.no_legacy_api) {
  731. $.fn.extend(methods);
  732. }
  733. }
  734. });
  735. $.fn.jqGrid = function( pin ) {
  736. if (typeof pin === 'string') {
  737. var fn = $.jgrid.getMethod(pin);
  738. if (!fn) {
  739. throw ("jqGrid - No such method: " + pin);
  740. }
  741. var args = $.makeArray(arguments).slice(1);
  742. return fn.apply(this,args);
  743. }
  744. return this.each( function() {
  745. if(this.grid) {return;}
  746. var p = $.extend(true,{
  747. url: "",
  748. height: 150,
  749. page: 1,
  750. rowNum: 20,
  751. rowTotal : null,
  752. records: 0,
  753. pager: "",
  754. pgbuttons: true,
  755. pginput: true,
  756. colModel: [],
  757. rowList: [],
  758. colNames: [],
  759. sortorder: "asc",
  760. sortname: "",
  761. datatype: "xml",
  762. mtype: "GET",
  763. altRows: false,
  764. selarrrow: [],
  765. savedRow: [],
  766. shrinkToFit: true,
  767. xmlReader: {},
  768. jsonReader: {},
  769. subGrid: false,
  770. subGridModel :[],
  771. reccount: 0,
  772. lastpage: 0,
  773. lastsort: 0,
  774. selrow: null,
  775. beforeSelectRow: null,
  776. onSelectRow: null,
  777. onSortCol: null,
  778. ondblClickRow: null,
  779. onRightClickRow: null,
  780. onPaging: null,
  781. onSelectAll: null,
  782. onInitGrid : null,
  783. loadComplete: null,
  784. gridComplete: null,
  785. loadError: null,
  786. loadBeforeSend: null,
  787. afterInsertRow: null,
  788. beforeRequest: null,
  789. beforeProcessing : null,
  790. onHeaderClick: null,
  791. viewrecords: false,
  792. loadonce: false,
  793. multiselect: false,
  794. multikey: false,
  795. editurl: null,
  796. search: false,
  797. caption: "",
  798. hidegrid: true,
  799. hiddengrid: false,
  800. postData: {},
  801. userData: {},
  802. treeGrid : false,
  803. treeGridModel : 'nested',
  804. treeReader : {},
  805. treeANode : -1,
  806. ExpandColumn: null,
  807. tree_root_level : 0,
  808. 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"},
  809. forceFit : false,
  810. gridstate : "visible",
  811. cellEdit: false,
  812. cellsubmit: "remote",
  813. nv:0,
  814. loadui: "enable",
  815. toolbar: [false,""],
  816. scroll: false,
  817. multiboxonly : false,
  818. deselectAfterSort : true,
  819. scrollrows : false,
  820. autowidth: false,
  821. scrollOffset :18,
  822. cellLayout: 5,
  823. subGridWidth: 20,
  824. multiselectWidth: 20,
  825. gridview: false,
  826. rownumWidth: 25,
  827. rownumbers : false,
  828. pagerpos: 'center',
  829. recordpos: 'right',
  830. footerrow : false,
  831. userDataOnFooter : false,
  832. hoverrows : true,
  833. altclass : 'ui-priority-secondary',
  834. viewsortcols : [false,'vertical',true],
  835. resizeclass : '',
  836. autoencode : false,
  837. remapColumns : [],
  838. ajaxGridOptions :{},
  839. direction : "ltr",
  840. toppager: false,
  841. headertitles: false,
  842. scrollTimeout: 40,
  843. data : [],
  844. _index : {},
  845. grouping : false,
  846. groupingView : {groupField:[],groupOrder:[], groupText:[],groupColumnShow:[],groupSummary:[], showSummaryOnHide: false, sortitems:[], sortnames:[], summary:[],summaryval:[], plusicon: 'ui-icon-circlesmall-plus', minusicon: 'ui-icon-circlesmall-minus', displayField: []},
  847. ignoreCase : false,
  848. cmTemplate : {},
  849. idPrefix : "",
  850. multiSort : false
  851. }, $.jgrid.defaults, pin || {});
  852. var ts= this, grid={
  853. headers:[],
  854. cols:[],
  855. footers: [],
  856. dragStart: function(i,x,y) {
  857. this.resizing = { idx: i, startX: x.clientX, sOL : y[0]};
  858. this.hDiv.style.cursor = "col-resize";
  859. this.curGbox = $("#rs_m"+$.jgrid.jqID(p.id),"#gbox_"+$.jgrid.jqID(p.id));
  860. this.curGbox.css({display:"block",left:y[0],top:y[1],height:y[2]});
  861. $(ts).triggerHandler("jqGridResizeStart", [x, i]);
  862. if($.isFunction(p.resizeStart)) { p.resizeStart.call(ts,x,i); }
  863. document.onselectstart=function(){return false;};
  864. },
  865. dragMove: function(x) {
  866. if(this.resizing) {
  867. var diff = x.clientX-this.resizing.startX,
  868. h = this.headers[this.resizing.idx],
  869. newWidth = p.direction === "ltr" ? h.width + diff : h.width - diff, hn, nWn;
  870. if(newWidth > 33) {
  871. this.curGbox.css({left:this.resizing.sOL+diff});
  872. if(p.forceFit===true ){
  873. hn = this.headers[this.resizing.idx+p.nv];
  874. nWn = p.direction === "ltr" ? hn.width - diff : hn.width + diff;
  875. if(nWn >33) {
  876. h.newWidth = newWidth;
  877. hn.newWidth = nWn;
  878. }
  879. } else {
  880. this.newWidth = p.direction === "ltr" ? p.tblwidth+diff : p.tblwidth-diff;
  881. h.newWidth = newWidth;
  882. }
  883. }
  884. }
  885. },
  886. dragEnd: function() {
  887. this.hDiv.style.cursor = "default";
  888. if(this.resizing) {
  889. var idx = this.resizing.idx,
  890. nw = this.headers[idx].newWidth || this.headers[idx].width;
  891. nw = parseInt(nw,10);
  892. this.resizing = false;
  893. $("#rs_m"+$.jgrid.jqID(p.id)).css("display","none");
  894. p.colModel[idx].width = nw;
  895. this.headers[idx].width = nw;
  896. this.headers[idx].el.style.width = nw + "px";
  897. this.cols[idx].style.width = nw+"px";
  898. if(this.footers.length>0) {this.footers[idx].style.width = nw+"px";}
  899. if(p.forceFit===true){
  900. nw = this.headers[idx+p.nv].newWidth || this.headers[idx+p.nv].width;
  901. this.headers[idx+p.nv].width = nw;
  902. this.headers[idx+p.nv].el.style.width = nw + "px";
  903. this.cols[idx+p.nv].style.width = nw+"px";
  904. if(this.footers.length>0) {this.footers[idx+p.nv].style.width = nw+"px";}
  905. p.colModel[idx+p.nv].width = nw;
  906. } else {
  907. p.tblwidth = this.newWidth || p.tblwidth;
  908. $('table:first',this.bDiv).css("width",p.tblwidth+"px");
  909. $('table:first',this.hDiv).css("width",p.tblwidth+"px");
  910. this.hDiv.scrollLeft = this.bDiv.scrollLeft;
  911. if(p.footerrow) {
  912. $('table:first',this.sDiv).css("width",p.tblwidth+"px");
  913. this.sDiv.scrollLeft = this.bDiv.scrollLeft;
  914. }
  915. }
  916. $(ts).triggerHandler("jqGridResizeStop", [nw, idx]);
  917. if($.isFunction(p.resizeStop)) { p.resizeStop.call(ts,nw,idx); }
  918. }
  919. this.curGbox = null;
  920. document.onselectstart=function(){return true;};
  921. },
  922. populateVisible: function() {
  923. if (grid.timer) { clearTimeout(grid.timer); }
  924. grid.timer = null;
  925. var dh = $(grid.bDiv).height();
  926. if (!dh) { return; }
  927. var table = $("table:first", grid.bDiv);
  928. var rows, rh;
  929. if(table[0].rows.length) {
  930. try {
  931. rows = table[0].rows[1];
  932. rh = rows ? $(rows).outerHeight() || grid.prevRowHeight : grid.prevRowHeight;
  933. } catch (pv) {
  934. rh = grid.prevRowHeight;
  935. }
  936. }
  937. if (!rh) { return; }
  938. grid.prevRowHeight = rh;
  939. var rn = p.rowNum;
  940. var scrollTop = grid.scrollTop = grid.bDiv.scrollTop;
  941. var ttop = Math.round(table.position().top) - scrollTop;
  942. var tbot = ttop + table.height();
  943. var div = rh * rn;
  944. var page, npage, empty;
  945. if ( tbot < dh && ttop <= 0 &&
  946. (p.lastpage===undefined||parseInt((tbot + scrollTop + div - 1) / div,10) <= p.lastpage))
  947. {
  948. npage = parseInt((dh - tbot + div - 1) / div,10);
  949. if (tbot >= 0 || npage < 2 || p.scroll === true) {
  950. page = Math.round((tbot + scrollTop) / div) + 1;
  951. ttop = -1;
  952. } else {
  953. ttop = 1;
  954. }
  955. }
  956. if (ttop > 0) {
  957. page = parseInt(scrollTop / div,10) + 1;
  958. npage = parseInt((scrollTop + dh) / div,10) + 2 - page;
  959. empty = true;
  960. }
  961. if (npage) {
  962. if (p.lastpage && (page > p.lastpage || p.lastpage===1 || (page === p.page && page===p.lastpage)) ) {
  963. return;
  964. }
  965. if (grid.hDiv.loading) {
  966. grid.timer = setTimeout(grid.populateVisible, p.scrollTimeout);
  967. } else {
  968. p.page = page;
  969. if (empty) {
  970. grid.selectionPreserver(table[0]);
  971. grid.emptyRows.call(table[0], false, false);
  972. }
  973. grid.populate(npage);
  974. }
  975. }
  976. },
  977. scrollGrid: function( e ) {
  978. if(p.scroll) {
  979. var scrollTop = grid.bDiv.scrollTop;
  980. if(grid.scrollTop === undefined) { grid.scrollTop = 0; }
  981. if (scrollTop !== grid.scrollTop) {
  982. grid.scrollTop = scrollTop;
  983. if (grid.timer) { clearTimeout(grid.timer); }
  984. grid.timer = setTimeout(grid.populateVisible, p.scrollTimeout);
  985. }
  986. }
  987. grid.hDiv.scrollLeft = grid.bDiv.scrollLeft;
  988. if(p.footerrow) {
  989. grid.sDiv.scrollLeft = grid.bDiv.scrollLeft;
  990. }
  991. if( e ) { e.stopPropagation(); }
  992. },
  993. selectionPreserver : function(ts) {
  994. var p = ts.p,
  995. sr = p.selrow, sra = p.selarrrow ? $.makeArray(p.selarrrow) : null,
  996. left = ts.grid.bDiv.scrollLeft,
  997. restoreSelection = function() {
  998. var i;
  999. p.selrow = null;
  1000. p.selarrrow = [];
  1001. if(p.multiselect && sra && sra.length>0) {
  1002. for(i=0;i<sra.length;i++){
  1003. if (sra[i] !== sr) {
  1004. $(ts).jqGrid("setSelection",sra[i],false, null);
  1005. }
  1006. }
  1007. }
  1008. if (sr) {
  1009. $(ts).jqGrid("setSelection",sr,false,null);
  1010. }
  1011. ts.grid.bDiv.scrollLeft = left;
  1012. $(ts).unbind('.selectionPreserver', restoreSelection);
  1013. };
  1014. $(ts).bind('jqGridGridComplete.selectionPreserver', restoreSelection);
  1015. }
  1016. };
  1017. if(this.tagName.toUpperCase() !== 'TABLE') {
  1018. alert("Element is not a table");
  1019. return;
  1020. }
  1021. if(document.documentMode !== undefined ) { // IE only
  1022. if(document.documentMode <= 5) {
  1023. alert("Grid can not be used in this ('quirks') mode!");
  1024. return;
  1025. }
  1026. }
  1027. $(this).empty().attr("tabindex","0");
  1028. this.p = p ;
  1029. this.p.useProp = !!$.fn.prop;
  1030. var i, dir;
  1031. if(this.p.colNames.length === 0) {
  1032. for (i=0;i<this.p.colModel.length;i++){
  1033. this.p.colNames[i] = this.p.colModel[i].label || this.p.colModel[i].name;
  1034. }
  1035. }
  1036. if( this.p.colNames.length !== this.p.colModel.length ) {
  1037. alert($.jgrid.errors.model);
  1038. return;
  1039. }
  1040. var gv = $("<div class='ui-jqgrid-view'></div>"),
  1041. isMSIE = $.jgrid.msie;
  1042. ts.p.direction = $.trim(ts.p.direction.toLowerCase());
  1043. if($.inArray(ts.p.direction,["ltr","rtl"]) === -1) { ts.p.direction = "ltr"; }
  1044. dir = ts.p.direction;
  1045. $(gv).insertBefore(this);
  1046. $(this).removeClass("scroll").appendTo(gv);
  1047. var eg = $("<div class='ui-jqgrid ui-widget ui-widget-content ui-corner-all'></div>");
  1048. $(eg).attr({"id" : "gbox_"+this.id,"dir":dir}).insertBefore(gv);
  1049. $(gv).attr("id","gview_"+this.id).appendTo(eg);
  1050. $("<div class='ui-widget-overlay jqgrid-overlay' id='lui_"+this.id+"'></div>").insertBefore(gv);
  1051. $("<div class='loading ui-state-default ui-state-active' id='load_"+this.id+"'>"+this.p.loadtext+"</div>").insertBefore(gv);
  1052. $(this).attr({cellspacing:"0",cellpadding:"0",border:"0","role":"grid","aria-multiselectable":!!this.p.multiselect,"aria-labelledby":"gbox_"+this.id});
  1053. var sortkeys = ["shiftKey","altKey","ctrlKey"],
  1054. intNum = function(val,defval) {
  1055. val = parseInt(val,10);
  1056. if (isNaN(val)) { return defval || 0;}
  1057. return val;
  1058. },
  1059. formatCol = function (pos, rowInd, tv, rawObject, rowId, rdata){
  1060. var cm = ts.p.colModel[pos],
  1061. ral = cm.align, result="style=\"", clas = cm.classes, nm = cm.name, celp, acp=[];
  1062. if(ral) { result += "text-align:"+ral+";"; }
  1063. if(cm.hidden===true) { result += "display:none;"; }
  1064. if(rowInd===0) {
  1065. result += "width: "+grid.headers[pos].width+"px;";
  1066. } else if (cm.cellattr && $.isFunction(cm.cellattr))
  1067. {
  1068. celp = cm.cellattr.call(ts, rowId, tv, rawObject, cm, rdata);
  1069. if(celp && typeof celp === "string") {
  1070. celp = celp.replace(/style/i,'style').replace(/title/i,'title');
  1071. if(celp.indexOf('title') > -1) { cm.title=false;}
  1072. if(celp.indexOf('class') > -1) { clas = undefined;}
  1073. acp = celp.split(/[^-]style/);
  1074. if(acp.length === 2 ) {
  1075. acp[1] = $.trim(acp[1].replace("=",""));
  1076. if(acp[1].indexOf("'") === 0 || acp[1].indexOf('"') === 0) {
  1077. acp[1] = acp[1].substring(1);
  1078. }
  1079. result += acp[1].replace(/'/gi,'"');
  1080. } else {
  1081. result += "\"";
  1082. }
  1083. }
  1084. }
  1085. if(!acp.length) { acp[0] = ""; result += "\"";}
  1086. result += (clas !== undefined ? (" class=\""+clas+"\"") :"") + ((cm.title && tv) ? (" title=\""+$.jgrid.stripHtml(tv)+"\"") :"");
  1087. result += " aria-describedby=\""+ts.p.id+"_"+nm+"\"";
  1088. return result + acp[0];
  1089. },
  1090. cellVal = function (val) {
  1091. return val == null || val === "" ? "&#160;" : (ts.p.autoencode ? $.jgrid.htmlEncode(val) : String(val));
  1092. },
  1093. formatter = function (rowId, cellval , colpos, rwdat, _act){
  1094. var cm = ts.p.colModel[colpos],v;
  1095. if(cm.formatter !== undefined) {
  1096. rowId = String(ts.p.idPrefix) !== "" ? $.jgrid.stripPref(ts.p.idPrefix, rowId) : rowId;
  1097. var opts= {rowId: rowId, colModel:cm, gid:ts.p.id, pos:colpos };
  1098. if($.isFunction( cm.formatter ) ) {
  1099. v = cm.formatter.call(ts,cellval,opts,rwdat,_act);
  1100. } else if($.fmatter){
  1101. v = $.fn.fmatter.call(ts,cm.formatter,cellval,opts,rwdat,_act);
  1102. } else {
  1103. v = cellVal(cellval);
  1104. }
  1105. } else {
  1106. v = cellVal(cellval);
  1107. }
  1108. return v;
  1109. },
  1110. addCell = function(rowId,cell,pos,irow, srvr, rdata) {
  1111. var v,prp;
  1112. v = formatter(rowId,cell,pos,srvr,'add');
  1113. prp = formatCol( pos,irow, v, srvr, rowId, rdata);
  1114. return "<td role=\"gridcell\" "+prp+">"+v+"</td>";
  1115. },
  1116. addMulti = function(rowid,pos,irow,checked){
  1117. var v = "<input role=\"checkbox\" type=\"checkbox\""+" id=\"jqg_"+ts.p.id+"_"+rowid+"\" class=\"cbox\" name=\"jqg_"+ts.p.id+"_"+rowid+"\"" + (checked ? "checked=\"checked\"" : "")+"/>",
  1118. prp = formatCol( pos,irow,'',null, rowid, true);
  1119. return "<td role=\"gridcell\" "+prp+">"+v+"</td>";
  1120. },
  1121. addRowNum = function (pos,irow,pG,rN) {
  1122. var v = (parseInt(pG,10)-1)*parseInt(rN,10)+1+irow,
  1123. prp = formatCol( pos,irow,v, null, irow, true);
  1124. return "<td role=\"gridcell\" class=\"ui-state-default jqgrid-rownum\" "+prp+">"+v+"</td>";
  1125. },
  1126. reader = function (datatype) {
  1127. var field, f=[], j=0, i;
  1128. for(i =0; i<ts.p.colModel.length; i++){
  1129. field = ts.p.colModel[i];
  1130. if (field.name !== 'cb' && field.name !=='subgrid' && field.name !=='rn') {
  1131. f[j]= datatype === "local" ?
  1132. field.name :
  1133. ( (datatype==="xml" || datatype === "xmlstring") ? field.xmlmap || field.name : field.jsonmap || field.name );
  1134. j++;
  1135. }
  1136. }
  1137. return f;
  1138. },
  1139. orderedCols = function (offset) {
  1140. var order = ts.p.remapColumns;
  1141. if (!order || !order.length) {
  1142. order = $.map(ts.p.colModel, function(v,i) { return i; });
  1143. }
  1144. if (offset) {
  1145. order = $.map(order, function(v) { return v<offset?null:v-offset; });
  1146. }
  1147. return order;
  1148. },
  1149. emptyRows = function (scroll, locdata) {
  1150. var firstrow;
  1151. if (this.p.deepempty) {
  1152. $(this.rows).slice(1).remove();
  1153. } else {
  1154. firstrow = this.rows.length > 0 ? this.rows[0] : null;
  1155. $(this.firstChild).empty().append(firstrow);
  1156. }
  1157. if (scroll && this.p.scroll) {
  1158. $(this.grid.bDiv.firstChild).css({height: "auto"});
  1159. $(this.grid.bDiv.firstChild.firstChild).css({height: 0, display: "none"});
  1160. if (this.grid.bDiv.scrollTop !== 0) {
  1161. this.grid.bDiv.scrollTop = 0;
  1162. }
  1163. }
  1164. if(locdata === true && this.p.treeGrid) {
  1165. this.p.data = []; this.p._index = {};
  1166. }
  1167. },
  1168. refreshIndex = function() {
  1169. var datalen = ts.p.data.length, idname, i, val,
  1170. ni = ts.p.rownumbers===true ? 1 :0,
  1171. gi = ts.p.multiselect ===true ? 1 :0,
  1172. si = ts.p.subGrid===true ? 1 :0;
  1173. if(ts.p.keyIndex === false || ts.p.loadonce === true) {
  1174. idname = ts.p.localReader.id;
  1175. } else {
  1176. idname = ts.p.colModel[ts.p.keyIndex+gi+si+ni].name;
  1177. }
  1178. for(i =0;i < datalen; i++) {
  1179. val = $.jgrid.getAccessor(ts.p.data[i],idname);
  1180. if (val === undefined) { val=String(i+1); }
  1181. ts.p._index[val] = i;
  1182. }
  1183. },
  1184. constructTr = function(id, hide, altClass, rd, cur, selected) {
  1185. var tabindex = '-1', restAttr = '', attrName, style = hide ? 'display:none;' : '',
  1186. classes = 'ui-widget-content jqgrow ui-row-' + ts.p.direction + (altClass ? ' ' + altClass : '') + (selected ? ' ui-state-highlight' : ''),
  1187. rowAttrObj = $(ts).triggerHandler("jqGridRowAttr", [rd, cur, id]);
  1188. if( typeof rowAttrObj !== "object" ) {
  1189. rowAttrObj = $.isFunction(ts.p.rowattr) ? ts.p.rowattr.call(ts, rd, cur, id) :{};
  1190. }
  1191. if(!$.isEmptyObject( rowAttrObj )) {
  1192. if (rowAttrObj.hasOwnProperty("id")) {
  1193. id = rowAttrObj.id;
  1194. delete rowAttrObj.id;
  1195. }
  1196. if (rowAttrObj.hasOwnProperty("tabindex")) {
  1197. tabindex = rowAttrObj.tabindex;
  1198. delete rowAttrObj.tabindex;
  1199. }
  1200. if (rowAttrObj.hasOwnProperty("style")) {
  1201. style += rowAttrObj.style;
  1202. delete rowAttrObj.style;
  1203. }
  1204. if (rowAttrObj.hasOwnProperty("class")) {
  1205. classes += ' ' + rowAttrObj['class'];
  1206. delete rowAttrObj['class'];
  1207. }
  1208. // dot't allow to change role attribute
  1209. try { delete rowAttrObj.role; } catch(ra){}
  1210. for (attrName in rowAttrObj) {
  1211. if (rowAttrObj.hasOwnProperty(attrName)) {
  1212. restAttr += ' ' + attrName + '=' + rowAttrObj[attrName];
  1213. }
  1214. }
  1215. }
  1216. return '<tr role="row" id="' + id + '" tabindex="' + tabindex + '" class="' + classes + '"' +
  1217. (style === '' ? '' : ' style="' + style + '"') + restAttr + '>';
  1218. },
  1219. addXmlData = function (xml,t, rcnt, more, adjust) {
  1220. var startReq = new Date(),
  1221. locdata = (ts.p.datatype !== "local" && ts.p.loadonce) || ts.p.datatype === "xmlstring",
  1222. xmlid = "_id_", xmlRd = ts.p.xmlReader,
  1223. frd = ts.p.datatype === "local" ? "local" : "xml";
  1224. if(locdata) {
  1225. ts.p.data = [];
  1226. ts.p._index = {};
  1227. ts.p.localReader.id = xmlid;
  1228. }
  1229. ts.p.reccount = 0;
  1230. if($.isXMLDoc(xml)) {
  1231. if(ts.p.treeANode===-1 && !ts.p.scroll) {
  1232. emptyRows.call(ts, false, true);
  1233. rcnt=1;
  1234. } else { rcnt = rcnt > 1 ? rcnt :1; }
  1235. } else { return; }
  1236. 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;
  1237. if(ts.p.subGrid===true) {
  1238. si = 1;
  1239. addSubGridCell = $.jgrid.getMethod("addSubGridCell");
  1240. }
  1241. if(!xmlRd.repeatitems) {f = reader(frd);}
  1242. if( ts.p.keyIndex===false) {
  1243. idn = $.isFunction( xmlRd.id ) ? xmlRd.id.call(ts, xml) : xmlRd.id;
  1244. } else {
  1245. idn = ts.p.keyIndex;
  1246. }
  1247. if(f.length>0 && !isNaN(idn)) {
  1248. if (ts.p.remapColumns && ts.p.remapColumns.length) {
  1249. idn = $.inArray(idn, ts.p.remapColumns);
  1250. }
  1251. idn=f[idn];
  1252. }
  1253. if( String(idn).indexOf("[") === -1 ) {
  1254. if (f.length) {
  1255. getId = function( trow, k) {return $(idn,trow).text() || k;};
  1256. } else {
  1257. getId = function( trow, k) {return $(xmlRd.cell,trow).eq(idn).text() || k;};
  1258. }
  1259. }
  1260. else {
  1261. getId = function( trow, k) {return trow.getAttribute(idn.replace(/[\[\]]/g,"")) || k;};
  1262. }
  1263. ts.p.userData = {};
  1264. ts.p.page = $.jgrid.getXmlData( xml,xmlRd.page ) || ts.p.page || 0;
  1265. ts.p.lastpage = $.jgrid.getXmlData( xml,xmlRd.total );
  1266. if(ts.p.lastpage===undefined) { ts.p.lastpage=1; }
  1267. ts.p.records = $.jgrid.getXmlData( xml,xmlRd.records ) || 0;
  1268. if($.isFunction(xmlRd.userdata)) {
  1269. ts.p.userData = xmlRd.userdata.call(ts, xml) || {};
  1270. } else {
  1271. $.jgrid.getXmlData(xml, xmlRd.userdata, true).each(function() {ts.p.userData[this.getAttribute("name")]= $(this).text();});
  1272. }
  1273. var gxml = $.jgrid.getXmlData( xml, xmlRd.root, true);
  1274. gxml = $.jgrid.getXmlData( gxml, xmlRd.row, true);
  1275. if (!gxml) { gxml = []; }
  1276. var gl = gxml.length, j=0, grpdata=[], rn = parseInt(ts.p.rowNum,10), br=ts.p.scroll?$.jgrid.randId():1, altr;
  1277. if (gl > 0 && ts.p.page <= 0) { ts.p.page = 1; }
  1278. if(gxml && gl){
  1279. if (adjust) { rn *= adjust+1; }
  1280. var afterInsRow = $.isFunction(ts.p.afterInsertRow), hiderow=false, groupingPrepare;
  1281. if(ts.p.grouping) {
  1282. hiderow = ts.p.groupingView.groupCollapse === true;
  1283. groupingPrepare = $.jgrid.getMethod("groupingPrepare");
  1284. }
  1285. while (j<gl) {
  1286. xmlr = gxml[j];
  1287. rid = getId(xmlr,br+j);
  1288. rid = ts.p.idPrefix + rid;
  1289. altr = rcnt === 0 ? 0 : rcnt+1;
  1290. cn1 = (altr+j)%2 === 1 ? cn : '';
  1291. var iStartTrTag = rowData.length;
  1292. rowData.push("");
  1293. if( ni ) {
  1294. rowData.push( addRowNum(0,j,ts.p.page,ts.p.rowNum) );
  1295. }
  1296. if( gi ) {
  1297. rowData.push( addMulti(rid,ni,j, false) );
  1298. }
  1299. if( si ) {
  1300. rowData.push( addSubGridCell.call(self,gi+ni,j+rcnt) );
  1301. }
  1302. if(xmlRd.repeatitems){
  1303. if (!F) { F=orderedCols(gi+si+ni); }
  1304. var cells = $.jgrid.getXmlData( xmlr, xmlRd.cell, true);
  1305. $.each(F, function (k) {
  1306. var cell = cells[this];
  1307. if (!cell) { return false; }
  1308. v = cell.textContent || cell.text;
  1309. rd[ts.p.colModel[k+gi+si+ni].name] = v;
  1310. rowData.push( addCell(rid,v,k+gi+si+ni,j+rcnt,xmlr, rd) );
  1311. });
  1312. } else {
  1313. for(i = 0; i < f.length;i++) {
  1314. v = $.jgrid.getXmlData( xmlr, f[i]);
  1315. rd[ts.p.colModel[i+gi+si+ni].name] = v;
  1316. rowData.push( addCell(rid, v, i+gi+si+ni, j+rcnt, xmlr, rd) );
  1317. }
  1318. }
  1319. rowData[iStartTrTag] = constructTr(rid, hiderow, cn1, rd, xmlr, false);
  1320. rowData.push("</tr>");
  1321. if(ts.p.grouping) {
  1322. grpdata = groupingPrepare.call(self,rowData, grpdata, rd, j);
  1323. rowData = [];
  1324. }
  1325. if(locdata || ts.p.treeGrid === true) {
  1326. rd[xmlid] = $.jgrid.stripPref(ts.p.idPrefix, rid);
  1327. ts.p.data.push(rd);
  1328. ts.p._index[rd[xmlid]] = ts.p.data.length-1;
  1329. }
  1330. if(ts.p.gridview === false ) {
  1331. $("tbody:first",t).append(rowData.join(''));
  1332. self.triggerHandler("jqGridAfterInsertRow", [rid, rd, xmlr]);
  1333. if(afterInsRow) {ts.p.afterInsertRow.call(ts,rid,rd,xmlr);}
  1334. rowData=[];
  1335. }
  1336. rd={};
  1337. ir++;
  1338. j++;
  1339. if(ir===rn) {break;}
  1340. }
  1341. }
  1342. if(ts.p.gridview === true) {
  1343. fpos = ts.p.treeANode > -1 ? ts.p.treeANode: 0;
  1344. if(ts.p.grouping) {
  1345. self.jqGrid('groupingRender',grpdata,ts.p.colModel.length);
  1346. grpdata = null;
  1347. } else if(ts.p.treeGrid === true && fpos > 0) {
  1348. $(ts.rows[fpos]).after(rowData.join(''));
  1349. } else {
  1350. $("tbody:first",t).append(rowData.join(''));
  1351. }
  1352. }
  1353. if(ts.p.subGrid === true ) {
  1354. try {self.jqGrid("addSubGrid",gi+ni);} catch (_){}
  1355. }
  1356. ts.p.totaltime = new Date() - startReq;
  1357. if(ir>0) { if(ts.p.records===0) { ts.p.records=gl;} }
  1358. rowData =null;
  1359. if( ts.p.treeGrid === true) {
  1360. try {self.jqGrid("setTreeNode", fpos+1, ir+fpos+1);} catch (e) {}
  1361. }
  1362. if(!ts.p.treeGrid && !ts.p.scroll) {ts.grid.bDiv.scrollTop = 0;}
  1363. ts.p.reccount=ir;
  1364. ts.p.treeANode = -1;
  1365. if(ts.p.userDataOnFooter) { self.jqGrid("footerData","set",ts.p.userData,true); }
  1366. if(locdata) {
  1367. ts.p.records = gl;
  1368. ts.p.lastpage = Math.ceil(gl/ rn);
  1369. }
  1370. if (!more) { ts.updatepager(false,true); }
  1371. if(locdata) {
  1372. while (ir<gl) {
  1373. xmlr = gxml[ir];
  1374. rid = getId(xmlr,ir+br);
  1375. rid = ts.p.idPrefix + rid;
  1376. if(xmlRd.repeatitems){
  1377. if (!F) { F=orderedCols(gi+si+ni); }
  1378. var cells2 = $.jgrid.getXmlData( xmlr, xmlRd.cell, true);
  1379. $.each(F, function (k) {
  1380. var cell = cells2[this];
  1381. if (!cell) { return false; }
  1382. v = cell.textContent || cell.text;
  1383. rd[ts.p.colModel[k+gi+si+ni].name] = v;
  1384. });
  1385. } else {
  1386. for(i = 0; i < f.length;i++) {
  1387. v = $.jgrid.getXmlData( xmlr, f[i]);
  1388. rd[ts.p.colModel[i+gi+si+ni].name] = v;
  1389. }
  1390. }
  1391. rd[xmlid] = $.jgrid.stripPref(ts.p.idPrefix, rid);
  1392. ts.p.data.push(rd);
  1393. ts.p._index[rd[xmlid]] = ts.p.data.length-1;
  1394. rd = {};
  1395. ir++;
  1396. }
  1397. }
  1398. },
  1399. addJSONData = function(data,t, rcnt, more, adjust) {
  1400. var startReq = new Date();
  1401. if(data) {
  1402. if(ts.p.treeANode === -1 && !ts.p.scroll) {
  1403. emptyRows.call(ts, false, true);
  1404. rcnt=1;
  1405. } else { rcnt = rcnt > 1 ? rcnt :1; }
  1406. } else { return; }
  1407. var dReader, locid = "_id_", frd,
  1408. locdata = (ts.p.datatype !== "local" && ts.p.loadonce) || ts.p.datatype === "jsonstring";
  1409. if(locdata) { ts.p.data = []; ts.p._index = {}; ts.p.localReader.id = locid;}
  1410. ts.p.reccount = 0;
  1411. if(ts.p.datatype === "local") {
  1412. dReader = ts.p.localReader;
  1413. frd= 'local';
  1414. } else {
  1415. dReader = ts.p.jsonReader;
  1416. frd='json';
  1417. }
  1418. 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,lp;
  1419. ts.p.page = $.jgrid.getAccessor(data,dReader.page) || ts.p.page || 0;
  1420. lp = $.jgrid.getAccessor(data,dReader.total);
  1421. if(si) {
  1422. addSubGridCell = $.jgrid.getMethod("addSubGridCell");
  1423. }
  1424. ts.p.lastpage = lp === undefined ? 1 : lp;
  1425. ts.p.records = $.jgrid.getAccessor(data,dReader.records) || 0;
  1426. ts.p.userData = $.jgrid.getAccessor(data,dReader.userdata) || {};
  1427. if( ts.p.keyIndex===false ) {
  1428. idn = $.isFunction(dReader.id) ? dReader.id.call(ts, data) : dReader.id;
  1429. } else {
  1430. idn = ts.p.keyIndex;
  1431. }
  1432. if(!dReader.repeatitems) {
  1433. f = objectReader;
  1434. if(f.length>0 && !isNaN(idn)) {
  1435. if (ts.p.remapColumns && ts.p.remapColumns.length) {
  1436. idn = $.inArray(idn, ts.p.remapColumns);
  1437. }
  1438. idn=f[idn];
  1439. }
  1440. }
  1441. drows = $.jgrid.getAccessor(data,dReader.root);
  1442. if (drows == null && $.isArray(data)) { drows = data; }
  1443. if (!drows) { drows = []; }
  1444. len = drows.length; i=0;
  1445. if (len > 0 && ts.p.page <= 0) { ts.p.page = 1; }
  1446. var rn = parseInt(ts.p.rowNum,10),br=ts.p.scroll?$.jgrid.randId():1, altr, selected=false, selr;
  1447. if (adjust) { rn *= adjust+1; }
  1448. if(ts.p.datatype === "local" && !ts.p.deselectAfterSort) {
  1449. selected = true;
  1450. }
  1451. var afterInsRow = $.isFunction(ts.p.afterInsertRow), grpdata=[],hiderow=false, groupingPrepare;
  1452. if(ts.p.grouping) {
  1453. hiderow = ts.p.groupingView.groupCollapse === true;
  1454. groupingPrepare = $.jgrid.getMethod("groupingPrepare");
  1455. }
  1456. while (i<len) {
  1457. cur = drows[i];
  1458. idr = $.jgrid.getAccessor(cur,idn);
  1459. if(idr === undefined) {
  1460. if (typeof idn === "number" && ts.p.colModel[idn+gi+si+ni] != null) {
  1461. // reread id by name
  1462. idr = $.jgrid.getAccessor(cur,ts.p.colModel[idn+gi+si+ni].name);
  1463. }
  1464. if(idr === undefined) {
  1465. idr = br+i;
  1466. if(f.length===0){
  1467. if(dReader.cell){
  1468. var ccur = $.jgrid.getAccessor(cur,dReader.cell) || cur;
  1469. idr = ccur != null && ccur[idn] !== undefined ? ccur[idn] : idr;
  1470. ccur=null;
  1471. }
  1472. }
  1473. }
  1474. }
  1475. idr = ts.p.idPrefix + idr;
  1476. altr = rcnt === 1 ? 0 : rcnt;
  1477. cn1 = (altr+i)%2 === 1 ? cn : '';
  1478. if( selected) {
  1479. if( ts.p.multiselect) {
  1480. selr = ($.inArray(idr, ts.p.selarrrow) !== -1);
  1481. } else {
  1482. selr = (idr === ts.p.selrow);
  1483. }
  1484. }
  1485. var iStartTrTag = rowData.length;
  1486. rowData.push("");
  1487. if( ni ) {
  1488. rowData.push( addRowNum(0,i,ts.p.page,ts.p.rowNum) );
  1489. }
  1490. if( gi ){
  1491. rowData.push( addMulti(idr,ni,i,selr) );
  1492. }
  1493. if( si ) {
  1494. rowData.push( addSubGridCell.call(self,gi+ni,i+rcnt) );
  1495. }
  1496. rowReader=objectReader;
  1497. if (dReader.repeatitems) {
  1498. if(dReader.cell) {cur = $.jgrid.getAccessor(cur,dReader.cell) || cur;}
  1499. if ($.isArray(cur)) { rowReader=arrayReader; }
  1500. }
  1501. for (j=0;j<rowReader.length;j++) {
  1502. v = $.jgrid.getAccessor(cur,rowReader[j]);
  1503. rd[ts.p.colModel[j+gi+si+ni].name] = v;
  1504. rowData.push( addCell(idr,v,j+gi+si+ni,i+rcnt,cur, rd) );
  1505. }
  1506. rowData[iStartTrTag] = constructTr(idr, hiderow, cn1, rd, cur, selr);
  1507. rowData.push( "</tr>" );
  1508. if(ts.p.grouping) {
  1509. grpdata = groupingPrepare.call(self,rowData, grpdata, rd, i);
  1510. rowData = [];
  1511. }
  1512. if(locdata || ts.p.treeGrid===true) {
  1513. rd[locid] = $.jgrid.stripPref(ts.p.idPrefix, idr);
  1514. ts.p.data.push(rd);
  1515. ts.p._index[rd[locid]] = ts.p.data.length-1;
  1516. }
  1517. if(ts.p.gridview === false ) {
  1518. $("#"+$.jgrid.jqID(ts.p.id)+" tbody:first").append(rowData.join(''));
  1519. self.triggerHandler("jqGridAfterInsertRow", [idr, rd, cur]);
  1520. if(afterInsRow) {ts.p.afterInsertRow.call(ts,idr,rd,cur);}
  1521. rowData=[];//ari=0;
  1522. }
  1523. rd={};
  1524. ir++;
  1525. i++;
  1526. if(ir===rn) { break; }
  1527. }
  1528. if(ts.p.gridview === true ) {
  1529. fpos = ts.p.treeANode > -1 ? ts.p.treeANode: 0;
  1530. if(ts.p.grouping) {
  1531. self.jqGrid('groupingRender',grpdata,ts.p.colModel.length);
  1532. grpdata = null;
  1533. } else if(ts.p.treeGrid === true && fpos > 0) {
  1534. $(ts.rows[fpos]).after(rowData.join(''));
  1535. } else {
  1536. $("#"+$.jgrid.jqID(ts.p.id)+" tbody:first").append(rowData.join(''));
  1537. }
  1538. }
  1539. if(ts.p.subGrid === true ) {
  1540. try { self.jqGrid("addSubGrid",gi+ni);} catch (_){}
  1541. }
  1542. ts.p.totaltime = new Date() - startReq;
  1543. if(ir>0) {
  1544. if(ts.p.records===0) { ts.p.records=len; }
  1545. }
  1546. rowData = null;
  1547. if( ts.p.treeGrid === true) {
  1548. try {self.jqGrid("setTreeNode", fpos+1, ir+fpos+1);} catch (e) {}
  1549. }
  1550. if(!ts.p.treeGrid && !ts.p.scroll) {ts.grid.bDiv.scrollTop = 0;}
  1551. ts.p.reccount=ir;
  1552. ts.p.treeANode = -1;
  1553. if(ts.p.userDataOnFooter) { self.jqGrid("footerData","set",ts.p.userData,true); }
  1554. if(locdata) {
  1555. ts.p.records = len;
  1556. ts.p.lastpage = Math.ceil(len/ rn);
  1557. }
  1558. if (!more) { ts.updatepager(false,true); }
  1559. if(locdata) {
  1560. while (ir<len && drows[ir]) {
  1561. cur = drows[ir];
  1562. idr = $.jgrid.getAccessor(cur,idn);
  1563. if(idr === undefined) {
  1564. if (typeof idn === "number" && ts.p.colModel[idn+gi+si+ni] != null) {
  1565. // reread id by name
  1566. idr = $.jgrid.getAccessor(cur,ts.p.colModel[idn+gi+si+ni].name);
  1567. }
  1568. if(idr === undefined) {
  1569. idr = br+ir;
  1570. if(f.length===0){
  1571. if(dReader.cell){
  1572. var ccur2 = $.jgrid.getAccessor(cur,dReader.cell) || cur;
  1573. idr = ccur2 != null && ccur2[idn] !== undefined ? ccur2[idn] : idr;
  1574. ccur2=null;
  1575. }
  1576. }
  1577. }
  1578. }
  1579. if(cur) {
  1580. idr = ts.p.idPrefix + idr;
  1581. rowReader=objectReader;
  1582. if (dReader.repeatitems) {
  1583. if(dReader.cell) {cur = $.jgrid.getAccessor(cur,dReader.cell) || cur;}
  1584. if ($.isArray(cur)) { rowReader=arrayReader; }
  1585. }
  1586. for (j=0;j<rowReader.length;j++) {
  1587. rd[ts.p.colModel[j+gi+si+ni].name] = $.jgrid.getAccessor(cur,rowReader[j]);
  1588. }
  1589. rd[locid] = $.jgrid.stripPref(ts.p.idPrefix, idr);
  1590. ts.p.data.push(rd);
  1591. ts.p._index[rd[locid]] = ts.p.data.length-1;
  1592. rd = {};
  1593. }
  1594. ir++;
  1595. }
  1596. }
  1597. },
  1598. addLocalData = function() {
  1599. var st = ts.p.multiSort ? [] : "", sto=[], fndsort=false, cmtypes={}, grtypes=[], grindexes=[], srcformat, sorttype, newformat;
  1600. if(!$.isArray(ts.p.data)) {
  1601. return;
  1602. }
  1603. var grpview = ts.p.grouping ? ts.p.groupingView : false, lengrp, gin;
  1604. $.each(ts.p.colModel,function(){
  1605. sorttype = this.sorttype || "text";
  1606. if(sorttype === "date" || sorttype === "datetime") {
  1607. if(this.formatter && typeof this.formatter === 'string' && this.formatter === 'date') {
  1608. if(this.formatoptions && this.formatoptions.srcformat) {
  1609. srcformat = this.formatoptions.srcformat;
  1610. } else {
  1611. srcformat = $.jgrid.formatter.date.srcformat;
  1612. }
  1613. if(this.formatoptions && this.formatoptions.newformat) {
  1614. newformat = this.formatoptions.newformat;
  1615. } else {
  1616. newformat = $.jgrid.formatter.date.newformat;
  1617. }
  1618. } else {
  1619. srcformat = newformat = this.datefmt || "Y-m-d";
  1620. }
  1621. cmtypes[this.name] = {"stype": sorttype, "srcfmt": srcformat,"newfmt":newformat};
  1622. } else {
  1623. cmtypes[this.name] = {"stype": sorttype, "srcfmt":'',"newfmt":''};
  1624. }
  1625. if(ts.p.grouping ) {
  1626. for(gin =0, lengrp = grpview.groupField.length; gin< lengrp; gin++) {
  1627. if( this.name === grpview.groupField[gin]) {
  1628. var grindex = this.name;
  1629. if (this.index) {
  1630. grindex = this.index;
  1631. }
  1632. grtypes[gin] = cmtypes[grindex];
  1633. grindexes[gin]= grindex;
  1634. }
  1635. }
  1636. }
  1637. if(ts.p.multiSort) {
  1638. if(this.lso) {
  1639. st.push(this.name);
  1640. var tmplso= this.lso.split("-");
  1641. sto.push( tmplso[tmplso.length-1] );
  1642. }
  1643. } else {
  1644. if(!fndsort && (this.index === ts.p.sortname || this.name === ts.p.sortname)){
  1645. st = this.name; // ???
  1646. fndsort = true;
  1647. }
  1648. }
  1649. });
  1650. if(ts.p.treeGrid) {
  1651. $(ts).jqGrid("SortTree", st, ts.p.sortorder, cmtypes[st].stype, cmtypes[st].srcfmt);
  1652. return;
  1653. }
  1654. var compareFnMap = {
  1655. 'eq':function(queryObj) {return queryObj.equals;},
  1656. 'ne':function(queryObj) {return queryObj.notEquals;},
  1657. 'lt':function(queryObj) {return queryObj.less;},
  1658. 'le':function(queryObj) {return queryObj.lessOrEquals;},
  1659. 'gt':function(queryObj) {return queryObj.greater;},
  1660. 'ge':function(queryObj) {return queryObj.greaterOrEquals;},
  1661. 'cn':function(queryObj) {return queryObj.contains;},
  1662. 'nc':function(queryObj,op) {return op === "OR" ? queryObj.orNot().contains : queryObj.andNot().contains;},
  1663. 'bw':function(queryObj) {return queryObj.startsWith;},
  1664. 'bn':function(queryObj,op) {return op === "OR" ? queryObj.orNot().startsWith : queryObj.andNot().startsWith;},
  1665. 'en':function(queryObj,op) {return op === "OR" ? queryObj.orNot().endsWith : queryObj.andNot().endsWith;},
  1666. 'ew':function(queryObj) {return queryObj.endsWith;},
  1667. 'ni':function(queryObj,op) {return op === "OR" ? queryObj.orNot().equals : queryObj.andNot().equals;},
  1668. 'in':function(queryObj) {return queryObj.equals;},
  1669. 'nu':function(queryObj) {return queryObj.isNull;},
  1670. 'nn':function(queryObj,op) {return op === "OR" ? queryObj.orNot().isNull : queryObj.andNot().isNull;}
  1671. },
  1672. query = $.jgrid.from(ts.p.data);
  1673. if (ts.p.ignoreCase) { query = query.ignoreCase(); }
  1674. function tojLinq ( group ) {
  1675. var s = 0, index, gor, ror, opr, rule;
  1676. if (group.groups != null) {
  1677. gor = group.groups.length && group.groupOp.toString().toUpperCase() === "OR";
  1678. if (gor) {
  1679. query.orBegin();
  1680. }
  1681. for (index = 0; index < group.groups.length; index++) {
  1682. if (s > 0 && gor) {
  1683. query.or();
  1684. }
  1685. try {
  1686. tojLinq(group.groups[index]);
  1687. } catch (e) {alert(e);}
  1688. s++;
  1689. }
  1690. if (gor) {
  1691. query.orEnd();
  1692. }
  1693. }
  1694. if (group.rules != null) {
  1695. //if(s>0) {
  1696. // var result = query.select();
  1697. // query = $.jgrid.from( result);
  1698. // if (ts.p.ignoreCase) { query = query.ignoreCase(); }
  1699. //}
  1700. try{
  1701. ror = group.rules.length && group.groupOp.toString().toUpperCase() === "OR";
  1702. if (ror) {
  1703. query.orBegin();
  1704. }
  1705. for (index = 0; index < group.rules.length; index++) {
  1706. rule = group.rules[index];
  1707. opr = group.groupOp.toString().toUpperCase();
  1708. if (compareFnMap[rule.op] && rule.field ) {
  1709. if(s > 0 && opr && opr === "OR") {
  1710. query = query.or();
  1711. }
  1712. query = compareFnMap[rule.op](query, opr)(rule.field, rule.data, cmtypes[rule.field]);
  1713. }
  1714. s++;
  1715. }
  1716. if (ror) {
  1717. query.orEnd();
  1718. }
  1719. } catch (g) {alert(g);}
  1720. }
  1721. }
  1722. if (ts.p.search === true) {
  1723. var srules = ts.p.postData.filters;
  1724. if(srules) {
  1725. if(typeof srules === "string") { srules = $.jgrid.parse(srules);}
  1726. tojLinq( srules );
  1727. } else {
  1728. try {
  1729. query = compareFnMap[ts.p.postData.searchOper](query)(ts.p.postData.searchField, ts.p.postData.searchString,cmtypes[ts.p.postData.searchField]);
  1730. } catch (se){}
  1731. }
  1732. }
  1733. if(ts.p.grouping) {
  1734. for(gin=0; gin<lengrp;gin++) {
  1735. query.orderBy(grindexes[gin],grpview.groupOrder[gin],grtypes[gin].stype, grtypes[gin].srcfmt);
  1736. }
  1737. }
  1738. if(ts.p.multiSort) {
  1739. $.each(st,function(i){
  1740. query.orderBy(this, sto[i], cmtypes[this].stype, cmtypes[this].srcfmt);
  1741. });
  1742. } else {
  1743. if (st && ts.p.sortorder && fndsort) {
  1744. if(ts.p.sortorder.toUpperCase() === "DESC") {
  1745. query.orderBy(ts.p.sortname, "d", cmtypes[st].stype, cmtypes[st].srcfmt);
  1746. } else {
  1747. query.orderBy(ts.p.sortname, "a", cmtypes[st].stype, cmtypes[st].srcfmt);
  1748. }
  1749. }
  1750. }
  1751. var queryResults = query.select(),
  1752. recordsperpage = parseInt(ts.p.rowNum,10),
  1753. total = queryResults.length,
  1754. page = parseInt(ts.p.page,10),
  1755. totalpages = Math.ceil(total / recordsperpage),
  1756. retresult = {};
  1757. queryResults = queryResults.slice( (page-1)*recordsperpage , page*recordsperpage );
  1758. query = null;
  1759. cmtypes = null;
  1760. retresult[ts.p.localReader.total] = totalpages;
  1761. retresult[ts.p.localReader.page] = page;
  1762. retresult[ts.p.localReader.records] = total;
  1763. retresult[ts.p.localReader.root] = queryResults;
  1764. retresult[ts.p.localReader.userdata] = ts.p.userData;
  1765. queryResults = null;
  1766. return retresult;
  1767. },
  1768. updatepager = function(rn, dnd) {
  1769. var cp, last, base, from,to,tot,fmt, pgboxes = "", sppg,
  1770. tspg = ts.p.pager ? "_"+$.jgrid.jqID(ts.p.pager.substr(1)) : "",
  1771. tspg_t = ts.p.toppager ? "_"+ts.p.toppager.substr(1) : "";
  1772. base = parseInt(ts.p.page,10)-1;
  1773. if(base < 0) { base = 0; }
  1774. base = base*parseInt(ts.p.rowNum,10);
  1775. to = base + ts.p.reccount;
  1776. if (ts.p.scroll) {
  1777. var rows = $("tbody:first > tr:gt(0)", ts.grid.bDiv);
  1778. base = to - rows.length;
  1779. ts.p.reccount = rows.length;
  1780. var rh = rows.outerHeight() || ts.grid.prevRowHeight;
  1781. if (rh) {
  1782. var top = base * rh;
  1783. var height = parseInt(ts.p.records,10) * rh;
  1784. $(">div:first",ts.grid.bDiv).css({height : height}).children("div:first").css({height:top,display:top?"":"none"});
  1785. if (ts.grid.bDiv.scrollTop == 0 && ts.p.page > 1) {
  1786. ts.grid.bDiv.scrollTop = ts.p.rowNum * (ts.p.page - 1) * rh;
  1787. }
  1788. }
  1789. ts.grid.bDiv.scrollLeft = ts.grid.hDiv.scrollLeft;
  1790. }
  1791. pgboxes = ts.p.pager || "";
  1792. pgboxes += ts.p.toppager ? (pgboxes ? "," + ts.p.toppager : ts.p.toppager) : "";
  1793. if(pgboxes) {
  1794. fmt = $.jgrid.formatter.integer || {};
  1795. cp = intNum(ts.p.page);
  1796. last = intNum(ts.p.lastpage);
  1797. $(".selbox",pgboxes)[ this.p.useProp ? 'prop' : 'attr' ]("disabled",false);
  1798. if(ts.p.pginput===true) {
  1799. $('.ui-pg-input',pgboxes).val(ts.p.page);
  1800. sppg = ts.p.toppager ? '#sp_1'+tspg+",#sp_1"+tspg_t : '#sp_1'+tspg;
  1801. $(sppg).html($.fmatter ? $.fmatter.util.NumberFormat(ts.p.lastpage,fmt):ts.p.lastpage);
  1802. }
  1803. if (ts.p.viewrecords){
  1804. if(ts.p.reccount === 0) {
  1805. $(".ui-paging-info",pgboxes).html(ts.p.emptyrecords);
  1806. } else {
  1807. from = base+1;
  1808. tot=ts.p.records;
  1809. if($.fmatter) {
  1810. from = $.fmatter.util.NumberFormat(from,fmt);
  1811. to = $.fmatter.util.NumberFormat(to,fmt);
  1812. tot = $.fmatter.util.NumberFormat(tot,fmt);
  1813. }
  1814. $(".ui-paging-info",pgboxes).html($.jgrid.format(ts.p.recordtext,from,to,tot));
  1815. }
  1816. }
  1817. if(ts.p.pgbuttons===true) {
  1818. if(cp<=0) {cp = last = 0;}
  1819. if(cp===1 || cp === 0) {
  1820. $("#first"+tspg+", #prev"+tspg).addClass('ui-state-disabled').removeClass('ui-state-hover');
  1821. if(ts.p.toppager) { $("#first_t"+tspg_t+", #prev_t"+tspg_t).addClass('ui-state-disabled').removeClass('ui-state-hover'); }
  1822. } else {
  1823. $("#first"+tspg+", #prev"+tspg).removeClass('ui-state-disabled');
  1824. if(ts.p.toppager) { $("#first_t"+tspg_t+", #prev_t"+tspg_t).removeClass('ui-state-disabled'); }
  1825. }
  1826. if(cp===last || cp === 0) {
  1827. $("#next"+tspg+", #last"+tspg).addClass('ui-state-disabled').removeClass('ui-state-hover');
  1828. if(ts.p.toppager) { $("#next_t"+tspg_t+", #last_t"+tspg_t).addClass('ui-state-disabled').removeClass('ui-state-hover'); }
  1829. } else {
  1830. $("#next"+tspg+", #last"+tspg).removeClass('ui-state-disabled');
  1831. if(ts.p.toppager) { $("#next_t"+tspg_t+", #last_t"+tspg_t).removeClass('ui-state-disabled'); }
  1832. }
  1833. }
  1834. }
  1835. if(rn===true && ts.p.rownumbers === true) {
  1836. $(">td.jqgrid-rownum",ts.rows).each(function(i){
  1837. $(this).html(base+1+i);
  1838. });
  1839. }
  1840. if(dnd && ts.p.jqgdnd) { $(ts).jqGrid('gridDnD','updateDnD');}
  1841. $(ts).triggerHandler("jqGridGridComplete");
  1842. if($.isFunction(ts.p.gridComplete)) {ts.p.gridComplete.call(ts);}
  1843. $(ts).triggerHandler("jqGridAfterGridComplete");
  1844. },
  1845. beginReq = function() {
  1846. ts.grid.hDiv.loading = true;
  1847. if(ts.p.hiddengrid) { return;}
  1848. switch(ts.p.loadui) {
  1849. case "disable":
  1850. break;
  1851. case "enable":
  1852. $("#load_"+$.jgrid.jqID(ts.p.id)).show();
  1853. break;
  1854. case "block":
  1855. $("#lui_"+$.jgrid.jqID(ts.p.id)).show();
  1856. $("#load_"+$.jgrid.jqID(ts.p.id)).show();
  1857. break;
  1858. }
  1859. },
  1860. endReq = function() {
  1861. ts.grid.hDiv.loading = false;
  1862. switch(ts.p.loadui) {
  1863. case "disable":
  1864. break;
  1865. case "enable":
  1866. $("#load_"+$.jgrid.jqID(ts.p.id)).hide();
  1867. break;
  1868. case "block":
  1869. $("#lui_"+$.jgrid.jqID(ts.p.id)).hide();
  1870. $("#load_"+$.jgrid.jqID(ts.p.id)).hide();
  1871. break;
  1872. }
  1873. },
  1874. populate = function (npage) {
  1875. if(!ts.grid.hDiv.loading) {
  1876. var pvis = ts.p.scroll && npage === false,
  1877. prm = {}, dt, dstr, pN=ts.p.prmNames;
  1878. if(ts.p.page <=0) { ts.p.page = 1; }
  1879. if(pN.search !== null) {prm[pN.search] = ts.p.search;} if(pN.nd !== null) {prm[pN.nd] = new Date().getTime();}
  1880. if(pN.rows !== null) {prm[pN.rows]= ts.p.rowNum;} if(pN.page !== null) {prm[pN.page]= ts.p.page;}
  1881. if(pN.sort !== null) {prm[pN.sort]= ts.p.sortname;} if(pN.order !== null) {prm[pN.order]= ts.p.sortorder;}
  1882. if(ts.p.rowTotal !== null && pN.totalrows !== null) { prm[pN.totalrows]= ts.p.rowTotal; }
  1883. var lcf = $.isFunction(ts.p.loadComplete), lc = lcf ? ts.p.loadComplete : null;
  1884. var adjust = 0;
  1885. npage = npage || 1;
  1886. if (npage > 1) {
  1887. if(pN.npage !== null) {
  1888. prm[pN.npage] = npage;
  1889. adjust = npage - 1;
  1890. npage = 1;
  1891. } else {
  1892. lc = function(req) {
  1893. ts.p.page++;
  1894. ts.grid.hDiv.loading = false;
  1895. if (lcf) {
  1896. ts.p.loadComplete.call(ts,req);
  1897. }
  1898. populate(npage-1);
  1899. };
  1900. }
  1901. } else if (pN.npage !== null) {
  1902. delete ts.p.postData[pN.npage];
  1903. }
  1904. if(ts.p.grouping) {
  1905. $(ts).jqGrid('groupingSetup');
  1906. var grp = ts.p.groupingView, gi, gs="";
  1907. for(gi=0;gi<grp.groupField.length;gi++) {
  1908. var index = grp.groupField[gi];
  1909. $.each(ts.p.colModel, function(cmIndex, cmValue) {
  1910. if (cmValue.name === index && cmValue.index){
  1911. index = cmValue.index;
  1912. }
  1913. } );
  1914. gs += index +" "+grp.groupOrder[gi]+", ";
  1915. }
  1916. prm[pN.sort] = gs + prm[pN.sort];
  1917. }
  1918. $.extend(ts.p.postData,prm);
  1919. var rcnt = !ts.p.scroll ? 1 : ts.rows.length-1;
  1920. var bfr = $(ts).triggerHandler("jqGridBeforeRequest");
  1921. if (bfr === false || bfr === 'stop') { return; }
  1922. if ($.isFunction(ts.p.datatype)) { ts.p.datatype.call(ts,ts.p.postData,"load_"+ts.p.id); return;}
  1923. if ($.isFunction(ts.p.beforeRequest)) {
  1924. bfr = ts.p.beforeRequest.call(ts);
  1925. if(bfr === undefined) { bfr = true; }
  1926. if ( bfr === false ) { return; }
  1927. }
  1928. dt = ts.p.datatype.toLowerCase();
  1929. switch(dt)
  1930. {
  1931. case "json":
  1932. case "jsonp":
  1933. case "xml":
  1934. case "script":
  1935. $.ajax($.extend({
  1936. url:ts.p.url,
  1937. type:ts.p.mtype,
  1938. dataType: dt ,
  1939. data: $.isFunction(ts.p.serializeGridData)? ts.p.serializeGridData.call(ts,ts.p.postData) : ts.p.postData,
  1940. success:function(data,st, xhr) {
  1941. if ($.isFunction(ts.p.beforeProcessing)) {
  1942. if (ts.p.beforeProcessing.call(ts, data, st, xhr) === false) {
  1943. endReq();
  1944. return;
  1945. }
  1946. }
  1947. if(dt === "xml") { addXmlData(data,ts.grid.bDiv,rcnt,npage>1,adjust); }
  1948. else { addJSONData(data,ts.grid.bDiv,rcnt,npage>1,adjust); }
  1949. $(ts).triggerHandler("jqGridLoadComplete", [data]);
  1950. if(lc) { lc.call(ts,data); }
  1951. $(ts).triggerHandler("jqGridAfterLoadComplete", [data]);
  1952. if (pvis) { ts.grid.populateVisible(); }
  1953. if( ts.p.loadonce || ts.p.treeGrid) {ts.p.datatype = "local";}
  1954. data=null;
  1955. if (npage === 1) { endReq(); }
  1956. },
  1957. error:function(xhr,st,err){
  1958. if($.isFunction(ts.p.loadError)) { ts.p.loadError.call(ts,xhr,st,err); }
  1959. if (npage === 1) { endReq(); }
  1960. xhr=null;
  1961. },
  1962. beforeSend: function(xhr, settings ){
  1963. var gotoreq = true;
  1964. if($.isFunction(ts.p.loadBeforeSend)) {
  1965. gotoreq = ts.p.loadBeforeSend.call(ts,xhr, settings);
  1966. }
  1967. if(gotoreq === undefined) { gotoreq = true; }
  1968. if(gotoreq === false) {
  1969. return false;
  1970. }
  1971. beginReq();
  1972. }
  1973. },$.jgrid.ajaxOptions, ts.p.ajaxGridOptions));
  1974. break;
  1975. case "xmlstring":
  1976. beginReq();
  1977. dstr = typeof ts.p.datastr !== 'string' ? ts.p.datastr : $.parseXML(ts.p.datastr);
  1978. addXmlData(dstr,ts.grid.bDiv);
  1979. $(ts).triggerHandler("jqGridLoadComplete", [dstr]);
  1980. if(lcf) {ts.p.loadComplete.call(ts,dstr);}
  1981. $(ts).triggerHandler("jqGridAfterLoadComplete", [dstr]);
  1982. ts.p.datatype = "local";
  1983. ts.p.datastr = null;
  1984. endReq();
  1985. break;
  1986. case "jsonstring":
  1987. beginReq();
  1988. if(typeof ts.p.datastr === 'string') { dstr = $.jgrid.parse(ts.p.datastr); }
  1989. else { dstr = ts.p.datastr; }
  1990. addJSONData(dstr,ts.grid.bDiv);
  1991. $(ts).triggerHandler("jqGridLoadComplete", [dstr]);
  1992. if(lcf) {ts.p.loadComplete.call(ts,dstr);}
  1993. $(ts).triggerHandler("jqGridAfterLoadComplete", [dstr]);
  1994. ts.p.datatype = "local";
  1995. ts.p.datastr = null;
  1996. endReq();
  1997. break;
  1998. case "local":
  1999. case "clientside":
  2000. beginReq();
  2001. ts.p.datatype = "local";
  2002. var req = addLocalData();
  2003. addJSONData(req,ts.grid.bDiv,rcnt,npage>1,adjust);
  2004. $(ts).triggerHandler("jqGridLoadComplete", [req]);
  2005. if(lc) { lc.call(ts,req); }
  2006. $(ts).triggerHandler("jqGridAfterLoadComplete", [req]);
  2007. if (pvis) { ts.grid.populateVisible(); }
  2008. endReq();
  2009. break;
  2010. }
  2011. }
  2012. },
  2013. setHeadCheckBox = function ( checked ) {
  2014. $('#cb_'+$.jgrid.jqID(ts.p.id),ts.grid.hDiv)[ts.p.useProp ? 'prop': 'attr']("checked", checked);
  2015. var fid = ts.p.frozenColumns ? ts.p.id+"_frozen" : "";
  2016. if(fid) {
  2017. $('#cb_'+$.jgrid.jqID(ts.p.id),ts.grid.fhDiv)[ts.p.useProp ? 'prop': 'attr']("checked", checked);
  2018. }
  2019. },
  2020. setPager = function (pgid, tp){
  2021. // TBD - consider escaping pgid with pgid = $.jgrid.jqID(pgid);
  2022. var sep = "<td class='ui-pg-button ui-state-disabled' style='width:4px;'><span class='ui-separator'></span></td>",
  2023. pginp = "",
  2024. pgl="<table cellspacing='0' cellpadding='0' border='0' style='table-layout:auto;' class='ui-pg-table'><tbody><tr>",
  2025. str="", pgcnt, lft, cent, rgt, twd, tdw, i,
  2026. clearVals = function(onpaging){
  2027. var ret;
  2028. if ($.isFunction(ts.p.onPaging) ) { ret = ts.p.onPaging.call(ts,onpaging); }
  2029. ts.p.selrow = null;
  2030. if(ts.p.multiselect) {ts.p.selarrrow =[]; setHeadCheckBox( false );}
  2031. ts.p.savedRow = [];
  2032. if(ret==='stop') {return false;}
  2033. return true;
  2034. };
  2035. pgid = pgid.substr(1);
  2036. tp += "_" + pgid;
  2037. pgcnt = "pg_"+pgid;
  2038. lft = pgid+"_left"; cent = pgid+"_center"; rgt = pgid+"_right";
  2039. $("#"+$.jgrid.jqID(pgid) )
  2040. .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>")
  2041. .attr("dir","ltr"); //explicit setting
  2042. if(ts.p.rowList.length >0){
  2043. str = "<td dir='"+dir+"'>";
  2044. str +="<select class='ui-pg-selbox' role='listbox'>";
  2045. for(i=0;i<ts.p.rowList.length;i++){
  2046. str +="<option role=\"option\" value=\""+ts.p.rowList[i]+"\""+((ts.p.rowNum === ts.p.rowList[i])?" selected=\"selected\"":"")+">"+ts.p.rowList[i]+"</option>";
  2047. }
  2048. str +="</select></td>";
  2049. }
  2050. if(dir==="rtl") { pgl += str; }
  2051. 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>";}
  2052. if(ts.p.pgbuttons===true) {
  2053. var po=["first"+tp,"prev"+tp, "next"+tp,"last"+tp]; if(dir==="rtl") { po.reverse(); }
  2054. pgl += "<td id='"+po[0]+"' class='ui-pg-button ui-corner-all'><span class='ui-icon ui-icon-seek-first'></span></td>";
  2055. pgl += "<td id='"+po[1]+"' class='ui-pg-button ui-corner-all'><span class='ui-icon ui-icon-seek-prev'></span></td>";
  2056. pgl += pginp !== "" ? sep+pginp+sep:"";
  2057. pgl += "<td id='"+po[2]+"' class='ui-pg-button ui-corner-all'><span class='ui-icon ui-icon-seek-next'></span></td>";
  2058. pgl += "<td id='"+po[3]+"' class='ui-pg-button ui-corner-all'><span class='ui-icon ui-icon-seek-end'></span></td>";
  2059. } else if (pginp !== "") { pgl += pginp; }
  2060. if(dir==="ltr") { pgl += str; }
  2061. pgl += "</tr></tbody></table>";
  2062. 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>");}
  2063. $("td#"+pgid+"_"+ts.p.pagerpos,"#"+pgcnt).append(pgl);
  2064. tdw = $(".ui-jqgrid").css("font-size") || "11px";
  2065. $(document.body).append("<div id='testpg' class='ui-jqgrid ui-widget ui-widget-content' style='font-size:"+tdw+";visibility:hidden;' ></div>");
  2066. twd = $(pgl).clone().appendTo("#testpg").width();
  2067. $("#testpg").remove();
  2068. if(twd > 0) {
  2069. if(pginp !== "") { twd += 50; } //should be param
  2070. $("td#"+pgid+"_"+ts.p.pagerpos,"#"+pgcnt).width(twd);
  2071. }
  2072. ts.p._nvtd = [];
  2073. ts.p._nvtd[0] = twd ? Math.floor((ts.p.width - twd)/2) : Math.floor(ts.p.width/3);
  2074. ts.p._nvtd[1] = 0;
  2075. pgl=null;
  2076. $('.ui-pg-selbox',"#"+pgcnt).bind('change',function() {
  2077. if(!clearVals('records')) { return false; }
  2078. ts.p.page = Math.round(ts.p.rowNum*(ts.p.page-1)/this.value-0.5)+1;
  2079. ts.p.rowNum = this.value;
  2080. if(ts.p.pager) { $('.ui-pg-selbox',ts.p.pager).val(this.value); }
  2081. if(ts.p.toppager) { $('.ui-pg-selbox',ts.p.toppager).val(this.value); }
  2082. populate();
  2083. return false;
  2084. });
  2085. if(ts.p.pgbuttons===true) {
  2086. $(".ui-pg-button","#"+pgcnt).hover(function(){
  2087. if($(this).hasClass('ui-state-disabled')) {
  2088. this.style.cursor='default';
  2089. } else {
  2090. $(this).addClass('ui-state-hover');
  2091. this.style.cursor='pointer';
  2092. }
  2093. },function() {
  2094. if(!$(this).hasClass('ui-state-disabled')) {
  2095. $(this).removeClass('ui-state-hover');
  2096. this.style.cursor= "default";
  2097. }
  2098. });
  2099. $("#first"+$.jgrid.jqID(tp)+", #prev"+$.jgrid.jqID(tp)+", #next"+$.jgrid.jqID(tp)+", #last"+$.jgrid.jqID(tp)).click( function() {
  2100. var cp = intNum(ts.p.page,1),
  2101. last = intNum(ts.p.lastpage,1), selclick = false,
  2102. fp=true, pp=true, np=true,lp=true;
  2103. if(last ===0 || last===1) {fp=false;pp=false;np=false;lp=false; }
  2104. else if( last>1 && cp >=1) {
  2105. if( cp === 1) { fp=false; pp=false; }
  2106. //else if( cp>1 && cp <last){ }
  2107. else if( cp===last){ np=false;lp=false; }
  2108. } else if( last>1 && cp===0 ) { np=false;lp=false; cp=last-1;}
  2109. if(!clearVals(this.id)) { return false; }
  2110. if( this.id === 'first'+tp && fp ) { ts.p.page=1; selclick=true;}
  2111. if( this.id === 'prev'+tp && pp) { ts.p.page=(cp-1); selclick=true;}
  2112. if( this.id === 'next'+tp && np) { ts.p.page=(cp+1); selclick=true;}
  2113. if( this.id === 'last'+tp && lp) { ts.p.page=last; selclick=true;}
  2114. if(selclick) {
  2115. populate();
  2116. }
  2117. return false;
  2118. });
  2119. }
  2120. if(ts.p.pginput===true) {
  2121. $('input.ui-pg-input',"#"+pgcnt).keypress( function(e) {
  2122. var key = e.charCode || e.keyCode || 0;
  2123. if(key === 13) {
  2124. if(!clearVals('user')) { return false; }
  2125. $(this).val( intNum( $(this).val(), 1));
  2126. ts.p.page = ($(this).val()>0) ? $(this).val():ts.p.page;
  2127. populate();
  2128. return false;
  2129. }
  2130. return this;
  2131. });
  2132. }
  2133. },
  2134. multiSort = function(iCol, obj ) {
  2135. var splas, sort="", cm = ts.p.colModel, fs=false, ls,
  2136. selTh = ts.p.frozenColumns ? obj : ts.grid.headers[iCol].el, so="";
  2137. $("span.ui-grid-ico-sort",selTh).addClass('ui-state-disabled');
  2138. $(selTh).attr("aria-selected","false");
  2139. if(cm[iCol].lso) {
  2140. if(cm[iCol].lso==="asc") {
  2141. cm[iCol].lso += "-desc";
  2142. so = "desc";
  2143. } else if(cm[iCol].lso==="desc") {
  2144. cm[iCol].lso += "-asc";
  2145. so = "asc";
  2146. } else if(cm[iCol].lso==="asc-desc" || cm[iCol].lso==="desc-asc") {
  2147. cm[iCol].lso="";
  2148. }
  2149. } else {
  2150. cm[iCol].lso = so = cm.firstsortorder || 'asc';
  2151. }
  2152. if( so ) {
  2153. $("span.s-ico",selTh).show();
  2154. $("span.ui-icon-"+so,selTh).removeClass('ui-state-disabled');
  2155. $(selTh).attr("aria-selected","true");
  2156. } else {
  2157. if(!ts.p.viewsortcols[0]) {
  2158. $("span.s-ico",selTh).hide();
  2159. }
  2160. }
  2161. ts.p.sortorder = "";
  2162. $.each(cm, function(i){
  2163. if(this.lso) {
  2164. if(i>0 && fs) {
  2165. sort += ", ";
  2166. }
  2167. splas = this.lso.split("-");
  2168. sort += cm[i].index || cm[i].name;
  2169. sort += " "+splas[splas.length-1];
  2170. fs = true;
  2171. ts.p.sortorder = splas[splas.length-1];
  2172. }
  2173. });
  2174. ls = sort.lastIndexOf(ts.p.sortorder);
  2175. sort = sort.substring(0, ls);
  2176. ts.p.sortname = sort;
  2177. },
  2178. sortData = function (index, idxcol,reload,sor, obj){
  2179. if(!ts.p.colModel[idxcol].sortable) { return; }
  2180. var so;
  2181. if(ts.p.savedRow.length > 0) {return;}
  2182. if(!reload) {
  2183. if( ts.p.lastsort === idxcol ) {
  2184. if( ts.p.sortorder === 'asc') {
  2185. ts.p.sortorder = 'desc';
  2186. } else if(ts.p.sortorder === 'desc') { ts.p.sortorder = 'asc';}
  2187. } else { ts.p.sortorder = ts.p.colModel[idxcol].firstsortorder || 'asc'; }
  2188. ts.p.page = 1;
  2189. }
  2190. if(ts.p.multiSort) {
  2191. multiSort( idxcol, obj);
  2192. } else {
  2193. if(sor) {
  2194. if(ts.p.lastsort === idxcol && ts.p.sortorder === sor && !reload) { return; }
  2195. ts.p.sortorder = sor;
  2196. }
  2197. var previousSelectedTh = ts.grid.headers[ts.p.lastsort].el, newSelectedTh = ts.p.frozenColumns ? obj : ts.grid.headers[idxcol].el;
  2198. $("span.ui-grid-ico-sort",previousSelectedTh).addClass('ui-state-disabled');
  2199. $(previousSelectedTh).attr("aria-selected","false");
  2200. if(ts.p.frozenColumns) {
  2201. ts.grid.fhDiv.find("span.ui-grid-ico-sort").addClass('ui-state-disabled');
  2202. ts.grid.fhDiv.find("th").attr("aria-selected","false");
  2203. }
  2204. $("span.ui-icon-"+ts.p.sortorder,newSelectedTh).removeClass('ui-state-disabled');
  2205. $(newSelectedTh).attr("aria-selected","true");
  2206. if(!ts.p.viewsortcols[0]) {
  2207. if(ts.p.lastsort !== idxcol) {
  2208. if(ts.p.frozenColumns){
  2209. ts.grid.fhDiv.find("span.s-ico").hide();
  2210. }
  2211. $("span.s-ico",previousSelectedTh).hide();
  2212. $("span.s-ico",newSelectedTh).show();
  2213. }
  2214. }
  2215. index = index.substring(5 + ts.p.id.length + 1); // bad to be changed!?!
  2216. ts.p.sortname = ts.p.colModel[idxcol].index || index;
  2217. so = ts.p.sortorder;
  2218. }
  2219. if ($(ts).triggerHandler("jqGridSortCol", [index, idxcol, so]) === 'stop') {
  2220. ts.p.lastsort = idxcol;
  2221. return;
  2222. }
  2223. if($.isFunction(ts.p.onSortCol)) {if (ts.p.onSortCol.call(ts,index,idxcol,so)==='stop') {ts.p.lastsort = idxcol; return;}}
  2224. if(ts.p.datatype === "local") {
  2225. if(ts.p.deselectAfterSort) {$(ts).jqGrid("resetSelection");}
  2226. } else {
  2227. ts.p.selrow = null;
  2228. if(ts.p.multiselect){setHeadCheckBox( false );}
  2229. ts.p.selarrrow =[];
  2230. ts.p.savedRow =[];
  2231. }
  2232. if(ts.p.scroll) {
  2233. var sscroll = ts.grid.bDiv.scrollLeft;
  2234. emptyRows.call(ts, true, false);
  2235. ts.grid.hDiv.scrollLeft = sscroll;
  2236. }
  2237. if(ts.p.subGrid && ts.p.datatype === 'local') {
  2238. $("td.sgexpanded","#"+$.jgrid.jqID(ts.p.id)).each(function(){
  2239. $(this).trigger("click");
  2240. });
  2241. }
  2242. populate();
  2243. ts.p.lastsort = idxcol;
  2244. if(ts.p.sortname !== index && idxcol) {ts.p.lastsort = idxcol;}
  2245. },
  2246. setColWidth = function () {
  2247. 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;
  2248. $.each(ts.p.colModel, function() {
  2249. if(this.hidden === undefined) {this.hidden=false;}
  2250. if(ts.p.grouping && ts.p.autowidth) {
  2251. var ind = $.inArray(this.name, ts.p.groupingView.groupField);
  2252. if(ind >= 0 && ts.p.groupingView.groupColumnShow.length > ind) {
  2253. this.hidden = !ts.p.groupingView.groupColumnShow[ind];
  2254. }
  2255. }
  2256. this.widthOrg = cw = intNum(this.width,0);
  2257. if(this.hidden===false){
  2258. initwidth += cw+brd;
  2259. if(this.fixed) {
  2260. gw += cw+brd;
  2261. } else {
  2262. vc++;
  2263. }
  2264. }
  2265. });
  2266. if(isNaN(ts.p.width)) {
  2267. ts.p.width = initwidth + ((ts.p.shrinkToFit ===false && !isNaN(ts.p.height)) ? scw : 0);
  2268. }
  2269. grid.width = ts.p.width;
  2270. ts.p.tblwidth = initwidth;
  2271. if(ts.p.shrinkToFit ===false && ts.p.forceFit === true) {ts.p.forceFit=false;}
  2272. if(ts.p.shrinkToFit===true && vc > 0) {
  2273. aw = grid.width-brd*vc-gw;
  2274. if(!isNaN(ts.p.height)) {
  2275. aw -= scw;
  2276. hs = true;
  2277. }
  2278. initwidth =0;
  2279. $.each(ts.p.colModel, function(i) {
  2280. if(this.hidden === false && !this.fixed){
  2281. cw = Math.round(aw*this.width/(ts.p.tblwidth-brd*vc-gw));
  2282. this.width =cw;
  2283. initwidth += cw;
  2284. lvc = i;
  2285. }
  2286. });
  2287. cr =0;
  2288. if (hs) {
  2289. if(grid.width-gw-(initwidth+brd*vc) !== scw){
  2290. cr = grid.width-gw-(initwidth+brd*vc)-scw;
  2291. }
  2292. } else if(!hs && Math.abs(grid.width-gw-(initwidth+brd*vc)) !== 1) {
  2293. cr = grid.width-gw-(initwidth+brd*vc);
  2294. }
  2295. ts.p.colModel[lvc].width += cr;
  2296. ts.p.tblwidth = initwidth+cr+brd*vc+gw;
  2297. if(ts.p.tblwidth > ts.p.width) {
  2298. ts.p.colModel[lvc].width -= (ts.p.tblwidth - parseInt(ts.p.width,10));
  2299. ts.p.tblwidth = ts.p.width;
  2300. }
  2301. }
  2302. },
  2303. nextVisible= function(iCol) {
  2304. var ret = iCol, j=iCol, i;
  2305. for (i = iCol+1;i<ts.p.colModel.length;i++){
  2306. if(ts.p.colModel[i].hidden !== true ) {
  2307. j=i; break;
  2308. }
  2309. }
  2310. return j-ret;
  2311. },
  2312. getOffset = function (iCol) {
  2313. var $th = $(ts.grid.headers[iCol].el), ret = [$th.position().left + $th.outerWidth()];
  2314. if(ts.p.direction==="rtl") { ret[0] = ts.p.width - ret[0]; }
  2315. ret[0] -= ts.grid.bDiv.scrollLeft;
  2316. ret.push($(ts.grid.hDiv).position().top);
  2317. ret.push($(ts.grid.bDiv).offset().top - $(ts.grid.hDiv).offset().top + $(ts.grid.bDiv).height());
  2318. return ret;
  2319. },
  2320. getColumnHeaderIndex = function (th) {
  2321. var i, headers = ts.grid.headers, ci = $.jgrid.getCellIndex(th);
  2322. for (i = 0; i < headers.length; i++) {
  2323. if (th === headers[i].el) {
  2324. ci = i;
  2325. break;
  2326. }
  2327. }
  2328. return ci;
  2329. };
  2330. this.p.id = this.id;
  2331. if ($.inArray(ts.p.multikey,sortkeys) === -1 ) {ts.p.multikey = false;}
  2332. ts.p.keyIndex=false;
  2333. for (i=0; i<ts.p.colModel.length;i++) {
  2334. ts.p.colModel[i] = $.extend(true, {}, ts.p.cmTemplate, ts.p.colModel[i].template || {}, ts.p.colModel[i]);
  2335. if (ts.p.keyIndex === false && ts.p.colModel[i].key===true) {
  2336. ts.p.keyIndex = i;
  2337. }
  2338. }
  2339. ts.p.sortorder = ts.p.sortorder.toLowerCase();
  2340. $.jgrid.cell_width = $.jgrid.cellWidth();
  2341. if(ts.p.grouping===true) {
  2342. ts.p.scroll = false;
  2343. ts.p.rownumbers = false;
  2344. //ts.p.subGrid = false; expiremental
  2345. ts.p.treeGrid = false;
  2346. ts.p.gridview = true;
  2347. }
  2348. if(this.p.treeGrid === true) {
  2349. try { $(this).jqGrid("setTreeGrid");} catch (_) {}
  2350. if(ts.p.datatype !== "local") { ts.p.localReader = {id: "_id_"}; }
  2351. }
  2352. if(this.p.subGrid) {
  2353. try { $(ts).jqGrid("setSubGrid");} catch (s){}
  2354. }
  2355. if(this.p.multiselect) {
  2356. this.p.colNames.unshift("<input role='checkbox' id='cb_"+this.p.id+"' class='cbox' type='checkbox'/>");
  2357. 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});
  2358. }
  2359. if(this.p.rownumbers) {
  2360. this.p.colNames.unshift("");
  2361. this.p.colModel.unshift({name:'rn',width:ts.p.rownumWidth,sortable:false,resizable:false,hidedlg:true,search:false,align:'center',fixed:true});
  2362. }
  2363. ts.p.xmlReader = $.extend(true,{
  2364. root: "rows",
  2365. row: "row",
  2366. page: "rows>page",
  2367. total: "rows>total",
  2368. records : "rows>records",
  2369. repeatitems: true,
  2370. cell: "cell",
  2371. id: "[id]",
  2372. userdata: "userdata",
  2373. subgrid: {root:"rows", row: "row", repeatitems: true, cell:"cell"}
  2374. }, ts.p.xmlReader);
  2375. ts.p.jsonReader = $.extend(true,{
  2376. root: "rows",
  2377. page: "page",
  2378. total: "total",
  2379. records: "records",
  2380. repeatitems: true,
  2381. cell: "cell",
  2382. id: "id",
  2383. userdata: "userdata",
  2384. subgrid: {root:"rows", repeatitems: true, cell:"cell"}
  2385. },ts.p.jsonReader);
  2386. ts.p.localReader = $.extend(true,{
  2387. root: "rows",
  2388. page: "page",
  2389. total: "total",
  2390. records: "records",
  2391. repeatitems: false,
  2392. cell: "cell",
  2393. id: "id",
  2394. userdata: "userdata",
  2395. subgrid: {root:"rows", repeatitems: true, cell:"cell"}
  2396. },ts.p.localReader);
  2397. if(ts.p.scroll){
  2398. ts.p.pgbuttons = false; ts.p.pginput=false; ts.p.rowList=[];
  2399. }
  2400. if(ts.p.data.length) { refreshIndex(); }
  2401. var thead = "<thead><tr class='ui-jqgrid-labels' role='rowheader'>",
  2402. tdc, idn, w, res, sort,
  2403. td, ptr, tbody, imgs,iac="",idc="",sortarr=[], sortord=[], sotmp=[];
  2404. if(ts.p.shrinkToFit===true && ts.p.forceFit===true) {
  2405. for (i=ts.p.colModel.length-1;i>=0;i--){
  2406. if(!ts.p.colModel[i].hidden) {
  2407. ts.p.colModel[i].resizable=false;
  2408. break;
  2409. }
  2410. }
  2411. }
  2412. if(ts.p.viewsortcols[1] === 'horizontal') {iac=" ui-i-asc";idc=" ui-i-desc";}
  2413. tdc = isMSIE ? "class='ui-th-div-ie'" :"";
  2414. 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>";
  2415. 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>";
  2416. if(ts.p.multiSort) {
  2417. sortarr = ts.p.sortname.split(",");
  2418. for (i=0; i<sortarr.length; i++) {
  2419. sotmp = $.trim(sortarr[i]).split(" ");
  2420. sortarr[i] = $.trim(sotmp[0]);
  2421. sortord[i] = sotmp[1] ? $.trim(sotmp[1]) : ts.p.sortorder || "asc";
  2422. }
  2423. }
  2424. for(i=0;i<this.p.colNames.length;i++){
  2425. var tooltip = ts.p.headertitles ? (" title=\""+$.jgrid.stripHtml(ts.p.colNames[i])+"\"") :"";
  2426. thead += "<th id='"+ts.p.id+"_"+ts.p.colModel[i].name+"' role='columnheader' class='ui-state-default ui-th-column ui-th-"+dir+"'"+ tooltip+">";
  2427. idn = ts.p.colModel[i].index || ts.p.colModel[i].name;
  2428. thead += "<div id='jqgh_"+ts.p.id+"_"+ts.p.colModel[i].name+"' "+tdc+">"+ts.p.colNames[i];
  2429. if(!ts.p.colModel[i].width) { ts.p.colModel[i].width = 150; }
  2430. else { ts.p.colModel[i].width = parseInt(ts.p.colModel[i].width,10); }
  2431. if(typeof ts.p.colModel[i].title !== "boolean") { ts.p.colModel[i].title = true; }
  2432. ts.p.colModel[i].lso = "";
  2433. if (idn === ts.p.sortname) {
  2434. ts.p.lastsort = i;
  2435. }
  2436. if(ts.p.multiSort) {
  2437. sotmp = $.inArray(idn,sortarr);
  2438. if( sotmp !== -1 ) {
  2439. ts.p.colModel[i].lso = sortord[sotmp];
  2440. }
  2441. }
  2442. thead += imgs+"</div></th>";
  2443. }
  2444. thead += "</tr></thead>";
  2445. imgs = null;
  2446. $(this).append(thead);
  2447. $("thead tr:first th",this).hover(function(){$(this).addClass('ui-state-hover');},function(){$(this).removeClass('ui-state-hover');});
  2448. if(this.p.multiselect) {
  2449. var emp=[], chk;
  2450. $('#cb_'+$.jgrid.jqID(ts.p.id),this).bind('click',function(){
  2451. ts.p.selarrrow = [];
  2452. var froz = ts.p.frozenColumns === true ? ts.p.id + "_frozen" : "";
  2453. if (this.checked) {
  2454. $(ts.rows).each(function(i) {
  2455. if (i>0) {
  2456. if(!$(this).hasClass("ui-subgrid") && !$(this).hasClass("jqgroup") && !$(this).hasClass('ui-state-disabled')){
  2457. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id) )[ts.p.useProp ? 'prop': 'attr']("checked",true);
  2458. $(this).addClass("ui-state-highlight").attr("aria-selected","true");
  2459. ts.p.selarrrow.push(this.id);
  2460. ts.p.selrow = this.id;
  2461. if(froz) {
  2462. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id), ts.grid.fbDiv )[ts.p.useProp ? 'prop': 'attr']("checked",true);
  2463. $("#"+$.jgrid.jqID(this.id), ts.grid.fbDiv).addClass("ui-state-highlight");
  2464. }
  2465. }
  2466. }
  2467. });
  2468. chk=true;
  2469. emp=[];
  2470. }
  2471. else {
  2472. $(ts.rows).each(function(i) {
  2473. if(i>0) {
  2474. if(!$(this).hasClass("ui-subgrid") && !$(this).hasClass('ui-state-disabled')){
  2475. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id) )[ts.p.useProp ? 'prop': 'attr']("checked", false);
  2476. $(this).removeClass("ui-state-highlight").attr("aria-selected","false");
  2477. emp.push(this.id);
  2478. if(froz) {
  2479. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(this.id), ts.grid.fbDiv )[ts.p.useProp ? 'prop': 'attr']("checked",false);
  2480. $("#"+$.jgrid.jqID(this.id), ts.grid.fbDiv).removeClass("ui-state-highlight");
  2481. }
  2482. }
  2483. }
  2484. });
  2485. ts.p.selrow = null;
  2486. chk=false;
  2487. }
  2488. $(ts).triggerHandler("jqGridSelectAll", [chk ? ts.p.selarrrow : emp, chk]);
  2489. if($.isFunction(ts.p.onSelectAll)) {ts.p.onSelectAll.call(ts, chk ? ts.p.selarrrow : emp,chk);}
  2490. });
  2491. }
  2492. if(ts.p.autowidth===true) {
  2493. var pw = $(eg).innerWidth();
  2494. ts.p.width = pw > 0? pw: 'nw';
  2495. }
  2496. setColWidth();
  2497. $(eg).css("width",grid.width+"px").append("<div class='ui-jqgrid-resize-mark' id='rs_m"+ts.p.id+"'>&#160;</div>");
  2498. $(gv).css("width",grid.width+"px");
  2499. thead = $("thead:first",ts).get(0);
  2500. var tfoot = "";
  2501. if(ts.p.footerrow) { tfoot += "<table role='grid' style='width:"+ts.p.tblwidth+"px' class='ui-jqgrid-ftable' cellspacing='0' cellpadding='0' border='0'><tbody><tr role='row' class='ui-widget-content footrow footrow-"+dir+"'>"; }
  2502. var thr = $("tr:first",thead),
  2503. firstr = "<tr class='jqgfirstrow' role='row' style='height:auto'>";
  2504. ts.p.disableClick=false;
  2505. $("th",thr).each(function ( j ) {
  2506. w = ts.p.colModel[j].width;
  2507. if(ts.p.colModel[j].resizable === undefined) {ts.p.colModel[j].resizable = true;}
  2508. if(ts.p.colModel[j].resizable){
  2509. res = document.createElement("span");
  2510. $(res).html("&#160;").addClass('ui-jqgrid-resize ui-jqgrid-resize-'+dir)
  2511. .css("cursor","col-resize");
  2512. $(this).addClass(ts.p.resizeclass);
  2513. } else {
  2514. res = "";
  2515. }
  2516. $(this).css("width",w+"px").prepend(res);
  2517. var hdcol = "";
  2518. if( ts.p.colModel[j].hidden ) {
  2519. $(this).css("display","none");
  2520. hdcol = "display:none;";
  2521. }
  2522. firstr += "<td role='gridcell' style='height:0px;width:"+w+"px;"+hdcol+"'></td>";
  2523. grid.headers[j] = { width: w, el: this };
  2524. sort = ts.p.colModel[j].sortable;
  2525. if( typeof sort !== 'boolean') {ts.p.colModel[j].sortable = true; sort=true;}
  2526. var nm = ts.p.colModel[j].name;
  2527. if( !(nm === 'cb' || nm==='subgrid' || nm==='rn') ) {
  2528. if(ts.p.viewsortcols[2]){
  2529. $(">div",this).addClass('ui-jqgrid-sortable');
  2530. }
  2531. }
  2532. if(sort) {
  2533. if(ts.p.multiSort) {
  2534. if(ts.p.viewsortcols[0]) {
  2535. $("div span.s-ico",this).show();
  2536. if(ts.p.colModel[j].lso){
  2537. $("div span.ui-icon-"+ts.p.colModel[j].lso,this).removeClass("ui-state-disabled");
  2538. }
  2539. } else if( ts.p.colModel[j].lso) {
  2540. $("div span.s-ico",this).show();
  2541. $("div span.ui-icon-"+ts.p.colModel[j].lso,this).removeClass("ui-state-disabled");
  2542. }
  2543. } else {
  2544. 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");}}
  2545. else if( j === ts.p.lastsort) {$("div span.s-ico",this).show();$("div span.ui-icon-"+ts.p.sortorder,this).removeClass("ui-state-disabled");}
  2546. }
  2547. }
  2548. if(ts.p.footerrow) { tfoot += "<td role='gridcell' "+formatCol(j,0,'', null, '', false)+">&#160;</td>"; }
  2549. }).mousedown(function(e) {
  2550. if ($(e.target).closest("th>span.ui-jqgrid-resize").length !== 1) { return; }
  2551. var ci = getColumnHeaderIndex(this);
  2552. if(ts.p.forceFit===true) {ts.p.nv= nextVisible(ci);}
  2553. grid.dragStart(ci, e, getOffset(ci));
  2554. return false;
  2555. }).click(function(e) {
  2556. if (ts.p.disableClick) {
  2557. ts.p.disableClick = false;
  2558. return false;
  2559. }
  2560. var s = "th>div.ui-jqgrid-sortable",r,d;
  2561. if (!ts.p.viewsortcols[2]) { s = "th>div>span>span.ui-grid-ico-sort"; }
  2562. var t = $(e.target).closest(s);
  2563. if (t.length !== 1) { return; }
  2564. var ci;
  2565. if(ts.p.frozenColumns) {
  2566. var tid = $(this)[0].id.substring(5);
  2567. $(ts.p.colModel).each(function(i){
  2568. if (this.name === tid) {
  2569. ci = i;return false;
  2570. }
  2571. });
  2572. } else {
  2573. ci = getColumnHeaderIndex(this);
  2574. }
  2575. if (!ts.p.viewsortcols[2]) { r=true;d=t.attr("sort"); }
  2576. if(ci != null){
  2577. sortData( $('div',this)[0].id, ci, r, d, this);
  2578. }
  2579. return false;
  2580. });
  2581. if (ts.p.sortable && $.fn.sortable) {
  2582. try {
  2583. $(ts).jqGrid("sortableColumns", thr);
  2584. } catch (e){}
  2585. }
  2586. if(ts.p.footerrow) { tfoot += "</tr></tbody></table>"; }
  2587. firstr += "</tr>";
  2588. tbody = document.createElement("tbody");
  2589. this.appendChild(tbody);
  2590. $(this).addClass('ui-jqgrid-btable').append(firstr);
  2591. firstr = null;
  2592. var hTable = $("<table class='ui-jqgrid-htable' style='width:"+ts.p.tblwidth+"px' role='grid' aria-labelledby='gbox_"+this.id+"' cellspacing='0' cellpadding='0' border='0'></table>").append(thead),
  2593. hg = (ts.p.caption && ts.p.hiddengrid===true) ? true : false,
  2594. hb = $("<div class='ui-jqgrid-hbox" + (dir==="rtl" ? "-rtl" : "" )+"'></div>");
  2595. thead = null;
  2596. grid.hDiv = document.createElement("div");
  2597. $(grid.hDiv)
  2598. .css({ width: grid.width+"px"})
  2599. .addClass("ui-state-default ui-jqgrid-hdiv")
  2600. .append(hb);
  2601. $(hb).append(hTable);
  2602. hTable = null;
  2603. if(hg) { $(grid.hDiv).hide(); }
  2604. if(ts.p.pager){
  2605. // TBD -- escape ts.p.pager here?
  2606. if(typeof ts.p.pager === "string") {if(ts.p.pager.substr(0,1) !== "#") { ts.p.pager = "#"+ts.p.pager;} }
  2607. else { ts.p.pager = "#"+ $(ts.p.pager).attr("id");}
  2608. $(ts.p.pager).css({width: grid.width+"px"}).addClass('ui-state-default ui-jqgrid-pager ui-corner-bottom').appendTo(eg);
  2609. if(hg) {$(ts.p.pager).hide();}
  2610. setPager(ts.p.pager,'');
  2611. }
  2612. if( ts.p.cellEdit === false && ts.p.hoverrows === true) {
  2613. $(ts).bind('mouseover',function(e) {
  2614. ptr = $(e.target).closest("tr.jqgrow");
  2615. if($(ptr).attr("class") !== "ui-subgrid") {
  2616. $(ptr).addClass("ui-state-hover");
  2617. }
  2618. }).bind('mouseout',function(e) {
  2619. ptr = $(e.target).closest("tr.jqgrow");
  2620. $(ptr).removeClass("ui-state-hover");
  2621. });
  2622. }
  2623. var ri,ci, tdHtml;
  2624. $(ts).before(grid.hDiv).click(function(e) {
  2625. td = e.target;
  2626. ptr = $(td,ts.rows).closest("tr.jqgrow");
  2627. 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 ) {
  2628. return this;
  2629. }
  2630. var scb = $(td).hasClass("cbox"),
  2631. cSel = $(ts).triggerHandler("jqGridBeforeSelectRow", [ptr[0].id, e]);
  2632. cSel = (cSel === false || cSel === 'stop') ? false : true;
  2633. if(cSel && $.isFunction(ts.p.beforeSelectRow)) { cSel = ts.p.beforeSelectRow.call(ts,ptr[0].id, e); }
  2634. if (td.tagName === 'A' || ((td.tagName === 'INPUT' || td.tagName === 'TEXTAREA' || td.tagName === 'OPTION' || td.tagName === 'SELECT' ) && !scb) ) { return; }
  2635. if(cSel === true) {
  2636. ri = ptr[0].id;
  2637. ci = $.jgrid.getCellIndex(td);
  2638. tdHtml = $(td).closest("td,th").html();
  2639. $(ts).triggerHandler("jqGridCellSelect", [ri,ci,tdHtml,e]);
  2640. if($.isFunction(ts.p.onCellSelect)) {
  2641. ts.p.onCellSelect.call(ts,ri,ci,tdHtml,e);
  2642. }
  2643. if(ts.p.cellEdit === true) {
  2644. if(ts.p.multiselect && scb){
  2645. $(ts).jqGrid("setSelection", ri ,true,e);
  2646. } else {
  2647. ri = ptr[0].rowIndex;
  2648. try {$(ts).jqGrid("editCell",ri,ci,true);} catch (_) {}
  2649. }
  2650. } else if ( !ts.p.multikey ) {
  2651. if(ts.p.multiselect && ts.p.multiboxonly) {
  2652. if(scb){$(ts).jqGrid("setSelection",ri,true,e);}
  2653. else {
  2654. var frz = ts.p.frozenColumns ? ts.p.id+"_frozen" : "";
  2655. $(ts.p.selarrrow).each(function(i,n){
  2656. var ind = ts.rows.namedItem(n);
  2657. $(ind).removeClass("ui-state-highlight");
  2658. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(n))[ts.p.useProp ? 'prop': 'attr']("checked", false);
  2659. if(frz) {
  2660. $("#"+$.jgrid.jqID(n), "#"+$.jgrid.jqID(frz)).removeClass("ui-state-highlight");
  2661. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+$.jgrid.jqID(n), "#"+$.jgrid.jqID(frz))[ts.p.useProp ? 'prop': 'attr']("checked", false);
  2662. }
  2663. });
  2664. ts.p.selarrrow = [];
  2665. $(ts).jqGrid("setSelection",ri,true,e);
  2666. }
  2667. } else {
  2668. $(ts).jqGrid("setSelection",ri,true,e);
  2669. }
  2670. } else {
  2671. if(e[ts.p.multikey]) {
  2672. $(ts).jqGrid("setSelection",ri,true,e);
  2673. } else if(ts.p.multiselect && scb) {
  2674. scb = $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+ri).is(":checked");
  2675. $("#jqg_"+$.jgrid.jqID(ts.p.id)+"_"+ri)[ts.p.useProp ? 'prop' : 'attr']("checked", scb);
  2676. }
  2677. }
  2678. }
  2679. }).bind('reloadGrid', function(e,opts) {
  2680. if(ts.p.treeGrid ===true) { ts.p.datatype = ts.p.treedatatype;}
  2681. if (opts && opts.current) {
  2682. ts.grid.selectionPreserver(ts);
  2683. }
  2684. if(ts.p.datatype==="local"){ $(ts).jqGrid("resetSelection"); if(ts.p.data.length) { refreshIndex();} }
  2685. else if(!ts.p.treeGrid) {
  2686. ts.p.selrow=null;
  2687. if(ts.p.multiselect) {ts.p.selarrrow =[];setHeadCheckBox(false);}
  2688. ts.p.savedRow = [];
  2689. }
  2690. if(ts.p.scroll) {emptyRows.call(ts, true, false);}
  2691. if (opts && opts.page) {
  2692. var page = opts.page;
  2693. if (page > ts.p.lastpage) { page = ts.p.lastpage; }
  2694. if (page < 1) { page = 1; }
  2695. ts.p.page = page;
  2696. if (ts.grid.prevRowHeight) {
  2697. ts.grid.bDiv.scrollTop = (page - 1) * ts.grid.prevRowHeight * ts.p.rowNum;
  2698. } else {
  2699. ts.grid.bDiv.scrollTop = 0;
  2700. }
  2701. }
  2702. if (ts.grid.prevRowHeight && ts.p.scroll) {
  2703. delete ts.p.lastpage;
  2704. ts.grid.populateVisible();
  2705. } else {
  2706. ts.grid.populate();
  2707. }
  2708. if(ts.p._inlinenav===true) {$(ts).jqGrid('showAddEditButtons');}
  2709. return false;
  2710. })
  2711. .dblclick(function(e) {
  2712. td = e.target;
  2713. ptr = $(td,ts.rows).closest("tr.jqgrow");
  2714. if($(ptr).length === 0 ){return;}
  2715. ri = ptr[0].rowIndex;
  2716. ci = $.jgrid.getCellIndex(td);
  2717. $(ts).triggerHandler("jqGridDblClickRow", [$(ptr).attr("id"),ri,ci,e]);
  2718. if ($.isFunction(ts.p.ondblClickRow)) { ts.p.ondblClickRow.call(ts,$(ptr).attr("id"),ri,ci, e); }
  2719. })
  2720. .bind('contextmenu', function(e) {
  2721. td = e.target;
  2722. ptr = $(td,ts.rows).closest("tr.jqgrow");
  2723. if($(ptr).length === 0 ){return;}
  2724. if(!ts.p.multiselect) { $(ts).jqGrid("setSelection",ptr[0].id,true,e); }
  2725. ri = ptr[0].rowIndex;
  2726. ci = $.jgrid.getCellIndex(td);
  2727. $(ts).triggerHandler("jqGridRightClickRow", [$(ptr).attr("id"),ri,ci,e]);
  2728. if ($.isFunction(ts.p.onRightClickRow)) { ts.p.onRightClickRow.call(ts,$(ptr).attr("id"),ri,ci, e); }
  2729. });
  2730. grid.bDiv = document.createElement("div");
  2731. if(isMSIE) { if(String(ts.p.height).toLowerCase() === "auto") { ts.p.height = "100%"; } }
  2732. $(grid.bDiv)
  2733. .append($('<div style="position:relative;'+(isMSIE && $.jgrid.msiever() < 8 ? "height:0.01%;" : "")+'"></div>').append('<div></div>').append(this))
  2734. .addClass("ui-jqgrid-bdiv")
  2735. .css({ height: ts.p.height+(isNaN(ts.p.height)?"":"px"), width: (grid.width)+"px"})
  2736. .scroll(grid.scrollGrid);
  2737. $("table:first",grid.bDiv).css({width:ts.p.tblwidth+"px"});
  2738. if( !$.support.tbody ) { //IE
  2739. if( $("tbody",this).length === 2 ) { $("tbody:gt(0)",this).remove();}
  2740. }
  2741. if(ts.p.multikey){
  2742. if( $.jgrid.msie) {
  2743. $(grid.bDiv).bind("selectstart",function(){return false;});
  2744. } else {
  2745. $(grid.bDiv).bind("mousedown",function(){return false;});
  2746. }
  2747. }
  2748. if(hg) {$(grid.bDiv).hide();}
  2749. grid.cDiv = document.createElement("div");
  2750. var arf = ts.p.hidegrid===true ? $("<a role='link' href='javascript:void(0)'/>").addClass('ui-jqgrid-titlebar-close HeaderButton').hover(
  2751. function(){ arf.addClass('ui-state-hover');},
  2752. function() {arf.removeClass('ui-state-hover');})
  2753. .append("<span class='ui-icon ui-icon-circle-triangle-n'></span>").css((dir==="rtl"?"left":"right"),"0px") : "";
  2754. $(grid.cDiv).append(arf).append("<span class='ui-jqgrid-title"+(dir==="rtl" ? "-rtl" :"" )+"'>"+ts.p.caption+"</span>")
  2755. .addClass("ui-jqgrid-titlebar ui-widget-header ui-corner-top ui-helper-clearfix");
  2756. $(grid.cDiv).insertBefore(grid.hDiv);
  2757. if( ts.p.toolbar[0] ) {
  2758. grid.uDiv = document.createElement("div");
  2759. if(ts.p.toolbar[1] === "top") {$(grid.uDiv).insertBefore(grid.hDiv);}
  2760. else if (ts.p.toolbar[1]==="bottom" ) {$(grid.uDiv).insertAfter(grid.hDiv);}
  2761. if(ts.p.toolbar[1]==="both") {
  2762. grid.ubDiv = document.createElement("div");
  2763. $(grid.uDiv).addClass("ui-userdata ui-state-default").attr("id","t_"+this.id).insertBefore(grid.hDiv);
  2764. $(grid.ubDiv).addClass("ui-userdata ui-state-default").attr("id","tb_"+this.id).insertAfter(grid.hDiv);
  2765. if(hg) {$(grid.ubDiv).hide();}
  2766. } else {
  2767. $(grid.uDiv).width(grid.width).addClass("ui-userdata ui-state-default").attr("id","t_"+this.id);
  2768. }
  2769. if(hg) {$(grid.uDiv).hide();}
  2770. }
  2771. if(ts.p.toppager) {
  2772. ts.p.toppager = $.jgrid.jqID(ts.p.id)+"_toppager";
  2773. grid.topDiv = $("<div id='"+ts.p.toppager+"'></div>")[0];
  2774. ts.p.toppager = "#"+ts.p.toppager;
  2775. $(grid.topDiv).addClass('ui-state-default ui-jqgrid-toppager').width(grid.width).insertBefore(grid.hDiv);
  2776. setPager(ts.p.toppager,'_t');
  2777. }
  2778. if(ts.p.footerrow) {
  2779. grid.sDiv = $("<div class='ui-jqgrid-sdiv'></div>")[0];
  2780. hb = $("<div class='ui-jqgrid-hbox"+(dir==="rtl"?"-rtl":"")+"'></div>");
  2781. $(grid.sDiv).append(hb).width(grid.width).insertAfter(grid.hDiv);
  2782. $(hb).append(tfoot);
  2783. grid.footers = $(".ui-jqgrid-ftable",grid.sDiv)[0].rows[0].cells;
  2784. if(ts.p.rownumbers) { grid.footers[0].className = 'ui-state-default jqgrid-rownum'; }
  2785. if(hg) {$(grid.sDiv).hide();}
  2786. }
  2787. hb = null;
  2788. if(ts.p.caption) {
  2789. var tdt = ts.p.datatype;
  2790. if(ts.p.hidegrid===true) {
  2791. $(".ui-jqgrid-titlebar-close",grid.cDiv).click( function(e){
  2792. var onHdCl = $.isFunction(ts.p.onHeaderClick),
  2793. elems = ".ui-jqgrid-bdiv, .ui-jqgrid-hdiv, .ui-jqgrid-pager, .ui-jqgrid-sdiv",
  2794. counter, self = this;
  2795. if(ts.p.toolbar[0]===true) {
  2796. if( ts.p.toolbar[1]==='both') {
  2797. elems += ', #' + $(grid.ubDiv).attr('id');
  2798. }
  2799. elems += ', #' + $(grid.uDiv).attr('id');
  2800. }
  2801. counter = $(elems,"#gview_"+$.jgrid.jqID(ts.p.id)).length;
  2802. if(ts.p.gridstate === 'visible') {
  2803. $(elems,"#gbox_"+$.jgrid.jqID(ts.p.id)).slideUp("fast", function() {
  2804. counter--;
  2805. if (counter === 0) {
  2806. $("span",self).removeClass("ui-icon-circle-triangle-n").addClass("ui-icon-circle-triangle-s");
  2807. ts.p.gridstate = 'hidden';
  2808. if($("#gbox_"+$.jgrid.jqID(ts.p.id)).hasClass("ui-resizable")) { $(".ui-resizable-handle","#gbox_"+$.jgrid.jqID(ts.p.id)).hide(); }
  2809. $(ts).triggerHandler("jqGridHeaderClick", [ts.p.gridstate,e]);
  2810. if(onHdCl) {if(!hg) {ts.p.onHeaderClick.call(ts,ts.p.gridstate,e);}}
  2811. }
  2812. });
  2813. } else if(ts.p.gridstate === 'hidden'){
  2814. $(elems,"#gbox_"+$.jgrid.jqID(ts.p.id)).slideDown("fast", function() {
  2815. counter--;
  2816. if (counter === 0) {
  2817. $("span",self).removeClass("ui-icon-circle-triangle-s").addClass("ui-icon-circle-triangle-n");
  2818. if(hg) {ts.p.datatype = tdt;populate();hg=false;}
  2819. ts.p.gridstate = 'visible';
  2820. if($("#gbox_"+$.jgrid.jqID(ts.p.id)).hasClass("ui-resizable")) { $(".ui-resizable-handle","#gbox_"+$.jgrid.jqID(ts.p.id)).show(); }
  2821. $(ts).triggerHandler("jqGridHeaderClick", [ts.p.gridstate,e]);
  2822. if(onHdCl) {if(!hg) {ts.p.onHeaderClick.call(ts,ts.p.gridstate,e);}}
  2823. }
  2824. });
  2825. }
  2826. return false;
  2827. });
  2828. if(hg) {ts.p.datatype="local"; $(".ui-jqgrid-titlebar-close",grid.cDiv).trigger("click");}
  2829. }
  2830. } else {$(grid.cDiv).hide();}
  2831. $(grid.hDiv).after(grid.bDiv)
  2832. .mousemove(function (e) {
  2833. if(grid.resizing){grid.dragMove(e);return false;}
  2834. });
  2835. $(".ui-jqgrid-labels",grid.hDiv).bind("selectstart", function () { return false; });
  2836. $(document).mouseup(function () {
  2837. if(grid.resizing) { grid.dragEnd(); return false;}
  2838. return true;
  2839. });
  2840. ts.formatCol = formatCol;
  2841. ts.sortData = sortData;
  2842. ts.updatepager = updatepager;
  2843. ts.refreshIndex = refreshIndex;
  2844. ts.setHeadCheckBox = setHeadCheckBox;
  2845. ts.constructTr = constructTr;
  2846. ts.formatter = function ( rowId, cellval , colpos, rwdat, act){return formatter(rowId, cellval , colpos, rwdat, act);};
  2847. $.extend(grid,{populate : populate, emptyRows: emptyRows});
  2848. this.grid = grid;
  2849. ts.addXmlData = function(d) {addXmlData(d,ts.grid.bDiv);};
  2850. ts.addJSONData = function(d) {addJSONData(d,ts.grid.bDiv);};
  2851. this.grid.cols = this.rows[0].cells;
  2852. $(ts).triggerHandler("jqGridInitGrid");
  2853. if ($.isFunction( ts.p.onInitGrid )) { ts.p.onInitGrid.call(ts); }
  2854. populate();ts.p.hiddengrid=false;
  2855. });
  2856. };
  2857. $.jgrid.extend({
  2858. getGridParam : function(pName) {
  2859. var $t = this[0];
  2860. if (!$t || !$t.grid) {return;}
  2861. if (!pName) { return $t.p; }
  2862. return $t.p[pName] !== undefined ? $t.p[pName] : null;
  2863. },
  2864. setGridParam : function (newParams){
  2865. return this.each(function(){
  2866. if (this.grid && typeof newParams === 'object') {$.extend(true,this.p,newParams);}
  2867. });
  2868. },
  2869. getDataIDs : function () {
  2870. var ids=[], i=0, len, j=0;
  2871. this.each(function(){
  2872. len = this.rows.length;
  2873. if(len && len>0){
  2874. while(i<len) {
  2875. if($(this.rows[i]).hasClass('jqgrow')) {
  2876. ids[j] = this.rows[i].id;
  2877. j++;
  2878. }
  2879. i++;
  2880. }
  2881. }
  2882. });
  2883. return ids;
  2884. },
  2885. setSelection : function(selection,onsr, e) {
  2886. return this.each(function(){
  2887. var $t = this, stat,pt, ner, ia, tpsr, fid;
  2888. if(selection === undefined) { return; }
  2889. onsr = onsr === false ? false : true;
  2890. pt=$t.rows.namedItem(String(selection));
  2891. if(!pt || !pt.className || pt.className.indexOf( 'ui-state-disabled' ) > -1 ) { return; }
  2892. function scrGrid(iR){
  2893. var ch = $($t.grid.bDiv)[0].clientHeight,
  2894. st = $($t.grid.bDiv)[0].scrollTop,
  2895. rpos = $($t.rows[iR]).position().top,
  2896. rh = $t.rows[iR].clientHeight;
  2897. if(rpos+rh >= ch+st) { $($t.grid.bDiv)[0].scrollTop = rpos-(ch+st)+rh+st; }
  2898. else if(rpos < ch+st) {
  2899. if(rpos < st) {
  2900. $($t.grid.bDiv)[0].scrollTop = rpos;
  2901. }
  2902. }
  2903. }
  2904. if($t.p.scrollrows===true) {
  2905. ner = $t.rows.namedItem(selection).rowIndex;
  2906. if(ner >=0 ){
  2907. scrGrid(ner);
  2908. }
  2909. }
  2910. if($t.p.frozenColumns === true ) {
  2911. fid = $t.p.id+"_frozen";
  2912. }
  2913. if(!$t.p.multiselect) {
  2914. if(pt.className !== "ui-subgrid") {
  2915. if( $t.p.selrow !== pt.id) {
  2916. $($t.rows.namedItem($t.p.selrow)).removeClass("ui-state-highlight").attr({"aria-selected":"false", "tabindex" : "-1"});
  2917. $(pt).addClass("ui-state-highlight").attr({"aria-selected":"true", "tabindex" : "0"});//.focus();
  2918. if(fid) {
  2919. $("#"+$.jgrid.jqID($t.p.selrow), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight");
  2920. $("#"+$.jgrid.jqID(selection), "#"+$.jgrid.jqID(fid)).addClass("ui-state-highlight");
  2921. }
  2922. stat = true;
  2923. } else {
  2924. stat = false;
  2925. }
  2926. $t.p.selrow = pt.id;
  2927. if( onsr ) {
  2928. $($t).triggerHandler("jqGridSelectRow", [pt.id, stat, e]);
  2929. if( $t.p.onSelectRow) { $t.p.onSelectRow.call($t, pt.id, stat, e); }
  2930. }
  2931. }
  2932. } else {
  2933. //unselect selectall checkbox when deselecting a specific row
  2934. $t.setHeadCheckBox( false );
  2935. $t.p.selrow = pt.id;
  2936. ia = $.inArray($t.p.selrow,$t.p.selarrrow);
  2937. if ( ia === -1 ){
  2938. if(pt.className !== "ui-subgrid") { $(pt).addClass("ui-state-highlight").attr("aria-selected","true");}
  2939. stat = true;
  2940. $t.p.selarrrow.push($t.p.selrow);
  2941. } else {
  2942. if(pt.className !== "ui-subgrid") { $(pt).removeClass("ui-state-highlight").attr("aria-selected","false");}
  2943. stat = false;
  2944. $t.p.selarrrow.splice(ia,1);
  2945. tpsr = $t.p.selarrrow[0];
  2946. $t.p.selrow = (tpsr === undefined) ? null : tpsr;
  2947. }
  2948. $("#jqg_"+$.jgrid.jqID($t.p.id)+"_"+$.jgrid.jqID(pt.id))[$t.p.useProp ? 'prop': 'attr']("checked",stat);
  2949. if(fid) {
  2950. if(ia === -1) {
  2951. $("#"+$.jgrid.jqID(selection), "#"+$.jgrid.jqID(fid)).addClass("ui-state-highlight");
  2952. } else {
  2953. $("#"+$.jgrid.jqID(selection), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight");
  2954. }
  2955. $("#jqg_"+$.jgrid.jqID($t.p.id)+"_"+$.jgrid.jqID(selection), "#"+$.jgrid.jqID(fid))[$t.p.useProp ? 'prop': 'attr']("checked",stat);
  2956. }
  2957. if( onsr ) {
  2958. $($t).triggerHandler("jqGridSelectRow", [pt.id, stat, e]);
  2959. if( $t.p.onSelectRow) { $t.p.onSelectRow.call($t, pt.id , stat, e); }
  2960. }
  2961. }
  2962. });
  2963. },
  2964. resetSelection : function( rowid ){
  2965. return this.each(function(){
  2966. var t = this, ind, sr, fid;
  2967. if( t.p.frozenColumns === true ) {
  2968. fid = t.p.id+"_frozen";
  2969. }
  2970. if(rowid !== undefined ) {
  2971. sr = rowid === t.p.selrow ? t.p.selrow : rowid;
  2972. $("#"+$.jgrid.jqID(t.p.id)+" tbody:first tr#"+$.jgrid.jqID(sr)).removeClass("ui-state-highlight").attr("aria-selected","false");
  2973. if (fid) { $("#"+$.jgrid.jqID(sr), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight"); }
  2974. if(t.p.multiselect) {
  2975. $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(sr), "#"+$.jgrid.jqID(t.p.id))[t.p.useProp ? 'prop': 'attr']("checked",false);
  2976. if(fid) { $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(sr), "#"+$.jgrid.jqID(fid))[t.p.useProp ? 'prop': 'attr']("checked",false); }
  2977. t.setHeadCheckBox( false);
  2978. }
  2979. sr = null;
  2980. } else if(!t.p.multiselect) {
  2981. if(t.p.selrow) {
  2982. $("#"+$.jgrid.jqID(t.p.id)+" tbody:first tr#"+$.jgrid.jqID(t.p.selrow)).removeClass("ui-state-highlight").attr("aria-selected","false");
  2983. if(fid) { $("#"+$.jgrid.jqID(t.p.selrow), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight"); }
  2984. t.p.selrow = null;
  2985. }
  2986. } else {
  2987. $(t.p.selarrrow).each(function(i,n){
  2988. ind = t.rows.namedItem(n);
  2989. $(ind).removeClass("ui-state-highlight").attr("aria-selected","false");
  2990. $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(n))[t.p.useProp ? 'prop': 'attr']("checked",false);
  2991. if(fid) {
  2992. $("#"+$.jgrid.jqID(n), "#"+$.jgrid.jqID(fid)).removeClass("ui-state-highlight");
  2993. $("#jqg_"+$.jgrid.jqID(t.p.id)+"_"+$.jgrid.jqID(n), "#"+$.jgrid.jqID(fid))[t.p.useProp ? 'prop': 'attr']("checked",false);
  2994. }
  2995. });
  2996. t.setHeadCheckBox( false );
  2997. t.p.selarrrow = [];
  2998. }
  2999. if(t.p.cellEdit === true) {
  3000. if(parseInt(t.p.iCol,10)>=0 && parseInt(t.p.iRow,10)>=0) {
  3001. $("td:eq("+t.p.iCol+")",t.rows[t.p.iRow]).removeClass("edit-cell ui-state-highlight");
  3002. $(t.rows[t.p.iRow]).removeClass("selected-row ui-state-hover");
  3003. }
  3004. }
  3005. t.p.savedRow = [];
  3006. });
  3007. },
  3008. getRowData : function( rowid ) {
  3009. var res = {}, resall, getall=false, len, j=0;
  3010. this.each(function(){
  3011. var $t = this,nm,ind;
  3012. if(rowid === undefined) {
  3013. getall = true;
  3014. resall = [];
  3015. len = $t.rows.length;
  3016. } else {
  3017. ind = $t.rows.namedItem(rowid);
  3018. if(!ind) { return res; }
  3019. len = 2;
  3020. }
  3021. while(j<len){
  3022. if(getall) { ind = $t.rows[j]; }
  3023. if( $(ind).hasClass('jqgrow') ) {
  3024. $('td[role="gridcell"]',ind).each( function(i) {
  3025. nm = $t.p.colModel[i].name;
  3026. if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn') {
  3027. if($t.p.treeGrid===true && nm === $t.p.ExpandColumn) {
  3028. res[nm] = $.jgrid.htmlDecode($("span:first",this).html());
  3029. } else {
  3030. try {
  3031. res[nm] = $.unformat.call($t,this,{rowId:ind.id, colModel:$t.p.colModel[i]},i);
  3032. } catch (e){
  3033. res[nm] = $.jgrid.htmlDecode($(this).html());
  3034. }
  3035. }
  3036. }
  3037. });
  3038. if(getall) { resall.push(res); res={}; }
  3039. }
  3040. j++;
  3041. }
  3042. });
  3043. return resall || res;
  3044. },
  3045. delRowData : function(rowid) {
  3046. var success = false, rowInd, ia;
  3047. this.each(function() {
  3048. var $t = this;
  3049. rowInd = $t.rows.namedItem(rowid);
  3050. if(!rowInd) {return false;}
  3051. $(rowInd).remove();
  3052. $t.p.records--;
  3053. $t.p.reccount--;
  3054. $t.updatepager(true,false);
  3055. success=true;
  3056. if($t.p.multiselect) {
  3057. ia = $.inArray(rowid,$t.p.selarrrow);
  3058. if(ia !== -1) { $t.p.selarrrow.splice(ia,1);}
  3059. }
  3060. if ($t.p.multiselect && $t.p.selarrrow.length > 0) {
  3061. $t.p.selrow = $t.p.selarrrow[$t.p.selarrrow.length-1];
  3062. } else {
  3063. $t.p.selrow = null;
  3064. }
  3065. if($t.p.datatype === 'local') {
  3066. var id = $.jgrid.stripPref($t.p.idPrefix, rowid),
  3067. pos = $t.p._index[id];
  3068. if(pos !== undefined) {
  3069. $t.p.data.splice(pos,1);
  3070. $t.refreshIndex();
  3071. }
  3072. }
  3073. if( $t.p.altRows === true && success ) {
  3074. var cn = $t.p.altclass;
  3075. $($t.rows).each(function(i){
  3076. if(i % 2 === 1) { $(this).addClass(cn); }
  3077. else { $(this).removeClass(cn); }
  3078. });
  3079. }
  3080. });
  3081. return success;
  3082. },
  3083. setRowData : function(rowid, data, cssp) {
  3084. var nm, success=true, title;
  3085. this.each(function(){
  3086. if(!this.grid) {return false;}
  3087. var t = this, vl, ind, cp = typeof cssp, lcdata={};
  3088. ind = t.rows.namedItem(rowid);
  3089. if(!ind) { return false; }
  3090. if( data ) {
  3091. try {
  3092. $(this.p.colModel).each(function(i){
  3093. nm = this.name;
  3094. var dval =$.jgrid.getAccessor(data,nm);
  3095. if( dval !== undefined) {
  3096. lcdata[nm] = this.formatter && typeof this.formatter === 'string' && this.formatter === 'date' ? $.unformat.date.call(t,dval,this) : dval;
  3097. vl = t.formatter( rowid, dval, i, data, 'edit');
  3098. title = this.title ? {"title":$.jgrid.stripHtml(vl)} : {};
  3099. if(t.p.treeGrid===true && nm === t.p.ExpandColumn) {
  3100. $("td[role='gridcell']:eq("+i+") > span:first",ind).html(vl).attr(title);
  3101. } else {
  3102. $("td[role='gridcell']:eq("+i+")",ind).html(vl).attr(title);
  3103. }
  3104. }
  3105. });
  3106. if(t.p.datatype === 'local') {
  3107. var id = $.jgrid.stripPref(t.p.idPrefix, rowid),
  3108. pos = t.p._index[id], key;
  3109. if(t.p.treeGrid) {
  3110. for(key in t.p.treeReader){
  3111. if(t.p.treeReader.hasOwnProperty(key)) {
  3112. delete lcdata[t.p.treeReader[key]];
  3113. }
  3114. }
  3115. }
  3116. if(pos !== undefined) {
  3117. t.p.data[pos] = $.extend(true, t.p.data[pos], lcdata);
  3118. }
  3119. lcdata = null;
  3120. }
  3121. } catch (e) {
  3122. success = false;
  3123. }
  3124. }
  3125. if(success) {
  3126. if(cp === 'string') {$(ind).addClass(cssp);} else if(cp === 'object') {$(ind).css(cssp);}
  3127. $(t).triggerHandler("jqGridAfterGridComplete");
  3128. }
  3129. });
  3130. return success;
  3131. },
  3132. addRowData : function(rowid,rdata,pos,src) {
  3133. if(!pos) {pos = "last";}
  3134. var success = false, nm, row, gi, si, ni,sind, i, v, prp="", aradd, cnm, cn, data, cm, id;
  3135. if(rdata) {
  3136. if($.isArray(rdata)) {
  3137. aradd=true;
  3138. pos = "last";
  3139. cnm = rowid;
  3140. } else {
  3141. rdata = [rdata];
  3142. aradd = false;
  3143. }
  3144. this.each(function() {
  3145. var t = this, datalen = rdata.length;
  3146. ni = t.p.rownumbers===true ? 1 :0;
  3147. gi = t.p.multiselect ===true ? 1 :0;
  3148. si = t.p.subGrid===true ? 1 :0;
  3149. if(!aradd) {
  3150. if(rowid !== undefined) { rowid = String(rowid);}
  3151. else {
  3152. rowid = $.jgrid.randId();
  3153. if(t.p.keyIndex !== false) {
  3154. cnm = t.p.colModel[t.p.keyIndex+gi+si+ni].name;
  3155. if(rdata[0][cnm] !== undefined) { rowid = rdata[0][cnm]; }
  3156. }
  3157. }
  3158. }
  3159. cn = t.p.altclass;
  3160. var k = 0, cna ="", lcdata = {},
  3161. air = $.isFunction(t.p.afterInsertRow) ? true : false;
  3162. while(k < datalen) {
  3163. data = rdata[k];
  3164. row=[];
  3165. if(aradd) {
  3166. try {
  3167. rowid = data[cnm];
  3168. if(rowid===undefined) {
  3169. rowid = $.jgrid.randId();
  3170. }
  3171. }
  3172. catch (e) {rowid = $.jgrid.randId();}
  3173. cna = t.p.altRows === true ? (t.rows.length-1)%2 === 0 ? cn : "" : "";
  3174. }
  3175. id = rowid;
  3176. rowid = t.p.idPrefix + rowid;
  3177. if(ni){
  3178. prp = t.formatCol(0,1,'',null,rowid, true);
  3179. row[row.length] = "<td role=\"gridcell\" class=\"ui-state-default jqgrid-rownum\" "+prp+">0</td>";
  3180. }
  3181. if(gi) {
  3182. v = "<input role=\"checkbox\" type=\"checkbox\""+" id=\"jqg_"+t.p.id+"_"+rowid+"\" class=\"cbox\"/>";
  3183. prp = t.formatCol(ni,1,'', null, rowid, true);
  3184. row[row.length] = "<td role=\"gridcell\" "+prp+">"+v+"</td>";
  3185. }
  3186. if(si) {
  3187. row[row.length] = $(t).jqGrid("addSubGridCell",gi+ni,1);
  3188. }
  3189. for(i = gi+si+ni; i < t.p.colModel.length;i++){
  3190. cm = t.p.colModel[i];
  3191. nm = cm.name;
  3192. lcdata[nm] = data[nm];
  3193. v = t.formatter( rowid, $.jgrid.getAccessor(data,nm), i, data );
  3194. prp = t.formatCol(i,1,v, data, rowid, lcdata);
  3195. row[row.length] = "<td role=\"gridcell\" "+prp+">"+v+"</td>";
  3196. }
  3197. row.unshift( t.constructTr(rowid, false, cna, lcdata, data, false ) );
  3198. row[row.length] = "</tr>";
  3199. if(t.rows.length === 0){
  3200. $("table:first",t.grid.bDiv).append(row.join(''));
  3201. } else {
  3202. switch (pos) {
  3203. case 'last':
  3204. $(t.rows[t.rows.length-1]).after(row.join(''));
  3205. sind = t.rows.length-1;
  3206. break;
  3207. case 'first':
  3208. $(t.rows[0]).after(row.join(''));
  3209. sind = 1;
  3210. break;
  3211. case 'after':
  3212. sind = t.rows.namedItem(src);
  3213. if (sind) {
  3214. if($(t.rows[sind.rowIndex+1]).hasClass("ui-subgrid")) { $(t.rows[sind.rowIndex+1]).after(row); }
  3215. else { $(sind).after(row.join('')); }
  3216. }
  3217. sind++;
  3218. break;
  3219. case 'before':
  3220. sind = t.rows.namedItem(src);
  3221. if(sind) {$(sind).before(row.join(''));sind=sind.rowIndex;}
  3222. sind--;
  3223. break;
  3224. }
  3225. }
  3226. if(t.p.subGrid===true) {
  3227. $(t).jqGrid("addSubGrid",gi+ni, sind);
  3228. }
  3229. t.p.records++;
  3230. t.p.reccount++;
  3231. $(t).triggerHandler("jqGridAfterInsertRow", [rowid,data,data]);
  3232. if(air) { t.p.afterInsertRow.call(t,rowid,data,data); }
  3233. k++;
  3234. if(t.p.datatype === 'local') {
  3235. lcdata[t.p.localReader.id] = id;
  3236. t.p._index[id] = t.p.data.length;
  3237. t.p.data.push(lcdata);
  3238. lcdata = {};
  3239. }
  3240. }
  3241. if( t.p.altRows === true && !aradd) {
  3242. if (pos === "last") {
  3243. if ((t.rows.length-1)%2 === 1) {$(t.rows[t.rows.length-1]).addClass(cn);}
  3244. } else {
  3245. $(t.rows).each(function(i){
  3246. if(i % 2 ===1) { $(this).addClass(cn); }
  3247. else { $(this).removeClass(cn); }
  3248. });
  3249. }
  3250. }
  3251. t.updatepager(true,true);
  3252. success = true;
  3253. });
  3254. }
  3255. return success;
  3256. },
  3257. footerData : function(action,data, format) {
  3258. var nm, success=false, res={}, title;
  3259. function isEmpty(obj) {
  3260. var i;
  3261. for(i in obj) {
  3262. if (obj.hasOwnProperty(i)) { return false; }
  3263. }
  3264. return true;
  3265. }
  3266. if(action === undefined) { action = "get"; }
  3267. if(typeof format !== "boolean") { format = true; }
  3268. action = action.toLowerCase();
  3269. this.each(function(){
  3270. var t = this, vl;
  3271. if(!t.grid || !t.p.footerrow) {return false;}
  3272. if(action === "set") { if(isEmpty(data)) { return false; } }
  3273. success=true;
  3274. $(this.p.colModel).each(function(i){
  3275. nm = this.name;
  3276. if(action === "set") {
  3277. if( data[nm] !== undefined) {
  3278. vl = format ? t.formatter( "", data[nm], i, data, 'edit') : data[nm];
  3279. title = this.title ? {"title":$.jgrid.stripHtml(vl)} : {};
  3280. $("tr.footrow td:eq("+i+")",t.grid.sDiv).html(vl).attr(title);
  3281. success = true;
  3282. }
  3283. } else if(action === "get") {
  3284. res[nm] = $("tr.footrow td:eq("+i+")",t.grid.sDiv).html();
  3285. }
  3286. });
  3287. });
  3288. return action === "get" ? res : success;
  3289. },
  3290. showHideCol : function(colname,show) {
  3291. return this.each(function() {
  3292. var $t = this, fndh=false, brd=$.jgrid.cell_width ? 0: $t.p.cellLayout, cw;
  3293. if (!$t.grid ) {return;}
  3294. if( typeof colname === 'string') {colname=[colname];}
  3295. show = show !== "none" ? "" : "none";
  3296. var sw = show === "" ? true :false,
  3297. gh = $t.p.groupHeader && (typeof $t.p.groupHeader === 'object' || $.isFunction($t.p.groupHeader) );
  3298. if(gh) { $($t).jqGrid('destroyGroupHeader', false); }
  3299. $(this.p.colModel).each(function(i) {
  3300. if ($.inArray(this.name,colname) !== -1 && this.hidden === sw) {
  3301. if($t.p.frozenColumns === true && this.frozen === true) {
  3302. return true;
  3303. }
  3304. $("tr",$t.grid.hDiv).each(function(){
  3305. $(this.cells[i]).css("display", show);
  3306. });
  3307. $($t.rows).each(function(){
  3308. if (!$(this).hasClass("jqgroup")) {
  3309. $(this.cells[i]).css("display", show);
  3310. }
  3311. });
  3312. if($t.p.footerrow) { $("tr.footrow td:eq("+i+")", $t.grid.sDiv).css("display", show); }
  3313. cw = parseInt(this.width,10);
  3314. if(show === "none") {
  3315. $t.p.tblwidth -= cw+brd;
  3316. } else {
  3317. $t.p.tblwidth += cw+brd;
  3318. }
  3319. this.hidden = !sw;
  3320. fndh=true;
  3321. $($t).triggerHandler("jqGridShowHideCol", [sw,this.name,i]);
  3322. }
  3323. });
  3324. if(fndh===true) {
  3325. if($t.p.shrinkToFit === true && !isNaN($t.p.height)) { $t.p.tblwidth += parseInt($t.p.scrollOffset,10);}
  3326. $($t).jqGrid("setGridWidth",$t.p.shrinkToFit === true ? $t.p.tblwidth : $t.p.width );
  3327. }
  3328. if( gh ) {
  3329. $($t).jqGrid('setGroupHeaders',$t.p.groupHeader);
  3330. }
  3331. });
  3332. },
  3333. hideCol : function (colname) {
  3334. return this.each(function(){$(this).jqGrid("showHideCol",colname,"none");});
  3335. },
  3336. showCol : function(colname) {
  3337. return this.each(function(){$(this).jqGrid("showHideCol",colname,"");});
  3338. },
  3339. remapColumns : function(permutation, updateCells, keepHeader)
  3340. {
  3341. function resortArray(a) {
  3342. var ac;
  3343. if (a.length) {
  3344. ac = $.makeArray(a);
  3345. } else {
  3346. ac = $.extend({}, a);
  3347. }
  3348. $.each(permutation, function(i) {
  3349. a[i] = ac[this];
  3350. });
  3351. }
  3352. var ts = this.get(0);
  3353. function resortRows(parent, clobj) {
  3354. $(">tr"+(clobj||""), parent).each(function() {
  3355. var row = this;
  3356. var elems = $.makeArray(row.cells);
  3357. $.each(permutation, function() {
  3358. var e = elems[this];
  3359. if (e) {
  3360. row.appendChild(e);
  3361. }
  3362. });
  3363. });
  3364. }
  3365. resortArray(ts.p.colModel);
  3366. resortArray(ts.p.colNames);
  3367. resortArray(ts.grid.headers);
  3368. resortRows($("thead:first", ts.grid.hDiv), keepHeader && ":not(.ui-jqgrid-labels)");
  3369. if (updateCells) {
  3370. resortRows($("#"+$.jgrid.jqID(ts.p.id)+" tbody:first"), ".jqgfirstrow, tr.jqgrow, tr.jqfoot");
  3371. }
  3372. if (ts.p.footerrow) {
  3373. resortRows($("tbody:first", ts.grid.sDiv));
  3374. }
  3375. if (ts.p.remapColumns) {
  3376. if (!ts.p.remapColumns.length){
  3377. ts.p.remapColumns = $.makeArray(permutation);
  3378. } else {
  3379. resortArray(ts.p.remapColumns);
  3380. }
  3381. }
  3382. ts.p.lastsort = $.inArray(ts.p.lastsort, permutation);
  3383. if(ts.p.treeGrid) { ts.p.expColInd = $.inArray(ts.p.expColInd, permutation); }
  3384. $(ts).triggerHandler("jqGridRemapColumns", [permutation, updateCells, keepHeader]);
  3385. },
  3386. setGridWidth : function(nwidth, shrink) {
  3387. return this.each(function(){
  3388. if (!this.grid ) {return;}
  3389. var $t = this, cw,
  3390. initwidth = 0, brd=$.jgrid.cell_width ? 0: $t.p.cellLayout, lvc, vc=0, hs=false, scw=$t.p.scrollOffset, aw, gw=0, cr;
  3391. if(typeof shrink !== 'boolean') {
  3392. shrink=$t.p.shrinkToFit;
  3393. }
  3394. if(isNaN(nwidth)) {return;}
  3395. nwidth = parseInt(nwidth,10);
  3396. $t.grid.width = $t.p.width = nwidth;
  3397. $("#gbox_"+$.jgrid.jqID($t.p.id)).css("width",nwidth+"px");
  3398. $("#gview_"+$.jgrid.jqID($t.p.id)).css("width",nwidth+"px");
  3399. $($t.grid.bDiv).css("width",nwidth+"px");
  3400. $($t.grid.hDiv).css("width",nwidth+"px");
  3401. if($t.p.pager ) {$($t.p.pager).css("width",nwidth+"px");}
  3402. if($t.p.toppager ) {$($t.p.toppager).css("width",nwidth+"px");}
  3403. if($t.p.toolbar[0] === true){
  3404. $($t.grid.uDiv).css("width",nwidth+"px");
  3405. if($t.p.toolbar[1]==="both") {$($t.grid.ubDiv).css("width",nwidth+"px");}
  3406. }
  3407. if($t.p.footerrow) { $($t.grid.sDiv).css("width",nwidth+"px"); }
  3408. if(shrink ===false && $t.p.forceFit === true) {$t.p.forceFit=false;}
  3409. if(shrink===true) {
  3410. $.each($t.p.colModel, function() {
  3411. if(this.hidden===false){
  3412. cw = this.widthOrg;
  3413. initwidth += cw+brd;
  3414. if(this.fixed) {
  3415. gw += cw+brd;
  3416. } else {
  3417. vc++;
  3418. }
  3419. }
  3420. });
  3421. if(vc === 0) { return; }
  3422. $t.p.tblwidth = initwidth;
  3423. aw = nwidth-brd*vc-gw;
  3424. if(!isNaN($t.p.height)) {
  3425. if($($t.grid.bDiv)[0].clientHeight < $($t.grid.bDiv)[0].scrollHeight || $t.rows.length === 1){
  3426. hs = true;
  3427. aw -= scw;
  3428. }
  3429. }
  3430. initwidth =0;
  3431. var cle = $t.grid.cols.length >0;
  3432. $.each($t.p.colModel, function(i) {
  3433. if(this.hidden === false && !this.fixed){
  3434. cw = this.widthOrg;
  3435. cw = Math.round(aw*cw/($t.p.tblwidth-brd*vc-gw));
  3436. if (cw < 0) { return; }
  3437. this.width =cw;
  3438. initwidth += cw;
  3439. $t.grid.headers[i].width=cw;
  3440. $t.grid.headers[i].el.style.width=cw+"px";
  3441. if($t.p.footerrow) { $t.grid.footers[i].style.width = cw+"px"; }
  3442. if(cle) { $t.grid.cols[i].style.width = cw+"px"; }
  3443. lvc = i;
  3444. }
  3445. });
  3446. if (!lvc) { return; }
  3447. cr =0;
  3448. if (hs) {
  3449. if(nwidth-gw-(initwidth+brd*vc) !== scw){
  3450. cr = nwidth-gw-(initwidth+brd*vc)-scw;
  3451. }
  3452. } else if( Math.abs(nwidth-gw-(initwidth+brd*vc)) !== 1) {
  3453. cr = nwidth-gw-(initwidth+brd*vc);
  3454. }
  3455. $t.p.colModel[lvc].width += cr;
  3456. $t.p.tblwidth = initwidth+cr+brd*vc+gw;
  3457. if($t.p.tblwidth > nwidth) {
  3458. var delta = $t.p.tblwidth - parseInt(nwidth,10);
  3459. $t.p.tblwidth = nwidth;
  3460. cw = $t.p.colModel[lvc].width = $t.p.colModel[lvc].width-delta;
  3461. } else {
  3462. cw= $t.p.colModel[lvc].width;
  3463. }
  3464. $t.grid.headers[lvc].width = cw;
  3465. $t.grid.headers[lvc].el.style.width=cw+"px";
  3466. if(cle) { $t.grid.cols[lvc].style.width = cw+"px"; }
  3467. if($t.p.footerrow) {
  3468. $t.grid.footers[lvc].style.width = cw+"px";
  3469. }
  3470. }
  3471. if($t.p.tblwidth) {
  3472. $('table:first',$t.grid.bDiv).css("width",$t.p.tblwidth+"px");
  3473. $('table:first',$t.grid.hDiv).css("width",$t.p.tblwidth+"px");
  3474. $t.grid.hDiv.scrollLeft = $t.grid.bDiv.scrollLeft;
  3475. if($t.p.footerrow) {
  3476. $('table:first',$t.grid.sDiv).css("width",$t.p.tblwidth+"px");
  3477. }
  3478. }
  3479. });
  3480. },
  3481. setGridHeight : function (nh) {
  3482. return this.each(function (){
  3483. var $t = this;
  3484. if(!$t.grid) {return;}
  3485. var bDiv = $($t.grid.bDiv);
  3486. bDiv.css({height: nh+(isNaN(nh)?"":"px")});
  3487. if($t.p.frozenColumns === true){
  3488. //follow the original set height to use 16, better scrollbar width detection
  3489. $('#'+$.jgrid.jqID($t.p.id)+"_frozen").parent().height(bDiv.height() - 16);
  3490. }
  3491. $t.p.height = nh;
  3492. if ($t.p.scroll) { $t.grid.populateVisible(); }
  3493. });
  3494. },
  3495. setCaption : function (newcap){
  3496. return this.each(function(){
  3497. this.p.caption=newcap;
  3498. $("span.ui-jqgrid-title, span.ui-jqgrid-title-rtl",this.grid.cDiv).html(newcap);
  3499. $(this.grid.cDiv).show();
  3500. });
  3501. },
  3502. setLabel : function(colname, nData, prop, attrp ){
  3503. return this.each(function(){
  3504. var $t = this, pos=-1;
  3505. if(!$t.grid) {return;}
  3506. if(colname !== undefined) {
  3507. $($t.p.colModel).each(function(i){
  3508. if (this.name === colname) {
  3509. pos = i;return false;
  3510. }
  3511. });
  3512. } else { return; }
  3513. if(pos>=0) {
  3514. var thecol = $("tr.ui-jqgrid-labels th:eq("+pos+")",$t.grid.hDiv);
  3515. if (nData){
  3516. var ico = $(".s-ico",thecol);
  3517. $("[id^=jqgh_]",thecol).empty().html(nData).append(ico);
  3518. $t.p.colNames[pos] = nData;
  3519. }
  3520. if (prop) {
  3521. if(typeof prop === 'string') {$(thecol).addClass(prop);} else {$(thecol).css(prop);}
  3522. }
  3523. if(typeof attrp === 'object') {$(thecol).attr(attrp);}
  3524. }
  3525. });
  3526. },
  3527. setCell : function(rowid,colname,nData,cssp,attrp, forceupd) {
  3528. return this.each(function(){
  3529. var $t = this, pos =-1,v, title;
  3530. if(!$t.grid) {return;}
  3531. if(isNaN(colname)) {
  3532. $($t.p.colModel).each(function(i){
  3533. if (this.name === colname) {
  3534. pos = i;return false;
  3535. }
  3536. });
  3537. } else {pos = parseInt(colname,10);}
  3538. if(pos>=0) {
  3539. var ind = $t.rows.namedItem(rowid);
  3540. if (ind){
  3541. var tcell = $("td:eq("+pos+")",ind);
  3542. if(nData !== "" || forceupd === true) {
  3543. v = $t.formatter(rowid, nData, pos,ind,'edit');
  3544. title = $t.p.colModel[pos].title ? {"title":$.jgrid.stripHtml(v)} : {};
  3545. if($t.p.treeGrid && $(".tree-wrap",$(tcell)).length>0) {
  3546. $("span",$(tcell)).html(v).attr(title);
  3547. } else {
  3548. $(tcell).html(v).attr(title);
  3549. }
  3550. if($t.p.datatype === "local") {
  3551. var cm = $t.p.colModel[pos], index;
  3552. nData = cm.formatter && typeof cm.formatter === 'string' && cm.formatter === 'date' ? $.unformat.date.call($t,nData,cm) : nData;
  3553. index = $t.p._index[$.jgrid.stripPref($t.p.idPrefix, rowid)];
  3554. if(index !== undefined) {
  3555. $t.p.data[index][cm.name] = nData;
  3556. }
  3557. }
  3558. }
  3559. if(typeof cssp === 'string'){
  3560. $(tcell).addClass(cssp);
  3561. } else if(cssp) {
  3562. $(tcell).css(cssp);
  3563. }
  3564. if(typeof attrp === 'object') {$(tcell).attr(attrp);}
  3565. }
  3566. }
  3567. });
  3568. },
  3569. getCell : function(rowid,col) {
  3570. var ret = false;
  3571. this.each(function(){
  3572. var $t=this, pos=-1;
  3573. if(!$t.grid) {return;}
  3574. if(isNaN(col)) {
  3575. $($t.p.colModel).each(function(i){
  3576. if (this.name === col) {
  3577. pos = i;return false;
  3578. }
  3579. });
  3580. } else {pos = parseInt(col,10);}
  3581. if(pos>=0) {
  3582. var ind = $t.rows.namedItem(rowid);
  3583. if(ind) {
  3584. try {
  3585. ret = $.unformat.call($t,$("td:eq("+pos+")",ind),{rowId:ind.id, colModel:$t.p.colModel[pos]},pos);
  3586. } catch (e){
  3587. ret = $.jgrid.htmlDecode($("td:eq("+pos+")",ind).html());
  3588. }
  3589. }
  3590. }
  3591. });
  3592. return ret;
  3593. },
  3594. getCol : function (col, obj, mathopr) {
  3595. var ret = [], val, sum=0, min, max, v;
  3596. obj = typeof obj !== 'boolean' ? false : obj;
  3597. if(mathopr === undefined) { mathopr = false; }
  3598. this.each(function(){
  3599. var $t=this, pos=-1;
  3600. if(!$t.grid) {return;}
  3601. if(isNaN(col)) {
  3602. $($t.p.colModel).each(function(i){
  3603. if (this.name === col) {
  3604. pos = i;return false;
  3605. }
  3606. });
  3607. } else {pos = parseInt(col,10);}
  3608. if(pos>=0) {
  3609. var ln = $t.rows.length, i =0;
  3610. if (ln && ln>0){
  3611. while(i<ln){
  3612. if($($t.rows[i]).hasClass('jqgrow')) {
  3613. try {
  3614. val = $.unformat.call($t,$($t.rows[i].cells[pos]),{rowId:$t.rows[i].id, colModel:$t.p.colModel[pos]},pos);
  3615. } catch (e) {
  3616. val = $.jgrid.htmlDecode($t.rows[i].cells[pos].innerHTML);
  3617. }
  3618. if(mathopr) {
  3619. v = parseFloat(val);
  3620. sum += v;
  3621. if (max === undefined) {max = min = v;}
  3622. min = Math.min(min, v);
  3623. max = Math.max(max, v);
  3624. }
  3625. else if(obj) { ret.push( {id:$t.rows[i].id,value:val} ); }
  3626. else { ret.push( val ); }
  3627. }
  3628. i++;
  3629. }
  3630. if(mathopr) {
  3631. switch(mathopr.toLowerCase()){
  3632. case 'sum': ret =sum; break;
  3633. case 'avg': ret = sum/ln; break;
  3634. case 'count': ret = ln; break;
  3635. case 'min': ret = min; break;
  3636. case 'max': ret = max; break;
  3637. }
  3638. }
  3639. }
  3640. }
  3641. });
  3642. return ret;
  3643. },
  3644. clearGridData : function(clearfooter) {
  3645. return this.each(function(){
  3646. var $t = this;
  3647. if(!$t.grid) {return;}
  3648. if(typeof clearfooter !== 'boolean') { clearfooter = false; }
  3649. if($t.p.deepempty) {$("#"+$.jgrid.jqID($t.p.id)+" tbody:first tr:gt(0)").remove();}
  3650. else {
  3651. var trf = $("#"+$.jgrid.jqID($t.p.id)+" tbody:first tr:first")[0];
  3652. $("#"+$.jgrid.jqID($t.p.id)+" tbody:first").empty().append(trf);
  3653. }
  3654. if($t.p.footerrow && clearfooter) { $(".ui-jqgrid-ftable td",$t.grid.sDiv).html("&#160;"); }
  3655. $t.p.selrow = null; $t.p.selarrrow= []; $t.p.savedRow = [];
  3656. $t.p.records = 0;$t.p.page=1;$t.p.lastpage=0;$t.p.reccount=0;
  3657. $t.p.data = []; $t.p._index = {};
  3658. $t.updatepager(true,false);
  3659. });
  3660. },
  3661. getInd : function(rowid,rc){
  3662. var ret =false,rw;
  3663. this.each(function(){
  3664. rw = this.rows.namedItem(rowid);
  3665. if(rw) {
  3666. ret = rc===true ? rw: rw.rowIndex;
  3667. }
  3668. });
  3669. return ret;
  3670. },
  3671. bindKeys : function( settings ){
  3672. var o = $.extend({
  3673. onEnter: null,
  3674. onSpace: null,
  3675. onLeftKey: null,
  3676. onRightKey: null,
  3677. scrollingRows : true
  3678. },settings || {});
  3679. return this.each(function(){
  3680. var $t = this;
  3681. if( !$('body').is('[role]') ){$('body').attr('role','application');}
  3682. $t.p.scrollrows = o.scrollingRows;
  3683. $($t).keydown(function(event){
  3684. var target = $($t).find('tr[tabindex=0]')[0], id, r, mind,
  3685. expanded = $t.p.treeReader.expanded_field;
  3686. //check for arrow keys
  3687. if(target) {
  3688. mind = $t.p._index[$.jgrid.stripPref($t.p.idPrefix, target.id)];
  3689. if(event.keyCode === 37 || event.keyCode === 38 || event.keyCode === 39 || event.keyCode === 40){
  3690. // up key
  3691. if(event.keyCode === 38 ){
  3692. r = target.previousSibling;
  3693. id = "";
  3694. if(r) {
  3695. if($(r).is(":hidden")) {
  3696. while(r) {
  3697. r = r.previousSibling;
  3698. if(!$(r).is(":hidden") && $(r).hasClass('jqgrow')) {id = r.id;break;}
  3699. }
  3700. } else {
  3701. id = r.id;
  3702. }
  3703. }
  3704. $($t).jqGrid('setSelection', id, true, event);
  3705. event.preventDefault();
  3706. }
  3707. //if key is down arrow
  3708. if(event.keyCode === 40){
  3709. r = target.nextSibling;
  3710. id ="";
  3711. if(r) {
  3712. if($(r).is(":hidden")) {
  3713. while(r) {
  3714. r = r.nextSibling;
  3715. if(!$(r).is(":hidden") && $(r).hasClass('jqgrow') ) {id = r.id;break;}
  3716. }
  3717. } else {
  3718. id = r.id;
  3719. }
  3720. }
  3721. $($t).jqGrid('setSelection', id, true, event);
  3722. event.preventDefault();
  3723. }
  3724. // left
  3725. if(event.keyCode === 37 ){
  3726. if($t.p.treeGrid && $t.p.data[mind][expanded]) {
  3727. $(target).find("div.treeclick").trigger('click');
  3728. }
  3729. $($t).triggerHandler("jqGridKeyLeft", [$t.p.selrow]);
  3730. if($.isFunction(o.onLeftKey)) {
  3731. o.onLeftKey.call($t, $t.p.selrow);
  3732. }
  3733. }
  3734. // right
  3735. if(event.keyCode === 39 ){
  3736. if($t.p.treeGrid && !$t.p.data[mind][expanded]) {
  3737. $(target).find("div.treeclick").trigger('click');
  3738. }
  3739. $($t).triggerHandler("jqGridKeyRight", [$t.p.selrow]);
  3740. if($.isFunction(o.onRightKey)) {
  3741. o.onRightKey.call($t, $t.p.selrow);
  3742. }
  3743. }
  3744. }
  3745. //check if enter was pressed on a grid or treegrid node
  3746. else if( event.keyCode === 13 ){
  3747. $($t).triggerHandler("jqGridKeyEnter", [$t.p.selrow]);
  3748. if($.isFunction(o.onEnter)) {
  3749. o.onEnter.call($t, $t.p.selrow);
  3750. }
  3751. } else if(event.keyCode === 32) {
  3752. $($t).triggerHandler("jqGridKeySpace", [$t.p.selrow]);
  3753. if($.isFunction(o.onSpace)) {
  3754. o.onSpace.call($t, $t.p.selrow);
  3755. }
  3756. }
  3757. }
  3758. });
  3759. });
  3760. },
  3761. unbindKeys : function(){
  3762. return this.each(function(){
  3763. $(this).unbind('keydown');
  3764. });
  3765. },
  3766. getLocalRow : function (rowid) {
  3767. var ret = false, ind;
  3768. this.each(function(){
  3769. if(rowid !== undefined) {
  3770. ind = this.p._index[$.jgrid.stripPref(this.p.idPrefix, rowid)];
  3771. if(ind >= 0 ) {
  3772. ret = this.p.data[ind];
  3773. }
  3774. }
  3775. });
  3776. return ret;
  3777. }
  3778. });
  3779. })(jQuery);
  3780. /*jshint eqeqeq:false */
  3781. /*global jQuery */
  3782. (function($){
  3783. /**
  3784. * jqGrid extension for custom methods
  3785. * Tony Tomov tony@trirand.com
  3786. * http://trirand.com/blog/
  3787. *
  3788. * Wildraid wildraid@mail.ru
  3789. * Oleg Kiriljuk oleg.kiriljuk@ok-soft-gmbh.com
  3790. * Dual licensed under the MIT and GPL licenses:
  3791. * http://www.opensource.org/licenses/mit-license.php
  3792. * http://www.gnu.org/licenses/gpl-2.0.html
  3793. **/
  3794. "use strict";
  3795. $.jgrid.extend({
  3796. getColProp : function(colname){
  3797. var ret ={}, $t = this[0];
  3798. if ( !$t.grid ) { return false; }
  3799. var cM = $t.p.colModel, i;
  3800. for ( i=0;i<cM.length;i++ ) {
  3801. if ( cM[i].name === colname ) {
  3802. ret = cM[i];
  3803. break;
  3804. }
  3805. }
  3806. return ret;
  3807. },
  3808. setColProp : function(colname, obj){
  3809. //do not set width will not work
  3810. return this.each(function(){
  3811. if ( this.grid ) {
  3812. if ( obj ) {
  3813. var cM = this.p.colModel, i;
  3814. for ( i=0;i<cM.length;i++ ) {
  3815. if ( cM[i].name === colname ) {
  3816. $.extend(true, this.p.colModel[i],obj);
  3817. break;
  3818. }
  3819. }
  3820. }
  3821. }
  3822. });
  3823. },
  3824. sortGrid : function(colname,reload, sor){
  3825. return this.each(function(){
  3826. var $t=this,idx=-1,i;
  3827. if ( !$t.grid ) { return;}
  3828. if ( !colname ) { colname = $t.p.sortname; }
  3829. for ( i=0;i<$t.p.colModel.length;i++ ) {
  3830. if ( $t.p.colModel[i].index === colname || $t.p.colModel[i].name === colname ) {
  3831. idx = i;
  3832. break;
  3833. }
  3834. }
  3835. if ( idx !== -1 ){
  3836. var sort = $t.p.colModel[idx].sortable;
  3837. if ( typeof sort !== 'boolean' ) { sort = true; }
  3838. if ( typeof reload !=='boolean' ) { reload = false; }
  3839. if ( sort ) { $t.sortData("jqgh_"+$t.p.id+"_" + colname, idx, reload, sor); }
  3840. }
  3841. });
  3842. },
  3843. clearBeforeUnload : function () {
  3844. return this.each(function(){
  3845. var grid = this.grid;
  3846. grid.emptyRows.call(this, true, true); // this work quick enough and reduce the size of memory leaks if we have someone
  3847. //$(document).unbind("mouseup"); // TODO add namespace
  3848. $(grid.hDiv).unbind("mousemove"); // TODO add namespace
  3849. $(this).unbind();
  3850. grid.dragEnd = null;
  3851. grid.dragMove = null;
  3852. grid.dragStart = null;
  3853. grid.emptyRows = null;
  3854. grid.populate = null;
  3855. grid.populateVisible = null;
  3856. grid.scrollGrid = null;
  3857. grid.selectionPreserver = null;
  3858. grid.bDiv = null;
  3859. grid.cDiv = null;
  3860. grid.hDiv = null;
  3861. grid.cols = null;
  3862. var i, l = grid.headers.length;
  3863. for (i = 0; i < l; i++) {
  3864. grid.headers[i].el = null;
  3865. }
  3866. this.formatCol = null;
  3867. this.sortData = null;
  3868. this.updatepager = null;
  3869. this.refreshIndex = null;
  3870. this.setHeadCheckBox = null;
  3871. this.constructTr = null;
  3872. this.formatter = null;
  3873. this.addXmlData = null;
  3874. this.addJSONData = null;
  3875. });
  3876. },
  3877. GridDestroy : function () {
  3878. return this.each(function(){
  3879. if ( this.grid ) {
  3880. if ( this.p.pager ) { // if not part of grid
  3881. $(this.p.pager).remove();
  3882. }
  3883. try {
  3884. $(this).jqGrid('clearBeforeUnload');
  3885. $("#gbox_"+$.jgrid.jqID(this.id)).remove();
  3886. } catch (_) {}
  3887. }
  3888. });
  3889. },
  3890. GridUnload : function(){
  3891. return this.each(function(){
  3892. if ( !this.grid ) {return;}
  3893. var defgrid = {id: $(this).attr('id'),cl: $(this).attr('class')};
  3894. if (this.p.pager) {
  3895. $(this.p.pager).empty().removeClass("ui-state-default ui-jqgrid-pager corner-bottom");
  3896. }
  3897. var newtable = document.createElement('table');
  3898. $(newtable).attr({id:defgrid.id});
  3899. newtable.className = defgrid.cl;
  3900. var gid = $.jgrid.jqID(this.id);
  3901. $(newtable).removeClass("ui-jqgrid-btable");
  3902. if( $(this.p.pager).parents("#gbox_"+gid).length === 1 ) {
  3903. $(newtable).insertBefore("#gbox_"+gid).show();
  3904. $(this.p.pager).insertBefore("#gbox_"+gid);
  3905. } else {
  3906. $(newtable).insertBefore("#gbox_"+gid).show();
  3907. }
  3908. $(this).jqGrid('clearBeforeUnload');
  3909. $("#gbox_"+gid).remove();
  3910. });
  3911. },
  3912. setGridState : function(state) {
  3913. return this.each(function(){
  3914. if ( !this.grid ) {return;}
  3915. var $t = this;
  3916. if(state === 'hidden'){
  3917. $(".ui-jqgrid-bdiv, .ui-jqgrid-hdiv","#gview_"+$.jgrid.jqID($t.p.id)).slideUp("fast");
  3918. if($t.p.pager) {$($t.p.pager).slideUp("fast");}
  3919. if($t.p.toppager) {$($t.p.toppager).slideUp("fast");}
  3920. if($t.p.toolbar[0]===true) {
  3921. if( $t.p.toolbar[1] === 'both') {
  3922. $($t.grid.ubDiv).slideUp("fast");
  3923. }
  3924. $($t.grid.uDiv).slideUp("fast");
  3925. }
  3926. if($t.p.footerrow) { $(".ui-jqgrid-sdiv","#gbox_"+$.jgrid.jqID($t.p.id)).slideUp("fast"); }
  3927. $(".ui-jqgrid-titlebar-close span",$t.grid.cDiv).removeClass("ui-icon-circle-triangle-n").addClass("ui-icon-circle-triangle-s");
  3928. $t.p.gridstate = 'hidden';
  3929. } else if(state === 'visible') {
  3930. $(".ui-jqgrid-hdiv, .ui-jqgrid-bdiv","#gview_"+$.jgrid.jqID($t.p.id)).slideDown("fast");
  3931. if($t.p.pager) {$($t.p.pager).slideDown("fast");}
  3932. if($t.p.toppager) {$($t.p.toppager).slideDown("fast");}
  3933. if($t.p.toolbar[0]===true) {
  3934. if( $t.p.toolbar[1] === 'both') {
  3935. $($t.grid.ubDiv).slideDown("fast");
  3936. }
  3937. $($t.grid.uDiv).slideDown("fast");
  3938. }
  3939. if($t.p.footerrow) { $(".ui-jqgrid-sdiv","#gbox_"+$.jgrid.jqID($t.p.id)).slideDown("fast"); }
  3940. $(".ui-jqgrid-titlebar-close span",$t.grid.cDiv).removeClass("ui-icon-circle-triangle-s").addClass("ui-icon-circle-triangle-n");
  3941. $t.p.gridstate = 'visible';
  3942. }
  3943. });
  3944. },
  3945. filterToolbar : function(p){
  3946. p = $.extend({
  3947. autosearch: true,
  3948. searchOnEnter : true,
  3949. beforeSearch: null,
  3950. afterSearch: null,
  3951. beforeClear: null,
  3952. afterClear: null,
  3953. searchurl : '',
  3954. stringResult: false,
  3955. groupOp: 'AND',
  3956. defaultSearch : "bw",
  3957. searchOperators : false,
  3958. operandTitle : "Click to select search operation.",
  3959. operands : { "eq" :"==", "ne":"!","lt":"<","le":"<=","gt":">","ge":">=","bw":"^","bn":"!^","in":"=","ni":"!=","ew":"|","en":"!@","cn":"~","nc":"!~","nu":"#","nn":"!#"}
  3960. }, $.jgrid.search , p || {});
  3961. return this.each(function(){
  3962. var $t = this;
  3963. if(this.ftoolbar) { return; }
  3964. var triggerToolbar = function() {
  3965. var sdata={}, j=0, v, nm, sopt={},so;
  3966. $.each($t.p.colModel,function(){
  3967. var $elem = $("#gs_"+$.jgrid.jqID(this.name), (this.frozen===true && $t.p.frozenColumns === true) ? $t.grid.fhDiv : $t.grid.hDiv);
  3968. nm = this.index || this.name;
  3969. if(p.searchOperators ) {
  3970. so = $elem.parent().prev().children("a").attr("soper") || p.defaultSearch;
  3971. } else {
  3972. so = (this.searchoptions && this.searchoptions.sopt) ? this.searchoptions.sopt[0] : this.stype==='select'? 'eq' : p.defaultSearch;
  3973. }
  3974. v = this.stype === "custom" && $.isFunction(this.searchoptions.custom_value) && $elem.length > 0 && $elem[0].nodeName.toUpperCase() === "SPAN" ?
  3975. this.searchoptions.custom_value.call($t, $elem.children(".customelement:first"), "get") :
  3976. $elem.val();
  3977. if(v || so==="nu" || so==="nn") {
  3978. sdata[nm] = v;
  3979. sopt[nm] = so;
  3980. j++;
  3981. } else {
  3982. try {
  3983. delete $t.p.postData[nm];
  3984. } catch (z) {}
  3985. }
  3986. });
  3987. var sd = j>0 ? true : false;
  3988. if(p.stringResult === true || $t.p.datatype === "local") {
  3989. var ruleGroup = "{\"groupOp\":\"" + p.groupOp + "\",\"rules\":[";
  3990. var gi=0;
  3991. $.each(sdata,function(i,n){
  3992. if (gi > 0) {ruleGroup += ",";}
  3993. ruleGroup += "{\"field\":\"" + i + "\",";
  3994. ruleGroup += "\"op\":\"" + sopt[i] + "\",";
  3995. n+="";
  3996. ruleGroup += "\"data\":\"" + n.replace(/\\/g,'\\\\').replace(/\"/g,'\\"') + "\"}";
  3997. gi++;
  3998. });
  3999. ruleGroup += "]}";
  4000. $.extend($t.p.postData,{filters:ruleGroup});
  4001. $.each(['searchField', 'searchString', 'searchOper'], function(i, n){
  4002. if($t.p.postData.hasOwnProperty(n)) { delete $t.p.postData[n];}
  4003. });
  4004. } else {
  4005. $.extend($t.p.postData,sdata);
  4006. }
  4007. var saveurl;
  4008. if($t.p.searchurl) {
  4009. saveurl = $t.p.url;
  4010. $($t).jqGrid("setGridParam",{url:$t.p.searchurl});
  4011. }
  4012. var bsr = $($t).triggerHandler("jqGridToolbarBeforeSearch") === 'stop' ? true : false;
  4013. if(!bsr && $.isFunction(p.beforeSearch)){bsr = p.beforeSearch.call($t);}
  4014. if(!bsr) { $($t).jqGrid("setGridParam",{search:sd}).trigger("reloadGrid",[{page:1}]); }
  4015. if(saveurl) {$($t).jqGrid("setGridParam",{url:saveurl});}
  4016. $($t).triggerHandler("jqGridToolbarAfterSearch");
  4017. if($.isFunction(p.afterSearch)){p.afterSearch.call($t);}
  4018. },
  4019. clearToolbar = function(trigger){
  4020. var sdata={}, j=0, nm;
  4021. trigger = (typeof trigger !== 'boolean') ? true : trigger;
  4022. $.each($t.p.colModel,function(){
  4023. var v, $elem = $("#gs_"+$.jgrid.jqID(this.name),(this.frozen===true && $t.p.frozenColumns === true) ? $t.grid.fhDiv : $t.grid.hDiv);
  4024. if(this.searchoptions && this.searchoptions.defaultValue !== undefined) { v = this.searchoptions.defaultValue; }
  4025. nm = this.index || this.name;
  4026. switch (this.stype) {
  4027. case 'select' :
  4028. $elem.find("option").each(function (i){
  4029. if(i===0) { this.selected = true; }
  4030. if ($(this).val() === v) {
  4031. this.selected = true;
  4032. return false;
  4033. }
  4034. });
  4035. if ( v !== undefined ) {
  4036. // post the key and not the text
  4037. sdata[nm] = v;
  4038. j++;
  4039. } else {
  4040. try {
  4041. delete $t.p.postData[nm];
  4042. } catch(e) {}
  4043. }
  4044. break;
  4045. case 'text':
  4046. $elem.val(v);
  4047. if(v !== undefined) {
  4048. sdata[nm] = v;
  4049. j++;
  4050. } else {
  4051. try {
  4052. delete $t.p.postData[nm];
  4053. } catch (y){}
  4054. }
  4055. break;
  4056. case 'custom':
  4057. if ($.isFunction(this.searchoptions.custom_value) && $elem.length > 0 && $elem[0].nodeName.toUpperCase() === "SPAN") {
  4058. this.searchoptions.custom_value.call($t, $elem.children(".customelement:first"), "set", v);
  4059. }
  4060. break;
  4061. }
  4062. });
  4063. var sd = j>0 ? true : false;
  4064. if(p.stringResult === true || $t.p.datatype === "local") {
  4065. var ruleGroup = "{\"groupOp\":\"" + p.groupOp + "\",\"rules\":[";
  4066. var gi=0;
  4067. $.each(sdata,function(i,n){
  4068. if (gi > 0) {ruleGroup += ",";}
  4069. ruleGroup += "{\"field\":\"" + i + "\",";
  4070. ruleGroup += "\"op\":\"" + "eq" + "\",";
  4071. n+="";
  4072. ruleGroup += "\"data\":\"" + n.replace(/\\/g,'\\\\').replace(/\"/g,'\\"') + "\"}";
  4073. gi++;
  4074. });
  4075. ruleGroup += "]}";
  4076. $.extend($t.p.postData,{filters:ruleGroup});
  4077. $.each(['searchField', 'searchString', 'searchOper'], function(i, n){
  4078. if($t.p.postData.hasOwnProperty(n)) { delete $t.p.postData[n];}
  4079. });
  4080. } else {
  4081. $.extend($t.p.postData,sdata);
  4082. }
  4083. var saveurl;
  4084. if($t.p.searchurl) {
  4085. saveurl = $t.p.url;
  4086. $($t).jqGrid("setGridParam",{url:$t.p.searchurl});
  4087. }
  4088. var bcv = $($t).triggerHandler("jqGridToolbarBeforeClear") === 'stop' ? true : false;
  4089. if(!bcv && $.isFunction(p.beforeClear)){bcv = p.beforeClear.call($t);}
  4090. if(!bcv) {
  4091. if(trigger) {
  4092. $($t).jqGrid("setGridParam",{search:sd}).trigger("reloadGrid",[{page:1}]);
  4093. }
  4094. }
  4095. if(saveurl) {$($t).jqGrid("setGridParam",{url:saveurl});}
  4096. $($t).triggerHandler("jqGridToolbarAfterClear");
  4097. if($.isFunction(p.afterClear)){p.afterClear();}
  4098. },
  4099. toggleToolbar = function(){
  4100. var trow = $("tr.ui-search-toolbar",$t.grid.hDiv),
  4101. trow2 = $t.p.frozenColumns === true ? $("tr.ui-search-toolbar",$t.grid.fhDiv) : false;
  4102. if(trow.css("display") === 'none') {
  4103. trow.show();
  4104. if(trow2) {
  4105. trow2.show();
  4106. }
  4107. } else {
  4108. trow.hide();
  4109. if(trow2) {
  4110. trow2.hide();
  4111. }
  4112. }
  4113. },
  4114. buildRuleMenu = function( elem, left, top ){
  4115. $("#sopt_menu").remove();
  4116. left=parseInt(left,10);
  4117. top=parseInt(top,10) + 18;
  4118. var fs = $('.ui-jqgrid-view').css('font-size') || '11px';
  4119. var str = '<ul id="sopt_menu" class="ui-search-menu" role="menu" tabindex="0" style="font-size:'+fs+';left:'+left+'px;top:'+top+'px;">',
  4120. selected = $(elem).attr("soper"), selclass,
  4121. aoprs = [], ina;
  4122. var i=0, nm =$(elem).attr("colname"),len = $t.p.colModel.length;
  4123. while(i<len) {
  4124. if($t.p.colModel[i].name === nm) {
  4125. break;
  4126. }
  4127. i++;
  4128. }
  4129. var cm = $t.p.colModel[i], options = $.extend({}, cm.searchoptions);
  4130. if(!options.sopt) {
  4131. options.sopt = [];
  4132. options.sopt[0]= cm.stype==='select' ? 'eq' : p.defaultSearch;
  4133. }
  4134. $.each(p.odata, function() { aoprs.push(this.oper); });
  4135. for ( i = 0 ; i < options.sopt.length; i++) {
  4136. ina = $.inArray(options.sopt[i],aoprs);
  4137. if(ina !== -1) {
  4138. selclass = selected === p.odata[ina].oper ? "ui-state-highlight" : "";
  4139. 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>';
  4140. }
  4141. }
  4142. str += "</ul>";
  4143. $('body').append(str);
  4144. $("#sopt_menu").addClass("ui-menu ui-widget ui-widget-content ui-corner-all");
  4145. $("#sopt_menu > li > a").hover(
  4146. function(){ $(this).addClass("ui-state-hover"); },
  4147. function(){ $(this).removeClass("ui-state-hover"); }
  4148. ).click(function( e ){
  4149. var v = $(this).attr("value"),
  4150. oper = $(this).attr("oper");
  4151. $($t).triggerHandler("jqGridToolbarSelectOper", [v, oper, elem]);
  4152. $("#sopt_menu").hide();
  4153. $(elem).text(oper).attr("soper",v);
  4154. if(p.autosearch===true){
  4155. var inpelm = $(elem).parent().next().children()[0];
  4156. if( $(inpelm).val() || v==="nu" || v ==="nn") {
  4157. triggerToolbar();
  4158. }
  4159. }
  4160. });
  4161. };
  4162. // create the row
  4163. var tr = $("<tr class='ui-search-toolbar' role='rowheader'></tr>");
  4164. var timeoutHnd;
  4165. $.each($t.p.colModel,function(){
  4166. var cm=this, soptions, surl, self, select = "", sot="=", so, i,
  4167. th = $("<th role='columnheader' class='ui-state-default ui-th-column ui-th-"+$t.p.direction+"'></th>"),
  4168. thd = $("<div style='position:relative;height:100%;padding-right:0.3em;padding-left:0.3em;'></div>"),
  4169. stbl = $("<table class='ui-search-table' cellspacing='0'><tr><td class='ui-search-oper'></td><td class='ui-search-input'></td></tr></table>");
  4170. if(this.hidden===true) { $(th).css("display","none");}
  4171. this.search = this.search === false ? false : true;
  4172. if(this.stype === undefined) {this.stype='text';}
  4173. soptions = $.extend({},this.searchoptions || {});
  4174. if(this.search){
  4175. if(p.searchOperators) {
  4176. so = (soptions.sopt) ? soptions.sopt[0] : cm.stype==='select' ? 'eq' : p.defaultSearch;
  4177. for(i = 0;i<p.odata.length;i++) {
  4178. if(p.odata[i].oper === so) {
  4179. sot = p.operands[so] || "";
  4180. break;
  4181. }
  4182. }
  4183. var st = soptions.searchtitle != null ? soptions.searchtitle : p.operandTitle;
  4184. select = "<a title='"+st+"' style='padding-right: 0.5em;' soper='"+so+"' class='soptclass' colname='"+this.name+"'>"+sot+"</a>";
  4185. }
  4186. $("td:eq(0)",stbl).append(select);
  4187. switch (this.stype)
  4188. {
  4189. case "select":
  4190. surl = this.surl || soptions.dataUrl;
  4191. if(surl) {
  4192. // data returned should have already constructed html select
  4193. // primitive jQuery load
  4194. self = thd;
  4195. $.ajax($.extend({
  4196. url: surl,
  4197. dataType: "html",
  4198. success: function(res) {
  4199. if(soptions.buildSelect !== undefined) {
  4200. var d = soptions.buildSelect(res);
  4201. if (d) {
  4202. $("td:eq(1)",stbl).append(d);
  4203. $(self).append(stbl);
  4204. }
  4205. } else {
  4206. $("td:eq(1)",stbl).append(res);
  4207. $(self).append(stbl);
  4208. }
  4209. if(soptions.defaultValue !== undefined) { $("select",self).val(soptions.defaultValue); }
  4210. $("select",self).attr({name:cm.index || cm.name, id: "gs_"+cm.name});
  4211. if(soptions.attr) {$("select",self).attr(soptions.attr);}
  4212. $("select",self).css({width: "100%"});
  4213. // preserve autoserch
  4214. $.jgrid.bindEv.call($t, $("select",self)[0], soptions);
  4215. if(p.autosearch===true){
  4216. $("select",self).change(function(){
  4217. triggerToolbar();
  4218. return false;
  4219. });
  4220. }
  4221. res=null;
  4222. }
  4223. }, $.jgrid.ajaxOptions, $t.p.ajaxSelectOptions || {} ));
  4224. } else {
  4225. var oSv, sep, delim;
  4226. if(cm.searchoptions) {
  4227. oSv = cm.searchoptions.value === undefined ? "" : cm.searchoptions.value;
  4228. sep = cm.searchoptions.separator === undefined ? ":" : cm.searchoptions.separator;
  4229. delim = cm.searchoptions.delimiter === undefined ? ";" : cm.searchoptions.delimiter;
  4230. } else if(cm.editoptions) {
  4231. oSv = cm.editoptions.value === undefined ? "" : cm.editoptions.value;
  4232. sep = cm.editoptions.separator === undefined ? ":" : cm.editoptions.separator;
  4233. delim = cm.editoptions.delimiter === undefined ? ";" : cm.editoptions.delimiter;
  4234. }
  4235. if (oSv) {
  4236. var elem = document.createElement("select");
  4237. elem.style.width = "100%";
  4238. $(elem).attr({name:cm.index || cm.name, id: "gs_"+cm.name});
  4239. var sv, ov, key, k;
  4240. if(typeof oSv === "string") {
  4241. so = oSv.split(delim);
  4242. for(k=0; k<so.length;k++){
  4243. sv = so[k].split(sep);
  4244. ov = document.createElement("option");
  4245. ov.value = sv[0]; ov.innerHTML = sv[1];
  4246. elem.appendChild(ov);
  4247. }
  4248. } else if(typeof oSv === "object" ) {
  4249. for (key in oSv) {
  4250. if(oSv.hasOwnProperty(key)) {
  4251. ov = document.createElement("option");
  4252. ov.value = key; ov.innerHTML = oSv[key];
  4253. elem.appendChild(ov);
  4254. }
  4255. }
  4256. }
  4257. if(soptions.defaultValue !== undefined) { $(elem).val(soptions.defaultValue); }
  4258. if(soptions.attr) {$(elem).attr(soptions.attr);}
  4259. $.jgrid.bindEv.call($t, elem , soptions);
  4260. $("td:eq(1)",stbl).append( elem );
  4261. $(thd).append(stbl);
  4262. if(p.autosearch===true){
  4263. $(elem).change(function(){
  4264. triggerToolbar();
  4265. return false;
  4266. });
  4267. }
  4268. }
  4269. }
  4270. break;
  4271. case "text":
  4272. var df = soptions.defaultValue !== undefined ? soptions.defaultValue: "";
  4273. $("td:eq(1)",stbl).append("<input type='text' style='width:100%;padding:0px;' name='"+(cm.index || cm.name)+"' id='gs_"+cm.name+"' value='"+df+"'/>");
  4274. $(thd).append(stbl);
  4275. if(soptions.attr) {$("input",thd).attr(soptions.attr);}
  4276. $.jgrid.bindEv.call($t, $("input",thd)[0], soptions);
  4277. if(p.autosearch===true){
  4278. if(p.searchOnEnter) {
  4279. $("input",thd).keypress(function(e){
  4280. var key = e.charCode || e.keyCode || 0;
  4281. if(key === 13){
  4282. triggerToolbar();
  4283. return false;
  4284. }
  4285. return this;
  4286. });
  4287. } else {
  4288. $("input",thd).keydown(function(e){
  4289. var key = e.which;
  4290. switch (key) {
  4291. case 13:
  4292. return false;
  4293. case 9 :
  4294. case 16:
  4295. case 37:
  4296. case 38:
  4297. case 39:
  4298. case 40:
  4299. case 27:
  4300. break;
  4301. default :
  4302. if(timeoutHnd) { clearTimeout(timeoutHnd); }
  4303. timeoutHnd = setTimeout(function(){triggerToolbar();},500);
  4304. }
  4305. });
  4306. }
  4307. }
  4308. break;
  4309. case "custom":
  4310. $("td:eq(1)",stbl).append("<span style='width:95%;padding:0px;' name='"+(cm.index || cm.name)+"' id='gs_"+cm.name+"'/>");
  4311. $(thd).append(stbl);
  4312. try {
  4313. if($.isFunction(soptions.custom_element)) {
  4314. var celm = soptions.custom_element.call($t,soptions.defaultValue !== undefined ? soptions.defaultValue: "",soptions);
  4315. if(celm) {
  4316. celm = $(celm).addClass("customelement");
  4317. $(thd).find(">span").append(celm);
  4318. } else {
  4319. throw "e2";
  4320. }
  4321. } else {
  4322. throw "e1";
  4323. }
  4324. } catch (e) {
  4325. if (e === "e1") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_element' "+$.jgrid.edit.msg.nodefined,$.jgrid.edit.bClose);}
  4326. if (e === "e2") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_element' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose);}
  4327. else { $.jgrid.info_dialog($.jgrid.errors.errcap,typeof e==="string"?e:e.message,$.jgrid.edit.bClose); }
  4328. }
  4329. break;
  4330. }
  4331. }
  4332. $(th).append(thd);
  4333. $(tr).append(th);
  4334. if(!p.searchOperators) {
  4335. $("td:eq(0)",stbl).hide();
  4336. }
  4337. });
  4338. $("table thead",$t.grid.hDiv).append(tr);
  4339. if(p.searchOperators) {
  4340. $(".soptclass").click(function(e){
  4341. var offset = $(this).offset(),
  4342. left = ( offset.left ),
  4343. top = ( offset.top);
  4344. buildRuleMenu(this, left, top );
  4345. e.stopPropagation();
  4346. });
  4347. $("body").on('click', function(e){
  4348. if(e.target.className !== "soptclass") {
  4349. $("#sopt_menu").hide();
  4350. }
  4351. });
  4352. }
  4353. this.ftoolbar = true;
  4354. this.triggerToolbar = triggerToolbar;
  4355. this.clearToolbar = clearToolbar;
  4356. this.toggleToolbar = toggleToolbar;
  4357. });
  4358. },
  4359. destroyFilterToolbar: function () {
  4360. return this.each(function () {
  4361. if (!this.ftoolbar) {
  4362. return;
  4363. }
  4364. this.triggerToolbar = null;
  4365. this.clearToolbar = null;
  4366. this.toggleToolbar = null;
  4367. this.ftoolbar = false;
  4368. $(this.grid.hDiv).find("table thead tr.ui-search-toolbar").remove();
  4369. });
  4370. },
  4371. destroyGroupHeader : function(nullHeader)
  4372. {
  4373. if(nullHeader === undefined) {
  4374. nullHeader = true;
  4375. }
  4376. return this.each(function()
  4377. {
  4378. var $t = this, $tr, i, l, headers, $th, $resizing, grid = $t.grid,
  4379. thead = $("table.ui-jqgrid-htable thead", grid.hDiv), cm = $t.p.colModel, hc;
  4380. if(!grid) { return; }
  4381. $(this).unbind('.setGroupHeaders');
  4382. $tr = $("<tr>", {role: "rowheader"}).addClass("ui-jqgrid-labels");
  4383. headers = grid.headers;
  4384. for (i = 0, l = headers.length; i < l; i++) {
  4385. hc = cm[i].hidden ? "none" : "";
  4386. $th = $(headers[i].el)
  4387. .width(headers[i].width)
  4388. .css('display',hc);
  4389. try {
  4390. $th.removeAttr("rowSpan");
  4391. } catch (rs) {
  4392. //IE 6/7
  4393. $th.attr("rowSpan",1);
  4394. }
  4395. $tr.append($th);
  4396. $resizing = $th.children("span.ui-jqgrid-resize");
  4397. if ($resizing.length>0) {// resizable column
  4398. $resizing[0].style.height = "";
  4399. }
  4400. $th.children("div")[0].style.top = "";
  4401. }
  4402. $(thead).children('tr.ui-jqgrid-labels').remove();
  4403. $(thead).prepend($tr);
  4404. if(nullHeader === true) {
  4405. $($t).jqGrid('setGridParam',{ 'groupHeader': null});
  4406. }
  4407. });
  4408. },
  4409. setGroupHeaders : function ( o ) {
  4410. o = $.extend({
  4411. useColSpanStyle : false,
  4412. groupHeaders: []
  4413. },o || {});
  4414. return this.each(function(){
  4415. this.p.groupHeader = o;
  4416. var ts = this,
  4417. i, cmi, skip = 0, $tr, $colHeader, th, $th, thStyle,
  4418. iCol,
  4419. cghi,
  4420. //startColumnName,
  4421. numberOfColumns,
  4422. titleText,
  4423. cVisibleColumns,
  4424. colModel = ts.p.colModel,
  4425. cml = colModel.length,
  4426. ths = ts.grid.headers,
  4427. $htable = $("table.ui-jqgrid-htable", ts.grid.hDiv),
  4428. $trLabels = $htable.children("thead").children("tr.ui-jqgrid-labels:last").addClass("jqg-second-row-header"),
  4429. $thead = $htable.children("thead"),
  4430. $theadInTable,
  4431. $firstHeaderRow = $htable.find(".jqg-first-row-header");
  4432. if($firstHeaderRow[0] === undefined) {
  4433. $firstHeaderRow = $('<tr>', {role: "row", "aria-hidden": "true"}).addClass("jqg-first-row-header").css("height", "auto");
  4434. } else {
  4435. $firstHeaderRow.empty();
  4436. }
  4437. var $firstRow,
  4438. inColumnHeader = function (text, columnHeaders) {
  4439. var length = columnHeaders.length, i;
  4440. for (i = 0; i < length; i++) {
  4441. if (columnHeaders[i].startColumnName === text) {
  4442. return i;
  4443. }
  4444. }
  4445. return -1;
  4446. };
  4447. $(ts).prepend($thead);
  4448. $tr = $('<tr>', {role: "rowheader"}).addClass("ui-jqgrid-labels jqg-third-row-header");
  4449. for (i = 0; i < cml; i++) {
  4450. th = ths[i].el;
  4451. $th = $(th);
  4452. cmi = colModel[i];
  4453. // build the next cell for the first header row
  4454. thStyle = { height: '0px', width: ths[i].width + 'px', display: (cmi.hidden ? 'none' : '')};
  4455. $("<th>", {role: 'gridcell'}).css(thStyle).addClass("ui-first-th-"+ts.p.direction).appendTo($firstHeaderRow);
  4456. th.style.width = ""; // remove unneeded style
  4457. iCol = inColumnHeader(cmi.name, o.groupHeaders);
  4458. if (iCol >= 0) {
  4459. cghi = o.groupHeaders[iCol];
  4460. numberOfColumns = cghi.numberOfColumns;
  4461. titleText = cghi.titleText;
  4462. // caclulate the number of visible columns from the next numberOfColumns columns
  4463. for (cVisibleColumns = 0, iCol = 0; iCol < numberOfColumns && (i + iCol < cml); iCol++) {
  4464. if (!colModel[i + iCol].hidden) {
  4465. cVisibleColumns++;
  4466. }
  4467. }
  4468. // The next numberOfColumns headers will be moved in the next row
  4469. // in the current row will be placed the new column header with the titleText.
  4470. // The text will be over the cVisibleColumns columns
  4471. $colHeader = $('<th>').attr({role: "columnheader"})
  4472. .addClass("ui-state-default ui-th-column-header ui-th-"+ts.p.direction)
  4473. .css({'height':'22px', 'border-top': '0px none'})
  4474. .html(titleText);
  4475. if(cVisibleColumns > 0) {
  4476. $colHeader.attr("colspan", String(cVisibleColumns));
  4477. }
  4478. if (ts.p.headertitles) {
  4479. $colHeader.attr("title", $colHeader.text());
  4480. }
  4481. // hide if not a visible cols
  4482. if( cVisibleColumns === 0) {
  4483. $colHeader.hide();
  4484. }
  4485. $th.before($colHeader); // insert new column header before the current
  4486. $tr.append(th); // move the current header in the next row
  4487. // set the coumter of headers which will be moved in the next row
  4488. skip = numberOfColumns - 1;
  4489. } else {
  4490. if (skip === 0) {
  4491. if (o.useColSpanStyle) {
  4492. // expand the header height to two rows
  4493. $th.attr("rowspan", "2");
  4494. } else {
  4495. $('<th>', {role: "columnheader"})
  4496. .addClass("ui-state-default ui-th-column-header ui-th-"+ts.p.direction)
  4497. .css({"display": cmi.hidden ? 'none' : '', 'border-top': '0px none'})
  4498. .insertBefore($th);
  4499. $tr.append(th);
  4500. }
  4501. } else {
  4502. // move the header to the next row
  4503. //$th.css({"padding-top": "2px", height: "19px"});
  4504. $tr.append(th);
  4505. skip--;
  4506. }
  4507. }
  4508. }
  4509. $theadInTable = $(ts).children("thead");
  4510. $theadInTable.prepend($firstHeaderRow);
  4511. $tr.insertAfter($trLabels);
  4512. $htable.append($theadInTable);
  4513. if (o.useColSpanStyle) {
  4514. // Increase the height of resizing span of visible headers
  4515. $htable.find("span.ui-jqgrid-resize").each(function () {
  4516. var $parent = $(this).parent();
  4517. if ($parent.is(":visible")) {
  4518. this.style.cssText = 'height: ' + $parent.height() + 'px !important; cursor: col-resize;';
  4519. }
  4520. });
  4521. // Set position of the sortable div (the main lable)
  4522. // with the column header text to the middle of the cell.
  4523. // One should not do this for hidden headers.
  4524. $htable.find("div.ui-jqgrid-sortable").each(function () {
  4525. var $ts = $(this), $parent = $ts.parent();
  4526. if ($parent.is(":visible") && $parent.is(":has(span.ui-jqgrid-resize)")) {
  4527. $ts.css('top', ($parent.height() - $ts.outerHeight()) / 2 + 'px');
  4528. }
  4529. });
  4530. }
  4531. $firstRow = $theadInTable.find("tr.jqg-first-row-header");
  4532. $(ts).bind('jqGridResizeStop.setGroupHeaders', function (e, nw, idx) {
  4533. $firstRow.find('th').eq(idx).width(nw);
  4534. });
  4535. });
  4536. },
  4537. setFrozenColumns : function () {
  4538. return this.each(function() {
  4539. if ( !this.grid ) {return;}
  4540. var $t = this, cm = $t.p.colModel,i=0, len = cm.length, maxfrozen = -1, frozen= false;
  4541. // TODO treeGrid and grouping Support
  4542. if($t.p.subGrid === true || $t.p.treeGrid === true || $t.p.cellEdit === true || $t.p.sortable || $t.p.scroll || $t.p.grouping )
  4543. {
  4544. return;
  4545. }
  4546. if($t.p.rownumbers) { i++; }
  4547. if($t.p.multiselect) { i++; }
  4548. // get the max index of frozen col
  4549. while(i<len)
  4550. {
  4551. // from left, no breaking frozen
  4552. if(cm[i].frozen === true)
  4553. {
  4554. frozen = true;
  4555. maxfrozen = i;
  4556. } else {
  4557. break;
  4558. }
  4559. i++;
  4560. }
  4561. if( maxfrozen>=0 && frozen) {
  4562. var top = $t.p.caption ? $($t.grid.cDiv).outerHeight() : 0,
  4563. hth = $(".ui-jqgrid-htable","#gview_"+$.jgrid.jqID($t.p.id)).height();
  4564. //headers
  4565. if($t.p.toppager) {
  4566. top = top + $($t.grid.topDiv).outerHeight();
  4567. }
  4568. if($t.p.toolbar[0] === true) {
  4569. if($t.p.toolbar[1] !== "bottom") {
  4570. top = top + $($t.grid.uDiv).outerHeight();
  4571. }
  4572. }
  4573. $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>');
  4574. $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>');
  4575. $("#gview_"+$.jgrid.jqID($t.p.id)).append($t.grid.fhDiv);
  4576. var htbl = $(".ui-jqgrid-htable","#gview_"+$.jgrid.jqID($t.p.id)).clone(true);
  4577. // groupheader support - only if useColSpanstyle is false
  4578. if($t.p.groupHeader) {
  4579. $("tr.jqg-first-row-header, tr.jqg-third-row-header", htbl).each(function(){
  4580. $("th:gt("+maxfrozen+")",this).remove();
  4581. });
  4582. var swapfroz = -1, fdel = -1, cs, rs;
  4583. $("tr.jqg-second-row-header th", htbl).each(function(){
  4584. cs= parseInt($(this).attr("colspan"),10);
  4585. rs= parseInt($(this).attr("rowspan"),10);
  4586. if(rs) {
  4587. swapfroz++;
  4588. fdel++;
  4589. }
  4590. if(cs) {
  4591. swapfroz = swapfroz+cs;
  4592. fdel++;
  4593. }
  4594. if(swapfroz === maxfrozen) {
  4595. return false;
  4596. }
  4597. });
  4598. if(swapfroz !== maxfrozen) {
  4599. fdel = maxfrozen;
  4600. }
  4601. $("tr.jqg-second-row-header", htbl).each(function(){
  4602. $("th:gt("+fdel+")",this).remove();
  4603. });
  4604. } else {
  4605. $("tr",htbl).each(function(){
  4606. $("th:gt("+maxfrozen+")",this).remove();
  4607. });
  4608. }
  4609. $(htbl).width(1);
  4610. // resizing stuff
  4611. $($t.grid.fhDiv).append(htbl)
  4612. .mousemove(function (e) {
  4613. if($t.grid.resizing){ $t.grid.dragMove(e);return false; }
  4614. });
  4615. $($t).bind('jqGridResizeStop.setFrozenColumns', function (e, w, index) {
  4616. var rhth = $(".ui-jqgrid-htable",$t.grid.fhDiv);
  4617. $("th:eq("+index+")",rhth).width( w );
  4618. var btd = $(".ui-jqgrid-btable",$t.grid.fbDiv);
  4619. $("tr:first td:eq("+index+")",btd).width( w );
  4620. });
  4621. // sorting stuff
  4622. $($t).bind('jqGridOnSortCol.setFrozenColumns', function (e, index, idxcol) {
  4623. 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);
  4624. $("span.ui-grid-ico-sort",previousSelectedTh).addClass('ui-state-disabled');
  4625. $(previousSelectedTh).attr("aria-selected","false");
  4626. $("span.ui-icon-"+$t.p.sortorder,newSelectedTh).removeClass('ui-state-disabled');
  4627. $(newSelectedTh).attr("aria-selected","true");
  4628. if(!$t.p.viewsortcols[0]) {
  4629. if($t.p.lastsort !== idxcol) {
  4630. $("span.s-ico",previousSelectedTh).hide();
  4631. $("span.s-ico",newSelectedTh).show();
  4632. }
  4633. }
  4634. });
  4635. // data stuff
  4636. //TODO support for setRowData
  4637. $("#gview_"+$.jgrid.jqID($t.p.id)).append($t.grid.fbDiv);
  4638. $($t.grid.bDiv).scroll(function () {
  4639. $($t.grid.fbDiv).scrollTop($(this).scrollTop());
  4640. });
  4641. if($t.p.hoverrows === true) {
  4642. $("#"+$.jgrid.jqID($t.p.id)).unbind('mouseover').unbind('mouseout');
  4643. }
  4644. $($t).bind('jqGridAfterGridComplete.setFrozenColumns', function () {
  4645. $("#"+$.jgrid.jqID($t.p.id)+"_frozen").remove();
  4646. $($t.grid.fbDiv).height($($t.grid.bDiv).height()-16);
  4647. var btbl = $("#"+$.jgrid.jqID($t.p.id)).clone(true);
  4648. $("tr",btbl).each(function(){
  4649. $("td:gt("+maxfrozen+")",this).remove();
  4650. });
  4651. $(btbl).width(1).attr("id",$t.p.id+"_frozen");
  4652. $($t.grid.fbDiv).append(btbl);
  4653. if($t.p.hoverrows === true) {
  4654. $("tr.jqgrow", btbl).hover(
  4655. function(){ $(this).addClass("ui-state-hover"); $("#"+$.jgrid.jqID(this.id), "#"+$.jgrid.jqID($t.p.id)).addClass("ui-state-hover"); },
  4656. function(){ $(this).removeClass("ui-state-hover"); $("#"+$.jgrid.jqID(this.id), "#"+$.jgrid.jqID($t.p.id)).removeClass("ui-state-hover"); }
  4657. );
  4658. $("tr.jqgrow", "#"+$.jgrid.jqID($t.p.id)).hover(
  4659. function(){ $(this).addClass("ui-state-hover"); $("#"+$.jgrid.jqID(this.id), "#"+$.jgrid.jqID($t.p.id)+"_frozen").addClass("ui-state-hover");},
  4660. function(){ $(this).removeClass("ui-state-hover"); $("#"+$.jgrid.jqID(this.id), "#"+$.jgrid.jqID($t.p.id)+"_frozen").removeClass("ui-state-hover"); }
  4661. );
  4662. }
  4663. btbl=null;
  4664. });
  4665. $t.p.frozenColumns = true;
  4666. }
  4667. });
  4668. },
  4669. destroyFrozenColumns : function() {
  4670. return this.each(function() {
  4671. if ( !this.grid ) {return;}
  4672. if(this.p.frozenColumns === true) {
  4673. var $t = this;
  4674. $($t.grid.fhDiv).remove();
  4675. $($t.grid.fbDiv).remove();
  4676. $t.grid.fhDiv = null; $t.grid.fbDiv=null;
  4677. $(this).unbind('.setFrozenColumns');
  4678. if($t.p.hoverrows === true) {
  4679. var ptr;
  4680. $("#"+$.jgrid.jqID($t.p.id)).bind('mouseover',function(e) {
  4681. ptr = $(e.target).closest("tr.jqgrow");
  4682. if($(ptr).attr("class") !== "ui-subgrid") {
  4683. $(ptr).addClass("ui-state-hover");
  4684. }
  4685. }).bind('mouseout',function(e) {
  4686. ptr = $(e.target).closest("tr.jqgrow");
  4687. $(ptr).removeClass("ui-state-hover");
  4688. });
  4689. }
  4690. this.p.frozenColumns = false;
  4691. }
  4692. });
  4693. }
  4694. });
  4695. })(jQuery);
  4696. /*
  4697. * jqModal - Minimalist Modaling with jQuery
  4698. * (http://dev.iceburg.net/jquery/jqmodal/)
  4699. *
  4700. * Copyright (c) 2007,2008 Brice Burgess <bhb@iceburg.net>
  4701. * Dual licensed under the MIT and GPL licenses:
  4702. * http://www.opensource.org/licenses/mit-license.php
  4703. * http://www.gnu.org/licenses/gpl.html
  4704. *
  4705. * $Version: 07/06/2008 +r13
  4706. */
  4707. (function($) {
  4708. $.fn.jqm=function(o){
  4709. var p={
  4710. overlay: 50,
  4711. closeoverlay : true,
  4712. overlayClass: 'jqmOverlay',
  4713. closeClass: 'jqmClose',
  4714. trigger: '.jqModal',
  4715. ajax: F,
  4716. ajaxText: '',
  4717. target: F,
  4718. modal: F,
  4719. toTop: F,
  4720. onShow: F,
  4721. onHide: F,
  4722. onLoad: F
  4723. };
  4724. return this.each(function(){if(this._jqm)return H[this._jqm].c=$.extend({},H[this._jqm].c,o);s++;this._jqm=s;
  4725. H[s]={c:$.extend(p,$.jqm.params,o),a:F,w:$(this).addClass('jqmID'+s),s:s};
  4726. if(p.trigger)$(this).jqmAddTrigger(p.trigger);
  4727. });};
  4728. $.fn.jqmAddClose=function(e){return hs(this,e,'jqmHide');};
  4729. $.fn.jqmAddTrigger=function(e){return hs(this,e,'jqmShow');};
  4730. $.fn.jqmShow=function(t){return this.each(function(){$.jqm.open(this._jqm,t);});};
  4731. $.fn.jqmHide=function(t){return this.each(function(){$.jqm.close(this._jqm,t)});};
  4732. $.jqm = {
  4733. hash:{},
  4734. 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);
  4735. if(c.modal) {if(!A[0])setTimeout(function(){L('bind');},1);A.push(s);}
  4736. else if(c.overlay > 0) {if(c.closeoverlay) h.w.jqmAddClose(o);}
  4737. else o=F;
  4738. h.o=(o)?o.addClass(c.overlayClass).prependTo('body'):F;
  4739. 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;
  4740. 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);});}
  4741. else if(cc)h.w.jqmAddClose($(cc,h.w));
  4742. if(c.toTop&&h.o)h.w.before('<span id="jqmP'+h.w[0]._jqm+'"></span>').insertAfter(h.o);
  4743. (c.onShow)?c.onShow(h):h.w.show();e(h);return F;
  4744. },
  4745. close:function(s){var h=H[s];if(!h.a)return F;h.a=F;
  4746. if(A[0]){A.pop();if(!A[0])L('unbind');}
  4747. if(h.c.toTop&&h.o)$('#jqmP'+h.w[0]._jqm).after(h.w).remove();
  4748. if(h.c.onHide)h.c.onHide(h);else{h.w.hide();if(h.o)h.o.remove();} return F;
  4749. },
  4750. params:{}};
  4751. var s=0,H=$.jqm.hash,A=[],F=false,
  4752. e=function(h){f(h);},
  4753. f=function(h){try{$(':input:visible',h.w)[0].focus();}catch(_){}},
  4754. L=function(t){$(document)[t]("keypress",m)[t]("keydown",m)[t]("mousedown",m);},
  4755. 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;},
  4756. hs=function(w,t,c){return w.each(function(){var s=this._jqm;$(t).each(function() {
  4757. 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);});});};
  4758. })(jQuery);/*
  4759. * jqDnR - Minimalistic Drag'n'Resize for jQuery.
  4760. *
  4761. * Copyright (c) 2007 Brice Burgess <bhb@iceburg.net>, http://www.iceburg.net
  4762. * Licensed under the MIT License:
  4763. * http://www.opensource.org/licenses/mit-license.php
  4764. *
  4765. * $Version: 2007.08.19 +r2
  4766. */
  4767. (function($){
  4768. $.fn.jqDrag=function(h){return i(this,h,'d');};
  4769. $.fn.jqResize=function(h,ar){return i(this,h,'r',ar);};
  4770. $.jqDnR={
  4771. dnr:{},
  4772. e:0,
  4773. drag:function(v){
  4774. if(M.k == 'd'){E.css({left:M.X+v.pageX-M.pX,top:M.Y+v.pageY-M.pY});}
  4775. else {
  4776. E.css({width:Math.max(v.pageX-M.pX+M.W,0),height:Math.max(v.pageY-M.pY+M.H,0)});
  4777. if(M1){E1.css({width:Math.max(v.pageX-M1.pX+M1.W,0),height:Math.max(v.pageY-M1.pY+M1.H,0)});}
  4778. }
  4779. return false;
  4780. },
  4781. stop:function(){
  4782. //E.css('opacity',M.o);
  4783. $(document).unbind('mousemove',J.drag).unbind('mouseup',J.stop);
  4784. }
  4785. };
  4786. var J=$.jqDnR,M=J.dnr,E=J.e,E1,M1,
  4787. i=function(e,h,k,aR){
  4788. return e.each(function(){
  4789. h=(h)?$(h,e):e;
  4790. h.bind('mousedown',{e:e,k:k},function(v){
  4791. var d=v.data,p={};E=d.e;E1 = aR ? $(aR) : false;
  4792. // attempt utilization of dimensions plugin to fix IE issues
  4793. if(E.css('position') != 'relative'){try{E.position(p);}catch(e){}}
  4794. M={
  4795. X:p.left||f('left')||0,
  4796. Y:p.top||f('top')||0,
  4797. W:f('width')||E[0].scrollWidth||0,
  4798. H:f('height')||E[0].scrollHeight||0,
  4799. pX:v.pageX,
  4800. pY:v.pageY,
  4801. k:d.k
  4802. //o:E.css('opacity')
  4803. };
  4804. // also resize
  4805. if(E1 && d.k != 'd'){
  4806. M1={
  4807. X:p.left||f1('left')||0,
  4808. Y:p.top||f1('top')||0,
  4809. W:E1[0].offsetWidth||f1('width')||0,
  4810. H:E1[0].offsetHeight||f1('height')||0,
  4811. pX:v.pageX,
  4812. pY:v.pageY,
  4813. k:d.k
  4814. };
  4815. } else {M1 = false;}
  4816. //E.css({opacity:0.8});
  4817. if($("input.hasDatepicker",E[0])[0]) {
  4818. try {$("input.hasDatepicker",E[0]).datepicker('hide');}catch (dpe){}
  4819. }
  4820. $(document).mousemove($.jqDnR.drag).mouseup($.jqDnR.stop);
  4821. return false;
  4822. });
  4823. });
  4824. },
  4825. f=function(k){return parseInt(E.css(k),10)||false;},
  4826. f1=function(k){return parseInt(E1.css(k),10)||false;};
  4827. })(jQuery);/*
  4828. The below work is licensed under Creative Commons GNU LGPL License.
  4829. Original work:
  4830. License: http://creativecommons.org/licenses/LGPL/2.1/
  4831. Author: Stefan Goessner/2006
  4832. Web: http://goessner.net/
  4833. Modifications made:
  4834. Version: 0.9-p5
  4835. Description: Restructured code, JSLint validated (no strict whitespaces),
  4836. added handling of empty arrays, empty strings, and int/floats values.
  4837. Author: Michael Schøler/2008-01-29
  4838. Web: http://michael.hinnerup.net/blog/2008/01/26/converting-json-to-xml-and-xml-to-json/
  4839. Description: json2xml added support to convert functions as CDATA
  4840. so it will be easy to write characters that cause some problems when convert
  4841. Author: Tony Tomov
  4842. */
  4843. /*global alert */
  4844. var xmlJsonClass = {
  4845. // Param "xml": Element or document DOM node.
  4846. // Param "tab": Tab or indent string for pretty output formatting omit or use empty string "" to supress.
  4847. // Returns: JSON string
  4848. xml2json: function(xml, tab) {
  4849. if (xml.nodeType === 9) {
  4850. // document node
  4851. xml = xml.documentElement;
  4852. }
  4853. var nws = this.removeWhite(xml);
  4854. var obj = this.toObj(nws);
  4855. var json = this.toJson(obj, xml.nodeName, "\t");
  4856. return "{\n" + tab + (tab ? json.replace(/\t/g, tab) : json.replace(/\t|\n/g, "")) + "\n}";
  4857. },
  4858. // Param "o": JavaScript object
  4859. // Param "tab": tab or indent string for pretty output formatting omit or use empty string "" to supress.
  4860. // Returns: XML string
  4861. json2xml: function(o, tab) {
  4862. var toXml = function(v, name, ind) {
  4863. var xml = "";
  4864. var i, n;
  4865. if (v instanceof Array) {
  4866. if (v.length === 0) {
  4867. xml += ind + "<"+name+">__EMPTY_ARRAY_</"+name+">\n";
  4868. }
  4869. else {
  4870. for (i = 0, n = v.length; i < n; i += 1) {
  4871. var sXml = ind + toXml(v[i], name, ind+"\t") + "\n";
  4872. xml += sXml;
  4873. }
  4874. }
  4875. }
  4876. else if (typeof(v) === "object") {
  4877. var hasChild = false;
  4878. xml += ind + "<" + name;
  4879. var m;
  4880. for (m in v) if (v.hasOwnProperty(m)) {
  4881. if (m.charAt(0) === "@") {
  4882. xml += " " + m.substr(1) + "=\"" + v[m].toString() + "\"";
  4883. }
  4884. else {
  4885. hasChild = true;
  4886. }
  4887. }
  4888. xml += hasChild ? ">" : "/>";
  4889. if (hasChild) {
  4890. for (m in v) if (v.hasOwnProperty(m)) {
  4891. if (m === "#text") {
  4892. xml += v[m];
  4893. }
  4894. else if (m === "#cdata") {
  4895. xml += "<![CDATA[" + v[m] + "]]>";
  4896. }
  4897. else if (m.charAt(0) !== "@") {
  4898. xml += toXml(v[m], m, ind+"\t");
  4899. }
  4900. }
  4901. xml += (xml.charAt(xml.length - 1) === "\n" ? ind : "") + "</" + name + ">";
  4902. }
  4903. }
  4904. else if (typeof(v) === "function") {
  4905. xml += ind + "<" + name + ">" + "<![CDATA[" + v + "]]>" + "</" + name + ">";
  4906. }
  4907. else {
  4908. if (v === undefined ) { v = ""; }
  4909. if (v.toString() === "\"\"" || v.toString().length === 0) {
  4910. xml += ind + "<" + name + ">__EMPTY_STRING_</" + name + ">";
  4911. }
  4912. else {
  4913. xml += ind + "<" + name + ">" + v.toString() + "</" + name + ">";
  4914. }
  4915. }
  4916. return xml;
  4917. };
  4918. var xml = "";
  4919. var m;
  4920. for (m in o) if (o.hasOwnProperty(m)) {
  4921. xml += toXml(o[m], m, "");
  4922. }
  4923. return tab ? xml.replace(/\t/g, tab) : xml.replace(/\t|\n/g, "");
  4924. },
  4925. // Internal methods
  4926. toObj: function(xml) {
  4927. var o = {};
  4928. var FuncTest = /function/i;
  4929. if (xml.nodeType === 1) {
  4930. // element node ..
  4931. if (xml.attributes.length) {
  4932. // element with attributes ..
  4933. var i;
  4934. for (i = 0; i < xml.attributes.length; i += 1) {
  4935. o["@" + xml.attributes[i].nodeName] = (xml.attributes[i].nodeValue || "").toString();
  4936. }
  4937. }
  4938. if (xml.firstChild) {
  4939. // element has child nodes ..
  4940. var textChild = 0, cdataChild = 0, hasElementChild = false;
  4941. var n;
  4942. for (n = xml.firstChild; n; n = n.nextSibling) {
  4943. if (n.nodeType === 1) {
  4944. hasElementChild = true;
  4945. }
  4946. else if (n.nodeType === 3 && n.nodeValue.match(/[^ \f\n\r\t\v]/)) {
  4947. // non-whitespace text
  4948. textChild += 1;
  4949. }
  4950. else if (n.nodeType === 4) {
  4951. // cdata section node
  4952. cdataChild += 1;
  4953. }
  4954. }
  4955. if (hasElementChild) {
  4956. if (textChild < 2 && cdataChild < 2) {
  4957. // structured element with evtl. a single text or/and cdata node ..
  4958. this.removeWhite(xml);
  4959. for (n = xml.firstChild; n; n = n.nextSibling) {
  4960. if (n.nodeType === 3) {
  4961. // text node
  4962. o["#text"] = this.escape(n.nodeValue);
  4963. }
  4964. else if (n.nodeType === 4) {
  4965. // cdata node
  4966. if (FuncTest.test(n.nodeValue)) {
  4967. o[n.nodeName] = [o[n.nodeName], n.nodeValue];
  4968. } else {
  4969. o["#cdata"] = this.escape(n.nodeValue);
  4970. }
  4971. }
  4972. else if (o[n.nodeName]) {
  4973. // multiple occurence of element ..
  4974. if (o[n.nodeName] instanceof Array) {
  4975. o[n.nodeName][o[n.nodeName].length] = this.toObj(n);
  4976. }
  4977. else {
  4978. o[n.nodeName] = [o[n.nodeName], this.toObj(n)];
  4979. }
  4980. }
  4981. else {
  4982. // first occurence of element ..
  4983. o[n.nodeName] = this.toObj(n);
  4984. }
  4985. }
  4986. }
  4987. else {
  4988. // mixed content
  4989. if (!xml.attributes.length) {
  4990. o = this.escape(this.innerXml(xml));
  4991. }
  4992. else {
  4993. o["#text"] = this.escape(this.innerXml(xml));
  4994. }
  4995. }
  4996. }
  4997. else if (textChild) {
  4998. // pure text
  4999. if (!xml.attributes.length) {
  5000. o = this.escape(this.innerXml(xml));
  5001. if (o === "__EMPTY_ARRAY_") {
  5002. o = "[]";
  5003. } else if (o === "__EMPTY_STRING_") {
  5004. o = "";
  5005. }
  5006. }
  5007. else {
  5008. o["#text"] = this.escape(this.innerXml(xml));
  5009. }
  5010. }
  5011. else if (cdataChild) {
  5012. // cdata
  5013. if (cdataChild > 1) {
  5014. o = this.escape(this.innerXml(xml));
  5015. }
  5016. else {
  5017. for (n = xml.firstChild; n; n = n.nextSibling) {
  5018. if(FuncTest.test(xml.firstChild.nodeValue)) {
  5019. o = xml.firstChild.nodeValue;
  5020. break;
  5021. } else {
  5022. o["#cdata"] = this.escape(n.nodeValue);
  5023. }
  5024. }
  5025. }
  5026. }
  5027. }
  5028. if (!xml.attributes.length && !xml.firstChild) {
  5029. o = null;
  5030. }
  5031. }
  5032. else if (xml.nodeType === 9) {
  5033. // document.node
  5034. o = this.toObj(xml.documentElement);
  5035. }
  5036. else {
  5037. alert("unhandled node type: " + xml.nodeType);
  5038. }
  5039. return o;
  5040. },
  5041. toJson: function(o, name, ind, wellform) {
  5042. if(wellform === undefined) wellform = true;
  5043. var json = name ? ("\"" + name + "\"") : "", tab = "\t", newline = "\n";
  5044. if(!wellform) {
  5045. tab= ""; newline= "";
  5046. }
  5047. if (o === "[]") {
  5048. json += (name ? ":[]" : "[]");
  5049. }
  5050. else if (o instanceof Array) {
  5051. var n, i, ar=[];
  5052. for (i = 0, n = o.length; i < n; i += 1) {
  5053. ar[i] = this.toJson(o[i], "", ind + tab, wellform);
  5054. }
  5055. json += (name ? ":[" : "[") + (ar.length > 1 ? (newline + ind + tab + ar.join(","+newline + ind + tab) + newline + ind) : ar.join("")) + "]";
  5056. }
  5057. else if (o === null) {
  5058. json += (name && ":") + "null";
  5059. }
  5060. else if (typeof(o) === "object") {
  5061. var arr = [], m;
  5062. for (m in o) {
  5063. if (o.hasOwnProperty(m)) {
  5064. arr[arr.length] = this.toJson(o[m], m, ind + tab, wellform);
  5065. }
  5066. }
  5067. json += (name ? ":{" : "{") + (arr.length > 1 ? (newline + ind + tab + arr.join(","+newline + ind + tab) + newline + ind) : arr.join("")) + "}";
  5068. }
  5069. else if (typeof(o) === "string") {
  5070. /*
  5071. var objRegExp = /(^-?\d+\.?\d*$)/;
  5072. var FuncTest = /function/i;
  5073. var os = o.toString();
  5074. if (objRegExp.test(os) || FuncTest.test(os) || os==="false" || os==="true") {
  5075. // int or float
  5076. json += (name && ":") + "\"" +os + "\"";
  5077. }
  5078. else {
  5079. */
  5080. json += (name && ":") + "\"" + o.replace(/\\/g,'\\\\').replace(/\"/g,'\\"') + "\"";
  5081. //}
  5082. }
  5083. else {
  5084. json += (name && ":") + o.toString();
  5085. }
  5086. return json;
  5087. },
  5088. innerXml: function(node) {
  5089. var s = "";
  5090. if ("innerHTML" in node) {
  5091. s = node.innerHTML;
  5092. }
  5093. else {
  5094. var asXml = function(n) {
  5095. var s = "", i;
  5096. if (n.nodeType === 1) {
  5097. s += "<" + n.nodeName;
  5098. for (i = 0; i < n.attributes.length; i += 1) {
  5099. s += " " + n.attributes[i].nodeName + "=\"" + (n.attributes[i].nodeValue || "").toString() + "\"";
  5100. }
  5101. if (n.firstChild) {
  5102. s += ">";
  5103. for (var c = n.firstChild; c; c = c.nextSibling) {
  5104. s += asXml(c);
  5105. }
  5106. s += "</" + n.nodeName + ">";
  5107. }
  5108. else {
  5109. s += "/>";
  5110. }
  5111. }
  5112. else if (n.nodeType === 3) {
  5113. s += n.nodeValue;
  5114. }
  5115. else if (n.nodeType === 4) {
  5116. s += "<![CDATA[" + n.nodeValue + "]]>";
  5117. }
  5118. return s;
  5119. };
  5120. for (var c = node.firstChild; c; c = c.nextSibling) {
  5121. s += asXml(c);
  5122. }
  5123. }
  5124. return s;
  5125. },
  5126. escape: function(txt) {
  5127. return txt.replace(/[\\]/g, "\\\\").replace(/[\"]/g, '\\"').replace(/[\n]/g, '\\n').replace(/[\r]/g, '\\r');
  5128. },
  5129. removeWhite: function(e) {
  5130. e.normalize();
  5131. var n;
  5132. for (n = e.firstChild; n; ) {
  5133. if (n.nodeType === 3) {
  5134. // text node
  5135. if (!n.nodeValue.match(/[^ \f\n\r\t\v]/)) {
  5136. // pure whitespace text node
  5137. var nxt = n.nextSibling;
  5138. e.removeChild(n);
  5139. n = nxt;
  5140. }
  5141. else {
  5142. n = n.nextSibling;
  5143. }
  5144. }
  5145. else if (n.nodeType === 1) {
  5146. // element node
  5147. this.removeWhite(n);
  5148. n = n.nextSibling;
  5149. }
  5150. else {
  5151. // any other node
  5152. n = n.nextSibling;
  5153. }
  5154. }
  5155. return e;
  5156. }
  5157. };/*
  5158. **
  5159. * formatter for values but most of the values if for jqGrid
  5160. * Some of this was inspired and based on how YUI does the table datagrid but in jQuery fashion
  5161. * we are trying to keep it as light as possible
  5162. * Joshua Burnett josh@9ci.com
  5163. * http://www.greenbill.com
  5164. *
  5165. * Changes from Tony Tomov tony@trirand.com
  5166. * Dual licensed under the MIT and GPL licenses:
  5167. * http://www.opensource.org/licenses/mit-license.php
  5168. * http://www.gnu.org/licenses/gpl-2.0.html
  5169. *
  5170. **/
  5171. /*jshint eqeqeq:false */
  5172. /*global jQuery */
  5173. (function($) {
  5174. "use strict";
  5175. $.fmatter = {};
  5176. //opts can be id:row id for the row, rowdata:the data for the row, colmodel:the column model for this column
  5177. //example {id:1234,}
  5178. $.extend($.fmatter,{
  5179. isBoolean : function(o) {
  5180. return typeof o === 'boolean';
  5181. },
  5182. isObject : function(o) {
  5183. return (o && (typeof o === 'object' || $.isFunction(o))) || false;
  5184. },
  5185. isString : function(o) {
  5186. return typeof o === 'string';
  5187. },
  5188. isNumber : function(o) {
  5189. return typeof o === 'number' && isFinite(o);
  5190. },
  5191. isValue : function (o) {
  5192. return (this.isObject(o) || this.isString(o) || this.isNumber(o) || this.isBoolean(o));
  5193. },
  5194. isEmpty : function(o) {
  5195. if(!this.isString(o) && this.isValue(o)) {
  5196. return false;
  5197. }
  5198. if (!this.isValue(o)){
  5199. return true;
  5200. }
  5201. o = $.trim(o).replace(/\&nbsp\;/ig,'').replace(/\&#160\;/ig,'');
  5202. return o==="";
  5203. }
  5204. });
  5205. $.fn.fmatter = function(formatType, cellval, opts, rwd, act) {
  5206. // build main options before element iteration
  5207. var v=cellval;
  5208. opts = $.extend({}, $.jgrid.formatter, opts);
  5209. try {
  5210. v = $.fn.fmatter[formatType].call(this, cellval, opts, rwd, act);
  5211. } catch(fe){}
  5212. return v;
  5213. };
  5214. $.fmatter.util = {
  5215. // Taken from YAHOO utils
  5216. NumberFormat : function(nData,opts) {
  5217. if(!$.fmatter.isNumber(nData)) {
  5218. nData *= 1;
  5219. }
  5220. if($.fmatter.isNumber(nData)) {
  5221. var bNegative = (nData < 0);
  5222. var sOutput = String(nData);
  5223. var sDecimalSeparator = opts.decimalSeparator || ".";
  5224. var nDotIndex;
  5225. if($.fmatter.isNumber(opts.decimalPlaces)) {
  5226. // Round to the correct decimal place
  5227. var nDecimalPlaces = opts.decimalPlaces;
  5228. var nDecimal = Math.pow(10, nDecimalPlaces);
  5229. sOutput = String(Math.round(nData*nDecimal)/nDecimal);
  5230. nDotIndex = sOutput.lastIndexOf(".");
  5231. if(nDecimalPlaces > 0) {
  5232. // Add the decimal separator
  5233. if(nDotIndex < 0) {
  5234. sOutput += sDecimalSeparator;
  5235. nDotIndex = sOutput.length-1;
  5236. }
  5237. // Replace the "."
  5238. else if(sDecimalSeparator !== "."){
  5239. sOutput = sOutput.replace(".",sDecimalSeparator);
  5240. }
  5241. // Add missing zeros
  5242. while((sOutput.length - 1 - nDotIndex) < nDecimalPlaces) {
  5243. sOutput += "0";
  5244. }
  5245. }
  5246. }
  5247. if(opts.thousandsSeparator) {
  5248. var sThousandsSeparator = opts.thousandsSeparator;
  5249. nDotIndex = sOutput.lastIndexOf(sDecimalSeparator);
  5250. nDotIndex = (nDotIndex > -1) ? nDotIndex : sOutput.length;
  5251. var sNewOutput = sOutput.substring(nDotIndex);
  5252. var nCount = -1, i;
  5253. for (i=nDotIndex; i>0; i--) {
  5254. nCount++;
  5255. if ((nCount%3 === 0) && (i !== nDotIndex) && (!bNegative || (i > 1))) {
  5256. sNewOutput = sThousandsSeparator + sNewOutput;
  5257. }
  5258. sNewOutput = sOutput.charAt(i-1) + sNewOutput;
  5259. }
  5260. sOutput = sNewOutput;
  5261. }
  5262. // Prepend prefix
  5263. sOutput = (opts.prefix) ? opts.prefix + sOutput : sOutput;
  5264. // Append suffix
  5265. sOutput = (opts.suffix) ? sOutput + opts.suffix : sOutput;
  5266. return sOutput;
  5267. }
  5268. return nData;
  5269. }
  5270. };
  5271. $.fn.fmatter.defaultFormat = function(cellval, opts) {
  5272. return ($.fmatter.isValue(cellval) && cellval!=="" ) ? cellval : opts.defaultValue || "&#160;";
  5273. };
  5274. $.fn.fmatter.email = function(cellval, opts) {
  5275. if(!$.fmatter.isEmpty(cellval)) {
  5276. return "<a href=\"mailto:" + cellval + "\">" + cellval + "</a>";
  5277. }
  5278. return $.fn.fmatter.defaultFormat(cellval,opts );
  5279. };
  5280. $.fn.fmatter.checkbox =function(cval, opts) {
  5281. var op = $.extend({},opts.checkbox), ds;
  5282. if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
  5283. op = $.extend({},op,opts.colModel.formatoptions);
  5284. }
  5285. if(op.disabled===true) {ds = "disabled=\"disabled\"";} else {ds="";}
  5286. if($.fmatter.isEmpty(cval) || cval === undefined ) {cval = $.fn.fmatter.defaultFormat(cval,op);}
  5287. cval=String(cval);
  5288. cval=cval.toLowerCase();
  5289. var bchk = cval.search(/(false|f|0|no|n|off|undefined)/i)<0 ? " checked='checked' " : "";
  5290. return "<input type=\"checkbox\" " + bchk + " value=\""+ cval+"\" offval=\"no\" "+ds+ "/>";
  5291. };
  5292. $.fn.fmatter.link = function(cellval, opts) {
  5293. var op = {target:opts.target};
  5294. var target = "";
  5295. if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
  5296. op = $.extend({},op,opts.colModel.formatoptions);
  5297. }
  5298. if(op.target) {target = 'target=' + op.target;}
  5299. if(!$.fmatter.isEmpty(cellval)) {
  5300. return "<a "+target+" href=\"" + cellval + "\">" + cellval + "</a>";
  5301. }
  5302. return $.fn.fmatter.defaultFormat(cellval,opts);
  5303. };
  5304. $.fn.fmatter.showlink = function(cellval, opts) {
  5305. var op = {baseLinkUrl: opts.baseLinkUrl,showAction:opts.showAction, addParam: opts.addParam || "", target: opts.target, idName: opts.idName},
  5306. target = "", idUrl;
  5307. if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
  5308. op = $.extend({},op,opts.colModel.formatoptions);
  5309. }
  5310. if(op.target) {target = 'target=' + op.target;}
  5311. idUrl = op.baseLinkUrl+op.showAction + '?'+ op.idName+'='+opts.rowId+op.addParam;
  5312. if($.fmatter.isString(cellval) || $.fmatter.isNumber(cellval)) { //add this one even if its blank string
  5313. return "<a "+target+" href=\"" + idUrl + "\">" + cellval + "</a>";
  5314. }
  5315. return $.fn.fmatter.defaultFormat(cellval,opts);
  5316. };
  5317. $.fn.fmatter.integer = function(cellval, opts) {
  5318. var op = $.extend({},opts.integer);
  5319. if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
  5320. op = $.extend({},op,opts.colModel.formatoptions);
  5321. }
  5322. if($.fmatter.isEmpty(cellval)) {
  5323. return op.defaultValue;
  5324. }
  5325. return $.fmatter.util.NumberFormat(cellval,op);
  5326. };
  5327. $.fn.fmatter.number = function (cellval, opts) {
  5328. var op = $.extend({},opts.number);
  5329. if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
  5330. op = $.extend({},op,opts.colModel.formatoptions);
  5331. }
  5332. if($.fmatter.isEmpty(cellval)) {
  5333. return op.defaultValue;
  5334. }
  5335. return $.fmatter.util.NumberFormat(cellval,op);
  5336. };
  5337. $.fn.fmatter.currency = function (cellval, opts) {
  5338. var op = $.extend({},opts.currency);
  5339. if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
  5340. op = $.extend({},op,opts.colModel.formatoptions);
  5341. }
  5342. if($.fmatter.isEmpty(cellval)) {
  5343. return op.defaultValue;
  5344. }
  5345. return $.fmatter.util.NumberFormat(cellval,op);
  5346. };
  5347. $.fn.fmatter.date = function (cellval, opts, rwd, act) {
  5348. var op = $.extend({},opts.date);
  5349. if(opts.colModel !== undefined && opts.colModel.formatoptions !== undefined) {
  5350. op = $.extend({},op,opts.colModel.formatoptions);
  5351. }
  5352. if(!op.reformatAfterEdit && act === 'edit'){
  5353. return $.fn.fmatter.defaultFormat(cellval, opts);
  5354. }
  5355. if(!$.fmatter.isEmpty(cellval)) {
  5356. return $.jgrid.parseDate(op.srcformat,cellval,op.newformat,op);
  5357. }
  5358. return $.fn.fmatter.defaultFormat(cellval, opts);
  5359. };
  5360. $.fn.fmatter.select = function (cellval,opts) {
  5361. // jqGrid specific
  5362. cellval = String(cellval);
  5363. var oSelect = false, ret=[], sep, delim;
  5364. if(opts.colModel.formatoptions !== undefined){
  5365. oSelect= opts.colModel.formatoptions.value;
  5366. sep = opts.colModel.formatoptions.separator === undefined ? ":" : opts.colModel.formatoptions.separator;
  5367. delim = opts.colModel.formatoptions.delimiter === undefined ? ";" : opts.colModel.formatoptions.delimiter;
  5368. } else if(opts.colModel.editoptions !== undefined){
  5369. oSelect= opts.colModel.editoptions.value;
  5370. sep = opts.colModel.editoptions.separator === undefined ? ":" : opts.colModel.editoptions.separator;
  5371. delim = opts.colModel.editoptions.delimiter === undefined ? ";" : opts.colModel.editoptions.delimiter;
  5372. }
  5373. if (oSelect) {
  5374. var msl = opts.colModel.editoptions.multiple === true ? true : false,
  5375. scell = [], sv;
  5376. if(msl) {scell = cellval.split(",");scell = $.map(scell,function(n){return $.trim(n);});}
  5377. if ($.fmatter.isString(oSelect)) {
  5378. // mybe here we can use some caching with care ????
  5379. var so = oSelect.split(delim), j=0, i;
  5380. for(i=0; i<so.length;i++){
  5381. sv = so[i].split(sep);
  5382. if(sv.length > 2 ) {
  5383. sv[1] = $.map(sv,function(n,i){if(i>0) {return n;}}).join(sep);
  5384. }
  5385. if(msl) {
  5386. if($.inArray(sv[0],scell)>-1) {
  5387. ret[j] = sv[1];
  5388. j++;
  5389. }
  5390. } else if($.trim(sv[0]) === $.trim(cellval)) {
  5391. ret[0] = sv[1];
  5392. break;
  5393. }
  5394. }
  5395. } else if($.fmatter.isObject(oSelect)) {
  5396. // this is quicker
  5397. if(msl) {
  5398. ret = $.map(scell, function(n){
  5399. return oSelect[n];
  5400. });
  5401. } else {
  5402. ret[0] = oSelect[cellval] || "";
  5403. }
  5404. }
  5405. }
  5406. cellval = ret.join(", ");
  5407. return cellval === "" ? $.fn.fmatter.defaultFormat(cellval,opts) : cellval;
  5408. };
  5409. $.fn.fmatter.rowactions = function(act) {
  5410. var $tr = $(this).closest("tr.jqgrow"),
  5411. rid = $tr.attr("id"),
  5412. $id = $(this).closest("table.ui-jqgrid-btable").attr('id').replace(/_frozen([^_]*)$/,'$1'),
  5413. $grid = $("#"+$id),
  5414. $t = $grid[0],
  5415. p = $t.p,
  5416. cm = p.colModel[$.jgrid.getCellIndex(this)],
  5417. $actionsDiv = cm.frozen ? $("tr#"+rid+" td:eq("+$.jgrid.getCellIndex(this)+") > div",$grid) :$(this).parent(),
  5418. op = {
  5419. keys: false,
  5420. onEdit: null,
  5421. onSuccess: null,
  5422. afterSave: null,
  5423. onError: null,
  5424. afterRestore: null,
  5425. extraparam: {},
  5426. url: null,
  5427. restoreAfterError: true,
  5428. mtype: "POST",
  5429. delOptions: {},
  5430. editOptions: {}
  5431. },
  5432. saverow = function(rowid, res) {
  5433. if($.isFunction(op.afterSave)) { op.afterSave.call($t, rowid, res); }
  5434. $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show();
  5435. $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide();
  5436. },
  5437. restorerow = function(rowid) {
  5438. if($.isFunction(op.afterRestore)) { op.afterRestore.call($t, rowid); }
  5439. $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show();
  5440. $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide();
  5441. };
  5442. if (cm.formatoptions !== undefined) {
  5443. op = $.extend(op,cm.formatoptions);
  5444. }
  5445. if (p.editOptions !== undefined) {
  5446. op.editOptions = p.editOptions;
  5447. }
  5448. if (p.delOptions !== undefined) {
  5449. op.delOptions = p.delOptions;
  5450. }
  5451. if ($tr.hasClass("jqgrid-new-row")){
  5452. op.extraparam[p.prmNames.oper] = p.prmNames.addoper;
  5453. }
  5454. var actop = {
  5455. keys: op.keys,
  5456. oneditfunc: op.onEdit,
  5457. successfunc: op.onSuccess,
  5458. url: op.url,
  5459. extraparam: op.extraparam,
  5460. aftersavefunc: saverow,
  5461. errorfunc: op.onError,
  5462. afterrestorefunc: restorerow,
  5463. restoreAfterError: op.restoreAfterError,
  5464. mtype: op.mtype
  5465. };
  5466. switch(act)
  5467. {
  5468. case 'edit':
  5469. $grid.jqGrid('editRow', rid, actop);
  5470. $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").hide();
  5471. $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").show();
  5472. $grid.triggerHandler("jqGridAfterGridComplete");
  5473. break;
  5474. case 'save':
  5475. if ($grid.jqGrid('saveRow', rid, actop)) {
  5476. $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show();
  5477. $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide();
  5478. $grid.triggerHandler("jqGridAfterGridComplete");
  5479. }
  5480. break;
  5481. case 'cancel' :
  5482. $grid.jqGrid('restoreRow', rid, restorerow);
  5483. $actionsDiv.find("div.ui-inline-edit,div.ui-inline-del").show();
  5484. $actionsDiv.find("div.ui-inline-save,div.ui-inline-cancel").hide();
  5485. $grid.triggerHandler("jqGridAfterGridComplete");
  5486. break;
  5487. case 'del':
  5488. $grid.jqGrid('delGridRow', rid, op.delOptions);
  5489. break;
  5490. case 'formedit':
  5491. $grid.jqGrid('setSelection', rid);
  5492. $grid.jqGrid('editGridRow', rid, op.editOptions);
  5493. break;
  5494. }
  5495. };
  5496. $.fn.fmatter.actions = function(cellval,opts) {
  5497. var op={keys:false, editbutton:true, delbutton:true, editformbutton: false},
  5498. rowid=opts.rowId, str="",ocl;
  5499. if(opts.colModel.formatoptions !== undefined) {
  5500. op = $.extend(op,opts.colModel.formatoptions);
  5501. }
  5502. if(rowid === undefined || $.fmatter.isEmpty(rowid)) {return "";}
  5503. if(op.editformbutton){
  5504. 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'); ";
  5505. 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>";
  5506. } else if(op.editbutton){
  5507. 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') ";
  5508. 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>";
  5509. }
  5510. if(op.delbutton) {
  5511. 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'); ";
  5512. 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>";
  5513. }
  5514. 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'); ";
  5515. 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>";
  5516. 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'); ";
  5517. 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>";
  5518. return "<div style='margin-left:8px;'>" + str + "</div>";
  5519. };
  5520. $.unformat = function (cellval,options,pos,cnt) {
  5521. // specific for jqGrid only
  5522. var ret, formatType = options.colModel.formatter,
  5523. op =options.colModel.formatoptions || {}, sep,
  5524. re = /([\.\*\_\'\(\)\{\}\+\?\\])/g,
  5525. unformatFunc = options.colModel.unformat||($.fn.fmatter[formatType] && $.fn.fmatter[formatType].unformat);
  5526. if(unformatFunc !== undefined && $.isFunction(unformatFunc) ) {
  5527. ret = unformatFunc.call(this, $(cellval).text(), options, cellval);
  5528. } else if(formatType !== undefined && $.fmatter.isString(formatType) ) {
  5529. var opts = $.jgrid.formatter || {}, stripTag;
  5530. switch(formatType) {
  5531. case 'integer' :
  5532. op = $.extend({},opts.integer,op);
  5533. sep = op.thousandsSeparator.replace(re,"\\$1");
  5534. stripTag = new RegExp(sep, "g");
  5535. ret = $(cellval).text().replace(stripTag,'');
  5536. break;
  5537. case 'number' :
  5538. op = $.extend({},opts.number,op);
  5539. sep = op.thousandsSeparator.replace(re,"\\$1");
  5540. stripTag = new RegExp(sep, "g");
  5541. ret = $(cellval).text().replace(stripTag,"").replace(op.decimalSeparator,'.');
  5542. break;
  5543. case 'currency':
  5544. op = $.extend({},opts.currency,op);
  5545. sep = op.thousandsSeparator.replace(re,"\\$1");
  5546. stripTag = new RegExp(sep, "g");
  5547. ret = $(cellval).text();
  5548. if (op.prefix && op.prefix.length) {
  5549. ret = ret.substr(op.prefix.length);
  5550. }
  5551. if (op.suffix && op.suffix.length) {
  5552. ret = ret.substr(0, ret.length - op.suffix.length);
  5553. }
  5554. ret = ret.replace(stripTag,'').replace(op.decimalSeparator,'.');
  5555. break;
  5556. case 'checkbox':
  5557. var cbv = (options.colModel.editoptions) ? options.colModel.editoptions.value.split(":") : ["Yes","No"];
  5558. ret = $('input',cellval).is(":checked") ? cbv[0] : cbv[1];
  5559. break;
  5560. case 'select' :
  5561. ret = $.unformat.select(cellval,options,pos,cnt);
  5562. break;
  5563. case 'actions':
  5564. return "";
  5565. default:
  5566. ret= $(cellval).text();
  5567. }
  5568. }
  5569. return ret !== undefined ? ret : cnt===true ? $(cellval).text() : $.jgrid.htmlDecode($(cellval).html());
  5570. };
  5571. $.unformat.select = function (cellval,options,pos,cnt) {
  5572. // Spacial case when we have local data and perform a sort
  5573. // cnt is set to true only in sortDataArray
  5574. var ret = [];
  5575. var cell = $(cellval).text();
  5576. if(cnt===true) {return cell;}
  5577. var op = $.extend({}, options.colModel.formatoptions !== undefined ? options.colModel.formatoptions: options.colModel.editoptions),
  5578. sep = op.separator === undefined ? ":" : op.separator,
  5579. delim = op.delimiter === undefined ? ";" : op.delimiter;
  5580. if(op.value){
  5581. var oSelect = op.value,
  5582. msl = op.multiple === true ? true : false,
  5583. scell = [], sv;
  5584. if(msl) {scell = cell.split(",");scell = $.map(scell,function(n){return $.trim(n);});}
  5585. if ($.fmatter.isString(oSelect)) {
  5586. var so = oSelect.split(delim), j=0, i;
  5587. for(i=0; i<so.length;i++){
  5588. sv = so[i].split(sep);
  5589. if(sv.length > 2 ) {
  5590. sv[1] = $.map(sv,function(n,i){if(i>0) {return n;}}).join(sep);
  5591. }
  5592. if(msl) {
  5593. if($.inArray(sv[1],scell)>-1) {
  5594. ret[j] = sv[0];
  5595. j++;
  5596. }
  5597. } else if($.trim(sv[1]) === $.trim(cell)) {
  5598. ret[0] = sv[0];
  5599. break;
  5600. }
  5601. }
  5602. } else if($.fmatter.isObject(oSelect) || $.isArray(oSelect) ){
  5603. if(!msl) {scell[0] = cell;}
  5604. ret = $.map(scell, function(n){
  5605. var rv;
  5606. $.each(oSelect, function(i,val){
  5607. if (val === n) {
  5608. rv = i;
  5609. return false;
  5610. }
  5611. });
  5612. if( rv !== undefined ) {return rv;}
  5613. });
  5614. }
  5615. return ret.join(", ");
  5616. }
  5617. return cell || "";
  5618. };
  5619. $.unformat.date = function (cellval, opts) {
  5620. var op = $.jgrid.formatter.date || {};
  5621. if(opts.formatoptions !== undefined) {
  5622. op = $.extend({},op,opts.formatoptions);
  5623. }
  5624. if(!$.fmatter.isEmpty(cellval)) {
  5625. return $.jgrid.parseDate(op.newformat,cellval,op.srcformat,op);
  5626. }
  5627. return $.fn.fmatter.defaultFormat(cellval, opts);
  5628. };
  5629. })(jQuery);
  5630. /*jshint eqeqeq:false */
  5631. /*global jQuery */
  5632. (function($){
  5633. /*
  5634. * jqGrid common function
  5635. * Tony Tomov tony@trirand.com
  5636. * http://trirand.com/blog/
  5637. * Dual licensed under the MIT and GPL licenses:
  5638. * http://www.opensource.org/licenses/mit-license.php
  5639. * http://www.gnu.org/licenses/gpl-2.0.html
  5640. */
  5641. "use strict";
  5642. $.extend($.jgrid,{
  5643. // Modal functions
  5644. showModal : function(h) {
  5645. h.w.show();
  5646. },
  5647. closeModal : function(h) {
  5648. h.w.hide().attr("aria-hidden","true");
  5649. if(h.o) {h.o.remove();}
  5650. },
  5651. hideModal : function (selector,o) {
  5652. o = $.extend({jqm : true, gb :''}, o || {});
  5653. if(o.onClose) {
  5654. var oncret = o.gb && typeof o.gb === "string" && o.gb.substr(0,6) === "#gbox_" ? o.onClose.call($("#" + o.gb.substr(6))[0], selector) : o.onClose(selector);
  5655. if (typeof oncret === 'boolean' && !oncret ) { return; }
  5656. }
  5657. if ($.fn.jqm && o.jqm === true) {
  5658. $(selector).attr("aria-hidden","true").jqmHide();
  5659. } else {
  5660. if(o.gb !== '') {
  5661. try {$(".jqgrid-overlay:first",o.gb).hide();} catch (e){}
  5662. }
  5663. $(selector).hide().attr("aria-hidden","true");
  5664. }
  5665. },
  5666. //Helper functions
  5667. findPos : function(obj) {
  5668. var curleft = 0, curtop = 0;
  5669. if (obj.offsetParent) {
  5670. do {
  5671. curleft += obj.offsetLeft;
  5672. curtop += obj.offsetTop;
  5673. } while (obj = obj.offsetParent);
  5674. //do not change obj == obj.offsetParent
  5675. }
  5676. return [curleft,curtop];
  5677. },
  5678. createModal : function(aIDs, content, p, insertSelector, posSelector, appendsel, css) {
  5679. p = $.extend(true, {}, $.jgrid.jqModal || {}, p);
  5680. var mw = document.createElement('div'), rtlsup, self = this;
  5681. css = $.extend({}, css || {});
  5682. rtlsup = $(p.gbox).attr("dir") === "rtl" ? true : false;
  5683. mw.className= "ui-widget ui-widget-content ui-corner-all ui-jqdialog";
  5684. mw.id = aIDs.themodal;
  5685. var mh = document.createElement('div');
  5686. mh.className = "ui-jqdialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix";
  5687. mh.id = aIDs.modalhead;
  5688. $(mh).append("<span class='ui-jqdialog-title'>"+p.caption+"</span>");
  5689. var ahr= $("<a href='javascript:void(0)' class='ui-jqdialog-titlebar-close ui-corner-all'></a>")
  5690. .hover(function(){ahr.addClass('ui-state-hover');},
  5691. function(){ahr.removeClass('ui-state-hover');})
  5692. .append("<span class='ui-icon ui-icon-closethick'></span>");
  5693. $(mh).append(ahr);
  5694. if(rtlsup) {
  5695. mw.dir = "rtl";
  5696. $(".ui-jqdialog-title",mh).css("float","right");
  5697. $(".ui-jqdialog-titlebar-close",mh).css("left",0.3+"em");
  5698. } else {
  5699. mw.dir = "ltr";
  5700. $(".ui-jqdialog-title",mh).css("float","left");
  5701. $(".ui-jqdialog-titlebar-close",mh).css("right",0.3+"em");
  5702. }
  5703. var mc = document.createElement('div');
  5704. $(mc).addClass("ui-jqdialog-content ui-widget-content").attr("id",aIDs.modalcontent);
  5705. $(mc).append(content);
  5706. mw.appendChild(mc);
  5707. $(mw).prepend(mh);
  5708. if(appendsel===true) { $('body').append(mw); } //append as first child in body -for alert dialog
  5709. else if (typeof appendsel === "string") {
  5710. $(appendsel).append(mw);
  5711. } else {$(mw).insertBefore(insertSelector);}
  5712. $(mw).css(css);
  5713. if(p.jqModal === undefined) {p.jqModal = true;} // internal use
  5714. var coord = {};
  5715. if ( $.fn.jqm && p.jqModal === true) {
  5716. if(p.left ===0 && p.top===0 && p.overlay) {
  5717. var pos = [];
  5718. pos = $.jgrid.findPos(posSelector);
  5719. p.left = pos[0] + 4;
  5720. p.top = pos[1] + 4;
  5721. }
  5722. coord.top = p.top+"px";
  5723. coord.left = p.left;
  5724. } else if(p.left !==0 || p.top!==0) {
  5725. coord.left = p.left;
  5726. coord.top = p.top+"px";
  5727. }
  5728. $("a.ui-jqdialog-titlebar-close",mh).click(function(){
  5729. var oncm = $("#"+$.jgrid.jqID(aIDs.themodal)).data("onClose") || p.onClose;
  5730. var gboxclose = $("#"+$.jgrid.jqID(aIDs.themodal)).data("gbox") || p.gbox;
  5731. self.hideModal("#"+$.jgrid.jqID(aIDs.themodal),{gb:gboxclose,jqm:p.jqModal,onClose:oncm});
  5732. return false;
  5733. });
  5734. if (p.width === 0 || !p.width) {p.width = 300;}
  5735. if(p.height === 0 || !p.height) {p.height =200;}
  5736. if(!p.zIndex) {
  5737. var parentZ = $(insertSelector).parents("*[role=dialog]").filter(':first').css("z-index");
  5738. if(parentZ) {
  5739. p.zIndex = parseInt(parentZ,10)+2;
  5740. } else {
  5741. p.zIndex = 950;
  5742. }
  5743. }
  5744. var rtlt = 0;
  5745. if( rtlsup && coord.left && !appendsel) {
  5746. rtlt = $(p.gbox).width()- (!isNaN(p.width) ? parseInt(p.width,10) :0) - 8; // to do
  5747. // just in case
  5748. coord.left = parseInt(coord.left,10) + parseInt(rtlt,10);
  5749. }
  5750. if(coord.left) { coord.left += "px"; }
  5751. $(mw).css($.extend({
  5752. width: isNaN(p.width) ? "auto": p.width+"px",
  5753. height:isNaN(p.height) ? "auto" : p.height + "px",
  5754. zIndex:p.zIndex,
  5755. overflow: 'hidden'
  5756. },coord))
  5757. .attr({tabIndex: "-1","role":"dialog","aria-labelledby":aIDs.modalhead,"aria-hidden":"true"});
  5758. if(p.drag === undefined) { p.drag=true;}
  5759. if(p.resize === undefined) {p.resize=true;}
  5760. if (p.drag) {
  5761. $(mh).css('cursor','move');
  5762. if($.fn.jqDrag) {
  5763. $(mw).jqDrag(mh);
  5764. } else {
  5765. try {
  5766. $(mw).draggable({handle: $("#"+$.jgrid.jqID(mh.id))});
  5767. } catch (e) {}
  5768. }
  5769. }
  5770. if(p.resize) {
  5771. if($.fn.jqResize) {
  5772. $(mw).append("<div class='jqResize ui-resizable-handle ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se'></div>");
  5773. $("#"+$.jgrid.jqID(aIDs.themodal)).jqResize(".jqResize",aIDs.scrollelm ? "#"+$.jgrid.jqID(aIDs.scrollelm) : false);
  5774. } else {
  5775. try {
  5776. $(mw).resizable({handles: 'se, sw',alsoResize: aIDs.scrollelm ? "#"+$.jgrid.jqID(aIDs.scrollelm) : false});
  5777. } catch (r) {}
  5778. }
  5779. }
  5780. if(p.closeOnEscape === true){
  5781. $(mw).keydown( function( e ) {
  5782. if( e.which == 27 ) {
  5783. var cone = $("#"+$.jgrid.jqID(aIDs.themodal)).data("onClose") || p.onClose;
  5784. self.hideModal("#"+$.jgrid.jqID(aIDs.themodal),{gb:p.gbox,jqm:p.jqModal,onClose: cone});
  5785. }
  5786. });
  5787. }
  5788. },
  5789. viewModal : function (selector,o){
  5790. o = $.extend({
  5791. toTop: true,
  5792. overlay: 10,
  5793. modal: false,
  5794. overlayClass : 'ui-widget-overlay',
  5795. onShow: $.jgrid.showModal,
  5796. onHide: $.jgrid.closeModal,
  5797. gbox: '',
  5798. jqm : true,
  5799. jqM : true
  5800. }, o || {});
  5801. if ($.fn.jqm && o.jqm === true) {
  5802. if(o.jqM) { $(selector).attr("aria-hidden","false").jqm(o).jqmShow(); }
  5803. else {$(selector).attr("aria-hidden","false").jqmShow();}
  5804. } else {
  5805. if(o.gbox !== '') {
  5806. $(".jqgrid-overlay:first",o.gbox).show();
  5807. $(selector).data("gbox",o.gbox);
  5808. }
  5809. $(selector).show().attr("aria-hidden","false");
  5810. try{$(':input:visible',selector)[0].focus();}catch(_){}
  5811. }
  5812. },
  5813. info_dialog : function(caption, content,c_b, modalopt) {
  5814. var mopt = {
  5815. width:290,
  5816. height:'auto',
  5817. dataheight: 'auto',
  5818. drag: true,
  5819. resize: false,
  5820. left:250,
  5821. top:170,
  5822. zIndex : 1000,
  5823. jqModal : true,
  5824. modal : false,
  5825. closeOnEscape : true,
  5826. align: 'center',
  5827. buttonalign : 'center',
  5828. buttons : []
  5829. // {text:'textbutt', id:"buttid", onClick : function(){...}}
  5830. // 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...
  5831. };
  5832. $.extend(true, mopt, $.jgrid.jqModal || {}, {caption:"<b>"+caption+"</b>"}, modalopt || {});
  5833. var jm = mopt.jqModal, self = this;
  5834. if($.fn.jqm && !jm) { jm = false; }
  5835. // in case there is no jqModal
  5836. var buttstr ="", i;
  5837. if(mopt.buttons.length > 0) {
  5838. for(i=0;i<mopt.buttons.length;i++) {
  5839. if(mopt.buttons[i].id === undefined) { mopt.buttons[i].id = "info_button_"+i; }
  5840. buttstr += "<a href='javascript:void(0)' id='"+mopt.buttons[i].id+"' class='fm-button ui-state-default ui-corner-all'>"+mopt.buttons[i].text+"</a>";
  5841. }
  5842. }
  5843. var dh = isNaN(mopt.dataheight) ? mopt.dataheight : mopt.dataheight+"px",
  5844. cn = "text-align:"+mopt.align+";";
  5845. var cnt = "<div id='info_id'>";
  5846. cnt += "<div id='infocnt' style='margin:0px;padding-bottom:1em;width:100%;overflow:auto;position:relative;height:"+dh+";"+cn+"'>"+content+"</div>";
  5847. cnt += c_b ? "<div class='ui-widget-content ui-helper-clearfix' style='text-align:"+mopt.buttonalign+";padding-bottom:0.8em;padding-top:0.5em;background-image: none;border-width: 1px 0 0 0;'><a href='javascript:void(0)' id='closedialog' class='fm-button ui-state-default ui-corner-all'>"+c_b+"</a>"+buttstr+"</div>" :
  5848. 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>" : "";
  5849. cnt += "</div>";
  5850. try {
  5851. if($("#info_dialog").attr("aria-hidden") === "false") {
  5852. $.jgrid.hideModal("#info_dialog",{jqm:jm});
  5853. }
  5854. $("#info_dialog").remove();
  5855. } catch (e){}
  5856. $.jgrid.createModal({
  5857. themodal:'info_dialog',
  5858. modalhead:'info_head',
  5859. modalcontent:'info_content',
  5860. scrollelm: 'infocnt'},
  5861. cnt,
  5862. mopt,
  5863. '','',true
  5864. );
  5865. // attach onclick after inserting into the dom
  5866. if(buttstr) {
  5867. $.each(mopt.buttons,function(i){
  5868. $("#"+$.jgrid.jqID(this.id),"#info_id").bind('click',function(){mopt.buttons[i].onClick.call($("#info_dialog")); return false;});
  5869. });
  5870. }
  5871. $("#closedialog", "#info_id").click(function(){
  5872. self.hideModal("#info_dialog",{
  5873. jqm:jm,
  5874. onClose: $("#info_dialog").data("onClose") || mopt.onClose,
  5875. gb: $("#info_dialog").data("gbox") || mopt.gbox
  5876. });
  5877. return false;
  5878. });
  5879. $(".fm-button","#info_dialog").hover(
  5880. function(){$(this).addClass('ui-state-hover');},
  5881. function(){$(this).removeClass('ui-state-hover');}
  5882. );
  5883. if($.isFunction(mopt.beforeOpen) ) { mopt.beforeOpen(); }
  5884. $.jgrid.viewModal("#info_dialog",{
  5885. onHide: function(h) {
  5886. h.w.hide().remove();
  5887. if(h.o) { h.o.remove(); }
  5888. },
  5889. modal :mopt.modal,
  5890. jqm:jm
  5891. });
  5892. if($.isFunction(mopt.afterOpen) ) { mopt.afterOpen(); }
  5893. try{ $("#info_dialog").focus();} catch (m){}
  5894. },
  5895. bindEv: function (el, opt) {
  5896. var $t = this;
  5897. if($.isFunction(opt.dataInit)) {
  5898. opt.dataInit.call($t,el);
  5899. }
  5900. if(opt.dataEvents) {
  5901. $.each(opt.dataEvents, function() {
  5902. if (this.data !== undefined) {
  5903. $(el).bind(this.type, this.data, this.fn);
  5904. } else {
  5905. $(el).bind(this.type, this.fn);
  5906. }
  5907. });
  5908. }
  5909. },
  5910. // Form Functions
  5911. createEl : function(eltype,options,vl,autowidth, ajaxso) {
  5912. var elem = "", $t = this;
  5913. function setAttributes(elm, atr, exl ) {
  5914. var exclude = ['dataInit','dataEvents','dataUrl', 'buildSelect','sopt', 'searchhidden', 'defaultValue', 'attr', 'custom_element', 'custom_value'];
  5915. if(exl !== undefined && $.isArray(exl)) {
  5916. $.merge(exclude, exl);
  5917. }
  5918. $.each(atr, function(key, value){
  5919. if($.inArray(key, exclude) === -1) {
  5920. $(elm).attr(key,value);
  5921. }
  5922. });
  5923. if(!atr.hasOwnProperty('id')) {
  5924. $(elm).attr('id', $.jgrid.randId());
  5925. }
  5926. }
  5927. switch (eltype)
  5928. {
  5929. case "textarea" :
  5930. elem = document.createElement("textarea");
  5931. if(autowidth) {
  5932. if(!options.cols) { $(elem).css({width:"98%"});}
  5933. } else if (!options.cols) { options.cols = 20; }
  5934. if(!options.rows) { options.rows = 2; }
  5935. if(vl==='&nbsp;' || vl==='&#160;' || (vl.length===1 && vl.charCodeAt(0)===160)) {vl="";}
  5936. elem.value = vl;
  5937. setAttributes(elem, options);
  5938. $(elem).attr({"role":"textbox","multiline":"true"});
  5939. break;
  5940. case "checkbox" : //what code for simple checkbox
  5941. elem = document.createElement("input");
  5942. elem.type = "checkbox";
  5943. if( !options.value ) {
  5944. var vl1 = vl.toLowerCase();
  5945. if(vl1.search(/(false|f|0|no|n|off|undefined)/i)<0 && vl1!=="") {
  5946. elem.checked=true;
  5947. elem.defaultChecked=true;
  5948. elem.value = vl;
  5949. } else {
  5950. elem.value = "on";
  5951. }
  5952. $(elem).attr("offval","off");
  5953. } else {
  5954. var cbval = options.value.split(":");
  5955. if(vl === cbval[0]) {
  5956. elem.checked=true;
  5957. elem.defaultChecked=true;
  5958. }
  5959. elem.value = cbval[0];
  5960. $(elem).attr("offval",cbval[1]);
  5961. }
  5962. setAttributes(elem, options, ['value']);
  5963. $(elem).attr("role","checkbox");
  5964. break;
  5965. case "select" :
  5966. elem = document.createElement("select");
  5967. elem.setAttribute("role","select");
  5968. var msl, ovm = [];
  5969. if(options.multiple===true) {
  5970. msl = true;
  5971. elem.multiple="multiple";
  5972. $(elem).attr("aria-multiselectable","true");
  5973. } else { msl = false; }
  5974. if(options.dataUrl !== undefined) {
  5975. var rowid = options.name ? String(options.id).substring(0, String(options.id).length - String(options.name).length - 1) : String(options.id),
  5976. postData = options.postData || ajaxso.postData;
  5977. if ($t.p && $t.p.idPrefix) {
  5978. rowid = $.jgrid.stripPref($t.p.idPrefix, rowid);
  5979. } else {
  5980. postData = undefined; // don't use postData for searching from jqFilter. One can implement the feature in the future if required.
  5981. }
  5982. $.ajax($.extend({
  5983. url: options.dataUrl,
  5984. type : "GET",
  5985. dataType: "html",
  5986. data: $.isFunction(postData) ? postData.call($t, rowid, vl, String(options.name)) : postData,
  5987. context: {elem:elem, options:options, vl:vl},
  5988. success: function(data){
  5989. var ovm = [], elem = this.elem, vl = this.vl,
  5990. options = $.extend({},this.options),
  5991. msl = options.multiple===true,
  5992. a = $.isFunction(options.buildSelect) ? options.buildSelect.call($t,data) : data;
  5993. if(typeof a === 'string') {
  5994. a = $( $.trim( a ) ).html();
  5995. }
  5996. if(a) {
  5997. $(elem).append(a);
  5998. setAttributes(elem, options);
  5999. if(options.size === undefined) { options.size = msl ? 3 : 1;}
  6000. if(msl) {
  6001. ovm = vl.split(",");
  6002. ovm = $.map(ovm,function(n){return $.trim(n);});
  6003. } else {
  6004. ovm[0] = $.trim(vl);
  6005. }
  6006. //$(elem).attr(options);
  6007. setTimeout(function(){
  6008. $("option",elem).each(function(i){
  6009. //if(i===0) { this.selected = ""; }
  6010. // fix IE8/IE7 problem with selecting of the first item on multiple=true
  6011. if (i === 0 && elem.multiple) { this.selected = false; }
  6012. $(this).attr("role","option");
  6013. if($.inArray($.trim($(this).text()),ovm) > -1 || $.inArray($.trim($(this).val()),ovm) > -1 ) {
  6014. this.selected= "selected";
  6015. }
  6016. });
  6017. },0);
  6018. }
  6019. }
  6020. },ajaxso || {}));
  6021. } else if(options.value) {
  6022. var i;
  6023. if(options.size === undefined) {
  6024. options.size = msl ? 3 : 1;
  6025. }
  6026. if(msl) {
  6027. ovm = vl.split(",");
  6028. ovm = $.map(ovm,function(n){return $.trim(n);});
  6029. }
  6030. if(typeof options.value === 'function') { options.value = options.value(); }
  6031. var so,sv, ov,
  6032. sep = options.separator === undefined ? ":" : options.separator,
  6033. delim = options.delimiter === undefined ? ";" : options.delimiter;
  6034. if(typeof options.value === 'string') {
  6035. so = options.value.split(delim);
  6036. for(i=0; i<so.length;i++){
  6037. sv = so[i].split(sep);
  6038. if(sv.length > 2 ) {
  6039. sv[1] = $.map(sv,function(n,ii){if(ii>0) { return n;} }).join(sep);
  6040. }
  6041. ov = document.createElement("option");
  6042. ov.setAttribute("role","option");
  6043. ov.value = sv[0]; ov.innerHTML = sv[1];
  6044. elem.appendChild(ov);
  6045. if (!msl && ($.trim(sv[0]) === $.trim(vl) || $.trim(sv[1]) === $.trim(vl))) { ov.selected ="selected"; }
  6046. if (msl && ($.inArray($.trim(sv[1]), ovm)>-1 || $.inArray($.trim(sv[0]), ovm)>-1)) {ov.selected ="selected";}
  6047. }
  6048. } else if (typeof options.value === 'object') {
  6049. var oSv = options.value, key;
  6050. for (key in oSv) {
  6051. if (oSv.hasOwnProperty(key ) ){
  6052. ov = document.createElement("option");
  6053. ov.setAttribute("role","option");
  6054. ov.value = key; ov.innerHTML = oSv[key];
  6055. elem.appendChild(ov);
  6056. if (!msl && ( $.trim(key) === $.trim(vl) || $.trim(oSv[key]) === $.trim(vl)) ) { ov.selected ="selected"; }
  6057. if (msl && ($.inArray($.trim(oSv[key]),ovm)>-1 || $.inArray($.trim(key),ovm)>-1)) { ov.selected ="selected"; }
  6058. }
  6059. }
  6060. }
  6061. setAttributes(elem, options, ['value']);
  6062. }
  6063. break;
  6064. case "text" :
  6065. case "password" :
  6066. case "button" :
  6067. var role;
  6068. if(eltype==="button") { role = "button"; }
  6069. else { role = "textbox"; }
  6070. elem = document.createElement("input");
  6071. elem.type = eltype;
  6072. elem.value = vl;
  6073. setAttributes(elem, options);
  6074. if(eltype !== "button"){
  6075. if(autowidth) {
  6076. if(!options.size) { $(elem).css({width:"98%"}); }
  6077. } else if (!options.size) { options.size = 20; }
  6078. }
  6079. $(elem).attr("role",role);
  6080. break;
  6081. case "image" :
  6082. case "file" :
  6083. elem = document.createElement("input");
  6084. elem.type = eltype;
  6085. setAttributes(elem, options);
  6086. break;
  6087. case "custom" :
  6088. elem = document.createElement("span");
  6089. try {
  6090. if($.isFunction(options.custom_element)) {
  6091. var celm = options.custom_element.call($t,vl,options);
  6092. if(celm) {
  6093. celm = $(celm).addClass("customelement").attr({id:options.id,name:options.name});
  6094. $(elem).empty().append(celm);
  6095. } else {
  6096. throw "e2";
  6097. }
  6098. } else {
  6099. throw "e1";
  6100. }
  6101. } catch (e) {
  6102. if (e==="e1") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_element' "+$.jgrid.edit.msg.nodefined, $.jgrid.edit.bClose);}
  6103. if (e==="e2") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_element' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose);}
  6104. else { $.jgrid.info_dialog($.jgrid.errors.errcap,typeof e==="string"?e:e.message,$.jgrid.edit.bClose); }
  6105. }
  6106. break;
  6107. }
  6108. return elem;
  6109. },
  6110. // Date Validation Javascript
  6111. checkDate : function (format, date) {
  6112. var daysInFebruary = function(year){
  6113. // February has 29 days in any year evenly divisible by four,
  6114. // EXCEPT for centurial years which are not also divisible by 400.
  6115. return (((year % 4 === 0) && ( year % 100 !== 0 || (year % 400 === 0))) ? 29 : 28 );
  6116. },
  6117. tsp = {}, sep;
  6118. format = format.toLowerCase();
  6119. //we search for /,-,. for the date separator
  6120. if(format.indexOf("/") !== -1) {
  6121. sep = "/";
  6122. } else if(format.indexOf("-") !== -1) {
  6123. sep = "-";
  6124. } else if(format.indexOf(".") !== -1) {
  6125. sep = ".";
  6126. } else {
  6127. sep = "/";
  6128. }
  6129. format = format.split(sep);
  6130. date = date.split(sep);
  6131. if (date.length !== 3) { return false; }
  6132. var j=-1,yln, dln=-1, mln=-1, i;
  6133. for(i=0;i<format.length;i++){
  6134. var dv = isNaN(date[i]) ? 0 : parseInt(date[i],10);
  6135. tsp[format[i]] = dv;
  6136. yln = format[i];
  6137. if(yln.indexOf("y") !== -1) { j=i; }
  6138. if(yln.indexOf("m") !== -1) { mln=i; }
  6139. if(yln.indexOf("d") !== -1) { dln=i; }
  6140. }
  6141. if (format[j] === "y" || format[j] === "yyyy") {
  6142. yln=4;
  6143. } else if(format[j] ==="yy"){
  6144. yln = 2;
  6145. } else {
  6146. yln = -1;
  6147. }
  6148. var daysInMonth = [0,31,29,31,30,31,30,31,31,30,31,30,31],
  6149. strDate;
  6150. if (j === -1) {
  6151. return false;
  6152. }
  6153. strDate = tsp[format[j]].toString();
  6154. if(yln === 2 && strDate.length === 1) {yln = 1;}
  6155. if (strDate.length !== yln || (tsp[format[j]]===0 && date[j]!=="00")){
  6156. return false;
  6157. }
  6158. if(mln === -1) {
  6159. return false;
  6160. }
  6161. strDate = tsp[format[mln]].toString();
  6162. if (strDate.length<1 || tsp[format[mln]]<1 || tsp[format[mln]]>12){
  6163. return false;
  6164. }
  6165. if(dln === -1) {
  6166. return false;
  6167. }
  6168. strDate = tsp[format[dln]].toString();
  6169. 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]]]){
  6170. return false;
  6171. }
  6172. return true;
  6173. },
  6174. isEmpty : function(val)
  6175. {
  6176. if (val.match(/^\s+$/) || val === "") {
  6177. return true;
  6178. }
  6179. return false;
  6180. },
  6181. checkTime : function(time){
  6182. // checks only hh:ss (and optional am/pm)
  6183. var re = /^(\d{1,2}):(\d{2})([apAP][Mm])?$/,regs;
  6184. if(!$.jgrid.isEmpty(time))
  6185. {
  6186. regs = time.match(re);
  6187. if(regs) {
  6188. if(regs[3]) {
  6189. if(regs[1] < 1 || regs[1] > 12) { return false; }
  6190. } else {
  6191. if(regs[1] > 23) { return false; }
  6192. }
  6193. if(regs[2] > 59) {
  6194. return false;
  6195. }
  6196. } else {
  6197. return false;
  6198. }
  6199. }
  6200. return true;
  6201. },
  6202. checkValues : function(val, valref, customobject, nam) {
  6203. var edtrul,i, nm, dft, len, g = this, cm = g.p.colModel;
  6204. if(customobject === undefined) {
  6205. if(typeof valref==='string'){
  6206. for( i =0, len=cm.length;i<len; i++){
  6207. if(cm[i].name===valref) {
  6208. edtrul = cm[i].editrules;
  6209. valref = i;
  6210. if(cm[i].formoptions != null) { nm = cm[i].formoptions.label; }
  6211. break;
  6212. }
  6213. }
  6214. } else if(valref >=0) {
  6215. edtrul = cm[valref].editrules;
  6216. }
  6217. } else {
  6218. edtrul = customobject;
  6219. nm = nam===undefined ? "_" : nam;
  6220. }
  6221. if(edtrul) {
  6222. if(!nm) { nm = g.p.colNames != null ? g.p.colNames[valref] : cm[valref].label; }
  6223. if(edtrul.required === true) {
  6224. if( $.jgrid.isEmpty(val) ) { return [false,nm+": "+$.jgrid.edit.msg.required,""]; }
  6225. }
  6226. // force required
  6227. var rqfield = edtrul.required === false ? false : true;
  6228. if(edtrul.number === true) {
  6229. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  6230. if(isNaN(val)) { return [false,nm+": "+$.jgrid.edit.msg.number,""]; }
  6231. }
  6232. }
  6233. if(edtrul.minValue !== undefined && !isNaN(edtrul.minValue)) {
  6234. if (parseFloat(val) < parseFloat(edtrul.minValue) ) { return [false,nm+": "+$.jgrid.edit.msg.minValue+" "+edtrul.minValue,""];}
  6235. }
  6236. if(edtrul.maxValue !== undefined && !isNaN(edtrul.maxValue)) {
  6237. if (parseFloat(val) > parseFloat(edtrul.maxValue) ) { return [false,nm+": "+$.jgrid.edit.msg.maxValue+" "+edtrul.maxValue,""];}
  6238. }
  6239. var filter;
  6240. if(edtrul.email === true) {
  6241. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  6242. // taken from $ Validate plugin
  6243. 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;
  6244. if(!filter.test(val)) {return [false,nm+": "+$.jgrid.edit.msg.email,""];}
  6245. }
  6246. }
  6247. if(edtrul.integer === true) {
  6248. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  6249. if(isNaN(val)) { return [false,nm+": "+$.jgrid.edit.msg.integer,""]; }
  6250. if ((val % 1 !== 0) || (val.indexOf('.') !== -1)) { return [false,nm+": "+$.jgrid.edit.msg.integer,""];}
  6251. }
  6252. }
  6253. if(edtrul.date === true) {
  6254. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  6255. if(cm[valref].formatoptions && cm[valref].formatoptions.newformat) {
  6256. dft = cm[valref].formatoptions.newformat;
  6257. if( $.jgrid.formatter.date.masks.hasOwnProperty(dft) ) {
  6258. dft = $.jgrid.formatter.date.masks[dft];
  6259. }
  6260. } else {
  6261. dft = cm[valref].datefmt || "Y-m-d";
  6262. }
  6263. if(!$.jgrid.checkDate (dft, val)) { return [false,nm+": "+$.jgrid.edit.msg.date+" - "+dft,""]; }
  6264. }
  6265. }
  6266. if(edtrul.time === true) {
  6267. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  6268. if(!$.jgrid.checkTime (val)) { return [false,nm+": "+$.jgrid.edit.msg.date+" - hh:mm (am/pm)",""]; }
  6269. }
  6270. }
  6271. if(edtrul.url === true) {
  6272. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  6273. filter = /^(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
  6274. if(!filter.test(val)) {return [false,nm+": "+$.jgrid.edit.msg.url,""];}
  6275. }
  6276. }
  6277. if(edtrul.custom === true) {
  6278. if( !(rqfield === false && $.jgrid.isEmpty(val)) ) {
  6279. if($.isFunction(edtrul.custom_func)) {
  6280. var ret = edtrul.custom_func.call(g,val,nm,valref);
  6281. return $.isArray(ret) ? ret : [false,$.jgrid.edit.msg.customarray,""];
  6282. }
  6283. return [false,$.jgrid.edit.msg.customfcheck,""];
  6284. }
  6285. }
  6286. }
  6287. return [true,"",""];
  6288. }
  6289. });
  6290. })(jQuery);
  6291. /*
  6292. * jqFilter jQuery jqGrid filter addon.
  6293. * Copyright (c) 2011, Tony Tomov, tony@trirand.com
  6294. * Dual licensed under the MIT and GPL licenses
  6295. * http://www.opensource.org/licenses/mit-license.php
  6296. * http://www.gnu.org/licenses/gpl-2.0.html
  6297. *
  6298. * The work is inspired from this Stefan Pirvu
  6299. * http://www.codeproject.com/KB/scripting/json-filtering.aspx
  6300. *
  6301. * The filter uses JSON entities to hold filter rules and groups. Here is an example of a filter:
  6302. { "groupOp": "AND",
  6303. "groups" : [
  6304. { "groupOp": "OR",
  6305. "rules": [
  6306. { "field": "name", "op": "eq", "data": "England" },
  6307. { "field": "id", "op": "le", "data": "5"}
  6308. ]
  6309. }
  6310. ],
  6311. "rules": [
  6312. { "field": "name", "op": "eq", "data": "Romania" },
  6313. { "field": "id", "op": "le", "data": "1"}
  6314. ]
  6315. }
  6316. */
  6317. /*jshint eqeqeq:false, eqnull:true, devel:true */
  6318. /*global jQuery */
  6319. (function ($) {
  6320. "use strict";
  6321. $.fn.jqFilter = function( arg ) {
  6322. if (typeof arg === 'string') {
  6323. var fn = $.fn.jqFilter[arg];
  6324. if (!fn) {
  6325. throw ("jqFilter - No such method: " + arg);
  6326. }
  6327. var args = $.makeArray(arguments).slice(1);
  6328. return fn.apply(this,args);
  6329. }
  6330. var p = $.extend(true,{
  6331. filter: null,
  6332. columns: [],
  6333. onChange : null,
  6334. afterRedraw : null,
  6335. checkValues : null,
  6336. error: false,
  6337. errmsg : "",
  6338. errorcheck : true,
  6339. showQuery : true,
  6340. sopt : null,
  6341. ops : [],
  6342. operands : null,
  6343. numopts : ['eq','ne', 'lt', 'le', 'gt', 'ge', 'nu', 'nn', 'in', 'ni'],
  6344. stropts : ['eq', 'ne', 'bw', 'bn', 'ew', 'en', 'cn', 'nc', 'nu', 'nn', 'in', 'ni'],
  6345. strarr : ['text', 'string', 'blob'],
  6346. groupOps : [{ op: "AND", text: "AND" }, { op: "OR", text: "OR" }],
  6347. groupButton : true,
  6348. ruleButtons : true,
  6349. direction : "ltr"
  6350. }, $.jgrid.filter, arg || {});
  6351. return this.each( function() {
  6352. if (this.filter) {return;}
  6353. this.p = p;
  6354. // setup filter in case if they is not defined
  6355. if (this.p.filter === null || this.p.filter === undefined) {
  6356. this.p.filter = {
  6357. groupOp: this.p.groupOps[0].op,
  6358. rules: [],
  6359. groups: []
  6360. };
  6361. }
  6362. var i, len = this.p.columns.length, cl,
  6363. isIE = /msie/i.test(navigator.userAgent) && !window.opera;
  6364. // translating the options
  6365. this.p.initFilter = $.extend(true,{},this.p.filter);
  6366. // set default values for the columns if they are not set
  6367. if( !len ) {return;}
  6368. for(i=0; i < len; i++) {
  6369. cl = this.p.columns[i];
  6370. if( cl.stype ) {
  6371. // grid compatibility
  6372. cl.inputtype = cl.stype;
  6373. } else if(!cl.inputtype) {
  6374. cl.inputtype = 'text';
  6375. }
  6376. if( cl.sorttype ) {
  6377. // grid compatibility
  6378. cl.searchtype = cl.sorttype;
  6379. } else if (!cl.searchtype) {
  6380. cl.searchtype = 'string';
  6381. }
  6382. if(cl.hidden === undefined) {
  6383. // jqGrid compatibility
  6384. cl.hidden = false;
  6385. }
  6386. if(!cl.label) {
  6387. cl.label = cl.name;
  6388. }
  6389. if(cl.index) {
  6390. cl.name = cl.index;
  6391. }
  6392. if(!cl.hasOwnProperty('searchoptions')) {
  6393. cl.searchoptions = {};
  6394. }
  6395. if(!cl.hasOwnProperty('searchrules')) {
  6396. cl.searchrules = {};
  6397. }
  6398. }
  6399. if(this.p.showQuery) {
  6400. $(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>");
  6401. }
  6402. var getGrid = function () {
  6403. return $("#" + $.jgrid.jqID(p.id))[0] || null;
  6404. };
  6405. /*
  6406. *Perform checking.
  6407. *
  6408. */
  6409. var checkData = function(val, colModelItem) {
  6410. var ret = [true,""], $t = getGrid();
  6411. if($.isFunction(colModelItem.searchrules)) {
  6412. ret = colModelItem.searchrules.call($t, val, colModelItem);
  6413. } else if($.jgrid && $.jgrid.checkValues) {
  6414. try {
  6415. ret = $.jgrid.checkValues.call($t, val, -1, colModelItem.searchrules, colModelItem.label);
  6416. } catch (e) {}
  6417. }
  6418. if(ret && ret.length && ret[0] === false) {
  6419. p.error = !ret[0];
  6420. p.errmsg = ret[1];
  6421. }
  6422. };
  6423. /* moving to common
  6424. randId = function() {
  6425. return Math.floor(Math.random()*10000).toString();
  6426. };
  6427. */
  6428. this.onchange = function ( ){
  6429. // clear any error
  6430. this.p.error = false;
  6431. this.p.errmsg="";
  6432. return $.isFunction(this.p.onChange) ? this.p.onChange.call( this, this.p ) : false;
  6433. };
  6434. /*
  6435. * Redraw the filter every time when new field is added/deleted
  6436. * and field is changed
  6437. */
  6438. this.reDraw = function() {
  6439. $("table.group:first",this).remove();
  6440. var t = this.createTableForGroup(p.filter, null);
  6441. $(this).append(t);
  6442. if($.isFunction(this.p.afterRedraw) ) {
  6443. this.p.afterRedraw.call(this, this.p);
  6444. }
  6445. };
  6446. /*
  6447. * Creates a grouping data for the filter
  6448. * @param group - object
  6449. * @param parentgroup - object
  6450. */
  6451. this.createTableForGroup = function(group, parentgroup) {
  6452. var that = this, i;
  6453. // this table will hold all the group (tables) and rules (rows)
  6454. var table = $("<table class='group ui-widget ui-widget-content' style='border:0px none;'><tbody></tbody></table>"),
  6455. // create error message row
  6456. align = "left";
  6457. if(this.p.direction === "rtl") {
  6458. align = "right";
  6459. table.attr("dir","rtl");
  6460. }
  6461. if(parentgroup === null) {
  6462. table.append("<tr class='error' style='display:none;'><th colspan='5' class='ui-state-error' align='"+align+"'></th></tr>");
  6463. }
  6464. var tr = $("<tr></tr>");
  6465. table.append(tr);
  6466. // this header will hold the group operator type and group action buttons for
  6467. // creating subgroup "+ {}", creating rule "+" or deleting the group "-"
  6468. var th = $("<th colspan='5' align='"+align+"'></th>");
  6469. tr.append(th);
  6470. if(this.p.ruleButtons === true) {
  6471. // dropdown for: choosing group operator type
  6472. var groupOpSelect = $("<select class='opsel'></select>");
  6473. th.append(groupOpSelect);
  6474. // populate dropdown with all posible group operators: or, and
  6475. var str= "", selected;
  6476. for (i = 0; i < p.groupOps.length; i++) {
  6477. selected = group.groupOp === that.p.groupOps[i].op ? " selected='selected'" :"";
  6478. str += "<option value='"+that.p.groupOps[i].op+"'" + selected+">"+that.p.groupOps[i].text+"</option>";
  6479. }
  6480. groupOpSelect
  6481. .append(str)
  6482. .bind('change',function() {
  6483. group.groupOp = $(groupOpSelect).val();
  6484. that.onchange(); // signals that the filter has changed
  6485. });
  6486. }
  6487. // button for adding a new subgroup
  6488. var inputAddSubgroup ="<span></span>";
  6489. if(this.p.groupButton) {
  6490. inputAddSubgroup = $("<input type='button' value='+ {}' title='Add subgroup' class='add-group'/>");
  6491. inputAddSubgroup.bind('click',function() {
  6492. if (group.groups === undefined ) {
  6493. group.groups = [];
  6494. }
  6495. group.groups.push({
  6496. groupOp: p.groupOps[0].op,
  6497. rules: [],
  6498. groups: []
  6499. }); // adding a new group
  6500. that.reDraw(); // the html has changed, force reDraw
  6501. that.onchange(); // signals that the filter has changed
  6502. return false;
  6503. });
  6504. }
  6505. th.append(inputAddSubgroup);
  6506. if(this.p.ruleButtons === true) {
  6507. // button for adding a new rule
  6508. var inputAddRule = $("<input type='button' value='+' title='Add rule' class='add-rule ui-add'/>"), cm;
  6509. inputAddRule.bind('click',function() {
  6510. //if(!group) { group = {};}
  6511. if (group.rules === undefined) {
  6512. group.rules = [];
  6513. }
  6514. for (i = 0; i < that.p.columns.length; i++) {
  6515. // but show only serchable and serchhidden = true fields
  6516. var searchable = (that.p.columns[i].search === undefined) ? true: that.p.columns[i].search,
  6517. hidden = (that.p.columns[i].hidden === true),
  6518. ignoreHiding = (that.p.columns[i].searchoptions.searchhidden === true);
  6519. if ((ignoreHiding && searchable) || (searchable && !hidden)) {
  6520. cm = that.p.columns[i];
  6521. break;
  6522. }
  6523. }
  6524. var opr;
  6525. if( cm.searchoptions.sopt ) {opr = cm.searchoptions.sopt;}
  6526. else if(that.p.sopt) { opr= that.p.sopt; }
  6527. else if ( $.inArray(cm.searchtype, that.p.strarr) !== -1 ) {opr = that.p.stropts;}
  6528. else {opr = that.p.numopts;}
  6529. group.rules.push({
  6530. field: cm.name,
  6531. op: opr[0],
  6532. data: ""
  6533. }); // adding a new rule
  6534. that.reDraw(); // the html has changed, force reDraw
  6535. // for the moment no change have been made to the rule, so
  6536. // this will not trigger onchange event
  6537. return false;
  6538. });
  6539. th.append(inputAddRule);
  6540. }
  6541. // button for delete the group
  6542. if (parentgroup !== null) { // ignore the first group
  6543. var inputDeleteGroup = $("<input type='button' value='-' title='Delete group' class='delete-group'/>");
  6544. th.append(inputDeleteGroup);
  6545. inputDeleteGroup.bind('click',function() {
  6546. // remove group from parent
  6547. for (i = 0; i < parentgroup.groups.length; i++) {
  6548. if (parentgroup.groups[i] === group) {
  6549. parentgroup.groups.splice(i, 1);
  6550. break;
  6551. }
  6552. }
  6553. that.reDraw(); // the html has changed, force reDraw
  6554. that.onchange(); // signals that the filter has changed
  6555. return false;
  6556. });
  6557. }
  6558. // append subgroup rows
  6559. if (group.groups !== undefined) {
  6560. for (i = 0; i < group.groups.length; i++) {
  6561. var trHolderForSubgroup = $("<tr></tr>");
  6562. table.append(trHolderForSubgroup);
  6563. var tdFirstHolderForSubgroup = $("<td class='first'></td>");
  6564. trHolderForSubgroup.append(tdFirstHolderForSubgroup);
  6565. var tdMainHolderForSubgroup = $("<td colspan='4'></td>");
  6566. tdMainHolderForSubgroup.append(this.createTableForGroup(group.groups[i], group));
  6567. trHolderForSubgroup.append(tdMainHolderForSubgroup);
  6568. }
  6569. }
  6570. if(group.groupOp === undefined) {
  6571. group.groupOp = that.p.groupOps[0].op;
  6572. }
  6573. // append rules rows
  6574. if (group.rules !== undefined) {
  6575. for (i = 0; i < group.rules.length; i++) {
  6576. table.append(
  6577. this.createTableRowForRule(group.rules[i], group)
  6578. );
  6579. }
  6580. }
  6581. return table;
  6582. };
  6583. /*
  6584. * Create the rule data for the filter
  6585. */
  6586. this.createTableRowForRule = function(rule, group ) {
  6587. // save current entity in a variable so that it could
  6588. // be referenced in anonimous method calls
  6589. var that=this, $t = getGrid(), tr = $("<tr></tr>"),
  6590. //document.createElement("tr"),
  6591. // first column used for padding
  6592. //tdFirstHolderForRule = document.createElement("td"),
  6593. i, op, trpar, cm, str="", selected;
  6594. //tdFirstHolderForRule.setAttribute("class", "first");
  6595. tr.append("<td class='first'></td>");
  6596. // create field container
  6597. var ruleFieldTd = $("<td class='columns'></td>");
  6598. tr.append(ruleFieldTd);
  6599. // dropdown for: choosing field
  6600. var ruleFieldSelect = $("<select></select>"), ina, aoprs = [];
  6601. ruleFieldTd.append(ruleFieldSelect);
  6602. ruleFieldSelect.bind('change',function() {
  6603. rule.field = $(ruleFieldSelect).val();
  6604. trpar = $(this).parents("tr:first");
  6605. for (i=0;i<that.p.columns.length;i++) {
  6606. if(that.p.columns[i].name === rule.field) {
  6607. cm = that.p.columns[i];
  6608. break;
  6609. }
  6610. }
  6611. if(!cm) {return;}
  6612. cm.searchoptions.id = $.jgrid.randId();
  6613. if(isIE && cm.inputtype === "text") {
  6614. if(!cm.searchoptions.size) {
  6615. cm.searchoptions.size = 10;
  6616. }
  6617. }
  6618. var elm = $.jgrid.createEl.call($t, cm.inputtype,cm.searchoptions, "", true, that.p.ajaxSelectOptions, true);
  6619. $(elm).addClass("input-elm");
  6620. //that.createElement(rule, "");
  6621. if( cm.searchoptions.sopt ) {op = cm.searchoptions.sopt;}
  6622. else if(that.p.sopt) { op= that.p.sopt; }
  6623. else if ($.inArray(cm.searchtype, that.p.strarr) !== -1) {op = that.p.stropts;}
  6624. else {op = that.p.numopts;}
  6625. // operators
  6626. var s ="", so = 0;
  6627. aoprs = [];
  6628. $.each(that.p.ops, function() { aoprs.push(this.oper); });
  6629. for ( i = 0 ; i < op.length; i++) {
  6630. ina = $.inArray(op[i],aoprs);
  6631. if(ina !== -1) {
  6632. if(so===0) {
  6633. rule.op = that.p.ops[ina].oper;
  6634. }
  6635. s += "<option value='"+that.p.ops[ina].oper+"'>"+that.p.ops[ina].text+"</option>";
  6636. so++;
  6637. }
  6638. }
  6639. $(".selectopts",trpar).empty().append( s );
  6640. $(".selectopts",trpar)[0].selectedIndex = 0;
  6641. if( $.jgrid.msie && $.jgrid.msiever() < 9) {
  6642. var sw = parseInt($("select.selectopts",trpar)[0].offsetWidth, 10) + 1;
  6643. $(".selectopts",trpar).width( sw );
  6644. $(".selectopts",trpar).css("width","auto");
  6645. }
  6646. // data
  6647. $(".data",trpar).empty().append( elm );
  6648. $.jgrid.bindEv.call($t, elm, cm.searchoptions);
  6649. $(".input-elm",trpar).bind('change',function( e ) {
  6650. var tmo = $(this).hasClass("ui-autocomplete-input") ? 200 :0;
  6651. setTimeout(function(){
  6652. var elem = e.target;
  6653. rule.data = elem.nodeName.toUpperCase() === "SPAN" && cm.searchoptions && $.isFunction(cm.searchoptions.custom_value) ?
  6654. cm.searchoptions.custom_value.call($t, $(elem).children(".customelement:first"), 'get') : elem.value;
  6655. that.onchange(); // signals that the filter has changed
  6656. }, tmo);
  6657. });
  6658. setTimeout(function(){ //IE, Opera, Chrome
  6659. rule.data = $(elm).val();
  6660. that.onchange(); // signals that the filter has changed
  6661. }, 0);
  6662. });
  6663. // populate drop down with user provided column definitions
  6664. var j=0;
  6665. for (i = 0; i < that.p.columns.length; i++) {
  6666. // but show only serchable and serchhidden = true fields
  6667. var searchable = (that.p.columns[i].search === undefined) ? true: that.p.columns[i].search,
  6668. hidden = (that.p.columns[i].hidden === true),
  6669. ignoreHiding = (that.p.columns[i].searchoptions.searchhidden === true);
  6670. if ((ignoreHiding && searchable) || (searchable && !hidden)) {
  6671. selected = "";
  6672. if(rule.field === that.p.columns[i].name) {
  6673. selected = " selected='selected'";
  6674. j=i;
  6675. }
  6676. str += "<option value='"+that.p.columns[i].name+"'" +selected+">"+that.p.columns[i].label+"</option>";
  6677. }
  6678. }
  6679. ruleFieldSelect.append( str );
  6680. // create operator container
  6681. var ruleOperatorTd = $("<td class='operators'></td>");
  6682. tr.append(ruleOperatorTd);
  6683. cm = p.columns[j];
  6684. // create it here so it can be referentiated in the onchange event
  6685. //var RD = that.createElement(rule, rule.data);
  6686. cm.searchoptions.id = $.jgrid.randId();
  6687. if(isIE && cm.inputtype === "text") {
  6688. if(!cm.searchoptions.size) {
  6689. cm.searchoptions.size = 10;
  6690. }
  6691. }
  6692. var ruleDataInput = $.jgrid.createEl.call($t, cm.inputtype,cm.searchoptions, rule.data, true, that.p.ajaxSelectOptions, true);
  6693. if(rule.op === 'nu' || rule.op === 'nn') {
  6694. $(ruleDataInput).attr('readonly','true');
  6695. $(ruleDataInput).attr('disabled','true');
  6696. } //retain the state of disabled text fields in case of null ops
  6697. // dropdown for: choosing operator
  6698. var ruleOperatorSelect = $("<select class='selectopts'></select>");
  6699. ruleOperatorTd.append(ruleOperatorSelect);
  6700. ruleOperatorSelect.bind('change',function() {
  6701. rule.op = $(ruleOperatorSelect).val();
  6702. trpar = $(this).parents("tr:first");
  6703. var rd = $(".input-elm",trpar)[0];
  6704. if (rule.op === "nu" || rule.op === "nn") { // disable for operator "is null" and "is not null"
  6705. rule.data = "";
  6706. rd.value = "";
  6707. rd.setAttribute("readonly", "true");
  6708. rd.setAttribute("disabled", "true");
  6709. } else {
  6710. rd.removeAttribute("readonly");
  6711. rd.removeAttribute("disabled");
  6712. }
  6713. that.onchange(); // signals that the filter has changed
  6714. });
  6715. // populate drop down with all available operators
  6716. if( cm.searchoptions.sopt ) {op = cm.searchoptions.sopt;}
  6717. else if(that.p.sopt) { op= that.p.sopt; }
  6718. else if ($.inArray(cm.searchtype, that.p.strarr) !== -1) {op = that.p.stropts;}
  6719. else {op = that.p.numopts;}
  6720. str="";
  6721. $.each(that.p.ops, function() { aoprs.push(this.oper); });
  6722. for ( i = 0; i < op.length; i++) {
  6723. ina = $.inArray(op[i],aoprs);
  6724. if(ina !== -1) {
  6725. selected = rule.op === that.p.ops[ina].oper ? " selected='selected'" : "";
  6726. str += "<option value='"+that.p.ops[ina].oper+"'"+selected+">"+that.p.ops[ina].text+"</option>";
  6727. }
  6728. }
  6729. ruleOperatorSelect.append( str );
  6730. // create data container
  6731. var ruleDataTd = $("<td class='data'></td>");
  6732. tr.append(ruleDataTd);
  6733. // textbox for: data
  6734. // is created previously
  6735. //ruleDataInput.setAttribute("type", "text");
  6736. ruleDataTd.append(ruleDataInput);
  6737. $.jgrid.bindEv.call($t, ruleDataInput, cm.searchoptions);
  6738. $(ruleDataInput)
  6739. .addClass("input-elm")
  6740. .bind('change', function() {
  6741. rule.data = cm.inputtype === 'custom' ? cm.searchoptions.custom_value.call($t, $(this).children(".customelement:first"),'get') : $(this).val();
  6742. that.onchange(); // signals that the filter has changed
  6743. });
  6744. // create action container
  6745. var ruleDeleteTd = $("<td></td>");
  6746. tr.append(ruleDeleteTd);
  6747. // create button for: delete rule
  6748. if(this.p.ruleButtons === true) {
  6749. var ruleDeleteInput = $("<input type='button' value='-' title='Delete rule' class='delete-rule ui-del'/>");
  6750. ruleDeleteTd.append(ruleDeleteInput);
  6751. //$(ruleDeleteInput).html("").height(20).width(30).button({icons: { primary: "ui-icon-minus", text:false}});
  6752. ruleDeleteInput.bind('click',function() {
  6753. // remove rule from group
  6754. for (i = 0; i < group.rules.length; i++) {
  6755. if (group.rules[i] === rule) {
  6756. group.rules.splice(i, 1);
  6757. break;
  6758. }
  6759. }
  6760. that.reDraw(); // the html has changed, force reDraw
  6761. that.onchange(); // signals that the filter has changed
  6762. return false;
  6763. });
  6764. }
  6765. return tr;
  6766. };
  6767. this.getStringForGroup = function(group) {
  6768. var s = "(", index;
  6769. if (group.groups !== undefined) {
  6770. for (index = 0; index < group.groups.length; index++) {
  6771. if (s.length > 1) {
  6772. s += " " + group.groupOp + " ";
  6773. }
  6774. try {
  6775. s += this.getStringForGroup(group.groups[index]);
  6776. } catch (eg) {alert(eg);}
  6777. }
  6778. }
  6779. if (group.rules !== undefined) {
  6780. try{
  6781. for (index = 0; index < group.rules.length; index++) {
  6782. if (s.length > 1) {
  6783. s += " " + group.groupOp + " ";
  6784. }
  6785. s += this.getStringForRule(group.rules[index]);
  6786. }
  6787. } catch (e) {alert(e);}
  6788. }
  6789. s += ")";
  6790. if (s === "()") {
  6791. return ""; // ignore groups that don't have rules
  6792. }
  6793. return s;
  6794. };
  6795. this.getStringForRule = function(rule) {
  6796. var opUF = "",opC="", i, cm, ret, val,
  6797. numtypes = ['int', 'integer', 'float', 'number', 'currency']; // jqGrid
  6798. for (i = 0; i < this.p.ops.length; i++) {
  6799. if (this.p.ops[i].oper === rule.op) {
  6800. opUF = this.p.operands.hasOwnProperty(rule.op) ? this.p.operands[rule.op] : "";
  6801. opC = this.p.ops[i].oper;
  6802. break;
  6803. }
  6804. }
  6805. for (i=0; i<this.p.columns.length; i++) {
  6806. if(this.p.columns[i].name === rule.field) {
  6807. cm = this.p.columns[i];
  6808. break;
  6809. }
  6810. }
  6811. if (cm === undefined) { return ""; }
  6812. val = rule.data;
  6813. if(opC === 'bw' || opC === 'bn') { val = val+"%"; }
  6814. if(opC === 'ew' || opC === 'en') { val = "%"+val; }
  6815. if(opC === 'cn' || opC === 'nc') { val = "%"+val+"%"; }
  6816. if(opC === 'in' || opC === 'ni') { val = " ("+val+")"; }
  6817. if(p.errorcheck) { checkData(rule.data, cm); }
  6818. if($.inArray(cm.searchtype, numtypes) !== -1 || opC === 'nn' || opC === 'nu') { ret = rule.field + " " + opUF + " " + val; }
  6819. else { ret = rule.field + " " + opUF + " \"" + val + "\""; }
  6820. return ret;
  6821. };
  6822. this.resetFilter = function () {
  6823. this.p.filter = $.extend(true,{},this.p.initFilter);
  6824. this.reDraw();
  6825. this.onchange();
  6826. };
  6827. this.hideError = function() {
  6828. $("th.ui-state-error", this).html("");
  6829. $("tr.error", this).hide();
  6830. };
  6831. this.showError = function() {
  6832. $("th.ui-state-error", this).html(this.p.errmsg);
  6833. $("tr.error", this).show();
  6834. };
  6835. this.toUserFriendlyString = function() {
  6836. return this.getStringForGroup(p.filter);
  6837. };
  6838. this.toString = function() {
  6839. // this will obtain a string that can be used to match an item.
  6840. var that = this;
  6841. function getStringRule(rule) {
  6842. if(that.p.errorcheck) {
  6843. var i, cm;
  6844. for (i=0; i<that.p.columns.length; i++) {
  6845. if(that.p.columns[i].name === rule.field) {
  6846. cm = that.p.columns[i];
  6847. break;
  6848. }
  6849. }
  6850. if(cm) {checkData(rule.data, cm);}
  6851. }
  6852. return rule.op + "(item." + rule.field + ",'" + rule.data + "')";
  6853. }
  6854. function getStringForGroup(group) {
  6855. var s = "(", index;
  6856. if (group.groups !== undefined) {
  6857. for (index = 0; index < group.groups.length; index++) {
  6858. if (s.length > 1) {
  6859. if (group.groupOp === "OR") {
  6860. s += " || ";
  6861. }
  6862. else {
  6863. s += " && ";
  6864. }
  6865. }
  6866. s += getStringForGroup(group.groups[index]);
  6867. }
  6868. }
  6869. if (group.rules !== undefined) {
  6870. for (index = 0; index < group.rules.length; index++) {
  6871. if (s.length > 1) {
  6872. if (group.groupOp === "OR") {
  6873. s += " || ";
  6874. }
  6875. else {
  6876. s += " && ";
  6877. }
  6878. }
  6879. s += getStringRule(group.rules[index]);
  6880. }
  6881. }
  6882. s += ")";
  6883. if (s === "()") {
  6884. return ""; // ignore groups that don't have rules
  6885. }
  6886. return s;
  6887. }
  6888. return getStringForGroup(this.p.filter);
  6889. };
  6890. // Here we init the filter
  6891. this.reDraw();
  6892. if(this.p.showQuery) {
  6893. this.onchange();
  6894. }
  6895. // mark is as created so that it will not be created twice on this element
  6896. this.filter = true;
  6897. });
  6898. };
  6899. $.extend($.fn.jqFilter,{
  6900. /*
  6901. * Return SQL like string. Can be used directly
  6902. */
  6903. toSQLString : function()
  6904. {
  6905. var s ="";
  6906. this.each(function(){
  6907. s = this.toUserFriendlyString();
  6908. });
  6909. return s;
  6910. },
  6911. /*
  6912. * Return filter data as object.
  6913. */
  6914. filterData : function()
  6915. {
  6916. var s;
  6917. this.each(function(){
  6918. s = this.p.filter;
  6919. });
  6920. return s;
  6921. },
  6922. getParameter : function (param) {
  6923. if(param !== undefined) {
  6924. if (this.p.hasOwnProperty(param) ) {
  6925. return this.p[param];
  6926. }
  6927. }
  6928. return this.p;
  6929. },
  6930. resetFilter: function() {
  6931. return this.each(function(){
  6932. this.resetFilter();
  6933. });
  6934. },
  6935. addFilter: function (pfilter) {
  6936. if (typeof pfilter === "string") {
  6937. pfilter = $.jgrid.parse( pfilter );
  6938. }
  6939. this.each(function(){
  6940. this.p.filter = pfilter;
  6941. this.reDraw();
  6942. this.onchange();
  6943. });
  6944. }
  6945. });
  6946. })(jQuery);
  6947. /*jshint eqeqeq:false, eqnull:true, devel:true */
  6948. /*global xmlJsonClass, jQuery */
  6949. (function($){
  6950. /**
  6951. * jqGrid extension for form editing Grid Data
  6952. * Tony Tomov tony@trirand.com
  6953. * http://trirand.com/blog/
  6954. * Dual licensed under the MIT and GPL licenses:
  6955. * http://www.opensource.org/licenses/mit-license.php
  6956. * http://www.gnu.org/licenses/gpl-2.0.html
  6957. **/
  6958. "use strict";
  6959. var rp_ge = {};
  6960. $.jgrid.extend({
  6961. searchGrid : function (p) {
  6962. p = $.extend(true, {
  6963. recreateFilter: false,
  6964. drag: true,
  6965. sField:'searchField',
  6966. sValue:'searchString',
  6967. sOper: 'searchOper',
  6968. sFilter: 'filters',
  6969. loadDefaults: true, // this options activates loading of default filters from grid's postData for Multipe Search only.
  6970. beforeShowSearch: null,
  6971. afterShowSearch : null,
  6972. onInitializeSearch: null,
  6973. afterRedraw : null,
  6974. afterChange: null,
  6975. closeAfterSearch : false,
  6976. closeAfterReset: false,
  6977. closeOnEscape : false,
  6978. searchOnEnter : false,
  6979. multipleSearch : false,
  6980. multipleGroup : false,
  6981. //cloneSearchRowOnAdd: true,
  6982. top : 0,
  6983. left: 0,
  6984. jqModal : true,
  6985. modal: false,
  6986. resize : true,
  6987. width: 450,
  6988. height: 'auto',
  6989. dataheight: 'auto',
  6990. showQuery: false,
  6991. errorcheck : true,
  6992. sopt: null,
  6993. stringResult: undefined,
  6994. onClose : null,
  6995. onSearch : null,
  6996. onReset : null,
  6997. toTop : true,
  6998. overlay : 30,
  6999. columns : [],
  7000. tmplNames : null,
  7001. tmplFilters : null,
  7002. tmplLabel : ' Template: ',
  7003. showOnLoad: false,
  7004. layer: null,
  7005. 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"}
  7006. }, $.jgrid.search, p || {});
  7007. return this.each(function() {
  7008. var $t = this;
  7009. if(!$t.grid) {return;}
  7010. var fid = "fbox_"+$t.p.id,
  7011. showFrm = true,
  7012. IDs = {themodal:'searchmod'+fid,modalhead:'searchhd'+fid,modalcontent:'searchcnt'+fid, scrollelm : fid},
  7013. defaultFilters = $t.p.postData[p.sFilter];
  7014. if(typeof defaultFilters === "string") {
  7015. defaultFilters = $.jgrid.parse( defaultFilters );
  7016. }
  7017. if(p.recreateFilter === true) {
  7018. $("#"+$.jgrid.jqID(IDs.themodal)).remove();
  7019. }
  7020. function showFilter(_filter) {
  7021. showFrm = $($t).triggerHandler("jqGridFilterBeforeShow", [_filter]);
  7022. if(showFrm === undefined) {
  7023. showFrm = true;
  7024. }
  7025. if(showFrm && $.isFunction(p.beforeShowSearch)) {
  7026. showFrm = p.beforeShowSearch.call($t,_filter);
  7027. }
  7028. if(showFrm) {
  7029. $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{gbox:"#gbox_"+$.jgrid.jqID(fid),jqm:p.jqModal, modal:p.modal, overlay: p.overlay, toTop: p.toTop});
  7030. $($t).triggerHandler("jqGridFilterAfterShow", [_filter]);
  7031. if($.isFunction(p.afterShowSearch)) {
  7032. p.afterShowSearch.call($t, _filter);
  7033. }
  7034. }
  7035. }
  7036. if ( $("#"+$.jgrid.jqID(IDs.themodal))[0] !== undefined ) {
  7037. showFilter($("#fbox_"+$.jgrid.jqID(+$t.p.id)));
  7038. } else {
  7039. var fil = $("<div><div id='"+fid+"' class='searchFilter' style='overflow:auto'></div></div>").insertBefore("#gview_"+$.jgrid.jqID($t.p.id)),
  7040. align = "left", butleft ="";
  7041. if($t.p.direction === "rtl") {
  7042. align = "right";
  7043. butleft = " style='text-align:left'";
  7044. fil.attr("dir","rtl");
  7045. }
  7046. var columns = $.extend([],$t.p.colModel),
  7047. bS ="<a href='javascript:void(0)' id='"+fid+"_search' class='fm-button ui-state-default ui-corner-all fm-button-icon-right ui-reset'><span class='ui-icon ui-icon-search'></span>"+p.Find+"</a>",
  7048. bC ="<a href='javascript:void(0)' id='"+fid+"_reset' class='fm-button ui-state-default ui-corner-all fm-button-icon-left ui-search'><span class='ui-icon ui-icon-arrowreturnthick-1-w'></span>"+p.Reset+"</a>",
  7049. bQ = "", tmpl="", colnm, found = false, bt, cmi=-1;
  7050. if(p.showQuery) {
  7051. bQ ="<a href='javascript:void(0)' id='"+fid+"_query' class='fm-button ui-state-default ui-corner-all fm-button-icon-left'><span class='ui-icon ui-icon-comment'></span>Query</a>";
  7052. }
  7053. if(!p.columns.length) {
  7054. $.each(columns, function(i,n){
  7055. if(!n.label) {
  7056. n.label = $t.p.colNames[i];
  7057. }
  7058. // find first searchable column and set it if no default filter
  7059. if(!found) {
  7060. var searchable = (n.search === undefined) ? true: n.search ,
  7061. hidden = (n.hidden === true),
  7062. ignoreHiding = (n.searchoptions && n.searchoptions.searchhidden === true);
  7063. if ((ignoreHiding && searchable) || (searchable && !hidden)) {
  7064. found = true;
  7065. colnm = n.index || n.name;
  7066. cmi =i;
  7067. }
  7068. }
  7069. });
  7070. } else {
  7071. columns = p.columns;
  7072. cmi = 0;
  7073. colnm = columns[0].index || columns[0].name;
  7074. }
  7075. // old behaviour
  7076. if( (!defaultFilters && colnm) || p.multipleSearch === false ) {
  7077. var cmop = "eq";
  7078. if(cmi >=0 && columns[cmi].searchoptions && columns[cmi].searchoptions.sopt) {
  7079. cmop = columns[cmi].searchoptions.sopt[0];
  7080. } else if(p.sopt && p.sopt.length) {
  7081. cmop = p.sopt[0];
  7082. }
  7083. defaultFilters = {groupOp: "AND", rules: [{field: colnm, op: cmop, data: ""}]};
  7084. }
  7085. found = false;
  7086. if(p.tmplNames && p.tmplNames.length) {
  7087. found = true;
  7088. tmpl = p.tmplLabel;
  7089. tmpl += "<select class='ui-template'>";
  7090. tmpl += "<option value='default'>Default</option>";
  7091. $.each(p.tmplNames, function(i,n){
  7092. tmpl += "<option value='"+i+"'>"+n+"</option>";
  7093. });
  7094. tmpl += "</select>";
  7095. }
  7096. 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>";
  7097. fid = $.jgrid.jqID( fid);
  7098. $("#"+fid).jqFilter({
  7099. columns : columns,
  7100. filter: p.loadDefaults ? defaultFilters : null,
  7101. showQuery: p.showQuery,
  7102. errorcheck : p.errorcheck,
  7103. sopt: p.sopt,
  7104. groupButton : p.multipleGroup,
  7105. ruleButtons : p.multipleSearch,
  7106. afterRedraw : p.afterRedraw,
  7107. ops : p.odata,
  7108. operands : p.operands,
  7109. ajaxSelectOptions: $t.p.ajaxSelectOptions,
  7110. groupOps: p.groupOps,
  7111. onChange : function() {
  7112. if(this.p.showQuery) {
  7113. $('.query',this).html(this.toUserFriendlyString());
  7114. }
  7115. if ($.isFunction(p.afterChange)) {
  7116. p.afterChange.call($t, $("#"+fid), p);
  7117. }
  7118. },
  7119. direction : $t.p.direction,
  7120. id: $t.p.id
  7121. });
  7122. fil.append( bt );
  7123. if(found && p.tmplFilters && p.tmplFilters.length) {
  7124. $(".ui-template", fil).bind('change', function(){
  7125. var curtempl = $(this).val();
  7126. if(curtempl==="default") {
  7127. $("#"+fid).jqFilter('addFilter', defaultFilters);
  7128. } else {
  7129. $("#"+fid).jqFilter('addFilter', p.tmplFilters[parseInt(curtempl,10)]);
  7130. }
  7131. return false;
  7132. });
  7133. }
  7134. if(p.multipleGroup === true) {p.multipleSearch = true;}
  7135. $($t).triggerHandler("jqGridFilterInitialize", [$("#"+fid)]);
  7136. if($.isFunction(p.onInitializeSearch) ) {
  7137. p.onInitializeSearch.call($t, $("#"+fid));
  7138. }
  7139. p.gbox = "#gbox_"+fid;
  7140. if (p.layer) {
  7141. $.jgrid.createModal(IDs ,fil,p,"#gview_"+$.jgrid.jqID($t.p.id),$("#gbox_"+$.jgrid.jqID($t.p.id))[0], "#"+$.jgrid.jqID(p.layer), {position: "relative"});
  7142. } else {
  7143. $.jgrid.createModal(IDs ,fil,p,"#gview_"+$.jgrid.jqID($t.p.id),$("#gbox_"+$.jgrid.jqID($t.p.id))[0]);
  7144. }
  7145. if (p.searchOnEnter || p.closeOnEscape) {
  7146. $("#"+$.jgrid.jqID(IDs.themodal)).keydown(function (e) {
  7147. var $target = $(e.target);
  7148. if (p.searchOnEnter && e.which === 13 && // 13 === $.ui.keyCode.ENTER
  7149. !$target.hasClass('add-group') && !$target.hasClass('add-rule') &&
  7150. !$target.hasClass('delete-group') && !$target.hasClass('delete-rule') &&
  7151. (!$target.hasClass("fm-button") || !$target.is("[id$=_query]"))) {
  7152. $("#"+fid+"_search").focus().click();
  7153. return false;
  7154. }
  7155. if (p.closeOnEscape && e.which === 27) { // 27 === $.ui.keyCode.ESCAPE
  7156. $("#"+$.jgrid.jqID(IDs.modalhead)).find(".ui-jqdialog-titlebar-close").focus().click();
  7157. return false;
  7158. }
  7159. });
  7160. }
  7161. if(bQ) {
  7162. $("#"+fid+"_query").bind('click', function(){
  7163. $(".queryresult", fil).toggle();
  7164. return false;
  7165. });
  7166. }
  7167. if (p.stringResult===undefined) {
  7168. // to provide backward compatibility, inferring stringResult value from multipleSearch
  7169. p.stringResult = p.multipleSearch;
  7170. }
  7171. $("#"+fid+"_search").bind('click', function(){
  7172. var fl = $("#"+fid),
  7173. sdata={}, res,
  7174. filters = fl.jqFilter('filterData');
  7175. if(p.errorcheck) {
  7176. fl[0].hideError();
  7177. if(!p.showQuery) {fl.jqFilter('toSQLString');}
  7178. if(fl[0].p.error) {
  7179. fl[0].showError();
  7180. return false;
  7181. }
  7182. }
  7183. if(p.stringResult) {
  7184. try {
  7185. // xmlJsonClass or JSON.stringify
  7186. res = xmlJsonClass.toJson(filters, '', '', false);
  7187. } catch (e) {
  7188. try {
  7189. res = JSON.stringify(filters);
  7190. } catch (e2) { }
  7191. }
  7192. if(typeof res==="string") {
  7193. sdata[p.sFilter] = res;
  7194. $.each([p.sField,p.sValue, p.sOper], function() {sdata[this] = "";});
  7195. }
  7196. } else {
  7197. if(p.multipleSearch) {
  7198. sdata[p.sFilter] = filters;
  7199. $.each([p.sField,p.sValue, p.sOper], function() {sdata[this] = "";});
  7200. } else {
  7201. sdata[p.sField] = filters.rules[0].field;
  7202. sdata[p.sValue] = filters.rules[0].data;
  7203. sdata[p.sOper] = filters.rules[0].op;
  7204. sdata[p.sFilter] = "";
  7205. }
  7206. }
  7207. $t.p.search = true;
  7208. $.extend($t.p.postData,sdata);
  7209. $($t).triggerHandler("jqGridFilterSearch");
  7210. if($.isFunction(p.onSearch) ) {
  7211. p.onSearch.call($t);
  7212. }
  7213. $($t).trigger("reloadGrid",[{page:1}]);
  7214. if(p.closeAfterSearch) {
  7215. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:p.jqModal,onClose: p.onClose});
  7216. }
  7217. return false;
  7218. });
  7219. $("#"+fid+"_reset").bind('click', function(){
  7220. var sdata={},
  7221. fl = $("#"+fid);
  7222. $t.p.search = false;
  7223. if(p.multipleSearch===false) {
  7224. sdata[p.sField] = sdata[p.sValue] = sdata[p.sOper] = "";
  7225. } else {
  7226. sdata[p.sFilter] = "";
  7227. }
  7228. fl[0].resetFilter();
  7229. if(found) {
  7230. $(".ui-template", fil).val("default");
  7231. }
  7232. $.extend($t.p.postData,sdata);
  7233. $($t).triggerHandler("jqGridFilterReset");
  7234. if($.isFunction(p.onReset) ) {
  7235. p.onReset.call($t);
  7236. }
  7237. $($t).trigger("reloadGrid",[{page:1}]);
  7238. return false;
  7239. });
  7240. showFilter($("#"+fid));
  7241. $(".fm-button:not(.ui-state-disabled)",fil).hover(
  7242. function(){$(this).addClass('ui-state-hover');},
  7243. function(){$(this).removeClass('ui-state-hover');}
  7244. );
  7245. }
  7246. });
  7247. },
  7248. editGridRow : function(rowid, p){
  7249. p = $.extend(true, {
  7250. top : 0,
  7251. left: 0,
  7252. width: 300,
  7253. datawidth: 'auto',
  7254. height: 'auto',
  7255. dataheight: 'auto',
  7256. modal: false,
  7257. overlay : 30,
  7258. drag: true,
  7259. resize: true,
  7260. url: null,
  7261. mtype : "POST",
  7262. clearAfterAdd :true,
  7263. closeAfterEdit : false,
  7264. reloadAfterSubmit : true,
  7265. onInitializeForm: null,
  7266. beforeInitData: null,
  7267. beforeShowForm: null,
  7268. afterShowForm: null,
  7269. beforeSubmit: null,
  7270. afterSubmit: null,
  7271. onclickSubmit: null,
  7272. afterComplete: null,
  7273. onclickPgButtons : null,
  7274. afterclickPgButtons: null,
  7275. editData : {},
  7276. recreateForm : false,
  7277. jqModal : true,
  7278. closeOnEscape : false,
  7279. addedrow : "first",
  7280. topinfo : '',
  7281. bottominfo: '',
  7282. saveicon : [],
  7283. closeicon : [],
  7284. savekey: [false,13],
  7285. navkeys: [false,38,40],
  7286. checkOnSubmit : false,
  7287. checkOnUpdate : false,
  7288. _savedData : {},
  7289. processing : false,
  7290. onClose : null,
  7291. ajaxEditOptions : {},
  7292. serializeEditData : null,
  7293. viewPagerButtons : true,
  7294. overlayClass : 'ui-widget-overlay'
  7295. }, $.jgrid.edit, p || {});
  7296. rp_ge[$(this)[0].p.id] = p;
  7297. return this.each(function(){
  7298. var $t = this;
  7299. if (!$t.grid || !rowid) {return;}
  7300. var gID = $t.p.id,
  7301. frmgr = "FrmGrid_"+gID, frmtborg = "TblGrid_"+gID, frmtb = "#"+$.jgrid.jqID(frmtborg),
  7302. IDs = {themodal:'editmod'+gID,modalhead:'edithd'+gID,modalcontent:'editcnt'+gID, scrollelm : frmgr},
  7303. onBeforeShow = $.isFunction(rp_ge[$t.p.id].beforeShowForm) ? rp_ge[$t.p.id].beforeShowForm : false,
  7304. onAfterShow = $.isFunction(rp_ge[$t.p.id].afterShowForm) ? rp_ge[$t.p.id].afterShowForm : false,
  7305. onBeforeInit = $.isFunction(rp_ge[$t.p.id].beforeInitData) ? rp_ge[$t.p.id].beforeInitData : false,
  7306. onInitializeForm = $.isFunction(rp_ge[$t.p.id].onInitializeForm) ? rp_ge[$t.p.id].onInitializeForm : false,
  7307. showFrm = true,
  7308. maxCols = 1, maxRows=0, postdata, diff, frmoper;
  7309. frmgr = $.jgrid.jqID(frmgr);
  7310. if (rowid === "new") {
  7311. rowid = "_empty";
  7312. frmoper = "add";
  7313. p.caption=rp_ge[$t.p.id].addCaption;
  7314. } else {
  7315. p.caption=rp_ge[$t.p.id].editCaption;
  7316. frmoper = "edit";
  7317. }
  7318. if(p.recreateForm===true && $("#"+$.jgrid.jqID(IDs.themodal))[0] !== undefined) {
  7319. $("#"+$.jgrid.jqID(IDs.themodal)).remove();
  7320. }
  7321. var closeovrl = true;
  7322. if(p.checkOnUpdate && p.jqModal && !p.modal) {
  7323. closeovrl = false;
  7324. }
  7325. function getFormData(){
  7326. $(frmtb+" > tbody > tr > td > .FormElement").each(function() {
  7327. var celm = $(".customelement", this);
  7328. if (celm.length) {
  7329. var elem = celm[0], nm = $(elem).attr('name');
  7330. $.each($t.p.colModel, function(){
  7331. if(this.name === nm && this.editoptions && $.isFunction(this.editoptions.custom_value)) {
  7332. try {
  7333. postdata[nm] = this.editoptions.custom_value.call($t, $("#"+$.jgrid.jqID(nm),frmtb),'get');
  7334. if (postdata[nm] === undefined) {throw "e1";}
  7335. } catch (e) {
  7336. if (e==="e1") {$.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose);}
  7337. else {$.jgrid.info_dialog($.jgrid.errors.errcap,e.message,$.jgrid.edit.bClose);}
  7338. }
  7339. return true;
  7340. }
  7341. });
  7342. } else {
  7343. switch ($(this).get(0).type) {
  7344. case "checkbox":
  7345. if($(this).is(":checked")) {
  7346. postdata[this.name]= $(this).val();
  7347. }else {
  7348. var ofv = $(this).attr("offval");
  7349. postdata[this.name]= ofv;
  7350. }
  7351. break;
  7352. case "select-one":
  7353. postdata[this.name]= $("option:selected",this).val();
  7354. break;
  7355. case "select-multiple":
  7356. postdata[this.name]= $(this).val();
  7357. if(postdata[this.name]) {postdata[this.name] = postdata[this.name].join(",");}
  7358. else {postdata[this.name] ="";}
  7359. var selectedText = [];
  7360. $("option:selected",this).each(
  7361. function(i,selected){
  7362. selectedText[i] = $(selected).text();
  7363. }
  7364. );
  7365. break;
  7366. case "password":
  7367. case "text":
  7368. case "textarea":
  7369. case "button":
  7370. postdata[this.name] = $(this).val();
  7371. break;
  7372. }
  7373. if($t.p.autoencode) {postdata[this.name] = $.jgrid.htmlEncode(postdata[this.name]);}
  7374. }
  7375. });
  7376. return true;
  7377. }
  7378. function createData(rowid,obj,tb,maxcols){
  7379. var nm, hc,trdata, cnt=0,tmp, dc,elc, retpos=[], ind=false,
  7380. tdtmpl = "<td class='CaptionTD'>&#160;</td><td class='DataTD'>&#160;</td>", tmpl="", i; //*2
  7381. for (i =1; i<=maxcols;i++) {
  7382. tmpl += tdtmpl;
  7383. }
  7384. if(rowid !== '_empty') {
  7385. ind = $(obj).jqGrid("getInd",rowid);
  7386. }
  7387. $(obj.p.colModel).each( function(i) {
  7388. nm = this.name;
  7389. // hidden fields are included in the form
  7390. if(this.editrules && this.editrules.edithidden === true) {
  7391. hc = false;
  7392. } else {
  7393. hc = this.hidden === true ? true : false;
  7394. }
  7395. dc = hc ? "style='display:none'" : "";
  7396. if ( nm !== 'cb' && nm !== 'subgrid' && this.editable===true && nm !== 'rn') {
  7397. if(ind === false) {
  7398. tmp = "";
  7399. } else {
  7400. if(nm === obj.p.ExpandColumn && obj.p.treeGrid === true) {
  7401. tmp = $("td[role='gridcell']:eq("+i+")",obj.rows[ind]).text();
  7402. } else {
  7403. try {
  7404. tmp = $.unformat.call(obj, $("td[role='gridcell']:eq("+i+")",obj.rows[ind]),{rowId:rowid, colModel:this},i);
  7405. } catch (_) {
  7406. tmp = (this.edittype && this.edittype === "textarea") ? $("td[role='gridcell']:eq("+i+")",obj.rows[ind]).text() : $("td[role='gridcell']:eq("+i+")",obj.rows[ind]).html();
  7407. }
  7408. if(!tmp || tmp === "&nbsp;" || tmp === "&#160;" || (tmp.length===1 && tmp.charCodeAt(0)===160) ) {tmp='';}
  7409. }
  7410. }
  7411. var opt = $.extend({}, this.editoptions || {} ,{id:nm,name:nm}),
  7412. frmopt = $.extend({}, {elmprefix:'',elmsuffix:'',rowabove:false,rowcontent:''}, this.formoptions || {}),
  7413. rp = parseInt(frmopt.rowpos,10) || cnt+1,
  7414. cp = parseInt((parseInt(frmopt.colpos,10) || 1)*2,10);
  7415. if(rowid === "_empty" && opt.defaultValue ) {
  7416. tmp = $.isFunction(opt.defaultValue) ? opt.defaultValue.call($t) : opt.defaultValue;
  7417. }
  7418. if(!this.edittype) {this.edittype = "text";}
  7419. if($t.p.autoencode) {tmp = $.jgrid.htmlDecode(tmp);}
  7420. elc = $.jgrid.createEl.call($t,this.edittype,opt,tmp,false,$.extend({},$.jgrid.ajaxOptions,obj.p.ajaxSelectOptions || {}));
  7421. //if(tmp === "" && this.edittype == "checkbox") {tmp = $(elc).attr("offval");}
  7422. //if(tmp === "" && this.edittype == "select") {tmp = $("option:eq(0)",elc).text();}
  7423. if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {rp_ge[$t.p.id]._savedData[nm] = tmp;}
  7424. $(elc).addClass("FormElement");
  7425. if( $.inArray(this.edittype, ['text','textarea','password','select']) > -1) {
  7426. $(elc).addClass("ui-widget-content ui-corner-all");
  7427. }
  7428. trdata = $(tb).find("tr[rowpos="+rp+"]");
  7429. if(frmopt.rowabove) {
  7430. var newdata = $("<tr><td class='contentinfo' colspan='"+(maxcols*2)+"'>"+frmopt.rowcontent+"</td></tr>");
  7431. $(tb).append(newdata);
  7432. newdata[0].rp = rp;
  7433. }
  7434. if ( trdata.length===0 ) {
  7435. trdata = $("<tr "+dc+" rowpos='"+rp+"'></tr>").addClass("FormData").attr("id","tr_"+nm);
  7436. $(trdata).append(tmpl);
  7437. $(tb).append(trdata);
  7438. trdata[0].rp = rp;
  7439. }
  7440. $("td:eq("+(cp-2)+")",trdata[0]).html(frmopt.label === undefined ? obj.p.colNames[i]: frmopt.label);
  7441. $("td:eq("+(cp-1)+")",trdata[0]).append(frmopt.elmprefix).append(elc).append(frmopt.elmsuffix);
  7442. if($.isFunction(opt.custom_value) && rowid !== "_empty" ) {
  7443. opt.custom_value.call($t, $("#"+nm,"#"+frmgr),'set',tmp);
  7444. }
  7445. $.jgrid.bindEv.call($t, elc, opt);
  7446. retpos[cnt] = i;
  7447. cnt++;
  7448. }
  7449. });
  7450. if( cnt > 0) {
  7451. 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>");
  7452. idrow[0].rp = cnt+999;
  7453. $(tb).append(idrow);
  7454. if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {rp_ge[$t.p.id]._savedData[obj.p.id+"_id"] = rowid;}
  7455. }
  7456. return retpos;
  7457. }
  7458. function fillData(rowid,obj,fmid){
  7459. var nm,cnt=0,tmp, fld,opt,vl,vlc;
  7460. 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;}
  7461. var cm = obj.p.colModel;
  7462. if(rowid === '_empty') {
  7463. $(cm).each(function(){
  7464. nm = this.name;
  7465. opt = $.extend({}, this.editoptions || {} );
  7466. fld = $("#"+$.jgrid.jqID(nm),"#"+fmid);
  7467. if(fld && fld.length && fld[0] !== null) {
  7468. vl = "";
  7469. if(opt.defaultValue ) {
  7470. vl = $.isFunction(opt.defaultValue) ? opt.defaultValue.call($t) : opt.defaultValue;
  7471. if(fld[0].type==='checkbox') {
  7472. vlc = vl.toLowerCase();
  7473. if(vlc.search(/(false|f|0|no|n|off|undefined)/i)<0 && vlc!=="") {
  7474. fld[0].checked = true;
  7475. fld[0].defaultChecked = true;
  7476. fld[0].value = vl;
  7477. } else {
  7478. fld[0].checked = false;
  7479. fld[0].defaultChecked = false;
  7480. }
  7481. } else {fld.val(vl);}
  7482. } else {
  7483. if( fld[0].type==='checkbox' ) {
  7484. fld[0].checked = false;
  7485. fld[0].defaultChecked = false;
  7486. vl = $(fld).attr("offval");
  7487. } else if (fld[0].type && fld[0].type.substr(0,6)==='select') {
  7488. fld[0].selectedIndex = 0;
  7489. } else {
  7490. fld.val(vl);
  7491. }
  7492. }
  7493. if(rp_ge[$t.p.id].checkOnSubmit===true || rp_ge[$t.p.id].checkOnUpdate) {rp_ge[$t.p.id]._savedData[nm] = vl;}
  7494. }
  7495. });
  7496. $("#id_g","#"+fmid).val(rowid);
  7497. return;
  7498. }
  7499. var tre = $(obj).jqGrid("getInd",rowid,true);
  7500. if(!tre) {return;}
  7501. $('td[role="gridcell"]',tre).each( function(i) {
  7502. nm = cm[i].name;
  7503. // hidden fields are included in the form
  7504. if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn' && cm[i].editable===true) {
  7505. if(nm === obj.p.ExpandColumn && obj.p.treeGrid === true) {
  7506. tmp = $(this).text();
  7507. } else {
  7508. try {
  7509. tmp = $.unformat.call(obj, $(this),{rowId:rowid, colModel:cm[i]},i);
  7510. } catch (_) {
  7511. tmp = cm[i].edittype==="textarea" ? $(this).text() : $(this).html();
  7512. }
  7513. }
  7514. if($t.p.autoencode) {tmp = $.jgrid.htmlDecode(tmp);}
  7515. if(rp_ge[$t.p.id].checkOnSubmit===true || rp_ge[$t.p.id].checkOnUpdate) {rp_ge[$t.p.id]._savedData[nm] = tmp;}
  7516. nm = $.jgrid.jqID(nm);
  7517. switch (cm[i].edittype) {
  7518. case "password":
  7519. case "text":
  7520. case "button" :
  7521. case "image":
  7522. case "textarea":
  7523. if(tmp === "&nbsp;" || tmp === "&#160;" || (tmp.length===1 && tmp.charCodeAt(0)===160) ) {tmp='';}
  7524. $("#"+nm,"#"+fmid).val(tmp);
  7525. break;
  7526. case "select":
  7527. var opv = tmp.split(",");
  7528. opv = $.map(opv,function(n){return $.trim(n);});
  7529. $("#"+nm+" option","#"+fmid).each(function(){
  7530. if (!cm[i].editoptions.multiple && ($.trim(tmp) === $.trim($(this).text()) || opv[0] === $.trim($(this).text()) || opv[0] === $.trim($(this).val())) ){
  7531. this.selected= true;
  7532. } else if (cm[i].editoptions.multiple){
  7533. if( $.inArray($.trim($(this).text()), opv ) > -1 || $.inArray($.trim($(this).val()), opv ) > -1 ){
  7534. this.selected = true;
  7535. }else{
  7536. this.selected = false;
  7537. }
  7538. } else {
  7539. this.selected = false;
  7540. }
  7541. });
  7542. break;
  7543. case "checkbox":
  7544. tmp = String(tmp);
  7545. if(cm[i].editoptions && cm[i].editoptions.value) {
  7546. var cb = cm[i].editoptions.value.split(":");
  7547. if(cb[0] === tmp) {
  7548. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']({"checked":true, "defaultChecked" : true});
  7549. } else {
  7550. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']({"checked":false, "defaultChecked" : false});
  7551. }
  7552. } else {
  7553. tmp = tmp.toLowerCase();
  7554. if(tmp.search(/(false|f|0|no|n|off|undefined)/i)<0 && tmp!=="") {
  7555. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("checked",true);
  7556. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("defaultChecked",true); //ie
  7557. } else {
  7558. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("checked", false);
  7559. $("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("defaultChecked", false); //ie
  7560. }
  7561. }
  7562. break;
  7563. case 'custom' :
  7564. try {
  7565. if(cm[i].editoptions && $.isFunction(cm[i].editoptions.custom_value)) {
  7566. cm[i].editoptions.custom_value.call($t, $("#"+nm,"#"+fmid),'set',tmp);
  7567. } else {throw "e1";}
  7568. } catch (e) {
  7569. if (e==="e1") {$.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.nodefined,$.jgrid.edit.bClose);}
  7570. else {$.jgrid.info_dialog($.jgrid.errors.errcap,e.message,$.jgrid.edit.bClose);}
  7571. }
  7572. break;
  7573. }
  7574. cnt++;
  7575. }
  7576. });
  7577. if(cnt>0) {$("#id_g",frmtb).val(rowid);}
  7578. }
  7579. function setNulls() {
  7580. $.each($t.p.colModel, function(i,n){
  7581. if(n.editoptions && n.editoptions.NullIfEmpty === true) {
  7582. if(postdata.hasOwnProperty(n.name) && postdata[n.name] === "") {
  7583. postdata[n.name] = 'null';
  7584. }
  7585. }
  7586. });
  7587. }
  7588. function postIt() {
  7589. var copydata, ret=[true,"",""], onCS = {}, opers = $t.p.prmNames, idname, oper, key, selr, i;
  7590. var retvals = $($t).triggerHandler("jqGridAddEditBeforeCheckValues", [$("#"+frmgr), frmoper]);
  7591. if(retvals && typeof retvals === 'object') {postdata = retvals;}
  7592. if($.isFunction(rp_ge[$t.p.id].beforeCheckValues)) {
  7593. retvals = rp_ge[$t.p.id].beforeCheckValues.call($t, postdata,$("#"+frmgr),frmoper);
  7594. if(retvals && typeof retvals === 'object') {postdata = retvals;}
  7595. }
  7596. for( key in postdata ){
  7597. if(postdata.hasOwnProperty(key)) {
  7598. ret = $.jgrid.checkValues.call($t,postdata[key],key);
  7599. if(ret[0] === false) {break;}
  7600. }
  7601. }
  7602. setNulls();
  7603. if(ret[0]) {
  7604. onCS = $($t).triggerHandler("jqGridAddEditClickSubmit", [rp_ge[$t.p.id], postdata, frmoper]);
  7605. if( onCS === undefined && $.isFunction( rp_ge[$t.p.id].onclickSubmit)) {
  7606. onCS = rp_ge[$t.p.id].onclickSubmit.call($t, rp_ge[$t.p.id], postdata, frmoper) || {};
  7607. }
  7608. ret = $($t).triggerHandler("jqGridAddEditBeforeSubmit", [postdata, $("#"+frmgr), frmoper]);
  7609. if(ret === undefined) {
  7610. ret = [true,"",""];
  7611. }
  7612. if( ret[0] && $.isFunction(rp_ge[$t.p.id].beforeSubmit)) {
  7613. ret = rp_ge[$t.p.id].beforeSubmit.call($t,postdata,$("#"+frmgr), frmoper);
  7614. }
  7615. }
  7616. if(ret[0] && !rp_ge[$t.p.id].processing) {
  7617. rp_ge[$t.p.id].processing = true;
  7618. $("#sData", frmtb+"_2").addClass('ui-state-active');
  7619. oper = opers.oper;
  7620. idname = opers.id;
  7621. // we add to pos data array the action - the name is oper
  7622. postdata[oper] = ($.trim(postdata[$t.p.id+"_id"]) === "_empty") ? opers.addoper : opers.editoper;
  7623. if(postdata[oper] !== opers.addoper) {
  7624. postdata[idname] = postdata[$t.p.id+"_id"];
  7625. } else {
  7626. // check to see if we have allredy this field in the form and if yes lieve it
  7627. if( postdata[idname] === undefined ) {postdata[idname] = postdata[$t.p.id+"_id"];}
  7628. }
  7629. delete postdata[$t.p.id+"_id"];
  7630. postdata = $.extend(postdata,rp_ge[$t.p.id].editData,onCS);
  7631. if($t.p.treeGrid === true) {
  7632. if(postdata[oper] === opers.addoper) {
  7633. selr = $($t).jqGrid("getGridParam", 'selrow');
  7634. var tr_par_id = $t.p.treeGridModel === 'adjacency' ? $t.p.treeReader.parent_id_field : 'parent_id';
  7635. postdata[tr_par_id] = selr;
  7636. }
  7637. for(i in $t.p.treeReader){
  7638. if($t.p.treeReader.hasOwnProperty(i)) {
  7639. var itm = $t.p.treeReader[i];
  7640. if(postdata.hasOwnProperty(itm)) {
  7641. if(postdata[oper] === opers.addoper && i === 'parent_id_field') {continue;}
  7642. delete postdata[itm];
  7643. }
  7644. }
  7645. }
  7646. }
  7647. postdata[idname] = $.jgrid.stripPref($t.p.idPrefix, postdata[idname]);
  7648. var ajaxOptions = $.extend({
  7649. url: rp_ge[$t.p.id].url || $($t).jqGrid('getGridParam','editurl'),
  7650. type: rp_ge[$t.p.id].mtype,
  7651. data: $.isFunction(rp_ge[$t.p.id].serializeEditData) ? rp_ge[$t.p.id].serializeEditData.call($t,postdata) : postdata,
  7652. complete:function(data,status){
  7653. var key;
  7654. postdata[idname] = $t.p.idPrefix + postdata[idname];
  7655. if(data.status >= 300 && data.status !== 304) {
  7656. ret[0] = false;
  7657. ret[1] = $($t).triggerHandler("jqGridAddEditErrorTextFormat", [data, frmoper]);
  7658. if ($.isFunction(rp_ge[$t.p.id].errorTextFormat)) {
  7659. ret[1] = rp_ge[$t.p.id].errorTextFormat.call($t, data, frmoper);
  7660. } else {
  7661. ret[1] = status + " Status: '" + data.statusText + "'. Error code: " + data.status;
  7662. }
  7663. } else {
  7664. // data is posted successful
  7665. // execute aftersubmit with the returned data from server
  7666. ret = $($t).triggerHandler("jqGridAddEditAfterSubmit", [data, postdata, frmoper]);
  7667. if(ret === undefined) {
  7668. ret = [true,"",""];
  7669. }
  7670. if( ret[0] && $.isFunction(rp_ge[$t.p.id].afterSubmit) ) {
  7671. ret = rp_ge[$t.p.id].afterSubmit.call($t, data,postdata, frmoper);
  7672. }
  7673. }
  7674. if(ret[0] === false) {
  7675. $("#FormError>td",frmtb).html(ret[1]);
  7676. $("#FormError",frmtb).show();
  7677. } else {
  7678. if($t.p.autoencode) {
  7679. $.each(postdata,function(n,v){
  7680. postdata[n] = $.jgrid.htmlDecode(v);
  7681. });
  7682. }
  7683. //rp_ge[$t.p.id].reloadAfterSubmit = rp_ge[$t.p.id].reloadAfterSubmit && $t.p.datatype != "local";
  7684. // the action is add
  7685. if(postdata[oper] === opers.addoper ) {
  7686. //id processing
  7687. // user not set the id ret[2]
  7688. if(!ret[2]) {ret[2] = $.jgrid.randId();}
  7689. postdata[idname] = ret[2];
  7690. if(rp_ge[$t.p.id].reloadAfterSubmit) {
  7691. $($t).trigger("reloadGrid");
  7692. } else {
  7693. if($t.p.treeGrid === true){
  7694. $($t).jqGrid("addChildNode",ret[2],selr,postdata );
  7695. } else {
  7696. $($t).jqGrid("addRowData",ret[2],postdata,p.addedrow);
  7697. }
  7698. }
  7699. if(rp_ge[$t.p.id].closeAfterAdd) {
  7700. if($t.p.treeGrid !== true){
  7701. $($t).jqGrid("setSelection",ret[2]);
  7702. }
  7703. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose});
  7704. } else if (rp_ge[$t.p.id].clearAfterAdd) {
  7705. fillData("_empty",$t,frmgr);
  7706. }
  7707. } else {
  7708. // the action is update
  7709. if(rp_ge[$t.p.id].reloadAfterSubmit) {
  7710. $($t).trigger("reloadGrid");
  7711. if( !rp_ge[$t.p.id].closeAfterEdit ) {setTimeout(function(){$($t).jqGrid("setSelection",postdata[idname]);},1000);}
  7712. } else {
  7713. if($t.p.treeGrid === true) {
  7714. $($t).jqGrid("setTreeRow", postdata[idname],postdata);
  7715. } else {
  7716. $($t).jqGrid("setRowData", postdata[idname],postdata);
  7717. }
  7718. }
  7719. 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});}
  7720. }
  7721. if($.isFunction(rp_ge[$t.p.id].afterComplete)) {
  7722. copydata = data;
  7723. setTimeout(function(){
  7724. $($t).triggerHandler("jqGridAddEditAfterComplete", [copydata, postdata, $("#"+frmgr), frmoper]);
  7725. rp_ge[$t.p.id].afterComplete.call($t, copydata, postdata, $("#"+frmgr), frmoper);
  7726. copydata=null;
  7727. },500);
  7728. }
  7729. if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {
  7730. $("#"+frmgr).data("disabled",false);
  7731. if(rp_ge[$t.p.id]._savedData[$t.p.id+"_id"] !== "_empty"){
  7732. for(key in rp_ge[$t.p.id]._savedData) {
  7733. if(rp_ge[$t.p.id]._savedData.hasOwnProperty(key) && postdata[key]) {
  7734. rp_ge[$t.p.id]._savedData[key] = postdata[key];
  7735. }
  7736. }
  7737. }
  7738. }
  7739. }
  7740. rp_ge[$t.p.id].processing=false;
  7741. $("#sData", frmtb+"_2").removeClass('ui-state-active');
  7742. try{$(':input:visible',"#"+frmgr)[0].focus();} catch (e){}
  7743. }
  7744. }, $.jgrid.ajaxOptions, rp_ge[$t.p.id].ajaxEditOptions );
  7745. if (!ajaxOptions.url && !rp_ge[$t.p.id].useDataProxy) {
  7746. if ($.isFunction($t.p.dataProxy)) {
  7747. rp_ge[$t.p.id].useDataProxy = true;
  7748. } else {
  7749. ret[0]=false;ret[1] += " "+$.jgrid.errors.nourl;
  7750. }
  7751. }
  7752. if (ret[0]) {
  7753. if (rp_ge[$t.p.id].useDataProxy) {
  7754. var dpret = $t.p.dataProxy.call($t, ajaxOptions, "set_"+$t.p.id);
  7755. if(dpret === undefined) {
  7756. dpret = [true, ""];
  7757. }
  7758. if(dpret[0] === false ) {
  7759. ret[0] = false;
  7760. ret[1] = dpret[1] || "Error deleting the selected row!" ;
  7761. } else {
  7762. if(ajaxOptions.data.oper === opers.addoper && rp_ge[$t.p.id].closeAfterAdd ) {
  7763. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});
  7764. }
  7765. if(ajaxOptions.data.oper === opers.editoper && rp_ge[$t.p.id].closeAfterEdit ) {
  7766. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});
  7767. }
  7768. }
  7769. } else {
  7770. $.ajax(ajaxOptions);
  7771. }
  7772. }
  7773. }
  7774. if(ret[0] === false) {
  7775. $("#FormError>td",frmtb).html(ret[1]);
  7776. $("#FormError",frmtb).show();
  7777. // return;
  7778. }
  7779. }
  7780. function compareData(nObj, oObj ) {
  7781. var ret = false,key;
  7782. for (key in nObj) {
  7783. if(nObj.hasOwnProperty(key) && nObj[key] != oObj[key]) {
  7784. ret = true;
  7785. break;
  7786. }
  7787. }
  7788. return ret;
  7789. }
  7790. function checkUpdates () {
  7791. var stat = true;
  7792. $("#FormError",frmtb).hide();
  7793. if(rp_ge[$t.p.id].checkOnUpdate) {
  7794. postdata = {};
  7795. getFormData();
  7796. diff = compareData(postdata,rp_ge[$t.p.id]._savedData);
  7797. if(diff) {
  7798. $("#"+frmgr).data("disabled",true);
  7799. $(".confirm","#"+IDs.themodal).show();
  7800. stat = false;
  7801. }
  7802. }
  7803. return stat;
  7804. }
  7805. function restoreInline()
  7806. {
  7807. var i;
  7808. if (rowid !== "_empty" && $t.p.savedRow !== undefined && $t.p.savedRow.length > 0 && $.isFunction($.fn.jqGrid.restoreRow)) {
  7809. for (i=0;i<$t.p.savedRow.length;i++) {
  7810. if ($t.p.savedRow[i].id == rowid) {
  7811. $($t).jqGrid('restoreRow',rowid);
  7812. break;
  7813. }
  7814. }
  7815. }
  7816. }
  7817. function updateNav(cr, posarr){
  7818. var totr = posarr[1].length-1;
  7819. if (cr===0) {
  7820. $("#pData",frmtb+"_2").addClass('ui-state-disabled');
  7821. } else if( posarr[1][cr-1] !== undefined && $("#"+$.jgrid.jqID(posarr[1][cr-1])).hasClass('ui-state-disabled')) {
  7822. $("#pData",frmtb+"_2").addClass('ui-state-disabled');
  7823. } else {
  7824. $("#pData",frmtb+"_2").removeClass('ui-state-disabled');
  7825. }
  7826. if (cr===totr) {
  7827. $("#nData",frmtb+"_2").addClass('ui-state-disabled');
  7828. } else if( posarr[1][cr+1] !== undefined && $("#"+$.jgrid.jqID(posarr[1][cr+1])).hasClass('ui-state-disabled')) {
  7829. $("#nData",frmtb+"_2").addClass('ui-state-disabled');
  7830. } else {
  7831. $("#nData",frmtb+"_2").removeClass('ui-state-disabled');
  7832. }
  7833. }
  7834. function getCurrPos() {
  7835. var rowsInGrid = $($t).jqGrid("getDataIDs"),
  7836. selrow = $("#id_g",frmtb).val(),
  7837. pos = $.inArray(selrow,rowsInGrid);
  7838. return [pos,rowsInGrid];
  7839. }
  7840. if ( $("#"+$.jgrid.jqID(IDs.themodal))[0] !== undefined ) {
  7841. showFrm = $($t).triggerHandler("jqGridAddEditBeforeInitData", [$("#"+$.jgrid.jqID(frmgr)), frmoper]);
  7842. if(showFrm === undefined) {
  7843. showFrm = true;
  7844. }
  7845. if(showFrm && onBeforeInit) {
  7846. showFrm = onBeforeInit.call($t,$("#"+frmgr), frmoper);
  7847. }
  7848. if(showFrm === false) {return;}
  7849. restoreInline();
  7850. $(".ui-jqdialog-title","#"+$.jgrid.jqID(IDs.modalhead)).html(p.caption);
  7851. $("#FormError",frmtb).hide();
  7852. if(rp_ge[$t.p.id].topinfo) {
  7853. $(".topinfo",frmtb).html(rp_ge[$t.p.id].topinfo);
  7854. $(".tinfo",frmtb).show();
  7855. } else {
  7856. $(".tinfo",frmtb).hide();
  7857. }
  7858. if(rp_ge[$t.p.id].bottominfo) {
  7859. $(".bottominfo",frmtb+"_2").html(rp_ge[$t.p.id].bottominfo);
  7860. $(".binfo",frmtb+"_2").show();
  7861. } else {
  7862. $(".binfo",frmtb+"_2").hide();
  7863. }
  7864. // filldata
  7865. fillData(rowid,$t,frmgr);
  7866. ///
  7867. if(rowid==="_empty" || !rp_ge[$t.p.id].viewPagerButtons) {
  7868. $("#pData, #nData",frmtb+"_2").hide();
  7869. } else {
  7870. $("#pData, #nData",frmtb+"_2").show();
  7871. }
  7872. if(rp_ge[$t.p.id].processing===true) {
  7873. rp_ge[$t.p.id].processing=false;
  7874. $("#sData", frmtb+"_2").removeClass('ui-state-active');
  7875. }
  7876. if($("#"+frmgr).data("disabled")===true) {
  7877. $(".confirm","#"+$.jgrid.jqID(IDs.themodal)).hide();
  7878. $("#"+frmgr).data("disabled",false);
  7879. }
  7880. $($t).triggerHandler("jqGridAddEditBeforeShowForm", [$("#"+frmgr), frmoper]);
  7881. if(onBeforeShow) { onBeforeShow.call($t, $("#"+frmgr), frmoper); }
  7882. $("#"+$.jgrid.jqID(IDs.themodal)).data("onClose",rp_ge[$t.p.id].onClose);
  7883. $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{gbox:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, jqM: false, overlay: p.overlay, modal:p.modal, overlayClass : p.overlayClass});
  7884. if(!closeovrl) {
  7885. $("." + $.jgrid.jqID(p.overlayClass)).click(function(){
  7886. if(!checkUpdates()) {return false;}
  7887. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});
  7888. return false;
  7889. });
  7890. }
  7891. $($t).triggerHandler("jqGridAddEditAfterShowForm", [$("#"+frmgr), frmoper]);
  7892. if(onAfterShow) { onAfterShow.call($t, $("#"+frmgr), frmoper); }
  7893. } else {
  7894. var dh = isNaN(p.dataheight) ? p.dataheight : p.dataheight+"px",
  7895. dw = isNaN(p.datawidth) ? p.datawidth : p.datawidth+"px",
  7896. frm = $("<form name='FormPost' id='"+frmgr+"' class='FormGrid' onSubmit='return false;' style='width:"+dw+";overflow:auto;position:relative;height:"+dh+";'></form>").data("disabled",false),
  7897. tbl = $("<table id='"+frmtborg+"' class='EditTable' cellspacing='0' cellpadding='0' border='0'><tbody></tbody></table>");
  7898. showFrm = $($t).triggerHandler("jqGridAddEditBeforeInitData", [$("#"+frmgr), frmoper]);
  7899. if(showFrm === undefined) {
  7900. showFrm = true;
  7901. }
  7902. if(showFrm && onBeforeInit) {
  7903. showFrm = onBeforeInit.call($t,$("#"+frmgr,frmoper));
  7904. }
  7905. if(showFrm === false) {return;}
  7906. restoreInline();
  7907. $($t.p.colModel).each( function() {
  7908. var fmto = this.formoptions;
  7909. maxCols = Math.max(maxCols, fmto ? fmto.colpos || 0 : 0 );
  7910. maxRows = Math.max(maxRows, fmto ? fmto.rowpos || 0 : 0 );
  7911. });
  7912. $(frm).append(tbl);
  7913. var flr = $("<tr id='FormError' style='display:none'><td class='ui-state-error' colspan='"+(maxCols*2)+"'></td></tr>");
  7914. flr[0].rp = 0;
  7915. $(tbl).append(flr);
  7916. //topinfo
  7917. flr = $("<tr style='display:none' class='tinfo'><td class='topinfo' colspan='"+(maxCols*2)+"'>"+rp_ge[$t.p.id].topinfo+"</td></tr>");
  7918. flr[0].rp = 0;
  7919. $(tbl).append(flr);
  7920. // set the id.
  7921. // use carefull only to change here colproperties.
  7922. // create data
  7923. var rtlb = $t.p.direction === "rtl" ? true :false,
  7924. bp = rtlb ? "nData" : "pData",
  7925. bn = rtlb ? "pData" : "nData";
  7926. createData(rowid,$t,tbl,maxCols);
  7927. // buttons at footer
  7928. var bP = "<a href='javascript:void(0)' id='"+bp+"' class='fm-button ui-state-default ui-corner-left'><span class='ui-icon ui-icon-triangle-1-w'></span></a>",
  7929. bN = "<a href='javascript:void(0)' id='"+bn+"' class='fm-button ui-state-default ui-corner-right'><span class='ui-icon ui-icon-triangle-1-e'></span></a>",
  7930. bS ="<a href='javascript:void(0)' id='sData' class='fm-button ui-state-default ui-corner-all'>"+p.bSubmit+"</a>",
  7931. bC ="<a href='javascript:void(0)' id='cData' class='fm-button ui-state-default ui-corner-all'>"+p.bCancel+"</a>";
  7932. 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>";
  7933. bt += "<tr style='display:none' class='binfo'><td class='bottominfo' colspan='2'>"+rp_ge[$t.p.id].bottominfo+"</td></tr>";
  7934. bt += "</tbody></table>";
  7935. if(maxRows > 0) {
  7936. var sd=[];
  7937. $.each($(tbl)[0].rows,function(i,r){
  7938. sd[i] = r;
  7939. });
  7940. sd.sort(function(a,b){
  7941. if(a.rp > b.rp) {return 1;}
  7942. if(a.rp < b.rp) {return -1;}
  7943. return 0;
  7944. });
  7945. $.each(sd, function(index, row) {
  7946. $('tbody',tbl).append(row);
  7947. });
  7948. }
  7949. p.gbox = "#gbox_"+$.jgrid.jqID(gID);
  7950. var cle = false;
  7951. if(p.closeOnEscape===true){
  7952. p.closeOnEscape = false;
  7953. cle = true;
  7954. }
  7955. var tms = $("<div></div>").append(frm).append(bt);
  7956. $.jgrid.createModal(IDs,tms,p,"#gview_"+$.jgrid.jqID($t.p.id),$("#gbox_"+$.jgrid.jqID($t.p.id))[0]);
  7957. if(rtlb) {
  7958. $("#pData, #nData",frmtb+"_2").css("float","right");
  7959. $(".EditButton",frmtb+"_2").css("text-align","left");
  7960. }
  7961. if(rp_ge[$t.p.id].topinfo) {$(".tinfo",frmtb).show();}
  7962. if(rp_ge[$t.p.id].bottominfo) {$(".binfo",frmtb+"_2").show();}
  7963. tms = null;bt=null;
  7964. $("#"+$.jgrid.jqID(IDs.themodal)).keydown( function( e ) {
  7965. var wkey = e.target;
  7966. if ($("#"+frmgr).data("disabled")===true ) {return false;}//??
  7967. if(rp_ge[$t.p.id].savekey[0] === true && e.which === rp_ge[$t.p.id].savekey[1]) { // save
  7968. if(wkey.tagName !== "TEXTAREA") {
  7969. $("#sData", frmtb+"_2").trigger("click");
  7970. return false;
  7971. }
  7972. }
  7973. if(e.which === 27) {
  7974. if(!checkUpdates()) {return false;}
  7975. if(cle) {$.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:p.gbox,jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});}
  7976. return false;
  7977. }
  7978. if(rp_ge[$t.p.id].navkeys[0]===true) {
  7979. if($("#id_g",frmtb).val() === "_empty") {return true;}
  7980. if(e.which === rp_ge[$t.p.id].navkeys[1]){ //up
  7981. $("#pData", frmtb+"_2").trigger("click");
  7982. return false;
  7983. }
  7984. if(e.which === rp_ge[$t.p.id].navkeys[2]){ //down
  7985. $("#nData", frmtb+"_2").trigger("click");
  7986. return false;
  7987. }
  7988. }
  7989. });
  7990. if(p.checkOnUpdate) {
  7991. $("a.ui-jqdialog-titlebar-close span","#"+$.jgrid.jqID(IDs.themodal)).removeClass("jqmClose");
  7992. $("a.ui-jqdialog-titlebar-close","#"+$.jgrid.jqID(IDs.themodal)).unbind("click")
  7993. .click(function(){
  7994. if(!checkUpdates()) {return false;}
  7995. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose});
  7996. return false;
  7997. });
  7998. }
  7999. p.saveicon = $.extend([true,"left","ui-icon-disk"],p.saveicon);
  8000. p.closeicon = $.extend([true,"left","ui-icon-close"],p.closeicon);
  8001. // beforeinitdata after creation of the form
  8002. if(p.saveicon[0]===true) {
  8003. $("#sData",frmtb+"_2").addClass(p.saveicon[1] === "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  8004. .append("<span class='ui-icon "+p.saveicon[2]+"'></span>");
  8005. }
  8006. if(p.closeicon[0]===true) {
  8007. $("#cData",frmtb+"_2").addClass(p.closeicon[1] === "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  8008. .append("<span class='ui-icon "+p.closeicon[2]+"'></span>");
  8009. }
  8010. if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {
  8011. bS ="<a href='javascript:void(0)' id='sNew' class='fm-button ui-state-default ui-corner-all' style='z-index:1002'>"+p.bYes+"</a>";
  8012. bN ="<a href='javascript:void(0)' id='nNew' class='fm-button ui-state-default ui-corner-all' style='z-index:1002'>"+p.bNo+"</a>";
  8013. bC ="<a href='javascript:void(0)' id='cNew' class='fm-button ui-state-default ui-corner-all' style='z-index:1002'>"+p.bExit+"</a>";
  8014. var zI = p.zIndex || 999;zI ++;
  8015. $("<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);
  8016. $("#sNew","#"+$.jgrid.jqID(IDs.themodal)).click(function(){
  8017. postIt();
  8018. $("#"+frmgr).data("disabled",false);
  8019. $(".confirm","#"+$.jgrid.jqID(IDs.themodal)).hide();
  8020. return false;
  8021. });
  8022. $("#nNew","#"+$.jgrid.jqID(IDs.themodal)).click(function(){
  8023. $(".confirm","#"+$.jgrid.jqID(IDs.themodal)).hide();
  8024. $("#"+frmgr).data("disabled",false);
  8025. setTimeout(function(){$(":input:visible","#"+frmgr)[0].focus();},0);
  8026. return false;
  8027. });
  8028. $("#cNew","#"+$.jgrid.jqID(IDs.themodal)).click(function(){
  8029. $(".confirm","#"+$.jgrid.jqID(IDs.themodal)).hide();
  8030. $("#"+frmgr).data("disabled",false);
  8031. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose});
  8032. return false;
  8033. });
  8034. }
  8035. // here initform - only once
  8036. $($t).triggerHandler("jqGridAddEditInitializeForm", [$("#"+frmgr), frmoper]);
  8037. if(onInitializeForm) {onInitializeForm.call($t,$("#"+frmgr), frmoper);}
  8038. if(rowid==="_empty" || !rp_ge[$t.p.id].viewPagerButtons) {$("#pData,#nData",frmtb+"_2").hide();} else {$("#pData,#nData",frmtb+"_2").show();}
  8039. $($t).triggerHandler("jqGridAddEditBeforeShowForm", [$("#"+frmgr), frmoper]);
  8040. if(onBeforeShow) { onBeforeShow.call($t, $("#"+frmgr), frmoper);}
  8041. $("#"+$.jgrid.jqID(IDs.themodal)).data("onClose",rp_ge[$t.p.id].onClose);
  8042. $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{gbox:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, overlay: p.overlay,modal:p.modal, overlayClass: p.overlayClass});
  8043. if(!closeovrl) {
  8044. $("." + $.jgrid.jqID(p.overlayClass)).click(function(){
  8045. if(!checkUpdates()) {return false;}
  8046. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});
  8047. return false;
  8048. });
  8049. }
  8050. $($t).triggerHandler("jqGridAddEditAfterShowForm", [$("#"+frmgr), frmoper]);
  8051. if(onAfterShow) { onAfterShow.call($t, $("#"+frmgr), frmoper); }
  8052. $(".fm-button","#"+$.jgrid.jqID(IDs.themodal)).hover(
  8053. function(){$(this).addClass('ui-state-hover');},
  8054. function(){$(this).removeClass('ui-state-hover');}
  8055. );
  8056. $("#sData", frmtb+"_2").click(function(){
  8057. postdata = {};
  8058. $("#FormError",frmtb).hide();
  8059. // all depend on ret array
  8060. //ret[0] - succes
  8061. //ret[1] - msg if not succes
  8062. //ret[2] - the id that will be set if reload after submit false
  8063. getFormData();
  8064. if(postdata[$t.p.id+"_id"] === "_empty") {postIt();}
  8065. else if(p.checkOnSubmit===true ) {
  8066. diff = compareData(postdata,rp_ge[$t.p.id]._savedData);
  8067. if(diff) {
  8068. $("#"+frmgr).data("disabled",true);
  8069. $(".confirm","#"+$.jgrid.jqID(IDs.themodal)).show();
  8070. } else {
  8071. postIt();
  8072. }
  8073. } else {
  8074. postIt();
  8075. }
  8076. return false;
  8077. });
  8078. $("#cData", frmtb+"_2").click(function(){
  8079. if(!checkUpdates()) {return false;}
  8080. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,onClose: rp_ge[$t.p.id].onClose});
  8081. return false;
  8082. });
  8083. $("#nData", frmtb+"_2").click(function(){
  8084. if(!checkUpdates()) {return false;}
  8085. $("#FormError",frmtb).hide();
  8086. var npos = getCurrPos();
  8087. npos[0] = parseInt(npos[0],10);
  8088. if(npos[0] !== -1 && npos[1][npos[0]+1]) {
  8089. $($t).triggerHandler("jqGridAddEditClickPgButtons", ['next',$("#"+frmgr),npos[1][npos[0]]]);
  8090. var nposret;
  8091. if($.isFunction(p.onclickPgButtons)) {
  8092. nposret = p.onclickPgButtons.call($t, 'next',$("#"+frmgr),npos[1][npos[0]]);
  8093. if( nposret !== undefined && nposret === false ) {return false;}
  8094. }
  8095. if( $("#"+$.jgrid.jqID(npos[1][npos[0]+1])).hasClass('ui-state-disabled')) {return false;}
  8096. fillData(npos[1][npos[0]+1],$t,frmgr);
  8097. $($t).jqGrid("setSelection",npos[1][npos[0]+1]);
  8098. $($t).triggerHandler("jqGridAddEditAfterClickPgButtons", ['next',$("#"+frmgr),npos[1][npos[0]]]);
  8099. if($.isFunction(p.afterclickPgButtons)) {
  8100. p.afterclickPgButtons.call($t, 'next',$("#"+frmgr),npos[1][npos[0]+1]);
  8101. }
  8102. updateNav(npos[0]+1,npos);
  8103. }
  8104. return false;
  8105. });
  8106. $("#pData", frmtb+"_2").click(function(){
  8107. if(!checkUpdates()) {return false;}
  8108. $("#FormError",frmtb).hide();
  8109. var ppos = getCurrPos();
  8110. if(ppos[0] !== -1 && ppos[1][ppos[0]-1]) {
  8111. $($t).triggerHandler("jqGridAddEditClickPgButtons", ['prev',$("#"+frmgr),ppos[1][ppos[0]]]);
  8112. var pposret;
  8113. if($.isFunction(p.onclickPgButtons)) {
  8114. pposret = p.onclickPgButtons.call($t, 'prev',$("#"+frmgr),ppos[1][ppos[0]]);
  8115. if( pposret !== undefined && pposret === false ) {return false;}
  8116. }
  8117. if( $("#"+$.jgrid.jqID(ppos[1][ppos[0]-1])).hasClass('ui-state-disabled')) {return false;}
  8118. fillData(ppos[1][ppos[0]-1],$t,frmgr);
  8119. $($t).jqGrid("setSelection",ppos[1][ppos[0]-1]);
  8120. $($t).triggerHandler("jqGridAddEditAfterClickPgButtons", ['prev',$("#"+frmgr),ppos[1][ppos[0]]]);
  8121. if($.isFunction(p.afterclickPgButtons)) {
  8122. p.afterclickPgButtons.call($t, 'prev',$("#"+frmgr),ppos[1][ppos[0]-1]);
  8123. }
  8124. updateNav(ppos[0]-1,ppos);
  8125. }
  8126. return false;
  8127. });
  8128. }
  8129. var posInit =getCurrPos();
  8130. updateNav(posInit[0],posInit);
  8131. });
  8132. },
  8133. viewGridRow : function(rowid, p){
  8134. p = $.extend(true, {
  8135. top : 0,
  8136. left: 0,
  8137. width: 0,
  8138. datawidth: 'auto',
  8139. height: 'auto',
  8140. dataheight: 'auto',
  8141. modal: false,
  8142. overlay: 30,
  8143. drag: true,
  8144. resize: true,
  8145. jqModal: true,
  8146. closeOnEscape : false,
  8147. labelswidth: '30%',
  8148. closeicon: [],
  8149. navkeys: [false,38,40],
  8150. onClose: null,
  8151. beforeShowForm : null,
  8152. beforeInitData : null,
  8153. viewPagerButtons : true,
  8154. recreateForm : false
  8155. }, $.jgrid.view, p || {});
  8156. rp_ge[$(this)[0].p.id] = p;
  8157. return this.each(function(){
  8158. var $t = this;
  8159. if (!$t.grid || !rowid) {return;}
  8160. var gID = $t.p.id,
  8161. frmgr = "ViewGrid_"+$.jgrid.jqID( gID ), frmtb = "ViewTbl_" + $.jgrid.jqID( gID ),
  8162. frmgr_id = "ViewGrid_"+gID, frmtb_id = "ViewTbl_"+gID,
  8163. IDs = {themodal:'viewmod'+gID,modalhead:'viewhd'+gID,modalcontent:'viewcnt'+gID, scrollelm : frmgr},
  8164. onBeforeInit = $.isFunction(rp_ge[$t.p.id].beforeInitData) ? rp_ge[$t.p.id].beforeInitData : false,
  8165. showFrm = true,
  8166. maxCols = 1, maxRows=0;
  8167. if(p.recreateForm===true && $("#"+$.jgrid.jqID(IDs.themodal))[0] !== undefined) {
  8168. $("#"+$.jgrid.jqID(IDs.themodal)).remove();
  8169. }
  8170. function focusaref(){ //Sfari 3 issues
  8171. if(rp_ge[$t.p.id].closeOnEscape===true || rp_ge[$t.p.id].navkeys[0]===true) {
  8172. setTimeout(function(){$(".ui-jqdialog-titlebar-close","#"+$.jgrid.jqID(IDs.modalhead)).focus();},0);
  8173. }
  8174. }
  8175. function createData(rowid,obj,tb,maxcols){
  8176. var nm, hc,trdata, cnt=0,tmp, dc, retpos=[], ind=false, i,
  8177. 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="",
  8178. tdtmpl2 = "<td class='CaptionTD form-view-label ui-widget-content'>&#160;</td><td class='DataTD form-view-data ui-widget-content'>&#160;</td>",
  8179. fmtnum = ['integer','number','currency'],max1 =0, max2=0 ,maxw,setme, viewfld;
  8180. for (i=1;i<=maxcols;i++) {
  8181. tmpl += i === 1 ? tdtmpl : tdtmpl2;
  8182. }
  8183. // find max number align rigth with property formatter
  8184. $(obj.p.colModel).each( function() {
  8185. if(this.editrules && this.editrules.edithidden === true) {
  8186. hc = false;
  8187. } else {
  8188. hc = this.hidden === true ? true : false;
  8189. }
  8190. if(!hc && this.align==='right') {
  8191. if(this.formatter && $.inArray(this.formatter,fmtnum) !== -1 ) {
  8192. max1 = Math.max(max1,parseInt(this.width,10));
  8193. } else {
  8194. max2 = Math.max(max2,parseInt(this.width,10));
  8195. }
  8196. }
  8197. });
  8198. maxw = max1 !==0 ? max1 : max2 !==0 ? max2 : 0;
  8199. ind = $(obj).jqGrid("getInd",rowid);
  8200. $(obj.p.colModel).each( function(i) {
  8201. nm = this.name;
  8202. setme = false;
  8203. // hidden fields are included in the form
  8204. if(this.editrules && this.editrules.edithidden === true) {
  8205. hc = false;
  8206. } else {
  8207. hc = this.hidden === true ? true : false;
  8208. }
  8209. dc = hc ? "style='display:none'" : "";
  8210. viewfld = (typeof this.viewable !== 'boolean') ? true : this.viewable;
  8211. if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn' && viewfld) {
  8212. if(ind === false) {
  8213. tmp = "";
  8214. } else {
  8215. if(nm === obj.p.ExpandColumn && obj.p.treeGrid === true) {
  8216. tmp = $("td:eq("+i+")",obj.rows[ind]).text();
  8217. } else {
  8218. tmp = $("td:eq("+i+")",obj.rows[ind]).html();
  8219. }
  8220. }
  8221. setme = this.align === 'right' && maxw !==0 ? true : false;
  8222. var frmopt = $.extend({},{rowabove:false,rowcontent:''}, this.formoptions || {}),
  8223. rp = parseInt(frmopt.rowpos,10) || cnt+1,
  8224. cp = parseInt((parseInt(frmopt.colpos,10) || 1)*2,10);
  8225. if(frmopt.rowabove) {
  8226. var newdata = $("<tr><td class='contentinfo' colspan='"+(maxcols*2)+"'>"+frmopt.rowcontent+"</td></tr>");
  8227. $(tb).append(newdata);
  8228. newdata[0].rp = rp;
  8229. }
  8230. trdata = $(tb).find("tr[rowpos="+rp+"]");
  8231. if ( trdata.length===0 ) {
  8232. trdata = $("<tr "+dc+" rowpos='"+rp+"'></tr>").addClass("FormData").attr("id","trv_"+nm);
  8233. $(trdata).append(tmpl);
  8234. $(tb).append(trdata);
  8235. trdata[0].rp = rp;
  8236. }
  8237. $("td:eq("+(cp-2)+")",trdata[0]).html('<b>'+ (frmopt.label === undefined ? obj.p.colNames[i]: frmopt.label)+'</b>');
  8238. $("td:eq("+(cp-1)+")",trdata[0]).append("<span>"+tmp+"</span>").attr("id","v_"+nm);
  8239. if(setme){
  8240. $("td:eq("+(cp-1)+") span",trdata[0]).css({'text-align':'right',width:maxw+"px"});
  8241. }
  8242. retpos[cnt] = i;
  8243. cnt++;
  8244. }
  8245. });
  8246. if( cnt > 0) {
  8247. 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>");
  8248. idrow[0].rp = cnt+99;
  8249. $(tb).append(idrow);
  8250. }
  8251. return retpos;
  8252. }
  8253. function fillData(rowid,obj){
  8254. var nm, hc,cnt=0,tmp,trv;
  8255. trv = $(obj).jqGrid("getInd",rowid,true);
  8256. if(!trv) {return;}
  8257. $('td',trv).each( function(i) {
  8258. nm = obj.p.colModel[i].name;
  8259. // hidden fields are included in the form
  8260. if(obj.p.colModel[i].editrules && obj.p.colModel[i].editrules.edithidden === true) {
  8261. hc = false;
  8262. } else {
  8263. hc = obj.p.colModel[i].hidden === true ? true : false;
  8264. }
  8265. if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn') {
  8266. if(nm === obj.p.ExpandColumn && obj.p.treeGrid === true) {
  8267. tmp = $(this).text();
  8268. } else {
  8269. tmp = $(this).html();
  8270. }
  8271. nm = $.jgrid.jqID("v_"+nm);
  8272. $("#"+nm+" span","#"+frmtb).html(tmp);
  8273. if (hc) {$("#"+nm,"#"+frmtb).parents("tr:first").hide();}
  8274. cnt++;
  8275. }
  8276. });
  8277. if(cnt>0) {$("#id_g","#"+frmtb).val(rowid);}
  8278. }
  8279. function updateNav(cr,posarr){
  8280. var totr = posarr[1].length-1;
  8281. if (cr===0) {
  8282. $("#pData","#"+frmtb+"_2").addClass('ui-state-disabled');
  8283. } else if( posarr[1][cr-1] !== undefined && $("#"+$.jgrid.jqID(posarr[1][cr-1])).hasClass('ui-state-disabled')) {
  8284. $("#pData",frmtb+"_2").addClass('ui-state-disabled');
  8285. } else {
  8286. $("#pData","#"+frmtb+"_2").removeClass('ui-state-disabled');
  8287. }
  8288. if (cr===totr) {
  8289. $("#nData","#"+frmtb+"_2").addClass('ui-state-disabled');
  8290. } else if( posarr[1][cr+1] !== undefined && $("#"+$.jgrid.jqID(posarr[1][cr+1])).hasClass('ui-state-disabled')) {
  8291. $("#nData",frmtb+"_2").addClass('ui-state-disabled');
  8292. } else {
  8293. $("#nData","#"+frmtb+"_2").removeClass('ui-state-disabled');
  8294. }
  8295. }
  8296. function getCurrPos() {
  8297. var rowsInGrid = $($t).jqGrid("getDataIDs"),
  8298. selrow = $("#id_g","#"+frmtb).val(),
  8299. pos = $.inArray(selrow,rowsInGrid);
  8300. return [pos,rowsInGrid];
  8301. }
  8302. if ( $("#"+$.jgrid.jqID(IDs.themodal))[0] !== undefined ) {
  8303. if(onBeforeInit) {
  8304. showFrm = onBeforeInit.call($t,$("#"+frmgr));
  8305. if(showFrm === undefined) {
  8306. showFrm = true;
  8307. }
  8308. }
  8309. if(showFrm === false) {return;}
  8310. $(".ui-jqdialog-title","#"+$.jgrid.jqID(IDs.modalhead)).html(p.caption);
  8311. $("#FormError","#"+frmtb).hide();
  8312. fillData(rowid,$t);
  8313. if($.isFunction(rp_ge[$t.p.id].beforeShowForm)) {rp_ge[$t.p.id].beforeShowForm.call($t,$("#"+frmgr));}
  8314. $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{gbox:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, jqM: false, overlay: p.overlay, modal:p.modal});
  8315. focusaref();
  8316. } else {
  8317. var dh = isNaN(p.dataheight) ? p.dataheight : p.dataheight+"px",
  8318. dw = isNaN(p.datawidth) ? p.datawidth : p.datawidth+"px",
  8319. frm = $("<form name='FormPost' id='"+frmgr_id+"' class='FormGrid' style='width:"+dw+";overflow:auto;position:relative;height:"+dh+";'></form>"),
  8320. tbl =$("<table id='"+frmtb_id+"' class='EditTable' cellspacing='1' cellpadding='2' border='0' style='table-layout:fixed'><tbody></tbody></table>");
  8321. if(onBeforeInit) {
  8322. showFrm = onBeforeInit.call($t,$("#"+frmgr));
  8323. if(showFrm === undefined) {
  8324. showFrm = true;
  8325. }
  8326. }
  8327. if(showFrm === false) {return;}
  8328. $($t.p.colModel).each( function() {
  8329. var fmto = this.formoptions;
  8330. maxCols = Math.max(maxCols, fmto ? fmto.colpos || 0 : 0 );
  8331. maxRows = Math.max(maxRows, fmto ? fmto.rowpos || 0 : 0 );
  8332. });
  8333. // set the id.
  8334. $(frm).append(tbl);
  8335. createData(rowid, $t, tbl, maxCols);
  8336. var rtlb = $t.p.direction === "rtl" ? true :false,
  8337. bp = rtlb ? "nData" : "pData",
  8338. bn = rtlb ? "pData" : "nData",
  8339. // buttons at footer
  8340. bP = "<a href='javascript:void(0)' id='"+bp+"' class='fm-button ui-state-default ui-corner-left'><span class='ui-icon ui-icon-triangle-1-w'></span></a>",
  8341. bN = "<a href='javascript:void(0)' id='"+bn+"' class='fm-button ui-state-default ui-corner-right'><span class='ui-icon ui-icon-triangle-1-e'></span></a>",
  8342. bC ="<a href='javascript:void(0)' id='cData' class='fm-button ui-state-default ui-corner-all'>"+p.bClose+"</a>";
  8343. if(maxRows > 0) {
  8344. var sd=[];
  8345. $.each($(tbl)[0].rows,function(i,r){
  8346. sd[i] = r;
  8347. });
  8348. sd.sort(function(a,b){
  8349. if(a.rp > b.rp) {return 1;}
  8350. if(a.rp < b.rp) {return -1;}
  8351. return 0;
  8352. });
  8353. $.each(sd, function(index, row) {
  8354. $('tbody',tbl).append(row);
  8355. });
  8356. }
  8357. p.gbox = "#gbox_"+$.jgrid.jqID(gID);
  8358. 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>");
  8359. $.jgrid.createModal(IDs,bt,p,"#gview_"+$.jgrid.jqID($t.p.id),$("#gview_"+$.jgrid.jqID($t.p.id))[0]);
  8360. if(rtlb) {
  8361. $("#pData, #nData","#"+frmtb+"_2").css("float","right");
  8362. $(".EditButton","#"+frmtb+"_2").css("text-align","left");
  8363. }
  8364. if(!p.viewPagerButtons) {$("#pData, #nData","#"+frmtb+"_2").hide();}
  8365. bt = null;
  8366. $("#"+IDs.themodal).keydown( function( e ) {
  8367. if(e.which === 27) {
  8368. if(rp_ge[$t.p.id].closeOnEscape) {$.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:p.gbox,jqm:p.jqModal, onClose: p.onClose});}
  8369. return false;
  8370. }
  8371. if(p.navkeys[0]===true) {
  8372. if(e.which === p.navkeys[1]){ //up
  8373. $("#pData", "#"+frmtb+"_2").trigger("click");
  8374. return false;
  8375. }
  8376. if(e.which === p.navkeys[2]){ //down
  8377. $("#nData", "#"+frmtb+"_2").trigger("click");
  8378. return false;
  8379. }
  8380. }
  8381. });
  8382. p.closeicon = $.extend([true,"left","ui-icon-close"],p.closeicon);
  8383. if(p.closeicon[0]===true) {
  8384. $("#cData","#"+frmtb+"_2").addClass(p.closeicon[1] === "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  8385. .append("<span class='ui-icon "+p.closeicon[2]+"'></span>");
  8386. }
  8387. if($.isFunction(p.beforeShowForm)) {p.beforeShowForm.call($t,$("#"+frmgr));}
  8388. $.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{gbox:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal,overlay: p.overlay, modal:p.modal});
  8389. $(".fm-button:not(.ui-state-disabled)","#"+frmtb+"_2").hover(
  8390. function(){$(this).addClass('ui-state-hover');},
  8391. function(){$(this).removeClass('ui-state-hover');}
  8392. );
  8393. focusaref();
  8394. $("#cData", "#"+frmtb+"_2").click(function(){
  8395. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: p.onClose});
  8396. return false;
  8397. });
  8398. $("#nData", "#"+frmtb+"_2").click(function(){
  8399. $("#FormError","#"+frmtb).hide();
  8400. var npos = getCurrPos();
  8401. npos[0] = parseInt(npos[0],10);
  8402. if(npos[0] !== -1 && npos[1][npos[0]+1]) {
  8403. if($.isFunction(p.onclickPgButtons)) {
  8404. p.onclickPgButtons.call($t,'next',$("#"+frmgr),npos[1][npos[0]]);
  8405. }
  8406. fillData(npos[1][npos[0]+1],$t);
  8407. $($t).jqGrid("setSelection",npos[1][npos[0]+1]);
  8408. if($.isFunction(p.afterclickPgButtons)) {
  8409. p.afterclickPgButtons.call($t,'next',$("#"+frmgr),npos[1][npos[0]+1]);
  8410. }
  8411. updateNav(npos[0]+1,npos);
  8412. }
  8413. focusaref();
  8414. return false;
  8415. });
  8416. $("#pData", "#"+frmtb+"_2").click(function(){
  8417. $("#FormError","#"+frmtb).hide();
  8418. var ppos = getCurrPos();
  8419. if(ppos[0] !== -1 && ppos[1][ppos[0]-1]) {
  8420. if($.isFunction(p.onclickPgButtons)) {
  8421. p.onclickPgButtons.call($t,'prev',$("#"+frmgr),ppos[1][ppos[0]]);
  8422. }
  8423. fillData(ppos[1][ppos[0]-1],$t);
  8424. $($t).jqGrid("setSelection",ppos[1][ppos[0]-1]);
  8425. if($.isFunction(p.afterclickPgButtons)) {
  8426. p.afterclickPgButtons.call($t,'prev',$("#"+frmgr),ppos[1][ppos[0]-1]);
  8427. }
  8428. updateNav(ppos[0]-1,ppos);
  8429. }
  8430. focusaref();
  8431. return false;
  8432. });
  8433. }
  8434. var posInit =getCurrPos();
  8435. updateNav(posInit[0],posInit);
  8436. });
  8437. },
  8438. delGridRow : function(rowids,p) {
  8439. p = $.extend(true, {
  8440. top : 0,
  8441. left: 0,
  8442. width: 240,
  8443. height: 'auto',
  8444. dataheight : 'auto',
  8445. modal: false,
  8446. overlay: 30,
  8447. drag: true,
  8448. resize: true,
  8449. url : '',
  8450. mtype : "POST",
  8451. reloadAfterSubmit: true,
  8452. beforeShowForm: null,
  8453. beforeInitData : null,
  8454. afterShowForm: null,
  8455. beforeSubmit: null,
  8456. onclickSubmit: null,
  8457. afterSubmit: null,
  8458. jqModal : true,
  8459. closeOnEscape : false,
  8460. delData: {},
  8461. delicon : [],
  8462. cancelicon : [],
  8463. onClose : null,
  8464. ajaxDelOptions : {},
  8465. processing : false,
  8466. serializeDelData : null,
  8467. useDataProxy : false
  8468. }, $.jgrid.del, p ||{});
  8469. rp_ge[$(this)[0].p.id] = p;
  8470. return this.each(function(){
  8471. var $t = this;
  8472. if (!$t.grid ) {return;}
  8473. if(!rowids) {return;}
  8474. var onBeforeShow = $.isFunction( rp_ge[$t.p.id].beforeShowForm ),
  8475. onAfterShow = $.isFunction( rp_ge[$t.p.id].afterShowForm ),
  8476. onBeforeInit = $.isFunction(rp_ge[$t.p.id].beforeInitData) ? rp_ge[$t.p.id].beforeInitData : false,
  8477. gID = $t.p.id, onCS = {},
  8478. showFrm = true,
  8479. dtbl = "DelTbl_"+$.jgrid.jqID(gID),postd, idname, opers, oper,
  8480. dtbl_id = "DelTbl_" + gID,
  8481. IDs = {themodal:'delmod'+gID,modalhead:'delhd'+gID,modalcontent:'delcnt'+gID, scrollelm: dtbl};
  8482. if ($.isArray(rowids)) {rowids = rowids.join();}
  8483. if ( $("#"+$.jgrid.jqID(IDs.themodal))[0] !== undefined ) {
  8484. if(onBeforeInit) {
  8485. showFrm = onBeforeInit.call($t,$("#"+dtbl));
  8486. if(showFrm === undefined) {
  8487. showFrm = true;
  8488. }
  8489. }
  8490. if(showFrm === false) {return;}
  8491. $("#DelData>td","#"+dtbl).text(rowids);
  8492. $("#DelError","#"+dtbl).hide();
  8493. if( rp_ge[$t.p.id].processing === true) {
  8494. rp_ge[$t.p.id].processing=false;
  8495. $("#dData", "#"+dtbl).removeClass('ui-state-active');
  8496. }
  8497. if(onBeforeShow) {rp_ge[$t.p.id].beforeShowForm.call($t,$("#"+dtbl));}
  8498. $.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});
  8499. if(onAfterShow) {rp_ge[$t.p.id].afterShowForm.call($t,$("#"+dtbl));}
  8500. } else {
  8501. var dh = isNaN(rp_ge[$t.p.id].dataheight) ? rp_ge[$t.p.id].dataheight : rp_ge[$t.p.id].dataheight+"px",
  8502. dw = isNaN(p.datawidth) ? p.datawidth : p.datawidth+"px",
  8503. tbl = "<div id='"+dtbl_id+"' class='formdata' style='width:"+dw+";overflow:auto;position:relative;height:"+dh+";'>";
  8504. tbl += "<table class='DelTable'><tbody>";
  8505. // error data
  8506. tbl += "<tr id='DelError' style='display:none'><td class='ui-state-error'></td></tr>";
  8507. tbl += "<tr id='DelData' style='display:none'><td >"+rowids+"</td></tr>";
  8508. tbl += "<tr><td class=\"delmsg\" style=\"white-space:pre;\">"+rp_ge[$t.p.id].msg+"</td></tr><tr><td >&#160;</td></tr>";
  8509. // buttons at footer
  8510. tbl += "</tbody></table></div>";
  8511. var bS = "<a href='javascript:void(0)' id='dData' class='fm-button ui-state-default ui-corner-all'>"+p.bSubmit+"</a>",
  8512. bC = "<a href='javascript:void(0)' id='eData' class='fm-button ui-state-default ui-corner-all'>"+p.bCancel+"</a>";
  8513. 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>";
  8514. p.gbox = "#gbox_"+$.jgrid.jqID(gID);
  8515. $.jgrid.createModal(IDs,tbl,p,"#gview_"+$.jgrid.jqID($t.p.id),$("#gview_"+$.jgrid.jqID($t.p.id))[0]);
  8516. if(onBeforeInit) {
  8517. showFrm = onBeforeInit.call($t,$("#"+dtbl));
  8518. if(showFrm === undefined) {
  8519. showFrm = true;
  8520. }
  8521. }
  8522. if(showFrm === false) {return;}
  8523. $(".fm-button","#"+dtbl+"_2").hover(
  8524. function(){$(this).addClass('ui-state-hover');},
  8525. function(){$(this).removeClass('ui-state-hover');}
  8526. );
  8527. p.delicon = $.extend([true,"left","ui-icon-scissors"],rp_ge[$t.p.id].delicon);
  8528. p.cancelicon = $.extend([true,"left","ui-icon-cancel"],rp_ge[$t.p.id].cancelicon);
  8529. if(p.delicon[0]===true) {
  8530. $("#dData","#"+dtbl+"_2").addClass(p.delicon[1] === "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  8531. .append("<span class='ui-icon "+p.delicon[2]+"'></span>");
  8532. }
  8533. if(p.cancelicon[0]===true) {
  8534. $("#eData","#"+dtbl+"_2").addClass(p.cancelicon[1] === "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
  8535. .append("<span class='ui-icon "+p.cancelicon[2]+"'></span>");
  8536. }
  8537. $("#dData","#"+dtbl+"_2").click(function(){
  8538. var ret=[true,""], pk,
  8539. postdata = $("#DelData>td","#"+dtbl).text(); //the pair is name=val1,val2,...
  8540. onCS = {};
  8541. if( $.isFunction( rp_ge[$t.p.id].onclickSubmit ) ) {onCS = rp_ge[$t.p.id].onclickSubmit.call($t,rp_ge[$t.p.id], postdata) || {};}
  8542. if( $.isFunction( rp_ge[$t.p.id].beforeSubmit ) ) {ret = rp_ge[$t.p.id].beforeSubmit.call($t,postdata);}
  8543. if(ret[0] && !rp_ge[$t.p.id].processing) {
  8544. rp_ge[$t.p.id].processing = true;
  8545. opers = $t.p.prmNames;
  8546. postd = $.extend({},rp_ge[$t.p.id].delData, onCS);
  8547. oper = opers.oper;
  8548. postd[oper] = opers.deloper;
  8549. idname = opers.id;
  8550. postdata = String(postdata).split(",");
  8551. if(!postdata.length) { return false; }
  8552. for(pk in postdata) {
  8553. if(postdata.hasOwnProperty(pk)) {
  8554. postdata[pk] = $.jgrid.stripPref($t.p.idPrefix, postdata[pk]);
  8555. }
  8556. }
  8557. postd[idname] = postdata.join();
  8558. $(this).addClass('ui-state-active');
  8559. var ajaxOptions = $.extend({
  8560. url: rp_ge[$t.p.id].url || $($t).jqGrid('getGridParam','editurl'),
  8561. type: rp_ge[$t.p.id].mtype,
  8562. data: $.isFunction(rp_ge[$t.p.id].serializeDelData) ? rp_ge[$t.p.id].serializeDelData.call($t,postd) : postd,
  8563. complete:function(data,status){
  8564. var i;
  8565. if(data.status >= 300 && data.status !== 304) {
  8566. ret[0] = false;
  8567. if ($.isFunction(rp_ge[$t.p.id].errorTextFormat)) {
  8568. ret[1] = rp_ge[$t.p.id].errorTextFormat.call($t,data);
  8569. } else {
  8570. ret[1] = status + " Status: '" + data.statusText + "'. Error code: " + data.status;
  8571. }
  8572. } else {
  8573. // data is posted successful
  8574. // execute aftersubmit with the returned data from server
  8575. if( $.isFunction( rp_ge[$t.p.id].afterSubmit ) ) {
  8576. ret = rp_ge[$t.p.id].afterSubmit.call($t,data,postd);
  8577. }
  8578. }
  8579. if(ret[0] === false) {
  8580. $("#DelError>td","#"+dtbl).html(ret[1]);
  8581. $("#DelError","#"+dtbl).show();
  8582. } else {
  8583. if(rp_ge[$t.p.id].reloadAfterSubmit && $t.p.datatype !== "local") {
  8584. $($t).trigger("reloadGrid");
  8585. } else {
  8586. if($t.p.treeGrid===true){
  8587. try {$($t).jqGrid("delTreeNode",$t.p.idPrefix+postdata[0]);} catch(e){}
  8588. } else {
  8589. for(i=0;i<postdata.length;i++) {
  8590. $($t).jqGrid("delRowData",$t.p.idPrefix+ postdata[i]);
  8591. }
  8592. }
  8593. $t.p.selrow = null;
  8594. $t.p.selarrrow = [];
  8595. }
  8596. if($.isFunction(rp_ge[$t.p.id].afterComplete)) {
  8597. setTimeout(function(){rp_ge[$t.p.id].afterComplete.call($t,data,postdata);},500);
  8598. }
  8599. }
  8600. rp_ge[$t.p.id].processing=false;
  8601. $("#dData", "#"+dtbl+"_2").removeClass('ui-state-active');
  8602. if(ret[0]) {$.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});}
  8603. }
  8604. }, $.jgrid.ajaxOptions, rp_ge[$t.p.id].ajaxDelOptions);
  8605. if (!ajaxOptions.url && !rp_ge[$t.p.id].useDataProxy) {
  8606. if ($.isFunction($t.p.dataProxy)) {
  8607. rp_ge[$t.p.id].useDataProxy = true;
  8608. } else {
  8609. ret[0]=false;ret[1] += " "+$.jgrid.errors.nourl;
  8610. }
  8611. }
  8612. if (ret[0]) {
  8613. if (rp_ge[$t.p.id].useDataProxy) {
  8614. var dpret = $t.p.dataProxy.call($t, ajaxOptions, "del_"+$t.p.id);
  8615. if(dpret === undefined) {
  8616. dpret = [true, ""];
  8617. }
  8618. if(dpret[0] === false ) {
  8619. ret[0] = false;
  8620. ret[1] = dpret[1] || "Error deleting the selected row!" ;
  8621. } else {
  8622. $.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, onClose: rp_ge[$t.p.id].onClose});
  8623. }
  8624. }
  8625. else {$.ajax(ajaxOptions);}
  8626. }
  8627. }
  8628. if(ret[0] === false) {
  8629. $("#DelError>td","#"+dtbl).html(ret[1]);
  8630. $("#DelError","#"+dtbl).show();
  8631. }
  8632. return false;
  8633. });
  8634. $("#eData", "#"+dtbl+"_2").click(function(){
  8635. $.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});
  8636. return false;
  8637. });
  8638. if(onBeforeShow) {rp_ge[$t.p.id].beforeShowForm.call($t,$("#"+dtbl));}
  8639. $.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});
  8640. if(onAfterShow) {rp_ge[$t.p.id].afterShowForm.call($t,$("#"+dtbl));}
  8641. }
  8642. if(rp_ge[$t.p.id].closeOnEscape===true) {
  8643. setTimeout(function(){$(".ui-jqdialog-titlebar-close","#"+$.jgrid.jqID(IDs.modalhead)).focus();},0);
  8644. }
  8645. });
  8646. },
  8647. navGrid : function (elem, o, pEdit,pAdd,pDel,pSearch, pView) {
  8648. o = $.extend({
  8649. edit: true,
  8650. editicon: "ui-icon-pencil",
  8651. add: true,
  8652. addicon:"ui-icon-plus",
  8653. del: true,
  8654. delicon:"ui-icon-trash",
  8655. search: true,
  8656. searchicon:"ui-icon-search",
  8657. refresh: true,
  8658. refreshicon:"ui-icon-refresh",
  8659. refreshstate: 'firstpage',
  8660. view: false,
  8661. viewicon : "ui-icon-document",
  8662. position : "left",
  8663. closeOnEscape : true,
  8664. beforeRefresh : null,
  8665. afterRefresh : null,
  8666. cloneToTop : false,
  8667. alertwidth : 200,
  8668. alertheight : 'auto',
  8669. alerttop: null,
  8670. alertleft: null,
  8671. alertzIndex : null
  8672. }, $.jgrid.nav, o ||{});
  8673. return this.each(function() {
  8674. if(this.nav) {return;}
  8675. var alertIDs = {themodal: 'alertmod_' + this.p.id, modalhead: 'alerthd_' + this.p.id,modalcontent: 'alertcnt_' + this.p.id},
  8676. $t = this, twd, tdw;
  8677. if(!$t.grid || typeof elem !== 'string') {return;}
  8678. if ($("#"+alertIDs.themodal)[0] === undefined) {
  8679. if(!o.alerttop && !o.alertleft) {
  8680. if (window.innerWidth !== undefined) {
  8681. o.alertleft = window.innerWidth;
  8682. o.alerttop = window.innerHeight;
  8683. } else if (document.documentElement !== undefined && document.documentElement.clientWidth !== undefined && document.documentElement.clientWidth !== 0) {
  8684. o.alertleft = document.documentElement.clientWidth;
  8685. o.alerttop = document.documentElement.clientHeight;
  8686. } else {
  8687. o.alertleft=1024;
  8688. o.alerttop=768;
  8689. }
  8690. o.alertleft = o.alertleft/2 - parseInt(o.alertwidth,10)/2;
  8691. o.alerttop = o.alerttop/2-25;
  8692. }
  8693. $.jgrid.createModal(alertIDs,
  8694. "<div>"+o.alerttext+"</div><span tabindex='0'><span tabindex='-1' id='jqg_alrt'></span></span>",
  8695. {
  8696. gbox:"#gbox_"+$.jgrid.jqID($t.p.id),
  8697. jqModal:true,
  8698. drag:true,
  8699. resize:true,
  8700. caption:o.alertcap,
  8701. top:o.alerttop,
  8702. left:o.alertleft,
  8703. width:o.alertwidth,
  8704. height: o.alertheight,
  8705. closeOnEscape:o.closeOnEscape,
  8706. zIndex: o.alertzIndex
  8707. },
  8708. "#gview_"+$.jgrid.jqID($t.p.id),
  8709. $("#gbox_"+$.jgrid.jqID($t.p.id))[0],
  8710. true
  8711. );
  8712. }
  8713. var clone = 1, i,
  8714. onHoverIn = function () {
  8715. if (!$(this).hasClass('ui-state-disabled')) {
  8716. $(this).addClass("ui-state-hover");
  8717. }
  8718. },
  8719. onHoverOut = function () {
  8720. $(this).removeClass("ui-state-hover");
  8721. };
  8722. if(o.cloneToTop && $t.p.toppager) {clone = 2;}
  8723. for(i = 0; i<clone; i++) {
  8724. var tbd,
  8725. navtbl = $("<table cellspacing='0' cellpadding='0' border='0' class='ui-pg-table navtable' style='float:left;table-layout:auto;'><tbody><tr></tr></tbody></table>"),
  8726. sep = "<td class='ui-pg-button ui-state-disabled' style='width:4px;'><span class='ui-separator'></span></td>",
  8727. pgid, elemids;
  8728. if(i===0) {
  8729. pgid = elem;
  8730. elemids = $t.p.id;
  8731. if(pgid === $t.p.toppager) {
  8732. elemids += "_top";
  8733. clone = 1;
  8734. }
  8735. } else {
  8736. pgid = $t.p.toppager;
  8737. elemids = $t.p.id+"_top";
  8738. }
  8739. if($t.p.direction === "rtl") {$(navtbl).attr("dir","rtl").css("float","right");}
  8740. if (o.add) {
  8741. pAdd = pAdd || {};
  8742. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  8743. $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.addicon+"'></span>"+o.addtext+"</div>");
  8744. $("tr",navtbl).append(tbd);
  8745. $(tbd,navtbl)
  8746. .attr({"title":o.addtitle || "",id : pAdd.id || "add_"+elemids})
  8747. .click(function(){
  8748. if (!$(this).hasClass('ui-state-disabled')) {
  8749. if ($.isFunction( o.addfunc )) {
  8750. o.addfunc.call($t);
  8751. } else {
  8752. $($t).jqGrid("editGridRow","new",pAdd);
  8753. }
  8754. }
  8755. return false;
  8756. }).hover(onHoverIn, onHoverOut);
  8757. tbd = null;
  8758. }
  8759. if (o.edit) {
  8760. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  8761. pEdit = pEdit || {};
  8762. $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.editicon+"'></span>"+o.edittext+"</div>");
  8763. $("tr",navtbl).append(tbd);
  8764. $(tbd,navtbl)
  8765. .attr({"title":o.edittitle || "",id: pEdit.id || "edit_"+elemids})
  8766. .click(function(){
  8767. if (!$(this).hasClass('ui-state-disabled')) {
  8768. var sr = $t.p.selrow;
  8769. if (sr) {
  8770. if($.isFunction( o.editfunc ) ) {
  8771. o.editfunc.call($t, sr);
  8772. } else {
  8773. $($t).jqGrid("editGridRow",sr,pEdit);
  8774. }
  8775. } else {
  8776. $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:true});
  8777. $("#jqg_alrt").focus();
  8778. }
  8779. }
  8780. return false;
  8781. }).hover(onHoverIn, onHoverOut);
  8782. tbd = null;
  8783. }
  8784. if (o.view) {
  8785. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  8786. pView = pView || {};
  8787. $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.viewicon+"'></span>"+o.viewtext+"</div>");
  8788. $("tr",navtbl).append(tbd);
  8789. $(tbd,navtbl)
  8790. .attr({"title":o.viewtitle || "",id: pView.id || "view_"+elemids})
  8791. .click(function(){
  8792. if (!$(this).hasClass('ui-state-disabled')) {
  8793. var sr = $t.p.selrow;
  8794. if (sr) {
  8795. if($.isFunction( o.viewfunc ) ) {
  8796. o.viewfunc.call($t, sr);
  8797. } else {
  8798. $($t).jqGrid("viewGridRow",sr,pView);
  8799. }
  8800. } else {
  8801. $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:true});
  8802. $("#jqg_alrt").focus();
  8803. }
  8804. }
  8805. return false;
  8806. }).hover(onHoverIn, onHoverOut);
  8807. tbd = null;
  8808. }
  8809. if (o.del) {
  8810. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  8811. pDel = pDel || {};
  8812. $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.delicon+"'></span>"+o.deltext+"</div>");
  8813. $("tr",navtbl).append(tbd);
  8814. $(tbd,navtbl)
  8815. .attr({"title":o.deltitle || "",id: pDel.id || "del_"+elemids})
  8816. .click(function(){
  8817. if (!$(this).hasClass('ui-state-disabled')) {
  8818. var dr;
  8819. if($t.p.multiselect) {
  8820. dr = $t.p.selarrrow;
  8821. if(dr.length===0) {dr = null;}
  8822. } else {
  8823. dr = $t.p.selrow;
  8824. }
  8825. if(dr){
  8826. if($.isFunction( o.delfunc )){
  8827. o.delfunc.call($t, dr);
  8828. }else{
  8829. $($t).jqGrid("delGridRow",dr,pDel);
  8830. }
  8831. } else {
  8832. $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:true});$("#jqg_alrt").focus();
  8833. }
  8834. }
  8835. return false;
  8836. }).hover(onHoverIn, onHoverOut);
  8837. tbd = null;
  8838. }
  8839. if(o.add || o.edit || o.del || o.view) {$("tr",navtbl).append(sep);}
  8840. if (o.search) {
  8841. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  8842. pSearch = pSearch || {};
  8843. $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.searchicon+"'></span>"+o.searchtext+"</div>");
  8844. $("tr",navtbl).append(tbd);
  8845. $(tbd,navtbl)
  8846. .attr({"title":o.searchtitle || "",id:pSearch.id || "search_"+elemids})
  8847. .click(function(){
  8848. if (!$(this).hasClass('ui-state-disabled')) {
  8849. if($.isFunction( o.searchfunc )) {
  8850. o.searchfunc.call($t, pSearch);
  8851. } else {
  8852. $($t).jqGrid("searchGrid",pSearch);
  8853. }
  8854. }
  8855. return false;
  8856. }).hover(onHoverIn, onHoverOut);
  8857. if (pSearch.showOnLoad && pSearch.showOnLoad === true) {
  8858. $(tbd,navtbl).click();
  8859. }
  8860. tbd = null;
  8861. }
  8862. if (o.refresh) {
  8863. tbd = $("<td class='ui-pg-button ui-corner-all'></td>");
  8864. $(tbd).append("<div class='ui-pg-div'><span class='ui-icon "+o.refreshicon+"'></span>"+o.refreshtext+"</div>");
  8865. $("tr",navtbl).append(tbd);
  8866. $(tbd,navtbl)
  8867. .attr({"title":o.refreshtitle || "",id: "refresh_"+elemids})
  8868. .click(function(){
  8869. if (!$(this).hasClass('ui-state-disabled')) {
  8870. if($.isFunction(o.beforeRefresh)) {o.beforeRefresh.call($t);}
  8871. $t.p.search = false;
  8872. try {
  8873. var gID = $t.p.id;
  8874. $t.p.postData.filters ="";
  8875. try {
  8876. $("#fbox_"+$.jgrid.jqID(gID)).jqFilter('resetFilter');
  8877. } catch(ef) {}
  8878. if($.isFunction($t.clearToolbar)) {$t.clearToolbar.call($t,false);}
  8879. } catch (e) {}
  8880. switch (o.refreshstate) {
  8881. case 'firstpage':
  8882. $($t).trigger("reloadGrid", [{page:1}]);
  8883. break;
  8884. case 'current':
  8885. $($t).trigger("reloadGrid", [{current:true}]);
  8886. break;
  8887. }
  8888. if($.isFunction(o.afterRefresh)) {o.afterRefresh.call($t);}
  8889. }
  8890. return false;
  8891. }).hover(onHoverIn, onHoverOut);
  8892. tbd = null;
  8893. }
  8894. tdw = $(".ui-jqgrid").css("font-size") || "11px";
  8895. $('body').append("<div id='testpg2' class='ui-jqgrid ui-widget ui-widget-content' style='font-size:"+tdw+";visibility:hidden;' ></div>");
  8896. twd = $(navtbl).clone().appendTo("#testpg2").width();
  8897. $("#testpg2").remove();
  8898. $(pgid+"_"+o.position,pgid).append(navtbl);
  8899. if($t.p._nvtd) {
  8900. if(twd > $t.p._nvtd[0] ) {
  8901. $(pgid+"_"+o.position,pgid).width(twd);
  8902. $t.p._nvtd[0] = twd;
  8903. }
  8904. $t.p._nvtd[1] = twd;
  8905. }
  8906. tdw =null;twd=null;navtbl =null;
  8907. this.nav = true;
  8908. }
  8909. });
  8910. },
  8911. navButtonAdd : function (elem, p) {
  8912. p = $.extend({
  8913. caption : "newButton",
  8914. title: '',
  8915. buttonicon : 'ui-icon-newwin',
  8916. onClickButton: null,
  8917. position : "last",
  8918. cursor : 'pointer'
  8919. }, p ||{});
  8920. return this.each(function() {
  8921. if( !this.grid) {return;}
  8922. if( typeof elem === "string" && elem.indexOf("#") !== 0) {elem = "#"+$.jgrid.jqID(elem);}
  8923. var findnav = $(".navtable",elem)[0], $t = this;
  8924. if (findnav) {
  8925. if( p.id && $("#"+$.jgrid.jqID(p.id), findnav)[0] !== undefined ) {return;}
  8926. var tbd = $("<td></td>");
  8927. if(p.buttonicon.toString().toUpperCase() === "NONE") {
  8928. $(tbd).addClass('ui-pg-button ui-corner-all').append("<div class='ui-pg-div'>"+p.caption+"</div>");
  8929. } else {
  8930. $(tbd).addClass('ui-pg-button ui-corner-all').append("<div class='ui-pg-div'><span class='ui-icon "+p.buttonicon+"'></span>"+p.caption+"</div>");
  8931. }
  8932. if(p.id) {$(tbd).attr("id",p.id);}
  8933. if(p.position==='first'){
  8934. if(findnav.rows[0].cells.length ===0 ) {
  8935. $("tr",findnav).append(tbd);
  8936. } else {
  8937. $("tr td:eq(0)",findnav).before(tbd);
  8938. }
  8939. } else {
  8940. $("tr",findnav).append(tbd);
  8941. }
  8942. $(tbd,findnav)
  8943. .attr("title",p.title || "")
  8944. .click(function(e){
  8945. if (!$(this).hasClass('ui-state-disabled')) {
  8946. if ($.isFunction(p.onClickButton) ) {p.onClickButton.call($t,e);}
  8947. }
  8948. return false;
  8949. })
  8950. .hover(
  8951. function () {
  8952. if (!$(this).hasClass('ui-state-disabled')) {
  8953. $(this).addClass('ui-state-hover');
  8954. }
  8955. },
  8956. function () {$(this).removeClass("ui-state-hover");}
  8957. );
  8958. }
  8959. });
  8960. },
  8961. navSeparatorAdd:function (elem,p) {
  8962. p = $.extend({
  8963. sepclass : "ui-separator",
  8964. sepcontent: '',
  8965. position : "last"
  8966. }, p ||{});
  8967. return this.each(function() {
  8968. if( !this.grid) {return;}
  8969. if( typeof elem === "string" && elem.indexOf("#") !== 0) {elem = "#"+$.jgrid.jqID(elem);}
  8970. var findnav = $(".navtable",elem)[0];
  8971. if(findnav) {
  8972. var sep = "<td class='ui-pg-button ui-state-disabled' style='width:4px;'><span class='"+p.sepclass+"'></span>"+p.sepcontent+"</td>";
  8973. if (p.position === 'first') {
  8974. if (findnav.rows[0].cells.length === 0) {
  8975. $("tr", findnav).append(sep);
  8976. } else {
  8977. $("tr td:eq(0)", findnav).before(sep);
  8978. }
  8979. } else {
  8980. $("tr", findnav).append(sep);
  8981. }
  8982. }
  8983. });
  8984. },
  8985. GridToForm : function( rowid, formid ) {
  8986. return this.each(function(){
  8987. var $t = this, i;
  8988. if (!$t.grid) {return;}
  8989. var rowdata = $($t).jqGrid("getRowData",rowid);
  8990. if (rowdata) {
  8991. for(i in rowdata) {
  8992. if(rowdata.hasOwnProperty(i)) {
  8993. if ( $("[name="+$.jgrid.jqID(i)+"]",formid).is("input:radio") || $("[name="+$.jgrid.jqID(i)+"]",formid).is("input:checkbox")) {
  8994. $("[name="+$.jgrid.jqID(i)+"]",formid).each( function() {
  8995. if( $(this).val() == rowdata[i] ) {
  8996. $(this)[$t.p.useProp ? 'prop': 'attr']("checked",true);
  8997. } else {
  8998. $(this)[$t.p.useProp ? 'prop': 'attr']("checked", false);
  8999. }
  9000. });
  9001. } else {
  9002. // this is very slow on big table and form.
  9003. $("[name="+$.jgrid.jqID(i)+"]",formid).val(rowdata[i]);
  9004. }
  9005. }
  9006. }
  9007. }
  9008. });
  9009. },
  9010. FormToGrid : function(rowid, formid, mode, position){
  9011. return this.each(function() {
  9012. var $t = this;
  9013. if(!$t.grid) {return;}
  9014. if(!mode) {mode = 'set';}
  9015. if(!position) {position = 'first';}
  9016. var fields = $(formid).serializeArray();
  9017. var griddata = {};
  9018. $.each(fields, function(i, field){
  9019. griddata[field.name] = field.value;
  9020. });
  9021. if(mode==='add') {$($t).jqGrid("addRowData",rowid,griddata, position);}
  9022. else if(mode==='set') {$($t).jqGrid("setRowData",rowid,griddata);}
  9023. });
  9024. }
  9025. });
  9026. })(jQuery);
  9027. /*jshint eqeqeq:false, eqnull:true, devel:true */
  9028. /*global jQuery */
  9029. (function($){
  9030. /**
  9031. * jqGrid extension for manipulating Grid Data
  9032. * Tony Tomov tony@trirand.com
  9033. * http://trirand.com/blog/
  9034. * Dual licensed under the MIT and GPL licenses:
  9035. * http://www.opensource.org/licenses/mit-license.php
  9036. * http://www.gnu.org/licenses/gpl-2.0.html
  9037. **/
  9038. "use strict";
  9039. $.jgrid.inlineEdit = $.jgrid.inlineEdit || {};
  9040. $.jgrid.extend({
  9041. //Editing
  9042. editRow : function(rowid,keys,oneditfunc,successfunc, url, extraparam, aftersavefunc,errorfunc, afterrestorefunc) {
  9043. // Compatible mode old versions
  9044. var o={}, args = $.makeArray(arguments).slice(1);
  9045. if( $.type(args[0]) === "object" ) {
  9046. o = args[0];
  9047. } else {
  9048. if (keys !== undefined) { o.keys = keys; }
  9049. if ($.isFunction(oneditfunc)) { o.oneditfunc = oneditfunc; }
  9050. if ($.isFunction(successfunc)) { o.successfunc = successfunc; }
  9051. if (url !== undefined) { o.url = url; }
  9052. if (extraparam !== undefined) { o.extraparam = extraparam; }
  9053. if ($.isFunction(aftersavefunc)) { o.aftersavefunc = aftersavefunc; }
  9054. if ($.isFunction(errorfunc)) { o.errorfunc = errorfunc; }
  9055. if ($.isFunction(afterrestorefunc)) { o.afterrestorefunc = afterrestorefunc; }
  9056. // last two not as param, but as object (sorry)
  9057. //if (restoreAfterError !== undefined) { o.restoreAfterError = restoreAfterError; }
  9058. //if (mtype !== undefined) { o.mtype = mtype || "POST"; }
  9059. }
  9060. o = $.extend(true, {
  9061. keys : false,
  9062. oneditfunc: null,
  9063. successfunc: null,
  9064. url: null,
  9065. extraparam: {},
  9066. aftersavefunc: null,
  9067. errorfunc: null,
  9068. afterrestorefunc: null,
  9069. restoreAfterError: true,
  9070. mtype: "POST"
  9071. }, $.jgrid.inlineEdit, o );
  9072. // End compatible
  9073. return this.each(function(){
  9074. var $t = this, nm, tmp, editable, cnt=0, focus=null, svr={}, ind,cm;
  9075. if (!$t.grid ) { return; }
  9076. ind = $($t).jqGrid("getInd",rowid,true);
  9077. if( ind === false ) {return;}
  9078. editable = $(ind).attr("editable") || "0";
  9079. if (editable === "0" && !$(ind).hasClass("not-editable-row")) {
  9080. cm = $t.p.colModel;
  9081. $('td[role="gridcell"]',ind).each( function(i) {
  9082. nm = cm[i].name;
  9083. var treeg = $t.p.treeGrid===true && nm === $t.p.ExpandColumn;
  9084. if(treeg) { tmp = $("span:first",this).html();}
  9085. else {
  9086. try {
  9087. tmp = $.unformat.call($t,this,{rowId:rowid, colModel:cm[i]},i);
  9088. } catch (_) {
  9089. tmp = ( cm[i].edittype && cm[i].edittype === 'textarea' ) ? $(this).text() : $(this).html();
  9090. }
  9091. }
  9092. if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn') {
  9093. if($t.p.autoencode) { tmp = $.jgrid.htmlDecode(tmp); }
  9094. svr[nm]=tmp;
  9095. if(cm[i].editable===true) {
  9096. if(focus===null) { focus = i; }
  9097. if (treeg) { $("span:first",this).html(""); }
  9098. else { $(this).html(""); }
  9099. var opt = $.extend({},cm[i].editoptions || {},{id:rowid+"_"+nm,name:nm});
  9100. if(!cm[i].edittype) { cm[i].edittype = "text"; }
  9101. if(tmp === "&nbsp;" || tmp === "&#160;" || (tmp.length===1 && tmp.charCodeAt(0)===160) ) {tmp='';}
  9102. var elc = $.jgrid.createEl.call($t,cm[i].edittype,opt,tmp,true,$.extend({},$.jgrid.ajaxOptions,$t.p.ajaxSelectOptions || {}));
  9103. $(elc).addClass("editable");
  9104. if(treeg) { $("span:first",this).append(elc); }
  9105. else { $(this).append(elc); }
  9106. $.jgrid.bindEv.call($t, elc, opt);
  9107. //Again IE
  9108. if(cm[i].edittype === "select" && cm[i].editoptions!==undefined && cm[i].editoptions.multiple===true && cm[i].editoptions.dataUrl===undefined && $.jgrid.msie) {
  9109. $(elc).width($(elc).width());
  9110. }
  9111. cnt++;
  9112. }
  9113. }
  9114. });
  9115. if(cnt > 0) {
  9116. svr.id = rowid; $t.p.savedRow.push(svr);
  9117. $(ind).attr("editable","1");
  9118. $("td:eq("+focus+") input",ind).focus();
  9119. if(o.keys===true) {
  9120. $(ind).bind("keydown",function(e) {
  9121. if (e.keyCode === 27) {
  9122. $($t).jqGrid("restoreRow",rowid, o.afterrestorefunc);
  9123. if($t.p._inlinenav) {
  9124. try {
  9125. $($t).jqGrid('showAddEditButtons');
  9126. } catch (eer1) {}
  9127. }
  9128. return false;
  9129. }
  9130. if (e.keyCode === 13) {
  9131. var ta = e.target;
  9132. if(ta.tagName === 'TEXTAREA') { return true; }
  9133. if( $($t).jqGrid("saveRow", rowid, o ) ) {
  9134. if($t.p._inlinenav) {
  9135. try {
  9136. $($t).jqGrid('showAddEditButtons');
  9137. } catch (eer2) {}
  9138. }
  9139. }
  9140. return false;
  9141. }
  9142. });
  9143. }
  9144. $($t).triggerHandler("jqGridInlineEditRow", [rowid, o]);
  9145. if( $.isFunction(o.oneditfunc)) { o.oneditfunc.call($t, rowid); }
  9146. }
  9147. }
  9148. });
  9149. },
  9150. saveRow : function(rowid, successfunc, url, extraparam, aftersavefunc,errorfunc, afterrestorefunc) {
  9151. // Compatible mode old versions
  9152. var args = $.makeArray(arguments).slice(1), o = {};
  9153. if( $.type(args[0]) === "object" ) {
  9154. o = args[0];
  9155. } else {
  9156. if ($.isFunction(successfunc)) { o.successfunc = successfunc; }
  9157. if (url !== undefined) { o.url = url; }
  9158. if (extraparam !== undefined) { o.extraparam = extraparam; }
  9159. if ($.isFunction(aftersavefunc)) { o.aftersavefunc = aftersavefunc; }
  9160. if ($.isFunction(errorfunc)) { o.errorfunc = errorfunc; }
  9161. if ($.isFunction(afterrestorefunc)) { o.afterrestorefunc = afterrestorefunc; }
  9162. }
  9163. o = $.extend(true, {
  9164. successfunc: null,
  9165. url: null,
  9166. extraparam: {},
  9167. aftersavefunc: null,
  9168. errorfunc: null,
  9169. afterrestorefunc: null,
  9170. restoreAfterError: true,
  9171. mtype: "POST"
  9172. }, $.jgrid.inlineEdit, o );
  9173. // End compatible
  9174. var success = false;
  9175. var $t = this[0], nm, tmp={}, tmp2={}, tmp3= {}, editable, fr, cv, ind;
  9176. if (!$t.grid ) { return success; }
  9177. ind = $($t).jqGrid("getInd",rowid,true);
  9178. if(ind === false) {return success;}
  9179. editable = $(ind).attr("editable");
  9180. o.url = o.url || $t.p.editurl;
  9181. if (editable==="1") {
  9182. var cm;
  9183. $('td[role="gridcell"]',ind).each(function(i) {
  9184. cm = $t.p.colModel[i];
  9185. nm = cm.name;
  9186. if ( nm !== 'cb' && nm !== 'subgrid' && cm.editable===true && nm !== 'rn' && !$(this).hasClass('not-editable-cell')) {
  9187. switch (cm.edittype) {
  9188. case "checkbox":
  9189. var cbv = ["Yes","No"];
  9190. if(cm.editoptions ) {
  9191. cbv = cm.editoptions.value.split(":");
  9192. }
  9193. tmp[nm]= $("input",this).is(":checked") ? cbv[0] : cbv[1];
  9194. break;
  9195. case 'text':
  9196. case 'password':
  9197. case 'textarea':
  9198. case "button" :
  9199. tmp[nm]=$("input, textarea",this).val();
  9200. break;
  9201. case 'select':
  9202. if(!cm.editoptions.multiple) {
  9203. tmp[nm] = $("select option:selected",this).val();
  9204. tmp2[nm] = $("select option:selected", this).text();
  9205. } else {
  9206. var sel = $("select",this), selectedText = [];
  9207. tmp[nm] = $(sel).val();
  9208. if(tmp[nm]) { tmp[nm]= tmp[nm].join(","); } else { tmp[nm] =""; }
  9209. $("select option:selected",this).each(
  9210. function(i,selected){
  9211. selectedText[i] = $(selected).text();
  9212. }
  9213. );
  9214. tmp2[nm] = selectedText.join(",");
  9215. }
  9216. if(cm.formatter && cm.formatter === 'select') { tmp2={}; }
  9217. break;
  9218. case 'custom' :
  9219. try {
  9220. if(cm.editoptions && $.isFunction(cm.editoptions.custom_value)) {
  9221. tmp[nm] = cm.editoptions.custom_value.call($t, $(".customelement",this),'get');
  9222. if (tmp[nm] === undefined) { throw "e2"; }
  9223. } else { throw "e1"; }
  9224. } catch (e) {
  9225. if (e==="e1") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.nodefined,$.jgrid.edit.bClose); }
  9226. if (e==="e2") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose); }
  9227. else { $.jgrid.info_dialog($.jgrid.errors.errcap,e.message,$.jgrid.edit.bClose); }
  9228. }
  9229. break;
  9230. }
  9231. cv = $.jgrid.checkValues.call($t,tmp[nm],i);
  9232. if(cv[0] === false) {
  9233. cv[1] = tmp[nm] + " " + cv[1];
  9234. return false;
  9235. }
  9236. if($t.p.autoencode) { tmp[nm] = $.jgrid.htmlEncode(tmp[nm]); }
  9237. if(o.url !== 'clientArray' && cm.editoptions && cm.editoptions.NullIfEmpty === true) {
  9238. if(tmp[nm] === "") {
  9239. tmp3[nm] = 'null';
  9240. }
  9241. }
  9242. }
  9243. });
  9244. if (cv[0] === false){
  9245. try {
  9246. var tr = $t.rows.namedItem(rowid), positions = $.jgrid.findPos(tr);
  9247. $.jgrid.info_dialog($.jgrid.errors.errcap,cv[1],$.jgrid.edit.bClose,{left:positions[0],top:positions[1]+$(tr).outerHeight()});
  9248. } catch (e) {
  9249. alert(cv[1]);
  9250. }
  9251. return success;
  9252. }
  9253. var idname, opers = $t.p.prmNames, oldRowId = rowid;
  9254. if ($t.p.keyIndex === false) {
  9255. idname = opers.id;
  9256. } else {
  9257. idname = $t.p.colModel[$t.p.keyIndex +
  9258. ($t.p.rownumbers === true ? 1 : 0) +
  9259. ($t.p.multiselect === true ? 1 : 0) +
  9260. ($t.p.subGrid === true ? 1 : 0)].name;
  9261. }
  9262. if(tmp) {
  9263. tmp[opers.oper] = opers.editoper;
  9264. if (tmp[idname] === undefined || tmp[idname]==="") {
  9265. tmp[idname] = rowid;
  9266. } else if (ind.id !== $t.p.idPrefix + tmp[idname]) {
  9267. // rename rowid
  9268. var oldid = $.jgrid.stripPref($t.p.idPrefix, rowid);
  9269. if ($t.p._index[oldid] !== undefined) {
  9270. $t.p._index[tmp[idname]] = $t.p._index[oldid];
  9271. delete $t.p._index[oldid];
  9272. }
  9273. rowid = $t.p.idPrefix + tmp[idname];
  9274. $(ind).attr("id", rowid);
  9275. if ($t.p.selrow === oldRowId) {
  9276. $t.p.selrow = rowid;
  9277. }
  9278. if ($.isArray($t.p.selarrrow)) {
  9279. var i = $.inArray(oldRowId, $t.p.selarrrow);
  9280. if (i>=0) {
  9281. $t.p.selarrrow[i] = rowid;
  9282. }
  9283. }
  9284. if ($t.p.multiselect) {
  9285. var newCboxId = "jqg_" + $t.p.id + "_" + rowid;
  9286. $("input.cbox",ind)
  9287. .attr("id", newCboxId)
  9288. .attr("name", newCboxId);
  9289. }
  9290. // TODO: to test the case of frozen columns
  9291. }
  9292. if($t.p.inlineData === undefined) { $t.p.inlineData ={}; }
  9293. tmp = $.extend({},tmp,$t.p.inlineData,o.extraparam);
  9294. }
  9295. if (o.url === 'clientArray') {
  9296. tmp = $.extend({},tmp, tmp2);
  9297. if($t.p.autoencode) {
  9298. $.each(tmp,function(n,v){
  9299. tmp[n] = $.jgrid.htmlDecode(v);
  9300. });
  9301. }
  9302. var k, resp = $($t).jqGrid("setRowData",rowid,tmp);
  9303. $(ind).attr("editable","0");
  9304. for(k=0;k<$t.p.savedRow.length;k++) {
  9305. if( String($t.p.savedRow[k].id) === String(oldRowId)) {fr = k; break;}
  9306. }
  9307. if(fr >= 0) { $t.p.savedRow.splice(fr,1); }
  9308. $($t).triggerHandler("jqGridInlineAfterSaveRow", [rowid, resp, tmp, o]);
  9309. if( $.isFunction(o.aftersavefunc) ) { o.aftersavefunc.call($t, rowid,resp, o); }
  9310. success = true;
  9311. $(ind).removeClass("jqgrid-new-row").unbind("keydown");
  9312. } else {
  9313. $("#lui_"+$.jgrid.jqID($t.p.id)).show();
  9314. tmp3 = $.extend({},tmp,tmp3);
  9315. tmp3[idname] = $.jgrid.stripPref($t.p.idPrefix, tmp3[idname]);
  9316. $.ajax($.extend({
  9317. url:o.url,
  9318. data: $.isFunction($t.p.serializeRowData) ? $t.p.serializeRowData.call($t, tmp3) : tmp3,
  9319. type: o.mtype,
  9320. async : false, //?!?
  9321. complete: function(res,stat){
  9322. $("#lui_"+$.jgrid.jqID($t.p.id)).hide();
  9323. if (stat === "success"){
  9324. var ret = true, sucret, k;
  9325. sucret = $($t).triggerHandler("jqGridInlineSuccessSaveRow", [res, rowid, o]);
  9326. if (!$.isArray(sucret)) {sucret = [true, tmp];}
  9327. if (sucret[0] && $.isFunction(o.successfunc)) {sucret = o.successfunc.call($t, res);}
  9328. if($.isArray(sucret)) {
  9329. // expect array - status, data, rowid
  9330. ret = sucret[0];
  9331. tmp = sucret[1] || tmp;
  9332. } else {
  9333. ret = sucret;
  9334. }
  9335. if (ret===true) {
  9336. if($t.p.autoencode) {
  9337. $.each(tmp,function(n,v){
  9338. tmp[n] = $.jgrid.htmlDecode(v);
  9339. });
  9340. }
  9341. tmp = $.extend({},tmp, tmp2);
  9342. $($t).jqGrid("setRowData",rowid,tmp);
  9343. $(ind).attr("editable","0");
  9344. for(k=0;k<$t.p.savedRow.length;k++) {
  9345. if( String($t.p.savedRow[k].id) === String(rowid)) {fr = k; break;}
  9346. }
  9347. if(fr >= 0) { $t.p.savedRow.splice(fr,1); }
  9348. $($t).triggerHandler("jqGridInlineAfterSaveRow", [rowid, res, tmp, o]);
  9349. if( $.isFunction(o.aftersavefunc) ) { o.aftersavefunc.call($t, rowid,res); }
  9350. success = true;
  9351. $(ind).removeClass("jqgrid-new-row").unbind("keydown");
  9352. } else {
  9353. $($t).triggerHandler("jqGridInlineErrorSaveRow", [rowid, res, stat, null, o]);
  9354. if($.isFunction(o.errorfunc) ) {
  9355. o.errorfunc.call($t, rowid, res, stat, null);
  9356. }
  9357. if(o.restoreAfterError === true) {
  9358. $($t).jqGrid("restoreRow",rowid, o.afterrestorefunc);
  9359. }
  9360. }
  9361. }
  9362. },
  9363. error:function(res,stat,err){
  9364. $("#lui_"+$.jgrid.jqID($t.p.id)).hide();
  9365. $($t).triggerHandler("jqGridInlineErrorSaveRow", [rowid, res, stat, err, o]);
  9366. if($.isFunction(o.errorfunc) ) {
  9367. o.errorfunc.call($t, rowid, res, stat, err);
  9368. } else {
  9369. var rT = res.responseText || res.statusText;
  9370. try {
  9371. $.jgrid.info_dialog($.jgrid.errors.errcap,'<div class="ui-state-error">'+ rT +'</div>', $.jgrid.edit.bClose,{buttonalign:'right'});
  9372. } catch(e) {
  9373. alert(rT);
  9374. }
  9375. }
  9376. if(o.restoreAfterError === true) {
  9377. $($t).jqGrid("restoreRow",rowid, o.afterrestorefunc);
  9378. }
  9379. }
  9380. }, $.jgrid.ajaxOptions, $t.p.ajaxRowOptions || {}));
  9381. }
  9382. }
  9383. return success;
  9384. },
  9385. restoreRow : function(rowid, afterrestorefunc) {
  9386. // Compatible mode old versions
  9387. var args = $.makeArray(arguments).slice(1), o={};
  9388. if( $.type(args[0]) === "object" ) {
  9389. o = args[0];
  9390. } else {
  9391. if ($.isFunction(afterrestorefunc)) { o.afterrestorefunc = afterrestorefunc; }
  9392. }
  9393. o = $.extend(true, {}, $.jgrid.inlineEdit, o );
  9394. // End compatible
  9395. return this.each(function(){
  9396. var $t= this, fr, ind, ares={}, k;
  9397. if (!$t.grid ) { return; }
  9398. ind = $($t).jqGrid("getInd",rowid,true);
  9399. if(ind === false) {return;}
  9400. for(k=0;k<$t.p.savedRow.length;k++) {
  9401. if( String($t.p.savedRow[k].id) === String(rowid)) {fr = k; break;}
  9402. }
  9403. if(fr >= 0) {
  9404. if($.isFunction($.fn.datepicker)) {
  9405. try {
  9406. $("input.hasDatepicker","#"+$.jgrid.jqID(ind.id)).datepicker('hide');
  9407. } catch (e) {}
  9408. }
  9409. $.each($t.p.colModel, function(){
  9410. if(this.editable === true && $t.p.savedRow[fr].hasOwnProperty(this.name)) {
  9411. ares[this.name] = $t.p.savedRow[fr][this.name];
  9412. }
  9413. });
  9414. $($t).jqGrid("setRowData",rowid,ares);
  9415. $(ind).attr("editable","0").unbind("keydown");
  9416. $t.p.savedRow.splice(fr,1);
  9417. if($("#"+$.jgrid.jqID(rowid), "#"+$.jgrid.jqID($t.p.id)).hasClass("jqgrid-new-row")){
  9418. setTimeout(function(){
  9419. $($t).jqGrid("delRowData",rowid);
  9420. $($t).jqGrid('showAddEditButtons');
  9421. },0);
  9422. }
  9423. }
  9424. $($t).triggerHandler("jqGridInlineAfterRestoreRow", [rowid]);
  9425. if ($.isFunction(o.afterrestorefunc))
  9426. {
  9427. o.afterrestorefunc.call($t, rowid);
  9428. }
  9429. });
  9430. },
  9431. addRow : function ( p ) {
  9432. p = $.extend(true, {
  9433. rowID : null,
  9434. initdata : {},
  9435. position :"first",
  9436. useDefValues : true,
  9437. useFormatter : false,
  9438. addRowParams : {extraparam:{}}
  9439. },p || {});
  9440. return this.each(function(){
  9441. if (!this.grid ) { return; }
  9442. var $t = this;
  9443. p.rowID = $.isFunction(p.rowID) ? p.rowID.call($t, p) : ( (p.rowID != null) ? p.rowID : $.jgrid.randId());
  9444. if(p.useDefValues === true) {
  9445. $($t.p.colModel).each(function(){
  9446. if( this.editoptions && this.editoptions.defaultValue ) {
  9447. var opt = this.editoptions.defaultValue,
  9448. tmp = $.isFunction(opt) ? opt.call($t) : opt;
  9449. p.initdata[this.name] = tmp;
  9450. }
  9451. });
  9452. }
  9453. $($t).jqGrid('addRowData', p.rowID, p.initdata, p.position);
  9454. p.rowID = $t.p.idPrefix + p.rowID;
  9455. $("#"+$.jgrid.jqID(p.rowID), "#"+$.jgrid.jqID($t.p.id)).addClass("jqgrid-new-row");
  9456. if(p.useFormatter) {
  9457. $("#"+$.jgrid.jqID(p.rowID)+" .ui-inline-edit", "#"+$.jgrid.jqID($t.p.id)).click();
  9458. } else {
  9459. var opers = $t.p.prmNames,
  9460. oper = opers.oper;
  9461. p.addRowParams.extraparam[oper] = opers.addoper;
  9462. $($t).jqGrid('editRow', p.rowID, p.addRowParams);
  9463. $($t).jqGrid('setSelection', p.rowID);
  9464. }
  9465. });
  9466. },
  9467. inlineNav : function (elem, o) {
  9468. o = $.extend(true,{
  9469. edit: true,
  9470. editicon: "ui-icon-pencil",
  9471. add: true,
  9472. addicon:"ui-icon-plus",
  9473. save: true,
  9474. saveicon:"ui-icon-disk",
  9475. cancel: true,
  9476. cancelicon:"ui-icon-cancel",
  9477. addParams : {addRowParams: {extraparam: {}}},
  9478. editParams : {},
  9479. restoreAfterSelect : true
  9480. }, $.jgrid.nav, o ||{});
  9481. return this.each(function(){
  9482. if (!this.grid ) { return; }
  9483. var $t = this, onSelect, gID = $.jgrid.jqID($t.p.id);
  9484. $t.p._inlinenav = true;
  9485. // detect the formatactions column
  9486. if(o.addParams.useFormatter === true) {
  9487. var cm = $t.p.colModel,i;
  9488. for (i = 0; i<cm.length; i++) {
  9489. if(cm[i].formatter && cm[i].formatter === "actions" ) {
  9490. if(cm[i].formatoptions) {
  9491. var defaults = {
  9492. keys:false,
  9493. onEdit : null,
  9494. onSuccess: null,
  9495. afterSave:null,
  9496. onError: null,
  9497. afterRestore: null,
  9498. extraparam: {},
  9499. url: null
  9500. },
  9501. ap = $.extend( defaults, cm[i].formatoptions );
  9502. o.addParams.addRowParams = {
  9503. "keys" : ap.keys,
  9504. "oneditfunc" : ap.onEdit,
  9505. "successfunc" : ap.onSuccess,
  9506. "url" : ap.url,
  9507. "extraparam" : ap.extraparam,
  9508. "aftersavefunc" : ap.afterSave,
  9509. "errorfunc": ap.onError,
  9510. "afterrestorefunc" : ap.afterRestore
  9511. };
  9512. }
  9513. break;
  9514. }
  9515. }
  9516. }
  9517. if(o.add) {
  9518. $($t).jqGrid('navButtonAdd', elem,{
  9519. caption : o.addtext,
  9520. title : o.addtitle,
  9521. buttonicon : o.addicon,
  9522. id : $t.p.id+"_iladd",
  9523. onClickButton : function () {
  9524. $($t).jqGrid('addRow', o.addParams);
  9525. if(!o.addParams.useFormatter) {
  9526. $("#"+gID+"_ilsave").removeClass('ui-state-disabled');
  9527. $("#"+gID+"_ilcancel").removeClass('ui-state-disabled');
  9528. $("#"+gID+"_iladd").addClass('ui-state-disabled');
  9529. $("#"+gID+"_iledit").addClass('ui-state-disabled');
  9530. }
  9531. }
  9532. });
  9533. }
  9534. if(o.edit) {
  9535. $($t).jqGrid('navButtonAdd', elem,{
  9536. caption : o.edittext,
  9537. title : o.edittitle,
  9538. buttonicon : o.editicon,
  9539. id : $t.p.id+"_iledit",
  9540. onClickButton : function () {
  9541. var sr = $($t).jqGrid('getGridParam','selrow');
  9542. if(sr) {
  9543. $($t).jqGrid('editRow', sr, o.editParams);
  9544. $("#"+gID+"_ilsave").removeClass('ui-state-disabled');
  9545. $("#"+gID+"_ilcancel").removeClass('ui-state-disabled');
  9546. $("#"+gID+"_iladd").addClass('ui-state-disabled');
  9547. $("#"+gID+"_iledit").addClass('ui-state-disabled');
  9548. } else {
  9549. $.jgrid.viewModal("#alertmod",{gbox:"#gbox_"+gID,jqm:true});$("#jqg_alrt").focus();
  9550. }
  9551. }
  9552. });
  9553. }
  9554. if(o.save) {
  9555. $($t).jqGrid('navButtonAdd', elem,{
  9556. caption : o.savetext || '',
  9557. title : o.savetitle || 'Save row',
  9558. buttonicon : o.saveicon,
  9559. id : $t.p.id+"_ilsave",
  9560. onClickButton : function () {
  9561. var sr = $t.p.savedRow[0].id;
  9562. if(sr) {
  9563. var opers = $t.p.prmNames,
  9564. oper = opers.oper, tmpParams = {};
  9565. if($("#"+$.jgrid.jqID(sr), "#"+gID ).hasClass("jqgrid-new-row")) {
  9566. o.addParams.addRowParams.extraparam[oper] = opers.addoper;
  9567. tmpParams = o.addParams.addRowParams;
  9568. } else {
  9569. if(!o.editParams.extraparam) {
  9570. o.editParams.extraparam = {};
  9571. }
  9572. o.editParams.extraparam[oper] = opers.editoper;
  9573. tmpParams = o.editParams;
  9574. }
  9575. if( $($t).jqGrid('saveRow', sr, tmpParams) ) {
  9576. $($t).jqGrid('showAddEditButtons');
  9577. }
  9578. } else {
  9579. $.jgrid.viewModal("#alertmod",{gbox:"#gbox_"+gID,jqm:true});$("#jqg_alrt").focus();
  9580. }
  9581. }
  9582. });
  9583. $("#"+gID+"_ilsave").addClass('ui-state-disabled');
  9584. }
  9585. if(o.cancel) {
  9586. $($t).jqGrid('navButtonAdd', elem,{
  9587. caption : o.canceltext || '',
  9588. title : o.canceltitle || 'Cancel row editing',
  9589. buttonicon : o.cancelicon,
  9590. id : $t.p.id+"_ilcancel",
  9591. onClickButton : function () {
  9592. var sr = $t.p.savedRow[0].id, cancelPrm = {};
  9593. if(sr) {
  9594. if($("#"+$.jgrid.jqID(sr), "#"+gID ).hasClass("jqgrid-new-row")) {
  9595. cancelPrm = o.addParams.addRowParams;
  9596. } else {
  9597. cancelPrm = o.editParams;
  9598. }
  9599. $($t).jqGrid('restoreRow', sr, cancelPrm);
  9600. $($t).jqGrid('showAddEditButtons');
  9601. } else {
  9602. $.jgrid.viewModal("#alertmod",{gbox:"#gbox_"+gID,jqm:true});$("#jqg_alrt").focus();
  9603. }
  9604. }
  9605. });
  9606. $("#"+gID+"_ilcancel").addClass('ui-state-disabled');
  9607. }
  9608. if(o.restoreAfterSelect === true) {
  9609. if($.isFunction($t.p.beforeSelectRow)) {
  9610. onSelect = $t.p.beforeSelectRow;
  9611. } else {
  9612. onSelect = false;
  9613. }
  9614. $t.p.beforeSelectRow = function(id, stat) {
  9615. var ret = true;
  9616. if($t.p.savedRow.length > 0 && $t.p._inlinenav===true && ( id !== $t.p.selrow && $t.p.selrow !==null) ) {
  9617. if($t.p.selrow === o.addParams.rowID ) {
  9618. $($t).jqGrid('delRowData', $t.p.selrow);
  9619. } else {
  9620. $($t).jqGrid('restoreRow', $t.p.selrow, o.editParams);
  9621. }
  9622. $($t).jqGrid('showAddEditButtons');
  9623. }
  9624. if(onSelect) {
  9625. ret = onSelect.call($t, id, stat);
  9626. }
  9627. return ret;
  9628. };
  9629. }
  9630. });
  9631. },
  9632. showAddEditButtons : function() {
  9633. return this.each(function(){
  9634. if (!this.grid ) { return; }
  9635. var gID = $.jgrid.jqID(this.p.id);
  9636. $("#"+gID+"_ilsave").addClass('ui-state-disabled');
  9637. $("#"+gID+"_ilcancel").addClass('ui-state-disabled');
  9638. $("#"+gID+"_iladd").removeClass('ui-state-disabled');
  9639. $("#"+gID+"_iledit").removeClass('ui-state-disabled');
  9640. });
  9641. }
  9642. //end inline edit
  9643. });
  9644. })(jQuery);
  9645. /*jshint eqeqeq:false */
  9646. /*global jQuery */
  9647. (function($){
  9648. /*
  9649. **
  9650. * jqGrid extension for cellediting Grid Data
  9651. * Tony Tomov tony@trirand.com
  9652. * http://trirand.com/blog/
  9653. * Dual licensed under the MIT and GPL licenses:
  9654. * http://www.opensource.org/licenses/mit-license.php
  9655. * http://www.gnu.org/licenses/gpl-2.0.html
  9656. **/
  9657. /**
  9658. * all events and options here are aded anonynous and not in the base grid
  9659. * since the array is to big. Here is the order of execution.
  9660. * From this point we use jQuery isFunction
  9661. * formatCell
  9662. * beforeEditCell,
  9663. * onSelectCell (used only for noneditable cels)
  9664. * afterEditCell,
  9665. * beforeSaveCell, (called before validation of values if any)
  9666. * beforeSubmitCell (if cellsubmit remote (ajax))
  9667. * afterSubmitCell(if cellsubmit remote (ajax)),
  9668. * afterSaveCell,
  9669. * errorCell,
  9670. * serializeCellData - new
  9671. * Options
  9672. * cellsubmit (remote,clientArray) (added in grid options)
  9673. * cellurl
  9674. * ajaxCellOptions
  9675. * */
  9676. "use strict";
  9677. $.jgrid.extend({
  9678. editCell : function (iRow,iCol, ed){
  9679. return this.each(function (){
  9680. var $t = this, nm, tmp,cc, cm;
  9681. if (!$t.grid || $t.p.cellEdit !== true) {return;}
  9682. iCol = parseInt(iCol,10);
  9683. // select the row that can be used for other methods
  9684. $t.p.selrow = $t.rows[iRow].id;
  9685. if (!$t.p.knv) {$($t).jqGrid("GridNav");}
  9686. // check to see if we have already edited cell
  9687. if ($t.p.savedRow.length>0) {
  9688. // prevent second click on that field and enable selects
  9689. if (ed===true ) {
  9690. if(iRow == $t.p.iRow && iCol == $t.p.iCol){
  9691. return;
  9692. }
  9693. }
  9694. // save the cell
  9695. $($t).jqGrid("saveCell",$t.p.savedRow[0].id,$t.p.savedRow[0].ic);
  9696. } else {
  9697. window.setTimeout(function () { $("#"+$.jgrid.jqID($t.p.knv)).attr("tabindex","-1").focus();},0);
  9698. }
  9699. cm = $t.p.colModel[iCol];
  9700. nm = cm.name;
  9701. if (nm==='subgrid' || nm==='cb' || nm==='rn') {return;}
  9702. cc = $("td:eq("+iCol+")",$t.rows[iRow]);
  9703. if (cm.editable===true && ed===true && !cc.hasClass("not-editable-cell")) {
  9704. if(parseInt($t.p.iCol,10)>=0 && parseInt($t.p.iRow,10)>=0) {
  9705. $("td:eq("+$t.p.iCol+")",$t.rows[$t.p.iRow]).removeClass("edit-cell ui-state-highlight");
  9706. $($t.rows[$t.p.iRow]).removeClass("selected-row ui-state-hover");
  9707. }
  9708. $(cc).addClass("edit-cell ui-state-highlight");
  9709. $($t.rows[iRow]).addClass("selected-row ui-state-hover");
  9710. try {
  9711. tmp = $.unformat.call($t,cc,{rowId: $t.rows[iRow].id, colModel:cm},iCol);
  9712. } catch (_) {
  9713. tmp = ( cm.edittype && cm.edittype === 'textarea' ) ? $(cc).text() : $(cc).html();
  9714. }
  9715. if($t.p.autoencode) { tmp = $.jgrid.htmlDecode(tmp); }
  9716. if (!cm.edittype) {cm.edittype = "text";}
  9717. $t.p.savedRow.push({id:iRow,ic:iCol,name:nm,v:tmp});
  9718. if(tmp === "&nbsp;" || tmp === "&#160;" || (tmp.length===1 && tmp.charCodeAt(0)===160) ) {tmp='';}
  9719. if($.isFunction($t.p.formatCell)) {
  9720. var tmp2 = $t.p.formatCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
  9721. if(tmp2 !== undefined ) {tmp = tmp2;}
  9722. }
  9723. var opt = $.extend({}, cm.editoptions || {} ,{id:iRow+"_"+nm,name:nm});
  9724. var elc = $.jgrid.createEl.call($t,cm.edittype,opt,tmp,true,$.extend({},$.jgrid.ajaxOptions,$t.p.ajaxSelectOptions || {}));
  9725. $($t).triggerHandler("jqGridBeforeEditCell", [$t.rows[iRow].id, nm, tmp, iRow, iCol]);
  9726. if ($.isFunction($t.p.beforeEditCell)) {
  9727. $t.p.beforeEditCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
  9728. }
  9729. $(cc).html("").append(elc).attr("tabindex","0");
  9730. $.jgrid.bindEv.call($t, elc, opt);
  9731. window.setTimeout(function () { $(elc).focus();},0);
  9732. $("input, select, textarea",cc).bind("keydown",function(e) {
  9733. if (e.keyCode === 27) {
  9734. if($("input.hasDatepicker",cc).length >0) {
  9735. if( $(".ui-datepicker").is(":hidden") ) { $($t).jqGrid("restoreCell",iRow,iCol); }
  9736. else { $("input.hasDatepicker",cc).datepicker('hide'); }
  9737. } else {
  9738. $($t).jqGrid("restoreCell",iRow,iCol);
  9739. }
  9740. } //ESC
  9741. if (e.keyCode === 13) {
  9742. $($t).jqGrid("saveCell",iRow,iCol);
  9743. // Prevent default action
  9744. return false;
  9745. } //Enter
  9746. if (e.keyCode === 9) {
  9747. if(!$t.grid.hDiv.loading ) {
  9748. if (e.shiftKey) {$($t).jqGrid("prevCell",iRow,iCol);} //Shift TAb
  9749. else {$($t).jqGrid("nextCell",iRow,iCol);} //Tab
  9750. } else {
  9751. return false;
  9752. }
  9753. }
  9754. e.stopPropagation();
  9755. });
  9756. $($t).triggerHandler("jqGridAfterEditCell", [$t.rows[iRow].id, nm, tmp, iRow, iCol]);
  9757. if ($.isFunction($t.p.afterEditCell)) {
  9758. $t.p.afterEditCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
  9759. }
  9760. } else {
  9761. if (parseInt($t.p.iCol,10)>=0 && parseInt($t.p.iRow,10)>=0) {
  9762. $("td:eq("+$t.p.iCol+")",$t.rows[$t.p.iRow]).removeClass("edit-cell ui-state-highlight");
  9763. $($t.rows[$t.p.iRow]).removeClass("selected-row ui-state-hover");
  9764. }
  9765. cc.addClass("edit-cell ui-state-highlight");
  9766. $($t.rows[iRow]).addClass("selected-row ui-state-hover");
  9767. tmp = cc.html().replace(/\&#160\;/ig,'');
  9768. $($t).triggerHandler("jqGridSelectCell", [$t.rows[iRow].id, nm, tmp, iRow, iCol]);
  9769. if ($.isFunction($t.p.onSelectCell)) {
  9770. $t.p.onSelectCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
  9771. }
  9772. }
  9773. $t.p.iCol = iCol; $t.p.iRow = iRow;
  9774. });
  9775. },
  9776. saveCell : function (iRow, iCol){
  9777. return this.each(function(){
  9778. var $t= this, fr;
  9779. if (!$t.grid || $t.p.cellEdit !== true) {return;}
  9780. if ( $t.p.savedRow.length >= 1) {fr = 0;} else {fr=null;}
  9781. if(fr !== null) {
  9782. var cc = $("td:eq("+iCol+")",$t.rows[iRow]),v,v2,
  9783. cm = $t.p.colModel[iCol], nm = cm.name, nmjq = $.jgrid.jqID(nm) ;
  9784. switch (cm.edittype) {
  9785. case "select":
  9786. if(!cm.editoptions.multiple) {
  9787. v = $("#"+iRow+"_"+nmjq+" option:selected",$t.rows[iRow]).val();
  9788. v2 = $("#"+iRow+"_"+nmjq+" option:selected",$t.rows[iRow]).text();
  9789. } else {
  9790. var sel = $("#"+iRow+"_"+nmjq,$t.rows[iRow]), selectedText = [];
  9791. v = $(sel).val();
  9792. if(v) { v.join(",");} else { v=""; }
  9793. $("option:selected",sel).each(
  9794. function(i,selected){
  9795. selectedText[i] = $(selected).text();
  9796. }
  9797. );
  9798. v2 = selectedText.join(",");
  9799. }
  9800. if(cm.formatter) { v2 = v; }
  9801. break;
  9802. case "checkbox":
  9803. var cbv = ["Yes","No"];
  9804. if(cm.editoptions){
  9805. cbv = cm.editoptions.value.split(":");
  9806. }
  9807. v = $("#"+iRow+"_"+nmjq,$t.rows[iRow]).is(":checked") ? cbv[0] : cbv[1];
  9808. v2=v;
  9809. break;
  9810. case "password":
  9811. case "text":
  9812. case "textarea":
  9813. case "button" :
  9814. v = $("#"+iRow+"_"+nmjq,$t.rows[iRow]).val();
  9815. v2=v;
  9816. break;
  9817. case 'custom' :
  9818. try {
  9819. if(cm.editoptions && $.isFunction(cm.editoptions.custom_value)) {
  9820. v = cm.editoptions.custom_value.call($t, $(".customelement",cc),'get');
  9821. if (v===undefined) { throw "e2";} else { v2=v; }
  9822. } else { throw "e1"; }
  9823. } catch (e) {
  9824. if (e==="e1") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.nodefined,$.jgrid.edit.bClose); }
  9825. if (e==="e2") { $.jgrid.info_dialog($.jgrid.errors.errcap,"function 'custom_value' "+$.jgrid.edit.msg.novalue,$.jgrid.edit.bClose); }
  9826. else {$.jgrid.info_dialog($.jgrid.errors.errcap,e.message,$.jgrid.edit.bClose); }
  9827. }
  9828. break;
  9829. }
  9830. // The common approach is if nothing changed do not do anything
  9831. if (v2 !== $t.p.savedRow[fr].v){
  9832. var vvv = $($t).triggerHandler("jqGridBeforeSaveCell", [$t.rows[iRow].id, nm, v, iRow, iCol]);
  9833. if (vvv) {v = vvv; v2=vvv;}
  9834. if ($.isFunction($t.p.beforeSaveCell)) {
  9835. var vv = $t.p.beforeSaveCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
  9836. if (vv) {v = vv; v2=vv;}
  9837. }
  9838. var cv = $.jgrid.checkValues.call($t,v,iCol);
  9839. if(cv[0] === true) {
  9840. var addpost = $($t).triggerHandler("jqGridBeforeSubmitCell", [$t.rows[iRow].id, nm, v, iRow, iCol]) || {};
  9841. if ($.isFunction($t.p.beforeSubmitCell)) {
  9842. addpost = $t.p.beforeSubmitCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
  9843. if (!addpost) {addpost={};}
  9844. }
  9845. if( $("input.hasDatepicker",cc).length >0) { $("input.hasDatepicker",cc).datepicker('hide'); }
  9846. if ($t.p.cellsubmit === 'remote') {
  9847. if ($t.p.cellurl) {
  9848. var postdata = {};
  9849. if($t.p.autoencode) { v = $.jgrid.htmlEncode(v); }
  9850. postdata[nm] = v;
  9851. var idname,oper, opers;
  9852. opers = $t.p.prmNames;
  9853. idname = opers.id;
  9854. oper = opers.oper;
  9855. postdata[idname] = $.jgrid.stripPref($t.p.idPrefix, $t.rows[iRow].id);
  9856. postdata[oper] = opers.editoper;
  9857. postdata = $.extend(addpost,postdata);
  9858. $("#lui_"+$.jgrid.jqID($t.p.id)).show();
  9859. $t.grid.hDiv.loading = true;
  9860. $.ajax( $.extend( {
  9861. url: $t.p.cellurl,
  9862. data :$.isFunction($t.p.serializeCellData) ? $t.p.serializeCellData.call($t, postdata) : postdata,
  9863. type: "POST",
  9864. complete: function (result, stat) {
  9865. $("#lui_"+$t.p.id).hide();
  9866. $t.grid.hDiv.loading = false;
  9867. if (stat === 'success') {
  9868. var ret = $($t).triggerHandler("jqGridAfterSubmitCell", [$t, result, postdata.id, nm, v, iRow, iCol]) || [true, ''];
  9869. if (ret[0] === true && $.isFunction($t.p.afterSubmitCell)) {
  9870. ret = $t.p.afterSubmitCell.call($t, result,postdata.id,nm,v,iRow,iCol);
  9871. }
  9872. if(ret[0] === true){
  9873. $(cc).empty();
  9874. $($t).jqGrid("setCell",$t.rows[iRow].id, iCol, v2, false, false, true);
  9875. $(cc).addClass("dirty-cell");
  9876. $($t.rows[iRow]).addClass("edited");
  9877. $($t).triggerHandler("jqGridAfterSaveCell", [$t.rows[iRow].id, nm, v, iRow, iCol]);
  9878. if ($.isFunction($t.p.afterSaveCell)) {
  9879. $t.p.afterSaveCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
  9880. }
  9881. $t.p.savedRow.splice(0,1);
  9882. } else {
  9883. $.jgrid.info_dialog($.jgrid.errors.errcap,ret[1],$.jgrid.edit.bClose);
  9884. $($t).jqGrid("restoreCell",iRow,iCol);
  9885. }
  9886. }
  9887. },
  9888. error:function(res,stat,err) {
  9889. $("#lui_"+$.jgrid.jqID($t.p.id)).hide();
  9890. $t.grid.hDiv.loading = false;
  9891. $($t).triggerHandler("jqGridErrorCell", [res, stat, err]);
  9892. if ($.isFunction($t.p.errorCell)) {
  9893. $t.p.errorCell.call($t, res,stat,err);
  9894. $($t).jqGrid("restoreCell",iRow,iCol);
  9895. } else {
  9896. $.jgrid.info_dialog($.jgrid.errors.errcap,res.status+" : "+res.statusText+"<br/>"+stat,$.jgrid.edit.bClose);
  9897. $($t).jqGrid("restoreCell",iRow,iCol);
  9898. }
  9899. }
  9900. }, $.jgrid.ajaxOptions, $t.p.ajaxCellOptions || {}));
  9901. } else {
  9902. try {
  9903. $.jgrid.info_dialog($.jgrid.errors.errcap,$.jgrid.errors.nourl,$.jgrid.edit.bClose);
  9904. $($t).jqGrid("restoreCell",iRow,iCol);
  9905. } catch (e) {}
  9906. }
  9907. }
  9908. if ($t.p.cellsubmit === 'clientArray') {
  9909. $(cc).empty();
  9910. $($t).jqGrid("setCell",$t.rows[iRow].id,iCol, v2, false, false, true);
  9911. $(cc).addClass("dirty-cell");
  9912. $($t.rows[iRow]).addClass("edited");
  9913. $($t).triggerHandler("jqGridAfterSaveCell", [$t.rows[iRow].id, nm, v, iRow, iCol]);
  9914. if ($.isFunction($t.p.afterSaveCell)) {
  9915. $t.p.afterSaveCell.call($t, $t.rows[iRow].id,nm, v, iRow,iCol);
  9916. }
  9917. $t.p.savedRow.splice(0,1);
  9918. }
  9919. } else {
  9920. try {
  9921. window.setTimeout(function(){$.jgrid.info_dialog($.jgrid.errors.errcap,v+" "+cv[1],$.jgrid.edit.bClose);},100);
  9922. $($t).jqGrid("restoreCell",iRow,iCol);
  9923. } catch (e) {}
  9924. }
  9925. } else {
  9926. $($t).jqGrid("restoreCell",iRow,iCol);
  9927. }
  9928. }
  9929. window.setTimeout(function () { $("#"+$.jgrid.jqID($t.p.knv)).attr("tabindex","-1").focus();},0);
  9930. });
  9931. },
  9932. restoreCell : function(iRow, iCol) {
  9933. return this.each(function(){
  9934. var $t= this, fr;
  9935. if (!$t.grid || $t.p.cellEdit !== true ) {return;}
  9936. if ( $t.p.savedRow.length >= 1) {fr = 0;} else {fr=null;}
  9937. if(fr !== null) {
  9938. var cc = $("td:eq("+iCol+")",$t.rows[iRow]);
  9939. // datepicker fix
  9940. if($.isFunction($.fn.datepicker)) {
  9941. try {
  9942. $("input.hasDatepicker",cc).datepicker('hide');
  9943. } catch (e) {}
  9944. }
  9945. $(cc).empty().attr("tabindex","-1");
  9946. $($t).jqGrid("setCell",$t.rows[iRow].id, iCol, $t.p.savedRow[fr].v, false, false, true);
  9947. $($t).triggerHandler("jqGridAfterRestoreCell", [$t.rows[iRow].id, $t.p.savedRow[fr].v, iRow, iCol]);
  9948. if ($.isFunction($t.p.afterRestoreCell)) {
  9949. $t.p.afterRestoreCell.call($t, $t.rows[iRow].id, $t.p.savedRow[fr].v, iRow, iCol);
  9950. }
  9951. $t.p.savedRow.splice(0,1);
  9952. }
  9953. window.setTimeout(function () { $("#"+$t.p.knv).attr("tabindex","-1").focus();},0);
  9954. });
  9955. },
  9956. nextCell : function (iRow,iCol) {
  9957. return this.each(function (){
  9958. var $t = this, nCol=false, i;
  9959. if (!$t.grid || $t.p.cellEdit !== true) {return;}
  9960. // try to find next editable cell
  9961. for (i=iCol+1; i<$t.p.colModel.length; i++) {
  9962. if ( $t.p.colModel[i].editable ===true) {
  9963. nCol = i; break;
  9964. }
  9965. }
  9966. if(nCol !== false) {
  9967. $($t).jqGrid("editCell",iRow,nCol,true);
  9968. } else {
  9969. if ($t.p.savedRow.length >0) {
  9970. $($t).jqGrid("saveCell",iRow,iCol);
  9971. }
  9972. }
  9973. });
  9974. },
  9975. prevCell : function (iRow,iCol) {
  9976. return this.each(function (){
  9977. var $t = this, nCol=false, i;
  9978. if (!$t.grid || $t.p.cellEdit !== true) {return;}
  9979. // try to find next editable cell
  9980. for (i=iCol-1; i>=0; i--) {
  9981. if ( $t.p.colModel[i].editable ===true) {
  9982. nCol = i; break;
  9983. }
  9984. }
  9985. if(nCol !== false) {
  9986. $($t).jqGrid("editCell",iRow,nCol,true);
  9987. } else {
  9988. if ($t.p.savedRow.length >0) {
  9989. $($t).jqGrid("saveCell",iRow,iCol);
  9990. }
  9991. }
  9992. });
  9993. },
  9994. GridNav : function() {
  9995. return this.each(function () {
  9996. var $t = this;
  9997. if (!$t.grid || $t.p.cellEdit !== true ) {return;}
  9998. // trick to process keydown on non input elements
  9999. $t.p.knv = $t.p.id + "_kn";
  10000. 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>"),
  10001. i, kdir;
  10002. function scrollGrid(iR, iC, tp){
  10003. if (tp.substr(0,1)==='v') {
  10004. var ch = $($t.grid.bDiv)[0].clientHeight,
  10005. st = $($t.grid.bDiv)[0].scrollTop,
  10006. nROT = $t.rows[iR].offsetTop+$t.rows[iR].clientHeight,
  10007. pROT = $t.rows[iR].offsetTop;
  10008. if(tp === 'vd') {
  10009. if(nROT >= ch) {
  10010. $($t.grid.bDiv)[0].scrollTop = $($t.grid.bDiv)[0].scrollTop + $t.rows[iR].clientHeight;
  10011. }
  10012. }
  10013. if(tp === 'vu'){
  10014. if (pROT < st ) {
  10015. $($t.grid.bDiv)[0].scrollTop = $($t.grid.bDiv)[0].scrollTop - $t.rows[iR].clientHeight;
  10016. }
  10017. }
  10018. }
  10019. if(tp==='h') {
  10020. var cw = $($t.grid.bDiv)[0].clientWidth,
  10021. sl = $($t.grid.bDiv)[0].scrollLeft,
  10022. nCOL = $t.rows[iR].cells[iC].offsetLeft+$t.rows[iR].cells[iC].clientWidth,
  10023. pCOL = $t.rows[iR].cells[iC].offsetLeft;
  10024. if(nCOL >= cw+parseInt(sl,10)) {
  10025. $($t.grid.bDiv)[0].scrollLeft = $($t.grid.bDiv)[0].scrollLeft + $t.rows[iR].cells[iC].clientWidth;
  10026. } else if (pCOL < sl) {
  10027. $($t.grid.bDiv)[0].scrollLeft = $($t.grid.bDiv)[0].scrollLeft - $t.rows[iR].cells[iC].clientWidth;
  10028. }
  10029. }
  10030. }
  10031. function findNextVisible(iC,act){
  10032. var ind, i;
  10033. if(act === 'lft') {
  10034. ind = iC+1;
  10035. for (i=iC;i>=0;i--){
  10036. if ($t.p.colModel[i].hidden !== true) {
  10037. ind = i;
  10038. break;
  10039. }
  10040. }
  10041. }
  10042. if(act === 'rgt') {
  10043. ind = iC-1;
  10044. for (i=iC; i<$t.p.colModel.length;i++){
  10045. if ($t.p.colModel[i].hidden !== true) {
  10046. ind = i;
  10047. break;
  10048. }
  10049. }
  10050. }
  10051. return ind;
  10052. }
  10053. $(selection).insertBefore($t.grid.cDiv);
  10054. $("#"+$t.p.knv)
  10055. .focus()
  10056. .keydown(function (e){
  10057. kdir = e.keyCode;
  10058. if($t.p.direction === "rtl") {
  10059. if(kdir===37) { kdir = 39;}
  10060. else if (kdir===39) { kdir = 37; }
  10061. }
  10062. switch (kdir) {
  10063. case 38:
  10064. if ($t.p.iRow-1 >0 ) {
  10065. scrollGrid($t.p.iRow-1,$t.p.iCol,'vu');
  10066. $($t).jqGrid("editCell",$t.p.iRow-1,$t.p.iCol,false);
  10067. }
  10068. break;
  10069. case 40 :
  10070. if ($t.p.iRow+1 <= $t.rows.length-1) {
  10071. scrollGrid($t.p.iRow+1,$t.p.iCol,'vd');
  10072. $($t).jqGrid("editCell",$t.p.iRow+1,$t.p.iCol,false);
  10073. }
  10074. break;
  10075. case 37 :
  10076. if ($t.p.iCol -1 >= 0) {
  10077. i = findNextVisible($t.p.iCol-1,'lft');
  10078. scrollGrid($t.p.iRow, i,'h');
  10079. $($t).jqGrid("editCell",$t.p.iRow, i,false);
  10080. }
  10081. break;
  10082. case 39 :
  10083. if ($t.p.iCol +1 <= $t.p.colModel.length-1) {
  10084. i = findNextVisible($t.p.iCol+1,'rgt');
  10085. scrollGrid($t.p.iRow,i,'h');
  10086. $($t).jqGrid("editCell",$t.p.iRow,i,false);
  10087. }
  10088. break;
  10089. case 13:
  10090. if (parseInt($t.p.iCol,10)>=0 && parseInt($t.p.iRow,10)>=0) {
  10091. $($t).jqGrid("editCell",$t.p.iRow,$t.p.iCol,true);
  10092. }
  10093. break;
  10094. default :
  10095. return true;
  10096. }
  10097. return false;
  10098. });
  10099. });
  10100. },
  10101. getChangedCells : function (mthd) {
  10102. var ret=[];
  10103. if (!mthd) {mthd='all';}
  10104. this.each(function(){
  10105. var $t= this,nm;
  10106. if (!$t.grid || $t.p.cellEdit !== true ) {return;}
  10107. $($t.rows).each(function(j){
  10108. var res = {};
  10109. if ($(this).hasClass("edited")) {
  10110. $('td',this).each( function(i) {
  10111. nm = $t.p.colModel[i].name;
  10112. if ( nm !== 'cb' && nm !== 'subgrid') {
  10113. if (mthd==='dirty') {
  10114. if ($(this).hasClass('dirty-cell')) {
  10115. try {
  10116. res[nm] = $.unformat.call($t,this,{rowId:$t.rows[j].id, colModel:$t.p.colModel[i]},i);
  10117. } catch (e){
  10118. res[nm] = $.jgrid.htmlDecode($(this).html());
  10119. }
  10120. }
  10121. } else {
  10122. try {
  10123. res[nm] = $.unformat.call($t,this,{rowId:$t.rows[j].id,colModel:$t.p.colModel[i]},i);
  10124. } catch (e) {
  10125. res[nm] = $.jgrid.htmlDecode($(this).html());
  10126. }
  10127. }
  10128. }
  10129. });
  10130. res.id = this.id;
  10131. ret.push(res);
  10132. }
  10133. });
  10134. });
  10135. return ret;
  10136. }
  10137. /// end cell editing
  10138. });
  10139. })(jQuery);
  10140. /*jshint eqeqeq:false */
  10141. /*global jQuery */
  10142. (function($){
  10143. /**
  10144. * jqGrid extension for SubGrid Data
  10145. * Tony Tomov tony@trirand.com
  10146. * http://trirand.com/blog/
  10147. * Dual licensed under the MIT and GPL licenses:
  10148. * http://www.opensource.org/licenses/mit-license.php
  10149. * http://www.gnu.org/licenses/gpl-2.0.html
  10150. **/
  10151. "use strict";
  10152. $.jgrid.extend({
  10153. setSubGrid : function () {
  10154. return this.each(function (){
  10155. var $t = this, cm, i,
  10156. suboptions = {
  10157. plusicon : "ui-icon-plus",
  10158. minusicon : "ui-icon-minus",
  10159. openicon: "ui-icon-carat-1-sw",
  10160. expandOnLoad: false,
  10161. delayOnLoad : 50,
  10162. selectOnExpand : false,
  10163. reloadOnExpand : true
  10164. };
  10165. $t.p.subGridOptions = $.extend(suboptions, $t.p.subGridOptions || {});
  10166. $t.p.colNames.unshift("");
  10167. $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});
  10168. cm = $t.p.subGridModel;
  10169. if(cm[0]) {
  10170. cm[0].align = $.extend([],cm[0].align || []);
  10171. for(i=0;i<cm[0].name.length;i++) { cm[0].align[i] = cm[0].align[i] || 'left';}
  10172. }
  10173. });
  10174. },
  10175. addSubGridCell :function (pos,iRow) {
  10176. var prp='',ic,sid;
  10177. this.each(function(){
  10178. prp = this.formatCol(pos,iRow);
  10179. sid= this.p.id;
  10180. ic = this.p.subGridOptions.plusicon;
  10181. });
  10182. return "<td role=\"gridcell\" aria-describedby=\""+sid+"_subgrid\" class=\"ui-sgcollapsed sgcollapsed\" "+prp+"><a href='javascript:void(0);'><span class='ui-icon "+ic+"'></span></a></td>";
  10183. },
  10184. addSubGrid : function( pos, sind ) {
  10185. return this.each(function(){
  10186. var ts = this;
  10187. if (!ts.grid ) { return; }
  10188. //-------------------------
  10189. var subGridCell = function(trdiv,cell,pos)
  10190. {
  10191. var tddiv = $("<td align='"+ts.p.subGridModel[0].align[pos]+"'></td>").html(cell);
  10192. $(trdiv).append(tddiv);
  10193. };
  10194. var subGridXml = function(sjxml, sbid){
  10195. var tddiv, i, sgmap,
  10196. dummy = $("<table cellspacing='0' cellpadding='0' border='0'><tbody></tbody></table>"),
  10197. trdiv = $("<tr></tr>");
  10198. for (i = 0; i<ts.p.subGridModel[0].name.length; i++) {
  10199. tddiv = $("<th class='ui-state-default ui-th-subgrid ui-th-column ui-th-"+ts.p.direction+"'></th>");
  10200. $(tddiv).html(ts.p.subGridModel[0].name[i]);
  10201. $(tddiv).width( ts.p.subGridModel[0].width[i]);
  10202. $(trdiv).append(tddiv);
  10203. }
  10204. $(dummy).append(trdiv);
  10205. if (sjxml){
  10206. sgmap = ts.p.xmlReader.subgrid;
  10207. $(sgmap.root+" "+sgmap.row, sjxml).each( function(){
  10208. trdiv = $("<tr class='ui-widget-content ui-subtblcell'></tr>");
  10209. if(sgmap.repeatitems === true) {
  10210. $(sgmap.cell,this).each( function(i) {
  10211. subGridCell(trdiv, $(this).text() || '&#160;',i);
  10212. });
  10213. } else {
  10214. var f = ts.p.subGridModel[0].mapping || ts.p.subGridModel[0].name;
  10215. if (f) {
  10216. for (i=0;i<f.length;i++) {
  10217. subGridCell(trdiv, $(f[i],this).text() || '&#160;',i);
  10218. }
  10219. }
  10220. }
  10221. $(dummy).append(trdiv);
  10222. });
  10223. }
  10224. var pID = $("table:first",ts.grid.bDiv).attr("id")+"_";
  10225. $("#"+$.jgrid.jqID(pID+sbid)).append(dummy);
  10226. ts.grid.hDiv.loading = false;
  10227. $("#load_"+$.jgrid.jqID(ts.p.id)).hide();
  10228. return false;
  10229. };
  10230. var subGridJson = function(sjxml, sbid){
  10231. var tddiv,result,i,cur, sgmap,j,
  10232. dummy = $("<table cellspacing='0' cellpadding='0' border='0'><tbody></tbody></table>"),
  10233. trdiv = $("<tr></tr>");
  10234. for (i = 0; i<ts.p.subGridModel[0].name.length; i++) {
  10235. tddiv = $("<th class='ui-state-default ui-th-subgrid ui-th-column ui-th-"+ts.p.direction+"'></th>");
  10236. $(tddiv).html(ts.p.subGridModel[0].name[i]);
  10237. $(tddiv).width( ts.p.subGridModel[0].width[i]);
  10238. $(trdiv).append(tddiv);
  10239. }
  10240. $(dummy).append(trdiv);
  10241. if (sjxml){
  10242. sgmap = ts.p.jsonReader.subgrid;
  10243. result = $.jgrid.getAccessor(sjxml, sgmap.root);
  10244. if ( result !== undefined ) {
  10245. for (i=0;i<result.length;i++) {
  10246. cur = result[i];
  10247. trdiv = $("<tr class='ui-widget-content ui-subtblcell'></tr>");
  10248. if(sgmap.repeatitems === true) {
  10249. if(sgmap.cell) { cur=cur[sgmap.cell]; }
  10250. for (j=0;j<cur.length;j++) {
  10251. subGridCell(trdiv, cur[j] || '&#160;',j);
  10252. }
  10253. } else {
  10254. var f = ts.p.subGridModel[0].mapping || ts.p.subGridModel[0].name;
  10255. if(f.length) {
  10256. for (j=0;j<f.length;j++) {
  10257. subGridCell(trdiv, cur[f[j]] || '&#160;',j);
  10258. }
  10259. }
  10260. }
  10261. $(dummy).append(trdiv);
  10262. }
  10263. }
  10264. }
  10265. var pID = $("table:first",ts.grid.bDiv).attr("id")+"_";
  10266. $("#"+$.jgrid.jqID(pID+sbid)).append(dummy);
  10267. ts.grid.hDiv.loading = false;
  10268. $("#load_"+$.jgrid.jqID(ts.p.id)).hide();
  10269. return false;
  10270. };
  10271. var populatesubgrid = function( rd )
  10272. {
  10273. var sid,dp, i, j;
  10274. sid = $(rd).attr("id");
  10275. dp = {nd_: (new Date().getTime())};
  10276. dp[ts.p.prmNames.subgridid]=sid;
  10277. if(!ts.p.subGridModel[0]) { return false; }
  10278. if(ts.p.subGridModel[0].params) {
  10279. for(j=0; j < ts.p.subGridModel[0].params.length; j++) {
  10280. for(i=0; i<ts.p.colModel.length; i++) {
  10281. if(ts.p.colModel[i].name === ts.p.subGridModel[0].params[j]) {
  10282. dp[ts.p.colModel[i].name]= $("td:eq("+i+")",rd).text().replace(/\&#160\;/ig,'');
  10283. }
  10284. }
  10285. }
  10286. }
  10287. if(!ts.grid.hDiv.loading) {
  10288. ts.grid.hDiv.loading = true;
  10289. $("#load_"+$.jgrid.jqID(ts.p.id)).show();
  10290. if(!ts.p.subgridtype) { ts.p.subgridtype = ts.p.datatype; }
  10291. if($.isFunction(ts.p.subgridtype)) {
  10292. ts.p.subgridtype.call(ts, dp);
  10293. } else {
  10294. ts.p.subgridtype = ts.p.subgridtype.toLowerCase();
  10295. }
  10296. switch(ts.p.subgridtype) {
  10297. case "xml":
  10298. case "json":
  10299. $.ajax($.extend({
  10300. type:ts.p.mtype,
  10301. url: ts.p.subGridUrl,
  10302. dataType:ts.p.subgridtype,
  10303. data: $.isFunction(ts.p.serializeSubGridData)? ts.p.serializeSubGridData.call(ts, dp) : dp,
  10304. complete: function(sxml) {
  10305. if(ts.p.subgridtype === "xml") {
  10306. subGridXml(sxml.responseXML, sid);
  10307. } else {
  10308. subGridJson($.jgrid.parse(sxml.responseText),sid);
  10309. }
  10310. sxml=null;
  10311. }
  10312. }, $.jgrid.ajaxOptions, ts.p.ajaxSubgridOptions || {}));
  10313. break;
  10314. }
  10315. }
  10316. return false;
  10317. };
  10318. var _id, pID,atd, nhc=0, bfsc, r;
  10319. $.each(ts.p.colModel,function(){
  10320. if(this.hidden === true || this.name === 'rn' || this.name === 'cb') {
  10321. nhc++;
  10322. }
  10323. });
  10324. var len = ts.rows.length, i=1;
  10325. if( sind !== undefined && sind > 0) {
  10326. i = sind;
  10327. len = sind+1;
  10328. }
  10329. while(i < len) {
  10330. if($(ts.rows[i]).hasClass('jqgrow')) {
  10331. $(ts.rows[i].cells[pos]).bind('click', function() {
  10332. var tr = $(this).parent("tr")[0];
  10333. r = tr.nextSibling;
  10334. if($(this).hasClass("sgcollapsed")) {
  10335. pID = ts.p.id;
  10336. _id = tr.id;
  10337. if(ts.p.subGridOptions.reloadOnExpand === true || ( ts.p.subGridOptions.reloadOnExpand === false && !$(r).hasClass('ui-subgrid') ) ) {
  10338. atd = pos >=1 ? "<td colspan='"+pos+"'>&#160;</td>":"";
  10339. bfsc = $(ts).triggerHandler("jqGridSubGridBeforeExpand", [pID + "_" + _id, _id]);
  10340. bfsc = (bfsc === false || bfsc === 'stop') ? false : true;
  10341. if(bfsc && $.isFunction(ts.p.subGridBeforeExpand)) {
  10342. bfsc = ts.p.subGridBeforeExpand.call(ts, pID+"_"+_id,_id);
  10343. }
  10344. if(bfsc === false) {return false;}
  10345. $(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>" );
  10346. $(ts).triggerHandler("jqGridSubGridRowExpanded", [pID + "_" + _id, _id]);
  10347. if( $.isFunction(ts.p.subGridRowExpanded)) {
  10348. ts.p.subGridRowExpanded.call(ts, pID+"_"+ _id,_id);
  10349. } else {
  10350. populatesubgrid(tr);
  10351. }
  10352. } else {
  10353. $(r).show();
  10354. }
  10355. $(this).html("<a href='javascript:void(0);'><span class='ui-icon "+ts.p.subGridOptions.minusicon+"'></span></a>").removeClass("sgcollapsed").addClass("sgexpanded");
  10356. if(ts.p.subGridOptions.selectOnExpand) {
  10357. $(ts).jqGrid('setSelection',_id);
  10358. }
  10359. } else if($(this).hasClass("sgexpanded")) {
  10360. bfsc = $(ts).triggerHandler("jqGridSubGridRowColapsed", [pID + "_" + _id, _id]);
  10361. bfsc = (bfsc === false || bfsc === 'stop') ? false : true;
  10362. if( bfsc && $.isFunction(ts.p.subGridRowColapsed)) {
  10363. _id = tr.id;
  10364. bfsc = ts.p.subGridRowColapsed.call(ts, pID+"_"+_id,_id );
  10365. }
  10366. if(bfsc===false) {return false;}
  10367. if(ts.p.subGridOptions.reloadOnExpand === true) {
  10368. $(r).remove(".ui-subgrid");
  10369. } else if($(r).hasClass('ui-subgrid')) { // incase of dynamic deleting
  10370. $(r).hide();
  10371. }
  10372. $(this).html("<a href='javascript:void(0);'><span class='ui-icon "+ts.p.subGridOptions.plusicon+"'></span></a>").removeClass("sgexpanded").addClass("sgcollapsed");
  10373. }
  10374. return false;
  10375. });
  10376. }
  10377. i++;
  10378. }
  10379. if(ts.p.subGridOptions.expandOnLoad === true) {
  10380. $(ts.rows).filter('.jqgrow').each(function(index,row){
  10381. $(row.cells[0]).click();
  10382. });
  10383. }
  10384. ts.subGridXml = function(xml,sid) {subGridXml(xml,sid);};
  10385. ts.subGridJson = function(json,sid) {subGridJson(json,sid);};
  10386. });
  10387. },
  10388. expandSubGridRow : function(rowid) {
  10389. return this.each(function () {
  10390. var $t = this;
  10391. if(!$t.grid && !rowid) {return;}
  10392. if($t.p.subGrid===true) {
  10393. var rc = $(this).jqGrid("getInd",rowid,true);
  10394. if(rc) {
  10395. var sgc = $("td.sgcollapsed",rc)[0];
  10396. if(sgc) {
  10397. $(sgc).trigger("click");
  10398. }
  10399. }
  10400. }
  10401. });
  10402. },
  10403. collapseSubGridRow : function(rowid) {
  10404. return this.each(function () {
  10405. var $t = this;
  10406. if(!$t.grid && !rowid) {return;}
  10407. if($t.p.subGrid===true) {
  10408. var rc = $(this).jqGrid("getInd",rowid,true);
  10409. if(rc) {
  10410. var sgc = $("td.sgexpanded",rc)[0];
  10411. if(sgc) {
  10412. $(sgc).trigger("click");
  10413. }
  10414. }
  10415. }
  10416. });
  10417. },
  10418. toggleSubGridRow : function(rowid) {
  10419. return this.each(function () {
  10420. var $t = this;
  10421. if(!$t.grid && !rowid) {return;}
  10422. if($t.p.subGrid===true) {
  10423. var rc = $(this).jqGrid("getInd",rowid,true);
  10424. if(rc) {
  10425. var sgc = $("td.sgcollapsed",rc)[0];
  10426. if(sgc) {
  10427. $(sgc).trigger("click");
  10428. } else {
  10429. sgc = $("td.sgexpanded",rc)[0];
  10430. if(sgc) {
  10431. $(sgc).trigger("click");
  10432. }
  10433. }
  10434. }
  10435. }
  10436. });
  10437. }
  10438. });
  10439. })(jQuery);
  10440. /**
  10441. * jqGrid extension - Tree Grid
  10442. * Tony Tomov tony@trirand.com
  10443. * http://trirand.com/blog/
  10444. * Dual licensed under the MIT and GPL licenses:
  10445. * http://www.opensource.org/licenses/mit-license.php
  10446. * http://www.gnu.org/licenses/gpl.html
  10447. **/
  10448. /*jshint eqeqeq:false */
  10449. /*global jQuery */
  10450. (function($) {
  10451. "use strict";
  10452. $.jgrid.extend({
  10453. setTreeNode : function(i, len){
  10454. return this.each(function(){
  10455. var $t = this;
  10456. if( !$t.grid || !$t.p.treeGrid ) {return;}
  10457. var expCol = $t.p.expColInd,
  10458. expanded = $t.p.treeReader.expanded_field,
  10459. isLeaf = $t.p.treeReader.leaf_field,
  10460. level = $t.p.treeReader.level_field,
  10461. icon = $t.p.treeReader.icon_field,
  10462. loaded = $t.p.treeReader.loaded, lft, rgt, curLevel, ident,lftpos, twrap,
  10463. ldat, lf;
  10464. while(i<len) {
  10465. var ind = $.jgrid.stripPref($t.p.idPrefix, $t.rows[i].id), dind = $t.p._index[ind], expan;
  10466. ldat = $t.p.data[dind];
  10467. //$t.rows[i].level = ldat[level];
  10468. if($t.p.treeGridModel === 'nested') {
  10469. if(!ldat[isLeaf]) {
  10470. lft = parseInt(ldat[$t.p.treeReader.left_field],10);
  10471. rgt = parseInt(ldat[$t.p.treeReader.right_field],10);
  10472. // NS Model
  10473. ldat[isLeaf] = (rgt === lft+1) ? 'true' : 'false';
  10474. $t.rows[i].cells[$t.p._treeleafpos].innerHTML = ldat[isLeaf];
  10475. }
  10476. }
  10477. //else {
  10478. //row.parent_id = rd[$t.p.treeReader.parent_id_field];
  10479. //}
  10480. curLevel = parseInt(ldat[level],10);
  10481. if($t.p.tree_root_level === 0) {
  10482. ident = curLevel+1;
  10483. lftpos = curLevel;
  10484. } else {
  10485. ident = curLevel;
  10486. lftpos = curLevel -1;
  10487. }
  10488. twrap = "<div class='tree-wrap tree-wrap-"+$t.p.direction+"' style='width:"+(ident*18)+"px;'>";
  10489. twrap += "<div style='"+($t.p.direction==="rtl" ? "right:" : "left:")+(lftpos*18)+"px;' class='ui-icon ";
  10490. if(ldat[loaded] !== undefined) {
  10491. if(ldat[loaded]==="true" || ldat[loaded]===true) {
  10492. ldat[loaded] = true;
  10493. } else {
  10494. ldat[loaded] = false;
  10495. }
  10496. }
  10497. if(ldat[isLeaf] === "true" || ldat[isLeaf] === true) {
  10498. twrap += ((ldat[icon] !== undefined && ldat[icon] !== "") ? ldat[icon] : $t.p.treeIcons.leaf)+" tree-leaf treeclick";
  10499. ldat[isLeaf] = true;
  10500. lf="leaf";
  10501. } else {
  10502. ldat[isLeaf] = false;
  10503. lf="";
  10504. }
  10505. ldat[expanded] = ((ldat[expanded] === "true" || ldat[expanded] === true) ? true : false) && (ldat[loaded] || ldat[loaded] === undefined);
  10506. if(ldat[expanded] === false) {
  10507. twrap += ((ldat[isLeaf] === true) ? "'" : $t.p.treeIcons.plus+" tree-plus treeclick'");
  10508. } else {
  10509. twrap += ((ldat[isLeaf] === true) ? "'" : $t.p.treeIcons.minus+" tree-minus treeclick'");
  10510. }
  10511. twrap += "></div></div>";
  10512. $($t.rows[i].cells[expCol]).wrapInner("<span class='cell-wrapper"+lf+"'></span>").prepend(twrap);
  10513. if(curLevel !== parseInt($t.p.tree_root_level,10)) {
  10514. var pn = $($t).jqGrid('getNodeParent',ldat);
  10515. expan = pn && pn.hasOwnProperty(expanded) ? pn[expanded] : true;
  10516. if( !expan ){
  10517. $($t.rows[i]).css("display","none");
  10518. }
  10519. }
  10520. $($t.rows[i].cells[expCol])
  10521. .find("div.treeclick")
  10522. .bind("click",function(e){
  10523. var target = e.target || e.srcElement,
  10524. ind2 =$.jgrid.stripPref($t.p.idPrefix,$(target,$t.rows).closest("tr.jqgrow")[0].id),
  10525. pos = $t.p._index[ind2];
  10526. if(!$t.p.data[pos][isLeaf]){
  10527. if($t.p.data[pos][expanded]){
  10528. $($t).jqGrid("collapseRow",$t.p.data[pos]);
  10529. $($t).jqGrid("collapseNode",$t.p.data[pos]);
  10530. } else {
  10531. $($t).jqGrid("expandRow",$t.p.data[pos]);
  10532. $($t).jqGrid("expandNode",$t.p.data[pos]);
  10533. }
  10534. }
  10535. return false;
  10536. });
  10537. if($t.p.ExpandColClick === true) {
  10538. $($t.rows[i].cells[expCol])
  10539. .find("span.cell-wrapper")
  10540. .css("cursor","pointer")
  10541. .bind("click",function(e) {
  10542. var target = e.target || e.srcElement,
  10543. ind2 =$.jgrid.stripPref($t.p.idPrefix,$(target,$t.rows).closest("tr.jqgrow")[0].id),
  10544. pos = $t.p._index[ind2];
  10545. if(!$t.p.data[pos][isLeaf]){
  10546. if($t.p.data[pos][expanded]){
  10547. $($t).jqGrid("collapseRow",$t.p.data[pos]);
  10548. $($t).jqGrid("collapseNode",$t.p.data[pos]);
  10549. } else {
  10550. $($t).jqGrid("expandRow",$t.p.data[pos]);
  10551. $($t).jqGrid("expandNode",$t.p.data[pos]);
  10552. }
  10553. }
  10554. $($t).jqGrid("setSelection",ind2);
  10555. return false;
  10556. });
  10557. }
  10558. i++;
  10559. }
  10560. });
  10561. },
  10562. setTreeGrid : function() {
  10563. return this.each(function (){
  10564. var $t = this, i=0, pico, ecol = false, nm, key, tkey, dupcols=[];
  10565. if(!$t.p.treeGrid) {return;}
  10566. if(!$t.p.treedatatype ) {$.extend($t.p,{treedatatype: $t.p.datatype});}
  10567. $t.p.subGrid = false;$t.p.altRows =false;
  10568. $t.p.pgbuttons = false;$t.p.pginput = false;
  10569. $t.p.gridview = true;
  10570. if($t.p.rowTotal === null ) { $t.p.rowNum = 10000; }
  10571. $t.p.multiselect = false;$t.p.rowList = [];
  10572. $t.p.expColInd = 0;
  10573. pico = 'ui-icon-triangle-1-' + ($t.p.direction==="rtl" ? 'w' : 'e');
  10574. $t.p.treeIcons = $.extend({plus:pico,minus:'ui-icon-triangle-1-s',leaf:'ui-icon-radio-off'},$t.p.treeIcons || {});
  10575. if($t.p.treeGridModel === 'nested') {
  10576. $t.p.treeReader = $.extend({
  10577. level_field: "level",
  10578. left_field:"lft",
  10579. right_field: "rgt",
  10580. leaf_field: "isLeaf",
  10581. expanded_field: "expanded",
  10582. loaded: "loaded",
  10583. icon_field: "icon"
  10584. },$t.p.treeReader);
  10585. } else if($t.p.treeGridModel === 'adjacency') {
  10586. $t.p.treeReader = $.extend({
  10587. level_field: "level",
  10588. parent_id_field: "parent",
  10589. leaf_field: "isLeaf",
  10590. expanded_field: "expanded",
  10591. loaded: "loaded",
  10592. icon_field: "icon"
  10593. },$t.p.treeReader );
  10594. }
  10595. for ( key in $t.p.colModel){
  10596. if($t.p.colModel.hasOwnProperty(key)) {
  10597. nm = $t.p.colModel[key].name;
  10598. if( nm === $t.p.ExpandColumn && !ecol ) {
  10599. ecol = true;
  10600. $t.p.expColInd = i;
  10601. }
  10602. i++;
  10603. //
  10604. for(tkey in $t.p.treeReader) {
  10605. if($t.p.treeReader.hasOwnProperty(tkey) && $t.p.treeReader[tkey] === nm) {
  10606. dupcols.push(nm);
  10607. }
  10608. }
  10609. }
  10610. }
  10611. $.each($t.p.treeReader,function(j,n){
  10612. if(n && $.inArray(n, dupcols) === -1){
  10613. if(j==='leaf_field') { $t.p._treeleafpos= i; }
  10614. i++;
  10615. $t.p.colNames.push(n);
  10616. $t.p.colModel.push({name:n,width:1,hidden:true,sortable:false,resizable:false,hidedlg:true,editable:true,search:false});
  10617. }
  10618. });
  10619. });
  10620. },
  10621. expandRow: function (record){
  10622. this.each(function(){
  10623. var $t = this;
  10624. if(!$t.grid || !$t.p.treeGrid) {return;}
  10625. var childern = $($t).jqGrid("getNodeChildren",record),
  10626. //if ($($t).jqGrid("isVisibleNode",record)) {
  10627. expanded = $t.p.treeReader.expanded_field,
  10628. rows = $t.rows;
  10629. $(childern).each(function(){
  10630. var id = $t.p.idPrefix + $.jgrid.getAccessor(this,$t.p.localReader.id);
  10631. $(rows.namedItem(id)).css("display","");
  10632. if(this[expanded]) {
  10633. $($t).jqGrid("expandRow",this);
  10634. }
  10635. });
  10636. //}
  10637. });
  10638. },
  10639. collapseRow : function (record) {
  10640. this.each(function(){
  10641. var $t = this;
  10642. if(!$t.grid || !$t.p.treeGrid) {return;}
  10643. var childern = $($t).jqGrid("getNodeChildren",record),
  10644. expanded = $t.p.treeReader.expanded_field,
  10645. rows = $t.rows;
  10646. $(childern).each(function(){
  10647. var id = $t.p.idPrefix + $.jgrid.getAccessor(this,$t.p.localReader.id);
  10648. $(rows.namedItem(id)).css("display","none");
  10649. if(this[expanded]){
  10650. $($t).jqGrid("collapseRow",this);
  10651. }
  10652. });
  10653. });
  10654. },
  10655. // NS ,adjacency models
  10656. getRootNodes : function() {
  10657. var result = [];
  10658. this.each(function(){
  10659. var $t = this;
  10660. if(!$t.grid || !$t.p.treeGrid) {return;}
  10661. switch ($t.p.treeGridModel) {
  10662. case 'nested' :
  10663. var level = $t.p.treeReader.level_field;
  10664. $($t.p.data).each(function(){
  10665. if(parseInt(this[level],10) === parseInt($t.p.tree_root_level,10)) {
  10666. result.push(this);
  10667. }
  10668. });
  10669. break;
  10670. case 'adjacency' :
  10671. var parent_id = $t.p.treeReader.parent_id_field;
  10672. $($t.p.data).each(function(){
  10673. if(this[parent_id] === null || String(this[parent_id]).toLowerCase() === "null") {
  10674. result.push(this);
  10675. }
  10676. });
  10677. break;
  10678. }
  10679. });
  10680. return result;
  10681. },
  10682. getNodeDepth : function(rc) {
  10683. var ret = null;
  10684. this.each(function(){
  10685. if(!this.grid || !this.p.treeGrid) {return;}
  10686. var $t = this;
  10687. switch ($t.p.treeGridModel) {
  10688. case 'nested' :
  10689. var level = $t.p.treeReader.level_field;
  10690. ret = parseInt(rc[level],10) - parseInt($t.p.tree_root_level,10);
  10691. break;
  10692. case 'adjacency' :
  10693. ret = $($t).jqGrid("getNodeAncestors",rc).length;
  10694. break;
  10695. }
  10696. });
  10697. return ret;
  10698. },
  10699. getNodeParent : function(rc) {
  10700. var result = null;
  10701. this.each(function(){
  10702. var $t = this;
  10703. if(!$t.grid || !$t.p.treeGrid) {return;}
  10704. switch ($t.p.treeGridModel) {
  10705. case 'nested' :
  10706. var lftc = $t.p.treeReader.left_field,
  10707. rgtc = $t.p.treeReader.right_field,
  10708. levelc = $t.p.treeReader.level_field,
  10709. lft = parseInt(rc[lftc],10), rgt = parseInt(rc[rgtc],10), level = parseInt(rc[levelc],10);
  10710. $(this.p.data).each(function(){
  10711. if(parseInt(this[levelc],10) === level-1 && parseInt(this[lftc],10) < lft && parseInt(this[rgtc],10) > rgt) {
  10712. result = this;
  10713. return false;
  10714. }
  10715. });
  10716. break;
  10717. case 'adjacency' :
  10718. var parent_id = $t.p.treeReader.parent_id_field,
  10719. dtid = $t.p.localReader.id;
  10720. $(this.p.data).each(function(){
  10721. if(this[dtid] === $.jgrid.stripPref($t.p.idPrefix, rc[parent_id]) ) {
  10722. result = this;
  10723. return false;
  10724. }
  10725. });
  10726. break;
  10727. }
  10728. });
  10729. return result;
  10730. },
  10731. getNodeChildren : function(rc) {
  10732. var result = [];
  10733. this.each(function(){
  10734. var $t = this;
  10735. if(!$t.grid || !$t.p.treeGrid) {return;}
  10736. switch ($t.p.treeGridModel) {
  10737. case 'nested' :
  10738. var lftc = $t.p.treeReader.left_field,
  10739. rgtc = $t.p.treeReader.right_field,
  10740. levelc = $t.p.treeReader.level_field,
  10741. lft = parseInt(rc[lftc],10), rgt = parseInt(rc[rgtc],10), level = parseInt(rc[levelc],10);
  10742. $(this.p.data).each(function(){
  10743. if(parseInt(this[levelc],10) === level+1 && parseInt(this[lftc],10) > lft && parseInt(this[rgtc],10) < rgt) {
  10744. result.push(this);
  10745. }
  10746. });
  10747. break;
  10748. case 'adjacency' :
  10749. var parent_id = $t.p.treeReader.parent_id_field,
  10750. dtid = $t.p.localReader.id;
  10751. $(this.p.data).each(function(){
  10752. if(this[parent_id] == $.jgrid.stripPref($t.p.idPrefix, rc[dtid])) {
  10753. result.push(this);
  10754. }
  10755. });
  10756. break;
  10757. }
  10758. });
  10759. return result;
  10760. },
  10761. getFullTreeNode : function(rc) {
  10762. var result = [];
  10763. this.each(function(){
  10764. var $t = this, len;
  10765. if(!$t.grid || !$t.p.treeGrid) {return;}
  10766. switch ($t.p.treeGridModel) {
  10767. case 'nested' :
  10768. var lftc = $t.p.treeReader.left_field,
  10769. rgtc = $t.p.treeReader.right_field,
  10770. levelc = $t.p.treeReader.level_field,
  10771. lft = parseInt(rc[lftc],10), rgt = parseInt(rc[rgtc],10), level = parseInt(rc[levelc],10);
  10772. $(this.p.data).each(function(){
  10773. if(parseInt(this[levelc],10) >= level && parseInt(this[lftc],10) >= lft && parseInt(this[lftc],10) <= rgt) {
  10774. result.push(this);
  10775. }
  10776. });
  10777. break;
  10778. case 'adjacency' :
  10779. if(rc) {
  10780. result.push(rc);
  10781. var parent_id = $t.p.treeReader.parent_id_field,
  10782. dtid = $t.p.localReader.id;
  10783. $(this.p.data).each(function(i){
  10784. len = result.length;
  10785. for (i = 0; i < len; i++) {
  10786. if ($.jgrid.stripPref($t.p.idPrefix, result[i][dtid]) === this[parent_id]) {
  10787. result.push(this);
  10788. break;
  10789. }
  10790. }
  10791. });
  10792. }
  10793. break;
  10794. }
  10795. });
  10796. return result;
  10797. },
  10798. // End NS, adjacency Model
  10799. getNodeAncestors : function(rc) {
  10800. var ancestors = [];
  10801. this.each(function(){
  10802. if(!this.grid || !this.p.treeGrid) {return;}
  10803. var parent = $(this).jqGrid("getNodeParent",rc);
  10804. while (parent) {
  10805. ancestors.push(parent);
  10806. parent = $(this).jqGrid("getNodeParent",parent);
  10807. }
  10808. });
  10809. return ancestors;
  10810. },
  10811. isVisibleNode : function(rc) {
  10812. var result = true;
  10813. this.each(function(){
  10814. var $t = this;
  10815. if(!$t.grid || !$t.p.treeGrid) {return;}
  10816. var ancestors = $($t).jqGrid("getNodeAncestors",rc),
  10817. expanded = $t.p.treeReader.expanded_field;
  10818. $(ancestors).each(function(){
  10819. result = result && this[expanded];
  10820. if(!result) {return false;}
  10821. });
  10822. });
  10823. return result;
  10824. },
  10825. isNodeLoaded : function(rc) {
  10826. var result;
  10827. this.each(function(){
  10828. var $t = this;
  10829. if(!$t.grid || !$t.p.treeGrid) {return;}
  10830. var isLeaf = $t.p.treeReader.leaf_field;
  10831. if(rc !== undefined ) {
  10832. if(rc.loaded !== undefined) {
  10833. result = rc.loaded;
  10834. } else if( rc[isLeaf] || $($t).jqGrid("getNodeChildren",rc).length > 0){
  10835. result = true;
  10836. } else {
  10837. result = false;
  10838. }
  10839. } else {
  10840. result = false;
  10841. }
  10842. });
  10843. return result;
  10844. },
  10845. expandNode : function(rc) {
  10846. return this.each(function(){
  10847. if(!this.grid || !this.p.treeGrid) {return;}
  10848. var expanded = this.p.treeReader.expanded_field,
  10849. parent = this.p.treeReader.parent_id_field,
  10850. loaded = this.p.treeReader.loaded,
  10851. level = this.p.treeReader.level_field,
  10852. lft = this.p.treeReader.left_field,
  10853. rgt = this.p.treeReader.right_field;
  10854. if(!rc[expanded]) {
  10855. var id = $.jgrid.getAccessor(rc,this.p.localReader.id);
  10856. var rc1 = $("#" + this.p.idPrefix + $.jgrid.jqID(id),this.grid.bDiv)[0];
  10857. var position = this.p._index[id];
  10858. if( $(this).jqGrid("isNodeLoaded",this.p.data[position]) ) {
  10859. rc[expanded] = true;
  10860. $("div.treeclick",rc1).removeClass(this.p.treeIcons.plus+" tree-plus").addClass(this.p.treeIcons.minus+" tree-minus");
  10861. } else if (!this.grid.hDiv.loading) {
  10862. rc[expanded] = true;
  10863. $("div.treeclick",rc1).removeClass(this.p.treeIcons.plus+" tree-plus").addClass(this.p.treeIcons.minus+" tree-minus");
  10864. this.p.treeANode = rc1.rowIndex;
  10865. this.p.datatype = this.p.treedatatype;
  10866. if(this.p.treeGridModel === 'nested') {
  10867. $(this).jqGrid("setGridParam",{postData:{nodeid:id,n_left:rc[lft],n_right:rc[rgt],n_level:rc[level]}});
  10868. } else {
  10869. $(this).jqGrid("setGridParam",{postData:{nodeid:id,parentid:rc[parent],n_level:rc[level]}} );
  10870. }
  10871. $(this).trigger("reloadGrid");
  10872. rc[loaded] = true;
  10873. if(this.p.treeGridModel === 'nested') {
  10874. $(this).jqGrid("setGridParam",{postData:{nodeid:'',n_left:'',n_right:'',n_level:''}});
  10875. } else {
  10876. $(this).jqGrid("setGridParam",{postData:{nodeid:'',parentid:'',n_level:''}});
  10877. }
  10878. }
  10879. }
  10880. });
  10881. },
  10882. collapseNode : function(rc) {
  10883. return this.each(function(){
  10884. if(!this.grid || !this.p.treeGrid) {return;}
  10885. var expanded = this.p.treeReader.expanded_field;
  10886. if(rc[expanded]) {
  10887. rc[expanded] = false;
  10888. var id = $.jgrid.getAccessor(rc,this.p.localReader.id);
  10889. var rc1 = $("#" + this.p.idPrefix + $.jgrid.jqID(id),this.grid.bDiv)[0];
  10890. $("div.treeclick",rc1).removeClass(this.p.treeIcons.minus+" tree-minus").addClass(this.p.treeIcons.plus+" tree-plus");
  10891. }
  10892. });
  10893. },
  10894. SortTree : function( sortname, newDir, st, datefmt) {
  10895. return this.each(function(){
  10896. if(!this.grid || !this.p.treeGrid) {return;}
  10897. var i, len,
  10898. rec, records = [], $t = this, query, roots,
  10899. rt = $(this).jqGrid("getRootNodes");
  10900. // Sorting roots
  10901. query = $.jgrid.from(rt);
  10902. query.orderBy(sortname,newDir,st, datefmt);
  10903. roots = query.select();
  10904. // Sorting children
  10905. for (i = 0, len = roots.length; i < len; i++) {
  10906. rec = roots[i];
  10907. records.push(rec);
  10908. $(this).jqGrid("collectChildrenSortTree",records, rec, sortname, newDir,st, datefmt);
  10909. }
  10910. $.each(records, function(index) {
  10911. var id = $.jgrid.getAccessor(this,$t.p.localReader.id);
  10912. $('#'+$.jgrid.jqID($t.p.id)+ ' tbody tr:eq('+index+')').after($('tr#'+$.jgrid.jqID(id),$t.grid.bDiv));
  10913. });
  10914. query = null;roots=null;records=null;
  10915. });
  10916. },
  10917. collectChildrenSortTree : function(records, rec, sortname, newDir,st, datefmt) {
  10918. return this.each(function(){
  10919. if(!this.grid || !this.p.treeGrid) {return;}
  10920. var i, len,
  10921. child, ch, query, children;
  10922. ch = $(this).jqGrid("getNodeChildren",rec);
  10923. query = $.jgrid.from(ch);
  10924. query.orderBy(sortname, newDir, st, datefmt);
  10925. children = query.select();
  10926. for (i = 0, len = children.length; i < len; i++) {
  10927. child = children[i];
  10928. records.push(child);
  10929. $(this).jqGrid("collectChildrenSortTree",records, child, sortname, newDir, st, datefmt);
  10930. }
  10931. });
  10932. },
  10933. // experimental
  10934. setTreeRow : function(rowid, data) {
  10935. var success=false;
  10936. this.each(function(){
  10937. var t = this;
  10938. if(!t.grid || !t.p.treeGrid) {return;}
  10939. success = $(t).jqGrid("setRowData",rowid,data);
  10940. });
  10941. return success;
  10942. },
  10943. delTreeNode : function (rowid) {
  10944. return this.each(function () {
  10945. var $t = this, rid = $t.p.localReader.id, i,
  10946. left = $t.p.treeReader.left_field,
  10947. right = $t.p.treeReader.right_field, myright, width, res, key;
  10948. if(!$t.grid || !$t.p.treeGrid) {return;}
  10949. var rc = $t.p._index[rowid];
  10950. if (rc !== undefined) {
  10951. // nested
  10952. myright = parseInt($t.p.data[rc][right],10);
  10953. width = myright - parseInt($t.p.data[rc][left],10) + 1;
  10954. var dr = $($t).jqGrid("getFullTreeNode",$t.p.data[rc]);
  10955. if(dr.length>0){
  10956. for (i=0;i<dr.length;i++){
  10957. $($t).jqGrid("delRowData",dr[i][rid]);
  10958. }
  10959. }
  10960. if( $t.p.treeGridModel === "nested") {
  10961. // ToDo - update grid data
  10962. res = $.jgrid.from($t.p.data)
  10963. .greater(left,myright,{stype:'integer'})
  10964. .select();
  10965. if(res.length) {
  10966. for( key in res) {
  10967. if(res.hasOwnProperty(key)) {
  10968. res[key][left] = parseInt(res[key][left],10) - width ;
  10969. }
  10970. }
  10971. }
  10972. res = $.jgrid.from($t.p.data)
  10973. .greater(right,myright,{stype:'integer'})
  10974. .select();
  10975. if(res.length) {
  10976. for( key in res) {
  10977. if(res.hasOwnProperty(key)) {
  10978. res[key][right] = parseInt(res[key][right],10) - width ;
  10979. }
  10980. }
  10981. }
  10982. }
  10983. }
  10984. });
  10985. },
  10986. addChildNode : function( nodeid, parentid, data, expandData ) {
  10987. //return this.each(function(){
  10988. var $t = this[0];
  10989. if(data) {
  10990. // we suppose tha the id is autoincremet and
  10991. var expanded = $t.p.treeReader.expanded_field,
  10992. isLeaf = $t.p.treeReader.leaf_field,
  10993. level = $t.p.treeReader.level_field,
  10994. //icon = $t.p.treeReader.icon_field,
  10995. parent = $t.p.treeReader.parent_id_field,
  10996. left = $t.p.treeReader.left_field,
  10997. right = $t.p.treeReader.right_field,
  10998. loaded = $t.p.treeReader.loaded,
  10999. method, parentindex, parentdata, parentlevel, i, len, max=0, rowind = parentid, leaf, maxright;
  11000. if(expandData===undefined) {expandData = false;}
  11001. if ( nodeid === undefined || nodeid === null ) {
  11002. i = $t.p.data.length-1;
  11003. if( i>= 0 ) {
  11004. while(i>=0){max = Math.max(max, parseInt($t.p.data[i][$t.p.localReader.id],10)); i--;}
  11005. }
  11006. nodeid = max+1;
  11007. }
  11008. var prow = $($t).jqGrid('getInd', parentid);
  11009. leaf = false;
  11010. // if not a parent we assume root
  11011. if ( parentid === undefined || parentid === null || parentid==="") {
  11012. parentid = null;
  11013. rowind = null;
  11014. method = 'last';
  11015. parentlevel = $t.p.tree_root_level;
  11016. i = $t.p.data.length+1;
  11017. } else {
  11018. method = 'after';
  11019. parentindex = $t.p._index[parentid];
  11020. parentdata = $t.p.data[parentindex];
  11021. parentid = parentdata[$t.p.localReader.id];
  11022. parentlevel = parseInt(parentdata[level],10)+1;
  11023. var childs = $($t).jqGrid('getFullTreeNode', parentdata);
  11024. // if there are child nodes get the last index of it
  11025. if(childs.length) {
  11026. i = childs[childs.length-1][$t.p.localReader.id];
  11027. rowind = i;
  11028. i = $($t).jqGrid('getInd',rowind)+1;
  11029. } else {
  11030. i = $($t).jqGrid('getInd', parentid)+1;
  11031. }
  11032. // if the node is leaf
  11033. if(parentdata[isLeaf]) {
  11034. leaf = true;
  11035. parentdata[expanded] = true;
  11036. //var prow = $($t).jqGrid('getInd', parentid);
  11037. $($t.rows[prow])
  11038. .find("span.cell-wrapperleaf").removeClass("cell-wrapperleaf").addClass("cell-wrapper")
  11039. .end()
  11040. .find("div.tree-leaf").removeClass($t.p.treeIcons.leaf+" tree-leaf").addClass($t.p.treeIcons.minus+" tree-minus");
  11041. $t.p.data[parentindex][isLeaf] = false;
  11042. parentdata[loaded] = true;
  11043. }
  11044. }
  11045. len = i+1;
  11046. if( data[expanded]===undefined) {data[expanded]= false;}
  11047. if( data[loaded]===undefined ) { data[loaded] = false;}
  11048. data[level] = parentlevel;
  11049. if( data[isLeaf]===undefined) {data[isLeaf]= true;}
  11050. if( $t.p.treeGridModel === "adjacency") {
  11051. data[parent] = parentid;
  11052. }
  11053. if( $t.p.treeGridModel === "nested") {
  11054. // this method requiere more attention
  11055. var query, res, key;
  11056. //maxright = parseInt(maxright,10);
  11057. // ToDo - update grid data
  11058. if(parentid !== null) {
  11059. maxright = parseInt(parentdata[right],10);
  11060. query = $.jgrid.from($t.p.data);
  11061. query = query.greaterOrEquals(right,maxright,{stype:'integer'});
  11062. res = query.select();
  11063. if(res.length) {
  11064. for( key in res) {
  11065. if(res.hasOwnProperty(key)) {
  11066. res[key][left] = res[key][left] > maxright ? parseInt(res[key][left],10) +2 : res[key][left];
  11067. res[key][right] = res[key][right] >= maxright ? parseInt(res[key][right],10) +2 : res[key][right];
  11068. }
  11069. }
  11070. }
  11071. data[left] = maxright;
  11072. data[right]= maxright+1;
  11073. } else {
  11074. maxright = parseInt( $($t).jqGrid('getCol', right, false, 'max'), 10);
  11075. res = $.jgrid.from($t.p.data)
  11076. .greater(left,maxright,{stype:'integer'})
  11077. .select();
  11078. if(res.length) {
  11079. for( key in res) {
  11080. if(res.hasOwnProperty(key)) {
  11081. res[key][left] = parseInt(res[key][left],10) +2 ;
  11082. }
  11083. }
  11084. }
  11085. res = $.jgrid.from($t.p.data)
  11086. .greater(right,maxright,{stype:'integer'})
  11087. .select();
  11088. if(res.length) {
  11089. for( key in res) {
  11090. if(res.hasOwnProperty(key)) {
  11091. res[key][right] = parseInt(res[key][right],10) +2 ;
  11092. }
  11093. }
  11094. }
  11095. data[left] = maxright+1;
  11096. data[right] = maxright + 2;
  11097. }
  11098. }
  11099. if( parentid === null || $($t).jqGrid("isNodeLoaded",parentdata) || leaf ) {
  11100. $($t).jqGrid('addRowData', nodeid, data, method, rowind);
  11101. $($t).jqGrid('setTreeNode', i, len);
  11102. }
  11103. if(parentdata && !parentdata[expanded] && expandData) {
  11104. $($t.rows[prow])
  11105. .find("div.treeclick")
  11106. .click();
  11107. }
  11108. }
  11109. //});
  11110. }
  11111. });
  11112. })(jQuery);
  11113. /*jshint eqeqeq:false, eqnull:true */
  11114. /*global jQuery */
  11115. // Grouping module
  11116. (function($){
  11117. "use strict";
  11118. $.extend($.jgrid,{
  11119. template : function(format){ //jqgformat
  11120. var args = $.makeArray(arguments).slice(1), j, al = args.length;
  11121. if(format==null) { format = ""; }
  11122. return format.replace(/\{([\w\-]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g, function(m,i){
  11123. if(!isNaN(parseInt(i,10))) {
  11124. return args[parseInt(i,10)];
  11125. }
  11126. for(j=0; j < al;j++) {
  11127. if($.isArray(args[j])) {
  11128. var nmarr = args[ j ],
  11129. k = nmarr.length;
  11130. while(k--) {
  11131. if(i===nmarr[k].nm) {
  11132. return nmarr[k].v;
  11133. }
  11134. }
  11135. }
  11136. }
  11137. });
  11138. }
  11139. });
  11140. $.jgrid.extend({
  11141. groupingSetup : function () {
  11142. return this.each(function (){
  11143. var $t = this, i, j, cml, cm = $t.p.colModel, grp = $t.p.groupingView;
  11144. if(grp !== null && ( (typeof grp === 'object') || $.isFunction(grp) ) ) {
  11145. if(!grp.groupField.length) {
  11146. $t.p.grouping = false;
  11147. } else {
  11148. if (grp.visibiltyOnNextGrouping === undefined) {
  11149. grp.visibiltyOnNextGrouping = [];
  11150. }
  11151. grp.lastvalues=[];
  11152. grp.groups =[];
  11153. grp.counters =[];
  11154. for(i=0;i<grp.groupField.length;i++) {
  11155. if(!grp.groupOrder[i]) {
  11156. grp.groupOrder[i] = 'asc';
  11157. }
  11158. if(!grp.groupText[i]) {
  11159. grp.groupText[i] = '{0}';
  11160. }
  11161. if( typeof grp.groupColumnShow[i] !== 'boolean') {
  11162. grp.groupColumnShow[i] = true;
  11163. }
  11164. if( typeof grp.groupSummary[i] !== 'boolean') {
  11165. grp.groupSummary[i] = false;
  11166. }
  11167. if(grp.groupColumnShow[i] === true) {
  11168. grp.visibiltyOnNextGrouping[i] = true;
  11169. $($t).jqGrid('showCol',grp.groupField[i]);
  11170. } else {
  11171. grp.visibiltyOnNextGrouping[i] = $("#"+$.jgrid.jqID($t.p.id+"_"+grp.groupField[i])).is(":visible");
  11172. $($t).jqGrid('hideCol',grp.groupField[i]);
  11173. }
  11174. }
  11175. grp.summary =[];
  11176. for(j=0, cml = cm.length; j < cml; j++) {
  11177. if(cm[j].summaryType) {
  11178. grp.summary.push({nm:cm[j].name,st:cm[j].summaryType, v: '', sr: cm[j].summaryRound, srt: cm[j].summaryRoundType || 'round'});
  11179. }
  11180. }
  11181. }
  11182. } else {
  11183. $t.p.grouping = false;
  11184. }
  11185. });
  11186. },
  11187. groupingPrepare : function (rData, gdata, record, irow) {
  11188. this.each(function(){
  11189. var grp = this.p.groupingView, $t= this, i,
  11190. grlen = grp.groupField.length,
  11191. fieldName,
  11192. v,
  11193. displayName,
  11194. displayValue,
  11195. changed = 0;
  11196. for(i=0;i<grlen;i++) {
  11197. fieldName = grp.groupField[i];
  11198. displayName = grp.displayField[i];
  11199. v = record[fieldName];
  11200. displayValue = displayName == null ? null : record[displayName];
  11201. if( displayValue == null ) {
  11202. displayValue = v;
  11203. }
  11204. if( v !== undefined ) {
  11205. if(irow === 0 ) {
  11206. // First record always starts a new group
  11207. grp.groups.push({idx:i,dataIndex:fieldName,value:v, displayValue: displayValue, startRow: irow, cnt:1, summary : [] } );
  11208. grp.lastvalues[i] = v;
  11209. grp.counters[i] = {cnt:1, pos:grp.groups.length-1, summary: $.extend(true,[],grp.summary)};
  11210. $.each(grp.counters[i].summary,function() {
  11211. if ($.isFunction(this.st)) {
  11212. this.v = this.st.call($t, this.v, this.nm, record);
  11213. } else {
  11214. this.v = $($t).jqGrid('groupingCalculations.handler',this.st, this.v, this.nm, this.sr, this.srt, record);
  11215. }
  11216. });
  11217. grp.groups[grp.counters[i].pos].summary = grp.counters[i].summary;
  11218. } else {
  11219. 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)) {
  11220. // This record is not in same group as previous one
  11221. grp.groups.push({idx:i,dataIndex:fieldName,value:v, displayValue: displayValue, startRow: irow, cnt:1, summary : [] } );
  11222. grp.lastvalues[i] = v;
  11223. changed = 1;
  11224. grp.counters[i] = {cnt:1, pos:grp.groups.length-1, summary: $.extend(true,[],grp.summary)};
  11225. $.each(grp.counters[i].summary,function() {
  11226. if ($.isFunction(this.st)) {
  11227. this.v = this.st.call($t, this.v, this.nm, record);
  11228. } else {
  11229. this.v = $($t).jqGrid('groupingCalculations.handler',this.st, this.v, this.nm, this.sr, this.srt, record);
  11230. }
  11231. });
  11232. grp.groups[grp.counters[i].pos].summary = grp.counters[i].summary;
  11233. } else {
  11234. if (changed === 1) {
  11235. // This group has changed because an earlier group changed.
  11236. grp.groups.push({idx:i,dataIndex:fieldName,value:v, displayValue: displayValue, startRow: irow, cnt:1, summary : [] } );
  11237. grp.lastvalues[i] = v;
  11238. grp.counters[i] = {cnt:1, pos:grp.groups.length-1, summary: $.extend(true,[],grp.summary)};
  11239. $.each(grp.counters[i].summary,function() {
  11240. if ($.isFunction(this.st)) {
  11241. this.v = this.st.call($t, this.v, this.nm, record);
  11242. } else {
  11243. this.v = $($t).jqGrid('groupingCalculations.handler',this.st, this.v, this.nm, this.sr, this.srt, record);
  11244. }
  11245. });
  11246. grp.groups[grp.counters[i].pos].summary = grp.counters[i].summary;
  11247. } else {
  11248. grp.counters[i].cnt += 1;
  11249. grp.groups[grp.counters[i].pos].cnt = grp.counters[i].cnt;
  11250. $.each(grp.counters[i].summary,function() {
  11251. if ($.isFunction(this.st)) {
  11252. this.v = this.st.call($t, this.v, this.nm, record);
  11253. } else {
  11254. this.v = $($t).jqGrid('groupingCalculations.handler',this.st, this.v, this.nm, this.sr, this.srt, record);
  11255. }
  11256. });
  11257. grp.groups[grp.counters[i].pos].summary = grp.counters[i].summary;
  11258. }
  11259. }
  11260. }
  11261. }
  11262. }
  11263. gdata.push( rData );
  11264. });
  11265. return gdata;
  11266. },
  11267. groupingToggle : function(hid){
  11268. this.each(function(){
  11269. var $t = this,
  11270. grp = $t.p.groupingView,
  11271. strpos = hid.split('_'),
  11272. uidpos,
  11273. //uid = hid.substring(0,strpos+1),
  11274. num = parseInt(strpos[strpos.length-2], 10);
  11275. strpos.splice(strpos.length-2,2);
  11276. var uid = strpos.join("_"),
  11277. minus = grp.minusicon,
  11278. plus = grp.plusicon,
  11279. tar = $("#"+$.jgrid.jqID(hid)),
  11280. r = tar.length ? tar[0].nextSibling : null,
  11281. tarspan = $("#"+$.jgrid.jqID(hid)+" span."+"tree-wrap-"+$t.p.direction),
  11282. collapsed = false, tspan;
  11283. if( tarspan.hasClass(minus) ) {
  11284. if(grp.showSummaryOnHide) {
  11285. if(r){
  11286. while(r) {
  11287. if($(r).hasClass('jqfoot') ) {
  11288. var lv = parseInt($(r).attr("jqfootlevel"),10);
  11289. if( lv <= num) {
  11290. break;
  11291. }
  11292. }
  11293. $(r).hide();
  11294. r = r.nextSibling;
  11295. }
  11296. }
  11297. } else {
  11298. if(r){
  11299. while(r) {
  11300. uidpos = r.className.indexOf(uid);
  11301. if(uidpos !== -1) {
  11302. if( parseInt(r.className.substring(uidpos+uid.length + 1),10) <= num) {
  11303. break;
  11304. }
  11305. }
  11306. $(r).hide();
  11307. r = r.nextSibling;
  11308. }
  11309. }
  11310. }
  11311. tarspan.removeClass(minus).addClass(plus);
  11312. collapsed = true;
  11313. } else {
  11314. if(r){
  11315. while(r) {
  11316. uidpos = r.className.indexOf(uid);
  11317. if(uidpos !== -1) {
  11318. if( parseInt(r.className.substring(uidpos+uid.length + 1),10) <= num) {
  11319. break;
  11320. }
  11321. }
  11322. $(r).show();
  11323. tspan = $(r).find("span."+"tree-wrap-"+$t.p.direction);
  11324. if( tspan && $(tspan).hasClass(plus) ) {
  11325. $(tspan).removeClass(plus).addClass(minus);
  11326. }
  11327. r = r.nextSibling;
  11328. }
  11329. }
  11330. tarspan.removeClass(plus).addClass(minus);
  11331. }
  11332. $($t).triggerHandler("jqGridGroupingClickGroup", [hid , collapsed]);
  11333. if( $.isFunction($t.p.onClickGroup)) { $t.p.onClickGroup.call($t, hid , collapsed); }
  11334. });
  11335. return false;
  11336. },
  11337. groupingRender : function (grdata, colspans ) {
  11338. return this.each(function(){
  11339. var $t = this,
  11340. grp = $t.p.groupingView,
  11341. str = "", icon = "", hid, clid, pmrtl = grp.groupCollapse ? grp.plusicon : grp.minusicon, gv, cp=[], len =grp.groupField.length;
  11342. pmrtl += " tree-wrap-"+$t.p.direction;
  11343. $.each($t.p.colModel, function (i,n){
  11344. var ii;
  11345. for(ii=0;ii<len;ii++) {
  11346. if(grp.groupField[ii] === n.name ) {
  11347. cp[ii] = i;
  11348. break;
  11349. }
  11350. }
  11351. });
  11352. var toEnd = 0;
  11353. function findGroupIdx( ind , offset, grp) {
  11354. var ret = false, i;
  11355. if(offset===0) {
  11356. ret = grp[ind];
  11357. } else {
  11358. var id = grp[ind].idx;
  11359. if(id===0) {
  11360. ret = grp[ind];
  11361. } else {
  11362. for(i=ind;i >= 0; i--) {
  11363. if(grp[i].idx === id-offset) {
  11364. ret = grp[i];
  11365. break;
  11366. }
  11367. }
  11368. }
  11369. }
  11370. return ret;
  11371. }
  11372. var sumreverse = $.makeArray(grp.groupSummary);
  11373. sumreverse.reverse();
  11374. $.each(grp.groups,function(i,n){
  11375. toEnd++;
  11376. clid = $t.p.id+"ghead_"+n.idx;
  11377. hid = clid+"_"+i;
  11378. icon = "<span style='cursor:pointer;' class='ui-icon "+pmrtl+"' onclick=\"jQuery('#"+$.jgrid.jqID($t.p.id)+"').jqGrid('groupingToggle','"+hid+"');return false;\"></span>";
  11379. try {
  11380. if ($.isArray(grp.formatDisplayField) && $.isFunction(grp.formatDisplayField[n.idx])) {
  11381. n.displayValue = grp.formatDisplayField[n.idx].call($t, n.displayValue, n.value, $t.p.colModel[cp[n.idx]], n.idx, grp);
  11382. }
  11383. gv = $t.formatter(hid, n.displayValue, cp[n.idx], n.value );
  11384. } catch (egv) {
  11385. gv = n.displayValue;
  11386. }
  11387. str += "<tr id=\""+hid+"\" role=\"row\" class= \"ui-widget-content jqgroup ui-row-"+$t.p.direction+" "+clid+"\"><td style=\"padding-left:"+(n.idx * 12) + "px;"+"\" colspan=\""+colspans+"\">"+icon+$.jgrid.template(grp.groupText[n.idx], gv, n.cnt, n.summary)+"</td></tr>";
  11388. var leaf = len-1 === n.idx;
  11389. if( leaf ) {
  11390. var gg = grp.groups[i+1], k, kk, ik;
  11391. var end = gg !== undefined ? grp.groups[i+1].startRow : grdata.length;
  11392. for(kk=n.startRow;kk<end;kk++) {
  11393. str += grdata[kk].join('');
  11394. }
  11395. var jj;
  11396. if (gg !== undefined) {
  11397. for (jj = 0; jj < grp.groupField.length; jj++) {
  11398. if (gg.dataIndex === grp.groupField[jj]) {
  11399. break;
  11400. }
  11401. }
  11402. toEnd = grp.groupField.length - jj;
  11403. }
  11404. for (ik = 0; ik < toEnd; ik++) {
  11405. if(!sumreverse[ik]) { continue; }
  11406. var hhdr = "";
  11407. if(grp.groupCollapse && !grp.showSummaryOnHide) {
  11408. hhdr = " style=\"display:none;\"";
  11409. }
  11410. str += "<tr"+hhdr+" jqfootlevel=\""+(n.idx-ik)+"\" role=\"row\" class=\"ui-widget-content jqfoot ui-row-"+$t.p.direction+"\">";
  11411. var fdata = findGroupIdx(i, ik, grp.groups),
  11412. cm = $t.p.colModel,
  11413. vv, grlen = fdata.cnt;
  11414. for(k=0; k<colspans;k++) {
  11415. var tmpdata = "<td "+$t.formatCol(k,1,'')+">&#160;</td>",
  11416. tplfld = "{0}";
  11417. $.each(fdata.summary,function(){
  11418. if(this.nm === cm[k].name) {
  11419. if(cm[k].summaryTpl) {
  11420. tplfld = cm[k].summaryTpl;
  11421. }
  11422. if(typeof this.st === 'string' && this.st.toLowerCase() === 'avg') {
  11423. if(this.v && grlen > 0) {
  11424. this.v = (this.v/grlen);
  11425. }
  11426. }
  11427. try {
  11428. vv = $t.formatter('', this.v, k, this);
  11429. } catch (ef) {
  11430. vv = this.v;
  11431. }
  11432. tmpdata= "<td "+$t.formatCol(k,1,'')+">"+$.jgrid.format(tplfld,vv)+ "</td>";
  11433. return false;
  11434. }
  11435. });
  11436. str += tmpdata;
  11437. }
  11438. str += "</tr>";
  11439. }
  11440. toEnd = jj;
  11441. }
  11442. });
  11443. $("#"+$.jgrid.jqID($t.p.id)+" tbody:first").append(str);
  11444. // free up memory
  11445. str = null;
  11446. });
  11447. },
  11448. groupingGroupBy : function (name, options ) {
  11449. return this.each(function(){
  11450. var $t = this;
  11451. if(typeof name === "string") {
  11452. name = [name];
  11453. }
  11454. var grp = $t.p.groupingView;
  11455. $t.p.grouping = true;
  11456. //Set default, in case visibilityOnNextGrouping is undefined
  11457. if (grp.visibiltyOnNextGrouping === undefined) {
  11458. grp.visibiltyOnNextGrouping = [];
  11459. }
  11460. var i;
  11461. // show previous hidden groups if they are hidden and weren't removed yet
  11462. for(i=0;i<grp.groupField.length;i++) {
  11463. if(!grp.groupColumnShow[i] && grp.visibiltyOnNextGrouping[i]) {
  11464. $($t).jqGrid('showCol',grp.groupField[i]);
  11465. }
  11466. }
  11467. // set visibility status of current group columns on next grouping
  11468. for(i=0;i<name.length;i++) {
  11469. grp.visibiltyOnNextGrouping[i] = $("#"+$.jgrid.jqID($t.p.id)+"_"+$.jgrid.jqID(name[i])).is(":visible");
  11470. }
  11471. $t.p.groupingView = $.extend($t.p.groupingView, options || {});
  11472. grp.groupField = name;
  11473. $($t).trigger("reloadGrid");
  11474. });
  11475. },
  11476. groupingRemove : function (current) {
  11477. return this.each(function(){
  11478. var $t = this;
  11479. if(current === undefined) {
  11480. current = true;
  11481. }
  11482. $t.p.grouping = false;
  11483. if(current===true) {
  11484. var grp = $t.p.groupingView, i;
  11485. // show previous hidden groups if they are hidden and weren't removed yet
  11486. for(i=0;i<grp.groupField.length;i++) {
  11487. if (!grp.groupColumnShow[i] && grp.visibiltyOnNextGrouping[i]) {
  11488. $($t).jqGrid('showCol', grp.groupField);
  11489. }
  11490. }
  11491. $("tr.jqgroup, tr.jqfoot","#"+$.jgrid.jqID($t.p.id)+" tbody:first").remove();
  11492. $("tr.jqgrow:hidden","#"+$.jgrid.jqID($t.p.id)+" tbody:first").show();
  11493. } else {
  11494. $($t).trigger("reloadGrid");
  11495. }
  11496. });
  11497. },
  11498. groupingCalculations : {
  11499. handler: function(fn, v, field, round, roundType, rc) {
  11500. var funcs = {
  11501. sum: function() {
  11502. return parseFloat(v||0) + parseFloat((rc[field]||0));
  11503. },
  11504. min: function() {
  11505. if(v==="") {
  11506. return parseFloat(rc[field]||0);
  11507. }
  11508. return Math.min(parseFloat(v),parseFloat(rc[field]||0));
  11509. },
  11510. max: function() {
  11511. if(v==="") {
  11512. return parseFloat(rc[field]||0);
  11513. }
  11514. return Math.max(parseFloat(v),parseFloat(rc[field]||0));
  11515. },
  11516. count: function() {
  11517. if(v==="") {v=0;}
  11518. if(rc.hasOwnProperty(field)) {
  11519. return v+1;
  11520. }
  11521. return 0;
  11522. },
  11523. avg: function() {
  11524. // the same as sum, but at end we divide it
  11525. // so use sum instead of duplicating the code (?)
  11526. return funcs.sum();
  11527. }
  11528. };
  11529. if(!funcs[fn]) {
  11530. throw ("jqGrid Grouping No such method: " + fn);
  11531. }
  11532. var res = funcs[fn]();
  11533. if (round != null) {
  11534. if (roundType === 'fixed') {
  11535. res = res.toFixed(round);
  11536. } else {
  11537. var mul = Math.pow(10, round);
  11538. res = Math.round(res * mul) / mul;
  11539. }
  11540. }
  11541. return res;
  11542. }
  11543. }
  11544. });
  11545. })(jQuery);
  11546. /*jshint eqeqeq:false, eqnull:true, devel:true */
  11547. /*global jQuery, xmlJsonClass */
  11548. (function($){
  11549. /*
  11550. * jqGrid extension for constructing Grid Data from external file
  11551. * Tony Tomov tony@trirand.com
  11552. * http://trirand.com/blog/
  11553. * Dual licensed under the MIT and GPL licenses:
  11554. * http://www.opensource.org/licenses/mit-license.php
  11555. * http://www.gnu.org/licenses/gpl-2.0.html
  11556. **/
  11557. "use strict";
  11558. $.jgrid.extend({
  11559. jqGridImport : function(o) {
  11560. o = $.extend({
  11561. imptype : "xml", // xml, json, xmlstring, jsonstring
  11562. impstring: "",
  11563. impurl: "",
  11564. mtype: "GET",
  11565. impData : {},
  11566. xmlGrid :{
  11567. config : "roots>grid",
  11568. data: "roots>rows"
  11569. },
  11570. jsonGrid :{
  11571. config : "grid",
  11572. data: "data"
  11573. },
  11574. ajaxOptions :{}
  11575. }, o || {});
  11576. return this.each(function(){
  11577. var $t = this;
  11578. var xmlConvert = function (xml,o) {
  11579. var cnfg = $(o.xmlGrid.config,xml)[0];
  11580. var xmldata = $(o.xmlGrid.data,xml)[0], jstr, jstr1, key;
  11581. if(xmlJsonClass.xml2json && $.jgrid.parse) {
  11582. jstr = xmlJsonClass.xml2json(cnfg," ");
  11583. jstr = $.jgrid.parse(jstr);
  11584. for(key in jstr) {
  11585. if(jstr.hasOwnProperty(key)) {
  11586. jstr1=jstr[key];
  11587. }
  11588. }
  11589. if(xmldata) {
  11590. // save the datatype
  11591. var svdatatype = jstr.grid.datatype;
  11592. jstr.grid.datatype = 'xmlstring';
  11593. jstr.grid.datastr = xml;
  11594. $($t).jqGrid( jstr1 ).jqGrid("setGridParam",{datatype:svdatatype});
  11595. } else {
  11596. $($t).jqGrid( jstr1 );
  11597. }
  11598. jstr = null;jstr1=null;
  11599. } else {
  11600. alert("xml2json or parse are not present");
  11601. }
  11602. };
  11603. var jsonConvert = function (jsonstr,o){
  11604. if (jsonstr && typeof jsonstr === 'string') {
  11605. var _jsonparse = false;
  11606. if($.jgrid.useJSON) {
  11607. $.jgrid.useJSON = false;
  11608. _jsonparse = true;
  11609. }
  11610. var json = $.jgrid.parse(jsonstr);
  11611. if(_jsonparse) { $.jgrid.useJSON = true; }
  11612. var gprm = json[o.jsonGrid.config];
  11613. var jdata = json[o.jsonGrid.data];
  11614. if(jdata) {
  11615. var svdatatype = gprm.datatype;
  11616. gprm.datatype = 'jsonstring';
  11617. gprm.datastr = jdata;
  11618. $($t).jqGrid( gprm ).jqGrid("setGridParam",{datatype:svdatatype});
  11619. } else {
  11620. $($t).jqGrid( gprm );
  11621. }
  11622. }
  11623. };
  11624. switch (o.imptype){
  11625. case 'xml':
  11626. $.ajax($.extend({
  11627. url:o.impurl,
  11628. type:o.mtype,
  11629. data: o.impData,
  11630. dataType:"xml",
  11631. complete: function(xml,stat) {
  11632. if(stat === 'success') {
  11633. xmlConvert(xml.responseXML,o);
  11634. $($t).triggerHandler("jqGridImportComplete", [xml, o]);
  11635. if($.isFunction(o.importComplete)) {
  11636. o.importComplete(xml);
  11637. }
  11638. }
  11639. xml=null;
  11640. }
  11641. }, o.ajaxOptions));
  11642. break;
  11643. case 'xmlstring' :
  11644. // we need to make just the conversion and use the same code as xml
  11645. if(o.impstring && typeof o.impstring === 'string') {
  11646. var xmld = $.parseXML(o.impstring);
  11647. if(xmld) {
  11648. xmlConvert(xmld,o);
  11649. $($t).triggerHandler("jqGridImportComplete", [xmld, o]);
  11650. if($.isFunction(o.importComplete)) {
  11651. o.importComplete(xmld);
  11652. }
  11653. o.impstring = null;
  11654. }
  11655. xmld = null;
  11656. }
  11657. break;
  11658. case 'json':
  11659. $.ajax($.extend({
  11660. url:o.impurl,
  11661. type:o.mtype,
  11662. data: o.impData,
  11663. dataType:"json",
  11664. complete: function(json) {
  11665. try {
  11666. jsonConvert(json.responseText,o );
  11667. $($t).triggerHandler("jqGridImportComplete", [json, o]);
  11668. if($.isFunction(o.importComplete)) {
  11669. o.importComplete(json);
  11670. }
  11671. } catch (ee){}
  11672. json=null;
  11673. }
  11674. }, o.ajaxOptions ));
  11675. break;
  11676. case 'jsonstring' :
  11677. if(o.impstring && typeof o.impstring === 'string') {
  11678. jsonConvert(o.impstring,o );
  11679. $($t).triggerHandler("jqGridImportComplete", [o.impstring, o]);
  11680. if($.isFunction(o.importComplete)) {
  11681. o.importComplete(o.impstring);
  11682. }
  11683. o.impstring = null;
  11684. }
  11685. break;
  11686. }
  11687. });
  11688. },
  11689. jqGridExport : function(o) {
  11690. o = $.extend({
  11691. exptype : "xmlstring",
  11692. root: "grid",
  11693. ident: "\t"
  11694. }, o || {});
  11695. var ret = null;
  11696. this.each(function () {
  11697. if(!this.grid) { return;}
  11698. var key, gprm = $.extend(true, {},$(this).jqGrid("getGridParam"));
  11699. // we need to check for:
  11700. // 1.multiselect, 2.subgrid 3. treegrid and remove the unneded columns from colNames
  11701. if(gprm.rownumbers) {
  11702. gprm.colNames.splice(0,1);
  11703. gprm.colModel.splice(0,1);
  11704. }
  11705. if(gprm.multiselect) {
  11706. gprm.colNames.splice(0,1);
  11707. gprm.colModel.splice(0,1);
  11708. }
  11709. if(gprm.subGrid) {
  11710. gprm.colNames.splice(0,1);
  11711. gprm.colModel.splice(0,1);
  11712. }
  11713. gprm.knv = null;
  11714. if(gprm.treeGrid) {
  11715. for (key in gprm.treeReader) {
  11716. if(gprm.treeReader.hasOwnProperty(key)) {
  11717. gprm.colNames.splice(gprm.colNames.length-1);
  11718. gprm.colModel.splice(gprm.colModel.length-1);
  11719. }
  11720. }
  11721. }
  11722. switch (o.exptype) {
  11723. case 'xmlstring' :
  11724. ret = "<"+o.root+">"+xmlJsonClass.json2xml(gprm,o.ident)+"</"+o.root+">";
  11725. break;
  11726. case 'jsonstring' :
  11727. ret = "{"+ xmlJsonClass.toJson(gprm,o.root,o.ident,false)+"}";
  11728. if(gprm.postData.filters !== undefined) {
  11729. ret=ret.replace(/filters":"/,'filters":');
  11730. ret=ret.replace(/}]}"/,'}]}');
  11731. }
  11732. break;
  11733. }
  11734. });
  11735. return ret;
  11736. },
  11737. excelExport : function(o) {
  11738. o = $.extend({
  11739. exptype : "remote",
  11740. url : null,
  11741. oper: "oper",
  11742. tag: "excel",
  11743. exportOptions : {}
  11744. }, o || {});
  11745. return this.each(function(){
  11746. if(!this.grid) { return;}
  11747. var url;
  11748. if(o.exptype === "remote") {
  11749. var pdata = $.extend({},this.p.postData);
  11750. pdata[o.oper] = o.tag;
  11751. var params = jQuery.param(pdata);
  11752. if(o.url.indexOf("?") !== -1) { url = o.url+"&"+params; }
  11753. else { url = o.url+"?"+params; }
  11754. window.location = url;
  11755. }
  11756. });
  11757. }
  11758. });
  11759. })(jQuery);
  11760. /*jshint evil:true, eqeqeq:false, eqnull:true, devel:true */
  11761. /*global jQuery */
  11762. (function($){
  11763. /*
  11764. **
  11765. * jqGrid addons using jQuery UI
  11766. * Author: Mark Williams
  11767. * Dual licensed under the MIT and GPL licenses:
  11768. * http://www.opensource.org/licenses/mit-license.php
  11769. * http://www.gnu.org/licenses/gpl-2.0.html
  11770. * depends on jQuery UI
  11771. **/
  11772. "use strict";
  11773. if ($.jgrid.msie && $.jgrid.msiever()===8) {
  11774. $.expr[":"].hidden = function(elem) {
  11775. return elem.offsetWidth === 0 || elem.offsetHeight === 0 ||
  11776. elem.style.display === "none";
  11777. };
  11778. }
  11779. // requiere load multiselect before grid
  11780. $.jgrid._multiselect = false;
  11781. if($.ui) {
  11782. if ($.ui.multiselect ) {
  11783. if($.ui.multiselect.prototype._setSelected) {
  11784. var setSelected = $.ui.multiselect.prototype._setSelected;
  11785. $.ui.multiselect.prototype._setSelected = function(item,selected) {
  11786. var ret = setSelected.call(this,item,selected);
  11787. if (selected && this.selectedList) {
  11788. var elt = this.element;
  11789. this.selectedList.find('li').each(function() {
  11790. if ($(this).data('optionLink')) {
  11791. $(this).data('optionLink').remove().appendTo(elt);
  11792. }
  11793. });
  11794. }
  11795. return ret;
  11796. };
  11797. }
  11798. if($.ui.multiselect.prototype.destroy) {
  11799. $.ui.multiselect.prototype.destroy = function() {
  11800. this.element.show();
  11801. this.container.remove();
  11802. if ($.Widget === undefined) {
  11803. $.widget.prototype.destroy.apply(this, arguments);
  11804. } else {
  11805. $.Widget.prototype.destroy.apply(this, arguments);
  11806. }
  11807. };
  11808. }
  11809. $.jgrid._multiselect = true;
  11810. }
  11811. }
  11812. $.jgrid.extend({
  11813. sortableColumns : function (tblrow)
  11814. {
  11815. return this.each(function (){
  11816. var ts = this, tid= $.jgrid.jqID( ts.p.id );
  11817. function start() {ts.p.disableClick = true;}
  11818. var sortable_opts = {
  11819. "tolerance" : "pointer",
  11820. "axis" : "x",
  11821. "scrollSensitivity": "1",
  11822. "items": '>th:not(:has(#jqgh_'+tid+'_cb'+',#jqgh_'+tid+'_rn'+',#jqgh_'+tid+'_subgrid),:hidden)',
  11823. "placeholder": {
  11824. element: function(item) {
  11825. var el = $(document.createElement(item[0].nodeName))
  11826. .addClass(item[0].className+" ui-sortable-placeholder ui-state-highlight")
  11827. .removeClass("ui-sortable-helper")[0];
  11828. return el;
  11829. },
  11830. update: function(self, p) {
  11831. p.height(self.currentItem.innerHeight() - parseInt(self.currentItem.css('paddingTop')||0, 10) - parseInt(self.currentItem.css('paddingBottom')||0, 10));
  11832. p.width(self.currentItem.innerWidth() - parseInt(self.currentItem.css('paddingLeft')||0, 10) - parseInt(self.currentItem.css('paddingRight')||0, 10));
  11833. }
  11834. },
  11835. "update": function(event, ui) {
  11836. var p = $(ui.item).parent(),
  11837. th = $(">th", p),
  11838. colModel = ts.p.colModel,
  11839. cmMap = {}, tid= ts.p.id+"_";
  11840. $.each(colModel, function(i) { cmMap[this.name]=i; });
  11841. var permutation = [];
  11842. th.each(function() {
  11843. var id = $(">div", this).get(0).id.replace(/^jqgh_/, "").replace(tid,"");
  11844. if (cmMap.hasOwnProperty(id)) {
  11845. permutation.push(cmMap[id]);
  11846. }
  11847. });
  11848. $(ts).jqGrid("remapColumns",permutation, true, true);
  11849. if ($.isFunction(ts.p.sortable.update)) {
  11850. ts.p.sortable.update(permutation);
  11851. }
  11852. setTimeout(function(){ts.p.disableClick=false;}, 50);
  11853. }
  11854. };
  11855. if (ts.p.sortable.options) {
  11856. $.extend(sortable_opts, ts.p.sortable.options);
  11857. } else if ($.isFunction(ts.p.sortable)) {
  11858. ts.p.sortable = { "update" : ts.p.sortable };
  11859. }
  11860. if (sortable_opts.start) {
  11861. var s = sortable_opts.start;
  11862. sortable_opts.start = function(e,ui) {
  11863. start();
  11864. s.call(this,e,ui);
  11865. };
  11866. } else {
  11867. sortable_opts.start = start;
  11868. }
  11869. if (ts.p.sortable.exclude) {
  11870. sortable_opts.items += ":not("+ts.p.sortable.exclude+")";
  11871. }
  11872. tblrow.sortable(sortable_opts).data("sortable").floating = true;
  11873. });
  11874. },
  11875. columnChooser : function(opts) {
  11876. var self = this;
  11877. if($("#colchooser_"+$.jgrid.jqID(self[0].p.id)).length ) { return; }
  11878. var selector = $('<div id="colchooser_'+self[0].p.id+'" style="position:relative;overflow:hidden"><div><select multiple="multiple"></select></div></div>');
  11879. var select = $('select', selector);
  11880. function insert(perm,i,v) {
  11881. if(i>=0){
  11882. var a = perm.slice();
  11883. var b = a.splice(i,Math.max(perm.length-i,i));
  11884. if(i>perm.length) { i = perm.length; }
  11885. a[i] = v;
  11886. return a.concat(b);
  11887. }
  11888. }
  11889. opts = $.extend({
  11890. "width" : 420,
  11891. "height" : 240,
  11892. "classname" : null,
  11893. "done" : function(perm) { if (perm) { self.jqGrid("remapColumns", perm, true); } },
  11894. /* msel is either the name of a ui widget class that
  11895. extends a multiselect, or a function that supports
  11896. creating a multiselect object (with no argument,
  11897. or when passed an object), and destroying it (when
  11898. passed the string "destroy"). */
  11899. "msel" : "multiselect",
  11900. /* "msel_opts" : {}, */
  11901. /* dlog is either the name of a ui widget class that
  11902. behaves in a dialog-like way, or a function, that
  11903. supports creating a dialog (when passed dlog_opts)
  11904. or destroying a dialog (when passed the string
  11905. "destroy")
  11906. */
  11907. "dlog" : "dialog",
  11908. "dialog_opts" : {
  11909. "minWidth": 470
  11910. },
  11911. /* dlog_opts is either an option object to be passed
  11912. to "dlog", or (more likely) a function that creates
  11913. the options object.
  11914. The default produces a suitable options object for
  11915. ui.dialog */
  11916. "dlog_opts" : function(opts) {
  11917. var buttons = {};
  11918. buttons[opts.bSubmit] = function() {
  11919. opts.apply_perm();
  11920. opts.cleanup(false);
  11921. };
  11922. buttons[opts.bCancel] = function() {
  11923. opts.cleanup(true);
  11924. };
  11925. return $.extend(true, {
  11926. "buttons": buttons,
  11927. "close": function() {
  11928. opts.cleanup(true);
  11929. },
  11930. "modal" : opts.modal || false,
  11931. "resizable": opts.resizable || true,
  11932. "width": opts.width+20
  11933. }, opts.dialog_opts || {});
  11934. },
  11935. /* Function to get the permutation array, and pass it to the
  11936. "done" function */
  11937. "apply_perm" : function() {
  11938. $('option',select).each(function() {
  11939. if (this.selected) {
  11940. self.jqGrid("showCol", colModel[this.value].name);
  11941. } else {
  11942. self.jqGrid("hideCol", colModel[this.value].name);
  11943. }
  11944. });
  11945. var perm = [];
  11946. //fixedCols.slice(0);
  11947. $('option:selected',select).each(function() { perm.push(parseInt(this.value,10)); });
  11948. $.each(perm, function() { delete colMap[colModel[parseInt(this,10)].name]; });
  11949. $.each(colMap, function() {
  11950. var ti = parseInt(this,10);
  11951. perm = insert(perm,ti,ti);
  11952. });
  11953. if (opts.done) {
  11954. opts.done.call(self, perm);
  11955. }
  11956. },
  11957. /* Function to cleanup the dialog, and select. Also calls the
  11958. done function with no permutation (to indicate that the
  11959. columnChooser was aborted */
  11960. "cleanup" : function(calldone) {
  11961. call(opts.dlog, selector, 'destroy');
  11962. call(opts.msel, select, 'destroy');
  11963. selector.remove();
  11964. if (calldone && opts.done) {
  11965. opts.done.call(self);
  11966. }
  11967. },
  11968. "msel_opts" : {}
  11969. }, $.jgrid.col, opts || {});
  11970. if($.ui) {
  11971. if ($.ui.multiselect ) {
  11972. if(opts.msel === "multiselect") {
  11973. if(!$.jgrid._multiselect) {
  11974. // should be in language file
  11975. alert("Multiselect plugin loaded after jqGrid. Please load the plugin before the jqGrid!");
  11976. return;
  11977. }
  11978. opts.msel_opts = $.extend($.ui.multiselect.defaults,opts.msel_opts);
  11979. }
  11980. }
  11981. }
  11982. if (opts.caption) {
  11983. selector.attr("title", opts.caption);
  11984. }
  11985. if (opts.classname) {
  11986. selector.addClass(opts.classname);
  11987. select.addClass(opts.classname);
  11988. }
  11989. if (opts.width) {
  11990. $(">div",selector).css({"width": opts.width,"margin":"0 auto"});
  11991. select.css("width", opts.width);
  11992. }
  11993. if (opts.height) {
  11994. $(">div",selector).css("height", opts.height);
  11995. select.css("height", opts.height - 10);
  11996. }
  11997. var colModel = self.jqGrid("getGridParam", "colModel");
  11998. var colNames = self.jqGrid("getGridParam", "colNames");
  11999. var colMap = {}, fixedCols = [];
  12000. select.empty();
  12001. $.each(colModel, function(i) {
  12002. colMap[this.name] = i;
  12003. if (this.hidedlg) {
  12004. if (!this.hidden) {
  12005. fixedCols.push(i);
  12006. }
  12007. return;
  12008. }
  12009. select.append("<option value='"+i+"' "+
  12010. (this.hidden?"":"selected='selected'")+">"+$.jgrid.stripHtml(colNames[i])+"</option>");
  12011. });
  12012. function call(fn, obj) {
  12013. if (!fn) { return; }
  12014. if (typeof fn === 'string') {
  12015. if ($.fn[fn]) {
  12016. $.fn[fn].apply(obj, $.makeArray(arguments).slice(2));
  12017. }
  12018. } else if ($.isFunction(fn)) {
  12019. fn.apply(obj, $.makeArray(arguments).slice(2));
  12020. }
  12021. }
  12022. var dopts = $.isFunction(opts.dlog_opts) ? opts.dlog_opts.call(self, opts) : opts.dlog_opts;
  12023. call(opts.dlog, selector, dopts);
  12024. var mopts = $.isFunction(opts.msel_opts) ? opts.msel_opts.call(self, opts) : opts.msel_opts;
  12025. call(opts.msel, select, mopts);
  12026. },
  12027. sortableRows : function (opts) {
  12028. // Can accept all sortable options and events
  12029. return this.each(function(){
  12030. var $t = this;
  12031. if(!$t.grid) { return; }
  12032. // Currently we disable a treeGrid sortable
  12033. if($t.p.treeGrid) { return; }
  12034. if($.fn.sortable) {
  12035. opts = $.extend({
  12036. "cursor":"move",
  12037. "axis" : "y",
  12038. "items": ".jqgrow"
  12039. },
  12040. opts || {});
  12041. if(opts.start && $.isFunction(opts.start)) {
  12042. opts._start_ = opts.start;
  12043. delete opts.start;
  12044. } else {opts._start_=false;}
  12045. if(opts.update && $.isFunction(opts.update)) {
  12046. opts._update_ = opts.update;
  12047. delete opts.update;
  12048. } else {opts._update_ = false;}
  12049. opts.start = function(ev,ui) {
  12050. $(ui.item).css("border-width","0px");
  12051. $("td",ui.item).each(function(i){
  12052. this.style.width = $t.grid.cols[i].style.width;
  12053. });
  12054. if($t.p.subGrid) {
  12055. var subgid = $(ui.item).attr("id");
  12056. try {
  12057. $($t).jqGrid('collapseSubGridRow',subgid);
  12058. } catch (e) {}
  12059. }
  12060. if(opts._start_) {
  12061. opts._start_.apply(this,[ev,ui]);
  12062. }
  12063. };
  12064. opts.update = function (ev,ui) {
  12065. $(ui.item).css("border-width","");
  12066. if($t.p.rownumbers === true) {
  12067. $("td.jqgrid-rownum",$t.rows).each(function( i ){
  12068. $(this).html( i+1+(parseInt($t.p.page,10)-1)*parseInt($t.p.rowNum,10) );
  12069. });
  12070. }
  12071. if(opts._update_) {
  12072. opts._update_.apply(this,[ev,ui]);
  12073. }
  12074. };
  12075. $("tbody:first",$t).sortable(opts);
  12076. $("tbody:first",$t).disableSelection();
  12077. }
  12078. });
  12079. },
  12080. gridDnD : function(opts) {
  12081. return this.each(function(){
  12082. var $t = this, i, cn;
  12083. if(!$t.grid) { return; }
  12084. // Currently we disable a treeGrid drag and drop
  12085. if($t.p.treeGrid) { return; }
  12086. if(!$.fn.draggable || !$.fn.droppable) { return; }
  12087. function updateDnD ()
  12088. {
  12089. var datadnd = $.data($t,"dnd");
  12090. $("tr.jqgrow:not(.ui-draggable)",$t).draggable($.isFunction(datadnd.drag) ? datadnd.drag.call($($t),datadnd) : datadnd.drag);
  12091. }
  12092. var appender = "<table id='jqgrid_dnd' class='ui-jqgrid-dnd'></table>";
  12093. if($("#jqgrid_dnd")[0] === undefined) {
  12094. $('body').append(appender);
  12095. }
  12096. if(typeof opts === 'string' && opts === 'updateDnD' && $t.p.jqgdnd===true) {
  12097. updateDnD();
  12098. return;
  12099. }
  12100. opts = $.extend({
  12101. "drag" : function (opts) {
  12102. return $.extend({
  12103. start : function (ev, ui) {
  12104. var i, subgid;
  12105. // if we are in subgrid mode try to collapse the node
  12106. if($t.p.subGrid) {
  12107. subgid = $(ui.helper).attr("id");
  12108. try {
  12109. $($t).jqGrid('collapseSubGridRow',subgid);
  12110. } catch (e) {}
  12111. }
  12112. // hack
  12113. // drag and drop does not insert tr in table, when the table has no rows
  12114. // we try to insert new empty row on the target(s)
  12115. for (i=0;i<$.data($t,"dnd").connectWith.length;i++){
  12116. if($($.data($t,"dnd").connectWith[i]).jqGrid('getGridParam','reccount') === 0 ){
  12117. $($.data($t,"dnd").connectWith[i]).jqGrid('addRowData','jqg_empty_row',{});
  12118. }
  12119. }
  12120. ui.helper.addClass("ui-state-highlight");
  12121. $("td",ui.helper).each(function(i) {
  12122. this.style.width = $t.grid.headers[i].width+"px";
  12123. });
  12124. if(opts.onstart && $.isFunction(opts.onstart) ) { opts.onstart.call($($t),ev,ui); }
  12125. },
  12126. stop :function(ev,ui) {
  12127. var i, ids;
  12128. if(ui.helper.dropped && !opts.dragcopy) {
  12129. ids = $(ui.helper).attr("id");
  12130. if(ids === undefined) { ids = $(this).attr("id"); }
  12131. $($t).jqGrid('delRowData',ids );
  12132. }
  12133. // if we have a empty row inserted from start event try to delete it
  12134. for (i=0;i<$.data($t,"dnd").connectWith.length;i++){
  12135. $($.data($t,"dnd").connectWith[i]).jqGrid('delRowData','jqg_empty_row');
  12136. }
  12137. if(opts.onstop && $.isFunction(opts.onstop) ) { opts.onstop.call($($t),ev,ui); }
  12138. }
  12139. },opts.drag_opts || {});
  12140. },
  12141. "drop" : function (opts) {
  12142. return $.extend({
  12143. accept: function(d) {
  12144. if (!$(d).hasClass('jqgrow')) { return d;}
  12145. var tid = $(d).closest("table.ui-jqgrid-btable");
  12146. if(tid.length > 0 && $.data(tid[0],"dnd") !== undefined) {
  12147. var cn = $.data(tid[0],"dnd").connectWith;
  12148. return $.inArray('#'+$.jgrid.jqID(this.id),cn) !== -1 ? true : false;
  12149. }
  12150. return false;
  12151. },
  12152. drop: function(ev, ui) {
  12153. if (!$(ui.draggable).hasClass('jqgrow')) { return; }
  12154. var accept = $(ui.draggable).attr("id");
  12155. var getdata = ui.draggable.parent().parent().jqGrid('getRowData',accept);
  12156. if(!opts.dropbyname) {
  12157. var j =0, tmpdata = {}, nm, key;
  12158. var dropmodel = $("#"+$.jgrid.jqID(this.id)).jqGrid('getGridParam','colModel');
  12159. try {
  12160. for (key in getdata) {
  12161. if (getdata.hasOwnProperty(key)) {
  12162. nm = dropmodel[j].name;
  12163. if( !(nm === 'cb' || nm === 'rn' || nm === 'subgrid' )) {
  12164. if(getdata.hasOwnProperty(key) && dropmodel[j]) {
  12165. tmpdata[nm] = getdata[key];
  12166. }
  12167. }
  12168. j++;
  12169. }
  12170. }
  12171. getdata = tmpdata;
  12172. } catch (e) {}
  12173. }
  12174. ui.helper.dropped = true;
  12175. if(opts.beforedrop && $.isFunction(opts.beforedrop) ) {
  12176. //parameters to this callback - event, element, data to be inserted, sender, reciever
  12177. // should return object which will be inserted into the reciever
  12178. var datatoinsert = opts.beforedrop.call(this,ev,ui,getdata,$('#'+$.jgrid.jqID($t.p.id)),$(this));
  12179. if (datatoinsert !== undefined && datatoinsert !== null && typeof datatoinsert === "object") { getdata = datatoinsert; }
  12180. }
  12181. if(ui.helper.dropped) {
  12182. var grid;
  12183. if(opts.autoid) {
  12184. if($.isFunction(opts.autoid)) {
  12185. grid = opts.autoid.call(this,getdata);
  12186. } else {
  12187. grid = Math.ceil(Math.random()*1000);
  12188. grid = opts.autoidprefix+grid;
  12189. }
  12190. }
  12191. // NULL is interpreted as undefined while null as object
  12192. $("#"+$.jgrid.jqID(this.id)).jqGrid('addRowData',grid,getdata,opts.droppos);
  12193. }
  12194. if(opts.ondrop && $.isFunction(opts.ondrop) ) { opts.ondrop.call(this,ev,ui, getdata); }
  12195. }}, opts.drop_opts || {});
  12196. },
  12197. "onstart" : null,
  12198. "onstop" : null,
  12199. "beforedrop": null,
  12200. "ondrop" : null,
  12201. "drop_opts" : {
  12202. "activeClass": "ui-state-active",
  12203. "hoverClass": "ui-state-hover"
  12204. },
  12205. "drag_opts" : {
  12206. "revert": "invalid",
  12207. "helper": "clone",
  12208. "cursor": "move",
  12209. "appendTo" : "#jqgrid_dnd",
  12210. "zIndex": 5000
  12211. },
  12212. "dragcopy": false,
  12213. "dropbyname" : false,
  12214. "droppos" : "first",
  12215. "autoid" : true,
  12216. "autoidprefix" : "dnd_"
  12217. }, opts || {});
  12218. if(!opts.connectWith) { return; }
  12219. opts.connectWith = opts.connectWith.split(",");
  12220. opts.connectWith = $.map(opts.connectWith,function(n){return $.trim(n);});
  12221. $.data($t,"dnd",opts);
  12222. if($t.p.reccount !== 0 && !$t.p.jqgdnd) {
  12223. updateDnD();
  12224. }
  12225. $t.p.jqgdnd = true;
  12226. for (i=0;i<opts.connectWith.length;i++){
  12227. cn =opts.connectWith[i];
  12228. $(cn).droppable($.isFunction(opts.drop) ? opts.drop.call($($t),opts) : opts.drop);
  12229. }
  12230. });
  12231. },
  12232. gridResize : function(opts) {
  12233. return this.each(function(){
  12234. var $t = this, gID = $.jgrid.jqID($t.p.id);
  12235. if(!$t.grid || !$.fn.resizable) { return; }
  12236. opts = $.extend({}, opts || {});
  12237. if(opts.alsoResize ) {
  12238. opts._alsoResize_ = opts.alsoResize;
  12239. delete opts.alsoResize;
  12240. } else {
  12241. opts._alsoResize_ = false;
  12242. }
  12243. if(opts.stop && $.isFunction(opts.stop)) {
  12244. opts._stop_ = opts.stop;
  12245. delete opts.stop;
  12246. } else {
  12247. opts._stop_ = false;
  12248. }
  12249. opts.stop = function (ev, ui) {
  12250. $($t).jqGrid('setGridParam',{height:$("#gview_"+gID+" .ui-jqgrid-bdiv").height()});
  12251. $($t).jqGrid('setGridWidth',ui.size.width,opts.shrinkToFit);
  12252. if(opts._stop_) { opts._stop_.call($t,ev,ui); }
  12253. };
  12254. if(opts._alsoResize_) {
  12255. var optstest = "{\'#gview_"+gID+" .ui-jqgrid-bdiv\':true,'" +opts._alsoResize_+"':true}";
  12256. opts.alsoResize = eval('('+optstest+')'); // the only way that I found to do this
  12257. } else {
  12258. opts.alsoResize = $(".ui-jqgrid-bdiv","#gview_"+gID);
  12259. }
  12260. delete opts._alsoResize_;
  12261. $("#gbox_"+gID).resizable(opts);
  12262. });
  12263. }
  12264. });
  12265. })(jQuery);
  12266. /*
  12267. Transform a table to a jqGrid.
  12268. Peter Romianowski <peter.romianowski@optivo.de>
  12269. If the first column of the table contains checkboxes or
  12270. radiobuttons then the jqGrid is made selectable.
  12271. */
  12272. // Addition - selector can be a class or id
  12273. function tableToGrid(selector, options) {
  12274. jQuery(selector).each(function() {
  12275. if(this.grid) {return;} //Adedd from Tony Tomov
  12276. // This is a small "hack" to make the width of the jqGrid 100%
  12277. jQuery(this).width("99%");
  12278. var w = jQuery(this).width();
  12279. // Text whether we have single or multi select
  12280. var inputCheckbox = jQuery('tr td:first-child input[type=checkbox]:first', jQuery(this));
  12281. var inputRadio = jQuery('tr td:first-child input[type=radio]:first', jQuery(this));
  12282. var selectMultiple = inputCheckbox.length > 0;
  12283. var selectSingle = !selectMultiple && inputRadio.length > 0;
  12284. var selectable = selectMultiple || selectSingle;
  12285. //var inputName = inputCheckbox.attr("name") || inputRadio.attr("name");
  12286. // Build up the columnModel and the data
  12287. var colModel = [];
  12288. var colNames = [];
  12289. jQuery('th', jQuery(this)).each(function() {
  12290. if (colModel.length === 0 && selectable) {
  12291. colModel.push({
  12292. name: '__selection__',
  12293. index: '__selection__',
  12294. width: 0,
  12295. hidden: true
  12296. });
  12297. colNames.push('__selection__');
  12298. } else {
  12299. colModel.push({
  12300. name: jQuery(this).attr("id") || jQuery.trim(jQuery.jgrid.stripHtml(jQuery(this).html())).split(' ').join('_'),
  12301. index: jQuery(this).attr("id") || jQuery.trim(jQuery.jgrid.stripHtml(jQuery(this).html())).split(' ').join('_'),
  12302. width: jQuery(this).width() || 150
  12303. });
  12304. colNames.push(jQuery(this).html());
  12305. }
  12306. });
  12307. var data = [];
  12308. var rowIds = [];
  12309. var rowChecked = [];
  12310. jQuery('tbody > tr', jQuery(this)).each(function() {
  12311. var row = {};
  12312. var rowPos = 0;
  12313. jQuery('td', jQuery(this)).each(function() {
  12314. if (rowPos === 0 && selectable) {
  12315. var input = jQuery('input', jQuery(this));
  12316. var rowId = input.attr("value");
  12317. rowIds.push(rowId || data.length);
  12318. if (input.is(":checked")) {
  12319. rowChecked.push(rowId);
  12320. }
  12321. row[colModel[rowPos].name] = input.attr("value");
  12322. } else {
  12323. row[colModel[rowPos].name] = jQuery(this).html();
  12324. }
  12325. rowPos++;
  12326. });
  12327. if(rowPos >0) { data.push(row); }
  12328. });
  12329. // Clear the original HTML table
  12330. jQuery(this).empty();
  12331. // Mark it as jqGrid
  12332. jQuery(this).addClass("scroll");
  12333. jQuery(this).jqGrid(jQuery.extend({
  12334. datatype: "local",
  12335. width: w,
  12336. colNames: colNames,
  12337. colModel: colModel,
  12338. multiselect: selectMultiple
  12339. //inputName: inputName,
  12340. //inputValueCol: imputName != null ? "__selection__" : null
  12341. }, options || {}));
  12342. // Add data
  12343. var a;
  12344. for (a = 0; a < data.length; a++) {
  12345. var id = null;
  12346. if (rowIds.length > 0) {
  12347. id = rowIds[a];
  12348. if (id && id.replace) {
  12349. // We have to do this since the value of a checkbox
  12350. // or radio button can be anything
  12351. id = encodeURIComponent(id).replace(/[.\-%]/g, "_");
  12352. }
  12353. }
  12354. if (id === null) {
  12355. id = a + 1;
  12356. }
  12357. jQuery(this).jqGrid("addRowData",id, data[a]);
  12358. }
  12359. // Set the selection
  12360. for (a = 0; a < rowChecked.length; a++) {
  12361. jQuery(this).jqGrid("setSelection",rowChecked[a]);
  12362. }
  12363. });
  12364. };