AppSetting.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. MWF.xDesktop.requireApp("Template", "MForm", null, false);
  2. MWF.xApplication.Attendance.AppSetting = 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/$AppSetting/";
  11. this.cssPath = "../x_component_Attendance/$AppSetting/"+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='APPEALABLE'></td>"+
  126. " <td styles='formTableValue' item='APPEALABLE'></td>"+
  127. "<tr><td styles='formTableTitle' lable='APPEAL_AUDITOR_TYPE'></td>"+
  128. " <td styles='formTableValue' item='APPEAL_AUDITOR_TYPE'></td>"+
  129. "<tr item='valueArea' style='display:"+ (d.APPEAL_AUDITOR_TYPE == "汇报对象" ? "none" : "") +"' ><td styles='formTableTitle' lable='APPEAL_AUDITOR_VALUE'></td>"+
  130. " <td styles='formTableValue' item='APPEAL_AUDITOR_VALUE'></td>"+
  131. //"<tr><td styles='formTableTitle' lable='APPEAL_CHECKER_TYPE'></td>"+
  132. //" <td styles='formTableValue' item='APPEAL_CHECKER_TYPE'></td>"+
  133. //"<tr><td styles='formTableTitle' lable='APPEAL_CHECKER_VALUE'></td>"+
  134. //" <td styles='formTableValue' item='APPEAL_CHECKER_VALUE'></td>"+
  135. "</table>";
  136. this.createTableArea.set("html",html);
  137. this.itemTemplate = {
  138. APPEALABLE : { text:"申诉及审批功能启用状态",
  139. type : "select",
  140. value : d.APPEALABLE || "true",
  141. selectText : ["开启","关闭"],
  142. selectValue : ["true","false"]
  143. },
  144. APPEAL_AUDITOR_TYPE : { text : "申诉审核人确定方式",
  145. type : "select",
  146. value : d.APPEAL_AUDITOR_TYPE ,
  147. selectValue : this.dataJson.APPEAL_AUDITOR_TYPE.selectContent.split("|"), //["人员属性","所属部门职位","指定人","汇报对象"],
  148. event : {
  149. change : function( item, ev ){
  150. this.createTableArea.getElement("[item='valueArea']").setStyle( "display" , (item.getValue() == "汇报对象") ? "none" : "" );
  151. }.bind(this)
  152. }
  153. },
  154. APPEAL_AUDITOR_VALUE : { text : "申诉审核人确定内容",
  155. type : "text",
  156. value : d.APPEAL_AUDITOR_VALUE ,
  157. defaultValue : "直属领导"
  158. }//,
  159. //APPEAL_CHECKER_TYPE : { text : "考勤结果申诉复核人确定方式",
  160. // type : "select",
  161. // value : d.APPEAL_CHECKER_TYPE ,
  162. // selectValue : ["无","人员属性","所属部门职位","指定人"] //,"指定角色"]
  163. //},
  164. //APPEAL_CHECKER_VALUE : { text : "考勤结果申诉复核人确定内容",
  165. // type : "text",
  166. // value : d.APPEAL_CHECKER_VALUE
  167. //}
  168. };
  169. this.document = new MForm( this.createTableArea, this.data, {
  170. style : "popup",
  171. isEdited : this.isEdited || this.isNew,
  172. itemTemplate : this.itemTemplate
  173. }, this.app,this.css);
  174. this.document.load();
  175. this.cancelActionNode = new Element("div", {
  176. "styles": this.css.createCancelActionNode,
  177. "text": "取消"
  178. }).inject(this.createFormNode);
  179. this.cancelActionNode.addEvent("click", function(e){
  180. this.cancelCreate(e);
  181. }.bind(this));
  182. if( this.isNew || this.isEdited ){
  183. this.createOkActionNode = new Element("div", {
  184. "styles": this.css.createOkActionNode,
  185. "text": "确定"
  186. }).inject(this.createFormNode);
  187. this.createOkActionNode.addEvent("click", function(e){
  188. this.okCreate(e);
  189. }.bind(this));
  190. }
  191. },
  192. setCreateNodeSize: function(){
  193. var size = this.app.node.getSize();
  194. var allSize = this.app.content.getSize();
  195. var height = "470";
  196. var width = "600";
  197. this.createAreaNode.setStyles({
  198. "width": ""+size.x+"px",
  199. "height": ""+size.y+"px"
  200. });
  201. var hY = height;
  202. var mY = (size.y-height)/2;
  203. this.createNode.setStyles({
  204. "height": ""+hY+"px",
  205. "margin-top": ""+mY+"px",
  206. "width" : ""+width+"px"
  207. });
  208. this.createContainerNode.setStyles({
  209. "height": ""+hY+"px"
  210. });
  211. var iconSize = this.createIconNode ? this.createIconNode.getSize() : {x:0,y:0};
  212. var formMargin = hY-iconSize.y-60;
  213. this.createFormNode.setStyles({
  214. "height": ""+formMargin+"px",
  215. "margin-top": ""+60+"px"
  216. });
  217. },
  218. cancelCreate: function(e){
  219. this.createMarkNode.destroy();
  220. this.createAreaNode.destroy();
  221. delete this;
  222. },
  223. okCreate: function(e){
  224. var data = this.document.getResult(true,",",true,false,false);
  225. if(data){
  226. var arr = this.encodeData( this.data, data );
  227. this.save( arr );
  228. }
  229. },
  230. save: function( arr ){
  231. var flag = true;
  232. arr.each( function( d ){
  233. this.app.restActions.saveSetting( d, function(json){
  234. if( json.type == "ERROR" ){
  235. this.app.notice( json.message , "error");
  236. flag = false;
  237. }
  238. }.bind(this), null, false);
  239. }.bind(this));
  240. if( flag ){
  241. this.createMarkNode.destroy();
  242. this.createAreaNode.destroy();
  243. this.app.notice( "保存成功" , "success");
  244. }
  245. }
  246. });