MyGrid.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /**
  2. * form配置界面
  3. * checkbox Grid
  4. */
  5. Ext.define('erp.view.ma.MyGrid',{
  6. extend: 'Ext.grid.Panel',
  7. alias: 'widget.mygrid',
  8. layout : 'fit',
  9. id: 'grid',
  10. emptyText : $I18N.common.grid.emptyText,
  11. columnLines : true,
  12. autoScroll : true,
  13. store: [],
  14. columns: [],
  15. multiselected: new Array(),
  16. plugins: Ext.create('Ext.grid.plugin.CellEditing', {
  17. clicksToEdit: 1
  18. }),
  19. orderby: ' order by fd_detno',
  20. GridUtil: Ext.create('erp.util.GridUtil'),
  21. bbar: {
  22. xtype: 'erpToolbar',
  23. allowExtraButtons: false
  24. },
  25. initComponent : function(){
  26. gridCondition = getUrlParam('gridCondition');//从url解析参数
  27. gridCondition = (gridCondition == null) ? "" : gridCondition.replace(/IS/g,"=");
  28. if(gridCondition == ''){
  29. this.GridUtil.getGridColumnsAndStore(this, 'common/singleGridPanel.action',
  30. {caller: 'Form', condition: gridCondition, _m: 0});
  31. } else {
  32. this.getGridColumnsAndStore();
  33. }
  34. this.callParent(arguments);
  35. },
  36. /**
  37. * 根据主表的fo_table,拿到该表的所有字段
  38. * 以及配置在formdetail的字段
  39. */
  40. getGridColumnsAndStore: function(){
  41. var grid = this;
  42. var main = parent.Ext.getCmp("content-panel");
  43. if(!main)
  44. main = parent.parent.Ext.getCmp("content-panel");
  45. if(main){
  46. main.getActiveTab().setLoading(true);//loading...
  47. }
  48. Ext.Ajax.request({//拿到grid的columns
  49. url : basePath + 'common/singleGridPanel.action',
  50. async: false,
  51. params: {
  52. caller: 'Form',
  53. condition: gridCondition + grid.orderby,
  54. _m: 0
  55. },
  56. method : 'post',
  57. callback : function(options,success,response){
  58. if(main){
  59. main.getActiveTab().setLoading(false);
  60. }
  61. var res = new Ext.decode(response.responseText);
  62. if(res.exceptionInfo){
  63. showError(res.exceptionInfo);return;
  64. }
  65. if(res.columns){
  66. grid.columns = res.columns;
  67. grid.fields = res.fields;
  68. grid.columns.push({
  69. xtype: 'checkcolumn',
  70. text: '配置',
  71. width: 60,
  72. dataIndex: 'deploy',
  73. cls: "x-grid-header-1",
  74. locked: true,
  75. editor: {
  76. xtype: 'checkbox',
  77. cls: "x-grid-checkheader-editor"
  78. }
  79. });
  80. grid.fields.push({name: 'deploy', type: 'bool'});
  81. //renderer
  82. grid.getRenderer();
  83. var data = Ext.decode(res.data.replace(/,}/g, '}').replace(/,]/g, ']'));
  84. Ext.each(data, function(d){
  85. d.deploy = true;
  86. d.fd_readonly = d.fd_readonly == 'T';
  87. d.fd_dbfind = d.fd_dbfind == 'T';
  88. d.fd_allowblank = d.fd_allowblank == 'T';
  89. });
  90. grid.data = data;
  91. if(res.dbfinds.length > 0){
  92. grid.dbfinds = res.dbfinds;
  93. }
  94. //取数据字典配置
  95. if(data[0].fd_table){
  96. grid.getDataDictionaryData(data[0].fd_table);
  97. }
  98. }
  99. }
  100. });
  101. },
  102. getRenderer: function(){
  103. var grid = this;
  104. Ext.each(grid.columns, function(column, y){
  105. //logictype
  106. var logic = column.logic;
  107. if(logic != null){
  108. if(logic == 'detno'){
  109. grid.detno = column.dataIndex;
  110. } else if(logic == 'keyField'){
  111. grid.keyField = column.dataIndex;
  112. } else if(logic == 'mainField'){
  113. grid.mainField = column.dataIndex;
  114. } else if(logic == 'necessaryField'){
  115. grid.necessaryField = column.dataIndex;
  116. if(!grid.necessaryFields){
  117. grid.necessaryFields = new Array();
  118. }
  119. grid.necessaryFields.push(column.dataIndex);
  120. if(!column.haveRendered){
  121. column.renderer = function(val, meta, item){
  122. if(item.data['fd_id'] != null && item.data['fd_id'] != '' && item.data['fd_id'] != '0'
  123. && item.data['fd_id'] != 0) {
  124. return '<img src="' + basePath + 'resource/images/renderer/finishrecord.png">' +
  125. '<span style="color:blue;" title="已配置">' + val + '</span>';
  126. } else {
  127. return '<img src="' + basePath + 'resource/images/renderer/important.png">' +
  128. '<span style="color:red;" title="未配置">' + val + '</span>';
  129. }
  130. };
  131. }
  132. } else if(logic == 'groupField'){
  133. grid.groupField = column.dataIndex;
  134. }
  135. }
  136. });
  137. },
  138. reconfigureGrid: function(){
  139. var grid = this;
  140. grid.store = Ext.create('Ext.data.Store', {
  141. storeId: 'gridStore',
  142. fields: grid.fields,
  143. data: grid.data,
  144. groupField: grid.groupField
  145. });
  146. },
  147. getDataDictionaryData: function(tablename){
  148. var me = this,data = this.data;
  149. Ext.Ajax.request({
  150. url : basePath + 'ma/getDataDictionary.action',
  151. async: false,
  152. params: {
  153. table: tablename
  154. },
  155. method : 'post',
  156. callback : function(options,success,response){
  157. var res = new Ext.decode(response.responseText);
  158. if(res.exceptionInfo){
  159. showError(res.exceptionInfo);return;
  160. } else if(res.success) {
  161. me.dictionary = {tablename: res.datadictionary};
  162. //取Max(序号)
  163. var dets = Ext.Array.pluck(data, 'fd_detno');
  164. Ext.Array.sort(dets, function(a, b){
  165. return b - a;
  166. });
  167. var det = dets[0];
  168. //data里面包含的字段
  169. var sel = Ext.Array.pluck(data, 'fd_field');
  170. var o = null;
  171. Ext.each(res.datadictionary, function(d, index){
  172. //将DataDictionary的数据转化成FormDetail数据
  173. if(!Ext.Array.contains(sel, d.ddd_fieldname)){
  174. o = new Object();
  175. o.fd_table = d.ddd_tablename;
  176. o.fd_field = d.ddd_fieldname;
  177. o.fd_caption = d.ddd_description;
  178. o.fd_captionfan = d.ddd_description;
  179. o.fd_captionen = d.ddd_description;
  180. o.fd_readonly = false;
  181. o.fd_allowblank = true;
  182. o.fd_columnwidth = 1;
  183. o.fd_dbfind = false;
  184. o.deploy = false;
  185. if(contains(d.ddd_fieldtype, 'varchar2', true)){
  186. o.fd_type = 'S';
  187. } else if(contains(d.ddd_fieldtype, 'number', true)){
  188. o.fd_type = 'N';
  189. } else if(d.ddd_fieldtype == 'timestamp'){
  190. o.fd_type = 'DT';
  191. } else if(d.ddd_fieldtype == 'date'){
  192. o.fd_type = 'D';
  193. } else if(d.ddd_fieldtype == 'int'){
  194. o.fd_type = 'N';
  195. } else if(d.ddd_fieldtype == 'float'){
  196. o.fd_type = 'N';
  197. } else {
  198. o.fd_type = 'S';
  199. }
  200. o.fd_fieldlength = 100;
  201. o.fd_detno = ++det;
  202. data.push(o);
  203. }
  204. });
  205. me.reconfigureGrid();
  206. }
  207. }
  208. });
  209. },
  210. getDeleted: function(){
  211. var grid = this,items = grid.store.data.items,key = grid.keyField,deleted = new Array(),d = null;
  212. Ext.each(items, function(item){
  213. d = item.data;
  214. if(item.dirty && !Ext.isEmpty(d[key]) && d['deploy'] == false) {
  215. deleted.push(grid.removeKey(d, 'deploy'));
  216. }
  217. });
  218. return deleted;
  219. },
  220. getAdded: function(){
  221. var grid = this,items = grid.store.data.items,key = grid.keyField,added = new Array(),d = null;
  222. Ext.each(items, function(item){
  223. d = item.data;
  224. if(item.dirty && d[key] == 0 && d['deploy'] == true) {
  225. added.push(grid.removeKey(d, 'deploy'));
  226. }
  227. });
  228. return added;
  229. },
  230. getUpdated: function(){
  231. var grid = this,items = grid.store.data.items,key = grid.keyField,updated = new Array(),d = null;
  232. Ext.each(items, function(item){
  233. d = item.data;
  234. if(item.dirty && !Ext.isEmpty(d[key]) && d[key] != 0 && d['deploy'] == true) {
  235. updated.push(grid.removeKey(d, 'deploy'));
  236. }
  237. });
  238. return updated;
  239. },
  240. removeKey: function(d, key){
  241. var a = new Object(),keys = Ext.Object.getKeys(d);
  242. Ext.each(keys, function(k){
  243. if(k != key) {
  244. a[k] = d[k];
  245. if(k == 'fd_readonly' || k == 'fd_dbfind' || k == 'fd_allowblank') {
  246. a[k] = a[k] ? 'T' : 'F';
  247. }
  248. }
  249. });
  250. return a;
  251. },
  252. getChange: function(){
  253. var grid = this,items = grid.store.data.items,key = grid.keyField,
  254. added = new Array(),updated = new Array(),deleted = new Array(),d = null,e = null;
  255. Ext.each(items, function(item){
  256. d = item.data;
  257. if (item.dirty) {
  258. e = grid.removeKey(d, 'deploy');
  259. if(d[key] == 0 && d['deploy'] == true) {
  260. added.push(e);
  261. }
  262. if(!Ext.isEmpty(d[key]) && d[key] != 0 && d['deploy'] == true) {
  263. updated.push(e);
  264. }
  265. if(!Ext.isEmpty(d[key]) && d['deploy'] == false) {
  266. deleted.push(e);
  267. }
  268. }
  269. });
  270. return {
  271. added: added,
  272. updated: updated,
  273. deleted: deleted
  274. };
  275. }
  276. });