MsdInfoGrid.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /**
  2. * ERP项目gridpanel通用样式1
  3. */
  4. Ext.define('erp.view.scm.product.MSDProduct.MsdInfoGrid',{
  5. extend: 'Ext.grid.Panel',
  6. alias: 'widget.msdInfoGridGrid',
  7. region: 'south',
  8. layout : 'fit',
  9. id: 'grid',
  10. emptyText : $I18N.common.grid.emptyText,
  11. columnLines : true,
  12. autoScroll : true,
  13. store: [],
  14. columns: [],
  15. tbar:[{
  16. xtype:'erpSaveButton'
  17. },{
  18. xtype:'erpDeleteButton'
  19. },{
  20. text: '操作日志',
  21. extend: 'Ext.Button',
  22. alias: 'widget.erpSaveButton',
  23. param: [],
  24. iconCls: 'x-button-icon-query',
  25. cls:'x-btn-gray',
  26. style: {
  27. marginLeft: '10px'
  28. },
  29. listeners:{
  30. click: function(btn){
  31. var grid = Ext.getCmp('grid');
  32. grid.getLogs();
  33. }
  34. }
  35. },'->',{
  36. xtype:'erpCloseButton'
  37. }],
  38. GridUtil: Ext.create('erp.util.GridUtil'),
  39. BaseUtil: Ext.create('erp.util.BaseUtil'),
  40. FormUtil: Ext.create('erp.util.FormUtil'),
  41. plugins: Ext.create('Ext.grid.plugin.CellEditing', {
  42. clicksToEdit: 1
  43. }),
  44. initComponent : function(){
  45. var gridCondition = this.BaseUtil.getUrlParam('gridCondition');
  46. gridCondition = (gridCondition == null || gridCondition == "null") ? "1=1" : gridCondition;
  47. var gridParam = {caller: caller, condition: gridCondition};
  48. this.GridUtil.getGridColumnsAndStore(this, 'common/singleGridPanel.action', gridParam, "");
  49. this.callParent(arguments);
  50. //给页面加上ctrl+alt+s键盘事件,自动跳转form配置界面
  51. this.addKeyBoardEvents();//监听Ctrl+Alt+S事件
  52. },
  53. getGridStore: function(){
  54. var grid = this;
  55. var jsonGridData = new Array();
  56. var s = grid.getStore().data.items;//获取store里面的数据
  57. for(var i=0;i<s.length;i++){//将grid里面各行的数据获取并拼成jsonGridData
  58. var data = s[i].data;
  59. if(s[i].dirty){
  60. var bool = true;
  61. Ext.each(grid.necessaryField, function(f){
  62. if(data[f] == null){
  63. bool = false;
  64. showError("有必填项未填写!代号:" + f);return;
  65. }
  66. });
  67. if(bool){
  68. Ext.each(grid.columns, function(c){
  69. if(c.xtype == 'numbercolumn'){//赋个默认值0吧,不然不好保存
  70. if(data[c.dataIndex] == null || data[c.dataIndex] == ''){
  71. data[c.dataIndex] = '0';//也可以从data里面去掉这些字段
  72. }
  73. }
  74. });
  75. jsonGridData.push(Ext.JSON.encode(data));
  76. }
  77. }
  78. }
  79. return jsonGridData;
  80. }, /**
  81. * 监听一些事件,
  82. * 如Ctrl+Alt+S
  83. */
  84. addKeyBoardEvents: function(){
  85. var me = this;
  86. if(Ext.isIE && !Ext.isIE11){
  87. document.body.attachEvent('onkeydown', function(){//ie的事件名称不同,也不支持addEventListener
  88. if(window.event.altKey && window.event.ctrlKey && window.event.keyCode == 83){
  89. if(Ext.ComponentQuery.query('gridpanel').length > 0){//有grid
  90. me.FormUtil.onAdd('form' + caller, 'Form配置维护(' + caller + ')', "jsps/ma/multiform.jsp?formCondition=fo_idIS" + me.fo_id +
  91. "&gridCondition=fd_foidIS" + me.fo_id + "&whoami=" + caller);
  92. }else if(Ext.ComponentQuery.query('formpanel').length == 0){
  93. me.FormUtil.onAdd('form' + caller, 'Form配置维护(' + caller + ')', "jsps/ma/multiform.jsp?formCondition=fo_idIS" + me.fo_id +
  94. "&gridCondition=fd_foidIS" + me.fo_id + "&whoami=" + caller);
  95. } else {
  96. me.FormUtil.onAdd('form' + caller, 'Form配置维护(' + caller + ')', "jsps/ma/form.jsp?formCondition=fo_idIS" + me.fo_id +
  97. "&gridCondition=fd_foidIS" + me.fo_id);
  98. }
  99. }
  100. });
  101. document.body.attachEvent("onmouseover", function(){
  102. if(window.event.ctrlKey){
  103. var e = window.event;
  104. me.Contextvalue = e.target.textContent == "" ? e.target.value : e.target.textContent;
  105. textarea_text = parent.document.getElementById("textarea_text");
  106. textarea_text.value = me.Contextvalue;
  107. textarea_text.focus();
  108. textarea_text.select();
  109. }
  110. });
  111. } else {
  112. document.body.addEventListener("keydown", function(e){
  113. if(Ext.isFF5){//firefox不支持window.event
  114. e = e || window.event;
  115. }
  116. if(e.altKey && e.ctrlKey && e.keyCode == 83){
  117. if(Ext.ComponentQuery.query('gridpanel').length > 0&&Ext.ComponentQuery.query('formpanel').length > 0){//有grid
  118. me.FormUtil.onAdd('form' + caller, 'Form配置维护(' + caller + ')', "jsps/ma/multiform.jsp?formCondition=fo_idIS" + me.fo_id +
  119. "&gridCondition=fd_foidIS" + me.fo_id + "&whoami=" + caller);
  120. }else if(Ext.ComponentQuery.query('formpanel').length == 0&&Ext.ComponentQuery.query('gridpanel').length > 0){//只有form
  121. me.FormUtil.onAdd('form' + caller, 'Form配置维护(' + caller + ')', "jsps/ma/multigrid.jsp?formCondition=fo_idIS" + me.fo_id +
  122. "&gridCondition=fd_foidIS" + me.fo_id + "&whoami=" + caller);
  123. } else {
  124. me.FormUtil.onAdd('form' + caller, 'Form配置维护(' + caller + ')', "jsps/ma/form.jsp?formCondition=fo_idIS" + me.fo_id +
  125. "&gridCondition=fd_foidIS" + me.fo_id);
  126. }
  127. }
  128. });
  129. document.body.addEventListener("mouseover", function(e){
  130. if(Ext.isFF5){
  131. e = e || window.event;
  132. }
  133. if(e.ctrlKey){
  134. me.Contextvalue = e.target.textContent == "" ? e.target.value : e.target.textContent;
  135. textarea_text = parent.document.getElementById("textarea_text");
  136. textarea_text.value = me.Contextvalue;
  137. textarea_text.focus();
  138. textarea_text.select();
  139. }
  140. });
  141. }
  142. },
  143. /**
  144. * 查询操作日志
  145. */
  146. getLogs: function() {
  147. if(Ext.getCmp('win' + caller)){
  148. Ext.getCmp('win' + caller).show();
  149. } else {
  150. Ext.Ajax.request({//拿到grid的columns
  151. url : basePath + 'common/getMessageLogs.action',
  152. async: false,
  153. params: {
  154. caller: caller,
  155. id: 0
  156. },
  157. method : 'post',
  158. callback : function(options,success,response){
  159. var res = new Ext.decode(response.responseText);
  160. if(res.exception || res.exceptionInfo){
  161. showError(res.exceptionInfo);
  162. return;
  163. }
  164. var logs = res.logs;
  165. logs = logs.length == 0 ? [{ml_date: $I18N.common.grid.emptyText, ml_man: $I18N.common.grid.emptyText,
  166. ml_content: $I18N.common.grid.emptyText, ml_result: $I18N.common.grid.emptyText}] : logs;
  167. Ext.create('Ext.window.Window', {
  168. id : 'win' + caller,
  169. title: '<span style="color:#CD6839;">操作日志</span>',
  170. iconCls: 'x-button-icon-set',
  171. closeAction: 'hide',
  172. height: "90%",
  173. width: "90%",
  174. maximizable : true,
  175. buttonAlign : 'center',
  176. layout : 'anchor',
  177. items: [{
  178. anchor: '100% 100%',
  179. xtype: 'gridpanel',
  180. ignore: true,
  181. bodyStyle: 'background:#f1f1f1;',
  182. autoScroll: true,
  183. store: Ext.create('Ext.data.Store', {
  184. fields: ['ml_date', 'ml_man', 'ml_content', 'ml_result'],
  185. data: logs
  186. }),
  187. columnLines: true,
  188. columns: [
  189. { header: '时间', dataIndex: 'ml_date', flex: 1.5 , renderer: function(val){
  190. if(val != '无数据'){
  191. return Ext.Date.format(new Date(val), 'Y-m-d H:i:s');
  192. }
  193. }},
  194. { header: '操作人员', dataIndex: 'ml_man', flex: 1 ,renderer: function(val){
  195. if(val == em_name){
  196. return '<font color=red>' + val + '</font>';
  197. } else {
  198. return val;
  199. }
  200. }},
  201. { header: '操作', dataIndex: 'ml_content', flex: 1.5},
  202. { header: '结果', dataIndex: 'ml_result', flex: 3}
  203. ]
  204. }],
  205. buttons : [{
  206. text : '关 闭',
  207. iconCls: 'x-button-icon-close',
  208. cls: 'x-btn-gray',
  209. handler : function(){
  210. Ext.getCmp('win' + caller).close();
  211. }
  212. }]
  213. }).show();
  214. }
  215. });
  216. }
  217. }
  218. });