MyGrid.js 8.8 KB

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