Explorer.js 51 KB

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