AddDbfindTrigger.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. dbCaller=this.dbCaller|| (typeof caller === 'undefined' ? '' : caller)
  65. mappinggirdKey=this.mappinggirdKey;
  66. window.onTriggerClick = this.id;
  67. // 存在查询条件的字段
  68. if(findConfig){
  69. dbCondition = findConfig;
  70. }
  71. if(dbKey){
  72. var dbKeyValue = Ext.getCmp(dbKey).value;
  73. if(dbKeyValue){
  74. dbCondition = mappingKey + " IS '" + dbKeyValue + "'";
  75. } else {
  76. showError(this.dbMessage);
  77. return
  78. }
  79. }
  80. if(gridKey){
  81. var gridKeys = gridKey.split('|');
  82. var mappinggirdKeys = mappinggirdKey.split('|');
  83. var gridErrorMessages = this.gridErrorMessage.split('|');
  84. for(var i=0;i<gridKeys.length;i++){
  85. var gridkeyvalue = Ext.getCmp(gridKeys[i]).value;
  86. if(i==0){
  87. if(gridkeyvalue){
  88. dbGridCondition = mappinggirdKeys[i] + " IS '"+gridkeyvalue+"' ";
  89. }else{
  90. showError(gridErrorMessages[i]);
  91. return
  92. }
  93. }else{
  94. if(gridkeyvalue){
  95. dbGridCondition =dbGridCondition+" AND "+ mappinggirdKeys[i] + " IS '"+gridkeyvalue+"' ";
  96. }else{
  97. showError(gridErrorMessages[i]);
  98. return
  99. }
  100. }
  101. }
  102. }
  103. if(this.dbBaseCondition){
  104. dbBaseCondition = this.dbBaseCondition;
  105. }
  106. if(!trigger.ownerCt){// 如果是grid的dbfind
  107. var grid = Ext.ComponentQuery.query('gridpanel');
  108. Ext.Array.each(grid, function(g, index){
  109. Ext.Array.each(g.columns,function(column){
  110. if(column.dataIndex == key) {
  111. dbfind = column.dbfind;
  112. trigger.owner = g;
  113. }
  114. });
  115. });
  116. }
  117. var keyValue = this.value;// 当前值
  118. keyValue = keyValue == null ? '' : keyValue;
  119. var width = Ext.isIE ? screen.width*0.7*0.9 : '80%',
  120. height = Ext.isIE ? screen.height*0.75 : '95%';
  121. var dbwin = new Ext.window.Window({
  122. id : 'dbwin',
  123. title: '查找',
  124. height: height,
  125. width: width,
  126. maximizable : true,
  127. buttonAlign : 'center',
  128. layout : 'anchor',
  129. items: [{
  130. tag : 'iframe',
  131. frame : true,
  132. anchor : '100% 100%',
  133. layout : 'fit',
  134. 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=" + dbCaller + '" height="100%" width="100%" frameborder="0" scrolling="no"></iframe>'
  135. }],
  136. buttons : [{
  137. text : '关 闭',
  138. iconCls: 'x-button-icon-close',
  139. cls: 'x-btn-gray',
  140. handler : function(){
  141. Ext.getCmp('dbwin').close();
  142. }
  143. },{
  144. text: '重置条件',
  145. id: 'reset',
  146. cls: 'x-btn-gray',
  147. hidden: true,
  148. handler: function(){
  149. var grid = Ext.getCmp('dbwin').el.dom.getElementsByTagName('iframe')[0].contentWindow.document.defaultView.Ext.getCmp('dbfindGridPanel');
  150. grid.resetCondition();
  151. grid.getCount();
  152. }
  153. }]
  154. });
  155. dbwin.show();
  156. trigger.lastTriggerId = null;
  157. }
  158. });