Explorer.min.js 27 KB

1
  1. MWF.xApplication.Template=MWF.xApplication.Template||{};MWF.xApplication.Template.Explorer=MWF.xApplication.Template.Explorer||{};MWF.require("MWF.widget.O2Identity",null,false);String.implement({toDOM:function(t,e){var i=this.test("^<the|^<tf|^<tb|^<colg|^<ca")&&["<table>","</table>",1]||this.test("^<col")&&["<table><colgroup>","</colgroup><tbody></tbody></table>",2]||this.test("^<tr")&&["<table><tbody>","</tbody></table>",2]||this.test("^<th|^<td")&&["<table><tbody><tr>","</tr></tbody></table>",3]||this.test("^<li")&&["<ul>","</ul>",1]||this.test("^<dt|^<dd")&&["<dl>","</dl>",1]||this.test("^<le")&&["<fieldset>","</fieldset>",1]||this.test("^<opt")&&['<select multiple="multiple">',"</select>",1]||["","",0];if(t){var s=new Element("div",{html:i[0]+this+i[1]}).getChildren();while(i[2]--)s=s[0].getChildren();s.inject(t);if(e)e(t);return s}else{var n=new Element("div",{html:i[0]+this+i[1]});n.setStyle("display","none").inject($(document.body));if(e)e(n);var s=n.getChildren();while(i[2]--)s=s[0].getChildren();n.dispose();return s}}});MWF.xApplication.Template.Explorer.ComplexView=new Class({Implements:[Options,Events],options:{style:"default",templateUrl:"",scrollEnable:false,scrollType:"xApp_TaskList",checkboxEnable:true,pagingEnable:false,documentSortable:false,documentKeyWord:null,pagingPar:{position:["top","bottom"],countPerPage:0,visiblePages:10,currentPage:1,currentItem:null,hasPagingBar:true,hasTruningBar:true,hasNextPage:true,hasPrevPage:false,hasJumper:true,hasReturn:true,hiddenWithInvalid:true,text:{prePage:"",nextPage:"",firstPage:"",lastPage:""}}},initialize:function(t,e,i,s,n){this.container=t;this.explorer=i;if(n){this.app=e||n.app||this.explorer.app;this.lp=n.lp||this.explorer.lp||this.app.lp;this.css=n.css||this.explorer.css||this.app.css;this.actions=n.actions||this.explorer.actions||this.app.actions||this.app.restActions}else{this.app=e||this.explorer.app;this.lp=this.explorer.lp||this.app.lp;this.css=this.explorer.css||this.app.css;this.actions=this.explorer.actions||this.app.actions||this.app.restActions}if(!s.templateUrl){s.templateUrl=this.explorer.path+"listItem.json"}else if(s.templateUrl.indexOf("/")==-1){s.templateUrl=this.explorer.path+s.templateUrl}this.setOptions(s)},initData:function(){this.items=[];this.documents={};this.isItemsLoaded=false;this.isItemLoadding=false;this.loadItemQueue=0;this.count=0},load:function(){this.fireEvent("queryLoad");this._queryLoad();this.initData();this.ayalyseTemplate();this.node=new Element("div",{styles:this.css.viewContentListNode}).inject(this.container);if(this.options.scrollEnable){this.setScroll()}this.getContentTemplateNode();this.createViewNode();this.initSortData();this.createViewHead();this.createViewBody();this._postLoad();this.fireEvent("postLoad")},reload:function(){this.clear();this.node=new Element("div",{styles:this.css.viewContentListNode}).inject(this.container);this.createViewNode();this.createViewHead();this.createViewBody()},initSortData:function(){this.sortField=null;this.sortType=null;this.sortFieldDefault=null;this.sortTypeDefault=null},destroy:function(){if(this.documentNodeTemplate){delete this.documentNodeTemplate}if(this.template)delete this.template;if(this.scrollBar||this.scrollContainerFun){this.destroyScroll()}if(this.pagingContainerTop){if(this.pagingContainerTopCreated){this.pagingContainerTop.destroy()}else{this.pagingContainerTop.empty()}}if(this.pagingContainerBottom){if(this.pagingContainerBottomCreated){this.pagingContainerBottom.destroy()}else{this.pagingContainerBottom.empty()}}if(this.paging)this.paging.destroy();this.clear()},clear:function(){if(this.documentDragSort){this.documentDragSort.removeLists(this.viewBodyNode||this.viewNode);this.documentDragSort.detach();this.documentDragSort=null}this.documents=null;MWF.release(this.items);this.items=[];this.documents={};this.node.destroy();this.container.empty();this.isItemsLoaded=false;this.isItemLoadding=false;this.loadItemQueue=0},clearBody:function(){this.items.each(function(t,e){t.destroy()});this.documents=null;MWF.release(this.items);this.items=[];this.documents={}},resort:function(t){this.sortField=t.retrieve("sortField");var e=t.retrieve("sortType");if(e==""){this.sortType="asc"}else if(this.sortType=="asc"){this.sortType="desc"}else{this.sortField=null;this.sortType=null}this.reload()},destroyScroll:function(){if(this.options.scrollType=="window"){if(this.scrollContainerFun){this.container.removeEvent("scroll",this.scrollContainerFun);this.scrollContainerFun=null}}else{if(this.scrollBar.scrollVAreaNode){this.scrollBar.scrollVAreaNode.destroy()}delete this.scrollBar}},setScroll:function(){if(this.options.scrollType=="window"){this.container.setStyle("overflow","auto");this.scrollContainerFun=function(){if(!this.options.pagingEnable){var t=this.container.getScrollSize();var e=this.container.getSize();var i=t.y-e.y;if(this.container.scrollTop+150>i){if(!this.isItemsLoaded)this.loadElementList()}}}.bind(this);this.container.addEvent("scroll",this.scrollContainerFun)}else{MWF.require("MWF.widget.ScrollBar",function(){this.scrollBar=new MWF.widget.ScrollBar(this.container,{indent:false,style:this.options.scrollType,where:"before",distance:60,friction:4,axis:{x:false,y:true},onScroll:function(t){if(!this.options.pagingEnable){var e=this.container.getScrollSize();var i=this.container.getSize();var s=e.y-i.y;if(t+200>s){if(!this.isItemsLoaded)this.loadElementList()}}}.bind(this)})}.bind(this))}},ayalyseTemplate:function(){MWF.getJSON(this.options.templateUrl,function(t){this.template=t}.bind(this),false)},formatElement:function(i,s,t){var e=s.html.toDOM(i,function(t,e){this.formatStyles(t);this.formatLable(t);if(i)this.setEventStyle(t,s)}.bind(this))[0];if(s.width){e.set("width",s.width)}if(t&&i){i.empty()}return e},formatStyles:function(t){t.getElements("[class]").each(function(t){var e=t.get("class");if(e&&this.css[e]){t.setStyles(this.css[e])}}.bind(this));t.getElements("[styles]").each(function(t){var e=t.get("styles");if(e&&this.css[e]){t.setStyles(this.css[e])}}.bind(this))},formatLable:function(t){t.getElements("[lable]").each(function(t){var e=t.get("lable");if(e&&this.lp[e]){t.set("text",this.lp[e]+(t.get("colon")?":":""))}}.bind(this))},createViewNode:function(){this.fireEvent("queryCreateViewNode");this._queryCreateViewNode();this.viewNode=this.formatElement(this.node,this.template.viewSetting);this._postCreateViewNode(this.viewNode);this.fireEvent("postCreateViewNode");if(!this.viewNode)return},getContentTemplateNode:function(){this.documentNodeTemplate=this.formatElement(null,this.template.documentSetting);this.template.items.each(function(t){t.nodeTemplate=this.formatElement(null,t.content)}.bind(this))},createViewHead:function(){this.fireEvent("queryCreateViewHead");this._queryCreateViewHead();if(this.template){if(!this.template.headSetting||this.template.headSetting.disable||!this.template.headSetting.html){return}}var i=this;var t;if(this.template.viewHeadSetting){t=this.viewHeadNode=this.formatElement(this.viewNode,this.template.viewHeadSetting)}var s=this.headNode=this.formatElement(t||this.viewNode,this.template.headSetting);this.headItemNodes={};this.template.items.each(function(t){if(!t.head)return;if(t.access&&!this.options[t.access])return;if(t.head.access&&!this.options[t.head.access])return;if(t.name=="$checkbox"&&!this.options.checkboxEnable)return;var e=this.formatElement(s,t.head);if(t.name){this.headItemNodes[t.name]=e}if(t.name=="$checkbox"&&this.options.checkboxEnable){this.checkboxElement=new Element("input",{type:"checkbox"}).inject(e);this.checkboxElement.addEvent("click",function(){this.selectAllCheckbox()}.bind(this))}if(t.defaultSort&&t.defaultSort!=""){this.sortFieldDefault=t.name;this.sortTypeDefault=t.defaultSort}}.bind(this));this.template.items.each(function(t){if(t.name&&t.sort&&t.sort!=""){var e=this.headItemNodes[t.name];e.store("sortField",t.name);if(this.sortField==t.name&&this.sortType!=""){e.store("sortType",this.sortType);this.sortIconNode=new Element("div",{styles:this.sortType=="asc"?this.css.sortIconNode_asc:this.css.sortIconNode_desc}).inject(e,"bottom")}else{e.store("sortType","");this.sortIconNode=new Element("div.sortIconNode",{styles:this.css.sortIconNode}).inject(e,"bottom")}e.setStyle("cursor","pointer");e.addEvent("click",function(){i.resort(this)})}}.bind(this));this.fireEvent("postCreateViewHead");this._postCreateViewHead(s)},setEventStyle:function(node,setting,bingObj,data){var _self=this;var styles,overStyles,downStyles;var styleStr=setting.styles;if(typeOf(styleStr)=="string"){if(styleStr&&styleStr.substr(0,"function".length)=="function"){eval("var fun = "+styleStr);styles=fun.call(bingObj,data)}else{styles=this.css[styleStr]}}else if(typeOf(styleStr)=="object"){styles=styleStr}else if(typeOf(styleStr)=="function"){eval("var fun = "+styleStr);styles=fun.call(bingObj,data)}if(!styles){var s=node.get("styles");if(!s)node.get("class");if(s)styles=this.css[s]}if(setting.icon){if(!styles)styles={};styles["background-image"]="url("+this.explorer.path+"/"+this.explorer.options.style+"/icon/"+setting.icon+")"}if(typeOf(setting.mouseoverStyles)=="string")overStyles=this.css[setting.mouseoverStyles];if(typeOf(setting.mouseoverStyles)=="object")overStyles=setting.mouseoverStyles;if(setting.mouseoverIcon){if(!overStyles)overStyles={};overStyles["background-image"]="url("+this.explorer.path+"/"+this.explorer.options.style+"/icon/"+setting.mouseoverIcon+")"}if(typeOf(setting.mousedownStyles)=="string")downStyles=this.css[setting.mousedownStyles];if(typeOf(setting.mousedownStyles)=="object")downStyles=setting.mousedownStyles;if(setting.mousedownIcon){if(!downStyles)downStyles={};downStyles["background-image"]="url("+this.explorer.path+"/"+this.explorer.options.style+"/icon/"+setting.mousedownIcon+")"}if(styles)node.setStyles(styles);if(overStyles&&styles){node.addEvent("mouseover",function(t){if(!_self.lockNodeStyle)this.node.setStyles(this.styles)}.bind({styles:overStyles,node:node}));node.addEvent("mouseout",function(t){if(!_self.lockNodeStyle)this.node.setStyles(this.styles)}.bind({styles:styles,node:node}))}if(downStyles&&(overStyles||styles)){node.addEvent("mousedown",function(t){if(!_self.lockNodeStyle)this.node.setStyles(this.styles)}.bind({styles:downStyles,node:node}));node.addEvent("mouseup",function(t){if(!_self.lockNodeStyle)this.node.setStyles(this.styles)}.bind({styles:overStyles||styles,node:node}))}},selectAllCheckbox:function(){var e=this.checkboxElement.get("checked");this.items.each(function(t){if(t.checkboxElement)t.checkboxElement.set("checked",e)}.bind(this))},getCheckedItems:function(){var e=[];this.items.each(function(t){if(t.checkboxElement.get("checked")){e.push(t)}}.bind(this));return e},createViewBody:function(){if(this.template.viewBodySetting){this.viewBodyNode=this.formatElement(this.viewNode,this.template.viewBodySetting)}this.loadElementList()},loadElementList:function(){if(this.options.pagingEnable){var t=this.options.pagingPar.currentItem;var e=this.options.pagingPar.countPerPage;if(t){var i=Math.ceil(t/e);var s=t%e;this.loadPagingElementList(e,i,t)}else{this.loadPagingElementList(e,this.options.pagingPar.currentPage)}}else{e=this.options.pagingPar.countPerPage;this.loadScrollElementList(e)}},loadScrollElementList:function(t){if(!this.isItemsLoaded){if(!this.isItemLoadding){this.isItemLoadding=true;this._getCurrentPageData(function(t){var s=[];this.fireEvent("queryCreateViewBody");this._queryCreateViewBody();var e=this.dataCount=t.count;if(e<=this.items.length){this.isItemsLoaded=true}if(t.data&&typeOf(t.data)=="array"){t.data.each(function(t){var e=t[this.options.documentKeyWord||"id"];if(!this.documents[e]){var i=this._createDocument(t,this.items.length);this.items.push(i);if(i)s.push(i.node);this.documents[e]=i}}.bind(this))}this.isItemLoadding=false;if(this.options.documentSortable&&s.length){if(this.documentDragSort){this.documentDragSort.addItems(s)}else{this.makeSortable()}}this.fireEvent("postCreateViewBody");this._postCreateViewBody(this.viewBodyNode||this.viewNode);if(this.loadItemQueue>0){this.loadItemQueue--;this.loadElementList()}}.bind(this),t)}else{this.loadItemQueue++}}},loadPagingElementList:function(t,e,i){this.currentPage=e||1;this._getCurrentPageData(function(t){this.items=[];this.documents={};this.fireEvent("queryCreateViewBody");this._queryCreateViewBody();if(this.documentDragSort){this.documentDragSort.removeLists(this.viewBodyNode||this.viewNode)}this.dataCount=t.count;this.createPaging(t.count,this.currentPage);t.data.each(function(t){var e=this._createDocument(t,this.items.length);this.items.push(e);var i=t[this.options.documentKeyWord||"id"];this.documents[i]=e}.bind(this));if(this.options.documentSortable&&this.items.length){this.makeSortable()}var e;if(i){if(this.options.documentKeyWord){e=this.documents[i].node.getTop()}else{e=this.items[i-1].node.getTop()}this.fireEvent("gotoItem",e)}this.fireEvent("postCreateViewBody");this._postCreateViewBody(this.viewBodyNode||this.viewNode)}.bind(this),t,e)},createPaging:function(t,e){if(!this.options.pagingEnable||this.paging)return;if(this.options.pagingPar.position.indexOf("top")>-1){if(!this.pagingContainerTop){this.pagingContainerTopCreated=true;this.pagingContainerTop=new Element("div",{styles:this.css.pagingContainer}).inject(this.viewNode,"before")}}if(this.options.pagingPar.position.indexOf("bottom")>-1){if(!this.pagingContainerBottom){this.pagingContainerBottomCreated=true;this.pagingContainerBottom=new Element("div",{styles:this.css.pagingContainer}).inject(this.viewNode,"after")}}var i=Object.merge(this.options.pagingPar,{itemSize:t,onJumpingPage:function(t){this.loadPagingElementList(this.options.pagingPar.countPerPage,t.pageNum,t.itemNum)}.bind(this)});if(e)i.currentPage=e;if(this.options.pagingPar.hasPagingBar){this.paging=new MWF.xApplication.Template.Explorer.Paging(this.pagingContainerTop,this.pagingContainerBottom,i,this.css);this.paging.load()}},_getCurrentPageData:function(e,t,i){if(this.options.pagingEnable){this.actions.listDetailFilter(i,t,n,function(t){if(e)e(t)}.bind(this))}else{if(!t)t=20;var s=this.items.length?this.items[this.items.length-1].data.id:"(0)";var n=this.filterData||{};this.actions.listDetailFilterNext(s,t,n,function(t){if(e)e(t)}.bind(this))}},getCurrentPageNum:function(){return this.paging.options.currentPage},getPageSize:function(){return this.paging.options.pageSize},gotoPage:function(t){this.paging.gotoPage(t)},makeSortable:function(){this.documentDragSort=new Sortables(this.viewBodyNode||this.viewNode,{clone:true,opacity:.3,onStart:function(t,e){if(this.css.itemSortCloneNode)e.setStyles(this.css.itemSortCloneNode);this.fireEvent("documentSortStart",[t,e]);this._documentSortStart(t,e)}.bind(this),onSort:function(t,e){this.fireEvent("documentSort",[t,e]);this._documentSort(t,e)}.bind(this),onComplete:function(t){var e=this.documentDragSort.serialize();this.fireEvent("documentSortComplete",[t,e]);this._documentSortComplete(t,e)}.bind(this)})},_createDocument:function(t,e){return new MWF.xApplication.Template.Explorer.ComplexDocument(this.viewBodyNode||this.viewNode,t,this.explorer,this,null,e)},_openDocument:function(t){},_removeDocument:function(t,e){},_create:function(){MWF.xDesktop.requireApp("Template","MPopupForm",function(){this.from=new MPopupForm(this.explorer);this.from.create()}.bind(this),false)},_queryLoad:function(){},_postLoad:function(){},_queryCreateViewNode:function(){},_postCreateViewNode:function(t){},_queryCreateViewHead:function(){},_postCreateViewHead:function(t){},_queryCreateViewBody:function(){},_postCreateViewBody:function(t){},_documentSortStart:function(t,e){},_documentSort:function(t,e){},_documentSortComplete:function(t,e){}});MWF.xApplication.Template.Explorer.ComplexDocument=new Class({Implements:[Options,Events],initialize:function(t,e,i,s,n,o){this.explorer=i;this.data=e;this.container=t;this.view=s;this.index=o;if(n){this.app=n.app||this.view.app||this.explorer.app;this.lp=n.lp||this.view.lp||this.explorer.lp||this.app.lp;this.css=n.css||this.view.css||this.explorer.css||this.app.css;this.actions=n.actions||this.view.actions||this.explorer.actions||this.app.actions||this.app.restActions}else{this.app=this.view.app||this.explorer.app;this.lp=this.view.lp||this.explorer.lp||this.app.lp;this.css=this.view.css||this.explorer.css||this.app.css;this.actions=this.view.actions||this.explorer.actions||this.app.actions||this.app.restActions}this.load()},load:function(){this.fireEvent("queryCreateDocumentNode");this._queryCreateDocumentNode(this.data);var e=this;this.node=this.view.documentNodeTemplate.clone().inject(this.container);this.view.template.items.each(function(t){if(t.access&&this._getItemAccess(t)){this.loadItem(t.name,t.content,t.nodeTemplate)}else{this.loadItem(t.name,t.content,t.nodeTemplate)}}.bind(this));var t=this.view.template.documentSetting;if(t.styles||t.mouseoverStyles||t.mousedownStyles||t.icon||t.mouseoverIcon||t.mousedownIcon){this.view.setEventStyle(this.node,t,this,this.data)}var i=this.getConditionResult(t.condition);if(t.action&&this[t.action]){if(i){this.node.addEvent("click",function(t){this.fun.call(e,this.node,t);t.stopPropagation()}.bind({fun:this[t.action],node:this.node}))}}if(t.event&&i){this.bindEvent(this.node,t.event)}this.fireEvent("postCreateDocumentNode");this._postCreateDocumentNode(this.node,this.data)},loadItem:function(s,n,t){var e=this[s]=t.clone();if(this.format(e,s,n)){e.inject(this.node)}if(n.items){var i=e.getElements("[item]");if(e.get("item"))i.push(e);i.each(function(t){var e=t.get("item");var i=n.items[e];if(i){if(!i.value&&i.value!="")i.value=e;if(!this.format(t,s,i)){t.dispose()}}}.bind(this))}},format:function(t,e,i){var s=this;if(e=="$checkbox"&&!this.view.options.checkboxEnable)return false;if(i.access){if(!this._getItemAccess(i))return false}var n=this.getConditionResult(i.condition);if(i.action&&!n){return false}var o=this.getConditionResult(i.show);if(!o)t.setStyle("display","none");if(i.text){var a=this.getExecuteResult(i.text);t.set("text",this.view.lp&&this.view.lp[a]?this.view.lp[a]:a)}if(i.title){var r=this.getExecuteResult(i.title);t.set("title",this.view.lp&&this.view.lp[r]?this.view.lp[r]:r)}if(!i.text&&i.value&&i.value!=""){if(i.type=="html"){t.set("html",this.getValue(i.value))}else{t.set("text",this.getValue(i.value))}}if(i.styles||i.mouseoverStyles||i.mousedownStyles||i.icon||i.mouseoverIcon||i.mousedownIcon){this.view.setEventStyle(t,i,this,this.data)}var h=i.action&&this[i.action];if(h){if(n){t.addEvent("click",function(t){this.fun.call(s,this.node,t);t.stopPropagation()}.bind({fun:h,node:t}))}else{return false}}if(i.event&&n){this.bindEvent(t,i.event)}if(i.attr){this.setAttr(t,i.attr)}if(e=="$checkbox"&&this.view.options.checkboxEnable){if(n){this.checkboxElement=new Element("input",{type:"checkbox"}).inject(t);if(i.event){this.bindEvent(this.checkboxElement,i.event)}if(!i.event||!i.event.contains("click")){this.checkboxElement.addEvent("click",function(t){t.stopPropagation()}.bind(this))}t.addEvent("click",function(t){this.checkboxElement.set("checked",!this.checkboxElement.get("checked"));t.stopPropagation()}.bind(this))}else{}}return true},getExecuteResult:function(str){var result=str;if(str&&str.substr(0,8)=="function"){eval("var fun = "+str);result=fun.call(this,this.data)}return result},getValue:function(str){if(str.substr(0,8)=="function"){eval("var fun = "+str);return fun.call(this,this.data)}else if(typeOf(this.data[str])=="number"){return this.data[str]}else{return this.data[str]?this.data[str]:""}},getConditionResult:function(str){var flag=true;if(str&&str.substr(0,8)=="function"){eval("var fun = "+str);flag=fun.call(this,this.data)}return flag},setAttr:function(item,attr){if(!attr||attr==""||attr=="$none")return;if(typeof attr=="string"){if(attr.indexOf("^^")>-1){var attrsArr=attr.split("##");if(attrsArr[0].split("^^").length!=2)return;attrs={};for(var i=0;i<attrsArr.length;i++){var aname=attrsArr[i].split("^^")[0];var afunction=attrsArr[i].split("^^")[1];if(afunction.substr(0,"function".length)=="function"){eval("var fun = "+afunction);attrs[aname]=fun.call(this,this.data)}else{attrs[aname]=afunction}}}else{eval("var attrs = "+attr)}}if(typeOf(attrs)=="object"){for(var a in attrs){item.set(a,attrs[a])}}},bindEvent:function(item,events){if(!events||events==""||events=="$none")return;if(typeof events=="string"){if(events.indexOf("^^")>-1){var eventsArr=events.split("##");if(eventsArr[0].split("^^").length!=2)return;events={};for(var i=0;i<eventsArr.length;i++){var ename=eventsArr[i].split("^^")[0];var efunction=eventsArr[i].split("^^")[1];events[ename]=eval("(function(){ return "+efunction+" })()")}}else{eval("var events = "+events)}}if(typeOf(events)=="object"){for(var e in events){item.addEvent(e,function(t){this.fun.call(this.bingObj,this.target,t);t.stopPropagation()}.bind({bingObj:this,target:item,fun:events[e]}))}}},_getItemAccess:function(t){if(t.access&&!this.explorer.options[t.access]){return false}else{return true}},_getActionAccess:function(t){return true},open:function(t){this.view._openDocument(this.data)},remove:function(t){var e=this.app.lp;var i=e.deleteDocument.replace(/{title}/g,this.data.title);var s=this;this.node.setStyles(this.css.documentNode_remove);this.readyRemove=true;this.view.lockNodeStyle=true;this.app.confirm("warn",t,e.deleteDocumentTitle,i,350,120,function(){s.view._removeDocument(s.data,false);s.view.lockNodeStyle=false;this.close()},function(){s.node.setStyles(s.css.documentNode);s.readyRemove=false;s.view.lockNodeStyle=false;this.close()})},destroy:function(){this.node.destroy()},_queryCreateDocumentNode:function(t){},_postCreateDocumentNode:function(t,e){}});MWF.xApplication.Template.Explorer.Paging=new Class({Implements:[Options,Events],options:{position:["top","bottom"],countPerPage:20,visiblePages:10,currentPage:1,itemSize:0,pageSize:0,hasNextPage:true,hasPrevPage:false,hasTruningBar:true,hasJumper:true,hasReturn:true,returnText:"返回首页",hiddenWithDisable:true,text:{prePage:"",nextPage:"",firstPage:"",lastPage:""}},initialize:function(t,e,i,s){this.setOptions(i||{});this.topContainer=t;this.bottomContainer=e;this.css=s},load:function(){this.fireEvent("queryLoad",this);this.options.pageSize=Math.ceil(this.options.itemSize/this.options.countPerPage);if((this.options.pageSize==1||this.options.pageSize==0)&&this.options.hiddenWithDisable&&!this.options.hasReturn)return;if(this.topContainer){this.topContainer.empty();if(this.options.hasTruningBar&&this.options.position.indexOf("top")>-1){this.createNode(this.topContainer)}}if(this.bottomContainer){this.bottomContainer.empty();if(this.options.hasPrevPage){this.createPrevPageNode(this.bottomContainer)}if(this.options.hasNextPage){this.createNextPageNode(this.bottomContainer)}if(this.options.hasTruningBar&&this.options.position.indexOf("bottom")>-1){this.createNode(this.bottomContainer)}}this.fireEvent("postLoad",this)},createNode:function(t){var e=this;var i=this.options.visiblePages;var s=this.options.pageSize;var n=this.options.currentPage;var o=Math.floor(i/2);var a,r,h;if(s<=i){h=1;r=s}else if(n+o>s){h=s-i;r=s}else if(n-o<1){h=1;r=i}else{h=n-o;r=n+o}var l=this.node=new Element("div.pagingBar",{styles:this.css.pagingBar}).inject(t);if(this.options.hasReturn){var c=this.pageReturn=new Element("div.pageReturn",{styles:this.css.pageReturn,text:this.options.returnText}).inject(l);c.addEvents({mouseover:function(t){t.target.setStyles(this.css.pageReturn_over)}.bind(this),mouseout:function(t){t.target.setStyles(this.css.pageReturn)}.bind(this),click:function(){this.fireEvent("pageReturn",this)}.bind(this)})}if(s!=1&&s!=0||!this.options.hiddenWithDisable){if(h>1||!this.options.hiddenWithDisable){var d=this.firstPage=new Element("div.firstPage",{styles:this.css.firstPage,text:"1..."}).inject(l);if(this.options.text.firstPage)d.set("text",this.options.text.firstPage);d.addEvents({mouseover:function(t){t.target.setStyles(this.css.firstPage_over)}.bind(this),mouseout:function(t){t.target.setStyles(this.css.firstPage)}.bind(this),click:function(){this.gotoPage(1)}.bind(this)})}if(n!=1||!this.options.hiddenWithDisable){var u=this.prePage=new Element("div.prePage",{styles:this.css.prePage}).inject(l);if(this.options.text.prePage)u.set("text",this.options.text.prePage);u.addEvents({mouseover:function(t){t.target.setStyles(this.css.prePage_over)}.bind(this),mouseout:function(t){t.target.setStyles(this.css.prePage)}.bind(this),click:function(){this.gotoPage(n-1)}.bind(this)})}this.pageTurnNodes=[];for(a=h;a<=r;a++){if(n==a){this.currentPage=new Element("div.currentPage",{styles:this.css.currentPage,text:a}).inject(l)}else{var p=new Element("div.pageItem",{styles:this.css.pageItem,text:a}).inject(l);p.addEvents({mouseover:function(t){t.target.setStyles(this.css.pageItem_over)}.bind(this),mouseout:function(t){t.target.setStyles(this.css.pageItem)}.bind(this),click:function(){this.obj.gotoPage(this.num)}.bind({obj:this,num:a})});this.pageTurnNodes.push(p)}}if(this.options.hasJumper){var f=this.pageJumper=new Element("input.pageJumper",{styles:this.css.pageJumper,title:"输入页码,按回车跳转"}).inject(l);new Element("div.pageText",{styles:this.css.pageText,text:"/"+s}).inject(l);f.addEvents({focus:function(t){t.target.setStyles(this.css.pageJumper_over)}.bind(this),blur:function(t){t.target.setStyles(this.css.pageJumper)}.bind(this),keyup:function(t){this.value=this.value.replace(/[^0-9_]/g,"")},keydown:function(t){if(t.code==13&&this.value!=""){e.gotoPage(this.value);t.stopPropagation()}}})}if(n!=s||!this.options.hiddenWithDisable){var g=this.nextPage=new Element("div.nextPage",{styles:this.css.nextPage}).inject(l);if(this.options.text.nextPage)g.set("text",this.options.text.nextPage);g.addEvents({mouseover:function(t){t.target.setStyles(this.css.nextPage_over)}.bind(this),mouseout:function(t){t.target.setStyles(this.css.nextPage)}.bind(this),click:function(){this.gotoPage(n+1)}.bind(this)})}if(r<s||!this.options.hiddenWithDisable){var m=this.lastPage=new Element("div.lastPage",{styles:this.css.lastPage,text:"..."+s}).inject(l);if(this.options.text.lastPage)m.set("text",this.options.text.lastPage);m.addEvents({mouseover:function(t){t.target.setStyles(this.css.lastPage_over)}.bind(this),mouseout:function(t){t.target.setStyles(this.css.lastPage)}.bind(this),click:function(){this.gotoPage(s)}.bind(this)})}}},createNextPageNode:function(t){if(this.nextPageNode){this.nextPageNode.destroy();delete this.nextPageNode}var e=this.options.pageSize;if(this.options.currentPage!=e&&e!=1&&e!=0){this.nextPageNode=new Element("div.nextPageNode",{styles:this.css.nextPageNode,text:"下一页"}).inject(t);this.nextPageNode.addEvents({mouseover:function(t){t.target.setStyles(this.css.nextPageNode_over)}.bind(this),mouseout:function(t){t.target.setStyles(this.css.nextPageNode)}.bind(this),click:function(){this.gotoPage(this.options.currentPage+1)}.bind(this)})}},createPrevPageNode:function(t){if(this.prevPageNode){this.prevPageNode.destroy();delete this.prevPageNode}var e=this.options.pageSize;if(this.options.currentPage!=1&&e!=1&&e!=0){this.prevPageNode=new Element("div.prevPageNode",{styles:this.css.prevPageNode,text:"上一页"}).inject(t);this.prevPageNode.addEvents({mouseover:function(t){t.target.setStyles(this.css.prevPageNode_over)}.bind(this),mouseout:function(t){t.target.setStyles(this.css.prevPageNode)}.bind(this),click:function(){this.gotoPage(this.options.currentPage-1)}.bind(this)})}},gotoPage:function(t){if(t<1||t>this.options.pageSize)return;this.fireEvent("jumpingPage",{pageNum:t});this.options.currentPage=t;this.load()},gotoItem:function(t){var e=Math.ceil(t/this.options.countPerPage);var i=t%this.options.countPerPage;this.fireEvent("jumpingPage",{pageNum:e,itemNum:t,index:i});this.options.currentPage=e;this.load()},destroy:function(){if(this.nextPageNode)this.nextPageNode.destroy()}});