WeekendSetting.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. MWF.xDesktop.requireApp("Template", "MPopupForm", null, false);
  2. MWF.xDesktop.requireApp("Template", "MForm", null, false);
  3. MWF.xApplication.Attendance.WeekendSetting = new Class({
  4. Extends: MWF.xApplication.Attendance.Explorer.PopupForm,
  5. options:{
  6. "height": 300,
  7. "hasTop" : true,
  8. "hasBottom" : true,
  9. "title": MWF.xApplication.Attendance.LP.weekendSetting
  10. },
  11. decodeData : function( data ){
  12. //{
  13. // 'configCode':'APPEALABLE',
  14. // 'configName':'申诉功能启用状态',
  15. // 'configValue':'false',
  16. // 'ordernumber':1
  17. //}
  18. var json = {};
  19. this.dataJson = {};
  20. data.each( function(d){
  21. json[d.configCode] = d.configValue;
  22. this.dataJson[d.configCode] = d;
  23. }.bind(this));
  24. //alert(JSON.stringify(json))
  25. return json;
  26. },
  27. encodeData : function( orgData, data ){
  28. var arr = [];
  29. for( var d in data ){
  30. if( this.itemTemplate[d] ){
  31. var flag = false;
  32. for( var i=0; i<orgData.length;i++ ){
  33. if( orgData[i].configCode == d ){
  34. flag = true;
  35. orgData[i].configValue = data[d];
  36. arr.push( Object.clone(orgData[i]) );
  37. }
  38. }
  39. if( !flag ){
  40. arr.push( {
  41. configCode : d,
  42. configValue : data[d],
  43. configName : this.itemTemplate[d].text
  44. } )
  45. }
  46. }
  47. };
  48. // alert(JSON.stringify(arr))
  49. return arr;
  50. },
  51. _createTableContent: function(){
  52. var lp = MWF.xApplication.Attendance.LP;
  53. var _self = this;
  54. this.app.restActions.listSetting(function(json){
  55. if( json.data && json.data.length>0){
  56. this.data = json.data;
  57. }
  58. }.bind(this),null,false);
  59. if( !this.data ){
  60. this.data = [];
  61. }
  62. var d = this.decodeData( this.data );
  63. var html = "<table width='100%' bordr='0' cellpadding='5' cellspacing='0' styles='formTable'>"+
  64. "<tr><td style='width: 100px;' styles='formTableTitle' lable='ATTENDANCE_WEEKEND'></td>"+
  65. " <td styles='formTableValue' item='ATTENDANCE_WEEKEND'></td>"+
  66. "</table>";
  67. html = html+"<span style='font-size:12px'>"+this.dataJson.ATTENDANCE_WEEKEND.description+"</span>"
  68. this.formTableArea.set("html",html);
  69. this.itemTemplate = {
  70. ATTENDANCE_WEEKEND : { text : lp.selectWeekend,
  71. type : "select",
  72. value : d.ATTENDANCE_WEEKEND ,
  73. selectValue :this.dataJson.ATTENDANCE_WEEKEND.selectContent.split("|") ,//["周六","周日"]
  74. /*event : {
  75. change : function( item, ev ){
  76. this.createTableArea.getElement("[item='valueArea']").setStyle( "display" , (item.getValue() == "汇报对象") ? "none" : "" );
  77. }.bind(this)
  78. }*/
  79. }
  80. };
  81. this.document = new MForm( this.formTableArea, this.data, {
  82. style : "attendance",
  83. isEdited : this.isEdited || this.isNew,
  84. itemTemplate : this.itemTemplate
  85. }, this.app,this.css);
  86. this.document.load();
  87. // this.cancelActionNode = new Element("div", {
  88. // "styles": this.css.createCancelActionNode,
  89. // "text": lp.cancel
  90. // }).inject(this.createFormNode);
  91. //
  92. //
  93. // this.cancelActionNode.addEvent("click", function(e){
  94. // this.cancelCreate(e);
  95. // }.bind(this));
  96. //
  97. // if( this.isNew || this.isEdited ){
  98. // this.createOkActionNode = new Element("div", {
  99. // "styles": this.css.createOkActionNode,
  100. // "text": lp.ok
  101. // }).inject(this.createFormNode);
  102. //
  103. // this.createOkActionNode.addEvent("click", function(e){
  104. // this.okCreate(e);
  105. // }.bind(this));
  106. // }
  107. },
  108. ok: function(e){
  109. var data = this.document.getResult(true,",",true,false,false);
  110. if(data){
  111. var arr = this.encodeData( this.data, data );
  112. this.save( arr );
  113. }
  114. },
  115. save: function( arr ){
  116. var flag = true;
  117. arr.each( function( d ){
  118. this.app.restActions.saveSetting( d, function(json){
  119. if( json.type == "ERROR" ){
  120. this.app.notice( json.message , "error");
  121. flag = false;
  122. }
  123. }.bind(this), null, false);
  124. }.bind(this));
  125. if( flag ){
  126. if( this.formMaskNode )this.formMaskNode.destroy();
  127. if( this.formAreaNode )this.formAreaNode.destroy();
  128. this.app.notice( MWF.xApplication.Attendance.LP.saveSuccess , "success");
  129. }
  130. }
  131. });