Explorer.js 50 KB

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