Explorer.js 49 KB

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