WeekendSetting.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. MWF.xDesktop.requireApp("Template", "MForm", null, false);
  2. MWF.xApplication.Attendance.WeekendSetting = new Class({
  3. Extends: MWF.widget.Common,
  4. options:{
  5. style : "default"
  6. },
  7. initialize: function(app, actions, options){
  8. this.setOptions(options);
  9. this.app = app;
  10. this.path = "/x_component_Attendance/$WeekendSetting/";
  11. this.cssPath = "/x_component_Attendance/$WeekendSetting/"+this.options.style+"/css.wcss";
  12. this._loadCss();
  13. this.actions = actions;
  14. this.load();
  15. },
  16. load: function(){
  17. this.app.restActions.listSetting(function(json){
  18. if( json.data && json.data.length>0){
  19. this.data = json.data;
  20. }
  21. }.bind(this),null,false);
  22. if( !this.data ){
  23. this.data = [];
  24. }
  25. },
  26. decodeData : function( data ){
  27. //{
  28. // 'configCode':'APPEALABLE',
  29. // 'configName':'申诉功能启用状态',
  30. // 'configValue':'false',
  31. // 'ordernumber':1
  32. //}
  33. var json = {};
  34. this.dataJson = {};
  35. data.each( function(d){
  36. json[d.configCode] = d.configValue;
  37. this.dataJson[d.configCode] = d;
  38. }.bind(this));
  39. //alert(JSON.stringify(json))
  40. return json;
  41. },
  42. encodeData : function( orgData, data ){
  43. var arr = [];
  44. for( var d in data ){
  45. if( this.itemTemplate[d] ){
  46. var flag = false;
  47. for( var i=0; i<orgData.length;i++ ){
  48. if( orgData[i].configCode == d ){
  49. flag = true;
  50. orgData[i].configValue = data[d];
  51. arr.push( Object.clone(orgData[i]) );
  52. }
  53. }
  54. if( !flag ){
  55. arr.push( {
  56. configCode : d,
  57. configValue : data[d],
  58. configName : this.itemTemplate[d].text
  59. } )
  60. }
  61. }
  62. };
  63. // alert(JSON.stringify(arr))
  64. return arr;
  65. },
  66. open: function(e){
  67. this.isNew = false;
  68. this.isEdited = false;
  69. this._open();
  70. },
  71. create: function(){
  72. this.isNew = true;
  73. this._open();
  74. },
  75. edit: function(){
  76. this.isEdited = true;
  77. this._open();
  78. },
  79. _open : function(){
  80. this.createMarkNode = new Element("div", {
  81. "styles": this.css.createMarkNode,
  82. "events": {
  83. "mouseover": function(e){e.stopPropagation();},
  84. "mouseout": function(e){e.stopPropagation();}
  85. }
  86. }).inject(this.app.content, "after");
  87. this.createAreaNode = new Element("div", {
  88. "styles": this.css.createAreaNode
  89. });
  90. this.createNode();
  91. this.createAreaNode.inject(this.createMarkNode, "after");
  92. this.createAreaNode.fade("in");
  93. this.setCreateNodeSize();
  94. this.setCreateNodeSizeFun = this.setCreateNodeSize.bind(this);
  95. this.addEvent("resize", this.setCreateNodeSizeFun);
  96. },
  97. createNode: function(){
  98. var _self = this;
  99. this.createNode = new Element("div", {
  100. "styles": this.css.createNode
  101. }).inject(this.createAreaNode);
  102. //
  103. //this.createIconNode = new Element("div", {
  104. // "styles": this.isNew ? this.css.createNewNode : this.css.createIconNode
  105. //}).inject(this.createNode);
  106. this.createContainerNode = new Element("div", {
  107. "styles": this.css.createContainerNode
  108. }).inject(this.createNode);
  109. this.setScrollBar( this.createContainerNode );
  110. this.createFormNode = new Element("div", {
  111. "styles": this.css.createFormNode
  112. }).inject(this.createContainerNode);
  113. this.createTableContainer = new Element("div", {
  114. "styles": this.css.createTableContainer
  115. }).inject(this.createFormNode);
  116. this.createTableArea = new Element("div", {
  117. "styles": this.css.createTableArea
  118. }).inject(this.createTableContainer);
  119. var table = new Element("table", {
  120. "width" : "100%", "border" : "0", "cellpadding" : "5", "cellspacing" : "0", "styles" : this.css.editTable, "class" : "editTable"
  121. }).inject( this.createTableArea );
  122. var d = this.decodeData( this.data );
  123. var html = "<table width='100%' bordr='0' cellpadding='5' cellspacing='0' styles='formTable'>"+
  124. "<tr><td colspan='4' styles='formTableHead'>周末设置</td></tr>" +
  125. "<tr><td styles='formTableTitle' lable='ATTENDANCE_WEEKEND'></td>"+
  126. " <td styles='formTableValue' item='ATTENDANCE_WEEKEND'></td>"+
  127. "</table>";
  128. html = html+"<span style='font-size:12px'>"+this.dataJson.ATTENDANCE_WEEKEND.description+"</span>"
  129. this.createTableArea.set("html",html);
  130. this.itemTemplate = {
  131. ATTENDANCE_WEEKEND : { text : "周末选择",
  132. type : "select",
  133. value : d.ATTENDANCE_WEEKEND ,
  134. selectValue :this.dataJson.ATTENDANCE_WEEKEND.selectContent.split("|") ,//["周六","周日"]
  135. /*event : {
  136. change : function( item, ev ){
  137. this.createTableArea.getElement("[item='valueArea']").setStyle( "display" , (item.getValue() == "汇报对象") ? "none" : "" );
  138. }.bind(this)
  139. }*/
  140. }
  141. };
  142. this.document = new MForm( this.createTableArea, this.data, {
  143. style : "popup",
  144. isEdited : this.isEdited || this.isNew,
  145. itemTemplate : this.itemTemplate
  146. }, this.app,this.css);
  147. this.document.load();
  148. this.cancelActionNode = new Element("div", {
  149. "styles": this.css.createCancelActionNode,
  150. "text": "取消"
  151. }).inject(this.createFormNode);
  152. this.cancelActionNode.addEvent("click", function(e){
  153. this.cancelCreate(e);
  154. }.bind(this));
  155. if( this.isNew || this.isEdited ){
  156. this.createOkActionNode = new Element("div", {
  157. "styles": this.css.createOkActionNode,
  158. "text": "确定"
  159. }).inject(this.createFormNode);
  160. this.createOkActionNode.addEvent("click", function(e){
  161. this.okCreate(e);
  162. }.bind(this));
  163. }
  164. },
  165. setCreateNodeSize: function(){
  166. var size = this.app.node.getSize();
  167. var allSize = this.app.content.getSize();
  168. var height = "270";
  169. var width = "600";
  170. this.createAreaNode.setStyles({
  171. "width": ""+size.x+"px",
  172. "height": ""+size.y+"px"
  173. });
  174. var hY = height;
  175. var mY = (size.y-height)/2;
  176. this.createNode.setStyles({
  177. "height": ""+hY+"px",
  178. "margin-top": ""+mY+"px",
  179. "width" : ""+width+"px"
  180. });
  181. this.createContainerNode.setStyles({
  182. "height": ""+hY+"px"
  183. });
  184. var iconSize = this.createIconNode ? this.createIconNode.getSize() : {x:0,y:0};
  185. var formMargin = hY-iconSize.y-60;
  186. this.createFormNode.setStyles({
  187. "height": ""+formMargin+"px",
  188. "margin-top": ""+60+"px"
  189. });
  190. },
  191. cancelCreate: function(e){
  192. this.createMarkNode.destroy();
  193. this.createAreaNode.destroy();
  194. delete this;
  195. },
  196. okCreate: function(e){
  197. var data = this.document.getResult(true,",",true,false,false);
  198. if(data){
  199. var arr = this.encodeData( this.data, data );
  200. this.save( arr );
  201. }
  202. },
  203. save: function( arr ){
  204. var flag = true;
  205. arr.each( function( d ){
  206. this.app.restActions.saveSetting( d, function(json){
  207. if( json.type == "ERROR" ){
  208. this.app.notice( json.message , "error");
  209. flag = false;
  210. }
  211. }.bind(this), null, false);
  212. }.bind(this));
  213. if( flag ){
  214. this.createMarkNode.destroy();
  215. this.createAreaNode.destroy();
  216. this.app.notice( "保存成功" , "success");
  217. }
  218. }
  219. });