Explorer.min.js 32 KB

12
  1. MWF.xApplication.Template=MWF.xApplication.Template||{};MWF.xApplication.Template.Explorer=MWF.xApplication.Template.Explorer||{};MWF.require("MWF.widget.Identity",null,false);MWF.xDesktop.requireApp("Template","lp."+MWF.language,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 o=new Element("div",{html:i[0]+this+i[1]});o.setStyle("display","none").inject($(document.body));if(e)e(o);var s=o.getChildren();while(i[2]--)s=s[0].getChildren();o.dispose();return s}}});MWF.xApplication.Template.Explorer.ComplexView=new Class({Implements:[Options,Events],options:{style:"default",templateUrl:"",scrollEnable:false,pagingEnable:false,documentKeyWord:null,pagingPar:{position:["top","bottom"],countPerPage:20,visiblePages:10,currentPage:1,currentItem:null,hasPagingBar:true,hasTruningBar:true,hasNextPage:true,hasPrevPage:false,hasReturn:true}},initialize:function(t,e,i,s,o){this.container=t;this.explorer=i;if(o){this.app=e||o.app||this.explorer.app;this.lp=o.lp||this.explorer.lp||this.app.lp;this.css=o.css||this.explorer.css||this.app.css;this.actions=o.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.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()},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){if(this.scrollBar.scrollVAreaNode){this.scrollBar.scrollVAreaNode.destroy()}delete this.scrollBar}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();delete this},clear:function(){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()},setScroll:function(){MWF.require("MWF.widget.ScrollBar",function(){this.scrollBar=new MWF.widget.ScrollBar(this.container,{indent:false,style:"xApp_TaskList",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(t,e,i){var s=e.html.toDOM(t,function(i,s){this.formatStyles(i);this.formatLable(i);if(t)this.setEventStyle(i,e)}.bind(this))[0];if(e.width){s.set("width",e.width)}if(i&&t){t.empty()}return s},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 t=this;var e=this.headNode=this.formatElement(this.viewNode,this.template.headSetting);this.template.items.each(function(i){if(!i.head)return;if(i.access&&!this.options[i.access])return;if(i.head.access&&!this.options[i.head.access])return;var s=this.formatElement(e,i.head);if(i.name=="$checkbox"){this.checkboxElement=new Element("input",{type:"checkbox"}).inject(s);this.checkboxElement.addEvent("click",function(){this.selectAllCheckbox()}.bind(this))}if(i.defaultSort&&i.defaultSort!=""){this.sortFieldDefault=i.name;this.sortTypeDefault=i.defaultSort}if(i.sort&&i.sort!=""){s.store("sortField",i.name);if(this.sortField==i.name&&this.sortType!=""){s.store("sortType",this.sortType);this.sortIconNode=new Element("div",{styles:this.sortType=="asc"?this.css.sortIconNode_asc:this.css.sortIconNode_desc}).inject(s,"top")}else{s.store("sortType","");this.sortIconNode=new Element("div",{styles:this.css.sortIconNode}).inject(s,"top")}s.setStyle("cursor","pointer");s.addEvent("click",function(){t.resort(this)})}}.bind(this));this.fireEvent("postCreateViewHead");this._postCreateViewHead(e)},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 t=this.checkboxElement.get("checked");this.items.each(function(e){if(e.checkboxElement)e.checkboxElement.set("checked",t)}.bind(this))},getCheckedItems:function(){var t=[];this.items.each(function(e){if(e.checkboxElement.get("checked")){t.push(e)}}.bind(this));return t},createViewBody:function(){this.loadElementList()},loadElementList:function(t){if(this.options.pagingEnable){var e=this.options.pagingPar.cloaurrentItem;var i=this.options.pagingPar.countPerPage;if(e){var s=Math.ceil(e/i);var o=e%i;this.loadPagingElementList(t,s,e)}else{this.loadPagingElementList(t,this.options.pagingPar.currentPage)}}else{this.loadScrollElementList(t)}},loadScrollElementList:function(t){if(!this.isItemsLoaded){if(!this.isItemLoadding){this.isItemLoadding=true;this._getCurrentPageData(function(t){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);this.documents[e]=i}}.bind(this))}this.isItemLoadding=false;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.dataCount=t.count;this.createPaging(t.count,e);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(i){if(this.options.documentKeyWord){var s=this.documents[i].node.getTop()}else{var s=this.items[i-1].node.getTop()}this.fireEvent("gotoItem",s)}}.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(t,e,i){if(this.options.pagingEnable){this.actions.listDetailFilter(i,e,o,function(e){if(t)t(e)}.bind(this))}else{if(!e)e=20;var s=this.items.length?this.items[this.items.length-1].data.id:"(0)";var o=this.filterData||{};this.actions.listDetailFilterNext(s,e,o,function(e){if(t)t(e)}.bind(this))}},getCurrentPageNum:function(){return this.paging.options.currentPage},getPageSize:function(){return this.paging.options.pageSize},gotoPage:function(t){this.paging.gotoPage(t)},_createDocument:function(t,e){return new MWF.xApplication.Template.Explorer.ComplexDocument(this.viewNode,t,this.explorer,this,null,e)},_openDocument:function(t){},_removeDocument:function(t,e){},_create:function(){this.from=new MWF.xApplication.Template.Explorer.PopupForm(this.explorer);this.from.create()},_queryCreateViewNode:function(){},_postCreateViewNode:function(t){},_queryCreateViewHead:function(){},_postCreateViewHead:function(t){}});MWF.xApplication.Template.Explorer.ComplexDocument=new Class({Implements:[Options,Events],initialize:function(t,e,i,s,o,n){this.explorer=i;this.data=e;this.container=t;this.view=s;this.index=n;if(o){this.app=o.app||this.view.app||this.explorer.app;this.lp=o.lp||this.view.lp||this.explorer.lp||this.app.lp;this.css=o.css||this.view.css||this.explorer.css||this.app.css;this.actions=o.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 t=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 e=this.view.template.documentSetting;if(e.styles||e.mouseoverStyles||e.mousedownStyles||e.icon||e.mouseoverIcon||e.mousedownIcon){this.view.setEventStyle(this.node,e,this,this.data)}var i=this.getConditionResult(e.condition);if(e.action&&this[e.action]){if(i){this.node.addEvent("click",function(e){this.fun.call(t,this.node,e);e.stopPropagation()}.bind({fun:this[e.action],node:this.node}))}}if(e.event&&i){this.bindEvent(this.node,e.event)}this.fireEvent("postCreateDocumentNode");this._postCreateDocumentNode(this.node,this.data)},loadItem:function(t,e,i){var s=this[t]=i.clone();if(this.format(s,t,e)){s.inject(this.node)}if(e.items){var o=s.getElements("[item]");if(s.get("item"))o.push(s);o.each(function(i){var s=i.get("item");var o=e.items[s];if(o){if(!o.value&&o.value!="")o.value=s;if(!this.format(i,t,o)){i.dispose()}}}.bind(this))}},format:function(t,e,i){var s=this;if(i.access){if(!this._getItemAccess(i))return false}var o=this.getConditionResult(i.show);if(!o)t.setStyle("display","none");var n=this.getConditionResult(i.condition);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)}if(i.action&&this[i.action]){if(n){t.addEvent("click",function(t){this.fun.call(s,this.node,t);t.stopPropagation()}.bind({fun:this[i.action],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"){if(n){this.checkboxElement=new Element("input",{type:"checkbox"}).inject(t);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();delete this},_queryCreateDocumentNode:function(t){},_postCreateDocumentNode:function(t,e){}});MWF.xApplication.Template.Explorer.PopupForm=new Class({Extends:MWF.widget.Common,Implements:[Options,Events],options:{style:"default",width:500,height:450,top:0,left:0,hasTop:false,hasTopIcon:false,hasTopContent:false,hasIcon:true,hasScroll:true,hasBottom:true,hasMark:true,title:"",draggable:false,maxAction:"false",closeAction:true,relativeToApp:true,sizeRelateTo:"app"},initialize:function(t,e,i,s){this.setOptions(i);this.explorer=t;if(s){if(this.options.relativeToApp){this.app=s.app||this.explorer.app;this.container=s.container||this.app.content;this.lp=s.lp||this.explorer.lp||this.app.lp;this.css=s.css||this.explorer.css||this.app.css;this.actions=s.actions||this.explorer.actions||this.app.actions||this.app.restActions}else{this.container=s.container;this.lp=s.lp||this.explorer.lp;this.css=s.css||this.explorer.css;this.actions=s.actions||this.explorer.actions}}else{if(this.options.relativeToApp){this.app=this.explorer.app;this.container=this.app.content;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}else{this.container=window.document.body;this.lp=this.explorer.lp;this.css=this.explorer.css;this.actions=this.explorer.actions}}this.data=e||{};this.load()},load:function(){},open:function(t){this.fireEvent("queryOpen");this.isNew=false;this.isEdited=false;this._open();this.fireEvent("postOpen")},create:function(){this.fireEvent("queryCreate");this.isNew=true;this._open();this.fireEvent("postCreate")},edit:function(){this.fireEvent("queryEdit");this.isEdited=true;this._open();this.fireEvent("postEdit")},_open:function(){if(this.options.hasMark){this.formMarkNode=new Element("div.formMarkNode",{styles:this.css.formMarkNode,events:{mouseover:function(t){t.stopPropagation()},mouseout:function(t){t.stopPropagation()},click:function(t){t.stopPropagation()}}}).inject(this.container||this.app.content)}this.formAreaNode=new Element("div.formAreaNode",{styles:this.css.formAreaNode});this.createFormNode();this.formAreaNode.inject(this.formMarkNode||this.container||this.app.content,"after");this.formAreaNode.fade("in");this.setFormNodeSize();this.setFormNodeSizeFun=this.setFormNodeSize.bind(this);if(this.app)this.app.addEvent("resize",this.setFormNodeSizeFun);if(this.options.draggable&&this.formTopNode){var t=(this.container||this.app.content).getSize();var e=this.formAreaNode.getSize();this.formAreaNode.makeDraggable({handle:this.formTopNode,limit:{x:[0,t.x-e.x],y:[0,t.y-e.y]}})}},createFormNode:function(){var t=this;this.formNode=new Element("div.formNode",{styles:this.css.formNode}).inject(this.formAreaNode);if(this.options.hasTop){this.createTopNode()}if(this.options.hasIcon){this.formIconNode=new Element("div.formIconNode",{styles:this.isNew?this.css.formNewNode:this.css.formIconNode}).inject(this.formNode)}this.createContent();if(this.options.hasBottom){this.createBottomNode()}if(this.options.hasScroll){MWF.require("MWF.widget.ScrollBar",function(){new MWF.widget.ScrollBar(this.formTableContainer,{indent:false,style:"xApp_TaskList",where:"before",distance:30,friction:4,axis:{x:false,y:true},onScroll:function(t){}})}.bind(this))}},createTopNode:function(){if(!this.formTopNode){this.formTopNode=new Element("div.formTopNode",{styles:this.css.formTopNode}).inject(this.formNode);if(this.options.hasTopIcon){this.formTopIconNode=new Element("div",{styles:this.css.formTopIconNode}).inject(this.formTopNode)}this.formTopTextNode=new Element("div",{styles:this.css.formTopTextNode,text:this.options.title}).inject(this.formTopNode);if(this.options.closeAction){this.formTopCloseActionNode=new Element("div",{styles:this.css.formTopCloseActionNode}).inject(this.formTopNode);this.formTopCloseActionNode.addEvent("click",function(){this.close()}.bind(this))}if(this.options.hasTopContent){this.formTopContentNode=new Element("div.formTopContentNode",{styles:this.css.formTopContentNode}).inject(this.formTopNode);this._createTopContent()}}},_createTopContent:function(){},createContent:function(){this.formContentNode=new Element("div.formContentNode",{styles:this.css.formContentNode}).inject(this.formNode);this.formTableContainer=new Element("div.formTableContainer",{styles:this.css.formTableContainer}).inject(this.formContentNode);this.formTableArea=new Element("div.formTableArea",{styles:this.css.formTableArea}).inject(this.formTableContainer);this._createTableContent()},_createTableContent:function(){var t="<table width='100%' bordr='0' cellpadding='5' cellspacing='0' styles='formTable'>"+"<tr><td styles='formTableTitle' lable='empName'></td>"+" <td styles='formTableValue' item='empName'></td></tr>"+"<tr><td styles='formTableTitle' lable='departmentName'></td>"+" <td styles='formTableValue' item='departmentName'></td></tr>"+"<tr><td styles='formTableTitle' lable='recordDateString'></td>"+" <td styles='formTableValue' item='recordDateString'></td></tr>"+"<tr><td styles='formTableTitle' lable='status'></td>"+" <td styles='formTableValue' item='status'></td></tr>"+"<tr><td styles='formTableTitle' lable='appealReason'></td>"+" <td styles='formTableValue' item='appealReason'></td></tr>"+"<tr><td styles='formTableTitle' lable='appealDescription'></td>"+" <td styles='formTableValue' item='appealDescription'></td></tr>"+"<tr><td styles='formTableTitle' lable='opinion1'></td>"+" <td styles='formTableValue' item='opinion1'></td></tr>"+"</table>";this.formTableArea.set("html",t);MWF.xDesktop.requireApp("Template","MForm",function(){this.form=new MForm(this.formTableArea,{empName:"xadmin"},{isEdited:this.isEdited||this.isNew,itemTemplate:{empName:{text:"姓名",type:"innertext"},departmentName:{text:"部门",tType:"department",notEmpty:true},recordDateString:{text:"日期",tType:"date"},status:{text:"状态",tType:"number"},appealReason:{text:"下拉框",type:"select",selectValue:["测试1","测试2"]},appealDescription:{text:"描述",type:"textarea"},opinion1:{text:"测试",type:"button",value:"测试"}}},this.app);this.form.load()}.bind(this),true)},createBottomNode:function(){this.formBottomNode=new Element("div.formBottomNode",{styles:this.css.formBottomNode}).inject(this.formNode);this._createBottomContent()},_createBottomContent:function(){this.cancelActionNode=new Element("div.formCancelActionNode",{styles:this.css.formCancelActionNode,text:this.lp.cancel}).inject(this.formBottomNode);this.cancelActionNode.addEvent("click",function(t){this.cancel(t)}.bind(this));if(this.isNew||this.isEdited){this.okActionNode=new Element("div.formOkActionNode",{styles:this.css.formOkActionNode,text:this.lp.ok}).inject(this.formBottomNode);this.okActionNode.addEvent("click",function(t){this.ok(t)}.bind(this))}},cancel:function(t){this.fireEvent("queryCancel");this.close();this.fireEvent("postCancel")},close:function(t){this.fireEvent("queryClose");this._close();if(this.setFormNodeSizeFun&&this.app){this.app.removeEvent("resize",this.setFormNodeSizeFun)}if(this.formMarkNode)this.formMarkNode.destroy();this.formAreaNode.destroy();this.fireEvent("postClose");delete this},_close:function(){},ok:function(t){this.fireEvent("queryOk");var e=this.form.getResult(true,",",true,false,true);if(e){this._ok(e,function(t){if(t.type=="error"){if(this.app)this.app.notice(t.message,"error")}else{if(this.formMarkNode)this.formMarkNode.destroy();this.formAreaNode.destroy();if(this.explorer&&this.explorer.view)this.explorer.view.reload();if(this.app)this.app.notice(this.isNew?this.lp.createSuccess:this.lp.updateSuccess,"success");this.fireEvent("postOk")}}.bind(this))}},_ok:function(t,e){},setFormNodeSize:function(t,e,i,s){if(!t)t=this.options.width?this.options.width:"50%";if(!e)e=this.options.height?this.options.height:"50%";if(!i)i=this.options.top?this.options.top:0;if(!s)s=this.options.left?this.options.left:0;var o=(this.container||this.app.content).getSize();var n=o.x;var a=o.y;"string"==typeof t&&(1<t.length&&"%"==t.substr(t.length-1,1))&&(t=parseInt(n*parseInt(t,10)/100,10));"string"==typeof e&&(1<e.length&&"%"==e.substr(e.length-1,1))&&(e=parseInt(a*parseInt(e,10)/100,10));300>t&&(t=300);220>e&&(e=220);i=i||parseInt((a-e)/2,10);s=s||parseInt((n-t)/2,10);this.formAreaNode.setStyles({width:""+t+"px",height:""+e+"px",top:""+i+"px",left:""+s+"px"});this.formNode.setStyles({width:""+t+"px",height:""+e+"px"});var r=this.formIconNode?this.formIconNode.getSize():{x:0,y:0};var l=this.formTopNode?this.formTopNode.getSize():{x:0,y:0};var h=this.formBottomNode?this.formBottomNode.getSize():{x:0,y:0};var c=e-r.y-l.y-h.y;this.formContentNode.setStyles({height:""+c+"px"});this.formTableContainer.setStyles({height:""+c+"px"})}});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,hasReturn:true,returnText:"返回首页"},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.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 o=this.options.currentPage;var n=Math.floor(i/2);var a,r,l;if(s<=i){l=1;r=s}else if(o+n>s){l=s-i;r=s}else if(o-n<1){l=1;r=i}else{l=o-n;r=o+n}var h=new Element("div.pagingBar",{styles:this.css.pagingBar}).inject(t);if(this.options.hasReturn){var c=new Element("div.pageReturn",{styles:this.css.pageReturn,text:this.options.returnText}).inject(h);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){if(o!=1){var p=new Element("div.prePage",{styles:this.css.prePage}).inject(h);p.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(o-1)}.bind(this)})}if(l>1){var d=new Element("div.pageItem",{styles:this.css.pageItem,text:"1..."}).inject(h);d.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.gotoPage(1)}.bind(this)})}for(a=l;a<=r;a++){if(o==a){new Element("div.currentPage",{styles:this.css.currentPage,text:a}).inject(h)}else{var f=new Element("div.pageItem",{styles:this.css.pageItem,text:a}).inject(h);f.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})})}}var u=new Element("input.pageJumper",{styles:this.css.pageJumper,title:"输入页码,按回车跳转"}).inject(h);new Element("div.pageText",{styles:this.css.pageText,text:"/"+s}).inject(h);u.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(r<s){var m=new Element("div.pageItem",{styles:this.css.pageItem,text:"..."+s}).inject(h);m.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.gotoPage(s)}.bind(this)})}if(o!=s){var g=new Element("div.nextPage",{styles:this.css.nextPage}).inject(h);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(o+1)}.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)
  2. })}},gotoPage:function(t){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();delete this}});