Explorer.js 57 KB

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