MyGrid.js.svn-base 8.9 KB

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