Dbfind.js 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.common.Dbfind', {
  3. extend: 'Ext.app.Controller',
  4. views:[
  5. 'common.dbfind.GridPanel',
  6. 'common.dbfind.Toolbar',
  7. 'common.dbfind.Viewport','core.grid.YnColumn'
  8. ],
  9. requires: ['erp.util.BaseUtil'],
  10. init:function(){
  11. this.control({
  12. 'erpDbfindGridPanel': {
  13. itemclick: this.onGridItemClick
  14. }
  15. });
  16. },
  17. onGridItemClick: function(selModel, record){//grid行选择
  18. var keyValues = record.data;
  19. var triggerV = null;
  20. if(!trigger.hidden) {
  21. if(!trigger.ownerCt || trigger.column){//如果是grid的dbfind
  22. var grid = trigger.owner;
  23. //grid前面有checkboxModel 的 时候 grid的一行得到焦点的时候会把这一行的record放入grid 中的lastSelected
  24. //为了解决selected.items[0]保存的是checkboxModel中选择列的情况
  25. var select = grid.lastSelectedRecord || trigger.record || grid.getSelectionModel().selected.items[0]
  26. || grid.selModel.lastSelected;//selected的数据
  27. Ext.Array.each(record.fields.keys, function(k){
  28. Ext.Array.each(grid.dbfinds, function(ds){
  29. if(Ext.isEmpty(ds.trigger) || ds.trigger == trigger.name) {
  30. if(Ext.Array.contains(ds.dbGridField.split(';'), k)) {//k == ds.dbGridField//支持多dbgrid的字段对应grid同一字段
  31. if(ds.field == key){
  32. triggerV = keyValues[k];//trigger所在位置赋值
  33. }
  34. select.set(ds.field, keyValues[k]);
  35. }
  36. }
  37. });
  38. });
  39. } else {
  40. var ff;
  41. Ext.Array.each(record.fields.keys,function(k){
  42. Ext.Array.each(dbfinds,function(ds){
  43. if(k == ds.dbGridField) {
  44. if(ds.field && ds.field.indexOf(";")>0){
  45. Ext.Array.each(ds.field.split(";"),function(s){
  46. if(trigger.name == s || trigger.id == s){
  47. triggerV = keyValues[k];
  48. }
  49. ff = parent.Ext.getCmp(s);
  50. if(ff) ff.setValue(keyValues[k]);
  51. });
  52. }
  53. else if(ds.field && parent.Ext.getCmp(ds.field)){
  54. if(trigger.name == ds.field || trigger.id == ds.field){
  55. triggerV = keyValues[k];
  56. }
  57. ff = parent.Ext.getCmp(ds.field);
  58. //有时候会拿不到dbkind
  59. var dbtype=getUrlParam('dbkind');
  60. if(dbtype!=null&&dbtype=='add'&&ff.value!=null&&ff.value!="") {
  61. //判断当前值是否存在于已选择里面
  62. var arr=ff.value.split("#");
  63. if(arr.indexOf(keyValues[k])<0)
  64. keyValues[k]=ff.value+"#"+keyValues[k];
  65. else
  66. keyValues[k]=ff.value;
  67. if(trigger.name == ds.field || trigger.id == ds.field){
  68. triggerV = keyValues[k];
  69. }
  70. }
  71. ff.setValue(keyValues[k]);
  72. }
  73. }
  74. });
  75. });
  76. }
  77. }
  78. trigger.setValue(triggerV);
  79. trigger.fireEvent('aftertrigger', trigger, record, dbfinds);
  80. var win = parent.Ext.getCmp('dbwin');
  81. win && win.close();
  82. }
  83. });