Explorer.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  1. MWF.xApplication.Attendance = MWF.xApplication.Attendance || {};
  2. MWF.require("MWF.xAction.org.express.RestActions", null,false);
  3. MWF.require("MWF.widget.Identity", null,false);
  4. MWF.xDesktop.requireApp("Attendance", "lp."+MWF.language, null, false);
  5. MWF.xApplication.Attendance.Explorer = new Class({
  6. Extends: MWF.widget.Common,
  7. Implements: [Options, Events],
  8. options: {
  9. "style": "default",
  10. "isAdmin": false,
  11. "searchKey" : ""
  12. },
  13. initialize: function(node, app, actions, options){
  14. this.setOptions(options);
  15. this.app = app;
  16. this.path = "/x_component_Attendance/$Explorer/";
  17. this.cssPath = "/x_component_Attendance/$Explorer/"+this.options.style+"/css.wcss";
  18. this._loadCss();
  19. this.actions = actions;
  20. this.node = $(node);
  21. this.initData();
  22. if (!this.personActions) this.personActions = new MWF.xAction.org.express.RestActions();
  23. },
  24. initData: function(){
  25. this.toolItemNodes = [];
  26. },
  27. reload: function(){
  28. this.node.empty();
  29. this.load();
  30. },
  31. load: function(){
  32. this.loadToolbar();
  33. this.loadContentNode();
  34. this.loadView();
  35. this.setNodeScroll();
  36. },
  37. destroy : function(){
  38. this.node.empty();
  39. delete this;
  40. },
  41. loadToolbar: function(){
  42. this.toolbarNode = new Element("div", {"styles": this.css.toolbarNode});
  43. this.toolbarNode.inject(this.node);
  44. var toolbarUrl = this.path+"toolbar.json";
  45. MWF.getJSON(toolbarUrl, function(json){
  46. json.each(function(tool){
  47. this.createToolbarItemNode(tool);
  48. }.bind(this));
  49. }.bind(this));
  50. //this.createSearchElementNode();
  51. },
  52. createToolbarItemNode : function( tool ){
  53. var toolItemNode = new Element("div", {
  54. "styles": (tool.styles && this.css[tool.styles]) ? this.css[tool.styles] : this.css.toolbarItemNode
  55. });
  56. if( tool.id ){
  57. toolItemNode.set( 'name' , tool.id );
  58. }
  59. toolItemNode.store("toolData", tool );
  60. if( tool.icon ){
  61. var iconNode = new Element("div", {
  62. "styles": this.css.toolbarItemIconNode
  63. }).inject(toolItemNode);
  64. iconNode.setStyle("background-image", "url("+this.path+this.options.style+"/icon/"+tool.icon+")");
  65. }
  66. if( tool.title ){
  67. var textNode = new Element("div", {
  68. "styles": this.css.toolbarItemTextNode,
  69. "text": tool.title
  70. });
  71. if( tool.text )textNode.set("title", tool.text);
  72. textNode.inject(toolItemNode);
  73. }
  74. toolItemNode.inject(this.toolbarNode);
  75. this.toolItemNodes.push(toolItemNode);
  76. this.setToolbarItemEvent(toolItemNode);
  77. },
  78. setToolbarItemEvent:function(toolItemNode){
  79. var _self = this;
  80. toolItemNode.addEvents({
  81. "click": function () {
  82. var data = this.retrieve("toolData");
  83. if( _self[data.action] )_self[data.action].apply(_self,[this]);
  84. }
  85. })
  86. },
  87. loadContentNode: function(){
  88. this.elementContentNode = new Element("div.elementContentNode", {
  89. "styles": this.css.elementContentNode
  90. }).inject(this.node);
  91. this.app.addEvent("resize", function(){this.setContentSize();}.bind(this));
  92. },
  93. loadView : function(){
  94. this.view = new MWF.xApplication.Attendance.Explorer.View(this.elementContentNode, this.app,this, this.viewData, this.options.searchKey );
  95. this.view.load();
  96. this.setContentSize();
  97. },
  98. setContentSize: function(){
  99. var toolbarSize = this.toolbarNode ? this.toolbarNode.getSize() : {"x":0,"y":0};
  100. var titlebarSize = this.app.titleBar ? this.app.titleBar.getSize() : {"x":0,"y":0};
  101. var nodeSize = this.node.getSize();
  102. var pt = this.elementContentNode.getStyle("padding-top").toFloat();
  103. var pb = this.elementContentNode.getStyle("padding-bottom").toFloat();
  104. //var filterSize = this.filterNode.getSize();
  105. var filterConditionSize = this.filterConditionNode ? this.filterConditionNode.getSize() : {"x":0,"y":0};
  106. var height = nodeSize.y-toolbarSize.y-pt-pb-filterConditionSize.y-titlebarSize.y;
  107. this.elementContentNode.setStyle("height", ""+height+"px");
  108. this.pageCount = (height/30).toInt()+5;
  109. this._setContentSize();
  110. if (this.view && this.view.items.length<this.pageCount){
  111. this.view.loadElementList(this.pageCount-this.view.items.length);
  112. }
  113. },
  114. _setContentSize: function(){
  115. },
  116. setNodeScroll: function(){
  117. var _self = this;
  118. MWF.require("MWF.widget.ScrollBar", function(){
  119. new MWF.widget.ScrollBar(this.elementContentNode, {
  120. "indent": false,"style":"xApp_TaskList", "where": "before", "distance": 30, "friction": 4, "axis": {"x": false, "y": true},
  121. "onScroll": function(y){
  122. var scrollSize = _self.elementContentNode.getScrollSize();
  123. var clientSize = _self.elementContentNode.getSize();
  124. var scrollHeight = scrollSize.y-clientSize.y;
  125. if (y+200>scrollHeight) {
  126. if (!_self.view.isItemsLoaded) _self.view.loadElementList();
  127. }
  128. }
  129. });
  130. }.bind(this));
  131. }
  132. });
  133. MWF.xApplication.Attendance.Explorer.View = new Class({
  134. initialize: function( container, app,explorer, searchKey ){
  135. this.container = container;
  136. this.app = app;
  137. this.explorer = explorer;
  138. this.css = explorer.css;
  139. this.actions = explorer.actions;
  140. this.searchKey = searchKey;
  141. this.listItemUrl = this.explorer.path+"listItem.json";
  142. },
  143. initData: function(){
  144. this.items=[];
  145. this.documents = {};
  146. this.isItemsLoaded = false;
  147. this.isItemLoadding = false;
  148. this.loadItemQueue = 0;
  149. this.count = 0;
  150. //this.controllers =[];
  151. },
  152. load : function(){
  153. this.initData();
  154. this.node = new Element("div", {
  155. "styles": this.css.elementContentListNode
  156. }).inject(this.container);
  157. this.table = new Element("table",{ "width" : "100%", "border" : "0", "cellpadding" : "5", "cellspacing" : "0", "class" : "editTable"}).inject(this.node);
  158. this.initSortData();
  159. this.createListHead();
  160. this.loadElementList();
  161. },
  162. initSortData : function(){
  163. this.sortField = null;
  164. this.sortType = null;
  165. this.sortFieldDefault = null;
  166. this.sortTypeDefault = null;
  167. },
  168. clear: function(){
  169. this.documents = null;
  170. MWF.release(this.items);
  171. this.items=[];
  172. this.documents = {};
  173. this.container.empty();
  174. this.isItemsLoaded = false;
  175. this.isItemLoadding = false;
  176. this.loadItemQueue = 0;
  177. //this.count = 0;
  178. },
  179. reload: function(){
  180. this.clear();
  181. this.node = new Element("div", {
  182. "styles": this.css.elementContentListNode
  183. }).inject(this.container);
  184. this.table = new Element("table",{ "width" : "100%", "border" : "0", "cellpadding" : "5", "cellspacing" : "0", "class" : "editTable"}).inject(this.node);
  185. this.createListHead();
  186. this.loadElementList();
  187. },
  188. resort : function(th){
  189. this.sortField = th.retrieve("sortField");
  190. var sortType = th.retrieve("sortType");
  191. //th.eliminate(sortType);
  192. if( sortType == "" ){
  193. this.sortType = "asc";
  194. }else if( this.sortType == "asc" ){
  195. this.sortType = "desc";
  196. }else{
  197. this.sortField = null;
  198. this.sortType = null;
  199. }
  200. this.reload();
  201. },
  202. createListHead : function(){
  203. var _self = this;
  204. var headNode = new Element("tr", {"styles": this.css.listHeadNode}).inject(this.table);
  205. MWF.getJSON( this.listItemUrl, function(json){
  206. this.listItemTemplate = json;
  207. json.each(function(cell){
  208. var isShow = true;
  209. if( cell.access ){
  210. if( cell.access == "admin" && !this.explorer.options.isAdmin ){
  211. isShow = false;
  212. }
  213. }
  214. if(isShow) {
  215. var th = new Element("th", {
  216. "styles": this.css[cell.headStyles],
  217. "text": cell.title,
  218. "width": cell.width
  219. }).inject(headNode)
  220. if( cell.name == "checkbox" ){
  221. this.checkboxElement = new Element("input",{
  222. "type" : "checkbox"
  223. }).inject( th );
  224. this.checkboxElement.addEvent("click",function(){
  225. this.selectAllCheckbox()
  226. }.bind(this))
  227. }
  228. if( cell.defaultSort && cell.defaultSort != "" ){
  229. this.sortFieldDefault = cell.name;
  230. this.sortTypeDefault = cell.defaultSort;
  231. }
  232. if( cell.sort && cell.sort != "" ){
  233. th.store("sortField",cell.name);
  234. if( this.sortField == cell.name && this.sortType!="" ){
  235. th.store("sortType",this.sortType);
  236. this.sortIconNode = new Element("div",{
  237. "styles": this.sortType == "asc" ? this.css.sortIconNode_asc : this.css.sortIconNode_desc
  238. }).inject( th, "top" );
  239. }else{
  240. th.store("sortType","");
  241. this.sortIconNode = new Element("div",{"styles":this.css.sortIconNode}).inject( th, "top" );
  242. }
  243. th.setStyle("cursor","pointer");
  244. th.addEvent("click",function(){
  245. _self.resort( this );
  246. })
  247. }
  248. }
  249. }.bind(this));
  250. }.bind(this),false);
  251. },
  252. selectAllCheckbox : function(){
  253. var flag = this.checkboxElement.get("checked");
  254. this.items.each( function( it ){
  255. if( it.checkboxElement )it.checkboxElement.set("checked",flag );
  256. }.bind(this))
  257. },
  258. loadElementList: function(count){
  259. if (!this.isItemsLoaded){
  260. if (!this.isItemLoadding){
  261. this.isItemLoadding = true;
  262. this._getCurrentPageData(function(json){
  263. //if( !json.data )return;
  264. var length = json.count; //|| json.data.length;
  265. //if (!this.isCountShow){
  266. // this.filterAllProcessNode.getFirst("span").set("text", "("+this.count+")");
  267. // this.isCountShow = true;
  268. //}
  269. if ( length <=this.items.length){
  270. this.isItemsLoaded = true;
  271. }
  272. json.data.each(function(data){
  273. if (!this.documents[data.id]){
  274. var item = this._createItem(data);
  275. this.items.push(item);
  276. this.documents[data.id] = item;
  277. }
  278. }.bind(this));
  279. this.isItemLoadding = false;
  280. if (this.loadItemQueue>0){
  281. this.loadItemQueue--;
  282. this.loadElementList();
  283. }
  284. }.bind(this), count);
  285. }else{
  286. this.loadItemQueue++;
  287. }
  288. }
  289. },
  290. _createItem: function(data){
  291. return new MWF.xApplication.Attendance.Explorer.Document(this.table, data, this.explorer, this);
  292. },
  293. _getCurrentPageData: function(callback, count){
  294. /* if(!count)count=20;
  295. var id = (this.items.length) ? this.items[this.items.length-1].data.id : "(0)";
  296. var data = {
  297. "catagoryIdList": [
  298. {
  299. "name": "catagoryId",
  300. "value": this.explorer.categoryData.id
  301. }
  302. ],
  303. "statusList": [
  304. {
  305. "name": "docStatus",
  306. "value": this.explorer.options.status
  307. }
  308. ]
  309. }
  310. if( this.searchKey && this.searchKey!="" ){
  311. data.titleList = [{
  312. "name" :"title",
  313. "value" : this.searchKey
  314. }]
  315. }
  316. if (this.filter && this.filter.filter ){
  317. var filterResult = this.filter.getFilterResult();
  318. for(var f in filterResult ){
  319. data[f] = filterResult[f];
  320. }
  321. this.actions.listDocumentFilterNext(id, count || this.pageCount, data, function(json){
  322. if (callback) callback(json);
  323. });
  324. }else{
  325. this.actions.listDocumentFilterNext(id, count || this.pageCount, data, function(json){
  326. if (callback) callback(json);
  327. });
  328. }*/
  329. },
  330. _removeDocument: function(documentData, all){
  331. //var id = document.data.id;
  332. //this.actions.removeDocument(id, function(json){
  333. // //json.data.each(function(item){
  334. // this.items.erase(this.documents[id]);
  335. // this.documents[id].destroy();
  336. // MWF.release(this.documents[id]);
  337. // delete this.documents[id];
  338. // this.app.notice(this.app.lp.deleteDocumentOK, "success");
  339. // // }.bind(this));
  340. //}.bind(this));
  341. },
  342. _createDocument: function(){
  343. },
  344. _openDocument: function( documentData ){
  345. }
  346. })
  347. MWF.xApplication.Attendance.Explorer.Document = new Class({
  348. initialize: function(container, data, explorer, view){
  349. this.explorer = explorer;
  350. this.app = explorer.app;
  351. this.data = data;
  352. this.container = container;
  353. this.view = view;
  354. this.css = this.explorer.css;
  355. this.load();
  356. },
  357. load: function(){
  358. this.node = new Element("tr", {"styles": this.css.documentItemNode});
  359. this.node.inject(this.container);
  360. //this.documentAreaNode = new Element("td", {"styles": this.css.documentItemDocumentNode}).inject(this.node);
  361. this.view.listItemTemplate.each(function(cell){
  362. var isShow = true;
  363. if( cell.access ){
  364. if( cell.access == "admin" && !this.explorer.options.isAdmin ){
  365. isShow = false;
  366. }
  367. }
  368. if(isShow){
  369. var value;
  370. if( cell.item.substr( 0, "function".length ) == "function" ){
  371. eval( "var fun = " + cell.item );
  372. value = fun.call( this, this.data );
  373. }else if( typeOf(this.data[cell.item]) == "number" ){
  374. value = this.data[cell.item];
  375. }else{
  376. value = this.data[cell.item] ? this.data[cell.item] : "";
  377. }
  378. var td = this[cell.name] = new Element("td",{
  379. "styles":this.css[cell.contentStyles],
  380. "text" : value
  381. }).inject(this.node);
  382. if( cell.name == "actions" && typeOf( cell.sub )=="array"){
  383. this.setActions( this[cell.name], cell.sub );
  384. }
  385. if( cell.name == "checkbox" ){
  386. var showCheckBox = true;
  387. if( cell.condition && cell.condition.substr( 0, "function".length ) == "function" ) {
  388. eval("var fun = " + cell.condition);
  389. showCheckBox = fun.call(this, this.data);
  390. }
  391. if( showCheckBox ){
  392. this.checkboxElement = new Element("input",{
  393. "type" : "checkbox"
  394. }).inject( td );
  395. this.checkboxElement.addEvent("click",function(ev){
  396. ev.stopPropagation();
  397. }.bind(this))
  398. td.addEvent("click",function(ev){
  399. this.checkboxElement.set("checked", !this.checkboxElement.get("checked") )
  400. ev.stopPropagation();
  401. }.bind(this))
  402. }
  403. }
  404. }
  405. }.bind(this));
  406. this.node.addEvents({
  407. "mouseover": function(){if (!this.readyRemove) this.node.setStyles(this.css.documentItemDocumentNode_over);}.bind(this),
  408. "mouseout": function(){if (!this.readyRemove) this.node.setStyles(this.css.documentItemDocumentNode);}.bind(this),
  409. "click": function(e){
  410. this.openDocument(e);
  411. }.bind(this)
  412. });
  413. },
  414. //setEvents: function(){
  415. //
  416. // this.node.addEvents({
  417. // "mouseover": function(){if (!this.readyRemove) this.node.setStyles(this.css.documentItemDocumentNode_over);}.bind(this),
  418. // "mouseout": function(){if (!this.readyRemove) this.node.setStyles(this.css.documentItemDocumentNode);}.bind(this),
  419. // "click": function(e){
  420. // this.openDocument(e);
  421. // }.bind(this)
  422. // });
  423. //
  424. // if (this.deleteNode){
  425. // this.deleteNode.addEvents({
  426. // "mouseover": function(){this.deleteNode.setStyles(this.css.actionDeleteNode_over);}.bind(this),
  427. // "mouseout": function(){this.deleteNode.setStyles(this.css.actionDeleteNode);}.bind(this),
  428. // "mousedown": function(){this.deleteNode.setStyles(this.css.actionDeleteNode_down);}.bind(this),
  429. // "mouseup": function(){this.deleteNode.setStyles(this.css.actionDeleteNode_over);}.bind(this),
  430. // "click": function(e){
  431. // this.remove(e);
  432. // e.stopPropagation();
  433. // }.bind(this)
  434. // });
  435. // }
  436. //},
  437. setActions: function( actionsNode, data ){
  438. var _self = this;
  439. data.each(function( d ){
  440. if( !d.action || !this[d.action])return;
  441. if( d.condition ){
  442. if( d.condition.substr( 0, "function".length ) == "function" ) {
  443. eval("var fun = " + d.condition );
  444. if( ! fun.call(this, this.data) ){
  445. return;
  446. }
  447. }
  448. }
  449. var node = this[d.action+"Node"] = new Element("div", {"title": d.title}).inject(actionsNode);
  450. var styles, overStyles, downStyles;
  451. if( typeOf( d.styles) == "string" ) styles = this.css[d.styles];
  452. if( typeOf(d.styles) == "object" ) styles = d.styles;
  453. if( typeOf( d.overStyles) == "string" ) overStyles = this.css[d.overStyles];
  454. if( typeOf(d.overStyles) == "object" ) overStyles = d.overStyles;
  455. if( typeOf( d.downStyles) == "string" ) downStyles = this.css[d.downStyles];
  456. if( typeOf(d.downStyles) == "object" ) downStyles = d.downStyles;
  457. if( styles )node.setStyles( styles );
  458. if( overStyles && styles ){
  459. node.addEvent( "mouseover", function(ev){ ev.target.setStyles( this.styles ); }.bind({"styles" : overStyles }) );
  460. node.addEvent( "mouseout", function(ev){ ev.target.setStyles( this.styles ); }.bind({"styles" : styles}) );
  461. }
  462. if( downStyles && ( overStyles || styles)){
  463. node.addEvent( "mousedown", function(ev){ ev.target.setStyles( this.styles ); }.bind({"styles" : downStyles }) );
  464. node.addEvent( "mouseup", function(ev){ ev.target.setStyles( this.styles ); }.bind({"styles" : overStyles || styles }) )
  465. }
  466. if( this[d.action] ){
  467. node.addEvent("click", function(ev){
  468. this.fun.call( _self, ev );
  469. ev.stopPropagation();
  470. }.bind({fun : this[d.action]}))
  471. }
  472. }.bind(this))
  473. //if( this.actionAreaNode ){
  474. // if( this.explorer.options.isAdmin ){
  475. // this.deleteNode = new Element("div", {"styles": this.css.actionDeleteNode, "title": this.app.lp.delete}).inject(this.actionAreaNode);
  476. // }
  477. //}
  478. },
  479. openDocument: function(e){
  480. //var options = {"documentId": this.data.id }//this.explorer.app.options.application.allowControl};
  481. //this.explorer.app.desktop.openApplication(e, "cms.Document", options);
  482. this.view._openDocument( this.data );
  483. },
  484. remove: function(e){
  485. var lp = this.app.lp;
  486. var text = lp.deleteDocument.replace(/{title}/g, this.data.title);
  487. var _self = this;
  488. this.node.setStyles(this.css.documentItemDocumentNode_remove);
  489. this.readyRemove = true;
  490. this.explorer.app.confirm("warn", e, lp.deleteDocumentTitle, text, 350, 120, function(){
  491. //var inputs = this.content.getElements("input");
  492. //var flag = "";
  493. //for (var i=0; i<inputs.length; i++){
  494. // if (inputs[i].checked){
  495. // flag = inputs[i].get("value");
  496. // break;
  497. // }
  498. //}
  499. //if (flag){
  500. //if (flag=="all"){
  501. //_self.explorer.removeDocument(_self, true);
  502. //}else{
  503. _self.view._removeDocument(_self.data, false);
  504. //}
  505. this.close();
  506. //}else{
  507. // this.content.getElement("#deleteDocument_checkInfor").set("text", lp.deleteAllDocumentCheck).setStyle("color", "red");
  508. //}
  509. }, function(){
  510. _self.node.setStyles(_self.css.documentItemDocumentNode);
  511. _self.readyRemove = false;
  512. this.close();
  513. });
  514. },
  515. destroy: function(){
  516. this.node.destroy();
  517. }
  518. });
  519. MWF.xApplication.Attendance.Explorer.PopupForm = new Class({
  520. Extends: MWF.widget.Common,
  521. Implements: [Options, Events],
  522. options: {
  523. "width": "500",
  524. "height": "400"
  525. },
  526. initialize: function( explorer, data,options){
  527. this.setOptions(options);
  528. this.explorer = explorer;
  529. this.app = explorer.app;
  530. this.data = data || {};
  531. this.css = this.explorer.css;
  532. this.load();
  533. },
  534. load: function(){
  535. },
  536. open: function(e){
  537. this.isNew = false;
  538. this.isEdited = false;
  539. this._open();
  540. },
  541. create: function(){
  542. this.isNew = true;
  543. this._open();
  544. },
  545. edit: function(){
  546. this.isEdited = true;
  547. this._open();
  548. },
  549. _open : function(){
  550. this.formMarkNode = new Element("div", {
  551. "styles": this.css.formMarkNode,
  552. "events": {
  553. "mouseover": function(e){e.stopPropagation();},
  554. "mouseout": function(e){e.stopPropagation();}
  555. }
  556. }).inject(this.app.content, "after");
  557. this.formAreaNode = new Element("div", {
  558. "styles": this.css.formAreaNode
  559. });
  560. this.createFormNode();
  561. this.formAreaNode.inject(this.formMarkNode, "after");
  562. this.formAreaNode.fade("in");
  563. this.setFormNodeSize();
  564. this.setFormNodeSizeFun = this.setFormNodeSize.bind(this);
  565. this.addEvent("resize", this.setFormNodeSizeFun);
  566. },
  567. createFormNode: function(){
  568. var _self = this;
  569. this.formNode = new Element("div", {
  570. "styles": this.css.formNode
  571. }).inject(this.formAreaNode);
  572. this.formIconNode = new Element("div", {
  573. "styles": this.isNew ? this.css.formNewNode : this.css.formIconNode
  574. }).inject(this.formNode);
  575. this.formFormNode = new Element("div", {
  576. "styles": this.css.formFormNode
  577. }).inject(this.formNode);
  578. this.formTableContainer = new Element("div", {
  579. "styles": this.css.formTableContainer
  580. }).inject(this.formFormNode);
  581. this.formTableArea = new Element("div", {
  582. "styles": this.css.formTableArea
  583. }).inject(this.formTableContainer);
  584. this._createTableContent();
  585. //formFormNode.set("html", html);
  586. //this.setScrollBar(this.formTableContainer)
  587. this._createAction();
  588. },
  589. _createTableContent: function(){
  590. var html = "<table width='100%' bordr='0' cellpadding='5' cellspacing='0' styles='formTable'>"+
  591. "<tr><td colspan='2' styles='formTableHead'>申诉处理单</td></tr>" +
  592. "<tr><td styles='formTabelTitle' lable='empName'></td>"+
  593. " <td styles='formTableValue' item='empName'></td></tr>" +
  594. "<tr><td styles='formTabelTitle' lable='departmentName'></td>"+
  595. " <td styles='formTableValue' item='departmentName'></td></tr>" +
  596. "<tr><td styles='formTabelTitle' lable='recordDateString'></td>"+
  597. " <td styles='formTableValue' item='recordDateString'></td></tr>" +
  598. "<tr><td styles='formTabelTitle' lable='status'></td>"+
  599. " <td styles='formTableValue' item='status'></td></tr>" +
  600. "<tr><td styles='formTabelTitle' lable='appealReason'></td>"+
  601. " <td styles='formTableValue' item='appealReason'></td></tr>" +
  602. "<tr><td styles='formTabelTitle' lable='appealDescription'></td>"+
  603. " <td styles='formTableValue' item='appealDescription'></td></tr>" +
  604. "<tr><td styles='formTabelTitle' lable='opinion1'></td>"+
  605. " <td styles='formTableValue' item='opinion1'></td></tr>" +
  606. "</table>"
  607. this.formTableArea.set("html",html);
  608. MWF.xDesktop.requireApp("Template", "MForm", function(){
  609. this.form = new MForm( this.formTableArea, {empName:"xadmin"}, {
  610. isEdited : this.isEdited || this.isNew,
  611. itemTemplate : {
  612. empName : { text:"姓名", type : "innertext" },
  613. departmentName : { text:"部门", tType : "department", notEmpty:true },
  614. recordDateString : { text:"日期", tType : "date"},
  615. status : { text:"状态", tType : "number" },
  616. appealReason : {
  617. text:"下拉框",
  618. type : "select",
  619. selectValue : ["测试1","测试2"]
  620. },
  621. appealDescription : { text:"描述", type : "textarea" },
  622. opinion1 : { text:"测试", type : "button", "value" : "测试" }
  623. }
  624. }, this.app);
  625. this.form.load();
  626. }.bind(this), true);
  627. },
  628. setFormNodeSize: function (width, height, top, left) {
  629. if (!width)width = this.options && this.options.width ? this.options.width : "50%"
  630. if (!height)height = this.options && this.options.height ? this.options.height : "50%"
  631. if (!top) top = this.options && this.options.top ? this.options.top : 0;
  632. if (!left) left = this.options && this.options.left ? this.options.left : 0;
  633. var allSize = this.app.content.getSize();
  634. var limitWidth = allSize.x; //window.screen.width
  635. var limitHeight = allSize.y; //window.screen.height
  636. "string" == typeof width && (1 < width.length && "%" == width.substr(width.length - 1, 1)) && (width = parseInt(limitWidth * parseInt(width, 10) / 100, 10));
  637. "string" == typeof height && (1 < height.length && "%" == height.substr(height.length - 1, 1)) && (height = parseInt(limitHeight * parseInt(height, 10) / 100, 10));
  638. 300 > width && (width = 300);
  639. 220 > height && (height = 220);
  640. top = top || parseInt((limitHeight - height) / 2, 10);
  641. left = left || parseInt((limitWidth - width) / 2, 10);
  642. this.formAreaNode.setStyles({
  643. "width": "" + width + "px",
  644. "height": "" + height + "px",
  645. "top": "" + top + "px",
  646. "left": "" + left + "px"
  647. });
  648. this.formNode.setStyles({
  649. "width": "" + width + "px",
  650. "height": "" + height + "px"
  651. });
  652. var iconSize = this.formIconNode ? this.formIconNode.getSize() : {x: 0, y: 0};
  653. var topSize = this.formTopNode ? this.formTopNode.getSize() : {x: 0, y: 0};
  654. var bottomSize = this.formBottomNode ? this.formBottomNode.getSize() : {x: 0, y: 0};
  655. var contentHeight = height - iconSize.y - topSize.y - bottomSize.y;
  656. //var formMargin = formHeight -iconSize.y;
  657. this.formFormNode.setStyles({
  658. "height": "" + contentHeight + "px"
  659. });
  660. },
  661. //setFormNodeSize: function(){
  662. // var size = this.app.node.getSize();
  663. // var allSize = this.app.content.getSize();
  664. //
  665. // this.formAreaNode.setStyles({
  666. // "width": ""+size.x+"px",
  667. // "height": ""+size.y+"px"
  668. // });
  669. // var hY = size.y*0.8;
  670. // var mY = size.y*0.2/2;
  671. // this.formNode.setStyles({
  672. // "height": ""+hY+"px",
  673. // "margin-top": ""+mY+"px"
  674. // });
  675. //
  676. // var iconSize = this.formIconNode ? this.formIconNode.getSize() : {x:0,y:30};
  677. // var formHeight = hY*0.8;
  678. // if (formHeight>250) formHeight = 250;
  679. // var formMargin = hY*0.3/2-iconSize.y;
  680. // this.formFormNode.setStyles({
  681. // "height": ""+formHeight+"px",
  682. // "margin-top": ""+formMargin+"px"
  683. // });
  684. //},
  685. _createAction : function(){
  686. this.cancelActionNode = new Element("div", {
  687. "styles": this.css.formCancelActionNode,
  688. "text": this.app.lp.cancel
  689. }).inject(this.formFormNode);
  690. this.cancelActionNode.addEvent("click", function(e){
  691. this.cancel(e);
  692. }.bind(this));
  693. if( this.isNew || this.isEdited){
  694. this.okActionNode = new Element("div", {
  695. "styles": this.css.formOkActionNode,
  696. "text": this.app.lp.ok
  697. }).inject(this.formFormNode);
  698. this.okActionNode.addEvent("click", function(e){
  699. this.ok(e);
  700. }.bind(this));
  701. }
  702. },
  703. cancel: function(e){
  704. this.close();
  705. },
  706. close: function(e){
  707. this.formMarkNode.destroy();
  708. this.formAreaNode.destroy();
  709. delete this;
  710. },
  711. ok: function(e){
  712. var data = this.form.getResult(true,",",true,false,true);
  713. if( data ){
  714. this._ok( data, function( json ){
  715. if( json.type == "ERROR" ){
  716. this.app.notice( json.message , "error");
  717. }else{
  718. this.formMarkNode.destroy();
  719. this.formAreaNode.destroy();
  720. if(this.explorer.view)this.explorer.view.reload();
  721. this.app.notice( this.isNew ? this.app.lp.createSuccess : this.app.lp.updateSuccess , "success");
  722. }
  723. }.bind(this))
  724. }
  725. },
  726. _ok: function( data, callback ){
  727. //this.app.restActions.saveDocument( this.data.id, data, function(json){
  728. // if( callback )callback(json);
  729. //}.bind(this));
  730. }
  731. })