AppSetting.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. data.each( function(d){
  35. json[d.configCode] = d.configValue;
  36. })
  37. //alert(JSON.stringify(json))
  38. return json;
  39. },
  40. encodeData : function( orgData, data ){
  41. var arr = [];
  42. for( var d in data ){
  43. if( this.itemTemplate[d] ){
  44. var flag = false;
  45. for( var i=0; i<orgData.length;i++ ){
  46. if( orgData[i].configCode == d ){
  47. flag = true;
  48. orgData[i].configValue = data[d];
  49. arr.push( Object.clone(orgData[i]) );
  50. }
  51. }
  52. if( !flag ){
  53. arr.push( {
  54. configCode : d,
  55. configValue : data[d],
  56. configName : this.itemTemplate[d].text
  57. } )
  58. }
  59. }
  60. };
  61. // alert(JSON.stringify(arr))
  62. return arr;
  63. },
  64. open: function(e){
  65. this.isNew = false;
  66. this.isEdited = false;
  67. this._open();
  68. },
  69. create: function(){
  70. this.isNew = true;
  71. this._open();
  72. },
  73. edit: function(){
  74. this.isEdited = true;
  75. this._open();
  76. },
  77. _open : function(){
  78. this.createMarkNode = new Element("div", {
  79. "styles": this.css.createMarkNode,
  80. "events": {
  81. "mouseover": function(e){e.stopPropagation();},
  82. "mouseout": function(e){e.stopPropagation();}
  83. }
  84. }).inject(this.app.content, "after");
  85. this.createAreaNode = new Element("div", {
  86. "styles": this.css.createAreaNode
  87. });
  88. this.createNode();
  89. this.createAreaNode.inject(this.createMarkNode, "after");
  90. this.createAreaNode.fade("in");
  91. this.setCreateNodeSize();
  92. this.setCreateNodeSizeFun = this.setCreateNodeSize.bind(this);
  93. this.addEvent("resize", this.setCreateNodeSizeFun);
  94. },
  95. createNode: function(){
  96. var _self = this;
  97. this.createNode = new Element("div", {
  98. "styles": this.css.createNode
  99. }).inject(this.createAreaNode);
  100. //
  101. //this.createIconNode = new Element("div", {
  102. // "styles": this.isNew ? this.css.createNewNode : this.css.createIconNode
  103. //}).inject(this.createNode);
  104. this.createContainerNode = new Element("div", {
  105. "styles": this.css.createContainerNode
  106. }).inject(this.createNode);
  107. this.setScrollBar( this.createContainerNode );
  108. this.createFormNode = new Element("div", {
  109. "styles": this.css.createFormNode
  110. }).inject(this.createContainerNode);
  111. this.createTableContainer = new Element("div", {
  112. "styles": this.css.createTableContainer
  113. }).inject(this.createFormNode);
  114. this.createTableArea = new Element("div", {
  115. "styles": this.css.createTableArea
  116. }).inject(this.createTableContainer);
  117. var table = new Element("table", {
  118. "width" : "100%", "border" : "0", "cellpadding" : "5", "cellspacing" : "0", "styles" : this.css.editTable, "class" : "editTable"
  119. }).inject( this.createTableArea );
  120. var d = this.decodeData( this.data );
  121. var html = "<table width='100%' bordr='0' cellpadding='5' cellspacing='0' styles='formTable'>"+
  122. "<tr><td colspan='4' styles='formTableHead'>系统设置</td></tr>" +
  123. "<tr><td styles='formTableTitle' lable='APPEALABLE'></td>"+
  124. " <td styles='formTableValue' item='APPEALABLE'></td>"+
  125. "<tr><td styles='formTableTitle' lable='APPEAL_AUDITOR_TYPE'></td>"+
  126. " <td styles='formTableValue' item='APPEAL_AUDITOR_TYPE'></td>"+
  127. "<tr><td styles='formTableTitle' lable='APPEAL_AUDITOR_VALUE'></td>"+
  128. " <td styles='formTableValue' item='APPEAL_AUDITOR_VALUE'></td>"+
  129. //"<tr><td styles='formTableTitle' lable='APPEAL_CHECKER_TYPE'></td>"+
  130. //" <td styles='formTableValue' item='APPEAL_CHECKER_TYPE'></td>"+
  131. //"<tr><td styles='formTableTitle' lable='APPEAL_CHECKER_VALUE'></td>"+
  132. //" <td styles='formTableValue' item='APPEAL_CHECKER_VALUE'></td>"+
  133. "</table>"
  134. this.createTableArea.set("html",html);
  135. this.itemTemplate = {
  136. APPEALABLE : { text:"申诉及审批功能启用状态",
  137. type : "select",
  138. value : d.APPEALABLE || "true",
  139. selectText : ["开启","关闭"],
  140. selectValue : ["true","false"]
  141. },
  142. APPEAL_AUDITOR_TYPE : { text : "考勤结果申诉审核人确定方式",
  143. type : "select",
  144. value : d.APPEAL_AUDITOR_TYPE ,
  145. selectValue : ["人员属性","所属部门职位","指定人"] //,"指定角色"]
  146. },
  147. APPEAL_AUDITOR_VALUE : { text : "考勤结果申诉审核人确定内容",
  148. type : "text",
  149. value : d.APPEAL_AUDITOR_VALUE ,
  150. defaultValue : "直属领导"
  151. }//,
  152. //APPEAL_CHECKER_TYPE : { text : "考勤结果申诉复核人确定方式",
  153. // type : "select",
  154. // value : d.APPEAL_CHECKER_TYPE ,
  155. // selectValue : ["无","人员属性","所属部门职位","指定人"] //,"指定角色"]
  156. //},
  157. //APPEAL_CHECKER_VALUE : { text : "考勤结果申诉复核人确定内容",
  158. // type : "text",
  159. // value : d.APPEAL_CHECKER_VALUE
  160. //}
  161. };
  162. this.document = new MForm( this.createTableArea, this.data, {
  163. style : "popup",
  164. isEdited : this.isEdited || this.isNew,
  165. itemTemplate : this.itemTemplate
  166. }, this.app,this.css);
  167. this.document.load();
  168. this.cancelActionNode = new Element("div", {
  169. "styles": this.css.createCancelActionNode,
  170. "text": "取消"
  171. }).inject(this.createFormNode);
  172. this.cancelActionNode.addEvent("click", function(e){
  173. this.cancelCreate(e);
  174. }.bind(this));
  175. if( this.isNew || this.isEdited ){
  176. this.createOkActionNode = new Element("div", {
  177. "styles": this.css.createOkActionNode,
  178. "text": "确定"
  179. }).inject(this.createFormNode);
  180. this.createOkActionNode.addEvent("click", function(e){
  181. this.okCreate(e);
  182. }.bind(this));
  183. }
  184. },
  185. setCreateNodeSize: function(){
  186. var size = this.app.node.getSize();
  187. var allSize = this.app.content.getSize();
  188. var height = "470";
  189. var width = "600";
  190. this.createAreaNode.setStyles({
  191. "width": ""+size.x+"px",
  192. "height": ""+size.y+"px"
  193. });
  194. var hY = height;
  195. var mY = (size.y-height)/2;
  196. this.createNode.setStyles({
  197. "height": ""+hY+"px",
  198. "margin-top": ""+mY+"px",
  199. "width" : ""+width+"px"
  200. });
  201. this.createContainerNode.setStyles({
  202. "height": ""+hY+"px"
  203. });
  204. var iconSize = this.createIconNode ? this.createIconNode.getSize() : {x:0,y:0};
  205. var formMargin = hY-iconSize.y-60;
  206. this.createFormNode.setStyles({
  207. "height": ""+formMargin+"px",
  208. "margin-top": ""+60+"px"
  209. });
  210. },
  211. cancelCreate: function(e){
  212. this.createMarkNode.destroy();
  213. this.createAreaNode.destroy();
  214. delete this;
  215. },
  216. okCreate: function(e){
  217. var data = this.document.getResult(true,",",true,false,false)
  218. if(data){
  219. var arr = this.encodeData( this.data, data )
  220. this.save( arr );
  221. }
  222. },
  223. save: function( arr ){
  224. var flag = true;
  225. arr.each( function( d ){
  226. this.app.restActions.saveSetting( d, function(json){
  227. if( json.type == "ERROR" ){
  228. this.app.notice( json.message , "error");
  229. flag = false;
  230. }
  231. }.bind(this), null, false);
  232. }.bind(this))
  233. if( flag ){
  234. this.createMarkNode.destroy();
  235. this.createAreaNode.destroy();
  236. this.app.notice( "保存成功" , "success");
  237. }
  238. }
  239. })