|
|
|
|
(function($){"use strict";var defaults={data:undefined,lang:"cn",multiple:false,pagination:true,dropButton:true,listSize:10,multipleControlbar:true,maxSelectLimit:0,selectToCloseList:false,initRecord:undefined,dbTable:"tbl",keyField:"id",showField:"name",searchField:undefined,andOr:"OR",separator:",",orderBy:undefined,pageSize:10,params:undefined,formatItem:undefined,autoFillResult:false,autoSelectFirst:false,noResultClean:true,selectOnly:false,inputDelay:.5,eSelect:undefined,eOpen:undefined,eAjaxSuccess:undefined,eTagRemove:undefined,eClear:undefined};var SelectPage=function(input,option){$.each({data:"source",keyField:"primaryKey",showField:"field",pageSize:"perPage"},function(i,j){if(typeof option[j]!=="undefined"){option[i]=option[j];delete option[j]}});this.setOption(option);this.setLanguage();this.setCssClass();this.setProp();this.setElem(input);this.setButtonAttrDefault();this.setInitRecord();this.eDropdownButton();this.eInput();this.eWhole()};SelectPage.version="2.19";SelectPage.dataKey="selectPageObject";SelectPage.prototype.setOption=function(option){option.searchField=option.searchField||option.showField;option.andOr=option.andOr.toUpperCase();if(option.andOr!=="AND"&&option.andOr!=="OR")option.andOr="AND";var arr=["searchField"];for(var i=0;i<arr.length;i++){option[arr[i]]=this.strToArray(option[arr[i]])}option.orderBy=option.orderBy||option.showField;if(option.orderBy!==false)option.orderBy=this.setOrderbyOption(option.orderBy,option.showField);if(option.multiple&&!option.selectToCloseList){option.autoFillResult=false;option.autoSelectFirst=false}if(!option.pagination)option.pageSize=200;if($.type(option.listSize)!=="number"||option.listSize<0)option.listSize=10;if(typeof option.formatItem==="string"){var _formatItem=option.formatItem;option.formatItem=function(row){if(typeof Template==="function"&&_formatItem.match(/\#([a-zA-Z0-9_\-]+)$/)){return Template(_formatItem.substring(1),row)}else{return _formatItem.replace(/\{(.*?)\}/gi,function(matched){matched=matched.substring(1,matched.length-1);return typeof row[matched]!=="undefined"?row[matched]:""})}}}this.option=option};SelectPage.prototype.strToArray=function(str){return str?str.replace(/[\s ]+/g,"").split(","):""};SelectPage.prototype.setOrderbyOption=function(arg_order,arg_field){var arr=[],orders=[];if(typeof arg_order==="object"){for(var i=0;i<arg_order.length;i++){orders=$.trim(arg_order[i]).split(" ");if(orders.length)arr.push(orders.length===2?orders.concat():[orders[0],"ASC"])}}else{orders=$.trim(arg_order).split(" ");arr[0]=orders.length===2?orders.concat():orders[0].toUpperCase().match(/^(ASC|DESC)$/i)?[arg_field,orders[0].toUpperCase()]:[orders[0],"ASC"]}return arr};SelectPage.prototype.setLanguage=function(){var message,p=this.option;switch(p.lang){case"en":message={add_btn:"Add button",add_title:"add a box",del_btn:"Del button",del_title:"delete a box",next:"Next",next_title:"Next"+p.pageSize+" (Right key)",prev:"Prev",prev_title:"Prev"+p.pageSize+" (Left key)",first_title:"First (Shift + Left key)",last_title:"Last (Shift + Right key)",get_all_btn:"Get All (Down key)",get_all_alt:"(button)",close_btn:"Close (Tab key)",close_alt:"(button)",loading:"loading...",loading_alt:"(loading)",page_info:"page_num of page_count",select_ng:"Attention : Please choose from among the list.",select_ok:"OK : Correctly selected.",not_found:"not found",ajax_error:"An error occurred while loading data.",clear:"Clear content",select_all:"Select current page",unselect_all:"Clear current page",clear_all:"Clear all selected",max_selected:"You can only select up to max_selected_limit items"};break;case"cn":default:message={add_btn:"添加按钮",add_title:"添加区域",del_btn:"删除按钮",del_title:"删除区域",next:"下一页",next_title:"下"+p.pageSize+" (→)",prev:"上一页",prev_title:"上"+p.pageSize+" (←)",first_title:"首页 (Shift + ←)",last_title:"尾页 (Shift + →)",get_all_btn:"获得全部 (↓)",get_all_alt:"(按钮)",close_btn:"关闭 (Tab键)",close_alt:"(按钮)",loading:"读取中...",loading_alt:"(读取中)",page_info:"第 page_n
|