supcan.min.js
2.76 KB
/*!
* Copyright © 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
*
* 硕正组件封装
* @author ThinkGem
* @version 2013-11-09
*/
var supcans=[];function supcan(d,c,b){var a=new Supcan(d,c,b);supcans.push(a);return a}function OnReady(a){for(i=0;i<supcans.length;i++){if(supcans[i].AF.id==a){supcans[i].init(supcans[i].url);supcans[i].options.ready()}}}function OnEvent(f,a,e,d,c,b){for(i=0;i<supcans.length;i++){if(supcans[i].AF.id==f){supcans[i].options.event(a,e,d,c,b)}}}function Supcan(AF,url,options){var $this=this;$this.AF=AF;if(url.indexOf("/")==-1){$this.url=ctx+"/supcan/treeList/"+url+".xml"}else{$this.url=url}$this.options=$.extend({su:$this,checked:true,curSelMode:"rows",dataType:"json",height:"auto",body:"body",ready:function(){},event:function(){}},options);$this.data="";$this.func=function(name,param){return $this.AF.func(name,param)};$this.autoHeight=function(){var supcanDiv=$($this.AF).parent(),height=0;$($this.options.body).each(function(){height+=$(this).height()});$(supcanDiv).height($(window).height()+$(supcanDiv).height()-height-10)};$this.init=function(url){$this.func("Build",url);if($this.options.checked){$this.func("InsertCol","0\r\nname=checked;isCheckboxOnly=true")}if($this.options.curSelMode){$this.func("SetProp","curSelMode \r\n "+$this.options.curSelMode)}if($this.options.height=="auto"){$(window).resize(function(){$this.autoHeight()});$this.autoHeight()}else{$($this.AF).parent().height($this.options.height)}};$this.load=function(dataUrl,paramString,callback){$.post(dataUrl,paramString,function(data){$this.func("Load",data);if($this.options.dataType=="json"){$this.data=eval("("+data+")")}else{$this.data=data}if(typeof callback=="function"){callback($this.data)}},"text")};$this.loadByForm=function(form,page){$this.load($(form).attr("action"),$(form).serialize(),function(data){if($this.options.dataType=="json"&&data!=""){$(form+"[name=pageNo]").val(data.pageNo);$(form+"[name=pageSize]").val(data.pageSize);$(page).html(data.html);$(page).find("a").bind("focus",function(){if(this.blur){this.blur()}})
}})};$this.getCellText=function(columnName,isMany){var rowIdxs=$this.func("GetCurrentRow","");if(rowIdxs!=""){rowIdxs=rowIdxs.split(",");if(isMany){var vals=[];for(i=0;i<rowIdxs.length;i++){vals.push($this.func("GetCellText",rowIdxs[i]+" \r\n "+columnName))}return vals.join(",")}else{if(rowIdxs.length==1){return $this.func("GetCellText",rowIdxs[0]+" \r\n "+columnName)}}}return""};$this.setTree=function(flag){$this.func("SetProp","curSelMode \r\n row"+(flag?"":"s"));$this.func("SetColProp","checked \r\n TreeCombine \r\n "+(flag?"auto,node":""));$this.func("SetProp","isTree \r\n "+(flag?"true":"false"))};$this.setGrayWindow=function(trueOrFalse){$this.func("GrayWindow",trueOrFalse?"1":"0")};return $this};