AssetsPracticeSys.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.fa.fix.AssetsPracticeSys', {
  3. extend: 'Ext.app.Controller',
  4. FormUtil: Ext.create('erp.util.FormUtil'),
  5. GridUtil: Ext.create('erp.util.GridUtil'),
  6. BaseUtil: Ext.create('erp.util.BaseUtil'),
  7. views:[
  8. 'core.grid.Panel4','core.toolbar.Toolbar3','core.button.Save','core.button.ResPost','core.trigger.CateTreeDbfindTrigger'
  9. ],
  10. init:function(){
  11. var me = this;
  12. me.gridLastSelected = null;
  13. this.control({
  14. 'erpGridPanel4': {
  15. itemclick: this.onGridItemClick,
  16. afterrender: function(grid){
  17. grid.plugins[0].on('beforeedit', function(e){
  18. if(e.field == 'ps_value'){//监听ps_value
  19. var record = e.record;
  20. var column = e.column;
  21. switch(record.data['ps_fieldtype']){
  22. case "B"://boolean
  23. if(column.xtype == 'booleancolumn'){
  24. break;
  25. }
  26. column.setEditor(new Ext.form.field.ComboBox({
  27. value: e.value,
  28. store: Ext.create('Ext.data.Store', {
  29. fields: ['display', 'value'],
  30. data : [
  31. {"display": $I18N.common.form.yes, "value": 'true'},
  32. {"display": $I18N.common.form.no, "value": 'false'}
  33. ]
  34. }),
  35. displayField: 'display',
  36. valueField: 'value',
  37. queryMode: 'local',
  38. value: 'false',
  39. hideTrigger: false
  40. }));
  41. column.renderer = function(val){
  42. if(column.xtype == 'booleancolumn'){
  43. if(val == 'true'){
  44. return $I18N.common.form.yes;
  45. } else {
  46. return $I18N.common.form.no;
  47. }
  48. }
  49. return val;
  50. };
  51. column.xtype = 'booleancolumn';
  52. break;
  53. case "N"://number
  54. if(column.xtype == 'textcolumn'){
  55. break;
  56. }
  57. column.setEditor(new Ext.form.field.Number({value: e.value}));
  58. column.xtype = 'textcolumn';
  59. break;
  60. case "D"://date
  61. column.renderer = function(val){
  62. if(record.data['ps_fieldtype'] == 'D' && column.xtype == 'datecolumn'){
  63. val = (val == null || val == '') ? new Date() : new Date(val);
  64. val = Ext.Date.toString(val);
  65. if(record.data['ps_value'] != val){
  66. record.set('ps_value', val);
  67. }
  68. }
  69. return val;
  70. };
  71. column.setEditor(new Ext.form.field.Date({value: e.value || new Date()}));
  72. column.xtype = 'datecolumn';
  73. //
  74. break;
  75. case "S"://string
  76. if(column.xtype == 'textcolumn'){
  77. break;
  78. }
  79. column.setEditor(new Ext.form.field.Text({value: e.value}));
  80. column.xtype = 'textcolumn';
  81. break;
  82. case "F"://dbfind
  83. // if(column.xtype == 'dbfindcolumn'){
  84. // break;
  85. // }
  86. column.setEditor(new erp.view.core.trigger.CateTreeDbfindTrigger({value: e.value}));
  87. column.xtype = 'catetreecolumn';
  88. break;
  89. case "C"://下拉框
  90. if(column.xtype == 'combocolumn'){
  91. break;
  92. }
  93. column.setEditor(new Ext.form.field.ComboBox({
  94. displayField: 'display',
  95. valueField: 'value',
  96. queryMode: 'local',
  97. store: Ext.create('Ext.data.Store', {
  98. fields: ['display', 'value'],
  99. data: [{
  100. display: 'S-001-002',
  101. value: 'S-001-002'
  102. },{
  103. display: 'S-001-003',
  104. value: 'S-001-003'
  105. }]
  106. }),
  107. value: e.value
  108. }));
  109. column.xtype = 'combocolumn';
  110. break;
  111. }
  112. }
  113. });
  114. }
  115. },
  116. 'erpSaveButton': {
  117. click: function(btn){
  118. this.beforeUpdate();
  119. }
  120. }
  121. });
  122. },
  123. onGridItemClick: function(selModel, record){//grid行选择
  124. },
  125. getForm: function(btn){
  126. return btn.ownerCt.ownerCt;
  127. },
  128. beforeSave: function(){
  129. this.FormUtil.beforeSave(this);
  130. },
  131. beforeUpdate: function(){
  132. Array.prototype.contains = function(obj) {
  133. var i = this.length;
  134. while (i--) {
  135. if (this[i] === obj) {
  136. return true;
  137. }
  138. }
  139. return false;
  140. };
  141. var grid = Ext.getCmp('grid');
  142. // var items = grid.store.data.items;
  143. // var rowNo = [];
  144. // Ext.each(items,function(item,index){
  145. //
  146. // Ext.each(grid.columns, function(c){
  147. // if(item.data[c.dataIndex]!=item.raw[c.dataIndex])
  148. // {
  149. // if(!rowNo.contains(index+1)){
  150. //
  151. // rowNo.push(index+1);
  152. // }
  153. // }
  154. //
  155. // });
  156. //
  157. // });
  158. //
  159. // if(rowNo.length==0){
  160. // Ext.Msg.alert("你未对数据做任何修改!");
  161. // return;
  162. // }
  163. // else{
  164. // var result = confirm("第"+rowNo.toString()+"行已经修改,确定更新?");
  165. // if(result){
  166. var index = 0;
  167. var jsonGridData = new Array();
  168. var s = grid.getStore().data.items;
  169. for(var i=0;i<s.length;i++){//将grid里面各行的数据获取并拼成jsonGridData
  170. var data = s[i].data;
  171. // Ext.each(grid.columns, function(c){
  172. // if(c.xtype == 'datecolumn'){
  173. // if(Ext.isDate(data[c.dataIndex])){
  174. // data[c.dataIndex] = Ext.Date.toString(data[c.dataIndex]);//在这里把GMT日期转化成Y-m-d格式日期
  175. // } else {
  176. // data[c.dataIndex] = '1970-01-01';//如果用户没输入日期,或输入有误,就给个默认日期,
  177. // //或干脆return;并且提示一下用户
  178. // }
  179. // } else if(c.xtype == 'numbercolumn'){//赋个默认值0吧,不然不好保存
  180. // if(data[c.dataIndex] == null || data[c.dataIndex] == ''){
  181. // data[c.dataIndex] = '0';
  182. // }
  183. // }
  184. // });
  185. jsonGridData[index++] = Ext.JSON.encode(data);
  186. }
  187. this.update(jsonGridData.toString());
  188. // }
  189. // else return;
  190. // }
  191. },
  192. update:function(param){
  193. Ext.Ajax.request({
  194. url: basePath+'fa/fix/updateAssetsPracticeSys.action',
  195. params:{
  196. param:param
  197. },
  198. success: function(response){
  199. var text = response.responseText;
  200. result = Ext.decode(text);
  201. if(result.success){
  202. Ext.Msg.alert("保存成功!"); // 尚未国际化,以后订正。
  203. }
  204. }
  205. });
  206. }
  207. });