AddDbfindTrigger.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /**
  2. * dbfind trigger
  3. * 支持带条件dbfind --之后往后添加
  4. */
  5. Ext.define('erp.view.core.trigger.AddDbfindTrigger', {
  6. extend: 'Ext.form.field.Trigger',
  7. alias: 'widget.adddbfindtrigger',
  8. triggerCls: 'x-form-search-trigger',
  9. initComponent: function() {
  10. this.addEvents({
  11. aftertrigger: true,
  12. beforetrigger: true
  13. });
  14. this.callParent(arguments);
  15. },
  16. listeners: {//功能:自动取数据(当前dbfind结果只有一条数据时,直接赋值,无需弹出window)
  17. focus: function(f){
  18. if(!f.readOnly) {
  19. var trigger = this;
  20. trigger.lastTriggerId = trigger.id;
  21. if(!trigger.ownerCt){
  22. if(!trigger.owner){
  23. var grid = Ext.ComponentQuery.query('gridpanel');
  24. Ext.Array.each(grid, function(g, index){
  25. Ext.Array.each(g.columns, function(column){
  26. if(column.dataIndex == trigger.name) {
  27. dbfind = column.dbfind;
  28. trigger.owner = g;
  29. }
  30. });
  31. });
  32. }
  33. if(trigger.owner.editingPlugin.activeEditor.field.id == trigger.id) {
  34. trigger.record = trigger.owner.editingPlugin.activeRecord;
  35. } else {
  36. trigger.record = trigger.owner.selModel.lastSelected;
  37. }
  38. var index = trigger.record.index;
  39. if(index != null){
  40. trigger.lastTriggerId = trigger.id + '---' + index;
  41. } else {
  42. trigger.lastTriggerId = null;
  43. }
  44. }
  45. }
  46. }
  47. },
  48. onTriggerClick: function() {
  49. var trigger = this, bool = true;// 放大镜所在
  50. bool = trigger.fireEvent('beforetrigger', trigger);
  51. if(bool == false) {
  52. return;
  53. }
  54. this.setFieldStyle('background:#C6E2FF;');
  55. var key = this.name,// name属性
  56. dbfind = '',// 需要dbfind的表和字段
  57. dbBaseCondition='',
  58. dbCondition='',
  59. dbGridCondition='',
  60. findConfig=this.findConfig,
  61. dbKey=this.dbKey,
  62. mappingKey=this.mappingKey,
  63. gridKey=this.gridKey,
  64. mappinggirdKey=this.mappinggirdKey;
  65. window.onTriggerClick = this.id;
  66. // 存在查询条件的字段
  67. if(findConfig){
  68. dbCondition = findConfig;
  69. }
  70. if(dbKey){
  71. var dbKeyValue = Ext.getCmp(dbKey).value;
  72. if(dbKeyValue){
  73. dbCondition = mappingKey + " IS '" + dbKeyValue + "'";
  74. } else {
  75. showError(this.dbMessage);
  76. return
  77. }
  78. }
  79. if(gridKey){
  80. var gridKeys = gridKey.split('|');
  81. var mappinggirdKeys = mappinggirdKey.split('|');
  82. var gridErrorMessages = this.gridErrorMessage.split('|');
  83. for(var i=0;i<gridKeys.length;i++){
  84. var gridkeyvalue = Ext.getCmp(gridKeys[i]).value;
  85. if(i==0){
  86. if(gridkeyvalue){
  87. dbGridCondition = mappinggirdKeys[i] + " IS '"+gridkeyvalue+"' ";
  88. }else{
  89. showError(gridErrorMessages[i]);
  90. return
  91. }
  92. }else{
  93. if(gridkeyvalue){
  94. dbGridCondition =dbGridCondition+" AND "+ mappinggirdKeys[i] + " IS '"+gridkeyvalue+"' ";
  95. }else{
  96. showError(gridErrorMessages[i]);
  97. return
  98. }
  99. }
  100. }
  101. }
  102. if(this.dbBaseCondition){
  103. dbBaseCondition = this.dbBaseCondition;
  104. }
  105. if(!trigger.ownerCt){// 如果是grid的dbfind
  106. var grid = Ext.ComponentQuery.query('gridpanel');
  107. Ext.Array.each(grid, function(g, index){
  108. Ext.Array.each(g.columns,function(column){
  109. if(column.dataIndex == key) {
  110. dbfind = column.dbfind;
  111. trigger.owner = g;
  112. }
  113. });
  114. });
  115. }
  116. var keyValue = this.value;// 当前值
  117. keyValue = keyValue == null ? '' : keyValue;
  118. var width = Ext.isIE ? screen.width*0.7*0.9 : '80%',
  119. height = Ext.isIE ? screen.height*0.75 : '95%';
  120. var dbwin = new Ext.window.Window({
  121. id : 'dbwin',
  122. title: '查找',
  123. height: height,
  124. width: width,
  125. maximizable : true,
  126. buttonAlign : 'center',
  127. layout : 'anchor',
  128. items: [{
  129. tag : 'iframe',
  130. frame : true,
  131. anchor : '100% 100%',
  132. layout : 'fit',
  133. html : '<iframe id="iframe_dbfind" src="'+basePath+'jsps/common/dbfind.jsp?dbkind=add&key='+key+"&dbfind="+dbfind+"&dbGridCondition="+dbGridCondition+"&dbCondition="+dbCondition+"&dbBaseCondition="+dbBaseCondition+"&keyValue="+encodeURIComponent(keyValue)+"&trigger="+trigger.id+ "&caller=" + caller + '" height="100%" width="100%" frameborder="0" scrolling="no"></iframe>'
  134. }],
  135. buttons : [{
  136. text : '关 闭',
  137. iconCls: 'x-button-icon-close',
  138. cls: 'x-btn-gray',
  139. handler : function(){
  140. Ext.getCmp('dbwin').close();
  141. }
  142. },{
  143. text: '重置条件',
  144. id: 'reset',
  145. cls: 'x-btn-gray',
  146. hidden: true,
  147. handler: function(){
  148. var grid = Ext.getCmp('dbwin').el.dom.getElementsByTagName('iframe')[0].contentWindow.document.defaultView.Ext.getCmp('dbfindGridPanel');
  149. grid.resetCondition();
  150. grid.getCount();
  151. }
  152. }]
  153. });
  154. dbwin.show();
  155. trigger.lastTriggerId = null;
  156. }
  157. });