Explorer.js 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496
  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.cssPath = "/x_component_Template/$PopupForm/"+this.options.style+"/css.wcss";
  874. this.load();
  875. },
  876. load: function () {
  877. this._loadCss();
  878. },
  879. _loadCss: function(){
  880. var css = {};
  881. var r = new Request.JSON({
  882. url: this.cssPath,
  883. secure: false,
  884. async: false,
  885. method: "get",
  886. noCache: false,
  887. onSuccess: function(responseJSON, responseText){
  888. css = responseJSON;
  889. MWF.widget.css[key] = responseJSON;
  890. }.bind(this),
  891. onError: function(text, error){
  892. alert(error + text);
  893. }
  894. });
  895. r.send();
  896. var isEmptyObject = true;
  897. for( var key in css ){
  898. if(key)isEmptyObject = false
  899. }
  900. if( !isEmptyObject ){
  901. this.css = Object.merge( css, this.css );
  902. }
  903. },
  904. open: function (e) {
  905. this.fireEvent("queryOpen");
  906. this.isNew = false;
  907. this.isEdited = false;
  908. this._open();
  909. this.fireEvent("postOpen");
  910. },
  911. create: function () {
  912. this.fireEvent("queryCreate");
  913. this.isNew = true;
  914. this._open();
  915. this.fireEvent("postCreate");
  916. },
  917. edit: function () {
  918. this.fireEvent("queryEdit");
  919. this.isEdited = true;
  920. this._open();
  921. this.fireEvent("postEdit");
  922. },
  923. _open: function () {
  924. if( this.options.hasMark ){
  925. this.formMarkNode = new Element("div.formMarkNode", {
  926. "styles": this.css.formMarkNode,
  927. "events": {
  928. "mouseover": function (e) {
  929. e.stopPropagation();
  930. },
  931. "mouseout": function (e) {
  932. e.stopPropagation();
  933. },
  934. "click": function (e) {
  935. e.stopPropagation();
  936. }
  937. }
  938. }).inject( this.container || this.app.content);
  939. }
  940. this.formAreaNode = new Element("div.formAreaNode", {
  941. "styles": this.css.formAreaNode
  942. });
  943. this.createFormNode();
  944. this.formAreaNode.inject(this.formMarkNode || this.container || this.app.content, "after");
  945. this.formAreaNode.fade("in");
  946. this.setFormNodeSize();
  947. this.setFormNodeSizeFun = this.setFormNodeSize.bind(this);
  948. if( this.app )this.app.addEvent("resize", this.setFormNodeSizeFun);
  949. if (this.options.draggable && this.formTopNode) {
  950. var size = (this.container || this.app.content).getSize();
  951. var nodeSize = this.formAreaNode.getSize();
  952. this.formAreaNode.makeDraggable({
  953. "handle": this.formTopNode,
  954. "limit": {
  955. "x": [0, size.x - nodeSize.x],
  956. "y": [0, size.y - nodeSize.y]
  957. }
  958. });
  959. }
  960. },
  961. createFormNode: function () {
  962. var _self = this;
  963. this.formNode = new Element("div.formNode", {
  964. "styles": this.css.formNode
  965. }).inject(this.formAreaNode);
  966. if (this.options.hasTop) {
  967. this.createTopNode();
  968. }
  969. if (this.options.hasIcon) {
  970. this.formIconNode = new Element("div.formIconNode", {
  971. "styles": this.isNew ? this.css.formNewNode : this.css.formIconNode
  972. }).inject(this.formNode);
  973. }
  974. this.createContent();
  975. //formContentNode.set("html", html);
  976. if (this.options.hasBottom) {
  977. this.createBottomNode();
  978. }
  979. this._setCustom();
  980. if( this.options.hasScroll ){
  981. //this.setScrollBar(this.formTableContainer)
  982. MWF.require("MWF.widget.ScrollBar", function () {
  983. new MWF.widget.ScrollBar(this.formTableContainer, {
  984. "indent": false,
  985. "style": "xApp_TaskList",
  986. "where": "before",
  987. "distance": 30,
  988. "friction": 4,
  989. "axis": {"x": false, "y": true},
  990. "onScroll": function (y) {
  991. //var scrollSize = _self.viewContainerNode.getScrollSize();
  992. //var clientSize = _self.viewContainerNode.getSize();
  993. //var scrollHeight = scrollSize.y - clientSize.y;
  994. //if (y + 200 > scrollHeight && _self.view && _self.view.loadElementList) {
  995. // if (!_self.view.isItemsLoaded) _self.view.loadElementList();
  996. //}
  997. }
  998. });
  999. }.bind(this));
  1000. }
  1001. },
  1002. _setCustom : function(){
  1003. },
  1004. createTopNode: function () {
  1005. if (!this.formTopNode) {
  1006. this.formTopNode = new Element("div.formTopNode", {
  1007. "styles": this.css.formTopNode
  1008. }).inject(this.formNode);
  1009. if(this.options.hasTopIcon){
  1010. this.formTopIconNode = new Element("div", {
  1011. "styles": this.css.formTopIconNode
  1012. }).inject(this.formTopNode)
  1013. }
  1014. this.formTopTextNode = new Element("div", {
  1015. "styles": this.css.formTopTextNode,
  1016. "text": this.options.title
  1017. }).inject(this.formTopNode);
  1018. if (this.options.closeAction) {
  1019. this.formTopCloseActionNode = new Element("div", {"styles": this.css.formTopCloseActionNode}).inject(this.formTopNode);
  1020. this.formTopCloseActionNode.addEvent("click", function () {
  1021. this.close()
  1022. }.bind(this))
  1023. }
  1024. if(this.options.hasTopContent){
  1025. this.formTopContentNode = new Element("div.formTopContentNode", {
  1026. "styles": this.css.formTopContentNode
  1027. }).inject(this.formTopNode);
  1028. this._createTopContent();
  1029. }
  1030. }
  1031. //if (!this.formTopNode) {
  1032. // this.formTopNode = new Element("div.formTopNode", {
  1033. // "styles": this.css.formTopNode,
  1034. // "text": this.options.title
  1035. // }).inject(this.formNode);
  1036. //
  1037. // this._createTopContent();
  1038. //
  1039. // if (this.options.closeAction) {
  1040. // this.formTopCloseActionNode = new Element("div.formTopCloseActionNode", {"styles": this.css.formTopCloseActionNode}).inject(this.formTopNode);
  1041. // this.formTopCloseActionNode.addEvent("click", function () {
  1042. // this.close()
  1043. // }.bind(this))
  1044. // }
  1045. //}
  1046. },
  1047. _createTopContent: function () {
  1048. },
  1049. createContent: function () {
  1050. this.formContentNode = new Element("div.formContentNode", {
  1051. "styles": this.css.formContentNode
  1052. }).inject(this.formNode);
  1053. this.formTableContainer = new Element("div.formTableContainer", {
  1054. "styles": this.css.formTableContainer
  1055. }).inject(this.formContentNode);
  1056. this.formTableArea = new Element("div.formTableArea", {
  1057. "styles": this.css.formTableArea
  1058. }).inject(this.formTableContainer);
  1059. this._createTableContent();
  1060. },
  1061. _createTableContent: function () {
  1062. var html = "<table width='100%' bordr='0' cellpadding='5' cellspacing='0' styles='formTable'>" +
  1063. //"<tr><td colspan='2' styles='formTableHead'>申诉处理单</td></tr>" +
  1064. "<tr><td styles='formTableTitle' lable='empName'></td>" +
  1065. " <td styles='formTableValue' item='empName'></td></tr>" +
  1066. "<tr><td styles='formTableTitle' lable='departmentName'></td>" +
  1067. " <td styles='formTableValue' item='departmentName'></td></tr>" +
  1068. "<tr><td styles='formTableTitle' lable='recordDateString'></td>" +
  1069. " <td styles='formTableValue' item='recordDateString'></td></tr>" +
  1070. "<tr><td styles='formTableTitle' lable='status'></td>" +
  1071. " <td styles='formTableValue' item='status'></td></tr>" +
  1072. "<tr><td styles='formTableTitle' lable='appealReason'></td>" +
  1073. " <td styles='formTableValue' item='appealReason'></td></tr>" +
  1074. "<tr><td styles='formTableTitle' lable='appealDescription'></td>" +
  1075. " <td styles='formTableValue' item='appealDescription'></td></tr>" +
  1076. "<tr><td styles='formTableTitle' lable='opinion1'></td>" +
  1077. " <td styles='formTableValue' item='opinion1'></td></tr>" +
  1078. "</table>"
  1079. this.formTableArea.set("html", html);
  1080. MWF.xDesktop.requireApp("Template", "MForm", function () {
  1081. this.form = new MForm(this.formTableArea, {empName: "xadmin"}, {
  1082. isEdited: this.isEdited || this.isNew,
  1083. itemTemplate: {
  1084. empName: {text: "姓名", type: "innertext"},
  1085. departmentName: {text: "部门", tType: "department", notEmpty: true},
  1086. recordDateString: {text: "日期", tType: "date"},
  1087. status: {text: "状态", tType: "number"},
  1088. appealReason: {
  1089. text: "下拉框",
  1090. type: "select",
  1091. selectValue: ["测试1", "测试2"]
  1092. },
  1093. appealDescription: {text: "描述", type: "textarea"},
  1094. opinion1: {text: "测试", type: "button", "value": "测试"}
  1095. }
  1096. }, this.app);
  1097. this.form.load();
  1098. }.bind(this), true);
  1099. },
  1100. createBottomNode: function () {
  1101. this.formBottomNode = new Element("div.formBottomNode", {
  1102. "styles": this.css.formBottomNode
  1103. }).inject(this.formNode);
  1104. this._createBottomContent()
  1105. },
  1106. _createBottomContent: function () {
  1107. this.cancelActionNode = new Element("div.formCancelActionNode", {
  1108. "styles": this.css.formCancelActionNode,
  1109. "text": this.lp.cancel
  1110. }).inject(this.formBottomNode);
  1111. this.cancelActionNode.addEvent("click", function (e) {
  1112. this.cancel(e);
  1113. }.bind(this));
  1114. if (this.isNew || this.isEdited) {
  1115. this.okActionNode = new Element("div.formOkActionNode", {
  1116. "styles": this.css.formOkActionNode,
  1117. "text": this.lp.ok
  1118. }).inject(this.formBottomNode);
  1119. this.okActionNode.addEvent("click", function (e) {
  1120. this.ok(e);
  1121. }.bind(this));
  1122. }
  1123. },
  1124. cancel: function (e) {
  1125. this.fireEvent("queryCancel");
  1126. this.close();
  1127. this.fireEvent("postCancel");
  1128. },
  1129. close: function (e) {
  1130. this.fireEvent("queryClose");
  1131. this._close();
  1132. if(this.setFormNodeSizeFun && this.app ){
  1133. this.app.removeEvent("resize",this.setFormNodeSizeFun);
  1134. }
  1135. if( this.formMarkNode )this.formMarkNode.destroy();
  1136. this.formAreaNode.destroy();
  1137. this.fireEvent("postClose");
  1138. delete this;
  1139. },
  1140. _close: function(){
  1141. },
  1142. ok: function (e) {
  1143. this.fireEvent("queryOk");
  1144. var data = this.form.getResult(true, ",", true, false, true);
  1145. if (data) {
  1146. this._ok(data, function (json) {
  1147. if (json.type == "error") {
  1148. if( this.app )this.app.notice(json.message, "error");
  1149. } else {
  1150. if( this.formMarkNode )this.formMarkNode.destroy();
  1151. this.formAreaNode.destroy();
  1152. if (this.explorer && this.explorer.view)this.explorer.view.reload();
  1153. if( this.app )this.app.notice(this.isNew ? this.lp.createSuccess : this.lp.updateSuccess, "success");
  1154. this.fireEvent("postOk");
  1155. }
  1156. }.bind(this))
  1157. }
  1158. },
  1159. _ok: function (data, callback) {
  1160. //this.app.restActions.saveDocument( this.data.id, data, function(json){
  1161. // if( callback )callback(json);
  1162. //}.bind(this), function( errorObj ){
  1163. // var error = JSON.parse( errorObj.responseText );
  1164. // this.app.notice( error.message, error );
  1165. //}.bind(this));
  1166. },
  1167. setFormNodeSize: function (width, height, top, left) {
  1168. if (!width)width = this.options.width ? this.options.width : "50%";
  1169. if (!height)height = this.options.height ? this.options.height : "50%";
  1170. if (!top) top = this.options.top ? this.options.top : 0;
  1171. if (!left) left = this.options.left ? this.options.left : 0;
  1172. //var appTitleSize = this.app.window.title.getSize();
  1173. var allSize = ( this.container || this.app.content).getSize();
  1174. var limitWidth = allSize.x; //window.screen.width
  1175. var limitHeight = allSize.y; //window.screen.height
  1176. "string" == typeof width && (1 < width.length && "%" == width.substr(width.length - 1, 1)) && (width = parseInt(limitWidth * parseInt(width, 10) / 100, 10));
  1177. "string" == typeof height && (1 < height.length && "%" == height.substr(height.length - 1, 1)) && (height = parseInt(limitHeight * parseInt(height, 10) / 100, 10));
  1178. 300 > width && (width = 300);
  1179. 220 > height && (height = 220);
  1180. top = top || parseInt((limitHeight - height) / 2, 10); //+appTitleSize.y);
  1181. left = left || parseInt((limitWidth - width) / 2, 10);
  1182. this.formAreaNode.setStyles({
  1183. "width": "" + width + "px",
  1184. "height": "" + height + "px",
  1185. "top": "" + top + "px",
  1186. "left": "" + left + "px"
  1187. });
  1188. this.formNode.setStyles({
  1189. "width": "" + width + "px",
  1190. "height": "" + height + "px"
  1191. });
  1192. var iconSize = this.formIconNode ? this.formIconNode.getSize() : {x: 0, y: 0};
  1193. var topSize = this.formTopNode ? this.formTopNode.getSize() : {x: 0, y: 0};
  1194. var bottomSize = this.formBottomNode ? this.formBottomNode.getSize() : {x: 0, y: 0};
  1195. var contentHeight = height - iconSize.y - topSize.y - bottomSize.y;
  1196. //var formMargin = formHeight -iconSize.y;
  1197. this.formContentNode.setStyles({
  1198. "height": "" + contentHeight + "px"
  1199. });
  1200. this.formTableContainer.setStyles({
  1201. "height": "" + contentHeight + "px"
  1202. });
  1203. }
  1204. });
  1205. MWF.xApplication.Template.Explorer.Paging = new Class({
  1206. Implements: [Options, Events],
  1207. options : {
  1208. position : ["top","bottom"],
  1209. countPerPage : 20,
  1210. visiblePages : 10,
  1211. currentPage : 1,
  1212. itemSize : 0,
  1213. pageSize : 0,
  1214. hasNextPage : true,
  1215. hasPrevPage : false,
  1216. hasTruningBar : true,
  1217. hasReturn : true,
  1218. returnText : "返回首页"
  1219. },
  1220. initialize: function (topContainer, bottomContainer, options, css) {
  1221. this.setOptions( options || {});
  1222. this.topContainer = topContainer;
  1223. this.bottomContainer = bottomContainer;
  1224. this.css = css;
  1225. },
  1226. load : function(){
  1227. this.fireEvent( "queryLoad", this);
  1228. this.options.pageSize = Math.ceil(this.options.itemSize/this.options.countPerPage);
  1229. if( (this.options.pageSize == 1 || this.options.pageSize == 0) && !this.options.hasReturn )return;
  1230. if( this.topContainer ){
  1231. this.topContainer.empty();
  1232. if( this.options.hasTruningBar && this.options.position.indexOf("top") > -1 ){
  1233. this.createNode( this.topContainer );
  1234. }
  1235. }
  1236. if( this.bottomContainer ){
  1237. this.bottomContainer.empty();
  1238. if( this.options.hasPrevPage ){
  1239. this.createPrevPageNode( this.bottomContainer );
  1240. }
  1241. if( this.options.hasNextPage ){
  1242. this.createNextPageNode( this.bottomContainer );
  1243. }
  1244. if( this.options.hasTruningBar && this.options.position.indexOf("bottom") > -1 ){
  1245. this.createNode( this.bottomContainer );
  1246. }
  1247. }
  1248. this.fireEvent( "postLoad", this);
  1249. },
  1250. createNode : function( container ){
  1251. var _self = this;
  1252. var visiblePages = this.options.visiblePages;
  1253. var pageSize = this.options.pageSize;
  1254. var currentPage = this.options.currentPage;
  1255. var halfCount = Math.floor( visiblePages / 2);
  1256. var i, max, min;
  1257. if( pageSize <= visiblePages ){
  1258. min = 1;
  1259. max = pageSize;
  1260. }else if( currentPage + halfCount > pageSize ){
  1261. min = pageSize - visiblePages;
  1262. max = pageSize;
  1263. }else if( currentPage - halfCount < 1 ){
  1264. min = 1;
  1265. max = visiblePages;
  1266. }else{
  1267. min = currentPage - halfCount;
  1268. max = currentPage + halfCount;
  1269. }
  1270. var node = new Element("div.pagingBar", { styles : this.css.pagingBar } ).inject( container );
  1271. if( this.options.hasReturn ){
  1272. var pageReturn = new Element( "div.pageReturn" , { styles : this.css.pageReturn , "text" : this.options.returnText } ).inject(node);
  1273. pageReturn.addEvents( {
  1274. "mouseover" : function( ev ){ ev.target.setStyles( this.css.pageReturn_over ) }.bind(this),
  1275. "mouseout" : function( ev ){ ev.target.setStyles( this.css.pageReturn ) }.bind(this),
  1276. "click" : function(){ this.fireEvent( "pageReturn" , this ) }.bind(this)
  1277. })
  1278. }
  1279. if( pageSize != 1 && pageSize != 0 ){
  1280. if( currentPage != 1 ){
  1281. var prePage = new Element( "div.prePage" , { styles : this.css.prePage } ).inject(node);
  1282. prePage.addEvents( {
  1283. "mouseover" : function( ev ){ ev.target.setStyles( this.css.prePage_over ) }.bind(this),
  1284. "mouseout" : function( ev ){ ev.target.setStyles( this.css.prePage ) }.bind(this),
  1285. "click" : function(){ this.gotoPage( currentPage-1 ) }.bind(this)
  1286. } )
  1287. }
  1288. if( min > 1 ){
  1289. var firstPage = new Element( "div.pageItem" , { styles : this.css.pageItem, text : "1..." }).inject(node);
  1290. firstPage.addEvents( {
  1291. "mouseover" : function( ev ){ ev.target.setStyles( this.css.pageItem_over ) }.bind(this),
  1292. "mouseout" : function( ev ){ ev.target.setStyles( this.css.pageItem ) }.bind(this),
  1293. "click" : function(){ this.gotoPage(1) }.bind(this)
  1294. } )
  1295. }
  1296. for( i=min; i<=max; i++ ){
  1297. if( currentPage == i ){
  1298. new Element("div.currentPage", {"styles" : this.css.currentPage, "text" : i }).inject(node);
  1299. }else{
  1300. var pageTurnNode = new Element("div.pageItem", {"styles" : this.css.pageItem, "text" : i }).inject(node);
  1301. pageTurnNode.addEvents( {
  1302. "mouseover" : function( ev ){ ev.target.setStyles( this.css.pageItem_over ) }.bind(this),
  1303. "mouseout" : function( ev ){ ev.target.setStyles( this.css.pageItem ) }.bind(this),
  1304. "click" : function(){ this.obj.gotoPage( this.num ) }.bind({ obj : this, num : i })
  1305. })
  1306. }
  1307. }
  1308. var pageJumper = new Element("input.pageJumper", {"styles" : this.css.pageJumper , "title" : "输入页码,按回车跳转"}).inject( node );
  1309. new Element( "div.pageText", {"styles" : this.css.pageText , "text" : "/" + pageSize }).inject( node );
  1310. pageJumper.addEvents( {
  1311. "focus" : function( ev ){ ev.target.setStyles( this.css.pageJumper_over ) }.bind(this),
  1312. "blur" : function( ev ){ ev.target.setStyles( this.css.pageJumper ) }.bind(this),
  1313. "keyup" : function(e){
  1314. this.value=this.value.replace(/[^0-9_]/g,'')
  1315. },
  1316. "keydown" : function(e){
  1317. if(e.code==13 && this.value!="" ){
  1318. _self.gotoPage( this.value );
  1319. e.stopPropagation();
  1320. //e.preventDefault();
  1321. }
  1322. }
  1323. });
  1324. if( max < pageSize ){
  1325. var lastPage = new Element( "div.pageItem" , { styles : this.css.pageItem, text : "..." + pageSize }).inject(node);
  1326. lastPage.addEvents( {
  1327. "mouseover" : function( ev ){ ev.target.setStyles( this.css.pageItem_over ) }.bind(this),
  1328. "mouseout" : function( ev ){ ev.target.setStyles( this.css.pageItem ) }.bind(this),
  1329. "click" : function(){ this.gotoPage( pageSize ) }.bind(this)
  1330. } )
  1331. }
  1332. if( currentPage != pageSize ){
  1333. var nextPage = new Element( "div.nextPage" , { styles : this.css.nextPage } ).inject(node);
  1334. nextPage.addEvents( {
  1335. "mouseover" : function( ev ){ ev.target.setStyles( this.css.nextPage_over ) }.bind(this),
  1336. "mouseout" : function( ev ){ ev.target.setStyles( this.css.nextPage ) }.bind(this),
  1337. "click" : function(){ this.gotoPage( currentPage+1 ) }.bind(this)
  1338. } )
  1339. }
  1340. }
  1341. },
  1342. createNextPageNode : function( container ){
  1343. if( this.nextPageNode ){
  1344. this.nextPageNode.destroy();
  1345. delete this.nextPageNode;
  1346. }
  1347. var pageSize = this.options.pageSize;
  1348. if( this.options.currentPage != pageSize && pageSize != 1 && pageSize != 0 ){
  1349. this.nextPageNode = new Element("div.nextPageNode", {
  1350. "styles" : this.css.nextPageNode,
  1351. "text" : "下一页"
  1352. }).inject(container);
  1353. this.nextPageNode.addEvents( {
  1354. "mouseover" : function( ev ){ ev.target.setStyles( this.css.nextPageNode_over ) }.bind(this),
  1355. "mouseout" : function( ev ){ ev.target.setStyles( this.css.nextPageNode ) }.bind(this),
  1356. "click" : function(){ this.gotoPage( this.options.currentPage+1 ) }.bind(this)
  1357. })
  1358. }
  1359. },
  1360. createPrevPageNode : function( container ){
  1361. if( this.prevPageNode ){
  1362. this.prevPageNode.destroy();
  1363. delete this.prevPageNode;
  1364. }
  1365. var pageSize = this.options.pageSize;
  1366. if( this.options.currentPage != 1 && pageSize != 1 && pageSize != 0 ){
  1367. this.prevPageNode = new Element("div.prevPageNode", {
  1368. "styles" : this.css.prevPageNode,
  1369. "text" : "上一页"
  1370. }).inject(container);
  1371. this.prevPageNode.addEvents( {
  1372. "mouseover" : function( ev ){ ev.target.setStyles( this.css.prevPageNode_over ) }.bind(this),
  1373. "mouseout" : function( ev ){ ev.target.setStyles( this.css.prevPageNode ) }.bind(this),
  1374. "click" : function(){ this.gotoPage( this.options.currentPage-1 ) }.bind(this)
  1375. })
  1376. }
  1377. },
  1378. gotoPage : function( num ){
  1379. this.fireEvent( "jumpingPage", { pageNum : num } );
  1380. this.options.currentPage = num;
  1381. this.load();
  1382. },
  1383. gotoItem : function( itemNum ){
  1384. var pageNum = Math.ceil( itemNum / this.options.countPerPage );
  1385. var index = itemNum % this.options.countPerPage;
  1386. this.fireEvent( "jumpingPage", { pageNum : pageNum, itemNum : itemNum, index : index } );
  1387. this.options.currentPage = pageNum;
  1388. this.load();
  1389. },
  1390. destroy : function(){
  1391. if( this.nextPageNode )this.nextPageNode.destroy();
  1392. delete this;
  1393. }
  1394. });