JobGrid.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. Ext.define('erp.view.sys.hr.JobGrid',{
  2. extend: 'Ext.grid.Panel',
  3. //store:Ext.data.StoreMgr.lookup('employeeStore'),
  4. alias: 'widget.jobgrid',
  5. id:'jobgrid',
  6. //selModel: new Ext.selection.CheckboxModel(),
  7. title:'岗位资料<span style="color:gray">(所有)</span>',
  8. columnLines: true,
  9. viewConfig: {
  10. stripeRows: true,
  11. enableTextSelection: true
  12. },
  13. initComponent : function(){
  14. var me=this;
  15. me.plugins = [me.cellEditingPlugin = Ext.create('Ext.grid.plugin.CellEditing',{
  16. clicksToEdit:1
  17. })];
  18. me.columns=[{
  19. dataIndex:'jo_id',
  20. width:0,
  21. text:'ID'
  22. },Ext.create('Ext.grid.RowNumberer',{
  23. width:35
  24. }),{
  25. dataIndex:'jo_code',
  26. width:100,
  27. text:'岗位编号',
  28. editor: {
  29. xtype: 'textfield',
  30. selectOnFocus: true,
  31. allowOnlyWhitespace: false,
  32. allowBlank:false
  33. },
  34. renderer:columnRequired
  35. },{
  36. dataIndex:'jo_name',
  37. width:120,
  38. text:'岗位名称',
  39. editor: {
  40. xtype: 'textfield',
  41. selectOnFocus: true,
  42. allowOnlyWhitespace: false,
  43. allowBlank:false
  44. },
  45. renderer:columnRequired
  46. },{
  47. dataIndex:'jo_orgcode',
  48. width:120,
  49. text:'所属组织编号'
  50. },{
  51. dataIndex:'jo_orgName',
  52. width:120,
  53. text:'所属组织名称'
  54. },{
  55. dataIndex:'jo_orgId',
  56. width:0,
  57. text:'组织ID'
  58. },{
  59. xtype:'actioncolumn',
  60. width:45,
  61. text :'操作',
  62. items:[{
  63. iconCls:'btn-delete',
  64. tooltip:'删除',
  65. width:75,
  66. handler:function(grid, rowIndex, colIndex) {
  67. Ext.Msg.confirm('删除数据?', '确定要删除当前选中行(行号:'+(rowIndex+1)+')?',
  68. function(choice) {
  69. if(choice === 'yes') {
  70. var record = grid.getStore().getAt(rowIndex),gridpanel=grid.ownerCt;
  71. gridpanel.removeDetail(gridpanel,record);
  72. }
  73. });
  74. }
  75. }]
  76. }];
  77. me.store=Ext.create('Ext.data.Store',{
  78. fields:[{name:'jo_id',type:'number'},
  79. {name:'jo_code',type:'string'},
  80. {name:'jo_name',type:'string'},
  81. {name:'jo_orgcode',type:'string'},
  82. {name:'jo_orgName',type:'string'},
  83. {name:'jo_orgId',type:'int'}],
  84. proxy: {
  85. type: 'ajax',
  86. url: basePath+'/hr/employee/getJobs.action',
  87. api: {
  88. create: basePath+'hr/employee/saveJobs.action',
  89. update: basePath+'hr/employee/updateJobs.action',
  90. },
  91. writer : {
  92. type : 'json',
  93. root : 'jsonData',
  94. encode : true,
  95. nameProperty:'data',
  96. allowSingle : false
  97. },
  98. reader: {
  99. type: 'json',
  100. root: 'jobs'
  101. }
  102. },
  103. autoLoad:me.storeAutoLoad
  104. });
  105. this.callParent(arguments);
  106. },
  107. loadNewStore: function(grid, param){
  108. var me = this;
  109. param=param||grid.params;
  110. grid.setLoading(true);//loading...
  111. Ext.Ajax.request({//拿到grid的columns
  112. url : basePath + "common/loadNewGridStore.action",
  113. params: param,
  114. method : 'post',
  115. callback : function(options,success,response){
  116. grid.setLoading(false);
  117. var res = new Ext.decode(response.responseText);
  118. if(res.exceptionInfo){
  119. showError(res.exceptionInfo);return;
  120. }
  121. var data = res.data;
  122. if(!data || data.length == 0){
  123. grid.store.removeAll();
  124. me.add10EmptyItems(grid);
  125. } else {
  126. grid.store.loadData(data);
  127. }
  128. //自定义event
  129. grid.addEvents({
  130. storeloaded: true
  131. });
  132. grid.fireEvent('storeloaded', grid, data);
  133. }
  134. });
  135. },
  136. removeDetail:function(grid,record){
  137. grid.setLoading(true);
  138. Ext.Ajax.request({
  139. url : basePath + 'hr/employee/deleteJob.action',
  140. params: {
  141. id: record.get('jo_id')
  142. },
  143. method : 'post',
  144. callback : function(options,success,response){
  145. grid.setLoading(false);
  146. var localJson = new Ext.decode(response.responseText);
  147. if(localJson.exceptionInfo){
  148. showError(localJson.exceptionInfo);return;
  149. }
  150. if(localJson.success){
  151. showResult('提示','删除成功!');
  152. grid.getStore().remove(record);
  153. /* var orgTree = Ext.getCmp('orgtree'),
  154. selectionModel=orgTree.getSelectionModel(),
  155. selectedList = selectionModel.getSelection()[0];
  156. grid.getStore().load({params:{
  157. orgid:selectedList.get('or_id')
  158. }});*/
  159. }
  160. }
  161. });
  162. },
  163. setColumns:function(columns){
  164. Ext.Array.each(columns,function(column){
  165. if(column.xtype=='yncolumn'){
  166. column.xtype='checkcolumn';
  167. column.editor= {
  168. xtype: 'checkbox',
  169. cls: 'x-grid-checkheader-editor'
  170. };
  171. }
  172. });
  173. return columns;
  174. },
  175. DetailUpdateSuccess:function(btn,type){
  176. var tabP=Ext.getCmp('saletabpanel'),_activeTab=tabP.activeTab;
  177. _activeTab.loadNewStore(_activeTab,_activeTab.params);
  178. var win=btn.up('window');
  179. if(win) win.close();
  180. },
  181. isVal:function(){
  182. var records=this.getStore().getModifiedRecords(),cm=this.columns,necessaryCM=new Array(),flag=true;
  183. Ext.Array.each(cm,function(c){
  184. if(c.editor && !c.editor.allowBlank){
  185. necessaryCM.push(c.dataIndex);
  186. }
  187. });
  188. Ext.Array.each(records,function(r){
  189. var o=r.data;
  190. for( n in o){
  191. if(Ext.Array.contains(necessaryCM,n) && !o[n]){
  192. flag=false;
  193. return flag;
  194. }
  195. }
  196. });
  197. return flag;
  198. }
  199. })