dwz.min.js 169 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646
  1. /**
  2. * @author ZhangHuihua@msn.com
  3. *
  4. */
  5. var DWZ = {
  6. regPlugins: [], // [function($parent){} ...]
  7. // sbar: show sidebar
  8. keyCode: {
  9. ENTER: 13, ESC: 27, END: 35, HOME: 36,
  10. SHIFT: 16, TAB: 9,
  11. LEFT: 37, RIGHT: 39, UP: 38, DOWN: 40,
  12. DELETE: 46, BACKSPACE:8
  13. },
  14. eventType: {
  15. pageClear:"pageClear", // 用于重新ajaxLoad、关闭nabTab, 关闭dialog时,去除xheditor等需要特殊处理的资源
  16. resizeGrid:"resizeGrid" // 用于窗口或dialog大小调整
  17. },
  18. isOverAxis: function(x, reference, size) {
  19. //Determines when x coordinate is over "b" element axis
  20. return (x > reference) && (x < (reference + size));
  21. },
  22. isOver: function(y, x, top, left, height, width) {
  23. //Determines when x, y coordinates is over "b" element
  24. return this.isOverAxis(y, top, height) && this.isOverAxis(x, left, width);
  25. },
  26. pageInfo: {pageNum:"pageNum", numPerPage:"numPerPage", orderField:"orderField", orderDirection:"orderDirection"},
  27. statusCode: {ok:200, error:300, timeout:301},
  28. keys: {statusCode:"statusCode", message:"message"},
  29. ui:{
  30. sbar:true,
  31. hideMode:'display' //navTab组件切换的隐藏方式,支持的值有’display’,’offsets’负数偏移位置的值,默认值为’display’
  32. },
  33. frag:{}, //page fragment
  34. _msg:{}, //alert message
  35. _set:{
  36. loginUrl:"", //session timeout
  37. loginTitle:"", //if loginTitle open a login dialog
  38. debug:false
  39. },
  40. msg:function(key, args){
  41. var _format = function(str,args) {
  42. args = args || [];
  43. var result = str || "";
  44. for (var i = 0; i < args.length; i++){
  45. result = result.replace(new RegExp("\\{" + i + "\\}", "g"), args[i]);
  46. }
  47. return result;
  48. }
  49. return _format(this._msg[key], args);
  50. },
  51. debug:function(msg){
  52. if (this._set.debug) {
  53. if (typeof(console) != "undefined") console.log(msg);
  54. else alert(msg);
  55. }
  56. },
  57. loadLogin:function(){
  58. if ($.pdialog && DWZ._set.loginTitle) {
  59. $.pdialog.open(DWZ._set.loginUrl, "login", DWZ._set.loginTitle, {mask:true,width:520,height:260});
  60. } else {
  61. window.location = DWZ._set.loginUrl;
  62. }
  63. },
  64. /*
  65. * json to string
  66. */
  67. obj2str:function(o) {
  68. var r = [];
  69. if(typeof o =="string") return "\""+o.replace(/([\'\"\\])/g,"\\$1").replace(/(\n)/g,"\\n").replace(/(\r)/g,"\\r").replace(/(\t)/g,"\\t")+"\"";
  70. if(typeof o == "object"){
  71. if(!o.sort){
  72. for(var i in o)
  73. r.push(i+":"+DWZ.obj2str(o[i]));
  74. if(!!document.all && !/^\n?function\s*toString\(\)\s*\{\n?\s*\[native code\]\n?\s*\}\n?\s*$/.test(o.toString)){
  75. r.push("toString:"+o.toString.toString());
  76. }
  77. r="{"+r.join()+"}"
  78. }else{
  79. for(var i =0;i<o.length;i++) {
  80. r.push(DWZ.obj2str(o[i]));
  81. }
  82. r="["+r.join()+"]"
  83. }
  84. return r;
  85. }
  86. return o.toString();
  87. },
  88. jsonEval:function(data) {
  89. try{
  90. if ($.type(data) == 'string')
  91. return eval('(' + data + ')');
  92. else return data;
  93. } catch (e){
  94. return {};
  95. }
  96. },
  97. ajaxError:function(xhr, ajaxOptions, thrownError){
  98. if (alertMsg) {
  99. alertMsg.error("<div>Http status: " + xhr.status + " " + xhr.statusText + "</div>"
  100. + "<div>ajaxOptions: "+ajaxOptions + "</div>"
  101. + "<div>thrownError: "+thrownError + "</div>"
  102. + "<div>"+xhr.responseText+"</div>");
  103. } else {
  104. alert("Http status: " + xhr.status + " " + xhr.statusText + "\najaxOptions: " + ajaxOptions + "\nthrownError:"+thrownError + "\n" +xhr.responseText);
  105. }
  106. },
  107. ajaxDone:function(json){
  108. if(json[DWZ.keys.statusCode] == DWZ.statusCode.error) {
  109. if(json[DWZ.keys.message] && alertMsg) alertMsg.error(json[DWZ.keys.message]);
  110. } else if (json[DWZ.keys.statusCode] == DWZ.statusCode.timeout) {
  111. if(alertMsg) alertMsg.error(json[DWZ.keys.message] || DWZ.msg("sessionTimout"), {okCall:DWZ.loadLogin});
  112. else DWZ.loadLogin();
  113. } else if (json[DWZ.keys.statusCode] == DWZ.statusCode.ok){
  114. if(json[DWZ.keys.message] && alertMsg) alertMsg.correct(json[DWZ.keys.message]);
  115. };
  116. },
  117. init:function(pageFrag, options){
  118. var op = $.extend({
  119. loginUrl:"login.html", loginTitle:null, callback:null, debug:false,
  120. statusCode:{}, keys:{}
  121. }, options);
  122. this._set.loginUrl = op.loginUrl;
  123. this._set.loginTitle = op.loginTitle;
  124. this._set.debug = op.debug;
  125. $.extend(DWZ.statusCode, op.statusCode);
  126. $.extend(DWZ.keys, op.keys);
  127. $.extend(DWZ.pageInfo, op.pageInfo);
  128. $.extend(DWZ.ui, op.ui);
  129. jQuery.ajax({
  130. type:'GET',
  131. url:pageFrag,
  132. dataType:'xml',
  133. timeout: 50000,
  134. cache: false,
  135. error: function(xhr){
  136. alert('Error loading XML document: ' + pageFrag + "\nHttp status: " + xhr.status + " " + xhr.statusText);
  137. },
  138. success: function(xml){
  139. $(xml).find("_PAGE_").each(function(){
  140. var pageId = $(this).attr("id");
  141. if (pageId) DWZ.frag[pageId] = $(this).text();
  142. });
  143. $(xml).find("_MSG_").each(function(){
  144. var id = $(this).attr("id");
  145. if (id) DWZ._msg[id] = $(this).text();
  146. });
  147. if (jQuery.isFunction(op.callback)) op.callback();
  148. }
  149. });
  150. var _doc = $(document);
  151. if (!_doc.isBind(DWZ.eventType.pageClear)) {
  152. _doc.bind(DWZ.eventType.pageClear, function(event){
  153. var box = event.target;
  154. if ($.fn.xheditor) {
  155. $("textarea.editor", box).xheditor(false);
  156. }
  157. });
  158. }
  159. }
  160. };
  161. (function($){
  162. // DWZ set regional
  163. $.setRegional = function(key, value){
  164. if (!$.regional) $.regional = {};
  165. $.regional[key] = value;
  166. };
  167. $.fn.extend({
  168. /**
  169. * @param {Object} op: {type:GET/POST, url:ajax请求地址, data:ajax请求参数列表, callback:回调函数 }
  170. */
  171. ajaxUrl: function(op){
  172. var $this = $(this);
  173. $this.trigger(DWZ.eventType.pageClear);
  174. $.ajax({
  175. type: op.type || 'GET',
  176. url: op.url,
  177. data: op.data,
  178. cache: false,
  179. success: function(response){
  180. var json = DWZ.jsonEval(response);
  181. if (json[DWZ.keys.statusCode]==DWZ.statusCode.error){
  182. if (json[DWZ.keys.message]) alertMsg.error(json[DWZ.keys.message]);
  183. } else {
  184. $this.html(response).initUI();
  185. if ($.isFunction(op.callback)) op.callback(response);
  186. }
  187. if (json[DWZ.keys.statusCode]==DWZ.statusCode.timeout){
  188. if ($.pdialog) $.pdialog.checkTimeout();
  189. if (navTab) navTab.checkTimeout();
  190. alertMsg.error(json[DWZ.keys.message] || DWZ.msg("sessionTimout"), {okCall:function(){
  191. DWZ.loadLogin();
  192. }});
  193. }
  194. },
  195. error: DWZ.ajaxError,
  196. statusCode: {
  197. 503: function(xhr, ajaxOptions, thrownError) {
  198. alert(DWZ.msg("statusCode_503") || thrownError);
  199. }
  200. }
  201. });
  202. },
  203. loadUrl: function(url,data,callback){
  204. $(this).ajaxUrl({url:url, data:data, callback:callback});
  205. },
  206. initUI: function(){
  207. return this.each(function(){
  208. if($.isFunction(initUI)) initUI(this);
  209. });
  210. },
  211. /**
  212. * adjust component inner reference box height
  213. * @param {Object} refBox: reference box jQuery Obj
  214. */
  215. layoutH: function($refBox){
  216. return this.each(function(){
  217. var $this = $(this);
  218. if (! $refBox) $refBox = $this.parents("div.layoutBox:first");
  219. var iRefH = $refBox.height();
  220. var iLayoutH = parseInt($this.attr("layoutH"));
  221. var iH = iRefH - iLayoutH > 50 ? iRefH - iLayoutH : 50;
  222. if ($this.isTag("table")) {
  223. $this.removeAttr("layoutH").wrap('<div layoutH="'+iLayoutH+'" style="overflow:auto;height:'+iH+'px"></div>');
  224. } else {
  225. $this.height(iH).css("overflow","auto");
  226. }
  227. });
  228. },
  229. hoverClass: function(className, speed){
  230. var _className = className || "hover";
  231. return this.each(function(){
  232. var $this = $(this), mouseOutTimer;
  233. $this.hover(function(){
  234. if (mouseOutTimer) clearTimeout(mouseOutTimer);
  235. $this.addClass(_className);
  236. },function(){
  237. mouseOutTimer = setTimeout(function(){$this.removeClass(_className);}, speed||10);
  238. });
  239. });
  240. },
  241. focusClass: function(className){
  242. var _className = className || "textInputFocus";
  243. return this.each(function(){
  244. $(this).focus(function(){
  245. $(this).addClass(_className);
  246. }).blur(function(){
  247. $(this).removeClass(_className);
  248. });
  249. });
  250. },
  251. inputAlert: function(){
  252. return this.each(function(){
  253. var $this = $(this);
  254. function getAltBox(){
  255. return $this.parent().find("label.alt");
  256. }
  257. function altBoxCss(opacity){
  258. var position = $this.position();
  259. return {
  260. width:$this.width(),
  261. top:position.top+'px',
  262. left:position.left +'px',
  263. opacity:opacity || 1
  264. };
  265. }
  266. if (getAltBox().size() < 1) {
  267. if (!$this.attr("id")) $this.attr("id", $this.attr("name") + "_" +Math.round(Math.random()*10000));
  268. var $label = $('<label class="alt" for="'+$this.attr("id")+'">'+$this.attr("alt")+'</label>').appendTo($this.parent());
  269. $label.css(altBoxCss(1));
  270. if ($this.val()) $label.hide();
  271. }
  272. $this.focus(function(){
  273. getAltBox().css(altBoxCss(0.3));
  274. }).blur(function(){
  275. if (!$(this).val()) getAltBox().show().css("opacity",1);
  276. }).keydown(function(){
  277. getAltBox().hide();
  278. });
  279. });
  280. },
  281. isTag:function(tn) {
  282. if(!tn) return false;
  283. return $(this)[0].tagName.toLowerCase() == tn?true:false;
  284. },
  285. /**
  286. * 判断当前元素是否已经绑定某个事件
  287. * @param {Object} type
  288. */
  289. isBind:function(type) {
  290. var _events = $(this).data("events");
  291. return _events && type && _events[type];
  292. },
  293. /**
  294. * 输出firebug日志
  295. * @param {Object} msg
  296. */
  297. log:function(msg){
  298. return this.each(function(){
  299. if (console) console.log("%s: %o", msg, this);
  300. });
  301. }
  302. });
  303. /**
  304. * 扩展String方法
  305. */
  306. $.extend(String.prototype, {
  307. isPositiveInteger:function(){
  308. return (new RegExp(/^[1-9]\d*$/).test(this));
  309. },
  310. isInteger:function(){
  311. return (new RegExp(/^\d+$/).test(this));
  312. },
  313. isNumber: function(value, element) {
  314. return (new RegExp(/^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/).test(this));
  315. },
  316. trim:function(){
  317. return this.replace(/(^\s*)|(\s*$)|\r|\n/g, "");
  318. },
  319. startsWith:function (pattern){
  320. return this.indexOf(pattern) === 0;
  321. },
  322. endsWith:function(pattern) {
  323. var d = this.length - pattern.length;
  324. return d >= 0 && this.lastIndexOf(pattern) === d;
  325. },
  326. replaceSuffix:function(index){
  327. return this.replace(/\[[0-9]+\]/,'['+index+']').replace('#index#',index);
  328. },
  329. trans:function(){
  330. return this.replace(/&lt;/g, '<').replace(/&gt;/g,'>').replace(/&quot;/g, '"');
  331. },
  332. encodeTXT: function(){
  333. return (this).replaceAll('&', '&amp;').replaceAll("<","&lt;").replaceAll(">", "&gt;").replaceAll(" ", "&nbsp;");
  334. },
  335. replaceAll:function(os, ns){
  336. return this.replace(new RegExp(os,"gm"),ns);
  337. },
  338. replaceTm:function($data){
  339. if (!$data) return this;
  340. return this.replace(RegExp("({[A-Za-z_]+[A-Za-z0-9_]*})","g"), function($1){
  341. return $data[$1.replace(/[{}]+/g, "")];
  342. });
  343. },
  344. replaceTmById:function(_box){
  345. var $parent = _box || $(document);
  346. return this.replace(RegExp("({[A-Za-z_]+[A-Za-z0-9_]*})","g"), function($1){
  347. var $input = $parent.find("#"+$1.replace(/[{}]+/g, ""));
  348. return $input.val() ? $input.val() : $1;
  349. });
  350. },
  351. isFinishedTm:function(){
  352. return !(new RegExp("{[A-Za-z_]+[A-Za-z0-9_]*}").test(this));
  353. },
  354. skipChar:function(ch) {
  355. if (!this || this.length===0) {return '';}
  356. if (this.charAt(0)===ch) {return this.substring(1).skipChar(ch);}
  357. return this;
  358. },
  359. isValidPwd:function() {
  360. return (new RegExp(/^([_]|[a-zA-Z0-9]){6,32}$/).test(this));
  361. },
  362. isValidMail:function(){
  363. return(new RegExp(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(this.trim()));
  364. },
  365. isSpaces:function() {
  366. for(var i=0; i<this.length; i+=1) {
  367. var ch = this.charAt(i);
  368. if (ch!=' '&& ch!="\n" && ch!="\t" && ch!="\r") {return false;}
  369. }
  370. return true;
  371. },
  372. isPhone:function() {
  373. return (new RegExp(/(^([0-9]{3,4}[-])?\d{3,8}(-\d{1,6})?$)|(^\([0-9]{3,4}\)\d{3,8}(\(\d{1,6}\))?$)|(^\d{3,8}$)/).test(this));
  374. },
  375. isUrl:function(){
  376. return (new RegExp(/^[a-zA-z]+:\/\/([a-zA-Z0-9\-\.]+)([-\w .\/?%&=:]*)$/).test(this));
  377. },
  378. isExternalUrl:function(){
  379. return this.isUrl() && this.indexOf("://"+document.domain) == -1;
  380. }
  381. });
  382. })(jQuery);
  383. /**
  384. * You can use this map like this:
  385. * var myMap = new Map();
  386. * myMap.put("key","value");
  387. * var key = myMap.get("key");
  388. * myMap.remove("key");
  389. */
  390. function Map(){
  391. this.elements = new Array();
  392. this.size = function(){
  393. return this.elements.length;
  394. }
  395. this.isEmpty = function(){
  396. return (this.elements.length < 1);
  397. }
  398. this.clear = function(){
  399. this.elements = new Array();
  400. }
  401. this.put = function(_key, _value){
  402. this.remove(_key);
  403. this.elements.push({key: _key, value: _value});
  404. }
  405. this.remove = function(_key){
  406. try {
  407. for (i = 0; i < this.elements.length; i++) {
  408. if (this.elements[i].key == _key) {
  409. this.elements.splice(i, 1);
  410. return true;
  411. }
  412. }
  413. } catch (e) {
  414. return false;
  415. }
  416. return false;
  417. }
  418. this.get = function(_key){
  419. try {
  420. for (i = 0; i < this.elements.length; i++) {
  421. if (this.elements[i].key == _key) { return this.elements[i].value; }
  422. }
  423. } catch (e) {
  424. return null;
  425. }
  426. }
  427. this.element = function(_index){
  428. if (_index < 0 || _index >= this.elements.length) { return null; }
  429. return this.elements[_index];
  430. }
  431. this.containsKey = function(_key){
  432. try {
  433. for (i = 0; i < this.elements.length; i++) {
  434. if (this.elements[i].key == _key) {
  435. return true;
  436. }
  437. }
  438. } catch (e) {
  439. return false;
  440. }
  441. return false;
  442. }
  443. this.values = function(){
  444. var arr = new Array();
  445. for (i = 0; i < this.elements.length; i++) {
  446. arr.push(this.elements[i].value);
  447. }
  448. return arr;
  449. }
  450. this.keys = function(){
  451. var arr = new Array();
  452. for (i = 0; i < this.elements.length; i++) {
  453. arr.push(this.elements[i].key);
  454. }
  455. return arr;
  456. }
  457. }
  458. /**
  459. * @author ZhangHuihua@msn.com
  460. * ----------------------------------------------------------
  461. * These functions use the same 'format' strings as the
  462. * java.text.SimpleDateFormat class, with minor exceptions.
  463. * The format string consists of the following abbreviations:
  464. *
  465. * Field | Full Form | Short Form
  466. * -------------+--------------------+-----------------------
  467. * Year | yyyy (4 digits) | yy (2 digits), y (2 or 4 digits)
  468. * Month | MMM (name or abbr.)| MM (2 digits), M (1 or 2 digits)
  469. * | NNN (abbr.) |
  470. * Day of Month | dd (2 digits) | d (1 or 2 digits)
  471. * Day of Week | EE (name) | E (abbr)
  472. * Hour (1-12) | hh (2 digits) | h (1 or 2 digits)
  473. * Hour (0-23) | HH (2 digits) | H (1 or 2 digits)
  474. * Hour (0-11) | KK (2 digits) | K (1 or 2 digits)
  475. * Hour (1-24) | kk (2 digits) | k (1 or 2 digits)
  476. * Minute | mm (2 digits) | m (1 or 2 digits)
  477. * Second | ss (2 digits) | s (1 or 2 digits)
  478. * AM/PM | a |
  479. *
  480. * NOTE THE DIFFERENCE BETWEEN MM and mm! Month=MM, not mm!
  481. * Examples:
  482. * "MMM d, y" matches: January 01, 2000
  483. * Dec 1, 1900
  484. * Nov 20, 00
  485. * "M/d/yy" matches: 01/20/00
  486. * 9/2/00
  487. * "MMM dd, yyyy hh:mm:ssa" matches: "January 01, 2000 12:30:45AM"
  488. * ----------------------------------------------------------
  489. */
  490. (function(){
  491. var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
  492. var DAY_NAMES=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat');
  493. function LZ(x) {return(x<0||x>9?"":"0")+x}
  494. /**
  495. * formatDate (date_object, format)
  496. * Returns a date in the output format specified.
  497. * The format string uses the same abbreviations as in parseDate()
  498. * @param {Object} date
  499. * @param {Object} format
  500. */
  501. function formatDate(date,format) {
  502. format=format+"";
  503. var result="";
  504. var i_format=0;
  505. var c="";
  506. var token="";
  507. var y=date.getYear()+"";
  508. var M=date.getMonth()+1;
  509. var d=date.getDate();
  510. var E=date.getDay();
  511. var H=date.getHours();
  512. var m=date.getMinutes();
  513. var s=date.getSeconds();
  514. var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
  515. // Convert real date parts into formatted versions
  516. var value={};
  517. if (y.length < 4) {y=""+(y-0+1900);}
  518. value["y"]=""+y;
  519. value["yyyy"]=y;
  520. value["yy"]=y.substring(2,4);
  521. value["M"]=M;
  522. value["MM"]=LZ(M);
  523. value["MMM"]=MONTH_NAMES[M-1];
  524. value["NNN"]=MONTH_NAMES[M+11];
  525. value["d"]=d;
  526. value["dd"]=LZ(d);
  527. value["E"]=DAY_NAMES[E+7];
  528. value["EE"]=DAY_NAMES[E];
  529. value["H"]=H;
  530. value["HH"]=LZ(H);
  531. if (H==0){value["h"]=12;}
  532. else if (H>12){value["h"]=H-12;}
  533. else {value["h"]=H;}
  534. value["hh"]=LZ(value["h"]);
  535. if (H>11){value["K"]=H-12;} else {value["K"]=H;}
  536. value["k"]=H+1;
  537. value["KK"]=LZ(value["K"]);
  538. value["kk"]=LZ(value["k"]);
  539. if (H > 11) { value["a"]="PM"; }
  540. else { value["a"]="AM"; }
  541. value["m"]=m;
  542. value["mm"]=LZ(m);
  543. value["s"]=s;
  544. value["ss"]=LZ(s);
  545. while (i_format < format.length) {
  546. c=format.charAt(i_format);
  547. token="";
  548. while ((format.charAt(i_format)==c) && (i_format < format.length)) {
  549. token += format.charAt(i_format++);
  550. }
  551. if (value[token] != null) { result += value[token]; }
  552. else { result += token; }
  553. }
  554. return result;
  555. }
  556. function _isInteger(val) {
  557. return (new RegExp(/^\d+$/).test(val));
  558. }
  559. function _getInt(str,i,minlength,maxlength) {
  560. for (var x=maxlength; x>=minlength; x--) {
  561. var token=str.substring(i,i+x);
  562. if (token.length < minlength) { return null; }
  563. if (_isInteger(token)) { return token; }
  564. }
  565. return null;
  566. }
  567. /**
  568. * parseDate( date_string , format_string )
  569. *
  570. * This function takes a date string and a format string. It matches
  571. * If the date string matches the format string, it returns the date.
  572. * If it does not match, it returns 0.
  573. * @param {Object} val
  574. * @param {Object} format
  575. */
  576. function parseDate(val,format) {
  577. val=val+"";
  578. format=format+"";
  579. var i_val=0;
  580. var i_format=0;
  581. var c="";
  582. var token="";
  583. var token2="";
  584. var x,y;
  585. var now=new Date(1900,0,1);
  586. var year=now.getYear();
  587. var month=now.getMonth()+1;
  588. var date=1;
  589. var hh=now.getHours();
  590. var mm=now.getMinutes();
  591. var ss=now.getSeconds();
  592. var ampm="";
  593. while (i_format < format.length) {
  594. // Get next token from format string
  595. c=format.charAt(i_format);
  596. token="";
  597. while ((format.charAt(i_format)==c) && (i_format < format.length)) {
  598. token += format.charAt(i_format++);
  599. }
  600. // Extract contents of value based on format token
  601. if (token=="yyyy" || token=="yy" || token=="y") {
  602. if (token=="yyyy") { x=4;y=4; }
  603. if (token=="yy") { x=2;y=2; }
  604. if (token=="y") { x=2;y=4; }
  605. year=_getInt(val,i_val,x,y);
  606. if (year==null) { return 0; }
  607. i_val += year.length;
  608. if (year.length==2) {
  609. if (year > 70) { year=1900+(year-0); }
  610. else { year=2000+(year-0); }
  611. }
  612. } else if (token=="MMM"||token=="NNN"){
  613. month=0;
  614. for (var i=0; i<MONTH_NAMES.length; i++) {
  615. var month_name=MONTH_NAMES[i];
  616. if (val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase()) {
  617. if (token=="MMM"||(token=="NNN"&&i>11)) {
  618. month=i+1;
  619. if (month>12) { month -= 12; }
  620. i_val += month_name.length;
  621. break;
  622. }
  623. }
  624. }
  625. if ((month < 1)||(month>12)){return 0;}
  626. } else if (token=="EE"||token=="E"){
  627. for (var i=0; i<DAY_NAMES.length; i++) {
  628. var day_name=DAY_NAMES[i];
  629. if (val.substring(i_val,i_val+day_name.length).toLowerCase()==day_name.toLowerCase()) {
  630. i_val += day_name.length;
  631. break;
  632. }
  633. }
  634. } else if (token=="MM"||token=="M") {
  635. month=_getInt(val,i_val,token.length,2);
  636. if(month==null||(month<1)||(month>12)){return 0;}
  637. i_val+=month.length;
  638. } else if (token=="dd"||token=="d") {
  639. date=_getInt(val,i_val,token.length,2);
  640. if(date==null||(date<1)||(date>31)){return 0;}
  641. i_val+=date.length;
  642. } else if (token=="hh"||token=="h") {
  643. hh=_getInt(val,i_val,token.length,2);
  644. if(hh==null||(hh<1)||(hh>12)){return 0;}
  645. i_val+=hh.length;
  646. } else if (token=="HH"||token=="H") {
  647. hh=_getInt(val,i_val,token.length,2);
  648. if(hh==null||(hh<0)||(hh>23)){return 0;}
  649. i_val+=hh.length;}
  650. else if (token=="KK"||token=="K") {
  651. hh=_getInt(val,i_val,token.length,2);
  652. if(hh==null||(hh<0)||(hh>11)){return 0;}
  653. i_val+=hh.length;
  654. } else if (token=="kk"||token=="k") {
  655. hh=_getInt(val,i_val,token.length,2);
  656. if(hh==null||(hh<1)||(hh>24)){return 0;}
  657. i_val+=hh.length;hh--;
  658. } else if (token=="mm"||token=="m") {
  659. mm=_getInt(val,i_val,token.length,2);
  660. if(mm==null||(mm<0)||(mm>59)){return 0;}
  661. i_val+=mm.length;
  662. } else if (token=="ss"||token=="s") {
  663. ss=_getInt(val,i_val,token.length,2);
  664. if(ss==null||(ss<0)||(ss>59)){return 0;}
  665. i_val+=ss.length;
  666. } else if (token=="a") {
  667. if (val.substring(i_val,i_val+2).toLowerCase()=="am") {ampm="AM";}
  668. else if (val.substring(i_val,i_val+2).toLowerCase()=="pm") {ampm="PM";}
  669. else {return 0;}
  670. i_val+=2;
  671. } else {
  672. if (val.substring(i_val,i_val+token.length)!=token) {return 0;}
  673. else {i_val+=token.length;}
  674. }
  675. }
  676. // If there are any trailing characters left in the value, it doesn't match
  677. if (i_val != val.length) { return 0; }
  678. // Is date valid for month?
  679. if (month==2) {
  680. // Check for leap year
  681. if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year
  682. if (date > 29){ return 0; }
  683. } else { if (date > 28) { return 0; } }
  684. }
  685. if ((month==4)||(month==6)||(month==9)||(month==11)) {
  686. if (date > 30) { return 0; }
  687. }
  688. // Correct hours value
  689. if (hh<12 && ampm=="PM") { hh=hh-0+12; }
  690. else if (hh>11 && ampm=="AM") { hh-=12; }
  691. return new Date(year,month-1,date,hh,mm,ss);
  692. }
  693. Date.prototype.formatDate = function(dateFmt) {
  694. return formatDate(this, dateFmt);
  695. };
  696. String.prototype.parseDate = function(dateFmt) {
  697. if (this.length < dateFmt.length) {
  698. dateFmt = dateFmt.slice(0,this.length);
  699. }
  700. return parseDate(this, dateFmt);
  701. };
  702. /**
  703. * replaceTmEval("{1+2}-{2-1}")
  704. */
  705. function replaceTmEval(data){
  706. return data.replace(RegExp("({[A-Za-z0-9_+-]*})","g"), function($1){
  707. return eval('(' + $1.replace(/[{}]+/g, "") + ')');
  708. });
  709. }
  710. /**
  711. * dateFmt:%y-%M-%d
  712. * %y-%M-{%d+1}
  713. * ex: new Date().formatDateTm('%y-%M-{%d-1}')
  714. * new Date().formatDateTm('2012-1')
  715. */
  716. Date.prototype.formatDateTm = function(dateFmt) {
  717. var y = this.getFullYear();
  718. var m = this.getMonth()+1;
  719. var d = this.getDate();
  720. var sDate = dateFmt.replaceAll("%y",y).replaceAll("%M",m).replaceAll("%d",d);
  721. sDate = replaceTmEval(sDate);
  722. var _y=1900, _m=0, _d=1;
  723. var aDate = sDate.split('-');
  724. if (aDate.length > 0) _y = aDate[0];
  725. if (aDate.length > 1) _m = aDate[1]-1;
  726. if (aDate.length > 2) _d = aDate[2];
  727. return new Date(_y,_m,_d).formatDate('yyyy-MM-dd');
  728. };
  729. })();
  730. /**
  731. * @requires jquery.validate.js
  732. * @author ZhangHuihua@msn.com
  733. */
  734. (function($){
  735. if ($.validator) {
  736. $.validator.addMethod("alphanumeric", function(value, element) {
  737. return this.optional(element) || /^\w+$/i.test(value);
  738. }, "Letters, numbers or underscores only please");
  739. $.validator.addMethod("lettersonly", function(value, element) {
  740. return this.optional(element) || /^[a-z]+$/i.test(value);
  741. }, "Letters only please");
  742. $.validator.addMethod("phone", function(value, element) {
  743. return this.optional(element) || /^[0-9 \(\)]{7,30}$/.test(value);
  744. }, "Please specify a valid phone number");
  745. $.validator.addMethod("postcode", function(value, element) {
  746. return this.optional(element) || /^[0-9 A-Za-z]{5,20}$/.test(value);
  747. }, "Please specify a valid postcode");
  748. $.validator.addMethod("date", function(value, element) {
  749. value = value.replace(/\s+/g, "");
  750. if (String.prototype.parseDate){
  751. var $input = $(element);
  752. var pattern = $input.attr('dateFmt') || 'yyyy-MM-dd';
  753. return !$input.val() || $input.val().parseDate(pattern);
  754. } else {
  755. return this.optional(element) || value.match(/^\d{4}[\/-]\d{1,2}[\/-]\d{1,2}$/);
  756. }
  757. }, "Please enter a valid date.");
  758. /*自定义js函数验证
  759. * <input type="text" name="xxx" customvalid="xxxFn(element)" title="xxx" />
  760. */
  761. $.validator.addMethod("customvalid", function(value, element, params) {
  762. try{
  763. return eval('(' + params + ')');
  764. }catch(e){
  765. return false;
  766. }
  767. }, "Please fix this field.");
  768. $.validator.addClassRules({
  769. date: {date: true},
  770. alphanumeric: { alphanumeric: true },
  771. lettersonly: { lettersonly: true },
  772. phone: { phone: true },
  773. postcode: {postcode: true}
  774. });
  775. $.validator.setDefaults({errorElement:"span"});
  776. $.validator.autoCreateRanges = true;
  777. }
  778. })(jQuery);/**
  779. * @author Roger Wu
  780. * @version 1.0
  781. */
  782. (function($){
  783. $.fn.cssv = function(pre){
  784. var cssPre = $(this).css(pre);
  785. return cssPre.substring(0, cssPre.indexOf("px")) * 1;
  786. };
  787. $.fn.jBar = function(options){
  788. var op = $.extend({container:"#container", collapse:".collapse", toggleBut:".toggleCollapse div", sideBar:"#sidebar", sideBar2:"#sidebar_s", splitBar:"#splitBar", splitBar2:"#splitBarProxy"}, options);
  789. return this.each(function(){
  790. var jbar = this;
  791. var sbar = $(op.sideBar2, jbar);
  792. var bar = $(op.sideBar, jbar);
  793. $(op.toggleBut, bar).click(function(){
  794. DWZ.ui.sbar = false;
  795. $(op.splitBar).hide();
  796. var sbarwidth = sbar.cssv("left") + sbar.outerWidth();
  797. var barleft = sbarwidth - bar.outerWidth();
  798. var cleft = $(op.container).cssv("left") - (bar.outerWidth() - sbar.outerWidth());
  799. var cwidth = bar.outerWidth() - sbar.outerWidth() + $(op.container).outerWidth();
  800. $(op.container).animate({left: cleft,width: cwidth},50,function(){
  801. bar.animate({left: barleft}, 500, function(){
  802. bar.hide();
  803. sbar.show().css("left", -50).animate({left: 5}, 200);
  804. $(window).trigger(DWZ.eventType.resizeGrid);
  805. });
  806. });
  807. $(op.collapse,sbar).click(function(){
  808. var sbarwidth = sbar.cssv("left") + sbar.outerWidth();
  809. if(bar.is(":hidden")) {
  810. $(op.toggleBut, bar).hide();
  811. bar.show().animate({left: sbarwidth}, 500);
  812. $(op.container).click(_hideBar);
  813. } else {
  814. bar.animate({left: barleft}, 500, function(){
  815. bar.hide();
  816. });
  817. }
  818. function _hideBar() {
  819. $(op.container).unbind("click", _hideBar);
  820. if (!DWZ.ui.sbar) {
  821. bar.animate({left: barleft}, 500, function(){
  822. bar.hide();
  823. });
  824. }
  825. }
  826. return false;
  827. });
  828. return false;
  829. });
  830. $(op.toggleBut, sbar).click(function(){
  831. DWZ.ui.sbar = true;
  832. sbar.animate({left: -25}, 200, function(){
  833. bar.show();
  834. });
  835. bar.animate({left: 5}, 800, function(){
  836. $(op.splitBar).show();
  837. $(op.toggleBut, bar).show();
  838. var cleft = 5 + bar.outerWidth() + $(op.splitBar).outerWidth();
  839. var cwidth = $(op.container).outerWidth() - (cleft - $(op.container).cssv("left"));
  840. $(op.container).css({left: cleft,width: cwidth});
  841. $(op.collapse, sbar).unbind('click');
  842. $(window).trigger(DWZ.eventType.resizeGrid);
  843. });
  844. return false;
  845. });
  846. $(op.splitBar).mousedown(function(event){
  847. $(op.splitBar2).each(function(){
  848. var spbar2 = $(this);
  849. setTimeout(function(){spbar2.show();}, 100);
  850. spbar2.css({visibility: "visible",left: $(op.splitBar).css("left")});
  851. spbar2.jDrag($.extend(options, {obj:$("#sidebar"), move:"horizontal", event:event,stop: function(){
  852. $(this).css("visibility", "hidden");
  853. var move = $(this).cssv("left") - $(op.splitBar).cssv("left");
  854. var sbarwidth = bar.outerWidth() + move;
  855. var cleft = $(op.container).cssv("left") + move;
  856. var cwidth = $(op.container).outerWidth() - move;
  857. bar.css("width", sbarwidth);
  858. $(op.splitBar).css("left", $(this).css("left"));
  859. $(op.container).css({left: cleft,width: cwidth});
  860. }}));
  861. return false;
  862. });
  863. });
  864. });
  865. }
  866. })(jQuery);
  867. /**
  868. * @author Roger Wu
  869. */
  870. (function($){
  871. $.fn.jDrag = function(options){
  872. if (typeof options == 'string') {
  873. if (options == 'destroy')
  874. return this.each(function(){
  875. $(this).unbind('mousedown', $.rwdrag.start);
  876. $.data(this, 'pp-rwdrag', null);
  877. });
  878. }
  879. return this.each(function(){
  880. var el = $(this);
  881. $.data($.rwdrag, 'pp-rwdrag', {
  882. options: $.extend({
  883. el: el,
  884. obj: el
  885. }, options)
  886. });
  887. if (options.event)
  888. $.rwdrag.start(options.event);
  889. else {
  890. var select = options.selector;
  891. $(select, obj).bind('mousedown', $.rwdrag.start);
  892. }
  893. });
  894. };
  895. $.rwdrag = {
  896. start: function(e){
  897. document.onselectstart=function(e){return false};//禁止选择
  898. var data = $.data(this, 'pp-rwdrag');
  899. var el = data.options.el[0];
  900. $.data(el, 'pp-rwdrag', {
  901. options: data.options
  902. });
  903. if (!$.rwdrag.current) {
  904. $.rwdrag.current = {
  905. el: el,
  906. oleft: parseInt(el.style.left) || 0,
  907. otop: parseInt(el.style.top) || 0,
  908. ox: e.pageX || e.screenX,
  909. oy: e.pageY || e.screenY
  910. };
  911. $(document).bind("mouseup", $.rwdrag.stop).bind("mousemove", $.rwdrag.drag);
  912. }
  913. },
  914. drag: function(e){
  915. if (!e) var e = window.event;
  916. var current = $.rwdrag.current;
  917. var data = $.data(current.el, 'pp-rwdrag');
  918. var left = (current.oleft + (e.pageX || e.clientX) - current.ox);
  919. var top = (current.otop + (e.pageY || e.clientY) - current.oy);
  920. if (top < 1) top = 0;
  921. if (data.options.move == 'horizontal') {
  922. if ((data.options.minW && left >= $(data.options.obj).cssv("left") + data.options.minW) && (data.options.maxW && left <= $(data.options.obj).cssv("left") + data.options.maxW))
  923. current.el.style.left = left + 'px';
  924. else if (data.options.scop) {
  925. if (data.options.relObj) {
  926. if ((left - parseInt(data.options.relObj.style.left)) > data.options.cellMinW) {
  927. current.el.style.left = left + 'px';
  928. }
  929. } else
  930. current.el.style.left = left + 'px';
  931. }
  932. } else if (data.options.move == 'vertical') {
  933. current.el.style.top = top + 'px';
  934. } else {
  935. var selector = data.options.selector ? $(data.options.selector, data.options.obj) : $(data.options.obj);
  936. if (left >= -selector.outerWidth() * 2 / 3 && top >= 0 && (left + selector.outerWidth() / 3 < $(window).width()) && (top + selector.outerHeight() < $(window).height())) {
  937. current.el.style.left = left + 'px';
  938. current.el.style.top = top + 'px';
  939. }
  940. }
  941. if (data.options.drag) {
  942. data.options.drag.apply(current.el, [current.el, e]);
  943. }
  944. return $.rwdrag.preventEvent(e);
  945. },
  946. stop: function(e){
  947. var current = $.rwdrag.current;
  948. var data = $.data(current.el, 'pp-rwdrag');
  949. $(document).unbind('mousemove', $.rwdrag.drag).unbind('mouseup', $.rwdrag.stop);
  950. if (data.options.stop) {
  951. data.options.stop.apply(current.el, [current.el, e]);
  952. }
  953. $.rwdrag.current = null;
  954. document.onselectstart=function(e){return true};//启用选择
  955. return $.rwdrag.preventEvent(e);
  956. },
  957. preventEvent:function(e){
  958. if (e.stopPropagation) e.stopPropagation();
  959. if (e.preventDefault) e.preventDefault();
  960. return false;
  961. }
  962. };
  963. })(jQuery);
  964. /**
  965. * @author Roger Wu
  966. * @version 1.0
  967. * added extend property oncheck
  968. */
  969. (function($){
  970. $.extend($.fn, {
  971. jTree:function(options) {
  972. var op = $.extend({checkFn:null, selected:"selected", exp:"expandable", coll:"collapsable", firstExp:"first_expandable", firstColl:"first_collapsable", lastExp:"last_expandable", lastColl:"last_collapsable", folderExp:"folder_expandable", folderColl:"folder_collapsable", endExp:"end_expandable", endColl:"end_collapsable",file:"file",ck:"checked", unck:"unchecked"}, options);
  973. return this.each(function(){
  974. var $this = $(this);
  975. var cnum = $this.children().length;
  976. $(">li", $this).each(function(){
  977. var $li = $(this);
  978. var first = $li.prev()[0]?false:true;
  979. var last = $li.next()[0]?false:true;
  980. $li.genTree({
  981. icon:$this.hasClass("treeFolder"),
  982. ckbox:$this.hasClass("treeCheck"),
  983. options: op,
  984. level: 0,
  985. exp:(cnum>1?(first?op.firstExp:(last?op.lastExp:op.exp)):op.endExp),
  986. coll:(cnum>1?(first?op.firstColl:(last?op.lastColl:op.coll)):op.endColl),
  987. showSub:(!$this.hasClass("collapse") && ($this.hasClass("expand") || (cnum>1?(first?true:false):true))),
  988. isLast:(cnum>1?(last?true:false):true)
  989. });
  990. });
  991. setTimeout(function(){
  992. if($this.hasClass("treeCheck")){
  993. var checkFn = eval($this.attr("oncheck"));
  994. if(checkFn && $.isFunction(checkFn)) {
  995. $("div.ckbox", $this).each(function(){
  996. var ckbox = $(this);
  997. ckbox.click(function(){
  998. var checked = $(ckbox).hasClass("checked");
  999. var items = [];
  1000. if(checked){
  1001. var tnode = $(ckbox).parent().parent();
  1002. var boxes = $("input", tnode);
  1003. if(boxes.size() > 1) {
  1004. $(boxes).each(function(){
  1005. items[items.length] = {name:$(this).attr("name"), value:$(this).val(), text:$(this).attr("text")};
  1006. });
  1007. } else {
  1008. items = {name:boxes.attr("name"), value:boxes.val(), text:boxes.attr("text")};
  1009. }
  1010. }
  1011. checkFn({checked:checked, items:items});
  1012. });
  1013. });
  1014. }
  1015. }
  1016. $("a", $this).click(function(event){
  1017. $("div." + op.selected, $this).removeClass(op.selected);
  1018. var parent = $(this).parent().addClass(op.selected);
  1019. var $li = $(this).parents("li:first"), sTarget = $li.attr("target");
  1020. if (sTarget) {
  1021. if ($("#"+sTarget, $this).size() == 0) {
  1022. $this.prepend('<input id="'+sTarget+'" type="hidden" />');
  1023. }
  1024. $("#"+sTarget, $this).val($li.attr("rel"));
  1025. }
  1026. $(".ckbox",parent).trigger("click");
  1027. event.stopPropagation();
  1028. $(document).trigger("click");
  1029. if (!$(this).attr("target")) return false;
  1030. });
  1031. },1);
  1032. });
  1033. },
  1034. subTree:function(op, level) {
  1035. return this.each(function(){
  1036. $(">li", this).each(function(){
  1037. var $this = $(this);
  1038. var isLast = ($this.next()[0]?false:true);
  1039. $this.genTree({
  1040. icon:op.icon,
  1041. ckbox:op.ckbox,
  1042. exp:isLast?op.options.lastExp:op.options.exp,
  1043. coll:isLast?op.options.lastColl:op.options.coll,
  1044. options:op.options,
  1045. level:level,
  1046. space:isLast?null:op.space,
  1047. showSub:op.showSub,
  1048. isLast:isLast
  1049. });
  1050. });
  1051. });
  1052. },
  1053. genTree:function(options) {
  1054. var op = $.extend({icon:options.icon,ckbox:options.ckbox,exp:"", coll:"", showSub:false, level:0, options:null, isLast:false}, options);
  1055. return this.each(function(){
  1056. var node = $(this);
  1057. var tree = $(">ul", node);
  1058. var parent = node.parent().prev();
  1059. var checked = 'unchecked';
  1060. if(op.ckbox) {
  1061. if($(">.checked",parent).size() > 0) checked = 'checked';
  1062. }
  1063. if (tree.size()>0) {
  1064. node.children(":first").wrap("<div></div>");
  1065. $(">div", node).prepend("<div class='" + (op.showSub ? op.coll : op.exp) + "'></div>"+(op.ckbox ?"<div class='ckbox " + checked + "'></div>":"")+(op.icon?"<div class='"+ (op.showSub ? op.options.folderColl : op.options.folderExp) +"'></div>":""));
  1066. op.showSub ? tree.show() : tree.hide();
  1067. $(">div>div:first,>div>a", node).click(function(){
  1068. var $fnode = $(">li:first",tree);
  1069. if($fnode.children(":first").isTag('a')) tree.subTree(op, op.level + 1);
  1070. var $this = $(this);
  1071. var isA = $this.isTag('a');
  1072. var $this = isA?$(">div>div", node).eq(op.level):$this;
  1073. if (!isA || tree.is(":hidden")) {
  1074. $this.toggleClass(op.exp).toggleClass(op.coll);
  1075. if (op.icon) {
  1076. $(">div>div:last", node).toggleClass(op.options.folderExp).toggleClass(op.options.folderColl);
  1077. }
  1078. }
  1079. (tree.is(":hidden"))?tree.slideDown("fast"):(isA?"":tree.slideUp("fast"));
  1080. return false;
  1081. });
  1082. addSpace(op.level, node);
  1083. if(op.showSub) tree.subTree(op, op.level + 1);
  1084. } else {
  1085. node.children().wrap("<div></div>");
  1086. $(">div", node).prepend("<div class='node'></div>"+(op.ckbox?"<div class='ckbox "+checked+"'></div>":"")+(op.icon?"<div class='file'></div>":""));
  1087. addSpace(op.level, node);
  1088. if(op.isLast)$(node).addClass("last");
  1089. }
  1090. if (op.ckbox) node._check(op);
  1091. $(">div",node).mouseover(function(){
  1092. $(this).addClass("hover");
  1093. }).mouseout(function(){
  1094. $(this).removeClass("hover");
  1095. });
  1096. if(/msie/.test(navigator.userAgent.toLowerCase()))
  1097. $(">div",node).click(function(){
  1098. $("a", this).trigger("click");
  1099. return false;
  1100. });
  1101. });
  1102. function addSpace(level,node) {
  1103. if (level > 0) {
  1104. var parent = node.parent().parent();
  1105. var space = !parent.next()[0]?"indent":"line";
  1106. var plist = "<div class='" + space + "'></div>";
  1107. if (level > 1) {
  1108. var next = $(">div>div", parent).filter(":first");
  1109. var prev = "";
  1110. while(level > 1){
  1111. prev = prev + "<div class='" + next.attr("class") + "'></div>";
  1112. next = next.next();
  1113. level--;
  1114. }
  1115. plist = prev + plist;
  1116. }
  1117. $(">div", node).prepend(plist);
  1118. }
  1119. }
  1120. },
  1121. _check:function(op) {
  1122. var node = $(this);
  1123. var ckbox = $(">div>.ckbox", node);
  1124. var $input = node.find("a");
  1125. var tname = $input.attr("tname"), tvalue = $input.attr("tvalue");
  1126. var attrs = "text='"+$input.text()+"' ";
  1127. if (tname) attrs += "name='"+tname+"' ";
  1128. if (tvalue) attrs += "value='"+tvalue+"' ";
  1129. ckbox.append("<input type='checkbox' style='display:none;' " + attrs + "/>").click(function(){
  1130. var cked = ckbox.hasClass("checked");
  1131. var aClass = cked?"unchecked":"checked";
  1132. var rClass = cked?"checked":"unchecked";
  1133. ckbox.removeClass(rClass).removeClass(!cked?"indeterminate":"").addClass(aClass);
  1134. $("input", ckbox).attr("checked", !cked);
  1135. $(">ul", node).find("li").each(function(){
  1136. var box = $("div.ckbox", this);
  1137. box.removeClass(rClass).removeClass(!cked?"indeterminate":"").addClass(aClass)
  1138. .find("input").attr("checked", !cked);
  1139. });
  1140. $(node)._checkParent();
  1141. return false;
  1142. });
  1143. var cAttr = $input.attr("checked") || false;
  1144. if (cAttr) {
  1145. ckbox.find("input").attr("checked", true);
  1146. ckbox.removeClass("unchecked").addClass("checked");
  1147. $(node)._checkParent();
  1148. }
  1149. },
  1150. _checkParent:function(){
  1151. if($(this).parent().hasClass("tree")) return;
  1152. var parent = $(this).parent().parent();
  1153. var stree = $(">ul", parent);
  1154. var ckbox = stree.find(">li>a").size()+stree.find("div.ckbox").size();
  1155. var ckboxed = stree.find("div.checked").size();
  1156. var aClass = (ckboxed==ckbox?"checked":(ckboxed!=0?"indeterminate":"unchecked"));
  1157. var rClass = (ckboxed==ckbox?"indeterminate":(ckboxed!=0?"checked":"indeterminate"));
  1158. $(">div>.ckbox", parent).removeClass("unchecked").removeClass("checked").removeClass(rClass).addClass(aClass);
  1159. var $checkbox = $(":checkbox", parent);
  1160. if (aClass == "checked") $checkbox.attr("checked","checked");
  1161. else if (aClass == "unchecked") $checkbox.removeAttr("checked");
  1162. parent._checkParent();
  1163. }
  1164. });
  1165. })(jQuery);/**
  1166. * @author Roger Wu
  1167. */
  1168. (function($) {
  1169. var jmenus = new Map();
  1170. // If the DWZ scope is not available, add it
  1171. $.dwz = $.dwz || {};
  1172. $(window).resize(function(){
  1173. setTimeout(function(){
  1174. for (var i=0; i<jmenus.size();i++){
  1175. fillSpace(jmenus.element(i).key);
  1176. }
  1177. }, 100);
  1178. });
  1179. $.fn.extend({
  1180. accordion: function(options, data) {
  1181. var args = Array.prototype.slice.call(arguments, 1);
  1182. return this.each(function() {
  1183. if (options.fillSpace) jmenus.put(options.fillSpace, this);
  1184. if (typeof options == "string") {
  1185. var accordion = $.data(this, "dwz-accordion");
  1186. accordion[options].apply(accordion, args);
  1187. // INIT with optional options
  1188. } else if (!$(this).is(".dwz-accordion"))
  1189. $.data(this, "dwz-accordion", new $.dwz.accordion(this, options));
  1190. });
  1191. },
  1192. /**
  1193. * deprecated, use accordion("activate", index) instead
  1194. * @param {Object} index
  1195. */
  1196. activate: function(index) {
  1197. return this.accordion("activate", index);
  1198. }
  1199. });
  1200. $.dwz.accordion = function(container, options) {
  1201. // setup configuration
  1202. this.options = options = $.extend({}, $.dwz.accordion.defaults, options);
  1203. this.element = container;
  1204. $(container).addClass("dwz-accordion");
  1205. if ( options.navigation ) {
  1206. var current = $(container).find("a").filter(options.navigationFilter);
  1207. if ( current.length ) {
  1208. if ( current.filter(options.header).length ) {
  1209. options.active = current;
  1210. } else {
  1211. options.active = current.parent().parent().prev();
  1212. current.addClass("current");
  1213. }
  1214. }
  1215. }
  1216. // calculate active if not specified, using the first header
  1217. options.headers = $(container).find(options.header);
  1218. options.active = findActive(options.headers, options.active);
  1219. if ( options.fillSpace ) {
  1220. fillSpace(options.fillSpace);
  1221. } else if ( options.autoheight ) {
  1222. var maxHeight = 0;
  1223. options.headers.next().each(function() {
  1224. maxHeight = Math.max(maxHeight, $(this).outerHeight());
  1225. }).height(maxHeight);
  1226. }
  1227. options.headers
  1228. .not(options.active || "")
  1229. .next()
  1230. .hide();
  1231. options.active.find("h2").addClass(options.selectedClass);
  1232. if (options.event)
  1233. $(container).bind((options.event) + ".dwz-accordion", clickHandler);
  1234. };
  1235. $.dwz.accordion.prototype = {
  1236. activate: function(index) {
  1237. // call clickHandler with custom event
  1238. clickHandler.call(this.element, {
  1239. target: findActive( this.options.headers, index )[0]
  1240. });
  1241. },
  1242. enable: function() {
  1243. this.options.disabled = false;
  1244. },
  1245. disable: function() {
  1246. this.options.disabled = true;
  1247. },
  1248. destroy: function() {
  1249. this.options.headers.next().css("display", "");
  1250. if ( this.options.fillSpace || this.options.autoheight ) {
  1251. this.options.headers.next().css("height", "");
  1252. }
  1253. $.removeData(this.element, "dwz-accordion");
  1254. $(this.element).removeClass("dwz-accordion").unbind(".dwz-accordion");
  1255. }
  1256. }
  1257. function scopeCallback(callback, scope) {
  1258. return function() {
  1259. return callback.apply(scope, arguments);
  1260. };
  1261. }
  1262. function completed(cancel) {
  1263. // if removed while animated data can be empty
  1264. if (!$.data(this, "dwz-accordion"))
  1265. return;
  1266. var instance = $.data(this, "dwz-accordion");
  1267. var options = instance.options;
  1268. options.running = cancel ? 0 : --options.running;
  1269. if ( options.running )
  1270. return;
  1271. if ( options.clearStyle ) {
  1272. options.toShow.add(options.toHide).css({
  1273. height: "",
  1274. overflow: ""
  1275. });
  1276. }
  1277. $(this).triggerHandler("change.dwz-accordion", [options.data], options.change);
  1278. }
  1279. function fillSpace(key){
  1280. var obj = jmenus.get(key);
  1281. if (!obj) return;
  1282. var parent = $(obj).parent();
  1283. var height = parent.height() - (($(".accordionHeader", obj).size()) * ($(".accordionHeader:first-child", obj).outerHeight())) -2;
  1284. var os = parent.children().not(obj);
  1285. $.each(os, function(i){
  1286. height -= $(os[i]).outerHeight();
  1287. });
  1288. $(".accordionContent",obj).height(height);
  1289. }
  1290. function toggle(toShow, toHide, data, clickedActive, down) {
  1291. var options = $.data(this, "dwz-accordion").options;
  1292. options.toShow = toShow;
  1293. options.toHide = toHide;
  1294. options.data = data;
  1295. var complete = scopeCallback(completed, this);
  1296. // count elements to animate
  1297. options.running = toHide.size() == 0 ? toShow.size() : toHide.size();
  1298. if ( options.animated ) {
  1299. if ( !options.alwaysOpen && clickedActive ) {
  1300. $.dwz.accordion.animations[options.animated]({
  1301. toShow: jQuery([]),
  1302. toHide: toHide,
  1303. complete: complete,
  1304. down: down,
  1305. autoheight: options.autoheight
  1306. });
  1307. } else {
  1308. $.dwz.accordion.animations[options.animated]({
  1309. toShow: toShow,
  1310. toHide: toHide,
  1311. complete: complete,
  1312. down: down,
  1313. autoheight: options.autoheight
  1314. });
  1315. }
  1316. } else {
  1317. if ( !options.alwaysOpen && clickedActive ) {
  1318. toShow.toggle();
  1319. } else {
  1320. toHide.hide();
  1321. toShow.show();
  1322. }
  1323. complete(true);
  1324. }
  1325. }
  1326. function clickHandler(event) {
  1327. var options = $.data(this, "dwz-accordion").options;
  1328. if (options.disabled)
  1329. return false;
  1330. // called only when using activate(false) to close all parts programmatically
  1331. if ( !event.target && !options.alwaysOpen ) {
  1332. options.active.find("h2").toggleClass(options.selectedClass);
  1333. var toHide = options.active.next(),
  1334. data = {
  1335. instance: this,
  1336. options: options,
  1337. newHeader: jQuery([]),
  1338. oldHeader: options.active,
  1339. newContent: jQuery([]),
  1340. oldContent: toHide
  1341. },
  1342. toShow = options.active = $([]);
  1343. toggle.call(this, toShow, toHide, data );
  1344. return false;
  1345. }
  1346. // get the click target
  1347. var clicked = $(event.target);
  1348. // due to the event delegation model, we have to check if one
  1349. // of the parent elements is our actual header, and find that
  1350. if ( clicked.parents(options.header).length )
  1351. while ( !clicked.is(options.header) )
  1352. clicked = clicked.parent();
  1353. var clickedActive = clicked[0] == options.active[0];
  1354. // if animations are still active, or the active header is the target, ignore click
  1355. if (options.running || (options.alwaysOpen && clickedActive))
  1356. return false;
  1357. if (!clicked.is(options.header))
  1358. return;
  1359. // switch classes
  1360. options.active.find("h2").toggleClass(options.selectedClass);
  1361. if ( !clickedActive ) {
  1362. clicked.find("h2").addClass(options.selectedClass);
  1363. }
  1364. // find elements to show and hide
  1365. var toShow = clicked.next(),
  1366. toHide = options.active.next(),
  1367. //data = [clicked, options.active, toShow, toHide],
  1368. data = {
  1369. instance: this,
  1370. options: options,
  1371. newHeader: clicked,
  1372. oldHeader: options.active,
  1373. newContent: toShow,
  1374. oldContent: toHide
  1375. },
  1376. down = options.headers.index( options.active[0] ) > options.headers.index( clicked[0] );
  1377. options.active = clickedActive ? $([]) : clicked;
  1378. toggle.call(this, toShow, toHide, data, clickedActive, down );
  1379. return false;
  1380. };
  1381. function findActive(headers, selector) {
  1382. return selector != undefined
  1383. ? typeof selector == "number"
  1384. ? headers.filter(":eq(" + selector + ")")
  1385. : headers.not(headers.not(selector))
  1386. : selector === false
  1387. ? $([])
  1388. : headers.filter(":eq(0)");
  1389. }
  1390. $.extend($.dwz.accordion, {
  1391. defaults: {
  1392. selectedClass: "collapsable",
  1393. alwaysOpen: true,
  1394. animated: 'slide',
  1395. event: "click",
  1396. header: ".accordionHeader",
  1397. autoheight: true,
  1398. running: 0,
  1399. navigationFilter: function() {
  1400. return this.href.toLowerCase() == location.href.toLowerCase();
  1401. }
  1402. },
  1403. animations: {
  1404. slide: function(options, additions) {
  1405. options = $.extend({
  1406. easing: "swing",
  1407. duration: 300
  1408. }, options, additions);
  1409. if ( !options.toHide.size() ) {
  1410. options.toShow.animate({height: "show"}, options);
  1411. return;
  1412. }
  1413. var hideHeight = options.toHide.height(),
  1414. showHeight = options.toShow.height(),
  1415. difference = showHeight / hideHeight;
  1416. options.toShow.css({ height: 0}).show();
  1417. options.toHide.filter(":hidden").each(options.complete).end().filter(":visible").animate({height:"hide"},{
  1418. step: function(now) {
  1419. var current = (hideHeight - now) * difference;
  1420. if (/msie|opera/.test(navigator.userAgent.toLowerCase())) {
  1421. current = Math.ceil(current);
  1422. }
  1423. options.toShow.height( current );
  1424. },
  1425. duration: options.duration,
  1426. easing: options.easing,
  1427. complete: function() {
  1428. if ( !options.autoheight ) {
  1429. options.toShow.css({height:"auto"});
  1430. }
  1431. options.toShow.css({overflow:"auto"});
  1432. options.complete();
  1433. }
  1434. });
  1435. },
  1436. bounceslide: function(options) {
  1437. this.slide(options, {
  1438. easing: options.down ? "bounceout" : "swing",
  1439. duration: options.down ? 1000 : 200
  1440. });
  1441. },
  1442. easeslide: function(options) {
  1443. this.slide(options, {
  1444. easing: "easeinout",
  1445. duration: 700
  1446. })
  1447. }
  1448. }
  1449. });
  1450. })(jQuery);
  1451. function initEnv() {
  1452. $("body").append(DWZ.frag["dwzFrag"]);
  1453. $(window).resize(function(){
  1454. initLayout();
  1455. $(this).trigger(DWZ.eventType.resizeGrid);
  1456. });
  1457. var ajaxbg = $("#background,#progressBar");
  1458. ajaxbg.hide();
  1459. $(document).ajaxStart(function(){
  1460. ajaxbg.show();
  1461. }).ajaxStop(function(){
  1462. ajaxbg.hide();
  1463. });
  1464. $("#leftside").jBar({minW:150, maxW:700});
  1465. if ($.taskBar) $.taskBar.init();
  1466. navTab.init();
  1467. if ($.fn.switchEnv) $("#switchEnvBox").switchEnv();
  1468. if ($.fn.navMenu) $("#navMenu").navMenu();
  1469. setTimeout(function(){
  1470. initLayout();
  1471. initUI();
  1472. // navTab styles
  1473. var jTabsPH = $("div.tabsPageHeader");
  1474. jTabsPH.find(".tabsLeft").hoverClass("tabsLeftHover");
  1475. jTabsPH.find(".tabsRight").hoverClass("tabsRightHover");
  1476. jTabsPH.find(".tabsMore").hoverClass("tabsMoreHover");
  1477. }, 10);
  1478. }
  1479. function initLayout(){
  1480. var iContentW = $(window).width() - (DWZ.ui.sbar ? $("#sidebar").width() + 10 : 34) - 5;
  1481. var iContentH = $(window).height() - $("#header").height() - 34;
  1482. $("#container").width(iContentW);
  1483. $("#container .tabsPageContent").height(iContentH - 34).find("[layoutH]").layoutH();
  1484. $("#sidebar, #sidebar_s .collapse, #splitBar, #splitBarProxy").height(iContentH - 5);
  1485. $("#taskbar").css({top: iContentH + $("#header").height() + 5, width:$(window).width()});
  1486. }
  1487. function initUI(_box){
  1488. var $p = $(_box || document);
  1489. $("div.panel", $p).jPanel();
  1490. //tables
  1491. $("table.table", $p).jTable();
  1492. // css tables
  1493. $('table.list', $p).cssTable();
  1494. //auto bind tabs
  1495. $("div.tabs", $p).each(function(){
  1496. var $this = $(this);
  1497. var options = {};
  1498. options.currentIndex = $this.attr("currentIndex") || 0;
  1499. options.eventType = $this.attr("eventType") || "click";
  1500. $this.tabs(options);
  1501. });
  1502. $("ul.tree", $p).jTree();
  1503. $('div.accordion', $p).each(function(){
  1504. var $this = $(this);
  1505. $this.accordion({fillSpace:$this.attr("fillSpace"),alwaysOpen:true,active:0});
  1506. });
  1507. $(":button.checkboxCtrl, :checkbox.checkboxCtrl", $p).checkboxCtrl($p);
  1508. if ($.fn.combox) $("select.combox",$p).combox();
  1509. if ($.fn.xheditor) {
  1510. $("textarea.editor", $p).each(function(){
  1511. var $this = $(this);
  1512. var op = {html5Upload:false, skin: 'vista',tools: $this.attr("tools") || 'full'};
  1513. var upAttrs = [
  1514. ["upLinkUrl","upLinkExt","zip,rar,txt"],
  1515. ["upImgUrl","upImgExt","jpg,jpeg,gif,png"],
  1516. ["upFlashUrl","upFlashExt","swf"],
  1517. ["upMediaUrl","upMediaExt","avi"]
  1518. ];
  1519. $(upAttrs).each(function(i){
  1520. var urlAttr = upAttrs[i][0];
  1521. var extAttr = upAttrs[i][1];
  1522. if ($this.attr(urlAttr)) {
  1523. op[urlAttr] = $this.attr(urlAttr);
  1524. op[extAttr] = $this.attr(extAttr) || upAttrs[i][2];
  1525. }
  1526. });
  1527. $this.xheditor(op);
  1528. });
  1529. }
  1530. if ($.fn.uploadify) {
  1531. $(":file[uploaderOption]", $p).each(function(){
  1532. var $this = $(this);
  1533. var options = {
  1534. fileObjName: $this.attr("name") || "file",
  1535. auto: true,
  1536. multi: true,
  1537. onUploadError: uploadifyError
  1538. };
  1539. var uploaderOption = DWZ.jsonEval($this.attr("uploaderOption"));
  1540. $.extend(options, uploaderOption);
  1541. DWZ.debug("uploaderOption: "+DWZ.obj2str(uploaderOption));
  1542. $this.uploadify(options);
  1543. });
  1544. }
  1545. // init styles
  1546. $("input[type=text], input[type=password], textarea", $p).addClass("textInput").focusClass("focus");
  1547. $("input[readonly], textarea[readonly]", $p).addClass("readonly");
  1548. $("input[disabled=true], textarea[disabled=true]", $p).addClass("disabled");
  1549. $("input[type=text]", $p).not("div.tabs input[type=text]", $p).filter("[alt]").inputAlert();
  1550. //Grid ToolBar
  1551. $("div.panelBar li, div.panelBar", $p).hoverClass("hover");
  1552. //Button
  1553. $("div.button", $p).hoverClass("buttonHover");
  1554. $("div.buttonActive", $p).hoverClass("buttonActiveHover");
  1555. //tabsPageHeader
  1556. $("div.tabsHeader li, div.tabsPageHeader li, div.accordionHeader, div.accordion", $p).hoverClass("hover");
  1557. //validate form
  1558. if ($.fn.validate) {
  1559. $("form.required-validate", $p).each(function(){
  1560. var $form = $(this);
  1561. $form.validate({
  1562. onsubmit: false,
  1563. focusInvalid: false,
  1564. focusCleanup: true,
  1565. errorElement: "span",
  1566. ignore:".ignore",
  1567. invalidHandler: function(form, validator) {
  1568. var errors = validator.numberOfInvalids();
  1569. if (errors) {
  1570. var message = DWZ.msg("validateFormError",[errors]);
  1571. alertMsg.error(message);
  1572. }
  1573. }
  1574. });
  1575. $form.find('input[customvalid]').each(function(){
  1576. var $input = $(this);
  1577. $input.rules("add", {
  1578. customvalid: $input.attr("customvalid")
  1579. })
  1580. });
  1581. });
  1582. }
  1583. if ($.fn.datepicker){
  1584. $('input.date', $p).each(function(){
  1585. var $this = $(this);
  1586. var opts = {};
  1587. if ($this.attr("dateFmt")) opts.pattern = $this.attr("dateFmt");
  1588. if ($this.attr("minDate")) opts.minDate = $this.attr("minDate");
  1589. if ($this.attr("maxDate")) opts.maxDate = $this.attr("maxDate");
  1590. if ($this.attr("mmStep")) opts.mmStep = $this.attr("mmStep");
  1591. if ($this.attr("ssStep")) opts.ssStep = $this.attr("ssStep");
  1592. $this.datepicker(opts);
  1593. });
  1594. }
  1595. // navTab
  1596. $("a[target=navTab]", $p).each(function(){
  1597. $(this).click(function(event){
  1598. var $this = $(this);
  1599. var title = $this.attr("title") || $this.text();
  1600. var tabid = $this.attr("rel") || "_blank";
  1601. var fresh = eval($this.attr("fresh") || "true");
  1602. var external = eval($this.attr("external") || "false");
  1603. var url = unescape($this.attr("href")).replaceTmById($(event.target).parents(".unitBox:first"));
  1604. DWZ.debug(url);
  1605. if (!url.isFinishedTm()) {
  1606. alertMsg.error($this.attr("warn") || DWZ.msg("alertSelectMsg"));
  1607. return false;
  1608. }
  1609. navTab.openTab(tabid, url,{title:title, fresh:fresh, external:external});
  1610. event.preventDefault();
  1611. });
  1612. });
  1613. //dialogs
  1614. $("a[target=dialog]", $p).each(function(){
  1615. $(this).click(function(event){
  1616. var $this = $(this);
  1617. var title = $this.attr("title") || $this.text();
  1618. var rel = $this.attr("rel") || "_blank";
  1619. var options = {};
  1620. var w = $this.attr("width");
  1621. var h = $this.attr("height");
  1622. if (w) options.width = w;
  1623. if (h) options.height = h;
  1624. options.max = eval($this.attr("max") || "false");
  1625. options.mask = eval($this.attr("mask") || "false");
  1626. options.maxable = eval($this.attr("maxable") || "true");
  1627. options.minable = eval($this.attr("minable") || "true");
  1628. options.fresh = eval($this.attr("fresh") || "true");
  1629. options.resizable = eval($this.attr("resizable") || "true");
  1630. options.drawable = eval($this.attr("drawable") || "true");
  1631. options.close = eval($this.attr("close") || "");
  1632. options.param = $this.attr("param") || "";
  1633. var url = unescape($this.attr("href")).replaceTmById($(event.target).parents(".unitBox:first"));
  1634. DWZ.debug(url);
  1635. if (!url.isFinishedTm()) {
  1636. alertMsg.error($this.attr("warn") || DWZ.msg("alertSelectMsg"));
  1637. return false;
  1638. }
  1639. $.pdialog.open(url, rel, title, options);
  1640. return false;
  1641. });
  1642. });
  1643. $("a[target=ajax]", $p).each(function(){
  1644. $(this).click(function(event){
  1645. var $this = $(this);
  1646. var rel = $this.attr("rel");
  1647. if (rel) {
  1648. var $rel = $("#"+rel);
  1649. $rel.loadUrl($this.attr("href"), {}, function(){
  1650. $rel.find("[layoutH]").layoutH();
  1651. });
  1652. }
  1653. event.preventDefault();
  1654. });
  1655. });
  1656. $("div.pagination", $p).each(function(){
  1657. var $this = $(this);
  1658. $this.pagination({
  1659. targetType:$this.attr("targetType"),
  1660. rel:$this.attr("rel"),
  1661. totalCount:$this.attr("totalCount"),
  1662. numPerPage:$this.attr("numPerPage"),
  1663. pageNumShown:$this.attr("pageNumShown"),
  1664. currentPage:$this.attr("currentPage")
  1665. });
  1666. });
  1667. if ($.fn.sortDrag) $("div.sortDrag", $p).sortDrag();
  1668. // dwz.ajax.js
  1669. if ($.fn.ajaxTodo) $("a[target=ajaxTodo]", $p).ajaxTodo();
  1670. if ($.fn.dwzExport) $("a[target=dwzExport]", $p).dwzExport();
  1671. if ($.fn.lookup) $("a[lookupGroup]", $p).lookup();
  1672. if ($.fn.multLookup) $("[multLookup]:button", $p).multLookup();
  1673. if ($.fn.suggest) $("input[suggestFields]", $p).suggest();
  1674. if ($.fn.itemDetail) $("table.itemDetail", $p).itemDetail();
  1675. if ($.fn.selectedTodo) $("a[target=selectedTodo]", $p).selectedTodo();
  1676. if ($.fn.pagerForm) $("form[rel=pagerForm]", $p).pagerForm({parentBox:$p});
  1677. // 执行第三方jQuery插件【 第三方jQuery插件注册:DWZ.regPlugins.push(function($p){}); 】
  1678. $.each(DWZ.regPlugins, function(index, fn){
  1679. fn($p);
  1680. });
  1681. }
  1682. /**
  1683. * Theme Plugins
  1684. * @author ZhangHuihua@msn.com
  1685. */
  1686. (function($){
  1687. $.fn.extend({
  1688. theme: function(options){
  1689. var op = $.extend({themeBase:"themes"}, options);
  1690. var _themeHref = op.themeBase + "/#theme#/style.css";
  1691. return this.each(function(){
  1692. var jThemeLi = $(this).find(">li[theme]");
  1693. var setTheme = function(themeName){
  1694. $("head").find("link[href$='style.css']").attr("href", _themeHref.replace("#theme#", themeName));
  1695. jThemeLi.find(">div").removeClass("selected");
  1696. jThemeLi.filter("[theme="+themeName+"]").find(">div").addClass("selected");
  1697. if ($.isFunction($.cookie)) $.cookie("dwz_theme", themeName);
  1698. }
  1699. jThemeLi.each(function(index){
  1700. var $this = $(this);
  1701. var themeName = $this.attr("theme");
  1702. $this.addClass(themeName).click(function(){
  1703. setTheme(themeName);
  1704. });
  1705. });
  1706. if ($.isFunction($.cookie)){
  1707. var themeName = $.cookie("dwz_theme");
  1708. if (themeName) {
  1709. setTheme(themeName);
  1710. }
  1711. }
  1712. });
  1713. }
  1714. });
  1715. })(jQuery);
  1716. /**
  1717. * @author zhanghuihua@msn.com
  1718. */
  1719. (function($){
  1720. $.fn.navMenu = function(){
  1721. return this.each(function(){
  1722. var $box = $(this);
  1723. $box.find("li>a").click(function(){
  1724. var $a = $(this);
  1725. $.post($a.attr("href"), {}, function(html){
  1726. $("#sidebar").find(".accordion").remove().end().append(html).initUI();
  1727. $box.find("li").removeClass("selected");
  1728. $a.parent().addClass("selected");
  1729. navTab.closeAllTab();
  1730. });
  1731. return false;
  1732. });
  1733. });
  1734. }
  1735. $.fn.switchEnv = function(){
  1736. var op = {cities$:">ul>li", boxTitle$:">a>span"};
  1737. return this.each(function(){
  1738. var $this = $(this);
  1739. $this.click(function(){
  1740. if ($this.hasClass("selected")){
  1741. _hide($this);
  1742. } else {
  1743. _show($this);
  1744. }
  1745. return false;
  1746. });
  1747. $this.find(op.cities$).click(function(){
  1748. var $li = $(this);
  1749. $.post($li.find(">a").attr("href"), {}, function(html){
  1750. _hide($this);
  1751. $this.find(op.boxTitle$).html($li.find(">a").html());
  1752. navTab.closeAllTab();
  1753. $("#sidebar").find(".accordion").remove().end().append(html).initUI();
  1754. });
  1755. return false;
  1756. });
  1757. });
  1758. }
  1759. function _show($box){
  1760. $box.addClass("selected");
  1761. $(document).bind("click",{box:$box}, _handler);
  1762. }
  1763. function _hide($box){
  1764. $box.removeClass("selected");
  1765. $(document).unbind("click", _handler);
  1766. }
  1767. function _handler(event){
  1768. _hide(event.data.box);
  1769. }
  1770. })(jQuery);
  1771. /**
  1772. * @author ZhangHuihua@msn.com
  1773. */
  1774. $.setRegional("alertMsg", {
  1775. title:{error:"Error", info:"Information", warn:"Warning", correct:"Successful", confirm:"Confirmation"},
  1776. butMsg:{ok:"OK", yes:"Yes", no:"No", cancel:"Cancel"}
  1777. });
  1778. var alertMsg = {
  1779. _boxId: "#alertMsgBox",
  1780. _bgId: "#alertBackground",
  1781. _closeTimer: null,
  1782. _types: {error:"error", info:"info", warn:"warn", correct:"correct", confirm:"confirm"},
  1783. _getTitle: function(key){
  1784. return $.regional.alertMsg.title[key];
  1785. },
  1786. _keydownOk: function(event){
  1787. if (event.keyCode == DWZ.keyCode.ENTER) event.data.target.trigger("click");
  1788. return false;
  1789. },
  1790. _keydownEsc: function(event){
  1791. if (event.keyCode == DWZ.keyCode.ESC) event.data.target.trigger("click");
  1792. },
  1793. /**
  1794. *
  1795. * @param {Object} type
  1796. * @param {Object} msg
  1797. * @param {Object} buttons [button1, button2]
  1798. */
  1799. _open: function(type, msg, buttons){
  1800. $(this._boxId).remove();
  1801. var butsHtml = "";
  1802. if (buttons) {
  1803. for (var i = 0; i < buttons.length; i++) {
  1804. var sRel = buttons[i].call ? "callback" : "";
  1805. butsHtml += DWZ.frag["alertButFrag"].replace("#butMsg#", buttons[i].name).replace("#callback#", sRel);
  1806. }
  1807. }
  1808. var boxHtml = DWZ.frag["alertBoxFrag"].replace("#type#", type).replace("#title#", this._getTitle(type)).replace("#message#", msg).replace("#butFragment#", butsHtml);
  1809. $(boxHtml).appendTo("body").css({top:-$(this._boxId).height()+"px"}).animate({top:"0px"}, 500);
  1810. if (this._closeTimer) {
  1811. clearTimeout(this._closeTimer);
  1812. this._closeTimer = null;
  1813. }
  1814. if (this._types.info == type || this._types.correct == type){
  1815. this._closeTimer = setTimeout(function(){alertMsg.close()}, 3500);
  1816. } else {
  1817. $(this._bgId).show();
  1818. }
  1819. var jButs = $(this._boxId).find("a.button");
  1820. var jCallButs = jButs.filter("[rel=callback]");
  1821. var jDoc = $(document);
  1822. for (var i = 0; i < buttons.length; i++) {
  1823. if (buttons[i].call) jCallButs.eq(i).click(buttons[i].call);
  1824. if (buttons[i].keyCode == DWZ.keyCode.ENTER) {
  1825. jDoc.bind("keydown",{target:jButs.eq(i)}, this._keydownOk);
  1826. }
  1827. if (buttons[i].keyCode == DWZ.keyCode.ESC) {
  1828. jDoc.bind("keydown",{target:jButs.eq(i)}, this._keydownEsc);
  1829. }
  1830. }
  1831. },
  1832. close: function(){
  1833. $(document).unbind("keydown", this._keydownOk).unbind("keydown", this._keydownEsc);
  1834. $(this._boxId).animate({top:-$(this._boxId).height()}, 500, function(){
  1835. $(this).remove();
  1836. });
  1837. $(this._bgId).hide();
  1838. },
  1839. error: function(msg, options) {
  1840. this._alert(this._types.error, msg, options);
  1841. },
  1842. info: function(msg, options) {
  1843. this._alert(this._types.info, msg, options);
  1844. },
  1845. warn: function(msg, options) {
  1846. this._alert(this._types.warn, msg, options);
  1847. },
  1848. correct: function(msg, options) {
  1849. this._alert(this._types.correct, msg, options);
  1850. },
  1851. _alert: function(type, msg, options) {
  1852. var op = {okName:$.regional.alertMsg.butMsg.ok, okCall:null};
  1853. $.extend(op, options);
  1854. var buttons = [
  1855. {name:op.okName, call: op.okCall, keyCode:DWZ.keyCode.ENTER}
  1856. ];
  1857. this._open(type, msg, buttons);
  1858. },
  1859. /**
  1860. *
  1861. * @param {Object} msg
  1862. * @param {Object} options {okName, okCal, cancelName, cancelCall}
  1863. */
  1864. confirm: function(msg, options) {
  1865. var op = {okName:$.regional.alertMsg.butMsg.ok, okCall:null, cancelName:$.regional.alertMsg.butMsg.cancel, cancelCall:null};
  1866. $.extend(op, options);
  1867. var buttons = [
  1868. {name:op.okName, call: op.okCall, keyCode:DWZ.keyCode.ENTER},
  1869. {name:op.cancelName, call: op.cancelCall, keyCode:DWZ.keyCode.ESC}
  1870. ];
  1871. this._open(this._types.confirm, msg, buttons);
  1872. }
  1873. };
  1874. /**
  1875. * @author zhanghuihua@msn.com
  1876. */
  1877. (function($){
  1878. var menu, shadow, hash;
  1879. $.fn.extend({
  1880. contextMenu: function(id, options){
  1881. var op = $.extend({
  1882. shadow : true,
  1883. bindings:{},
  1884. ctrSub:null
  1885. }, options
  1886. );
  1887. if (!menu) {
  1888. menu = $('<div id="contextmenu"></div>').appendTo('body').hide();
  1889. }
  1890. if (!shadow) {
  1891. shadow = $('<div id="contextmenuShadow"></div>').appendTo('body').hide();
  1892. }
  1893. hash = hash || [];
  1894. hash.push({
  1895. id : id,
  1896. shadow: op.shadow,
  1897. bindings: op.bindings || {},
  1898. ctrSub: op.ctrSub
  1899. });
  1900. var index = hash.length - 1;
  1901. $(this).bind('contextmenu', function(e) {
  1902. display(index, this, e, op);
  1903. return false;
  1904. });
  1905. return this;
  1906. }
  1907. });
  1908. function display(index, trigger, e, options) {
  1909. var cur = hash[index];
  1910. var content = $(DWZ.frag[cur.id]);
  1911. content.find('li').hoverClass();
  1912. // Send the content to the menu
  1913. menu.html(content);
  1914. $.each(cur.bindings, function(id, func) {
  1915. $("[rel='"+id+"']", menu).bind('click', function(e) {
  1916. hide();
  1917. func($(trigger), $("#"+cur.id));
  1918. });
  1919. });
  1920. var posX = e.pageX;
  1921. var posY = e.pageY;
  1922. if ($(window).width() < posX + menu.width()) posX -= menu.width();
  1923. if ($(window).height() < posY + menu.height()) posY -= menu.height();
  1924. menu.css({'left':posX,'top':posY}).show();
  1925. if (cur.shadow) shadow.css({width:menu.width(),height:menu.height(),left:posX+3,top:posY+3}).show();
  1926. $(document).one('click', hide);
  1927. if ($.isFunction(cur.ctrSub)) {cur.ctrSub($(trigger), $("#"+cur.id));}
  1928. }
  1929. function hide() {
  1930. menu.hide();
  1931. shadow.hide();
  1932. }
  1933. })(jQuery);
  1934. /**
  1935. * @author ZhangHuihua@msn.com
  1936. *
  1937. */
  1938. var navTab = {
  1939. componentBox: null, // tab component. contain tabBox, prevBut, nextBut, panelBox
  1940. _tabBox: null,
  1941. _prevBut: null,
  1942. _nextBut: null,
  1943. _panelBox: null,
  1944. _moreBut:null,
  1945. _moreBox:null,
  1946. _currentIndex: 0,
  1947. _op: {id:"navTab", stTabBox:".navTab-tab", stPanelBox:".navTab-panel", mainTabId:"main", close$:"a.close", prevClass:"tabsLeft", nextClass:"tabsRight", stMore:".tabsMore", stMoreLi:"ul.tabsMoreList"},
  1948. init: function(options){
  1949. if ($.History) $.History.init("#container");
  1950. var $this = this;
  1951. $.extend(this._op, options);
  1952. this.componentBox = $("#"+this._op.id);
  1953. this._tabBox = this.componentBox.find(this._op.stTabBox);
  1954. this._panelBox = this.componentBox.find(this._op.stPanelBox);
  1955. this._prevBut = this.componentBox.find("."+this._op.prevClass);
  1956. this._nextBut = this.componentBox.find("."+this._op.nextClass);
  1957. this._moreBut = this.componentBox.find(this._op.stMore);
  1958. this._moreBox = this.componentBox.find(this._op.stMoreLi);
  1959. this._prevBut.click(function(event) {$this._scrollPrev()});
  1960. this._nextBut.click(function(event) {$this._scrollNext()});
  1961. this._moreBut.click(function(){
  1962. $this._moreBox.show();
  1963. return false;
  1964. });
  1965. $(document).click(function(){$this._moreBox.hide()});
  1966. this._contextmenu(this._tabBox);
  1967. this._contextmenu(this._getTabs());
  1968. this._init();
  1969. this._ctrlScrollBut();
  1970. },
  1971. _init: function(){
  1972. var $this = this;
  1973. this._getTabs().each(function(iTabIndex){
  1974. $(this).unbind("click").click(function(event){
  1975. $this._switchTab(iTabIndex);
  1976. });
  1977. $(this).find(navTab._op.close$).unbind("click").click(function(){
  1978. $this._closeTab(iTabIndex);
  1979. });
  1980. });
  1981. this._getMoreLi().each(function(iTabIndex){
  1982. $(this).find(">a").unbind("click").click(function(event){
  1983. $this._switchTab(iTabIndex);
  1984. });
  1985. });
  1986. this._switchTab(this._currentIndex);
  1987. },
  1988. _contextmenu:function($obj){ // navTab右键菜单
  1989. var $this = this;
  1990. $obj.contextMenu('navTabCM', {
  1991. bindings:{
  1992. reload:function(t,m){
  1993. $this._reload(t, true);
  1994. },
  1995. closeCurrent:function(t,m){
  1996. var tabId = t.attr("tabid");
  1997. if (tabId) $this.closeTab(tabId);
  1998. else $this.closeCurrentTab();
  1999. },
  2000. closeOther:function(t,m){
  2001. var index = $this._indexTabId(t.attr("tabid"));
  2002. $this._closeOtherTab(index > 0 ? index : $this._currentIndex);
  2003. },
  2004. closeAll:function(t,m){
  2005. $this.closeAllTab();
  2006. }
  2007. },
  2008. ctrSub:function(t,m){
  2009. var mReload = m.find("[rel='reload']");
  2010. var mCur = m.find("[rel='closeCurrent']");
  2011. var mOther = m.find("[rel='closeOther']");
  2012. var mAll = m.find("[rel='closeAll']");
  2013. var $tabLi = $this._getTabs();
  2014. if ($tabLi.size() < 2) {
  2015. mCur.addClass("disabled");
  2016. mOther.addClass("disabled");
  2017. mAll.addClass("disabled");
  2018. }
  2019. if ($this._currentIndex == 0 || t.attr("tabid") == $this._op.mainTabId) {
  2020. mCur.addClass("disabled");
  2021. mReload.addClass("disabled");
  2022. } else if ($tabLi.size() == 2) {
  2023. mOther.addClass("disabled");
  2024. }
  2025. }
  2026. });
  2027. },
  2028. _getTabs: function(){
  2029. return this._tabBox.find("> li");
  2030. },
  2031. _getPanels: function(){
  2032. return this._panelBox.find("> div");
  2033. },
  2034. _getMoreLi: function(){
  2035. return this._moreBox.find("> li");
  2036. },
  2037. _getTab: function(tabid){
  2038. var index = this._indexTabId(tabid);
  2039. if (index >= 0) return this._getTabs().eq(index);
  2040. },
  2041. getPanel: function(tabid){
  2042. var index = this._indexTabId(tabid);
  2043. if (index >= 0) return this._getPanels().eq(index);
  2044. },
  2045. _getTabsW: function(iStart, iEnd){
  2046. return this._tabsW(this._getTabs().slice(iStart, iEnd));
  2047. },
  2048. _tabsW:function($tabs){
  2049. var iW = 0;
  2050. $tabs.each(function(){
  2051. iW += $(this).outerWidth(true);
  2052. });
  2053. return iW;
  2054. },
  2055. _indexTabId: function(tabid){
  2056. if (!tabid) return -1;
  2057. var iOpenIndex = -1;
  2058. this._getTabs().each(function(index){
  2059. if ($(this).attr("tabid") == tabid){iOpenIndex = index; return;}
  2060. });
  2061. return iOpenIndex;
  2062. },
  2063. _getLeft: function(){
  2064. return this._tabBox.position().left;
  2065. },
  2066. _getScrollBarW: function(){
  2067. return this.componentBox.width()-55;
  2068. },
  2069. _visibleStart: function(){
  2070. var iLeft = this._getLeft(), iW = 0;
  2071. var $tabs = this._getTabs();
  2072. for (var i=0; i<$tabs.size(); i++){
  2073. if (iW + iLeft >= 0) return i;
  2074. iW += $tabs.eq(i).outerWidth(true);
  2075. }
  2076. return 0;
  2077. },
  2078. _visibleEnd: function(){
  2079. var iLeft = this._getLeft(), iW = 0;
  2080. var $tabs = this._getTabs();
  2081. for (var i=0; i<$tabs.size(); i++){
  2082. iW += $tabs.eq(i).outerWidth(true);
  2083. if (iW + iLeft > this._getScrollBarW()) return i;
  2084. }
  2085. return $tabs.size();
  2086. },
  2087. _scrollPrev: function(){
  2088. var iStart = this._visibleStart();
  2089. if (iStart > 0){
  2090. this._scrollTab(-this._getTabsW(0, iStart-1));
  2091. }
  2092. },
  2093. _scrollNext: function(){
  2094. var iEnd = this._visibleEnd();
  2095. if (iEnd < this._getTabs().size()){
  2096. this._scrollTab(-this._getTabsW(0, iEnd+1) + this._getScrollBarW());
  2097. }
  2098. },
  2099. _scrollTab: function(iLeft, isNext){
  2100. var $this = this;
  2101. this._tabBox.animate({ left: iLeft+'px' }, 200, function(){$this._ctrlScrollBut();});
  2102. },
  2103. _scrollCurrent: function(){ // auto scroll current tab
  2104. var iW = this._tabsW(this._getTabs());
  2105. if (iW <= this._getScrollBarW()){
  2106. this._scrollTab(0);
  2107. } else if (this._getLeft() < this._getScrollBarW() - iW){
  2108. this._scrollTab(this._getScrollBarW()-iW);
  2109. } else if (this._currentIndex < this._visibleStart()) {
  2110. this._scrollTab(-this._getTabsW(0, this._currentIndex));
  2111. } else if (this._currentIndex >= this._visibleEnd()) {
  2112. this._scrollTab(this._getScrollBarW() - this._getTabs().eq(this._currentIndex).outerWidth(true) - this._getTabsW(0, this._currentIndex));
  2113. }
  2114. },
  2115. _ctrlScrollBut: function(){
  2116. var iW = this._tabsW(this._getTabs());
  2117. if (this._getScrollBarW() > iW){
  2118. this._prevBut.hide();
  2119. this._nextBut.hide();
  2120. this._tabBox.parent().removeClass("tabsPageHeaderMargin");
  2121. } else {
  2122. this._prevBut.show().removeClass("tabsLeftDisabled");
  2123. this._nextBut.show().removeClass("tabsRightDisabled");
  2124. this._tabBox.parent().addClass("tabsPageHeaderMargin");
  2125. if (this._getLeft() >= 0){
  2126. this._prevBut.addClass("tabsLeftDisabled");
  2127. } else if (this._getLeft() <= this._getScrollBarW() - iW) {
  2128. this._nextBut.addClass("tabsRightDisabled");
  2129. }
  2130. }
  2131. },
  2132. _switchTab: function(iTabIndex){
  2133. var $tab = this._getTabs().removeClass("selected").eq(iTabIndex).addClass("selected");
  2134. if (DWZ.ui.hideMode == 'offsets') {
  2135. this._getPanels().css({position: 'absolute', top:'-100000px', left:'-100000px'}).eq(iTabIndex).css({position: '', top:'', left:''});
  2136. } else {
  2137. this._getPanels().hide().eq(iTabIndex).show();
  2138. }
  2139. this._getMoreLi().removeClass("selected").eq(iTabIndex).addClass("selected");
  2140. this._currentIndex = iTabIndex;
  2141. this._scrollCurrent();
  2142. this._reload($tab);
  2143. },
  2144. _closeTab: function(index, openTabid){
  2145. this._getTabs().eq(index).remove();
  2146. this._getPanels().eq(index).trigger(DWZ.eventType.pageClear).remove();
  2147. this._getMoreLi().eq(index).remove();
  2148. if (this._currentIndex >= index) this._currentIndex--;
  2149. if (openTabid) {
  2150. var openIndex = this._indexTabId(openTabid);
  2151. if (openIndex > 0) this._currentIndex = openIndex;
  2152. }
  2153. this._init();
  2154. this._scrollCurrent();
  2155. this._reload(this._getTabs().eq(this._currentIndex));
  2156. },
  2157. closeTab: function(tabid){
  2158. var index = this._indexTabId(tabid);
  2159. if (index > 0) { this._closeTab(index); }
  2160. },
  2161. closeCurrentTab: function(openTabid){ //openTabid 可以为空,默认关闭当前tab后,打开最后一个tab
  2162. if (this._currentIndex > 0) {this._closeTab(this._currentIndex, openTabid);}
  2163. },
  2164. closeAllTab: function(){
  2165. this._getTabs().filter(":gt(0)").remove();
  2166. this._getPanels().filter(":gt(0)").trigger(DWZ.eventType.pageClear).remove();
  2167. this._getMoreLi().filter(":gt(0)").remove();
  2168. this._currentIndex = 0;
  2169. this._init();
  2170. this._scrollCurrent();
  2171. },
  2172. _closeOtherTab: function(index){
  2173. index = index || this._currentIndex;
  2174. if (index > 0) {
  2175. var str$ = ":eq("+index+")";
  2176. this._getTabs().not(str$).filter(":gt(0)").remove();
  2177. this._getPanels().not(str$).filter(":gt(0)").trigger(DWZ.eventType.pageClear).remove();
  2178. this._getMoreLi().not(str$).filter(":gt(0)").remove();
  2179. this._currentIndex = 1;
  2180. this._init();
  2181. this._scrollCurrent();
  2182. } else {
  2183. this.closeAllTab();
  2184. }
  2185. },
  2186. _loadUrlCallback: function($panel){
  2187. $panel.find("[layoutH]").layoutH();
  2188. $panel.find(":button.close").click(function(){
  2189. navTab.closeCurrentTab();
  2190. });
  2191. },
  2192. _reload: function($tab, flag){
  2193. flag = flag || $tab.data("reloadFlag");
  2194. var url = $tab.attr("url");
  2195. if (flag && url) {
  2196. $tab.data("reloadFlag", null);
  2197. var $panel = this.getPanel($tab.attr("tabid"));
  2198. if ($tab.hasClass("external")){
  2199. navTab.openExternal(url, $panel);
  2200. }else {
  2201. //获取pagerForm参数
  2202. var $pagerForm = $("#pagerForm", $panel);
  2203. var args = $pagerForm.size()>0 ? $pagerForm.serializeArray() : {}
  2204. $panel.loadUrl(url, args, function(){navTab._loadUrlCallback($panel);});
  2205. }
  2206. }
  2207. },
  2208. reloadFlag: function(tabid){
  2209. var $tab = this._getTab(tabid);
  2210. if ($tab){
  2211. if (this._indexTabId(tabid) == this._currentIndex) this._reload($tab, true);
  2212. else $tab.data("reloadFlag", 1);
  2213. }
  2214. },
  2215. reload: function(url, options){
  2216. var op = $.extend({data:{}, navTabId:"", callback:null}, options);
  2217. var $tab = op.navTabId ? this._getTab(op.navTabId) : this._getTabs().eq(this._currentIndex);
  2218. var $panel = op.navTabId ? this.getPanel(op.navTabId) : this._getPanels().eq(this._currentIndex);
  2219. if ($panel){
  2220. if (!url) {
  2221. url = $tab.attr("url");
  2222. }
  2223. if (url) {
  2224. if ($tab.hasClass("external")) {
  2225. navTab.openExternal(url, $panel);
  2226. } else {
  2227. if ($.isEmptyObject(op.data)) { //获取pagerForm参数
  2228. var $pagerForm = $("#pagerForm", $panel);
  2229. op.data = $pagerForm.size()>0 ? $pagerForm.serializeArray() : {}
  2230. }
  2231. $panel.ajaxUrl({
  2232. type:"POST", url:url, data:op.data, callback:function(response){
  2233. navTab._loadUrlCallback($panel);
  2234. if ($.isFunction(op.callback)) op.callback(response);
  2235. }
  2236. });
  2237. }
  2238. }
  2239. }
  2240. },
  2241. getCurrentPanel: function() {
  2242. return this._getPanels().eq(this._currentIndex);
  2243. },
  2244. checkTimeout:function(){
  2245. var json = DWZ.jsonEval(this.getCurrentPanel().html());
  2246. if (json && json[DWZ.keys.statusCode] == DWZ.statusCode.timeout) this.closeCurrentTab();
  2247. },
  2248. openExternal:function(url, $panel){
  2249. var ih = navTab._panelBox.height();
  2250. $panel.html(DWZ.frag["externalFrag"].replaceAll("{url}", url).replaceAll("{height}", ih+"px"));
  2251. },
  2252. /**
  2253. *
  2254. * @param {Object} tabid
  2255. * @param {Object} url
  2256. * @param {Object} params: title, data, fresh
  2257. */
  2258. openTab: function(tabid, url, options){ //if found tabid replace tab, else create a new tab.
  2259. var op = $.extend({title:"New Tab", type:"GET", data:{}, fresh:true, external:false}, options);
  2260. var iOpenIndex = this._indexTabId(tabid);
  2261. if (iOpenIndex >= 0){
  2262. var $tab = this._getTabs().eq(iOpenIndex);
  2263. var span$ = $tab.attr("tabid") == this._op.mainTabId ? "> span > span" : "> span";
  2264. $tab.find(">a").attr("title", op.title).find(span$).html(op.title);
  2265. var $panel = this._getPanels().eq(iOpenIndex);
  2266. if(op.fresh || $tab.attr("url") != url) {
  2267. $tab.attr("url", url);
  2268. if (op.external || url.isExternalUrl()) {
  2269. $tab.addClass("external");
  2270. navTab.openExternal(url, $panel);
  2271. } else {
  2272. $tab.removeClass("external");
  2273. $panel.ajaxUrl({
  2274. type:op.type, url:url, data:op.data, callback:function(){
  2275. navTab._loadUrlCallback($panel);
  2276. }
  2277. });
  2278. }
  2279. }
  2280. this._currentIndex = iOpenIndex;
  2281. } else {
  2282. var tabFrag = '<li tabid="#tabid#"><a href="javascript:" title="#title#" class="#tabid#"><span>#title#</span></a><a href="javascript:;" class="close">close</a></li>';
  2283. this._tabBox.append(tabFrag.replaceAll("#tabid#", tabid).replaceAll("#title#", op.title));
  2284. this._panelBox.append('<div class="page unitBox"></div>');
  2285. this._moreBox.append('<li><a href="javascript:" title="#title#">#title#</a></li>'.replaceAll("#title#", op.title));
  2286. var $tabs = this._getTabs();
  2287. var $tab = $tabs.filter(":last");
  2288. var $panel = this._getPanels().filter(":last");
  2289. if (op.external || url.isExternalUrl()) {
  2290. $tab.addClass("external");
  2291. navTab.openExternal(url, $panel);
  2292. } else {
  2293. $tab.removeClass("external");
  2294. $panel.ajaxUrl({
  2295. type:op.type, url:url, data:op.data, callback:function(){
  2296. navTab._loadUrlCallback($panel);
  2297. }
  2298. });
  2299. }
  2300. if ($.History) {
  2301. setTimeout(function(){
  2302. $.History.addHistory(tabid, function(tabid){
  2303. var i = navTab._indexTabId(tabid);
  2304. if (i >= 0) navTab._switchTab(i);
  2305. }, tabid);
  2306. }, 10);
  2307. }
  2308. this._currentIndex = $tabs.size() - 1;
  2309. this._contextmenu($tabs.filter(":last").hoverClass("hover"));
  2310. }
  2311. this._init();
  2312. this._scrollCurrent();
  2313. this._getTabs().eq(this._currentIndex).attr("url", url);
  2314. }
  2315. };/**
  2316. * @author ZhangHuihua@msn.com
  2317. *
  2318. */
  2319. (function($){
  2320. $.fn.extend({
  2321. /**
  2322. * options: reverse[true, false], eventType[click, hover], currentIndex[default index 0]
  2323. * stTab[tabs selector], stTabPanel[tab panel selector]
  2324. * ajaxClass[ajax load], closeClass[close tab]
  2325. */
  2326. tabs: function (options){
  2327. var op = $.extend({reverse:false, eventType:"click", currentIndex:0, stTabHeader:"> .tabsHeader", stTab:">.tabsHeaderContent>ul", stTabPanel:"> .tabsContent", ajaxClass:"j-ajax", closeClass:"close", prevClass:"tabsLeft", nextClass:"tabsRight"}, options);
  2328. return this.each(function(){
  2329. initTab($(this));
  2330. });
  2331. function initTab(jT){
  2332. var jSelector = jT.add($("> *", jT));
  2333. var jTabHeader = $(op.stTabHeader, jSelector);
  2334. var jTabs = $(op.stTab + " li", jTabHeader);
  2335. var jGroups = $(op.stTabPanel + " > *", jSelector);
  2336. jTabs.unbind().find("a").unbind();
  2337. jTabHeader.find("."+op.prevClass).unbind();
  2338. jTabHeader.find("."+op.nextClass).unbind();
  2339. jTabs.each(function(iTabIndex){
  2340. if (op.currentIndex == iTabIndex) $(this).addClass("selected");
  2341. else $(this).removeClass("selected");
  2342. if (op.eventType == "hover") $(this).hover(function(event){switchTab(jT, iTabIndex)});
  2343. else $(this).click(function(event){switchTab(jT, iTabIndex)});
  2344. $("a", this).each(function(){
  2345. if ($(this).hasClass(op.ajaxClass)) {
  2346. $(this).click(function(event){
  2347. var jGroup = jGroups.eq(iTabIndex);
  2348. if (this.href && !jGroup.attr("loaded")) jGroup.loadUrl(this.href,{},function(){
  2349. jGroup.find("[layoutH]").layoutH();
  2350. jGroup.attr("loaded",true);
  2351. });
  2352. event.preventDefault();
  2353. });
  2354. } else if ($(this).hasClass(op.closeClass)) {
  2355. $(this).click(function(event){
  2356. jTabs.eq(iTabIndex).remove();
  2357. jGroups.eq(iTabIndex).remove();
  2358. if (iTabIndex == op.currentIndex) {
  2359. op.currentIndex = (iTabIndex+1 < jTabs.size()) ? iTabIndex : iTabIndex - 1;
  2360. } else if (iTabIndex < op.currentIndex){
  2361. op.currentIndex = iTabIndex;
  2362. }
  2363. initTab(jT);
  2364. return false;
  2365. });
  2366. }
  2367. });
  2368. });
  2369. switchTab(jT, op.currentIndex);
  2370. }
  2371. function switchTab(jT, iTabIndex){
  2372. var jSelector = jT.add($("> *", jT));
  2373. var jTabHeader = $(op.stTabHeader, jSelector);
  2374. var jTabs = $(op.stTab + " li", jTabHeader);
  2375. var jGroups = $(op.stTabPanel + " > *", jSelector);
  2376. var jTab = jTabs.eq(iTabIndex);
  2377. var jGroup = jGroups.eq(iTabIndex);
  2378. if (op.reverse && (jTab.hasClass("selected") )) {
  2379. jTabs.removeClass("selected");
  2380. jGroups.hide();
  2381. } else {
  2382. op.currentIndex = iTabIndex;
  2383. jTabs.removeClass("selected");
  2384. jTab.addClass("selected");
  2385. jGroups.hide().eq(op.currentIndex).show();
  2386. }
  2387. if (!jGroup.attr("inited")){
  2388. jGroup.attr("inited", 1000).find("input[type=text]").filter("[alt]").inputAlert();
  2389. }
  2390. }
  2391. }
  2392. });
  2393. })(jQuery);/**
  2394. * @author Roger Wu
  2395. * @version 1.0
  2396. */
  2397. (function($){
  2398. $.fn.extend({jresize:function(options) {
  2399. if (typeof options == 'string') {
  2400. if (options == 'destroy')
  2401. return this.each(function() {
  2402. var dialog = this;
  2403. $("div[class^='resizable']",dialog).each(function() {
  2404. $(this).hide();
  2405. });
  2406. });
  2407. }
  2408. return this.each(function(){
  2409. var dialog = $(this);
  2410. var resizable = $(".resizable");
  2411. $("div[class^='resizable']",dialog).each(function() {
  2412. var bar = this;
  2413. $(bar).mousedown(function(event) {
  2414. $.pdialog.switchDialog(dialog);
  2415. $.resizeTool.start(resizable, dialog, event, $(bar).attr("tar"));
  2416. return false;
  2417. }).show();
  2418. });
  2419. });
  2420. }});
  2421. $.resizeTool = {
  2422. start:function(resizable, dialog, e, target) {
  2423. $.pdialog.initResize(resizable, dialog, target);
  2424. $.data(resizable[0], 'layer-drag', {
  2425. options: $.extend($.pdialog._op, {target:target, dialog:dialog,stop:$.resizeTool.stop})
  2426. });
  2427. $.layerdrag.start(resizable[0], e, $.pdialog._op);
  2428. },
  2429. stop:function(){
  2430. var data = $.data(arguments[0], 'layer-drag');
  2431. $.pdialog.resizeDialog(arguments[0], data.options.dialog, data.options.target);
  2432. $("body").css("cursor", "");
  2433. $(arguments[0]).hide();
  2434. }
  2435. };
  2436. $.layerdrag = {
  2437. start:function(obj, e, options) {
  2438. if (!$.layerdrag.current) {
  2439. $.layerdrag.current = {
  2440. el: obj,
  2441. oleft: parseInt(obj.style.left) || 0,
  2442. owidth: parseInt(obj.style.width) || 0,
  2443. otop: parseInt(obj.style.top) || 0,
  2444. oheight:parseInt(obj.style.height) || 0,
  2445. ox: e.pageX || e.screenX,
  2446. oy: e.pageY || e.clientY
  2447. };
  2448. $(document).bind('mouseup', $.layerdrag.stop);
  2449. $(document).bind('mousemove', $.layerdrag.drag);
  2450. }
  2451. return $.layerdrag.preventEvent(e);
  2452. },
  2453. drag: function(e) {
  2454. if (!e) var e = window.event;
  2455. var current = $.layerdrag.current;
  2456. var data = $.data(current.el, 'layer-drag');
  2457. var lmove = (e.pageX || e.screenX) - current.ox;
  2458. var tmove = (e.pageY || e.clientY) - current.oy;
  2459. if((e.pageY || e.clientY) <= 0 || (e.pageY || e.clientY) >= ($(window).height() - $(".dialogHeader", $(data.options.dialog)).outerHeight())) return false;
  2460. var target = data.options.target;
  2461. var width = current.owidth;
  2462. var height = current.oheight;
  2463. if (target != "n" && target != "s") {
  2464. width += (target.indexOf("w") >= 0)?-lmove:lmove;
  2465. }
  2466. if (width >= $.pdialog._op.minW) {
  2467. if (target.indexOf("w") >= 0) {
  2468. current.el.style.left = (current.oleft + lmove) + 'px';
  2469. }
  2470. if (target != "n" && target != "s") {
  2471. current.el.style.width = width + 'px';
  2472. }
  2473. }
  2474. if (target != "w" && target != "e") {
  2475. height += (target.indexOf("n") >= 0)?-tmove:tmove;
  2476. }
  2477. if (height >= $.pdialog._op.minH) {
  2478. if (target.indexOf("n") >= 0) {
  2479. current.el.style.top = (current.otop + tmove) + 'px';
  2480. }
  2481. if (target != "w" && target != "e") {
  2482. current.el.style.height = height + 'px';
  2483. }
  2484. }
  2485. return $.layerdrag.preventEvent(e);
  2486. },
  2487. stop: function(e) {
  2488. var current = $.layerdrag.current;
  2489. var data = $.data(current.el, 'layer-drag');
  2490. $(document).unbind('mousemove', $.layerdrag.drag);
  2491. $(document).unbind('mouseup', $.layerdrag.stop);
  2492. if (data.options.stop) {
  2493. data.options.stop.apply(current.el, [ current.el ]);
  2494. }
  2495. $.layerdrag.current = null;
  2496. return $.layerdrag.preventEvent(e);
  2497. },
  2498. preventEvent:function(e) {
  2499. if (e.stopPropagation) e.stopPropagation();
  2500. if (e.preventDefault) e.preventDefault();
  2501. return false;
  2502. }
  2503. };
  2504. })(jQuery);/**
  2505. * @author Roger Wu
  2506. * reference:dwz.drag.js, dwz.dialogDrag.js, dwz.resize.js, dwz.taskBar.js
  2507. */
  2508. (function($){
  2509. $.pdialog = {
  2510. _op:{height:300, width:580, minH:40, minW:50, total:20, max:false, mask:false, resizable:true, drawable:true, maxable:true,minable:true,fresh:true},
  2511. _current:null,
  2512. _zIndex:42,
  2513. getCurrent:function(){
  2514. return this._current;
  2515. },
  2516. reload:function(url, options){
  2517. var op = $.extend({data:{}, dialogId:"", callback:null}, options);
  2518. var dialog = (op.dialogId && $("body").data(op.dialogId)) || this._current;
  2519. if (dialog){
  2520. var jDContent = dialog.find(".dialogContent");
  2521. jDContent.ajaxUrl({
  2522. type:"POST", url:url, data:op.data, callback:function(response){
  2523. jDContent.find("[layoutH]").layoutH(jDContent);
  2524. $(".pageContent", dialog).width($(dialog).width()-14);
  2525. $(":button.close", dialog).click(function(){
  2526. $.pdialog.close(dialog);
  2527. return false;
  2528. });
  2529. if ($.isFunction(op.callback)) op.callback(response);
  2530. }
  2531. });
  2532. }
  2533. },
  2534. //打开一个层
  2535. open:function(url, dlgid, title, options) {
  2536. var op = $.extend({},$.pdialog._op, options);
  2537. var dialog = $("body").data(dlgid);
  2538. //重复打开一个层
  2539. if(dialog) {
  2540. if(dialog.is(":hidden")) {
  2541. dialog.show();
  2542. }
  2543. if(op.fresh || url != $(dialog).data("url")){
  2544. dialog.data("url",url);
  2545. dialog.find(".dialogHeader").find("h1").html(title);
  2546. this.switchDialog(dialog);
  2547. var jDContent = dialog.find(".dialogContent");
  2548. jDContent.loadUrl(url, {}, function(){
  2549. jDContent.find("[layoutH]").layoutH(jDContent);
  2550. $(".pageContent", dialog).width($(dialog).width()-14);
  2551. $("button.close").click(function(){
  2552. $.pdialog.close(dialog);
  2553. return false;
  2554. });
  2555. });
  2556. }
  2557. } else { //打开一个全新的层
  2558. $("body").append(DWZ.frag["dialogFrag"]);
  2559. dialog = $(">.dialog:last-child", "body");
  2560. dialog.data("id",dlgid);
  2561. dialog.data("url",url);
  2562. if(options.close) dialog.data("close",options.close);
  2563. if(options.param) dialog.data("param",options.param);
  2564. ($.fn.bgiframe && dialog.bgiframe());
  2565. dialog.find(".dialogHeader").find("h1").html(title);
  2566. $(dialog).css("zIndex", ($.pdialog._zIndex+=2));
  2567. $("div.shadow").css("zIndex", $.pdialog._zIndex - 3).show();
  2568. $.pdialog._init(dialog, options);
  2569. $(dialog).click(function(){
  2570. $.pdialog.switchDialog(dialog);
  2571. });
  2572. if(op.resizable)
  2573. dialog.jresize();
  2574. if(op.drawable)
  2575. dialog.dialogDrag();
  2576. $("a.close", dialog).click(function(event){
  2577. $.pdialog.close(dialog);
  2578. return false;
  2579. });
  2580. if (op.maxable) {
  2581. $("a.maximize", dialog).show().click(function(event){
  2582. $.pdialog.switchDialog(dialog);
  2583. $.pdialog.maxsize(dialog);
  2584. dialog.jresize("destroy").dialogDrag("destroy");
  2585. return false;
  2586. });
  2587. } else {
  2588. $("a.maximize", dialog).hide();
  2589. }
  2590. $("a.restore", dialog).click(function(event){
  2591. $.pdialog.restore(dialog);
  2592. dialog.jresize().dialogDrag();
  2593. return false;
  2594. });
  2595. if (op.minable) {
  2596. $("a.minimize", dialog).show().click(function(event){
  2597. $.pdialog.minimize(dialog);
  2598. return false;
  2599. });
  2600. } else {
  2601. $("a.minimize", dialog).hide();
  2602. }
  2603. $("div.dialogHeader a", dialog).mousedown(function(){
  2604. return false;
  2605. });
  2606. $("div.dialogHeader", dialog).dblclick(function(){
  2607. if($("a.restore",dialog).is(":hidden"))
  2608. $("a.maximize",dialog).trigger("click");
  2609. else
  2610. $("a.restore",dialog).trigger("click");
  2611. });
  2612. if(op.max) {
  2613. // $.pdialog.switchDialog(dialog);
  2614. $.pdialog.maxsize(dialog);
  2615. dialog.jresize("destroy").dialogDrag("destroy");
  2616. }
  2617. $("body").data(dlgid, dialog);
  2618. $.pdialog._current = dialog;
  2619. $.pdialog.attachShadow(dialog);
  2620. //load data
  2621. var jDContent = $(".dialogContent",dialog);
  2622. jDContent.loadUrl(url, {}, function(){
  2623. jDContent.find("[layoutH]").layoutH(jDContent);
  2624. $(".pageContent", dialog).width($(dialog).width()-14);
  2625. $("button.close").click(function(){
  2626. $.pdialog.close(dialog);
  2627. return false;
  2628. });
  2629. });
  2630. }
  2631. if (op.mask) {
  2632. $(dialog).css("zIndex", 1000);
  2633. $("a.minimize",dialog).hide();
  2634. $(dialog).data("mask", true);
  2635. $("#dialogBackground").show();
  2636. }else {
  2637. //add a task to task bar
  2638. if(op.minable) $.taskBar.addDialog(dlgid,title);
  2639. }
  2640. },
  2641. /**
  2642. * 切换当前层
  2643. * @param {Object} dialog
  2644. */
  2645. switchDialog:function(dialog) {
  2646. var index = $(dialog).css("zIndex");
  2647. $.pdialog.attachShadow(dialog);
  2648. if($.pdialog._current) {
  2649. var cindex = $($.pdialog._current).css("zIndex");
  2650. $($.pdialog._current).css("zIndex", index);
  2651. $(dialog).css("zIndex", cindex);
  2652. $("div.shadow").css("zIndex", cindex - 1);
  2653. $.pdialog._current = dialog;
  2654. }
  2655. $.taskBar.switchTask(dialog.data("id"));
  2656. },
  2657. /**
  2658. * 给当前层附上阴隐层
  2659. * @param {Object} dialog
  2660. */
  2661. attachShadow:function(dialog) {
  2662. var shadow = $("div.shadow");
  2663. if(shadow.is(":hidden")) shadow.show();
  2664. shadow.css({
  2665. top: parseInt($(dialog)[0].style.top) - 2,
  2666. left: parseInt($(dialog)[0].style.left) - 4,
  2667. height: parseInt($(dialog).height()) + 8,
  2668. width: parseInt($(dialog).width()) + 8,
  2669. zIndex:parseInt($(dialog).css("zIndex")) - 1
  2670. });
  2671. $(".shadow_c", shadow).children().andSelf().each(function(){
  2672. $(this).css("height", $(dialog).outerHeight() - 4);
  2673. });
  2674. },
  2675. _init:function(dialog, options) {
  2676. var op = $.extend({}, this._op, options);
  2677. var height = op.height>op.minH?op.height:op.minH;
  2678. var width = op.width>op.minW?op.width:op.minW;
  2679. if(isNaN(dialog.height()) || dialog.height() < height){
  2680. $(dialog).height(height+"px");
  2681. $(".dialogContent",dialog).height(height - $(".dialogHeader", dialog).outerHeight() - $(".dialogFooter", dialog).outerHeight() - 6);
  2682. }
  2683. if(isNaN(dialog.css("width")) || dialog.width() < width) {
  2684. $(dialog).width(width+"px");
  2685. }
  2686. var iTop = ($(window).height()-dialog.height())/2;
  2687. dialog.css({
  2688. left: ($(window).width()-dialog.width())/2,
  2689. top: iTop > 0 ? iTop : 0
  2690. });
  2691. },
  2692. /**
  2693. * 初始化半透明层
  2694. * @param {Object} resizable
  2695. * @param {Object} dialog
  2696. * @param {Object} target
  2697. */
  2698. initResize:function(resizable, dialog,target) {
  2699. $("body").css("cursor", target + "-resize");
  2700. resizable.css({
  2701. top: $(dialog).css("top"),
  2702. left: $(dialog).css("left"),
  2703. height:$(dialog).css("height"),
  2704. width:$(dialog).css("width")
  2705. });
  2706. resizable.show();
  2707. },
  2708. /**
  2709. * 改变阴隐层
  2710. * @param {Object} target
  2711. * @param {Object} options
  2712. */
  2713. repaint:function(target,options){
  2714. var shadow = $("div.shadow");
  2715. if(target != "w" && target != "e") {
  2716. shadow.css("height", shadow.outerHeight() + options.tmove);
  2717. $(".shadow_c", shadow).children().andSelf().each(function(){
  2718. $(this).css("height", $(this).outerHeight() + options.tmove);
  2719. });
  2720. }
  2721. if(target == "n" || target =="nw" || target == "ne") {
  2722. shadow.css("top", options.otop - 2);
  2723. }
  2724. if(options.owidth && (target != "n" || target != "s")) {
  2725. shadow.css("width", options.owidth + 8);
  2726. }
  2727. if(target.indexOf("w") >= 0) {
  2728. shadow.css("left", options.oleft - 4);
  2729. }
  2730. },
  2731. /**
  2732. * 改变左右拖动层的高度
  2733. * @param {Object} target
  2734. * @param {Object} tmove
  2735. * @param {Object} dialog
  2736. */
  2737. resizeTool:function(target, tmove, dialog) {
  2738. $("div[class^='resizable']", dialog).filter(function(){
  2739. return $(this).attr("tar") == 'w' || $(this).attr("tar") == 'e';
  2740. }).each(function(){
  2741. $(this).css("height", $(this).outerHeight() + tmove);
  2742. });
  2743. },
  2744. /**
  2745. * 改变原始层的大小
  2746. * @param {Object} obj
  2747. * @param {Object} dialog
  2748. * @param {Object} target
  2749. */
  2750. resizeDialog:function(obj, dialog, target) {
  2751. var oleft = parseInt(obj.style.left);
  2752. var otop = parseInt(obj.style.top);
  2753. var height = parseInt(obj.style.height);
  2754. var width = parseInt(obj.style.width);
  2755. if(target == "n" || target == "nw") {
  2756. tmove = parseInt($(dialog).css("top")) - otop;
  2757. } else {
  2758. tmove = height - parseInt($(dialog).css("height"));
  2759. }
  2760. $(dialog).css({left:oleft,width:width,top:otop,height:height});
  2761. $(".dialogContent", dialog).css("width", (width-12) + "px");
  2762. $(".pageContent", dialog).css("width", (width-14) + "px");
  2763. if (target != "w" && target != "e") {
  2764. var content = $(".dialogContent", dialog);
  2765. content.css({height:height - $(".dialogHeader", dialog).outerHeight() - $(".dialogFooter", dialog).outerHeight() - 6});
  2766. content.find("[layoutH]").layoutH(content);
  2767. $.pdialog.resizeTool(target, tmove, dialog);
  2768. }
  2769. $.pdialog.repaint(target, {oleft:oleft,otop: otop,tmove: tmove,owidth:width});
  2770. $(window).trigger(DWZ.eventType.resizeGrid);
  2771. },
  2772. close:function(dialog) {
  2773. if(typeof dialog == 'string') dialog = $("body").data(dialog);
  2774. var close = dialog.data("close");
  2775. var go = true;
  2776. if(close && $.isFunction(close)) {
  2777. var param = dialog.data("param");
  2778. if(param && param != ""){
  2779. param = DWZ.jsonEval(param);
  2780. go = close(param);
  2781. } else {
  2782. go = close();
  2783. }
  2784. if(!go) return;
  2785. }
  2786. $(dialog).hide();
  2787. $("div.shadow").hide();
  2788. if($(dialog).data("mask")){
  2789. $("#dialogBackground").hide();
  2790. } else{
  2791. if ($(dialog).data("id")) $.taskBar.closeDialog($(dialog).data("id"));
  2792. }
  2793. $("body").removeData($(dialog).data("id"));
  2794. $(dialog).trigger(DWZ.eventType.pageClear).remove();
  2795. },
  2796. closeCurrent:function(){
  2797. this.close($.pdialog._current);
  2798. },
  2799. checkTimeout:function(){
  2800. var $conetnt = $(".dialogContent", $.pdialog._current);
  2801. var json = DWZ.jsonEval($conetnt.html());
  2802. if (json && json[DWZ.keys.statusCode] == DWZ.statusCode.timeout) this.closeCurrent();
  2803. },
  2804. maxsize:function(dialog) {
  2805. $(dialog).data("original",{
  2806. top:$(dialog).css("top"),
  2807. left:$(dialog).css("left"),
  2808. width:$(dialog).css("width"),
  2809. height:$(dialog).css("height")
  2810. });
  2811. $("a.maximize",dialog).hide();
  2812. $("a.restore",dialog).show();
  2813. var iContentW = $(window).width();
  2814. var iContentH = $(window).height() - 34;
  2815. $(dialog).css({top:"0px",left:"0px",width:iContentW+"px",height:iContentH+"px"});
  2816. $.pdialog._resizeContent(dialog,iContentW,iContentH);
  2817. },
  2818. restore:function(dialog) {
  2819. var original = $(dialog).data("original");
  2820. var dwidth = parseInt(original.width);
  2821. var dheight = parseInt(original.height);
  2822. $(dialog).css({
  2823. top:original.top,
  2824. left:original.left,
  2825. width:dwidth,
  2826. height:dheight
  2827. });
  2828. $.pdialog._resizeContent(dialog,dwidth,dheight);
  2829. $("a.maximize",dialog).show();
  2830. $("a.restore",dialog).hide();
  2831. $.pdialog.attachShadow(dialog);
  2832. },
  2833. minimize:function(dialog){
  2834. $(dialog).hide();
  2835. $("div.shadow").hide();
  2836. var task = $.taskBar.getTask($(dialog).data("id"));
  2837. $(".resizable").css({
  2838. top: $(dialog).css("top"),
  2839. left: $(dialog).css("left"),
  2840. height:$(dialog).css("height"),
  2841. width:$(dialog).css("width")
  2842. }).show().animate({top:$(window).height()-60,left:task.position().left,width:task.outerWidth(),height:task.outerHeight()},250,function(){
  2843. $(this).hide();
  2844. $.taskBar.inactive($(dialog).data("id"));
  2845. });
  2846. },
  2847. _resizeContent:function(dialog,width,height) {
  2848. var content = $(".dialogContent", dialog);
  2849. content.css({width:(width-12) + "px",height:height - $(".dialogHeader", dialog).outerHeight() - $(".dialogFooter", dialog).outerHeight() - 6});
  2850. content.find("[layoutH]").layoutH(content);
  2851. $(".pageContent", dialog).css("width", (width-14) + "px");
  2852. $(window).trigger(DWZ.eventType.resizeGrid);
  2853. }
  2854. };
  2855. })(jQuery);/**
  2856. * @author Roger Wu
  2857. */
  2858. (function($){
  2859. $.fn.dialogDrag = function(options){
  2860. if (typeof options == 'string') {
  2861. if (options == 'destroy')
  2862. return this.each(function() {
  2863. var dialog = this;
  2864. $("div.dialogHeader", dialog).unbind("mousedown");
  2865. });
  2866. }
  2867. return this.each(function(){
  2868. var dialog = $(this);
  2869. $("div.dialogHeader", dialog).mousedown(function(e){
  2870. $.pdialog.switchDialog(dialog);
  2871. dialog.data("task",true);
  2872. setTimeout(function(){
  2873. if(dialog.data("task"))$.dialogDrag.start(dialog,e);
  2874. },100);
  2875. return false;
  2876. }).mouseup(function(e){
  2877. dialog.data("task",false);
  2878. return false;
  2879. });
  2880. });
  2881. };
  2882. $.dialogDrag = {
  2883. currId:null,
  2884. _init:function(dialog) {
  2885. this.currId = new Date().getTime();
  2886. var shadow = $("#dialogProxy");
  2887. if (!shadow.size()) {
  2888. shadow = $(DWZ.frag["dialogProxy"]);
  2889. $("body").append(shadow);
  2890. }
  2891. $("h1", shadow).html($(".dialogHeader h1", dialog).text());
  2892. },
  2893. start:function(dialog,event){
  2894. this._init(dialog);
  2895. var sh = $("#dialogProxy");
  2896. sh.css({
  2897. left: dialog.css("left"),
  2898. top: dialog.css("top"),
  2899. height: dialog.css("height"),
  2900. width: dialog.css("width"),
  2901. zIndex:parseInt(dialog.css("zIndex")) + 1
  2902. }).show();
  2903. $("div.dialogContent",sh).css("height",$("div.dialogContent",dialog).css("height"));
  2904. sh.data("dialog",dialog);
  2905. dialog.css({left:"-10000px",top:"-10000px"});
  2906. $(".shadow").hide();
  2907. $(sh).jDrag({
  2908. selector:".dialogHeader",
  2909. stop: this.stop,
  2910. event:event
  2911. });
  2912. return false;
  2913. },
  2914. stop:function(){
  2915. var sh = $(arguments[0]);
  2916. var dialog = sh.data("dialog");
  2917. $(dialog).css({left:$(sh).css("left"),top:$(sh).css("top")});
  2918. $.pdialog.attachShadow(dialog);
  2919. $(sh).hide();
  2920. }
  2921. }
  2922. })(jQuery);/**
  2923. * @author ZhangHuihua@msn.com
  2924. */
  2925. (function($){
  2926. var _op = {
  2927. cursor: 'move', // selector 的鼠标手势
  2928. sortBoxs: 'div.sortDrag', //拖动排序项父容器
  2929. replace: false, //2个sortBox之间拖动替换
  2930. items: '> *', //拖动排序项选择器
  2931. selector: '', //拖动排序项用于拖动的子元素的选择器,为空时等于item
  2932. zIndex: 1000
  2933. };
  2934. var sortDrag = {
  2935. start:function($sortBox, $item, event, op){
  2936. var $placeholder = this._createPlaceholder($item);
  2937. var $helper = $item.clone();
  2938. var position = $item.position();
  2939. $helper.data('$sortBox', $sortBox).data('op', op).data('$item', $item).data('$placeholder', $placeholder);
  2940. $helper.addClass('sortDragHelper').css({position:'absolute',top:position.top+$sortBox.scrollTop(),left:position.left,zIndex:op.zIndex,width:$item.width()+'px',height:$item.height()+'px'}).jDrag({
  2941. selector:op.selector,
  2942. drag:this.drag,
  2943. stop:this.stop,
  2944. event:event
  2945. });
  2946. $item.before($placeholder).before($helper).hide();
  2947. return false;
  2948. },
  2949. drag:function(el, event){
  2950. var $helper = $(arguments[0]), $sortBox = $helper.data('$sortBox'), $placeholder = $helper.data('$placeholder');
  2951. var $items = $sortBox.find($helper.data('op')['items']).filter(':visible').filter(':not(.sortDragPlaceholder, .sortDragHelper)');
  2952. var helperPos = $helper.position(), firstPos = $items.eq(0).position();
  2953. var $overBox = sortDrag._getOverSortBox($helper, event);
  2954. if ($overBox.length > 0 && $overBox[0] != $sortBox[0]){ //移动到其他容器
  2955. $placeholder.appendTo($overBox);
  2956. $helper.data('$sortBox', $overBox);
  2957. } else {
  2958. for (var i=0; i<$items.length; i++) {
  2959. var $this = $items.eq(i), position = $this.position();
  2960. if (helperPos.top > position.top + 10) {
  2961. $this.after($placeholder);
  2962. } else if (helperPos.top <= position.top) {
  2963. $this.before($placeholder);
  2964. break;
  2965. }
  2966. }
  2967. }
  2968. },
  2969. stop:function(){
  2970. var $helper = $(arguments[0]), $sortBox = $helper.data('$sortBox'), $item = $helper.data('$item'), $placeholder = $helper.data('$placeholder');
  2971. var position = $placeholder.position();
  2972. $helper.animate({
  2973. top: (position.top+$sortBox.scrollTop()) + "px",
  2974. left: position.left + "px"
  2975. },
  2976. {
  2977. complete: function(){
  2978. if ($helper.data('op')['replace']){ //2个sortBox之间替换处理
  2979. $srcBox = $item.parents(_op.sortBoxs+":first");
  2980. $destBox = $placeholder.parents(_op.sortBoxs+":first");
  2981. if ($srcBox[0] != $destBox[0]) { //判断是否移动到其他容器中
  2982. $replaceItem = $placeholder.next();
  2983. if ($replaceItem.size() > 0) {
  2984. $replaceItem.insertAfter($item);
  2985. }
  2986. }
  2987. }
  2988. $item.insertAfter($placeholder).show();
  2989. $placeholder.remove();
  2990. $helper.remove();
  2991. },
  2992. duration: 300
  2993. });
  2994. },
  2995. _createPlaceholder:function($item){
  2996. return $('<'+$item[0].nodeName+' class="sortDragPlaceholder"/>').css({
  2997. width:$item.outerWidth()+'px',
  2998. height:$item.outerHeight()+'px',
  2999. marginTop:$item.css('marginTop'),
  3000. marginRight:$item.css('marginRight'),
  3001. marginBottom:$item.css('marginBottom'),
  3002. marginLeft:$item.css('marginLeft')
  3003. });
  3004. },
  3005. _getOverSortBox:function($item, e){
  3006. var itemPos = $item.position();
  3007. var y = itemPos.top+($item.height()/2), x = itemPos.left+($item.width()/2);
  3008. return $(_op.sortBoxs).filter(':visible').filter(function(){
  3009. var $sortBox = $(this), sortBoxPos = $sortBox.position(),
  3010. sortBoxH = $sortBox.height(), sortBoxW = $sortBox.width();
  3011. return DWZ.isOver(y, x, sortBoxPos.top, sortBoxPos.left, sortBoxH, sortBoxW);
  3012. });
  3013. }
  3014. };
  3015. $.fn.sortDrag = function(options){
  3016. return this.each(function(){
  3017. var op = $.extend({}, _op, options);
  3018. var $sortBox = $(this);
  3019. if ($sortBox.attr('selector')) op.selector = $sortBox.attr('selector');
  3020. $sortBox.find(op.items).each(function(i){
  3021. var $item = $(this), $selector = $item;
  3022. if (op.selector) {
  3023. $selector = $item.find(op.selector).css({cursor:op.cursor});
  3024. }
  3025. $selector.mousedown(function(event){
  3026. sortDrag.start($sortBox, $item, event, op);
  3027. event.preventDefault();
  3028. });
  3029. });
  3030. });
  3031. }
  3032. })(jQuery);
  3033. /**
  3034. * Theme Plugins
  3035. * @author ZhangHuihua@msn.com
  3036. */
  3037. (function($){
  3038. $.fn.extend({
  3039. cssTable: function(options){
  3040. return this.each(function(){
  3041. var $this = $(this);
  3042. var $trs = $this.find('tbody>tr');
  3043. var $grid = $this.parent(); // table
  3044. var nowrap = $this.hasClass("nowrap");
  3045. $trs.hoverClass("hover").each(function(index){
  3046. var $tr = $(this);
  3047. if (!nowrap && index % 2 == 1) $tr.addClass("trbg");
  3048. $tr.click(function(){
  3049. $trs.filter(".selected").removeClass("selected");
  3050. $tr.addClass("selected");
  3051. var sTarget = $tr.attr("target");
  3052. if (sTarget) {
  3053. if ($("#"+sTarget, $grid).size() == 0) {
  3054. $grid.prepend('<input id="'+sTarget+'" type="hidden" />');
  3055. }
  3056. $("#"+sTarget, $grid).val($tr.attr("rel"));
  3057. }
  3058. });
  3059. });
  3060. $this.find("thead [orderField]").orderBy({
  3061. targetType: $this.attr("targetType"),
  3062. rel:$this.attr("rel"),
  3063. asc: $this.attr("asc") || "asc",
  3064. desc: $this.attr("desc") || "desc"
  3065. });
  3066. });
  3067. }
  3068. });
  3069. })(jQuery);
  3070. /**
  3071. * @author Roger Wu v1.0
  3072. * @author ZhangHuihua@msn.com 2011-4-1
  3073. */
  3074. (function($){
  3075. $.fn.jTable = function(options){
  3076. return this.each(function(){
  3077. var $table = $(this), nowrapTD = $table.attr("nowrapTD");
  3078. var tlength = $table.width();
  3079. var aStyles = [];
  3080. var $tc = $table.parent().addClass("j-resizeGrid"); // table parent container
  3081. var layoutH = $(this).attr("layoutH");
  3082. var oldThs = $table.find("thead>tr:last-child").find("th");
  3083. for(var i = 0, l = oldThs.size(); i < l; i++) {
  3084. var $th = $(oldThs[i]);
  3085. var style = [], width = $th.innerWidth() - (100 * $th.innerWidth() / tlength)-2;
  3086. style[0] = parseInt(width);
  3087. style[1] = $th.attr("align");
  3088. aStyles[aStyles.length] = style;
  3089. }
  3090. $(this).wrap("<div class='grid'></div>");
  3091. var $grid = $table.parent().html($table.html());
  3092. var thead = $grid.find("thead");
  3093. thead.wrap("<div class='gridHeader'><div class='gridThead'><table style='width:" + (tlength - 20) + "px;'></table></div></div>");
  3094. var lastH = $(">tr:last-child", thead);
  3095. var ths = $(">th", lastH);
  3096. $("th",thead).each(function(){
  3097. var $th = $(this);
  3098. $th.html("<div class='gridCol' title='"+$th.text()+"'>"+ $th.html() +"</div>");
  3099. });
  3100. ths.each(function(i){
  3101. var $th = $(this), style = aStyles[i];
  3102. $th.addClass(style[1]).hoverClass("hover").removeAttr("align").removeAttr("width").width(style[0]);
  3103. }).filter("[orderField]").orderBy({
  3104. targetType: $table.attr("targetType"),
  3105. rel:$table.attr("rel"),
  3106. asc: $table.attr("asc") || "asc",
  3107. desc: $table.attr("desc") || "desc"
  3108. });
  3109. var tbody = $grid.find(">tbody");
  3110. var layoutStr = layoutH ? " layoutH='" + layoutH + "'" : "";
  3111. tbody.wrap("<div class='gridScroller'" + layoutStr + " style='width:" + $tc.width() + "px;'><div class='gridTbody'><table style='width:" + (tlength - 20) + "px;'></table></div></div>");
  3112. var ftr = $(">tr:first-child", tbody);
  3113. var $trs = tbody.find('>tr');
  3114. $trs.hoverClass().each(function(){
  3115. var $tr = $(this);
  3116. var $ftds = $(">td", this);
  3117. for (var i=0; i < $ftds.size(); i++) {
  3118. var $ftd = $($ftds[i]);
  3119. if (nowrapTD != "false") $ftd.html("<div>" + $ftd.html() + "</div>");
  3120. if (i < aStyles.length) $ftd.addClass(aStyles[i][1]);
  3121. }
  3122. $tr.click(function(){
  3123. $trs.filter(".selected").removeClass("selected");
  3124. $tr.addClass("selected");
  3125. var sTarget = $tr.attr("target");
  3126. if (sTarget) {
  3127. if ($("#"+sTarget, $grid).size() == 0) {
  3128. $grid.prepend('<input id="'+sTarget+'" type="hidden" />');
  3129. }
  3130. $("#"+sTarget, $grid).val($tr.attr("rel"));
  3131. }
  3132. });
  3133. });
  3134. $(">td",ftr).each(function(i){
  3135. if (i < aStyles.length) $(this).width(aStyles[i][0]);
  3136. });
  3137. $grid.append("<div class='resizeMarker' style='height:300px; left:57px;display:none;'></div><div class='resizeProxy' style='height:300px; left:377px;display:none;'></div>");
  3138. var scroller = $(".gridScroller", $grid);
  3139. scroller.scroll(function(event){
  3140. var header = $(".gridThead", $grid);
  3141. if(scroller.scrollLeft() > 0){
  3142. header.css("position", "relative");
  3143. var scroll = scroller.scrollLeft();
  3144. header.css("left", scroller.cssv("left") - scroll);
  3145. }
  3146. if(scroller.scrollLeft() == 0) {
  3147. header.css("position", "relative");
  3148. header.css("left", "0px");
  3149. }
  3150. return false;
  3151. });
  3152. $(">tr", thead).each(function(){
  3153. $(">th", this).each(function(i){
  3154. var th = this, $th = $(this);
  3155. $th.mouseover(function(event){
  3156. var offset = $.jTableTool.getOffset(th, event).offsetX;
  3157. if($th.outerWidth() - offset < 5) {
  3158. $th.css("cursor", "col-resize").mousedown(function(event){
  3159. $(".resizeProxy", $grid).show().css({
  3160. left: $.jTableTool.getRight(th)- $(".gridScroller", $grid).scrollLeft(),
  3161. top:$.jTableTool.getTop(th),
  3162. height:$.jTableTool.getHeight(th,$grid),
  3163. cursor:"col-resize"
  3164. });
  3165. $(".resizeMarker", $grid).show().css({
  3166. left: $.jTableTool.getLeft(th) + 1 - $(".gridScroller", $grid).scrollLeft(),
  3167. top: $.jTableTool.getTop(th),
  3168. height:$.jTableTool.getHeight(th,$grid)
  3169. });
  3170. $(".resizeProxy", $grid).jDrag($.extend(options, {scop:true, cellMinW:20, relObj:$(".resizeMarker", $grid)[0],
  3171. move: "horizontal",
  3172. event:event,
  3173. stop: function(){
  3174. var pleft = $(".resizeProxy", $grid).position().left;
  3175. var mleft = $(".resizeMarker", $grid).position().left;
  3176. var move = pleft - mleft - $th.outerWidth() -9;
  3177. var cols = $.jTableTool.getColspan($th);
  3178. var cellNum = $.jTableTool.getCellNum($th);
  3179. var oldW = $th.width(), newW = $th.width() + move;
  3180. var $dcell = $(">td", ftr).eq(cellNum - 1);
  3181. $th.width(newW + "px");
  3182. $dcell.width(newW+"px");
  3183. var $table1 = $(thead).parent();
  3184. $table1.width(($table1.width() - oldW + newW)+"px");
  3185. var $table2 = $(tbody).parent();
  3186. $table2.width(($table2.width() - oldW + newW)+"px");
  3187. $(".resizeMarker,.resizeProxy", $grid).hide();
  3188. }
  3189. })
  3190. );
  3191. });
  3192. } else {
  3193. $th.css("cursor", $th.attr("orderField") ? "pointer" : "default");
  3194. $th.unbind("mousedown");
  3195. }
  3196. return false;
  3197. });
  3198. });
  3199. });
  3200. function _resizeGrid(){
  3201. $("div.j-resizeGrid").each(function(){
  3202. var width = $(this).innerWidth();
  3203. if (width){
  3204. $("div.gridScroller", this).width(width+"px");
  3205. }
  3206. });
  3207. }
  3208. $(window).unbind(DWZ.eventType.resizeGrid).bind("resizeGrid", _resizeGrid);
  3209. });
  3210. };
  3211. $.jTableTool = {
  3212. getLeft:function(obj) {
  3213. var width = 0;
  3214. $(obj).prevAll().each(function(){
  3215. width += $(this).outerWidth();
  3216. });
  3217. return width - 1;
  3218. },
  3219. getRight:function(obj) {
  3220. var width = 0;
  3221. $(obj).prevAll().andSelf().each(function(){
  3222. width += $(this).outerWidth();
  3223. });
  3224. return width - 1;
  3225. },
  3226. getTop:function(obj) {
  3227. var height = 0;
  3228. $(obj).parent().prevAll().each(function(){
  3229. height += $(this).outerHeight();
  3230. });
  3231. return height;
  3232. },
  3233. getHeight:function(obj, parent) {
  3234. var height = 0;
  3235. var head = $(obj).parent();
  3236. head.nextAll().andSelf().each(function(){
  3237. height += $(this).outerHeight();
  3238. });
  3239. $(".gridTbody", parent).children().each(function(){
  3240. height += $(this).outerHeight();
  3241. });
  3242. return height;
  3243. },
  3244. getCellNum:function(obj) {
  3245. return $(obj).prevAll().andSelf().size();
  3246. },
  3247. getColspan:function(obj) {
  3248. return $(obj).attr("colspan") || 1;
  3249. },
  3250. getStart:function(obj) {
  3251. var start = 1;
  3252. $(obj).prevAll().each(function(){
  3253. start += parseInt($(this).attr("colspan") || 1);
  3254. });
  3255. return start;
  3256. },
  3257. getPageCoord:function(element){
  3258. var coord = {x: 0, y: 0};
  3259. while (element){
  3260. coord.x += element.offsetLeft;
  3261. coord.y += element.offsetTop;
  3262. element = element.offsetParent;
  3263. }
  3264. return coord;
  3265. },
  3266. getOffset:function(obj, evt){
  3267. if(/msie/.test(navigator.userAgent.toLowerCase())) {
  3268. var objset = $(obj).offset();
  3269. var evtset = {
  3270. offsetX:evt.pageX || evt.screenX,
  3271. offsetY:evt.pageY || evt.screenY
  3272. };
  3273. var offset ={
  3274. offsetX: evtset.offsetX - objset.left,
  3275. offsetY: evtset.offsetY - objset.top
  3276. };
  3277. return offset;
  3278. }
  3279. var target = evt.target;
  3280. if (target.offsetLeft == undefined){
  3281. target = target.parentNode;
  3282. }
  3283. var pageCoord = $.jTableTool.getPageCoord(target);
  3284. var eventCoord ={
  3285. x: window.pageXOffset + evt.clientX,
  3286. y: window.pageYOffset + evt.clientY
  3287. };
  3288. var offset ={
  3289. offsetX: eventCoord.x - pageCoord.x,
  3290. offsetY: eventCoord.y - pageCoord.y
  3291. };
  3292. return offset;
  3293. }
  3294. };
  3295. })(jQuery);
  3296. /**
  3297. * @author Roger Wu
  3298. * @version 1.0
  3299. */
  3300. (function($){
  3301. $.fn.extend({
  3302. jTask:function(options){
  3303. return this.each(function(){
  3304. var $task = $(this);
  3305. var id = $task.attr("id");
  3306. $task.click(function(e){
  3307. var dialog = $("body").data(id);
  3308. if ($task.hasClass("selected")) {
  3309. $("a.minimize", dialog).trigger("click");
  3310. } else {
  3311. if (dialog.is(":hidden")) {
  3312. $.taskBar.restoreDialog(dialog);
  3313. } else
  3314. $(dialog).trigger("click");
  3315. }
  3316. $.taskBar.scrollCurrent($(this));
  3317. return false;
  3318. });
  3319. $("div.close", $task).click(function(e){
  3320. $.pdialog.close(id)
  3321. return false;
  3322. }).hoverClass("closeHover");
  3323. $task.hoverClass("hover");
  3324. });
  3325. }
  3326. });
  3327. $.taskBar = {
  3328. _taskBar:null,
  3329. _taskBox:null,
  3330. _prevBut:null,
  3331. _nextBut:null,
  3332. _op:{id:"taskbar", taskBox:"div.taskbarContent",prevBut:".taskbarLeft",prevDis:"taskbarLeftDisabled", nextBut:".taskbarRight",nextDis:"taskbarRightDisabled", selected:"selected",boxMargin:"taskbarMargin"},
  3333. init:function(options) {
  3334. var $this = this;
  3335. $.extend(this._op, options);
  3336. this._taskBar = $("#" + this._op.id);
  3337. if (this._taskBar.size() == 0) {
  3338. this._taskBar = $(DWZ.frag["taskbar"]).appendTo($("#layout"));
  3339. this._taskBar.find(".taskbarLeft").hoverClass("taskbarLeftHover");
  3340. this._taskBar.find(".taskbarRight").hoverClass("taskbarRightHover");
  3341. }
  3342. this._taskBox = this._taskBar.find(this._op.taskBox);
  3343. this._taskList = this._taskBox.find(">ul");
  3344. this._prevBut = this._taskBar.find(this._op.prevBut);
  3345. this._nextBut = this._taskBar.find(this._op.nextBut);
  3346. this._prevBut.click(function(e){$this.scrollLeft()});
  3347. this._nextBut.click(function(e){$this.scrollRight()});
  3348. this._contextmenu(this._taskBox); // taskBar右键菜单
  3349. },
  3350. _contextmenu:function(obj) {
  3351. $(obj).contextMenu('dialogCM', {
  3352. bindings:{
  3353. closeCurrent:function(t,m){
  3354. var obj = t.isTag("li")?t:$.taskBar._getCurrent();
  3355. $("div.close", obj).trigger("click");
  3356. },
  3357. closeOther:function(t,m){
  3358. var selector = t.isTag("li")?("#" +t.attr("id")):".selected";
  3359. var tasks = $.taskBar._taskList.find(">li:not(:"+selector+")");
  3360. tasks.each(function(i){
  3361. $("div.close",tasks[i]).trigger("click");
  3362. });
  3363. },
  3364. closeAll:function(t,m){
  3365. var tasks = $.taskBar._getTasks();
  3366. tasks.each(function(i){
  3367. $("div.close",tasks[i]).trigger("click");
  3368. });
  3369. }
  3370. },
  3371. ctrSub:function(t,m){
  3372. var mCur = m.find("[rel='closeCurrent']");
  3373. var mOther = m.find("[rel='closeOther']");
  3374. if(!$.taskBar._getCurrent()[0]) {
  3375. mCur.addClass("disabled");
  3376. mOther.addClass("disabled");
  3377. } else {
  3378. if($.taskBar._getTasks().size() == 1)
  3379. mOther.addClass("disabled");
  3380. }
  3381. }
  3382. });
  3383. },
  3384. _scrollCurrent:function(){
  3385. var iW = this._tasksW(this._getTasks());
  3386. if (iW > this._getTaskBarW()) {
  3387. var $this = this;
  3388. var lTask = $(">li:last-child", this._taskList);
  3389. var left = this._getTaskBarW() - lTask.position().left - lTask.outerWidth(true);
  3390. this._taskList.animate({
  3391. left: left + 'px'
  3392. }, 200, function(){
  3393. $this._ctrlScrollBut();
  3394. });
  3395. } else {
  3396. this._ctrlScrollBut();
  3397. }
  3398. },
  3399. _getTaskBarW:function(){
  3400. return this._taskBox.width()- (this._prevBut.is(":hidden")?this._prevBut.width()+2:0) - (this._nextBut.is(":hidden")?this._nextBut.width()+2:0);
  3401. },
  3402. _scrollTask:function(task){
  3403. var $this = this;
  3404. if(task.position().left + this._getLeft()+task.outerWidth() > this._getBarWidth()) {
  3405. var left = this._getTaskBarW()- task.position().left - task.outerWidth(true) - 2;
  3406. this._taskList.animate({left: left + 'px'}, 200, function(){
  3407. $this._ctrlScrollBut();
  3408. });
  3409. } else if(task.position().left + this._getLeft() < 0) {
  3410. var left = this._getLeft()-(task.position().left + this._getLeft());
  3411. this._taskList.animate({left: left + 'px'}, 200, function(){
  3412. $this._ctrlScrollBut();
  3413. });
  3414. }
  3415. },
  3416. /**
  3417. * 控制左右移动按钮何时显示与隐藏
  3418. */
  3419. _ctrlScrollBut:function(){
  3420. var iW = this._tasksW(this._getTasks());
  3421. if (this._getTaskBarW() > iW) {
  3422. this._taskBox.removeClass(this._op.boxMargin);
  3423. this._nextBut.hide();
  3424. this._prevBut.hide();
  3425. if(this._getTasks().eq(0)[0])this._scrollTask(this._getTasks().eq(0));
  3426. } else {
  3427. this._taskBox.addClass(this._op.boxMargin);
  3428. this._nextBut.show().removeClass(this._op.nextDis);
  3429. this._prevBut.show().removeClass(this._op.prevDis);
  3430. if (this._getLeft() >= 0){
  3431. this._prevBut.addClass(this._op.prevDis);
  3432. }
  3433. if (this._getLeft() <= this._getTaskBarW() - iW) {
  3434. this._nextBut.addClass(this._op.nextDis);
  3435. }
  3436. }
  3437. },
  3438. _getLeft: function(){
  3439. return this._taskList.position().left;
  3440. },
  3441. /**
  3442. * 取得第一个完全显示在taskbar上的任务
  3443. */
  3444. _visibleStart: function(){
  3445. var iLeft = this._getLeft();
  3446. var jTasks = this._getTasks();
  3447. for (var i=0; i<jTasks.size(); i++){
  3448. if (jTasks.eq(i).position().left + jTasks.eq(i).outerWidth(true) + iLeft >= 0) return jTasks.eq(i);
  3449. }
  3450. return jTasks.eq(0);
  3451. },
  3452. /**
  3453. * 取得最后一个完全显示在taskbar上的任务
  3454. */
  3455. _visibleEnd: function(){
  3456. var iLeft = this._getLeft();
  3457. var jTasks = this._getTasks();
  3458. for (var i=0; i<jTasks.size(); i++){
  3459. if (jTasks.eq(i).position().left + jTasks.eq(i).outerWidth(true) + iLeft > this._getBarWidth()) return jTasks.eq(i);
  3460. }
  3461. return jTasks.eq(jTasks.size()-1);
  3462. },
  3463. /**
  3464. * 取得所有的任务
  3465. */
  3466. _getTasks:function(){
  3467. return this._taskList.find(">li");
  3468. },
  3469. /**
  3470. * 计算所传入的所有任务的宽度和
  3471. * @param {Object} jTasks
  3472. */
  3473. _tasksW:function(jTasks){
  3474. var iW = 0;
  3475. jTasks.each(function(){
  3476. iW += $(this).outerWidth(true);
  3477. });
  3478. return iW;
  3479. },
  3480. _getBarWidth: function() {
  3481. return this._taskBar.innerWidth();
  3482. },
  3483. /**
  3484. * 在任务栏上新加一个任务
  3485. * @param {Object} id
  3486. * @param {Object} title
  3487. */
  3488. addDialog: function(id, title){
  3489. this.show();
  3490. var task = $("#"+id,this._taskList);
  3491. if (!task[0]) {
  3492. var taskFrag = '<li id="#taskid#"><div class="taskbutton"><span>#title#</span></div><div class="close">Close</div></li>';
  3493. this._taskList.append(taskFrag.replace("#taskid#", id).replace("#title#", title));
  3494. task = $("#"+id,this._taskList);
  3495. task.jTask();
  3496. } else {
  3497. $(">div>span", task).text(title);
  3498. }
  3499. this._contextmenu(task);
  3500. this.switchTask(id);
  3501. this._scrollTask(task);
  3502. },
  3503. /**
  3504. * 关闭一个任务
  3505. * @param {Object} id
  3506. */
  3507. closeDialog: function(obj){
  3508. var task = (typeof obj == 'string')? $("#"+obj, this._taskList):obj;
  3509. task.remove();
  3510. if(this._getTasks().size() == 0){
  3511. this.hide();
  3512. }
  3513. this._scrollCurrent();
  3514. },
  3515. /**
  3516. *
  3517. * @param {Object} id or dialog
  3518. */
  3519. restoreDialog:function(obj){
  3520. var dialog = (typeof obj == 'string')?$("body").data(obj):obj;
  3521. var id = (typeof obj == 'string')?obj:dialog.data("id");
  3522. var task = $.taskBar.getTask(id);
  3523. $(".resizable").css({top: $(window).height()-60,left:$(task).position().left,height:$(task).outerHeight(),width:$(task).outerWidth()
  3524. }).show().animate({top:$(dialog).css("top"),left: $(dialog).css("left"),width:$(dialog).css("width"),height:$(dialog).css("height")},250,function(){
  3525. $(this).hide();
  3526. $(dialog).show();
  3527. $.pdialog.attachShadow(dialog);
  3528. });
  3529. $.taskBar.switchTask(id);
  3530. },
  3531. /**
  3532. * 把任务变成不是当前的
  3533. * @param {Object} id
  3534. */
  3535. inactive:function(id){
  3536. $("#" + id, this._taskList).removeClass("selected");
  3537. },
  3538. /**
  3539. * 向左移一个任务
  3540. */
  3541. scrollLeft: function(){
  3542. var task = this._visibleStart();
  3543. this._scrollTask(task);
  3544. },
  3545. /**
  3546. * 向右移一个任务
  3547. */
  3548. scrollRight: function(){
  3549. var task = this._visibleEnd();
  3550. this._scrollTask(task);
  3551. },
  3552. /**
  3553. * 移出当前点击的任务
  3554. * @param {Object} task
  3555. */
  3556. scrollCurrent:function(task){
  3557. this._scrollTask(task);
  3558. },
  3559. /**
  3560. * 切换任务
  3561. * @param {Object} id
  3562. */
  3563. switchTask:function(id) {
  3564. this._getCurrent().removeClass("selected");
  3565. this.getTask(id).addClass("selected");
  3566. },
  3567. _getCurrent:function() {
  3568. return this._taskList.find(">.selected");
  3569. },
  3570. getTask:function(id) {
  3571. return $("#" + id, this._taskList);
  3572. },
  3573. /**
  3574. * 显示任务栏
  3575. */
  3576. show:function(){
  3577. if (this._taskBar.is(":hidden")) {
  3578. this._taskBar.css("top", $(window).height() - 34 + this._taskBar.outerHeight()).show();
  3579. this._taskBar.animate({
  3580. top: $(window).height() - this._taskBar.outerHeight()
  3581. }, 500);
  3582. }
  3583. },
  3584. /**
  3585. * 隐藏任务栏
  3586. */
  3587. hide:function(){
  3588. this._taskBar.animate({
  3589. top: $(window).height() - 29 + this._taskBar.outerHeight(true)
  3590. }, 500,function(){
  3591. $.taskBar._taskBar.hide();
  3592. });
  3593. }
  3594. }
  3595. })(jQuery);/**
  3596. * @author ZhangHuihua@msn.com
  3597. *
  3598. */
  3599. /**
  3600. * 普通ajax表单提交
  3601. * @param {Object} form
  3602. * @param {Object} callback
  3603. * @param {String} confirmMsg 提示确认信息
  3604. */
  3605. function validateCallback(form, callback, confirmMsg) {
  3606. var $form = $(form);
  3607. if (!$form.valid()) {
  3608. return false;
  3609. }
  3610. var _submitFn = function(){
  3611. $.ajax({
  3612. type: form.method || 'POST',
  3613. url:$form.attr("action"),
  3614. data:$form.serializeArray(),
  3615. dataType:"json",
  3616. cache: false,
  3617. success: callback || DWZ.ajaxDone,
  3618. error: DWZ.ajaxError
  3619. });
  3620. }
  3621. if (confirmMsg) {
  3622. alertMsg.confirm(confirmMsg, {okCall: _submitFn});
  3623. } else {
  3624. _submitFn();
  3625. }
  3626. return false;
  3627. }
  3628. /**
  3629. * 带文件上传的ajax表单提交
  3630. * @param {Object} form
  3631. * @param {Object} callback
  3632. */
  3633. function iframeCallback(form, callback){
  3634. var $form = $(form), $iframe = $("#callbackframe");
  3635. if(!$form.valid()) {return false;}
  3636. if ($iframe.size() == 0) {
  3637. $iframe = $("<iframe id='callbackframe' name='callbackframe' src='about:blank' style='display:none'></iframe>").appendTo("body");
  3638. }
  3639. if(!form.ajax) {
  3640. $form.append('<input type="hidden" name="ajax" value="1" />');
  3641. }
  3642. form.target = "callbackframe";
  3643. _iframeResponse($iframe[0], callback || DWZ.ajaxDone);
  3644. }
  3645. function _iframeResponse(iframe, callback){
  3646. var $iframe = $(iframe), $document = $(document);
  3647. $document.trigger("ajaxStart");
  3648. $iframe.bind("load", function(event){
  3649. $iframe.unbind("load");
  3650. $document.trigger("ajaxStop");
  3651. if (iframe.src == "javascript:'%3Chtml%3E%3C/html%3E';" || // For Safari
  3652. iframe.src == "javascript:'<html></html>';") { // For FF, IE
  3653. return;
  3654. }
  3655. var doc = iframe.contentDocument || iframe.document;
  3656. // fixing Opera 9.26,10.00
  3657. if (doc.readyState && doc.readyState != 'complete') return;
  3658. // fixing Opera 9.64
  3659. if (doc.body && doc.body.innerHTML == "false") return;
  3660. var response;
  3661. if (doc.XMLDocument) {
  3662. // response is a xml document Internet Explorer property
  3663. response = doc.XMLDocument;
  3664. } else if (doc.body){
  3665. try{
  3666. response = $iframe.contents().find("body").text();
  3667. response = jQuery.parseJSON(response);
  3668. } catch (e){ // response is html document or plain text
  3669. response = doc.body.innerHTML;
  3670. }
  3671. } else {
  3672. // response is a xml document
  3673. response = doc;
  3674. }
  3675. callback(response);
  3676. });
  3677. }
  3678. /**
  3679. * navTabAjaxDone是DWZ框架中预定义的表单提交回调函数.
  3680. * 服务器转回navTabId可以把那个navTab标记为reloadFlag=1, 下次切换到那个navTab时会重新载入内容.
  3681. * callbackType如果是closeCurrent就会关闭当前tab
  3682. * 只有callbackType="forward"时需要forwardUrl值
  3683. * navTabAjaxDone这个回调函数基本可以通用了,如果还有特殊需要也可以自定义回调函数.
  3684. * 如果表单提交只提示操作是否成功, 就可以不指定回调函数. 框架会默认调用DWZ.ajaxDone()
  3685. * <form action="/user.do?method=save" onsubmit="return validateCallback(this, navTabAjaxDone)">
  3686. *
  3687. * form提交后返回json数据结构statusCode=DWZ.statusCode.ok表示操作成功, 做页面跳转等操作. statusCode=DWZ.statusCode.error表示操作失败, 提示错误原因.
  3688. * statusCode=DWZ.statusCode.timeout表示session超时,下次点击时跳转到DWZ.loginUrl
  3689. * {"statusCode":"200", "message":"操作成功", "navTabId":"navNewsLi", "forwardUrl":"", "callbackType":"closeCurrent", "rel"."xxxId"}
  3690. * {"statusCode":"300", "message":"操作失败"}
  3691. * {"statusCode":"301", "message":"会话超时"}
  3692. *
  3693. */
  3694. function navTabAjaxDone(json){
  3695. DWZ.ajaxDone(json);
  3696. if (json[DWZ.keys.statusCode] == DWZ.statusCode.ok){
  3697. if (json.navTabId){ //把指定navTab页面标记为需要“重新载入”。注意navTabId不能是当前navTab页面的
  3698. navTab.reloadFlag(json.navTabId);
  3699. } else { //重新载入当前navTab页面
  3700. var $pagerForm = $("#pagerForm", navTab.getCurrentPanel());
  3701. var args = $pagerForm.size()>0 ? $pagerForm.serializeArray() : {}
  3702. navTabPageBreak(args, json.rel);
  3703. }
  3704. if ("closeCurrent" == json.callbackType) {
  3705. setTimeout(function(){navTab.closeCurrentTab(json.navTabId);}, 100);
  3706. } else if ("forward" == json.callbackType) {
  3707. navTab.reload(json.forwardUrl);
  3708. } else if ("forwardConfirm" == json.callbackType) {
  3709. alertMsg.confirm(json.confirmMsg || DWZ.msg("forwardConfirmMsg"), {
  3710. okCall: function(){
  3711. navTab.reload(json.forwardUrl);
  3712. },
  3713. cancelCall: function(){
  3714. navTab.closeCurrentTab(json.navTabId);
  3715. }
  3716. });
  3717. } else {
  3718. navTab.getCurrentPanel().find(":input[initValue]").each(function(){
  3719. var initVal = $(this).attr("initValue");
  3720. $(this).val(initVal);
  3721. });
  3722. }
  3723. }
  3724. }
  3725. /**
  3726. * dialog上的表单提交回调函数
  3727. * 当前navTab页面有pagerForm就重新加载
  3728. * 服务器转回navTabId,可以重新载入指定的navTab. statusCode=DWZ.statusCode.ok表示操作成功, 自动关闭当前dialog
  3729. *
  3730. * form提交后返回json数据结构,json格式和navTabAjaxDone一致
  3731. */
  3732. function dialogAjaxDone(json){
  3733. DWZ.ajaxDone(json);
  3734. if (json[DWZ.keys.statusCode] == DWZ.statusCode.ok){
  3735. if (json.navTabId){
  3736. navTab.reload(json.forwardUrl, {navTabId: json.navTabId});
  3737. } else {
  3738. var $pagerForm = $("#pagerForm", navTab.getCurrentPanel());
  3739. var args = $pagerForm.size()>0 ? $pagerForm.serializeArray() : {}
  3740. navTabPageBreak(args, json.rel);
  3741. }
  3742. if ("closeCurrent" == json.callbackType) {
  3743. $.pdialog.closeCurrent();
  3744. }
  3745. }
  3746. }
  3747. /**
  3748. * 处理navTab上的查询, 会重新载入当前navTab
  3749. * @param {Object} form
  3750. */
  3751. function navTabSearch(form, navTabId){
  3752. var $form = $(form);
  3753. if (form[DWZ.pageInfo.pageNum]) form[DWZ.pageInfo.pageNum].value = 1;
  3754. navTab.reload($form.attr('action'), {data: $form.serializeArray(), navTabId:navTabId});
  3755. return false;
  3756. }
  3757. /**
  3758. * 处理dialog弹出层上的查询, 会重新载入当前dialog
  3759. * @param {Object} form
  3760. */
  3761. function dialogSearch(form){
  3762. var $form = $(form);
  3763. if (form[DWZ.pageInfo.pageNum]) form[DWZ.pageInfo.pageNum].value = 1;
  3764. $.pdialog.reload($form.attr('action'), {data: $form.serializeArray()});
  3765. return false;
  3766. }
  3767. function dwzSearch(form, targetType){
  3768. if (targetType == "dialog") dialogSearch(form);
  3769. else navTabSearch(form);
  3770. return false;
  3771. }
  3772. /**
  3773. * 处理div上的局部查询, 会重新载入指定div
  3774. * @param {Object} form
  3775. */
  3776. function divSearch(form, rel){
  3777. var $form = $(form);
  3778. if (form[DWZ.pageInfo.pageNum]) form[DWZ.pageInfo.pageNum].value = 1;
  3779. if (rel) {
  3780. var $box = $("#" + rel);
  3781. $box.ajaxUrl({
  3782. type:"POST", url:$form.attr("action"), data: $form.serializeArray(), callback:function(){
  3783. $box.find("[layoutH]").layoutH();
  3784. }
  3785. });
  3786. }
  3787. return false;
  3788. }
  3789. /**
  3790. *
  3791. * @param {Object} args {pageNum:"",numPerPage:"",orderField:"",orderDirection:""}
  3792. * @param String formId 分页表单选择器,非必填项默认值是 "pagerForm"
  3793. */
  3794. function _getPagerForm($parent, args) {
  3795. var form = $("#pagerForm", $parent).get(0);
  3796. if (form) {
  3797. if (args["pageNum"]) form[DWZ.pageInfo.pageNum].value = args["pageNum"];
  3798. if (args["numPerPage"]) form[DWZ.pageInfo.numPerPage].value = args["numPerPage"];
  3799. if (args["orderField"]) form[DWZ.pageInfo.orderField].value = args["orderField"];
  3800. if (args["orderDirection"] && form[DWZ.pageInfo.orderDirection]) form[DWZ.pageInfo.orderDirection].value = args["orderDirection"];
  3801. }
  3802. return form;
  3803. }
  3804. /**
  3805. * 处理navTab中的分页和排序
  3806. * targetType: navTab 或 dialog
  3807. * rel: 可选 用于局部刷新div id号
  3808. * data: pagerForm参数 {pageNum:"n", numPerPage:"n", orderField:"xxx", orderDirection:""}
  3809. * callback: 加载完成回调函数
  3810. */
  3811. function dwzPageBreak(options){
  3812. var op = $.extend({ targetType:"navTab", rel:"", data:{pageNum:"", numPerPage:"", orderField:"", orderDirection:""}, callback:null}, options);
  3813. var $parent = op.targetType == "dialog" ? $.pdialog.getCurrent() : navTab.getCurrentPanel();
  3814. if (op.rel) {
  3815. var $box = $parent.find("#" + op.rel);
  3816. var form = _getPagerForm($box, op.data);
  3817. if (form) {
  3818. $box.ajaxUrl({
  3819. type:"POST", url:$(form).attr("action"), data: $(form).serializeArray(), callback:function(){
  3820. $box.find("[layoutH]").layoutH();
  3821. }
  3822. });
  3823. }
  3824. } else {
  3825. var form = _getPagerForm($parent, op.data);
  3826. var params = $(form).serializeArray();
  3827. if (op.targetType == "dialog") {
  3828. if (form) $.pdialog.reload($(form).attr("action"), {data: params, callback: op.callback});
  3829. } else {
  3830. if (form) navTab.reload($(form).attr("action"), {data: params, callback: op.callback});
  3831. }
  3832. }
  3833. }
  3834. /**
  3835. * 处理navTab中的分页和排序
  3836. * @param args {pageNum:"n", numPerPage:"n", orderField:"xxx", orderDirection:""}
  3837. * @param rel: 可选 用于局部刷新div id号
  3838. */
  3839. function navTabPageBreak(args, rel){
  3840. dwzPageBreak({targetType:"navTab", rel:rel, data:args});
  3841. }
  3842. /**
  3843. * 处理dialog中的分页和排序
  3844. * 参数同 navTabPageBreak
  3845. */
  3846. function dialogPageBreak(args, rel){
  3847. dwzPageBreak({targetType:"dialog", rel:rel, data:args});
  3848. }
  3849. function ajaxTodo(url, callback){
  3850. var $callback = callback || navTabAjaxDone;
  3851. if (! $.isFunction($callback)) $callback = eval('(' + callback + ')');
  3852. $.ajax({
  3853. type:'POST',
  3854. url:url,
  3855. dataType:"json",
  3856. cache: false,
  3857. success: $callback,
  3858. error: DWZ.ajaxError
  3859. });
  3860. }
  3861. /**
  3862. * http://www.uploadify.com/documentation/uploadify/onqueuecomplete/
  3863. */
  3864. function uploadifyQueueComplete(queueData){
  3865. var msg = "The total number of files uploaded: "+queueData.uploadsSuccessful+"<br/>"
  3866. + "The total number of errors while uploading: "+queueData.uploadsErrored+"<br/>"
  3867. + "The total number of bytes uploaded: "+queueData.queueBytesUploaded+"<br/>"
  3868. + "The average speed of all uploaded files: "+queueData.averageSpeed;
  3869. if (queueData.uploadsErrored) {
  3870. alertMsg.error(msg);
  3871. } else {
  3872. alertMsg.correct(msg);
  3873. }
  3874. }
  3875. /**
  3876. * http://www.uploadify.com/documentation/uploadify/onuploadsuccess/
  3877. */
  3878. function uploadifySuccess(file, data, response){
  3879. alert(data)
  3880. }
  3881. /**
  3882. * http://www.uploadify.com/documentation/uploadify/onuploaderror/
  3883. */
  3884. function uploadifyError(file, errorCode, errorMsg) {
  3885. alertMsg.error(errorCode+": "+errorMsg);
  3886. }
  3887. /**
  3888. * http://www.uploadify.com/documentation/
  3889. * @param {Object} event
  3890. * @param {Object} queueID
  3891. * @param {Object} fileObj
  3892. * @param {Object} errorObj
  3893. */
  3894. function uploadifyError(event, queueId, fileObj, errorObj){
  3895. alert("event:" + event + "\nqueueId:" + queueId + "\nfileObj.name:"
  3896. + fileObj.name + "\nerrorObj.type:" + errorObj.type + "\nerrorObj.info:" + errorObj.info);
  3897. }
  3898. $.fn.extend({
  3899. ajaxTodo:function(){
  3900. return this.each(function(){
  3901. var $this = $(this);
  3902. $this.click(function(event){
  3903. if ($this.hasClass('disabled')) {
  3904. return false;
  3905. }
  3906. var url = unescape($this.attr("href")).replaceTmById($(event.target).parents(".unitBox:first"));
  3907. DWZ.debug(url);
  3908. if (!url.isFinishedTm()) {
  3909. alertMsg.error($this.attr("warn") || DWZ.msg("alertSelectMsg"));
  3910. return false;
  3911. }
  3912. var title = $this.attr("title");
  3913. if (title) {
  3914. alertMsg.confirm(title, {
  3915. okCall: function(){
  3916. ajaxTodo(url, $this.attr("callback"));
  3917. }
  3918. });
  3919. } else {
  3920. ajaxTodo(url, $this.attr("callback"));
  3921. }
  3922. event.preventDefault();
  3923. });
  3924. });
  3925. },
  3926. dwzExport: function(){
  3927. function _doExport($this) {
  3928. var $p = $this.attr("targetType") == "dialog" ? $.pdialog.getCurrent() : navTab.getCurrentPanel();
  3929. var $form = $("#pagerForm", $p);
  3930. var url = $this.attr("href");
  3931. //window.location = url+(url.indexOf('?') == -1 ? "?" : "&")+$form.serialize();
  3932. var $iframe = $("#callbackframe");
  3933. if ($iframe.size() == 0) {
  3934. $iframe = $("<iframe id='callbackframe' name='callbackframe' src='about:blank' style='display:none'></iframe>").appendTo("body");
  3935. }
  3936. form.target = "callbackframe";
  3937. }
  3938. return this.each(function(){
  3939. var $this = $(this);
  3940. $this.click(function(event){
  3941. var title = $this.attr("title");
  3942. if (title) {
  3943. alertMsg.confirm(title, {
  3944. okCall: function(){_doExport($this);}
  3945. });
  3946. } else {_doExport($this);}
  3947. event.preventDefault();
  3948. });
  3949. });
  3950. }
  3951. });
  3952. /**
  3953. *
  3954. * @author ZhangHuihua@msn.com
  3955. * @param {Object} opts Several options
  3956. */
  3957. (function($){
  3958. $.fn.extend({
  3959. pagination: function(opts){
  3960. var setting = {
  3961. first$:"li.j-first", prev$:"li.j-prev", next$:"li.j-next", last$:"li.j-last", nums$:"li.j-num>a", jumpto$:"li.jumpto",
  3962. pageNumFrag:'<li class="#liClass#"><a href="javascript:;">#pageNum#</a></li>'
  3963. };
  3964. return this.each(function(){
  3965. var $this = $(this);
  3966. var pc = new Pagination(opts);
  3967. var interval = pc.getInterval();
  3968. var pageNumFrag = '';
  3969. for (var i=interval.start; i<interval.end;i++){
  3970. pageNumFrag += setting.pageNumFrag.replaceAll("#pageNum#", i).replaceAll("#liClass#", i==pc.getCurrentPage() ? 'selected j-num' : 'j-num');
  3971. }
  3972. $this.html(DWZ.frag["pagination"].replaceAll("#pageNumFrag#", pageNumFrag).replaceAll("#currentPage#", pc.getCurrentPage())).find("li").hoverClass();
  3973. var $first = $this.find(setting.first$);
  3974. var $prev = $this.find(setting.prev$);
  3975. var $next = $this.find(setting.next$);
  3976. var $last = $this.find(setting.last$);
  3977. if (pc.hasPrev()){
  3978. $first.add($prev).find(">span").hide();
  3979. _bindEvent($prev, pc.getCurrentPage()-1, pc.targetType(), pc.rel());
  3980. _bindEvent($first, 1, pc.targetType(), pc.rel());
  3981. } else {
  3982. $first.add($prev).addClass("disabled").find(">a").hide();
  3983. }
  3984. if (pc.hasNext()) {
  3985. $next.add($last).find(">span").hide();
  3986. _bindEvent($next, pc.getCurrentPage()+1, pc.targetType(), pc.rel());
  3987. _bindEvent($last, pc.numPages(), pc.targetType(), pc.rel());
  3988. } else {
  3989. $next.add($last).addClass("disabled").find(">a").hide();
  3990. }
  3991. $this.find(setting.nums$).each(function(i){
  3992. _bindEvent($(this), i+interval.start, pc.targetType(), pc.rel());
  3993. });
  3994. $this.find(setting.jumpto$).each(function(){
  3995. var $this = $(this);
  3996. var $inputBox = $this.find(":text");
  3997. var $button = $this.find(":button");
  3998. $button.click(function(event){
  3999. var pageNum = $inputBox.val();
  4000. if (pageNum && pageNum.isPositiveInteger()) {
  4001. dwzPageBreak({targetType:pc.targetType(), rel:pc.rel(), data: {pageNum:pageNum}});
  4002. }
  4003. });
  4004. $inputBox.keyup(function(event){
  4005. if (event.keyCode == DWZ.keyCode.ENTER) $button.click();
  4006. });
  4007. });
  4008. });
  4009. function _bindEvent($target, pageNum, targetType, rel){
  4010. $target.bind("click", {pageNum:pageNum}, function(event){
  4011. dwzPageBreak({targetType:targetType, rel:rel, data:{pageNum:event.data.pageNum}});
  4012. event.preventDefault();
  4013. });
  4014. }
  4015. },
  4016. orderBy: function(options){
  4017. var op = $.extend({ targetType:"navTab", rel:"", asc:"asc", desc:"desc"}, options);
  4018. return this.each(function(){
  4019. var $this = $(this).css({cursor:"pointer"}).click(function(){
  4020. var orderField = $this.attr("orderField");
  4021. var orderDirection = $this.hasClass(op.asc) ? op.desc : op.asc;
  4022. dwzPageBreak({targetType:op.targetType, rel:op.rel, data:{orderField: orderField, orderDirection: orderDirection}});
  4023. });
  4024. });
  4025. },
  4026. pagerForm: function(options){
  4027. var op = $.extend({pagerForm$:"#pagerForm", parentBox:document}, options);
  4028. var frag = '<input type="hidden" name="#name#" value="#value#" />';
  4029. return this.each(function(){
  4030. var $searchForm = $(this), $pagerForm = $(op.pagerForm$, op.parentBox);
  4031. var actionUrl = $pagerForm.attr("action").replaceAll("#rel#", $searchForm.attr("action"));
  4032. $pagerForm.attr("action", actionUrl);
  4033. $searchForm.find(":input").each(function(){
  4034. var $input = $(this), name = $input.attr("name");
  4035. if (name && (!$input.is(":checkbox,:radio") || $input.is(":checked"))){
  4036. if ($pagerForm.find(":input[name='"+name+"']").length == 0) {
  4037. var inputFrag = frag.replaceAll("#name#", name).replaceAll("#value#", $input.val());
  4038. $pagerForm.append(inputFrag);
  4039. }
  4040. }
  4041. });
  4042. });
  4043. }
  4044. });
  4045. var Pagination = function(opts) {
  4046. this.opts = $.extend({
  4047. targetType:"navTab", // navTab, dialog
  4048. rel:"", //用于局部刷新div id号
  4049. totalCount:0,
  4050. numPerPage:10,
  4051. pageNumShown:10,
  4052. currentPage:1,
  4053. callback:function(){return false;}
  4054. }, opts);
  4055. }
  4056. $.extend(Pagination.prototype, {
  4057. targetType:function(){return this.opts.targetType},
  4058. rel:function(){return this.opts.rel},
  4059. numPages:function() {
  4060. return Math.ceil(this.opts.totalCount/this.opts.numPerPage);
  4061. },
  4062. getInterval:function(){
  4063. var ne_half = Math.ceil(this.opts.pageNumShown/2);
  4064. var np = this.numPages();
  4065. var upper_limit = np - this.opts.pageNumShown;
  4066. var start = this.getCurrentPage() > ne_half ? Math.max( Math.min(this.getCurrentPage() - ne_half, upper_limit), 0 ) : 0;
  4067. var end = this.getCurrentPage() > ne_half ? Math.min(this.getCurrentPage()+ne_half, np) : Math.min(this.opts.pageNumShown, np);
  4068. return {start:start+1, end:end+1};
  4069. },
  4070. getCurrentPage:function(){
  4071. var currentPage = parseInt(this.opts.currentPage);
  4072. if (isNaN(currentPage)) return 1;
  4073. return currentPage;
  4074. },
  4075. hasPrev:function(){
  4076. return this.getCurrentPage() > 1;
  4077. },
  4078. hasNext:function(){
  4079. return this.getCurrentPage() < this.numPages();
  4080. }
  4081. });
  4082. })(jQuery);
  4083. /**
  4084. * @author ZhangHuihua@msn.com
  4085. */
  4086. (function($){
  4087. var _lookup = {currentGroup:"", suffix:"", $target:null, pk:"id"};
  4088. var _util = {
  4089. _lookupPrefix: function(key){
  4090. var strDot = _lookup.currentGroup ? "." : "";
  4091. return _lookup.currentGroup + strDot + key + _lookup.suffix;
  4092. },
  4093. lookupPk: function(key){
  4094. return this._lookupPrefix(key);
  4095. },
  4096. lookupField: function(key){
  4097. return this.lookupPk(key);
  4098. }
  4099. };
  4100. $.extend({
  4101. bringBackSuggest: function(args){
  4102. var $box = _lookup['$target'].parents(".unitBox:first");
  4103. $box.find(":input").each(function(){
  4104. var $input = $(this), inputName = $input.attr("name");
  4105. for (var key in args) {
  4106. var name = (_lookup.pk == key) ? _util.lookupPk(key) : _util.lookupField(key);
  4107. if (name == inputName) {
  4108. $input.val(args[key]);
  4109. break;
  4110. }
  4111. }
  4112. });
  4113. },
  4114. bringBack: function(args){
  4115. $.bringBackSuggest(args);
  4116. $.pdialog.closeCurrent();
  4117. }
  4118. });
  4119. $.fn.extend({
  4120. lookup: function(){
  4121. return this.each(function(){
  4122. var $this = $(this), options = {mask:true,
  4123. width:$this.attr('width')||820, height:$this.attr('height')||400,
  4124. maxable:eval($this.attr("maxable") || "true"),
  4125. resizable:eval($this.attr("resizable") || "true")
  4126. };
  4127. $this.click(function(event){
  4128. _lookup = $.extend(_lookup, {
  4129. currentGroup: $this.attr("lookupGroup") || "",
  4130. suffix: $this.attr("suffix") || "",
  4131. $target: $this,
  4132. pk: $this.attr("lookupPk") || "id"
  4133. });
  4134. var url = unescape($this.attr("href")).replaceTmById($(event.target).parents(".unitBox:first"));
  4135. if (!url.isFinishedTm()) {
  4136. alertMsg.error($this.attr("warn") || DWZ.msg("alertSelectMsg"));
  4137. return false;
  4138. }
  4139. $.pdialog.open(url, "_blank", $this.attr("title") || $this.text(), options);
  4140. return false;
  4141. });
  4142. });
  4143. },
  4144. multLookup: function(){
  4145. return this.each(function(){
  4146. var $this = $(this), args={};
  4147. $this.click(function(event){
  4148. var $unitBox = $this.parents(".unitBox:first");
  4149. $unitBox.find("[name='"+$this.attr("multLookup")+"']").filter(":checked").each(function(){
  4150. var _args = DWZ.jsonEval($(this).val());
  4151. for (var key in _args) {
  4152. var value = args[key] ? args[key]+"," : "";
  4153. args[key] = value + _args[key];
  4154. }
  4155. });
  4156. if ($.isEmptyObject(args)) {
  4157. alertMsg.error($this.attr("warn") || DWZ.msg("alertSelectMsg"));
  4158. return false;
  4159. }
  4160. $.bringBack(args);
  4161. });
  4162. });
  4163. },
  4164. suggest: function(){
  4165. var op = {suggest$:"#suggest", suggestShadow$: "#suggestShadow"};
  4166. var selectedIndex = -1;
  4167. return this.each(function(){
  4168. var $input = $(this).attr('autocomplete', 'off').keydown(function(event){
  4169. if (event.keyCode == DWZ.keyCode.ENTER && $(op.suggest$).is(':visible')) return false; //屏蔽回车提交
  4170. });
  4171. var suggestFields=$input.attr('suggestFields').split(",");
  4172. function _show(event){
  4173. var offset = $input.offset();
  4174. var iTop = offset.top+this.offsetHeight;
  4175. var $suggest = $(op.suggest$);
  4176. if ($suggest.size() == 0) $suggest = $('<div id="suggest"></div>').appendTo($('body'));
  4177. $suggest.css({
  4178. left:offset.left+'px',
  4179. top:iTop+'px'
  4180. }).show();
  4181. _lookup = $.extend(_lookup, {
  4182. currentGroup: $input.attr("lookupGroup") || "",
  4183. suffix: $input.attr("suffix") || "",
  4184. $target: $input,
  4185. pk: $input.attr("lookupPk") || "id"
  4186. });
  4187. var url = unescape($input.attr("suggestUrl")).replaceTmById($(event.target).parents(".unitBox:first"));
  4188. if (!url.isFinishedTm()) {
  4189. alertMsg.error($input.attr("warn") || DWZ.msg("alertSelectMsg"));
  4190. return false;
  4191. }
  4192. var postData = {};
  4193. postData[$input.attr("postField")||"inputValue"] = $input.val();
  4194. $.ajax({
  4195. global:false,
  4196. type:'POST', dataType:"json", url:url, cache: false,
  4197. data: postData,
  4198. success: function(response){
  4199. if (!response) return;
  4200. var html = '';
  4201. $.each(response, function(i){
  4202. var liAttr = '', liLabel = '';
  4203. for (var i=0; i<suggestFields.length; i++){
  4204. var str = this[suggestFields[i]];
  4205. if (str) {
  4206. if (liLabel) liLabel += '-';
  4207. liLabel += str;
  4208. }
  4209. }
  4210. for (var key in this) {
  4211. if (liAttr) liAttr += ',';
  4212. liAttr += key+":'"+this[key]+"'";
  4213. }
  4214. html += '<li lookupAttrs="'+liAttr+'">' + liLabel + '</li>';
  4215. });
  4216. var $lis = $suggest.html('<ul>'+html+'</ul>').find("li");
  4217. $lis.hoverClass("selected").click(function(){
  4218. _select($(this));
  4219. });
  4220. if ($lis.size() == 1 && event.keyCode != DWZ.keyCode.BACKSPACE) {
  4221. _select($lis.eq(0));
  4222. } else if ($lis.size() == 0){
  4223. var jsonStr = "";
  4224. for (var i=0; i<suggestFields.length; i++){
  4225. if (_util.lookupField(suggestFields[i]) == event.target.name) {
  4226. break;
  4227. }
  4228. if (jsonStr) jsonStr += ',';
  4229. jsonStr += suggestFields[i]+":''";
  4230. }
  4231. jsonStr = "{"+_lookup.pk+":''," + jsonStr +"}";
  4232. $.bringBackSuggest(DWZ.jsonEval(jsonStr));
  4233. }
  4234. },
  4235. error: function(){
  4236. $suggest.html('');
  4237. }
  4238. });
  4239. $(document).bind("click", _close);
  4240. return false;
  4241. }
  4242. function _select($item){
  4243. var jsonStr = "{"+ $item.attr('lookupAttrs') +"}";
  4244. $.bringBackSuggest(DWZ.jsonEval(jsonStr));
  4245. }
  4246. function _close(){
  4247. $(op.suggest$).html('').hide();
  4248. selectedIndex = -1;
  4249. $(document).unbind("click", _close);
  4250. }
  4251. $input.focus(_show).click(false).keyup(function(event){
  4252. var $items = $(op.suggest$).find("li");
  4253. switch(event.keyCode){
  4254. case DWZ.keyCode.ESC:
  4255. case DWZ.keyCode.TAB:
  4256. case DWZ.keyCode.SHIFT:
  4257. case DWZ.keyCode.HOME:
  4258. case DWZ.keyCode.END:
  4259. case DWZ.keyCode.LEFT:
  4260. case DWZ.keyCode.RIGHT:
  4261. break;
  4262. case DWZ.keyCode.ENTER:
  4263. _close();
  4264. break;
  4265. case DWZ.keyCode.DOWN:
  4266. if (selectedIndex >= $items.size()-1) selectedIndex = -1;
  4267. else selectedIndex++;
  4268. break;
  4269. case DWZ.keyCode.UP:
  4270. if (selectedIndex < 0) selectedIndex = $items.size()-1;
  4271. else selectedIndex--;
  4272. break;
  4273. default:
  4274. _show(event);
  4275. }
  4276. $items.removeClass("selected");
  4277. if (selectedIndex>=0) {
  4278. var $item = $items.eq(selectedIndex).addClass("selected");
  4279. _select($item);
  4280. }
  4281. });
  4282. });
  4283. },
  4284. itemDetail: function(){
  4285. return this.each(function(){
  4286. var $table = $(this).css("clear","both"), $tbody = $table.find("tbody");
  4287. var fields=[];
  4288. $table.find("tr:first th[type]").each(function(i){
  4289. var $th = $(this);
  4290. var field = {
  4291. type: $th.attr("type") || "text",
  4292. patternDate: $th.attr("dateFmt") || "yyyy-MM-dd",
  4293. name: $th.attr("name") || "",
  4294. defaultVal: $th.attr("defaultVal") || "",
  4295. size: $th.attr("size") || "12",
  4296. enumUrl: $th.attr("enumUrl") || "",
  4297. lookupGroup: $th.attr("lookupGroup") || "",
  4298. lookupUrl: $th.attr("lookupUrl") || "",
  4299. lookupPk: $th.attr("lookupPk") || "id",
  4300. suggestUrl: $th.attr("suggestUrl"),
  4301. suggestFields: $th.attr("suggestFields"),
  4302. postField: $th.attr("postField") || "",
  4303. fieldClass: $th.attr("fieldClass") || "",
  4304. fieldAttrs: $th.attr("fieldAttrs") || ""
  4305. };
  4306. fields.push(field);
  4307. });
  4308. $tbody.find("a.btnDel").click(function(){
  4309. var $btnDel = $(this);
  4310. if ($btnDel.is("[href^=javascript:]")){
  4311. $btnDel.parents("tr:first").remove();
  4312. initSuffix($tbody);
  4313. return false;
  4314. }
  4315. function delDbData(){
  4316. $.ajax({
  4317. type:'POST', dataType:"json", url:$btnDel.attr('href'), cache: false,
  4318. success: function(){
  4319. $btnDel.parents("tr:first").remove();
  4320. initSuffix($tbody);
  4321. },
  4322. error: DWZ.ajaxError
  4323. });
  4324. }
  4325. if ($btnDel.attr("title")){
  4326. alertMsg.confirm($btnDel.attr("title"), {okCall: delDbData});
  4327. } else {
  4328. delDbData();
  4329. }
  4330. return false;
  4331. });
  4332. var addButTxt = $table.attr('addButton') || "Add New";
  4333. if (addButTxt) {
  4334. var $addBut = $('<div class="button"><div class="buttonContent"><button type="button">'+addButTxt+'</button></div></div>').insertBefore($table).find("button");
  4335. var $rowNum = $('<input type="text" name="dwz_rowNum" class="textInput" style="margin:2px;" value="1" size="2"/>').insertBefore($table);
  4336. var trTm = "";
  4337. $addBut.click(function(){
  4338. if (! trTm) trTm = trHtml(fields);
  4339. var rowNum = 1;
  4340. try{rowNum = parseInt($rowNum.val())} catch(e){}
  4341. for (var i=0; i<rowNum; i++){
  4342. var $tr = $(trTm);
  4343. $tr.appendTo($tbody).initUI().find("a.btnDel").click(function(){
  4344. $(this).parents("tr:first").remove();
  4345. initSuffix($tbody);
  4346. return false;
  4347. });
  4348. }
  4349. initSuffix($tbody);
  4350. });
  4351. }
  4352. });
  4353. /**
  4354. * 删除时重新初始化下标
  4355. */
  4356. function initSuffix($tbody) {
  4357. $tbody.find('>tr').each(function(i){
  4358. $(':input, a.btnLook, a.btnAttach', this).each(function(){
  4359. var $this = $(this), name = $this.attr('name'), val = $this.val();
  4360. if (name) $this.attr('name', name.replaceSuffix(i));
  4361. var lookupGroup = $this.attr('lookupGroup');
  4362. if (lookupGroup) {$this.attr('lookupGroup', lookupGroup.replaceSuffix(i));}
  4363. var suffix = $this.attr("suffix");
  4364. if (suffix) {$this.attr('suffix', suffix.replaceSuffix(i));}
  4365. if (val && val.indexOf("#index#") >= 0) $this.val(val.replace('#index#',i+1));
  4366. });
  4367. });
  4368. }
  4369. function tdHtml(field){
  4370. var html = '', suffix = '';
  4371. if (field.name.endsWith("[#index#]")) suffix = "[#index#]";
  4372. else if (field.name.endsWith("[]")) suffix = "[]";
  4373. var suffixFrag = suffix ? ' suffix="' + suffix + '" ' : '';
  4374. var attrFrag = '';
  4375. if (field.fieldAttrs){
  4376. var attrs = DWZ.jsonEval(field.fieldAttrs);
  4377. for (var key in attrs) {
  4378. attrFrag += key+'="'+attrs[key]+'"';
  4379. }
  4380. }
  4381. switch(field.type){
  4382. case 'del':
  4383. html = '<a href="javascript:void(0)" class="btnDel '+ field.fieldClass + '">删除</a>';
  4384. break;
  4385. case 'lookup':
  4386. var suggestFrag = '';
  4387. if (field.suggestFields) {
  4388. suggestFrag = 'autocomplete="off" lookupGroup="'+field.lookupGroup+'"'+suffixFrag+' suggestUrl="'+field.suggestUrl+'" suggestFields="'+field.suggestFields+'"' + ' postField="'+field.postField+'"';
  4389. }
  4390. html = '<input type="hidden" name="'+field.lookupGroup+'.'+field.lookupPk+suffix+'"/>'
  4391. + '<input type="text" name="'+field.name+'"'+suggestFrag+' lookupPk="'+field.lookupPk+'" size="'+field.size+'" class="'+field.fieldClass+'"/>'
  4392. + '<a class="btnLook" href="'+field.lookupUrl+'" lookupGroup="'+field.lookupGroup+'" '+suggestFrag+' lookupPk="'+field.lookupPk+'" title="查找带回">查找带回</a>';
  4393. break;
  4394. case 'attach':
  4395. html = '<input type="hidden" name="'+field.lookupGroup+'.'+field.lookupPk+suffix+'"/>'
  4396. + '<input type="text" name="'+field.name+'" size="'+field.size+'" readonly="readonly" class="'+field.fieldClass+'"/>'
  4397. + '<a class="btnAttach" href="'+field.lookupUrl+'" lookupGroup="'+field.lookupGroup+'" '+suffixFrag+' lookupPk="'+field.lookupPk+'" width="560" height="300" title="查找带回">查找带回</a>';
  4398. break;
  4399. case 'enum':
  4400. $.ajax({
  4401. type:"POST", dataType:"html", async: false,
  4402. url:field.enumUrl,
  4403. data:{inputName:field.name},
  4404. success:function(response){
  4405. html = response;
  4406. }
  4407. });
  4408. break;
  4409. case 'date':
  4410. html = '<input type="text" name="'+field.name+'" value="'+field.defaultVal+'" class="date '+field.fieldClass+'" dateFmt="'+field.patternDate+'" size="'+field.size+'"/>'
  4411. +'<a class="inputDateButton" href="javascript:void(0)">选择</a>';
  4412. break;
  4413. default:
  4414. html = '<input type="'+field.type+'" name="'+field.name+'" value="'+field.defaultVal+'" size="'+field.size+'" class="'+field.fieldClass+'" '+attrFrag+'/>';
  4415. break;
  4416. }
  4417. return '<td>'+html+'</td>';
  4418. }
  4419. function trHtml(fields){
  4420. var html = '';
  4421. $(fields).each(function(){
  4422. html += tdHtml(this);
  4423. });
  4424. return '<tr class="unitBox">'+html+'</tr>';
  4425. }
  4426. },
  4427. selectedTodo: function(){
  4428. function _getIds(selectedIds, targetType){
  4429. var ids = "";
  4430. var $box = targetType == "dialog" ? $.pdialog.getCurrent() : navTab.getCurrentPanel();
  4431. $box.find("input:checked").filter("[name='"+selectedIds+"']").each(function(i){
  4432. var val = $(this).val();
  4433. ids += i==0 ? val : ","+val;
  4434. });
  4435. return ids;
  4436. }
  4437. return this.each(function(){
  4438. var $this = $(this);
  4439. var selectedIds = $this.attr("rel") || "ids";
  4440. var postType = $this.attr("postType") || "map";
  4441. $this.click(function(){
  4442. var targetType = $this.attr("targetType");
  4443. var ids = _getIds(selectedIds, targetType);
  4444. if (!ids) {
  4445. alertMsg.error($this.attr("warn") || DWZ.msg("alertSelectMsg"));
  4446. return false;
  4447. }
  4448. var _callback = $this.attr("callback") || (targetType == "dialog" ? dialogAjaxDone : navTabAjaxDone);
  4449. if (! $.isFunction(_callback)) _callback = eval('(' + _callback + ')');
  4450. function _doPost(){
  4451. $.ajax({
  4452. type:'POST', url:$this.attr('href'), dataType:'json', cache: false,
  4453. data: function(){
  4454. if (postType == 'map'){
  4455. return $.map(ids.split(','), function(val, i) {
  4456. return {name: selectedIds, value: val};
  4457. })
  4458. } else {
  4459. var _data = {};
  4460. _data[selectedIds] = ids;
  4461. return _data;
  4462. }
  4463. }(),
  4464. success: _callback,
  4465. error: DWZ.ajaxError
  4466. });
  4467. }
  4468. var title = $this.attr("title");
  4469. if (title) {
  4470. alertMsg.confirm(title, {okCall: _doPost});
  4471. } else {
  4472. _doPost();
  4473. }
  4474. return false;
  4475. });
  4476. });
  4477. }
  4478. });
  4479. })(jQuery);
  4480. /**
  4481. * reference dwz.util.date.js
  4482. * @author ZhangHuihua@msn.com
  4483. *
  4484. */
  4485. (function($){
  4486. $.setRegional("datepicker", {
  4487. dayNames:['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
  4488. monthNames:['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
  4489. });
  4490. $.fn.datepicker = function(opts){
  4491. var setting = {
  4492. box$:"#calendar",
  4493. year$:"#calendar [name=year]", month$:"#calendar [name=month]",
  4494. tmInputs$:"#calendar .time :text", hour$:"#calendar .time .hh", minute$:"#calendar .time .mm", second$:"#calendar .time .ss",
  4495. tmBox$:"#calendar .tm", tmUp$:"#calendar .time .up", tmDown$:"#calendar .time .down",
  4496. close$:"#calendar .close", calIcon$:"a.inputDateButton",
  4497. main$:"#calendar .main", days$:"#calendar .days", dayNames$:"#calendar .dayNames",
  4498. clearBut$:"#calendar .clearBut", okBut$:"#calendar .okBut"
  4499. };
  4500. function changeTmMenu(sltClass){
  4501. var $tm = $(setting.tmBox$);
  4502. $tm.removeClass("hh").removeClass("mm").removeClass("ss");
  4503. if (sltClass) {
  4504. $tm.addClass(sltClass);
  4505. $(setting.tmInputs$).removeClass("slt").filter("." + sltClass).addClass("slt");
  4506. }
  4507. }
  4508. function clickTmMenu($input, type){
  4509. $(setting.tmBox$).find("."+type+" li").each(function(){
  4510. var $li = $(this);
  4511. $li.click(function(){
  4512. $input.val($li.text());
  4513. });
  4514. });
  4515. }
  4516. function keydownInt(e){
  4517. if (!((e.keyCode >= 48 && e.keyCode <= 57) || (e.keyCode == DWZ.keyCode.DELETE || e.keyCode == DWZ.keyCode.BACKSPACE))) { return false; }
  4518. }
  4519. function changeTm($input, type){
  4520. var ivalue = parseInt($input.val()), istart = parseInt($input.attr("start")) || 0, iend = parseInt($input.attr("end"));
  4521. var istep = parseInt($input.attr('step') || 1);
  4522. if (type == 1) {
  4523. if (ivalue <= iend-istep){$input.val(ivalue + istep);}
  4524. } else if (type == -1){
  4525. if (ivalue >= istart+istep){$input.val(ivalue - istep);}
  4526. } else if (ivalue > iend) {
  4527. $input.val(iend);
  4528. } else if (ivalue < istart) {
  4529. $input.val(istart);
  4530. }
  4531. }
  4532. return this.each(function(){
  4533. var $this = $(this);
  4534. var dp = new Datepicker($this.val(), opts);
  4535. function generateCalendar(dp){
  4536. var dw = dp.getDateWrap();
  4537. var minDate = dp.getMinDate();
  4538. var maxDate = dp.getMaxDate();
  4539. var monthStart = new Date(dw.year,dw.month-1,1);
  4540. var startDay = monthStart.getDay();
  4541. var dayStr="";
  4542. if (startDay > 0){
  4543. monthStart.setMonth(monthStart.getMonth() - 1);
  4544. var prevDateWrap = dp.getDateWrap(monthStart);
  4545. for(var t=prevDateWrap.days-startDay+1;t<=prevDateWrap.days;t++) {
  4546. var _date = new Date(dw.year,dw.month-2,t);
  4547. var _ctrClass = (_date >= minDate && _date <= maxDate) ? '' : 'disabled';
  4548. dayStr+='<dd class="other '+_ctrClass+'" chMonth="-1" day="' + t + '">'+t+'</dd>';
  4549. }
  4550. }
  4551. for(var t=1;t<=dw.days;t++){
  4552. var _date = new Date(dw.year,dw.month-1,t);
  4553. var _ctrClass = (_date >= minDate && _date <= maxDate) ? '' : 'disabled';
  4554. if(t==dw.day){
  4555. dayStr+='<dd class="slt '+_ctrClass+'" day="' + t + '">'+t+'</dd>';
  4556. }else{
  4557. dayStr+='<dd class="'+_ctrClass+'" day="' + t + '">'+t+'</dd>';
  4558. }
  4559. }
  4560. for(var t=1;t<=42-startDay-dw.days;t++){
  4561. var _date = new Date(dw.year,dw.month,t);
  4562. var _ctrClass = (_date >= minDate && _date <= maxDate) ? '' : 'disabled';
  4563. dayStr+='<dd class="other '+_ctrClass+'" chMonth="1" day="' + t + '">'+t+'</dd>';
  4564. }
  4565. var $days = $(setting.days$).html(dayStr).find("dd");
  4566. $days.not('.disabled').click(function(){
  4567. var $day = $(this);
  4568. if (!dp.hasTime()) {
  4569. $this.val(dp.formatDate(dp.changeDay($day.attr("day"), $day.attr("chMonth"))));
  4570. closeCalendar();
  4571. } else {
  4572. $days.removeClass("slt");
  4573. $day.addClass("slt");
  4574. }
  4575. });
  4576. if (!dp.hasDate()) $(setting.main$).addClass('nodate'); // 仅时间,无日期
  4577. if (dp.hasTime()) {
  4578. $("#calendar .time").show();
  4579. var $hour = $(setting.hour$).val(dw.hour).focus(function(){
  4580. changeTmMenu("hh");
  4581. });
  4582. var iMinute = parseInt(dw.minute / dp.opts.mmStep) * dp.opts.mmStep;
  4583. var $minute = $(setting.minute$).val(iMinute).attr('step',dp.opts.mmStep).focus(function(){
  4584. changeTmMenu("mm");
  4585. });
  4586. var $second = $(setting.second$).val(dp.hasSecond() ? dw.second : 0).attr('step',dp.opts.ssStep).focus(function(){
  4587. changeTmMenu("ss");
  4588. });
  4589. $hour.add($minute).add($second).click(function(){return false});
  4590. clickTmMenu($hour,"hh");
  4591. clickTmMenu($minute,"mm");
  4592. clickTmMenu($second,"ss");
  4593. $(setting.box$).click(function(){
  4594. changeTmMenu();
  4595. });
  4596. var $inputs = $(setting.tmInputs$);
  4597. $inputs.keydown(keydownInt).each(function(){
  4598. var $input = $(this);
  4599. $input.keyup(function(){
  4600. changeTm($input, 0);
  4601. });
  4602. });
  4603. $(setting.tmUp$).click(function(){
  4604. $inputs.filter(".slt").each(function(){
  4605. changeTm($(this), 1);
  4606. });
  4607. });
  4608. $(setting.tmDown$).click(function(){
  4609. $inputs.filter(".slt").each(function(){
  4610. changeTm($(this), -1);
  4611. });
  4612. });
  4613. if (!dp.hasHour()) $hour.attr("disabled",true);
  4614. if (!dp.hasMinute()) $minute.attr("disabled",true);
  4615. if (!dp.hasSecond()) $second.attr("disabled",true);
  4616. }
  4617. }
  4618. function closeCalendar() {
  4619. $(setting.box$).remove();
  4620. $(document).unbind("click", closeCalendar);
  4621. }
  4622. $this.click(function(event){
  4623. closeCalendar();
  4624. var dp = new Datepicker($this.val(), opts);
  4625. var offset = $this.offset();
  4626. var iTop = offset.top+this.offsetHeight;
  4627. $(DWZ.frag['calendarFrag']).appendTo("body").css({
  4628. left:offset.left+'px',
  4629. top:iTop+'px'
  4630. }).show().click(function(event){
  4631. event.stopPropagation();
  4632. });
  4633. ($.fn.bgiframe && $(setting.box$).bgiframe());
  4634. var dayNames = "";
  4635. $.each($.regional.datepicker.dayNames, function(i,v){
  4636. dayNames += "<dt>" + v + "</dt>"
  4637. });
  4638. $(setting.dayNames$).html(dayNames);
  4639. var dw = dp.getDateWrap();
  4640. var $year = $(setting.year$);
  4641. var yearstart = dp.getMinDate().getFullYear();
  4642. var yearend = dp.getMaxDate().getFullYear();
  4643. for(y=yearstart; y<=yearend; y++){
  4644. $year.append('<option value="'+ y +'"'+ (dw.year==y ? 'selected="selected"' : '') +'>'+ y +'</option>');
  4645. }
  4646. var $month = $(setting.month$);
  4647. $.each($.regional.datepicker.monthNames, function(i,v){
  4648. var m = i+1;
  4649. $month.append('<option value="'+ m +'"'+ (dw.month==m ? 'selected="selected"' : '') +'>'+ v +'</option>');
  4650. });
  4651. // generate calendar
  4652. generateCalendar(dp);
  4653. $year.add($month).change(function(){
  4654. dp.changeDate($year.val(), $month.val());
  4655. generateCalendar(dp);
  4656. });
  4657. // fix top
  4658. var iBoxH = $(setting.box$).outerHeight(true);
  4659. if (iTop > iBoxH && iTop > $(window).height()-iBoxH) {
  4660. $(setting.box$).css("top", offset.top - iBoxH);
  4661. }
  4662. $(setting.close$).click(function(){
  4663. closeCalendar();
  4664. });
  4665. $(setting.clearBut$).click(function(){
  4666. $this.val("");
  4667. closeCalendar();
  4668. });
  4669. $(setting.okBut$).click(function(){
  4670. var $dd = $(setting.days$).find("dd.slt");
  4671. if ($dd.hasClass("disabled")) return false;
  4672. var date = dp.changeDay($dd.attr("day"), $dd.attr("chMonth"));
  4673. if (dp.hasTime()) {
  4674. date.setHours(parseInt($(setting.hour$).val()));
  4675. date.setMinutes(parseInt($(setting.minute$).val()));
  4676. date.setSeconds(parseInt($(setting.second$).val()));
  4677. }
  4678. $this.val(dp.formatDate(date));
  4679. closeCalendar();
  4680. });
  4681. $(document).bind("click", closeCalendar);
  4682. return false;
  4683. });
  4684. $this.parent().find(setting.calIcon$).click(function(){
  4685. $this.trigger("click");
  4686. return false;
  4687. });
  4688. });
  4689. }
  4690. var Datepicker = function(sDate, opts) {
  4691. this.opts = $.extend({
  4692. pattern:'yyyy-MM-dd',
  4693. minDate:"1900-01-01",
  4694. maxDate:"2099-12-31",
  4695. mmStep:1,
  4696. ssStep:1
  4697. }, opts);
  4698. //动态minDate、maxDate
  4699. var now = new Date();
  4700. this.opts.minDate = now.formatDateTm(this.opts.minDate);
  4701. this.opts.maxDate = now.formatDateTm(this.opts.maxDate);
  4702. this.sDate = sDate.trim();
  4703. }
  4704. $.extend(Datepicker.prototype, {
  4705. get: function(name) {
  4706. return this.opts[name];
  4707. },
  4708. _getDays: function (y,m){//获取某年某月的天数
  4709. return m==2?(y%4||!(y%100)&&y%400?28:29):(/4|6|9|11/.test(m)?30:31);
  4710. },
  4711. _minMaxDate: function(sDate){
  4712. var _count = sDate.split('-').length -1;
  4713. var _format = 'y-M-d';
  4714. if (_count == 1) _format = 'y-M';
  4715. else if (_count == 0) _format = 'y';
  4716. return sDate.parseDate(_format);
  4717. },
  4718. getMinDate: function(){
  4719. return this._minMaxDate(this.opts.minDate);
  4720. },
  4721. getMaxDate: function(){
  4722. var _sDate = this.opts.maxDate;
  4723. var _count = _sDate.split('-').length -1;
  4724. var _date = this._minMaxDate(_sDate);
  4725. if (_count < 2) { //format:y-M、y
  4726. var _day = this._getDays(_date.getFullYear(), _date.getMonth()+1);
  4727. _date.setDate(_day);
  4728. if (_count == 0) {//format:y
  4729. _date.setMonth(11);
  4730. }
  4731. }
  4732. return _date;
  4733. },
  4734. getDateWrap: function(date){ //得到年,月,日
  4735. if (!date) date = this.parseDate(this.sDate) || new Date();
  4736. var y = date.getFullYear();
  4737. var m = date.getMonth()+1;
  4738. var days = this._getDays(y,m);
  4739. return {
  4740. year:y, month:m, day:date.getDate(),
  4741. hour:date.getHours(),minute:date.getMinutes(),second:date.getSeconds(),
  4742. days: days, date:date
  4743. }
  4744. },
  4745. /**
  4746. * @param {year:2010, month:05, day:24}
  4747. */
  4748. changeDate: function(y, m, d){
  4749. var date = new Date(y, m - 1, d || 1);
  4750. this.sDate = this.formatDate(date);
  4751. return date;
  4752. },
  4753. changeDay: function(day, chMonth){
  4754. if (!chMonth) chMonth = 0;
  4755. var dw = this.getDateWrap();
  4756. return this.changeDate(dw.year, dw.month+parseInt(chMonth), day);
  4757. },
  4758. parseDate: function(sDate){
  4759. if (!sDate) return null;
  4760. return sDate.parseDate(this.opts.pattern);
  4761. },
  4762. formatDate: function(date){
  4763. return date.formatDate(this.opts.pattern);
  4764. },
  4765. hasHour: function() {
  4766. return this.opts.pattern.indexOf("H") != -1;
  4767. },
  4768. hasMinute: function() {
  4769. return this.opts.pattern.indexOf("m") != -1;
  4770. },
  4771. hasSecond: function() {
  4772. return this.opts.pattern.indexOf("s") != -1;
  4773. },
  4774. hasTime: function() {
  4775. return this.hasHour() || this.hasMinute() || this.hasSecond();
  4776. },
  4777. hasDate: function() {
  4778. var _dateKeys = ['y','M','d','E'];
  4779. for (var i=0; i<_dateKeys.length; i++){
  4780. if (this.opts.pattern.indexOf(_dateKeys[i]) != -1) return true;
  4781. }
  4782. return false;
  4783. }
  4784. });
  4785. })(jQuery);
  4786. /**
  4787. * @author Roger Wu
  4788. */
  4789. (function($){
  4790. $.extend($.fn, {
  4791. jBlindUp: function(options){
  4792. var op = $.extend({duration: 500, easing: "swing", call: function(){}}, options);
  4793. return this.each(function(){
  4794. var $this = $(this);
  4795. $(this).animate({height: 0}, {
  4796. step: function(){},
  4797. duration: op.duration,
  4798. easing: op.easing,
  4799. complete: function(){
  4800. $this.css({display: "none"});
  4801. op.call();
  4802. }
  4803. });
  4804. });
  4805. },
  4806. jBlindDown: function(options){
  4807. var op = $.extend({to:0, duration: 500,easing: "swing",call: function(){}}, options);
  4808. return this.each(function(){
  4809. var $this = $(this);
  4810. var fixedPanelHeight = (op.to > 0)?op.to:$.effect.getDimensions($this[0]).height;
  4811. $this.animate({height: fixedPanelHeight}, {
  4812. step: function(){},
  4813. duration: op.duration,
  4814. easing: op.easing,
  4815. complete: function(){
  4816. $this.css({display: ""});
  4817. op.call(); }
  4818. });
  4819. });
  4820. },
  4821. jSlideUp:function(options) {
  4822. var op = $.extend({to:0, duration: 500,easing: "swing",call: function(){}}, options);
  4823. return this.each(function(){
  4824. var $this = $(this);
  4825. $this.wrapInner("<div></div>");
  4826. var fixedHeight = (op.to > 0)?op.to:$.effect.getDimensions($(">div",$this)[0]).height;
  4827. $this.css({overflow:"visible",position:"relative"});
  4828. $(">div",$this).css({position:"relative"}).animate({top: -fixedHeight}, {
  4829. easing: op.easing,
  4830. duration: op.duration,
  4831. complete:function(){$this.html($(this).html());}
  4832. });
  4833. });
  4834. },
  4835. jSlideDown:function(options) {
  4836. var op = $.extend({to:0, duration: 500,easing: "swing",call: function(){}}, options);
  4837. return this.each(function(){
  4838. var $this = $(this);
  4839. var fixedHeight = (op.to > 0)?op.to:$.effect.getDimensions($this[0]).height;
  4840. $this.wrapInner("<div style=\"top:-" + fixedHeight + "px;\"></div>");
  4841. $this.css({overflow:"visible",position:"relative", height:"0px"})
  4842. .animate({height: fixedHeight}, {
  4843. duration: op.duration,
  4844. easing: op.easing,
  4845. complete: function(){ $this.css({display: "", overflow:""}); op.call(); }
  4846. });
  4847. $(">div",$this).css({position:"relative"}).animate({top: 0}, {
  4848. easing: op.easing,
  4849. duration: op.duration,
  4850. complete:function(){$this.html($(this).html());}
  4851. });
  4852. });
  4853. }
  4854. });
  4855. $.effect = {
  4856. getDimensions: function(element, displayElement){
  4857. var dimensions = new $.effect.Rectangle;
  4858. var displayOrig = $(element).css('display');
  4859. var visibilityOrig = $(element).css('visibility');
  4860. var isZero = $(element).height()==0?true:false;
  4861. if ($(element).is(":hidden")) {
  4862. $(element).css({visibility: 'hidden', display: 'block'});
  4863. if(isZero)$(element).css("height","");
  4864. if ($.browser.opera)
  4865. refElement.focus();
  4866. }
  4867. dimensions.height = $(element).outerHeight();
  4868. dimensions.width = $(element).outerWidth();
  4869. if (displayOrig == 'none'){
  4870. $(element).css({visibility: visibilityOrig, display: 'none'});
  4871. if(isZero) if(isZero)$(element).css("height","0px");
  4872. }
  4873. return dimensions;
  4874. }
  4875. }
  4876. $.effect.Rectangle = function(){
  4877. this.width = 0;
  4878. this.height = 0;
  4879. this.unit = "px";
  4880. }
  4881. })(jQuery);
  4882. /**
  4883. * @author Roger Wu
  4884. * @version 1.0
  4885. */
  4886. (function($){
  4887. $.extend($.fn, {
  4888. jPanel:function(options){
  4889. var op = $.extend({header:"panelHeader", headerC:"panelHeaderContent", content:"panelContent", coll:"collapsable", exp:"expandable", footer:"panelFooter", footerC:"panelFooterContent"}, options);
  4890. return this.each(function(){
  4891. var $panel = $(this);
  4892. var close = $panel.hasClass("close");
  4893. var collapse = $panel.hasClass("collapse");
  4894. var $content = $(">div", $panel).addClass(op.content);
  4895. var title = $(">h1",$panel).wrap('<div class="'+op.header+'"><div class="'+op.headerC+'"></div></div>');
  4896. if(collapse)$("<a href=\"\"></a>").addClass(close?op.exp:op.coll).insertAfter(title);
  4897. var header = $(">div:first", $panel);
  4898. var footer = $('<div class="'+op.footer+'"><div class="'+op.footerC+'"></div></div>').appendTo($panel);
  4899. var defaultH = $panel.attr("defH")?$panel.attr("defH"):0;
  4900. var minH = $panel.attr("minH")?$panel.attr("minH"):0;
  4901. if (close)
  4902. $content.css({
  4903. height: "0px",
  4904. display: "none"
  4905. });
  4906. else {
  4907. if (defaultH > 0)
  4908. $content.height(defaultH + "px");
  4909. else if(minH > 0){
  4910. $content.css("minHeight", minH+"px");
  4911. }
  4912. }
  4913. if(!collapse) return;
  4914. var $pucker = $("a", header);
  4915. var inH = $content.innerHeight() - 6;
  4916. if(minH > 0 && minH >= inH) defaultH = minH;
  4917. else defaultH = inH;
  4918. $pucker.click(function(){
  4919. if($pucker.hasClass(op.exp)){
  4920. $content.jBlindDown({to:defaultH,call:function(){
  4921. $pucker.removeClass(op.exp).addClass(op.coll);
  4922. if(minH > 0) $content.css("minHeight",minH+"px");
  4923. }});
  4924. } else {
  4925. if(minH > 0) $content.css("minHeight","");
  4926. if(minH >= inH) $content.css("height", minH+"px");
  4927. $content.jBlindUp({call:function(){
  4928. $pucker.removeClass(op.coll).addClass(op.exp);
  4929. }});
  4930. }
  4931. return false;
  4932. });
  4933. });
  4934. }
  4935. });
  4936. })(jQuery);
  4937. /**
  4938. * @author ZhangHuihua@msn.com
  4939. */
  4940. (function($){
  4941. $.fn.extend({
  4942. checkboxCtrl: function(parent){
  4943. return this.each(function(){
  4944. var $trigger = $(this);
  4945. $trigger.click(function(){
  4946. var group = $trigger.attr("group");
  4947. if ($trigger.is(":checkbox")) {
  4948. var type = $trigger.is(":checked") ? "all" : "none";
  4949. if (group) $.checkbox.select(group, type, parent);
  4950. } else {
  4951. if (group) $.checkbox.select(group, $trigger.attr("selectType") || "all", parent);
  4952. }
  4953. });
  4954. });
  4955. }
  4956. });
  4957. $.checkbox = {
  4958. selectAll: function(_name, _parent){
  4959. this.select(_name, "all", _parent);
  4960. },
  4961. unSelectAll: function(_name, _parent){
  4962. this.select(_name, "none", _parent);
  4963. },
  4964. selectInvert: function(_name, _parent){
  4965. this.select(_name, "invert", _parent);
  4966. },
  4967. select: function(_name, _type, _parent){
  4968. $parent = $(_parent || document);
  4969. $checkboxLi = $parent.find(":checkbox[name='"+_name+"']");
  4970. switch(_type){
  4971. case "invert":
  4972. $checkboxLi.each(function(){
  4973. $checkbox = $(this);
  4974. $checkbox.attr('checked', !$checkbox.is(":checked"));
  4975. });
  4976. break;
  4977. case "none":
  4978. $checkboxLi.attr('checked', false);
  4979. break;
  4980. default:
  4981. $checkboxLi.attr('checked', true);
  4982. break;
  4983. }
  4984. $checkboxLi.trigger('change');
  4985. }
  4986. };
  4987. })(jQuery);
  4988. /**
  4989. * @author Roger Wu
  4990. */
  4991. (function($){
  4992. var allSelectBox = [];
  4993. var killAllBox = function(bid){
  4994. $.each(allSelectBox, function(i){
  4995. if (allSelectBox[i] != bid) {
  4996. if (!$("#" + allSelectBox[i])[0]) {
  4997. $("#op_" + allSelectBox[i]).remove();
  4998. //allSelectBox.splice(i,1);
  4999. } else {
  5000. $("#op_" + allSelectBox[i]).css({ height: "", width: "" }).hide();
  5001. }
  5002. $(document).unbind("click", killAllBox);
  5003. }
  5004. });
  5005. };
  5006. var _onchange = function (event){
  5007. var $ref = $("#"+event.data.ref);
  5008. if ($ref.size() == 0) return false;
  5009. $.ajax({
  5010. type:'POST', dataType:"json", url:event.data.refUrl.replace("{value}", encodeURIComponent(event.data.$this.val())), cache: false,
  5011. data:{},
  5012. success: function(json){
  5013. if (!json) return;
  5014. var html = '';
  5015. $.each(json, function(i){
  5016. if (json[i] && json[i].length > 1){
  5017. html += '<option value="'+json[i][0]+'">' + json[i][1] + '</option>';
  5018. }
  5019. });
  5020. var $refCombox = $ref.parents("div.combox:first");
  5021. $ref.html(html).insertAfter($refCombox);
  5022. $refCombox.remove();
  5023. $ref.trigger("change").combox();
  5024. },
  5025. error: DWZ.ajaxError
  5026. });
  5027. };
  5028. $.extend($.fn, {
  5029. comboxSelect: function(options){
  5030. var op = $.extend({ selector: ">a" }, options);
  5031. return this.each(function(){
  5032. var box = $(this);
  5033. var selector = $(op.selector, box);
  5034. allSelectBox.push(box.attr("id"));
  5035. $(op.selector, box).click(function(){
  5036. var options = $("#op_"+box.attr("id"));
  5037. if (options.is(":hidden")) {
  5038. if(options.height() > 300) {
  5039. options.css({height:"300px",overflow:"scroll"});
  5040. }
  5041. var top = box.offset().top+box[0].offsetHeight-50;
  5042. if(top + options.height() > $(window).height() - 20) {
  5043. top = $(window).height() - 20 - options.height();
  5044. }
  5045. options.css({top:top,left:box.offset().left}).show();
  5046. killAllBox(box.attr("id"));
  5047. $(document).click(killAllBox);
  5048. } else {
  5049. $(document).unbind("click", killAllBox);
  5050. killAllBox();
  5051. }
  5052. return false;
  5053. });
  5054. $("#op_"+box.attr("id")).find(">li").comboxOption(selector, box);
  5055. });
  5056. },
  5057. comboxOption: function(selector, box){
  5058. return this.each(function(){
  5059. $(">a", this).click(function(){
  5060. var $this = $(this);
  5061. $this.parent().parent().find(".selected").removeClass("selected");
  5062. $this.addClass("selected");
  5063. selector.text($this.text());
  5064. var $input = $("select", box);
  5065. if ($input.val() != $this.attr("value")) {
  5066. $("select", box).val($this.attr("value")).trigger("change");
  5067. }
  5068. });
  5069. });
  5070. },
  5071. combox:function(){
  5072. /* 清理下拉层 */
  5073. var _selectBox = [];
  5074. $.each(allSelectBox, function(i){
  5075. if ($("#" + allSelectBox[i])[0]) {
  5076. _selectBox.push(allSelectBox[i]);
  5077. } else {
  5078. $("#op_" + allSelectBox[i]).remove();
  5079. }
  5080. });
  5081. allSelectBox = _selectBox;
  5082. return this.each(function(i){
  5083. var $this = $(this).removeClass("combox");
  5084. var name = $this.attr("name");
  5085. var value= $this.val();
  5086. var label = $('option[value="' + value + '"]',$this).text();
  5087. var ref = $this.attr("ref");
  5088. var refUrl = $this.attr('refUrl') || '';
  5089. var cid = $this.attr("id") || Math.round(Math.random()*10000000);
  5090. var select = '<div class="combox"><div id="combox_'+ cid +'" class="select"' + (ref?' ref="' + ref + '"' : '') + '>';
  5091. select += '<a href="javascript:" class="'+$this.attr("class")+'" name="' + name +'" value="' + value + '">' + label +'</a></div></div>';
  5092. var options = '<ul class="comboxop" id="op_combox_'+ cid +'">';
  5093. $("option", $this).each(function(){
  5094. var option = $(this);
  5095. options +="<li><a class=\""+ (value==option[0].value?"selected":"") +"\" href=\"#\" value=\"" + option[0].value + "\">" + option[0].text + "</a></li>";
  5096. });
  5097. options +="</ul>";
  5098. $("body").append(options);
  5099. $this.after(select);
  5100. $("div.select", $this.next()).comboxSelect().append($this);
  5101. if (ref && refUrl) {
  5102. $this.unbind("change", _onchange).bind("change", {ref:ref, refUrl:refUrl, $this:$this}, _onchange);
  5103. }
  5104. });
  5105. }
  5106. });
  5107. })(jQuery);
  5108. /**
  5109. * jQuery ajax history plugins
  5110. * @author ZhangHuihua@msn.com
  5111. */
  5112. (function($){
  5113. $.extend({
  5114. History: {
  5115. _hash: new Array(),
  5116. _cont: undefined,
  5117. _currentHash: "",
  5118. _callback: undefined,
  5119. init: function(cont, callback){
  5120. $.History._cont = cont;
  5121. $.History._callback = callback;
  5122. var current_hash = location.hash.replace(/\?.*$/, '');
  5123. $.History._currentHash = current_hash;
  5124. if (/msie/.test(navigator.userAgent.toLowerCase())) {
  5125. if ($.History._currentHash == '') {
  5126. $.History._currentHash = '#';
  5127. }
  5128. $("body").append('<iframe id="jQuery_history" style="display: none;" src="about:blank"></iframe>');
  5129. var ihistory = $("#jQuery_history")[0];
  5130. var iframe = ihistory.contentDocument || ihistory.contentWindow.document;
  5131. iframe.open();
  5132. iframe.close();
  5133. iframe.location.hash = current_hash;
  5134. }
  5135. if ($.isFunction(this._callback))
  5136. $.History._callback(current_hash.skipChar("#"));
  5137. setInterval($.History._historyCheck, 100);
  5138. },
  5139. _historyCheck: function(){
  5140. var current_hash = "";
  5141. if (/msie/.test(navigator.userAgent.toLowerCase())) {
  5142. var ihistory = $("#jQuery_history")[0];
  5143. var iframe = ihistory.contentWindow;
  5144. current_hash = iframe.location.hash.skipChar("#").replace(/\?.*$/, '');
  5145. } else {
  5146. current_hash = location.hash.skipChar('#').replace(/\?.*$/, '');
  5147. }
  5148. // if (!current_hash) {
  5149. // if (current_hash != $.History._currentHash) {
  5150. // $.History._currentHash = current_hash;
  5151. // //TODO
  5152. // }
  5153. // } else {
  5154. if (current_hash != $.History._currentHash) {
  5155. $.History._currentHash = current_hash;
  5156. $.History.loadHistory(current_hash);
  5157. }
  5158. // }
  5159. },
  5160. addHistory: function(hash, fun, args){
  5161. $.History._currentHash = hash;
  5162. var history = [hash, fun, args];
  5163. $.History._hash.push(history);
  5164. if (/msie/.test(navigator.userAgent.toLowerCase())) {
  5165. var ihistory = $("#jQuery_history")[0];
  5166. var iframe = ihistory.contentDocument || ihistory.contentWindow.document;
  5167. iframe.open();
  5168. iframe.close();
  5169. iframe.location.hash = hash.replace(/\?.*$/, '');
  5170. location.hash = hash.replace(/\?.*$/, '');
  5171. } else {
  5172. location.hash = hash.replace(/\?.*$/, '');
  5173. }
  5174. },
  5175. loadHistory: function(hash){
  5176. if (/msie/.test(navigator.userAgent.toLowerCase())) {
  5177. location.hash = hash;
  5178. }
  5179. for (var i = 0; i < $.History._hash.length; i += 1) {
  5180. if ($.History._hash[i][0] == hash) {
  5181. $.History._hash[i][1]($.History._hash[i][2]);
  5182. return;
  5183. }
  5184. }
  5185. }
  5186. }
  5187. });
  5188. })(jQuery);
  5189. /**
  5190. * @author ZhangHuihua@msn.com
  5191. *
  5192. */
  5193. (function($){
  5194. $.printBox = function(rel){
  5195. var _printBoxId = 'printBox';
  5196. var $contentBox = rel ? $('#'+rel) : $("body"),
  5197. $printBox = $('#'+_printBoxId);
  5198. if ($printBox.size()==0){
  5199. $printBox = $('<div id="'+_printBoxId+'"></div>').appendTo("body");
  5200. }
  5201. $printBox.html($contentBox.html()).find("[layoutH]").height("auto");
  5202. window.print();
  5203. }
  5204. })(jQuery);