Explorer.js 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334
  1. MWF.xApplication.Template = MWF.xApplication.Template || {};
  2. MWF.xApplication.Template.Explorer = MWF.xApplication.Template.Explorer || {};
  3. MWF.require("MWF.widget.O2Identity", null, false);
  4. //MWF.xDesktop.requireApp("Template", "lp." + MWF.language, null, false);
  5. String.implement({
  6. toDOM: function( container, callback ){
  7. var wrapper = this.test('^<the|^<tf|^<tb|^<colg|^<ca') && ['<table>', '</table>', 1] ||
  8. this.test('^<col') && ['<table><colgroup>', '</colgroup><tbody></tbody></table>',2] ||
  9. this.test('^<tr') && ['<table><tbody>', '</tbody></table>', 2] ||
  10. this.test('^<th|^<td') && ['<table><tbody><tr>', '</tr></tbody></table>', 3] ||
  11. this.test('^<li') && ['<ul>', '</ul>', 1] ||
  12. this.test('^<dt|^<dd') && ['<dl>', '</dl>', 1] ||
  13. this.test('^<le') && ['<fieldset>', '</fieldset>', 1] ||
  14. this.test('^<opt') && ['<select multiple="multiple">', '</select>', 1] ||
  15. ['', '', 0];
  16. if( container ){
  17. var el = new Element('div', {html: wrapper[0] + this + wrapper[1]}).getChildren();
  18. while(wrapper[2]--) el = el[0].getChildren();
  19. el.inject( container );
  20. if( callback )callback( container );
  21. return el;
  22. }else{
  23. var div = new Element('div', {html: wrapper[0] + this + wrapper[1]});
  24. div.setStyle("display","none").inject( $(document.body) );
  25. if( callback )callback( div );
  26. var el = div.getChildren();
  27. while(wrapper[2]--) el = el[0].getChildren();
  28. div.dispose();
  29. return el;
  30. }
  31. }
  32. });
  33. MWF.xApplication.Template.Explorer.ComplexView = new Class({
  34. Implements: [Options, Events],
  35. options: {
  36. "style": "default",
  37. "templateUrl": "",
  38. "scrollEnable" : false,
  39. "scrollType" : "xApp_TaskList",
  40. "checkboxEnable" : true,
  41. "pagingEnable" : false,
  42. "documentSortable" : false, //item可以拖动排序,和 onSortCompleted 结合使用
  43. "documentKeyWord" : null,
  44. "noItemText": null,
  45. "pagingPar" : {
  46. position : [ "top" , "bottom" ], //分页条,上下
  47. countPerPage : 0,
  48. visiblePages : 10,
  49. currentPage : 1,
  50. currentItem : null,
  51. hasPagingBar : true,
  52. pagingBarUseWidget: false,
  53. hasTruningBar : true,
  54. hasNextPage : true,
  55. hasPrevPage : false,
  56. hasJumper : true,
  57. hasReturn : true,
  58. hiddenWithInvalid : true,
  59. text : {
  60. prePage : "",
  61. nextPage : "",
  62. firstPage : "",
  63. lastPage : ""
  64. }
  65. }
  66. },
  67. initialize: function (container, app, explorer, options, para) {
  68. this.container = container;
  69. this.explorer = explorer;
  70. if( para ){
  71. this.app = app || para.app || this.explorer.app;
  72. this.lp = para.lp || this.explorer.lp || this.app.lp;
  73. this.css = para.css || this.explorer.css || this.app.css;
  74. this.actions = para.actions || this.explorer.actions || this.app.actions || this.app.restActions;
  75. }else{
  76. this.app = app || this.explorer.app;
  77. this.lp = this.explorer.lp || this.app.lp;
  78. this.css = this.explorer.css || this.app.css;
  79. this.actions = this.explorer.actions || this.app.actions || this.app.restActions;
  80. }
  81. if (!options.templateUrl) {
  82. options.templateUrl = this.explorer.path + "listItem.json"
  83. } else if (options.templateUrl.indexOf("/") == -1) {
  84. options.templateUrl = this.explorer.path + options.templateUrl;
  85. }
  86. this.setOptions(options);
  87. },
  88. initData: function () {
  89. this.items = [];
  90. this.documents = {};
  91. this.isItemsLoaded = false;
  92. this.isItemLoadding = false;
  93. this.loadItemQueue = 0;
  94. this.count = 0;
  95. //this.controllers =[];
  96. },
  97. load: function () {
  98. this.fireEvent("queryLoad");
  99. this._queryLoad( );
  100. this.initData();
  101. this.ayalyseTemplate();
  102. this.node = new Element("div", {
  103. "styles": this.css.viewContentListNode
  104. }).inject(this.container);
  105. if( this.options.wrapView ){
  106. this.viewWrapNode = new Element("div").inject(this.node);
  107. }
  108. if( this.options.scrollEnable ){
  109. this.setScroll();
  110. }
  111. this.getContentTemplateNode();
  112. this.createViewNode();
  113. this.initSortData(); //点击列排序
  114. this.createViewHead();
  115. this.createViewBody();
  116. this._postLoad();
  117. this.fireEvent("postLoad");
  118. },
  119. reload: function () {
  120. debugger;
  121. this.clear();
  122. this.node = new Element("div", {
  123. "styles": this.css.viewContentListNode
  124. }).inject(this.container);
  125. if( this.options.wrapView ){
  126. this.viewWrapNode = new Element("div").inject(this.node);
  127. }
  128. this.createViewNode();
  129. this.createViewHead();
  130. this.createViewBody();
  131. this.fireEvent("postReloadLoad");
  132. },
  133. initSortData: function () {
  134. this.sortField = null;
  135. this.sortType = null;
  136. this.sortFieldDefault = null;
  137. this.sortTypeDefault = null;
  138. },
  139. destroy: function(){
  140. if(this.documentNodeTemplate){
  141. delete this.documentNodeTemplate;
  142. }
  143. if(this.template)delete this.template;
  144. if( this.scrollBar || this.scrollContainerFun ){
  145. this.destroyScroll()
  146. }
  147. this.clear();
  148. //delete this;
  149. },
  150. clear: function () {
  151. if(this.pagingContainerTop ){
  152. if( this.pagingContainerTopCreated ){
  153. this.pagingContainerTop.destroy();
  154. this.pagingContainerTop = null;
  155. }else{
  156. this.pagingContainerTop.empty();
  157. }
  158. }
  159. if( this.pagingContainerBottom ){
  160. if( this.pagingContainerBottomCreated ){
  161. this.pagingContainerBottom.destroy();
  162. this.pagingContainerBottom = null;
  163. }else{
  164. this.pagingContainerBottom.empty();
  165. }
  166. }
  167. if( this.paging )this.paging.destroy();
  168. this.paging = null;
  169. if( this.documentDragSort ){
  170. this.documentDragSort.removeLists( this.viewBodyNode || this.viewNode );
  171. this.documentDragSort.detach();
  172. this.documentDragSort = null;
  173. }
  174. this.documents = null;
  175. MWF.release(this.items);
  176. this.items = [];
  177. this.documents = {};
  178. this.viewWrapNode = null;
  179. this.node.destroy();
  180. this.container.empty();
  181. this.isItemsLoaded = false;
  182. this.isItemLoadding = false;
  183. this.loadItemQueue = 0;
  184. },
  185. clearBody : function(){
  186. this.items.each( function(item,i){
  187. item.destroy();
  188. });
  189. this.documents = null;
  190. MWF.release(this.items);
  191. this.items = [];
  192. this.documents = {};
  193. },
  194. resort: function (el) {
  195. this.sortField = el.retrieve("sortField");
  196. var sortType = el.retrieve("sortType");
  197. if (sortType == "") {
  198. this.sortType = "asc";
  199. } else if (this.sortType == "asc") {
  200. this.sortType = "desc";
  201. } else {
  202. this.sortField = null;
  203. this.sortType = null;
  204. }
  205. this.reload();
  206. },
  207. destroyScroll: function(){
  208. if( this.options.scrollType == "window" ){
  209. if( this.scrollContainerFun ){
  210. this.container.removeEvent("scroll", this.scrollContainerFun );
  211. this.scrollContainerFun = null;
  212. }
  213. }else{
  214. if(this.scrollBar.scrollVAreaNode){
  215. this.scrollBar.scrollVAreaNode.destroy();
  216. }
  217. delete this.scrollBar;
  218. }
  219. },
  220. setScroll: function(){
  221. if( this.options.scrollType == "window" ){
  222. this.container.setStyle("overflow","auto");
  223. this.scrollContainerFun = function(){
  224. if( !this.options.pagingEnable ){
  225. var scrollSize = this.container.getScrollSize();
  226. var clientSize = this.container.getSize();
  227. var scrollHeight = scrollSize.y - clientSize.y;
  228. if (this.container.scrollTop + 150 > scrollHeight ) {
  229. if (! this.isItemsLoaded) this.loadElementList();
  230. }
  231. }
  232. }.bind(this);
  233. this.container.addEvent("scroll", this.scrollContainerFun )
  234. }else{
  235. MWF.require("MWF.widget.ScrollBar", function () {
  236. this.scrollBar = new MWF.widget.ScrollBar(this.container, {
  237. "indent": false,
  238. "style": this.options.scrollType,
  239. "where": "before",
  240. "distance": 60,
  241. "friction": 4,
  242. "axis": {"x": false, "y": true},
  243. "onScroll": function (y) {
  244. if( !this.options.pagingEnable ){
  245. var scrollSize = this.container.getScrollSize();
  246. var clientSize = this.container.getSize();
  247. var scrollHeight = scrollSize.y - clientSize.y;
  248. if (y + 200 > scrollHeight ) {
  249. if (! this.isItemsLoaded) this.loadElementList();
  250. }
  251. }
  252. }.bind(this)
  253. });
  254. }.bind(this));
  255. }
  256. },
  257. ayalyseTemplate: function () {
  258. MWF.getJSON(this.options.templateUrl, function (json) {
  259. this.template = json;
  260. }.bind(this), false)
  261. },
  262. formatElement: function (container, setting, clear ) {
  263. //container.appendHTML(setting.html);
  264. var el = setting.html.toDOM( container, function( c , el ){
  265. this.formatStyles(c);
  266. this.formatLable(c);
  267. if(container)this.setEventStyle(c, setting);
  268. }.bind(this) )[0];
  269. if( setting.width ){
  270. el.set("width",setting.width )
  271. }
  272. if( clear && container ){
  273. container.empty();
  274. }
  275. return el;
  276. },
  277. formatStyles: function ( container ) {
  278. container.getElements("[class]").each(function (el) {
  279. var className = el.get("class");
  280. if (className && this.css[className]) {
  281. el.setStyles(this.css[className])
  282. }
  283. }.bind(this));
  284. container.getElements("[styles]").each(function (el) {
  285. var styles = el.get("styles");
  286. if (styles && this.css[styles]) {
  287. el.setStyles(this.css[styles])
  288. }
  289. }.bind(this));
  290. },
  291. formatLable: function (container) {
  292. container.getElements("[lable]").each(function (el) {
  293. var lable = el.get("lable");
  294. if (lable && this.lp[lable]) {
  295. el.set("text", this.lp[lable] + (el.get("colon") ? ":" : "") )
  296. }
  297. }.bind(this))
  298. },
  299. createViewNode: function () {
  300. this.fireEvent("queryCreateViewNode");
  301. this._queryCreateViewNode( );
  302. this.viewNode = this.formatElement(this.viewWrapNode || this.node, this.template.viewSetting);
  303. this._postCreateViewNode( this.viewNode );
  304. this.fireEvent("postCreateViewNode");
  305. if (!this.viewNode)return;
  306. },
  307. getContentTemplateNode: function(){
  308. this.documentNodeTemplate = this.formatElement(null, this.template.documentSetting);
  309. this.template.items.each(function (item) {
  310. item.nodeTemplate = this.formatElement(null, item.content);
  311. }.bind(this))
  312. },
  313. createViewHead: function () {
  314. this.fireEvent("queryCreateViewHead");
  315. this._queryCreateViewHead( );
  316. if (this.template) {
  317. if (!this.template.headSetting || this.template.headSetting.disable || !this.template.headSetting.html) {
  318. return;
  319. }
  320. }
  321. var _self = this;
  322. var viewHeadNode;
  323. if( this.template.viewHeadSetting ){
  324. viewHeadNode = this.viewHeadNode = this.formatElement(this.viewNode, this.template.viewHeadSetting);
  325. }
  326. var headNode = this.headNode = this.formatElement( viewHeadNode || this.viewNode, this.template.headSetting);
  327. this.headItemNodes = {};
  328. this.template.items.each(function (item) {
  329. if( !item.head )return;
  330. ////如果设置了权限,那么options里需要有 对应的设置项才会展现
  331. // 比如 item.access == isAdmin 那么 this.options.isAdmin要为true才展现
  332. if (item.access && !this.options[item.access])return;
  333. if( item.condition && !this.getConditionResult(item.condition))return;
  334. if (item.head.access && !this.options[item.head.access])return;
  335. if( item.head.condition && !this.getConditionResult(item.head.condition))return;
  336. if( item.name == "$checkbox" && !this.options.checkboxEnable )return;
  337. var headItemNode = this.formatElement(headNode, item.head);
  338. if( item.name ){
  339. this.headItemNodes[item.name] = headItemNode;
  340. }
  341. if (item.name == "$checkbox" && this.options.checkboxEnable ) {
  342. this.checkboxElement = new Element("input", {
  343. "type": "checkbox"
  344. }).inject(headItemNode);
  345. this.checkboxElement.addEvent("click", function () {
  346. this.selectAllCheckbox()
  347. }.bind(this))
  348. }
  349. if (item.defaultSort && item.defaultSort != "") {
  350. this.sortFieldDefault = item.name;
  351. this.sortTypeDefault = item.defaultSort;
  352. }
  353. }.bind(this));
  354. this.template.items.each( function(item){
  355. if (item.name && item.sort && item.sort != "") {
  356. var headItemNode = this.headItemNodes[item.name];
  357. headItemNode.store("sortField", item.name);
  358. if (this.sortField == item.name && this.sortType != "") {
  359. headItemNode.store("sortType", this.sortType);
  360. this.sortIconNode = new Element("div", {
  361. "styles": this.sortType == "asc" ? this.css.sortIconNode_asc : this.css.sortIconNode_desc
  362. }).inject(headItemNode, "bottom");
  363. } else {
  364. headItemNode.store("sortType", "");
  365. this.sortIconNode = new Element("div.sortIconNode", {"styles": this.css.sortIconNode}).inject(headItemNode, "bottom");
  366. }
  367. headItemNode.setStyle("cursor", "pointer");
  368. headItemNode.addEvent("click", function () {
  369. _self.resort(this);
  370. })
  371. }
  372. }.bind(this));
  373. this.fireEvent("postCreateViewHead");
  374. this._postCreateViewHead( headNode )
  375. },
  376. getConditionResult: function (str) {
  377. var flag = true;
  378. if (str && str.substr(0, 8) == "function") { //"function".length
  379. eval("var fun = " + str);
  380. flag = fun.call(this, this.data);
  381. }
  382. return flag;
  383. },
  384. setEventStyle: function (node, setting, bingObj, data) {
  385. var _self = this;
  386. var styles, overStyles, downStyles;
  387. var styleStr = setting.styles;
  388. if (typeOf(styleStr) == "string"){
  389. if (styleStr && styleStr.substr(0, "function".length) == "function") {
  390. eval("var fun = " + styleStr );
  391. styles = fun.call(bingObj, data);
  392. }else{
  393. styles = this.css[styleStr];
  394. }
  395. }else if (typeOf(styleStr) == "object"){
  396. styles = styleStr;
  397. }else if (typeOf(styleStr) == "function"){
  398. eval("var fun = " + styleStr );
  399. styles = fun.call(bingObj, data);
  400. }
  401. if (!styles) {
  402. var s = node.get("styles");
  403. if (!s)node.get("class");
  404. if (s)styles = this.css[s]
  405. }
  406. if (setting.icon) {
  407. if (!styles)styles = {};
  408. styles["background-image"] = "url(" + this.explorer.path + "/" + this.explorer.options.style + "/icon/" + setting.icon + ")";
  409. }
  410. if (typeOf(setting.mouseoverStyles) == "string")overStyles = this.css[setting.mouseoverStyles];
  411. if (typeOf(setting.mouseoverStyles) == "object") overStyles = setting.mouseoverStyles;
  412. if (setting.mouseoverIcon) {
  413. if (!overStyles)overStyles = {};
  414. overStyles["background-image"] = "url(" + this.explorer.path + "/" + this.explorer.options.style + "/icon/" + setting.mouseoverIcon + ")"
  415. }
  416. if (typeOf(setting.mousedownStyles) == "string")downStyles = this.css[setting.mousedownStyles];
  417. if (typeOf(setting.mousedownStyles) == "object") downStyles = setting.mousedownStyles;
  418. if (setting.mousedownIcon) {
  419. if (!downStyles)downStyles = {};
  420. downStyles["background-image"] = "url(" + this.explorer.path + "/" + this.explorer.options.style + "/icon/" + setting.mousedownIcon + ")"
  421. }
  422. if (styles)node.setStyles(styles);
  423. var holdMouseDownStyles = setting.holdMouseDownStyles || false;
  424. if (overStyles && styles) {
  425. node.addEvent("mouseover", function (ev) {
  426. if( !_self.lockNodeStyle && (!this.holdMouseDownStyles || _self.mousedownNode != this.node ) )this.node.setStyles(this.styles);
  427. }.bind({"styles": overStyles, "node":node, "holdMouseDownStyles" : holdMouseDownStyles }));
  428. node.addEvent("mouseout", function (ev) {
  429. if( !_self.lockNodeStyle && (!this.holdMouseDownStyles || _self.mousedownNode != this.node ) )this.node.setStyles(this.styles);
  430. }.bind({"styles": styles, "node":node, "holdMouseDownStyles" : holdMouseDownStyles}));
  431. }
  432. if (downStyles && ( overStyles || styles)) {
  433. node.addEvent("mousedown", function (ev) {
  434. if( !_self.lockNodeStyle )this.node.setStyles(this.styles);
  435. if( _self.mousedownNode && this.holdMouseDownStyles && _self.mousedownNode != this.node ){
  436. _self.mousedownNode.setStyles( this.normalStyle )
  437. }
  438. if( this.holdMouseDownStyles ){
  439. _self.mousedownNode = this.node;
  440. }
  441. }.bind({"styles": downStyles, normalStyle : (styles || overStyles), "node":node, "holdMouseDownStyles" : holdMouseDownStyles}));
  442. node.addEvent("mouseup", function (ev) {
  443. if( !_self.lockNodeStyle && (!this.holdMouseDownStyles || _self.mousedownNode != this.node ) )this.node.setStyles(this.styles);
  444. }.bind({"styles": overStyles || styles, "node":node, "holdMouseDownStyles" : holdMouseDownStyles}))
  445. }
  446. },
  447. selectAllCheckbox: function () {
  448. var flag = this.checkboxElement.get("checked");
  449. this.items.each(function (it) {
  450. if (it.checkboxElement)it.checkboxElement.set("checked", flag)
  451. }.bind(this))
  452. },
  453. getCheckedItems : function(){
  454. var checkedItems = [];
  455. this.items.each(function (it) {
  456. if (it.checkboxElement.get("checked")) {
  457. checkedItems.push( it )
  458. }
  459. }.bind(this));
  460. return checkedItems;
  461. },
  462. createViewBody : function(){
  463. if( this.template.viewBodySetting ){
  464. this.viewBodyNode = this.formatElement(this.viewNode, this.template.viewBodySetting);
  465. }
  466. this.loadElementList();
  467. },
  468. createNoItemNode: function(){
  469. new Element("div", {
  470. styles : this.css.noItemTextNode,
  471. text: this.options.noItemText
  472. }).inject(this.viewWrapNode || this.node);
  473. },
  474. loadElementList: function () {
  475. if( this.options.pagingEnable ){
  476. var currentItem = this.options.pagingPar.currentItem;
  477. var countPerPage = this.options.pagingPar.countPerPage;
  478. if( currentItem ){
  479. var pageNum = Math.ceil( currentItem / countPerPage );
  480. var itemNum = currentItem % countPerPage;
  481. this.loadPagingElementList( countPerPage , pageNum, currentItem );
  482. }else{
  483. this.loadPagingElementList( countPerPage , this.options.pagingPar.currentPage ); //使用分页的方式
  484. }
  485. }else{
  486. countPerPage = this.options.pagingPar.countPerPage;
  487. this.loadScrollElementList( countPerPage ); //滚动条下拉取下一页
  488. }
  489. },
  490. loadScrollElementList : function( count ){
  491. if (!this.isItemsLoaded) {
  492. if (!this.isItemLoadding) {
  493. this.isItemLoadding = true;
  494. this._getCurrentPageData(function (json) {
  495. var itemList = [];
  496. this.fireEvent("queryCreateViewBody",[this]);
  497. this._queryCreateViewBody( );
  498. var length = this.dataCount = json.count; //|| json.data.length;
  499. if (length <= this.items.length) {
  500. this.isItemsLoaded = true;
  501. }
  502. if( json.data && typeOf( json.data )=="array" ){
  503. json.data.each(function (data ) {
  504. var key = data[ this.options.documentKeyWord || "id" ];
  505. if (!this.documents[key]) {
  506. var item = this._createDocument(data, this.items.length);
  507. this.items.push(item);
  508. if(item)itemList.push( item.node );
  509. this.documents[key] = item;
  510. }
  511. }.bind(this));
  512. }
  513. this.isItemLoadding = false;
  514. if( this.options.documentSortable && itemList.length){
  515. if( this.documentDragSort ){
  516. this.documentDragSort.addItems( itemList );
  517. }else{
  518. this.makeSortable();
  519. }
  520. }
  521. this.fireEvent("postCreateViewBody", [this]);
  522. this._postCreateViewBody( this.viewBodyNode || this.viewNode );
  523. if (this.loadItemQueue > 0) {
  524. this.loadItemQueue--;
  525. this.loadElementList();
  526. }
  527. }.bind(this), count);
  528. } else {
  529. this.loadItemQueue++;
  530. }
  531. }
  532. },
  533. loadPagingElementList : function( count, pageNum, itemNum ){
  534. this.currentPage = pageNum || 1;
  535. this._getCurrentPageData(function (json) {
  536. this.items = [];
  537. this.documents = {};
  538. this.fireEvent("queryCreateViewBody");
  539. this._queryCreateViewBody( );
  540. if( this.documentDragSort ){
  541. this.documentDragSort.removeLists( this.viewBodyNode || this.viewNode );
  542. }
  543. this.dataCount = json.count;
  544. this.createPaging( json.count, this.currentPage );
  545. json.data.each(function (data ) {
  546. var item = this._createDocument(data, this.items.length);
  547. this.items.push( item );
  548. var key = data[ this.options.documentKeyWord || "id" ];
  549. this.documents[key] = item;
  550. }.bind(this));
  551. if( this.options.documentSortable && this.items.length){
  552. this.makeSortable();
  553. }
  554. if( !this.dataCount && this.options.noItemText ){
  555. this.createNoItemNode()
  556. }
  557. var top;
  558. if( itemNum && this.documents[ itemNum ] ){
  559. if( this.options.documentKeyWord ){
  560. top = this.documents[ itemNum ].node.getTop();
  561. }else{
  562. top = this.items[itemNum-1].node.getTop();
  563. }
  564. this.fireEvent( "gotoItem", top );
  565. }
  566. this.fireEvent("postCreateViewBody");
  567. this._postCreateViewBody( this.viewBodyNode || this.viewNode );
  568. }.bind(this), count, pageNum );
  569. },
  570. createPaging : function( itemSize, pageNum ){
  571. if( !this.options.pagingEnable || this.paging )return;
  572. if( this.options.pagingPar.position.indexOf("top") > -1 ){
  573. if( !this.pagingContainerTop ){
  574. this.pagingContainerTopCreated = true;
  575. this.pagingContainerTop = new Element("div", {"styles":this.css.pagingContainer}).inject( this.viewWrapNode || this.viewNode, "before" );
  576. }
  577. }
  578. if( this.options.pagingPar.position.indexOf("bottom") > -1 ){
  579. if( !this.pagingContainerBottom ){
  580. this.pagingContainerBottomCreated = true;
  581. this.pagingContainerBottom = new Element("div", {"styles":this.css.pagingContainer}).inject( this.viewWrapNode || this.viewNode, "after" );
  582. }
  583. }
  584. var par = Object.merge( this.options.pagingPar, {
  585. itemSize : itemSize,
  586. onJumpingPage : function( arg1, arg2 ){
  587. if( o2.typeOf(arg1) === "object" ){
  588. this.loadPagingElementList( this.options.pagingPar.countPerPage, arg1.pageNum, arg1.itemNum );
  589. }else{
  590. this.loadPagingElementList( this.options.pagingPar.countPerPage, arg1, arg2 );
  591. }
  592. if(this.checkboxElement){
  593. this.checkboxElement.set("checked", false);
  594. }
  595. }.bind(this)
  596. });
  597. if( pageNum )par.currentPage = pageNum;
  598. if( this.options.pagingPar.hasPagingBar ){
  599. if( this.options.pagingPar.pagingBarUseWidget ){
  600. if(this.pagingContainerTop){
  601. this.loadWidgetPaging(this.pagingContainerTop, itemSize, par)
  602. }
  603. if(this.pagingContainerBottom){
  604. this.loadWidgetPaging(this.pagingContainerBottom, itemSize, par)
  605. }
  606. }else{
  607. this.paging = new MWF.xApplication.Template.Explorer.Paging(
  608. this.pagingContainerTop, this.pagingContainerBottom, par, this.css);
  609. this.paging.load();
  610. }
  611. }
  612. },
  613. loadWidgetPaging: function(node, itemSize, par){
  614. if(!o2.widget.Paging)MWF.require("o2.widget.Paging", null, false);
  615. var pageSize = Math.ceil(itemSize/this.options.pagingPar.countPerPage);
  616. this.paging = new o2.widget.Paging(node, Object.merge({
  617. countPerPage: 20,
  618. visiblePages: 9,
  619. currentPage: 1,
  620. itemSize: 0,
  621. pageSize: pageSize,
  622. hasNextPage: true,
  623. hasPrevPage: true,
  624. hasTruningBar: true,
  625. hasBatchTuring: true,
  626. hasFirstPage: true,
  627. hasLastPage: true,
  628. hasJumper: true,
  629. hiddenWithDisable: false,
  630. hiddenWithNoItem: true,
  631. text: {
  632. prePage: "",
  633. nextPage: "",
  634. firstPage: "",
  635. lastPage: ""
  636. }
  637. }, par), this.options.pagingPar.pagingStyles || {});
  638. this.paging.load();
  639. },
  640. _getCurrentPageData: function (callback, count, page) {
  641. if( this.options.pagingEnable ){
  642. this.actions.listDetailFilter(page, count, filter, function (json) {
  643. if (callback)callback(json);
  644. }.bind(this))
  645. }else{
  646. if (!count)count = 20;
  647. var id = (this.items.length) ? this.items[this.items.length - 1].data.id : "(0)";
  648. var filter = this.filterData || {};
  649. this.actions.listDetailFilterNext(id, count, filter, function (json) {
  650. if (callback)callback(json);
  651. }.bind(this))
  652. }
  653. },
  654. getCurrentPageNum: function(){
  655. return this.paging.options.currentPage;
  656. },
  657. getPageSize: function(){
  658. return this.paging.options.pageSize;
  659. },
  660. gotoPage : function( page ){
  661. this.paging.gotoPage( page );
  662. },
  663. makeSortable:function(){
  664. this.documentDragSort = new Sortables( this.viewBodyNode || this.viewNode,
  665. {
  666. clone:true,
  667. opacity:0.3,
  668. onStart : function (element, clone) {
  669. if(this.css.itemSortCloneNode)clone.setStyles( this.css.itemSortCloneNode );
  670. this.fireEvent( "documentSortStart", [ element, clone ] );
  671. this._documentSortStart(element, clone);
  672. }.bind(this),
  673. onSort : function (element, clone) {
  674. this.fireEvent( "documentSort", [ element, clone ] );
  675. this._documentSort(element, clone);
  676. }.bind(this),
  677. onComplete : function (element) {
  678. var serial = this.documentDragSort.serialize();
  679. this.fireEvent( "documentSortComplete", [ element, serial ] );
  680. this._documentSortComplete(element, serial);
  681. //var id = element.get("id");
  682. //var idStr = dragSort.serialize();
  683. //var submitData = {
  684. // "ordersymbol":this.filter.ordersymbol,
  685. // "ids":idStr
  686. //};
  687. //this.actions.changeKeyWorkPosition(submitData,function(json){
  688. // this.createViewContent();
  689. //}.bind(this));
  690. }.bind(this)
  691. }
  692. )
  693. },
  694. _createDocument: function (data, index) {
  695. return new MWF.xApplication.Template.Explorer.ComplexDocument(this.viewBodyNode || this.viewNode, data, this.explorer, this, null,index);
  696. },
  697. _openDocument: function (documentData) {
  698. },
  699. _removeDocument: function (documentData, all) {
  700. //var id = document.data.id;
  701. //this.actions.removeDocument(id, function(json){
  702. // //json.data.each(function(item){
  703. // this.items.erase(this.documents[id]);
  704. // this.documents[id].destroy();
  705. // MWF.release(this.documents[id]);
  706. // delete this.documents[id];
  707. // this.app.notice(this.app.lp.deleteDocumentOK, "success");
  708. // // }.bind(this));
  709. //}.bind(this));
  710. },
  711. _create: function () {
  712. MWF.xDesktop.requireApp("Template", "MPopupForm", function(){
  713. this.from = new MPopupForm(this.explorer);
  714. this.from.create();
  715. }.bind(this), false);
  716. },
  717. _queryLoad: function(){
  718. },
  719. _postLoad: function(){
  720. },
  721. _queryCreateViewNode: function(){
  722. },
  723. _postCreateViewNode: function( viewNode ){
  724. },
  725. _queryCreateViewHead:function(){
  726. },
  727. _postCreateViewHead: function( headNode ){
  728. },
  729. _queryCreateViewBody:function(){
  730. },
  731. _postCreateViewBody: function( bodyNode ){
  732. },
  733. _documentSortStart: function( element, clone ){
  734. },
  735. _documentSort: function( element, clone ){
  736. },
  737. _documentSortComplete: function( element, serial ){
  738. }
  739. });
  740. MWF.xApplication.Template.Explorer.ComplexDocument = new Class({
  741. Implements: [Options, Events],
  742. initialize: function (container, data, explorer, view, para, index) {
  743. this.explorer = explorer;
  744. this.data = data;
  745. this.container = container;
  746. this.view = view;
  747. this.index = index;
  748. if( para ){
  749. this.app = para.app || this.view.app || this.explorer.app;
  750. this.lp = para.lp || this.view.lp || this.explorer.lp || this.app.lp;
  751. this.css = para.css || this.view.css || this.explorer.css || this.app.css;
  752. this.actions = para.actions || this.view.actions || this.explorer.actions || this.app.actions || this.app.restActions;
  753. }else{
  754. this.app = this.view.app || this.explorer.app;
  755. this.lp = this.view.lp || this.explorer.lp || this.app.lp;
  756. this.css = this.view.css || this.explorer.css || this.app.css;
  757. this.actions = this.view.actions || this.explorer.actions || this.app.actions || this.app.restActions;
  758. }
  759. this.load();
  760. },
  761. load: function () {
  762. this.fireEvent("queryCreateDocumentNode");
  763. this._queryCreateDocumentNode( this.data );
  764. var _self = this;
  765. this.node = this.view.documentNodeTemplate.clone().inject(this.container);
  766. //this.documentAreaNode = new Element("td", {"styles": this.css.documentNode}).inject(this.node);
  767. this._load()
  768. },
  769. reload : function(){
  770. this.preNode = this.node;
  771. this.node = this.view.documentNodeTemplate.clone().inject(this.preNode,"after");
  772. this.preNode.destroy();
  773. this._load()
  774. },
  775. _load : function(){
  776. var _self = this;
  777. this.view.template.items.each(function (item) {
  778. var flag = true;
  779. if( item.condition ){
  780. flag = this.getConditionResult( item.condition );
  781. }
  782. if( flag && item.access ){
  783. flag = this._getItemAccess(item);
  784. }
  785. if( flag ){
  786. this.loadItem(item.name, item.content, item.nodeTemplate);
  787. }
  788. }.bind(this));
  789. var setting = this.view.template.documentSetting;
  790. if( setting.styles || setting.mouseoverStyles || setting.mousedownStyles || setting.icon || setting.mouseoverIcon || setting.mousedownIcon ){
  791. this.view.setEventStyle( this.node, setting, this, this.data );
  792. }
  793. var available = this.getConditionResult(setting.condition);
  794. if( setting.action && this[setting.action] ){
  795. if ( available ){
  796. this.node.addEvent("click", function (ev) {
  797. this.fun.call(_self, this.node, ev);
  798. ev.stopPropagation();
  799. }.bind({fun: this[setting.action], node : this.node}))
  800. }
  801. }
  802. if( setting.event && available ){
  803. this.bindEvent( this.node, setting.event );
  804. }
  805. this.fireEvent("postCreateDocumentNode");
  806. this._postCreateDocumentNode( this.node, this.data )
  807. },
  808. loadItem: function (name, item, nodeTemplate ) {
  809. var itemNode = this[name] = nodeTemplate.clone();
  810. if( this.format(itemNode, name, item) ){
  811. itemNode.inject(this.node);
  812. }
  813. if (item.items) {
  814. var elements = itemNode.getElements("[item]");
  815. if( itemNode.get("item") )elements.push(itemNode);
  816. elements.each(function (el) {
  817. var key = el.get("item");
  818. var sub = item.items[key];
  819. if( sub ){
  820. if( !sub.value && sub.value!="" )sub.value = key;
  821. if( !this.format(el, name, sub) ){
  822. el.dispose()
  823. }
  824. }
  825. }.bind(this))
  826. }
  827. },
  828. format: function (itemNode, name, item) {
  829. var _self = this;
  830. if( name == "$checkbox" && !this.view.options.checkboxEnable )return false;
  831. if (item.access) {
  832. if (!this._getItemAccess(item))return false;
  833. }
  834. var available = this.getConditionResult(item.condition);
  835. if ( item.action && !available) {
  836. return false;
  837. }
  838. //if (item.condition) {
  839. // if (!this.getConditionResult(item.condition))return false;
  840. //}
  841. var show = this.getConditionResult( item.show );
  842. if( !show )itemNode.setStyle("display","none");
  843. if (item.text) {
  844. var text = this.getExecuteResult( item.text );
  845. //var text = item.text;
  846. itemNode.set("text", this.view.lp && this.view.lp[text] ? this.view.lp[text] : text);
  847. }
  848. if (item.title) {
  849. var title = this.getExecuteResult( item.title );
  850. //var title = item.title;
  851. itemNode.set("title", this.view.lp && this.view.lp[title] ? this.view.lp[title] : title);
  852. }
  853. if ( !item.text && item.value && item.value != "") {
  854. if( item.type == "html" ){
  855. itemNode.set("html", this.getValue(item.value));
  856. }else{
  857. itemNode.set("text", this.getValue(item.value));
  858. }
  859. }
  860. if( item.styles || item.mouseoverStyles || item.mousedownStyles || item.icon || item.mouseoverIcon || item.mousedownIcon ){
  861. this.view.setEventStyle( itemNode, item, this, this.data );
  862. }
  863. var action = item.action && this[item.action];
  864. if ( action ) {
  865. if ( available ){
  866. itemNode.addEvent("click", function (ev) {
  867. this.fun.call(_self, this.node, ev);
  868. ev.stopPropagation();
  869. }.bind({fun: action, node : itemNode}))
  870. }else{
  871. return false;
  872. }
  873. }
  874. if( item.event && available ){
  875. this.bindEvent( itemNode, item.event );
  876. }
  877. if( item.attr ){
  878. this.setAttr( itemNode, item.attr );
  879. }
  880. if ( name == "$checkbox" && this.view.options.checkboxEnable ) {
  881. if ( available ){
  882. this.checkboxElement = new Element("input", {
  883. "type": "checkbox"
  884. }).inject(itemNode);
  885. if( item.event ){
  886. this.bindEvent( this.checkboxElement, item.event );
  887. }
  888. if( !item.event || !item.event.contains( "click" ) ){
  889. this.checkboxElement.addEvent("click", function (ev) {
  890. ev.stopPropagation();
  891. }.bind(this));
  892. }
  893. itemNode.addEvent("click", function (ev) {
  894. this.checkboxElement.set("checked", !this.checkboxElement.get("checked"));
  895. ev.stopPropagation();
  896. }.bind(this))
  897. }else{
  898. //return false;
  899. }
  900. }
  901. return true;
  902. },
  903. getExecuteResult : function( str ){
  904. var result = str;
  905. if (str && str.substr(0, 8) == "function") { //"function".length
  906. eval("var fun = " + str);
  907. result = fun.call(this, this.data);
  908. }
  909. return result;
  910. },
  911. getValue: function (str) {
  912. if (str.substr(0, 8 ) == "function") { //"function".length
  913. eval("var fun = " + str);
  914. return fun.call(this, this.data);
  915. } else if (typeOf(this.data[str]) == "number") {
  916. return this.data[str];
  917. } else {
  918. return this.data[str] ? this.data[str] : "";
  919. }
  920. },
  921. getConditionResult: function (str) {
  922. var flag = true;
  923. if (str && str.substr(0, 8) == "function") { //"function".length
  924. eval("var fun = " + str);
  925. flag = fun.call(this, this.data);
  926. }
  927. return flag;
  928. },
  929. setAttr: function(item, attr){
  930. if( !attr || attr == "" || attr == "$none" )return;
  931. if( typeof attr == "string" ){
  932. if( attr.indexOf("^^") > -1 ){
  933. var attrsArr = attr.split("##");
  934. if( attrsArr[0].split("^^").length != 2 )return;
  935. attrs = {};
  936. for(var i=0;i<attrsArr.length;i++){
  937. var aname = attrsArr[i].split("^^")[0];
  938. var afunction = attrsArr[i].split("^^")[1];
  939. if( afunction.substr(0, "function".length) == "function" ){
  940. eval("var fun = " + afunction );
  941. attrs[ aname ] = fun.call(this, this.data); //字符串变对象或function,方法1
  942. }else{
  943. attrs[ aname ] = afunction;
  944. }
  945. }
  946. }else{
  947. //字符串变对象或function,方法2
  948. eval( "var attrs = " + attr );
  949. }
  950. }
  951. if( typeOf(attrs) == "object" ){
  952. for( var a in attrs ){
  953. item.set( a, attrs[a] );
  954. }
  955. }
  956. },
  957. bindEvent: function(item,events){
  958. if( !events || events == "" || events == "$none" )return;
  959. if( typeof events == "string" ){
  960. if( events.indexOf("^^") > -1 ){
  961. var eventsArr = events.split("##");
  962. if( eventsArr[0].split("^^").length != 2 )return;
  963. events = {};
  964. for(var i=0;i<eventsArr.length;i++){
  965. var ename = eventsArr[i].split("^^")[0];
  966. var efunction = eventsArr[i].split("^^")[1];
  967. events[ ename ] = eval( "(function(){ return "+ efunction +" })()" ); //字符串变对象或function,方法1
  968. }
  969. }else{
  970. //字符串变对象或function,方法2
  971. eval( "var events = " + events );
  972. }
  973. }
  974. if( typeOf(events) == "object" ){
  975. for( var e in events ){
  976. item.addEvent( e, function(ev){
  977. this.fun.call( this.bingObj, this.target, ev );
  978. ev.stopPropagation();
  979. }.bind({bingObj : this, target: item, fun : events[e]}));
  980. }
  981. }
  982. },
  983. _getItemAccess: function (item) {
  984. if (item.access && !this.explorer.options[item.access]) {
  985. return false;
  986. } else {
  987. return true;
  988. }
  989. },
  990. _getActionAccess: function (actionData) {
  991. return true;
  992. },
  993. open: function (e) {
  994. //var options = {"documentId": this.data.id }//this.explorer.app.options.application.allowControl};
  995. //this.explorer.app.desktop.openApplication(e, "cms.Document", options);
  996. this.view._openDocument(this.data);
  997. },
  998. remove: function (e) {
  999. var lp = this.lp || this.view.lp || this.app.lp;
  1000. var text = lp.deleteDocument.replace(/{title}/g, this.data.title);
  1001. var _self = this;
  1002. this.node.setStyles(this.css.documentNode_remove);
  1003. this.readyRemove = true;
  1004. this.view.lockNodeStyle = true;
  1005. //this.explorer.app.confirm("warn", e, lp.deleteDocumentTitle, text, 350, 120, function () {
  1006. this.app.confirm("warn", e, lp.deleteDocumentTitle, text, 350, 120, function () {
  1007. //var inputs = this.content.getElements("input");
  1008. //var flag = "";
  1009. //for (var i=0; i<inputs.length; i++){
  1010. // if (inputs[i].checked){
  1011. // flag = inputs[i].get("value");
  1012. // break;
  1013. // }
  1014. //}
  1015. //if (flag){
  1016. //if (flag=="all"){
  1017. //_self.explorer.removeDocument(_self, true);
  1018. //}else{
  1019. _self.view._removeDocument(_self.data, false);
  1020. _self.view.lockNodeStyle = false;
  1021. //}
  1022. this.close();
  1023. //}else{
  1024. // this.content.getElement("#deleteDocument_checkInfor").set("text", lp.deleteAllDocumentCheck).setStyle("color", "red");
  1025. //}
  1026. }, function () {
  1027. _self.node.setStyles(_self.css.documentNode);
  1028. _self.readyRemove = false;
  1029. _self.view.lockNodeStyle = false;
  1030. this.close();
  1031. });
  1032. },
  1033. destroy: function () {
  1034. this.node.destroy();
  1035. //delete this;
  1036. },
  1037. _queryCreateDocumentNode:function( itemData ){
  1038. },
  1039. _postCreateDocumentNode: function( itemNode, itemData ){
  1040. }
  1041. });
  1042. MWF.xApplication.Template.Explorer.Paging = new Class({
  1043. Implements: [Options, Events],
  1044. options : {
  1045. position : ["top","bottom"],
  1046. countPerPage : 20,
  1047. visiblePages : 10,
  1048. currentPage : 1,
  1049. itemSize : 0,
  1050. pageSize : 0,
  1051. hasNextPage : true,
  1052. hasPrevPage : false,
  1053. hasTruningBar : true,
  1054. hasJumper : true,
  1055. hasReturn : true,
  1056. returnText : "",
  1057. hiddenWithDisable: true,
  1058. text : {
  1059. prePage : "",
  1060. nextPage : "",
  1061. firstPage : "",
  1062. lastPage : ""
  1063. }
  1064. },
  1065. initialize: function (topContainer, bottomContainer, options, css) {
  1066. if (!options.returnText) options.returnText = MWF.xApplication.Template.LP.explorer.returnText;
  1067. this.setOptions( options || {});
  1068. this.topContainer = topContainer;
  1069. this.bottomContainer = bottomContainer;
  1070. this.css = css;
  1071. },
  1072. load : function(){
  1073. this.fireEvent( "queryLoad", this);
  1074. this.options.pageSize = Math.ceil(this.options.itemSize/this.options.countPerPage);
  1075. if( ( (this.options.pageSize == 1 || this.options.pageSize == 0) && this.options.hiddenWithDisable ) && !this.options.hasReturn )return;
  1076. if( this.topContainer ){
  1077. this.topContainer.empty();
  1078. if( this.options.hasTruningBar && this.options.position.indexOf("top") > -1 ){
  1079. this.createNode( this.topContainer );
  1080. }
  1081. }
  1082. if( this.bottomContainer ){
  1083. this.bottomContainer.empty();
  1084. if( this.options.hasPrevPage ){
  1085. this.createPrevPageNode( this.bottomContainer );
  1086. }
  1087. if( this.options.hasNextPage ){
  1088. this.createNextPageNode( this.bottomContainer );
  1089. }
  1090. if( this.options.hasTruningBar && this.options.position.indexOf("bottom") > -1 ){
  1091. this.createNode( this.bottomContainer );
  1092. }
  1093. }
  1094. this.fireEvent( "postLoad", this);
  1095. },
  1096. createNode : function( container ){
  1097. var _self = this;
  1098. var visiblePages = this.options.visiblePages;
  1099. var pageSize = this.options.pageSize;
  1100. var currentPage = this.options.currentPage;
  1101. var halfCount = Math.floor( visiblePages / 2);
  1102. var i, max, min;
  1103. if( pageSize <= visiblePages ){
  1104. min = 1;
  1105. max = pageSize;
  1106. }else if( currentPage + halfCount > pageSize ){
  1107. min = pageSize - visiblePages;
  1108. max = pageSize;
  1109. }else if( currentPage - halfCount < 1 ){
  1110. min = 1;
  1111. max = visiblePages;
  1112. }else{
  1113. min = currentPage - halfCount;
  1114. max = currentPage + halfCount;
  1115. }
  1116. var node = this.node = new Element("div.pagingBar", { styles : this.css.pagingBar } ).inject( container );
  1117. if( this.options.hasReturn ){
  1118. var pageReturn = this.pageReturn = new Element( "div.pageReturn" , { styles : this.css.pageReturn , "text" : this.options.returnText } ).inject(node);
  1119. pageReturn.addEvents( {
  1120. "mouseover" : function( ev ){ ev.target.setStyles( this.css.pageReturn_over ) }.bind(this),
  1121. "mouseout" : function( ev ){ ev.target.setStyles( this.css.pageReturn ) }.bind(this),
  1122. "click" : function(){ this.fireEvent( "pageReturn" , this ) }.bind(this)
  1123. })
  1124. }
  1125. if( (pageSize != 1 && pageSize != 0) || !this.options.hiddenWithDisable ){
  1126. if( min > 1 || !this.options.hiddenWithDisable){
  1127. var firstPage = this.firstPage = new Element( "div.firstPage" , { styles : this.css.firstPage, text : "1..." }).inject(node);
  1128. if( this.options.text.firstPage )firstPage.set( "text", this.options.text.firstPage );
  1129. firstPage.addEvents( {
  1130. "mouseover" : function( ev ){ ev.target.setStyles( this.css.firstPage_over ) }.bind(this),
  1131. "mouseout" : function( ev ){ ev.target.setStyles( this.css.firstPage ) }.bind(this),
  1132. "click" : function(){ this.gotoPage(1) }.bind(this)
  1133. } )
  1134. }
  1135. if( currentPage != 1 || !this.options.hiddenWithDisable){
  1136. var prePage = this.prePage = new Element( "div.prePage" , { styles : this.css.prePage } ).inject(node);
  1137. if( this.options.text.prePage )prePage.set( "text", this.options.text.prePage );
  1138. prePage.addEvents( {
  1139. "mouseover" : function( ev ){ ev.target.setStyles( this.css.prePage_over ) }.bind(this),
  1140. "mouseout" : function( ev ){ ev.target.setStyles( this.css.prePage ) }.bind(this),
  1141. "click" : function(){ this.gotoPage( currentPage-1 ) }.bind(this)
  1142. } )
  1143. }
  1144. this.pageTurnNodes = [];
  1145. for( i=min; i<=max; i++ ){
  1146. if( currentPage == i ){
  1147. this.currentPage = new Element("div.currentPage", {"styles" : this.css.currentPage, "text" : i }).inject(node);
  1148. }else{
  1149. var pageTurnNode = new Element("div.pageItem", {"styles" : this.css.pageItem, "text" : i }).inject(node);
  1150. pageTurnNode.addEvents( {
  1151. "mouseover" : function( ev ){ ev.target.setStyles( this.css.pageItem_over ) }.bind(this),
  1152. "mouseout" : function( ev ){ ev.target.setStyles( this.css.pageItem ) }.bind(this),
  1153. "click" : function(){ this.obj.gotoPage( this.num ) }.bind({ obj : this, num : i })
  1154. });
  1155. this.pageTurnNodes.push( pageTurnNode );
  1156. }
  1157. }
  1158. if( this.options.hasJumper ){
  1159. var pageJumper = this.pageJumper = new Element("input.pageJumper", {"styles" : this.css.pageJumper , "title" : MWF.xApplication.Template.LP.explorer.pageJumperText }).inject( node );
  1160. new Element( "div.pageText", {"styles" : this.css.pageText , "text" : "/" + pageSize }).inject( node );
  1161. pageJumper.addEvents( {
  1162. "focus" : function( ev ){ ev.target.setStyles( this.css.pageJumper_over ) }.bind(this),
  1163. "blur" : function( ev ){ ev.target.setStyles( this.css.pageJumper ) }.bind(this),
  1164. "keyup" : function(e){
  1165. this.value=this.value.replace(/[^0-9_]/g,'')
  1166. },
  1167. "keydown" : function(e){
  1168. if(e.code==13 && this.value!="" ){
  1169. _self.gotoPage( this.value );
  1170. e.stopPropagation();
  1171. //e.preventDefault();
  1172. }
  1173. }
  1174. });
  1175. }
  1176. if( currentPage != pageSize || !this.options.hiddenWithDisable){
  1177. var nextPage = this.nextPage = new Element( "div.nextPage" , { styles : this.css.nextPage } ).inject(node);
  1178. if( this.options.text.nextPage )nextPage.set( "text", this.options.text.nextPage );
  1179. nextPage.addEvents( {
  1180. "mouseover" : function( ev ){ ev.target.setStyles( this.css.nextPage_over ) }.bind(this),
  1181. "mouseout" : function( ev ){ ev.target.setStyles( this.css.nextPage ) }.bind(this),
  1182. "click" : function(){ this.gotoPage( currentPage+1 ) }.bind(this)
  1183. } )
  1184. }
  1185. if( max < pageSize || !this.options.hiddenWithDisable){
  1186. var lastPage = this.lastPage = new Element( "div.lastPage" , { styles : this.css.lastPage, text : "..." + pageSize }).inject(node);
  1187. if( this.options.text.lastPage )lastPage.set( "text", this.options.text.lastPage );
  1188. lastPage.addEvents( {
  1189. "mouseover" : function( ev ){ ev.target.setStyles( this.css.lastPage_over ) }.bind(this),
  1190. "mouseout" : function( ev ){ ev.target.setStyles( this.css.lastPage ) }.bind(this),
  1191. "click" : function(){ this.gotoPage( pageSize ) }.bind(this)
  1192. } )
  1193. }
  1194. }
  1195. },
  1196. createNextPageNode : function( container ){
  1197. if( this.nextPageNode ){
  1198. this.nextPageNode.destroy();
  1199. delete this.nextPageNode;
  1200. }
  1201. var pageSize = this.options.pageSize;
  1202. if( this.options.currentPage != pageSize && pageSize != 1 && pageSize != 0 ){
  1203. this.nextPageNode = new Element("div.nextPageNode", {
  1204. "styles" : this.css.nextPageNode,
  1205. "text" : MWF.xApplication.Template.LP.explorer.nextPage
  1206. }).inject(container);
  1207. this.nextPageNode.addEvents( {
  1208. "mouseover" : function( ev ){ ev.target.setStyles( this.css.nextPageNode_over ) }.bind(this),
  1209. "mouseout" : function( ev ){ ev.target.setStyles( this.css.nextPageNode ) }.bind(this),
  1210. "click" : function(){ this.gotoPage( this.options.currentPage+1 ) }.bind(this)
  1211. })
  1212. }
  1213. },
  1214. createPrevPageNode : function( container ){
  1215. if( this.prevPageNode ){
  1216. this.prevPageNode.destroy();
  1217. delete this.prevPageNode;
  1218. }
  1219. var pageSize = this.options.pageSize;
  1220. if( this.options.currentPage != 1 && pageSize != 1 && pageSize != 0 ){
  1221. this.prevPageNode = new Element("div.prevPageNode", {
  1222. "styles" : this.css.prevPageNode,
  1223. "text" : MWF.xApplication.Template.LP.explorer.prePage
  1224. }).inject(container);
  1225. this.prevPageNode.addEvents( {
  1226. "mouseover" : function( ev ){ ev.target.setStyles( this.css.prevPageNode_over ) }.bind(this),
  1227. "mouseout" : function( ev ){ ev.target.setStyles( this.css.prevPageNode ) }.bind(this),
  1228. "click" : function(){ this.gotoPage( this.options.currentPage-1 ) }.bind(this)
  1229. })
  1230. }
  1231. },
  1232. gotoPage : function( num ){
  1233. if(o2.typeOf(num) === "string")num = num.toInt();
  1234. if( num < 1 || num > this.options.pageSize )return;
  1235. this.fireEvent( "jumpingPage", { pageNum : num } );
  1236. this.options.currentPage = num;
  1237. this.load();
  1238. },
  1239. gotoItem : function( itemNum ){
  1240. var pageNum = Math.ceil( itemNum / this.options.countPerPage );
  1241. var index = itemNum % this.options.countPerPage;
  1242. this.fireEvent( "jumpingPage", { pageNum : pageNum, itemNum : itemNum, index : index } );
  1243. this.options.currentPage = pageNum;
  1244. this.load();
  1245. },
  1246. destroy : function(){
  1247. if( this.nextPageNode )this.nextPageNode.destroy();
  1248. //delete this;
  1249. }
  1250. });
  1251. //MWF.xApplication.Template.Explorer.PopupForm = new Class({
  1252. // Extends: MPopupForm
  1253. //});