/* * Flexigrid for jQuery - New Wave Grid * * Copyright (c) 2008 Paulo P. Marinas (webplicity.net/flexigrid) * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * * $Date: 2008-04-01 00:09:43 +0800 (Tue, 01 Apr 2008) $ */ (function(a){a.addFlex=function(n,r){if(n.grid){return false}var x,A,C,k,w,q,y,b,c,h,m,j,l,f,d,B,e,o,z,u,v;r=a.extend({height:200,width:"auto",striped:true,novstripe:false,minwidth:30,minheight:80,resizable:true,url:false,method:"POST",dataType:"xml",errormsg:"Connection Error",usepager:false,nowrap:true,page:1,total:1,useRp:true,rp:15,rpOptions:[10,15,20,25,40],title:false,pagestat:"Displaying {from} to {to} of {total} items",procmsg:"Processing, please wait ...",query:"",qtype:"",nomsg:"No items",minColToggle:1,showToggleBtn:true,hideOnSubmit:true,autoload:true,blockOpacity:0.5,onToggleCol:false,onChangeSort:false,onSuccess:false,onSubmit:false},r);a(n).show().attr({cellPadding:0,cellSpacing:0,border:0}).removeAttr("width");x={hset:{},rePosDrag:function(){var i,g;i=0-this.hDiv.scrollLeft;if(this.hDiv.scrollLeft>0){i-=Math.floor(r.cgwidth/2)}a(x.cDrag).css({top:x.hDiv.offsetTop+1});g=this.cdpad;a("div",x.cDrag).hide();a("thead tr:first th:visible",this.hDiv).each(function(){var s,p;s=a("thead tr:first th:visible",x.hDiv).index(this);if(i==0){i-=Math.floor(r.cgwidth/2)}p=parseInt(a("div",this).width())+i+g;a("div:eq("+s+")",x.cDrag).css({left:p+"px"}).show();i=p})},fixHeight:function(i){var s,p,g;if(!i){i=a(x.bDiv).height()}s=a(this.hDiv).height();a("div",this.cDrag).each(function(){a(this).height(i+s)});p=parseInt(a(x.nDiv).height());if(p>i){a(x.nDiv).height(i).width(200)}else{a(x.nDiv).height("auto").width("auto")}a(x.block).css({height:i,marginBottom:(i*-1)});g=x.bDiv.offsetTop+i;if(r.height!="auto"&&r.resizable){g=x.vDiv.offsetTop}a(x.rDiv).css({height:g})},dragStart:function(t,s,p){var D,g,i;if(t=="colresize"){a(x.nDiv).hide();a(x.nBtn).hide();D=a("div",this.cDrag).index(p);g=a("th:visible div:eq("+D+")",this.hDiv).width();a(p).addClass("dragging").siblings().hide();a(p).prev().addClass("dragging").show();this.colresize={startX:s.pageX,ol:parseInt(p.style.left),ow:g,n:D};a("body").css("cursor","col-resize")}else{if(t=="vresize"){i=false;a("body").css("cursor","row-resize");if(p){i=true;a("body").css("cursor","col-resize")}this.vresize={h:r.height,sy:s.pageY,w:r.width,sx:s.pageX,hgo:i}}else{if(t=="colMove"){a(x.nDiv).hide();a(x.nBtn).hide();this.hset=a(this.hDiv).offset();this.hset.right=this.hset.left+a("table",this.hDiv).width();this.hset.bottom=this.hset.top+a("table",this.hDiv).height();this.dcol=p;this.dcoln=a("th",this.hDiv).index(p);this.colCopy=document.createElement("div");this.colCopy.className="colCopy";this.colCopy.innerHTML=p.innerHTML;if(a.browser.msie){this.colCopy.className="colCopy ie"}a(this.colCopy).css({position:"absolute","float":"left",display:"none",textAlign:p.align});a("body").append(this.colCopy);a(this.cDrag).hide()}}}a("body").noSelect()},dragMove:function(t){var i,I,G,F,p,H,D,s,g,E;if(this.colresize){i=this.colresize.n;H=t.pageX-this.colresize.startX;D=this.colresize.ol+H;s=this.colresize.ow+H;if(s>r.minwidth){a("div:eq("+i+")",this.cDrag).css("left",D);this.colresize.nw=s}}else{if(this.vresize){I=this.vresize;F=t.pageY;H=F-I.sy;if(!r.defwidth){r.defwidth=r.width}if(r.width!="auto"&&!r.nohresize&&I.hgo){G=t.pageX;p=G-I.sx;g=I.w+p;if(g>r.defwidth){this.gDiv.style.width=g+"px";r.width=g}}E=I.h+H;if((E>r.minheight||r.heightthis.hset.right||t.pageXthis.hset.bottom||t.pageYthis.dcolt){a("th:eq("+this.dcolt+")",this.hDiv).before(this.dcol)}else{a("th:eq("+this.dcolt+")",this.hDiv).after(this.dcol)}this.switchCol(this.dcoln,this.dcolt);a(this.cdropleft).remove();a(this.cdropright).remove();this.rePosDrag()}this.dcol=null;this.hset=null;this.dcoln=null;this.dcolt=null;this.colCopy=null;a(".thMove",this.hDiv).removeClass("thMove");a(this.cDrag).show()}}}a("body").css("cursor","default");a("body").noSelect(false)},toggleCol:function(t,p){var i,s,g;i=a("th[axis='col"+t+"']",this.hDiv)[0];s=a("thead th",x.hDiv).index(i);g=a("input[value="+t+"]",x.nDiv)[0];if(p==null){p=i.hide}if(a("input:checked",x.nDiv).lengthg){a("td:eq("+g+")",this).before(a("td:eq("+i+")",this))}else{a("td:eq("+g+")",this).after(a("td:eq("+i+")",this))}});if(i>g){a("tr:eq("+g+")",this.nDiv).before(a("tr:eq("+i+")",this.nDiv))}else{a("tr:eq("+g+")",this.nDiv).after(a("tr:eq("+i+")",this.nDiv))}if(a.browser.msie&&a.browser.version<7){a("tr:eq("+g+") input",this.nDiv)[0].checked=true}this.hDiv.scrollLeft=this.bDiv.scrollLeft},scroll:function(){this.hDiv.scrollLeft=this.bDiv.scrollLeft;this.rePosDrag()},addData:function(t){var s,E,g,D,p;if(r.preProcess){t=r.preProcess(t)}a(".pReload",this.pDiv).removeClass("loading");this.loading=false;if(!t){a(".pPageStat",this.pDiv).html(r.errormsg);return false}if(r.dataType=="xml"){r.total=+a("rows total",t).text()}else{r.total=t.total}if(r.total==0){a("tr, a, td, div",n).unbind();a(n).empty();r.pages=1;r.page=1;this.buildpager();a(".pPageStat",this.pDiv).html(r.nomsg);return false}r.pages=Math.ceil(r.total/r.rp);if(r.dataType=="xml"){r.page=+a("rows page",t).text()}else{r.page=t.page}this.buildpager();b=document.createElement("tbody");if(r.dataType=="json"){a.each(t.rows,function(F,G){s=document.createElement("tr");if(F%2&&r.striped){s.className="erow"}if(G.id){s.id="row"+G.id}a("thead tr:first th",x.hDiv).each(function(){E=document.createElement("td");g=a(this).attr("axis").substr(3);E.align=this.align;E.innerHTML=G.cell[g];a(s).append(E);E=null});if(a("thead",this.gDiv).length<1){for(g=0;gr.pages){r.page=r.pages}p=[{name:"page",value:r.newp},{name:"rp",value:r.rp},{name:"sortname",value:r.sortname},{name:"sortorder",value:r.sortorder},{name:"query",value:r.query},{name:"qtype",value:r.qtype}];if(r.params){for(i=0;i1){r.newp=parseInt(r.page)-1}break;case"next":if(r.pager.pages){g=r.pages}}a(".pcontrol input",this.pDiv).val(g);r.newp=g;break}if(r.newp==r.page){return false}if(r.onChangePage){r.onChangePage(r.newp)}else{this.populate()}},addCellProp:function(){var p,t,s,i,g;a("tbody tr td",x.bDiv).each(function(){p=document.createElement("div");t=a("td",a(this).parent()).index(this);s=a("th:eq("+t+")",x.hDiv).get(0);if(s!=null){if(r.sortname==a(s).attr("abbr")&&r.sortname){this.className="sorted"}a(p).css({textAlign:s.align,width:a("div:first",s)[0].style.width});if(s.hide){a(this).css("display","none")}}if(r.nowrap==false){a(p).css("white-space","normal")}if(this.innerHTML==""){this.innerHTML=" "}p.innerHTML=this.innerHTML;i=a(this).parent()[0];g=false;if(i.id){g=i.id.substr(3)}if(s!=null){if(s.process){s.process(p,g)}}a(this).empty().append(p).removeAttr("width")})},getCellDim:function(p){var E,g,t,G,D,i,F,s;E=parseInt(a(p).height());g=parseInt(a(p).parent().height());t=parseInt(p.style.width);G=parseInt(a(p).parent().width());D=p.offsetParent.offsetTop;i=p.offsetParent.offsetLeft;F=parseInt(a(p).css("paddingLeft"));s=parseInt(a(p).css("paddingTop"));return{ht:E,wt:t,top:D,left:i,pdl:F,pdt:s,pht:g,pwt:G}},addRowProp:function(){var g;a("tbody tr",x.bDiv).each(function(){a(this).click(function(i){g=(i.target||i.srcElement);if(g.href||g.type){return true}a(this).toggleClass("trSelected");if(r.singleSelect){a(this).siblings().removeClass("trSelected")}}).mousedown(function(i){if(i.shiftKey){a(this).toggleClass("trSelected");x.multisel=true;this.focus();a(x.gDiv).noSelect()}}).mouseup(function(){if(x.multisel){x.multisel=false;a(x.gDiv).noSelect(false)}}).hover(function(i){if(x.multisel){a(this).toggleClass("trSelected")}},function(){});if(a.browser.msie&&a.browser.version<7){a(this).hover(function(){a(this).addClass("trOver")},function(){a(this).removeClass("trOver")})}})},pager:0};if(r.colModel){y=document.createElement("thead");c=document.createElement("tr");for(v=0;v"+k.name+"";if(k.bclass){a("span",w).addClass(k.bclass).css({paddingLeft:20})}w.onpress=k.onpress;w.name=k.name;if(k.onpress){a(w).click(function(){this.onpress(this.name,x.gDiv)})}a(C).append(w);if(a.browser.msie&&a.browser.version<7){a(w).hover(function(){a(this).addClass("fbOver")},function(){a(this).removeClass("fbOver")})}}else{a(C).append("
")}}a(x.tDiv).append(C);a(x.tDiv).append("
");a(x.gDiv).prepend(x.tDiv)}x.hDiv.className="hDiv";a(n).before(x.hDiv);x.hTable.cellPadding=0;x.hTable.cellSpacing=0;a(x.hDiv).append('
');a("div",x.hDiv).append(x.hTable);y=a("thead:first",n).get(0);if(y){a(x.hTable).append(y)}y=null;if(!r.colmodel){m=0}a("thead tr:first th",x.hDiv).each(function(){q=document.createElement("div");if(a(this).attr("abbr")){a(this).click(function(i){if(!a(this).hasClass("thOver")){return false}var g=(i.target||i.srcElement);if(g.href||g.type){return true}x.changeSort(this)});if(a(this).attr("abbr")==r.sortname){this.className="sorted";q.className="s"+r.sortorder}}if(this.hide){a(this).hide()}if(!r.colmodel){a(this).attr("axis","col"+m++)}a(q).css({textAlign:this.align,width:this.width+"px"});q.innerHTML=this.innerHTML;a(this).empty().append(q).removeAttr("width").mousedown(function(g){x.dragStart("colMove",g,this)}).hover(function(){var i,D,E,p,t,g,s;if(!x.colresize&&!a(this).hasClass("thMove")&&!x.colCopy){a(this).addClass("thOver")}if(a(this).attr("abbr")!=r.sortname&&!x.colCopy&&!x.colresize&&a(this).attr("abbr")){a("div",this).addClass("s"+r.sortorder)}else{if(a(this).attr("abbr")==r.sortname&&!x.colCopy&&!x.colresize&&a(this).attr("abbr")){D="";if(r.sortorder=="asc"){D="desc"}else{D="asc"}a("div",this).removeClass("s"+r.sortorder).addClass("s"+D)}}if(x.colCopy){E=a("th",x.hDiv).index(this);if(E==x.dcoln){return false}if(Ea(x.gDiv).width()){a(x.nDiv).css("left",t-s+1)}else{a(x.nDiv).css("left",i)}if(a(this).hasClass("sorted")){a(x.nBtn).addClass("srtd")}else{a(x.nBtn).removeClass("srtd")}}}},function(){var g;a(this).removeClass("thOver");if(a(this).attr("abbr")!=r.sortname){a("div",this).removeClass("s"+r.sortorder)}else{if(a(this).attr("abbr")==r.sortname){g="";if(r.sortorder=="asc"){g="desc"}else{g="asc"}a("div",this).addClass("s"+r.sortorder).removeClass("s"+g)}}if(x.colCopy){a(x.cdropleft).remove();a(x.cdropright).remove();x.dcolt=null}})});x.bDiv.className="bDiv";a(n).before(x.bDiv);a(x.bDiv).css({height:(r.height=="auto")?"auto":r.height+"px"}).scroll(function(g){x.scroll()}).append(n);if(r.height=="auto"){a("table",x.bDiv).addClass("autoht")}x.addCellProp();x.addRowProp();f=a("thead tr:first th:first",x.hDiv).get(0);if(f!=null){x.cDrag.className="cDrag";x.cdpad=0;x.cdpad+=(isNaN(parseInt(a("div",f).css("borderLeftWidth")))?0:parseInt(a("div",f).css("borderLeftWidth")));x.cdpad+=(isNaN(parseInt(a("div",f).css("borderRightWidth")))?0:parseInt(a("div",f).css("borderRightWidth")));x.cdpad+=(isNaN(parseInt(a("div",f).css("paddingLeft")))?0:parseInt(a("div",f).css("paddingLeft")));x.cdpad+=(isNaN(parseInt(a("div",f).css("paddingRight")))?0:parseInt(a("div",f).css("paddingRight")));x.cdpad+=(isNaN(parseInt(a(f).css("borderLeftWidth")))?0:parseInt(a(f).css("borderLeftWidth")));x.cdpad+=(isNaN(parseInt(a(f).css("borderRightWidth")))?0:parseInt(a(f).css("borderRightWidth")));x.cdpad+=(isNaN(parseInt(a(f).css("paddingLeft")))?0:parseInt(a(f).css("paddingLeft")));x.cdpad+=(isNaN(parseInt(a(f).css("paddingRight")))?0:parseInt(a(f).css("paddingRight")));a(x.bDiv).before(x.cDrag);a(x.cDrag).css({top:-a(x.hDiv).height()+"px"});a("thead tr:first th",x.hDiv).each(function(){var g=document.createElement("div");a(x.cDrag).append(g);if(!r.cgwidth){r.cgwidth=a(g).width()}a(g).css({height:a(x.bDiv).height()+a(x.hDiv).height()}).mousedown(function(i){x.dragStart("colresize",i,this)});if(a.browser.msie&&a.browser.version<7){x.fixHeight(a(x.gDiv).height());a(g).hover(function(){x.fixHeight();a(this).addClass("dragging")},function(){if(!x.colresize){a(this).removeClass("dragging")}})}})}if(r.striped){a("tbody tr:odd",x.bDiv).addClass("erow")}if(r.resizable&&r.height!="auto"){x.vDiv.className="vGrip";a(x.vDiv).mousedown(function(g){x.dragStart("vresize",g)}).html("");a(x.bDiv).after(x.vDiv)}if(r.resizable&&r.width!="auto"&&!r.nohresize){x.rDiv.className="hGrip";a(x.rDiv).mousedown(function(g){x.dragStart("vresize",g,true)}).html("").css("height",a(x.gDiv).height());if(a.browser.msie&&a.browser.version<7){a(x.rDiv).hover(function(){a(this).addClass("hgOver")},function(){a(this).removeClass("hgOver")})}a(x.gDiv).append(x.rDiv)}if(r.usepager){x.pDiv.className="pDiv";x.pDiv.innerHTML='
';a(x.bDiv).after(x.pDiv);a("div",x.pDiv).html('
Page of 1
');a(".pReload",x.pDiv).click(function(){x.populate()});a(".pFirst",x.pDiv).click(function(){x.changePage("first")});a(".pPrev",x.pDiv).click(function(){x.changePage("prev")});a(".pNext",x.pDiv).click(function(){x.changePage("next")});a(".pLast",x.pDiv).click(function(){x.changePage("last")});a(".pcontrol input",x.pDiv).keydown(function(g){if(g.keyCode==13){x.changePage("input")}});if(a.browser.msie&&a.browser.version<7){a(".pButton",x.pDiv).hover(function(){a(this).addClass("pBtnOver")},function(){a(this).removeClass("pBtnOver")})}if(r.useRp){d="";for(B=0;B"+r.rpOptions[B]+"  "}a(".pDiv2",x.pDiv).prepend("
");a("select",x.pDiv).change(function(){if(r.onRpChange){r.onRpChange(+this.value)}else{r.newp=1;r.rp=+this.value;x.populate()}})}if(r.searchitems){a(".pDiv2",x.pDiv).prepend("
");a(".pSearch",x.pDiv).click(function(){a(x.sDiv).slideToggle("fast",function(){a(".sDiv:visible input:first",x.gDiv).trigger("focus")})});x.sDiv.className="sDiv";sitems=r.searchitems;e="";for(o=0;o"+sitems[o].display+"  "}if(r.qtype==""){r.qtype=sitems[0].name}a(x.sDiv).append("
Quick Search
");a("input[name=q],select[name=qtype]",x.sDiv).keydown(function(g){if(g.keyCode==13){x.doSearch()}});a("input[value=Clear]",x.sDiv).click(function(){a("input[name=q]",x.sDiv).val("");r.query="";x.doSearch()});a(x.bDiv).after(x.sDiv)}}a(x.pDiv,x.sDiv).append("
");if(r.title){x.mDiv.className="mDiv";x.mDiv.innerHTML='
'+r.title+"
";a(x.gDiv).prepend(x.mDiv);if(r.showTableToggleBtn){a(x.mDiv).append('
');a("div.ptogtitle",x.mDiv).click(function(){a(x.gDiv).toggleClass("hideBody");a(this).toggleClass("vsble")})}}x.cdropleft=document.createElement("span");x.cdropleft.className="cdropleft";x.cdropright=document.createElement("span");x.cdropright.className="cdropright";x.block.className="gBlock";z=a(x.bDiv).height();a(x.block).css({width:x.bDiv.style.width,height:z,background:"white",position:"relative",marginBottom:(z*-1),zIndex:1,top:x.bDiv.offsetTop,left:"0px"});a(x.block).fadeTo(0,r.blockOpacity);if(a("th",x.hDiv).length){x.nDiv.className="nDiv";x.nDiv.innerHTML="
";a(x.nDiv).css({marginBottom:(z*-1),display:"none",top:x.bDiv.offsetTop}).noSelect();j=0;a("th div",x.hDiv).each(function(){var i,g;i=a("th[axis='col"+j+"']",x.hDiv)[0];g='checked="checked"';if(i.style.display=="none"){g=""}a("tbody",x.nDiv).append(''+this.innerHTML+"");j++});if(a.browser.msie&&a.browser.version<7){a("tr",x.nDiv).hover(function(){a(this).addClass("ndcolover")},function(){a(this).removeClass("ndcolover")})}a("td.ndcol2",x.nDiv).click(function(){if(a("input:checked",x.nDiv).length<=r.minColToggle&&a(this).prev().find("input")[0].checked){return false}return x.toggleCol(a(this).prev().find("input").val())});a("input.togCol",x.nDiv).click(function(){if(a("input:checked",x.nDiv).length").attr("title","Hide/Show Columns").click(function(){a(x.nDiv).toggle();return true});if(r.showToggleBtn){a(x.gDiv).prepend(x.nBtn)}}a(x.iDiv).addClass("iDiv").css({display:"none"});a(x.bDiv).append(x.iDiv);a(x.bDiv).hover(function(){a(x.nDiv).hide();a(x.nBtn).hide()},function(){if(x.multisel){x.multisel=false}});a(x.gDiv).hover(function(){},function(){a(x.nDiv).hide();a(x.nBtn).hide()});a(document).mousemove(function(g){x.dragMove(g)}).mouseup(function(g){x.dragEnd()}).hover(function(){},function(){x.dragEnd()});if(a.browser.msie&&a.browser.version<7){a(".hDiv,.bDiv,.mDiv,.pDiv,.vGrip,.tDiv, .sDiv",x.gDiv).css({width:"100%"});a(x.gDiv).addClass("ie6");if(r.width!="auto"){a(x.gDiv).addClass("ie6fullwidthbug")}}x.rePosDrag();x.fixHeight();n.p=r;n.grid=x;if(r.url&&r.autoload){x.populate()}return n};docloaded=false;a(document).ready(function(){docloaded=true});a.fn.flexigrid=function(b){return this.each(function(){if(docloaded===false){a(this).hide();var c=this;a(document).ready(function(){a.addFlex(c,b)})}else{a.addFlex(this,b)}})};a.fn.flexReload=function(b){return this.each(function(){if(this.grid&&this.p.url){this.grid.populate()}})};a.fn.flexOptions=function(b){return this.each(function(){if(this.grid){a.extend(this.p,b)}})};a.fn.flexToggleCol=function(c,b){return this.each(function(){if(this.grid){this.grid.toggleCol(c,b)}})};a.fn.flexAddData=function(b){return this.each(function(){if(this.grid){this.grid.addData(b)}})};a.fn.noSelect=function(b){if(b==null){prevent=true}else{prevent=b}if(prevent){return this.each(function(){if(a.browser.msie||a.browser.safari){a(this).bind("selectstart",function(){return false})}else{if(a.browser.mozilla){a(this).css("MozUserSelect","none");a("body").trigger("focus")}else{if(a.browser.opera){a(this).bind("mousedown",function(){return false})}else{a(this).attr("unselectable","on")}}}})}else{return this.each(function(){if(a.browser.msie||a.browser.safari){a(this).unbind("selectstart")}else{if(a.browser.mozilla){a(this).css("MozUserSelect","inherit")}else{if(a.browser.opera){a(this).unbind("mousedown")}else{a(this).removeAttr("unselectable","on")}}}})}}})(jQuery);