KnowledgeSearch.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.oa.knowledge.KnowledgeSearch', {
  3. extend: 'Ext.app.Controller',
  4. requires: ['erp.util.FormUtil', 'erp.util.GridUtil', 'erp.util.BaseUtil', 'erp.util.RenderUtil'],
  5. BaseUtil:Ext.create('erp.util.BaseUtil'),
  6. views:[
  7. 'oa.knowledge.Recknowledge','common.datalist.Toolbar',
  8. 'oa.knowledge.KnowledgeSearchForm','oa.knowledge.KnowledgeSearchGrid','core.trigger.DbfindTrigger'
  9. ],
  10. init:function(){
  11. var grid=Ext.getCmp('grid');
  12. var me=this;
  13. this.control({
  14. 'erpSearchGridPanel': {
  15. //itemclick: me.onGridItemClick
  16. },
  17. 'textfield[id=search]':{
  18. change:function(){
  19. currentnum=1;
  20. me.onTextFieldChange(me);
  21. }
  22. },
  23. 'checkbox[id=regular]':{
  24. change:function(){
  25. me.regExpToggle(me);
  26. }
  27. },
  28. 'checkbox[id=case]':{
  29. change:function(){
  30. me.caseSensitiveToggle(me);
  31. }
  32. },
  33. 'button[id=prev]':{
  34. click:function(){
  35. me.onPreviousClick();
  36. }
  37. },
  38. 'button[id=next]':{
  39. click:function(){
  40. me.onNextClick();
  41. }
  42. },
  43. 'button[id=previous]':{
  44. click:function(){
  45. me.previous(me);
  46. }
  47. },
  48. 'button[id=nextone]':{
  49. click:function(){
  50. me.next(me);
  51. }
  52. }
  53. });
  54. },
  55. onTextFieldChange: function(base) {
  56. var me = Ext.getCmp('grid'),
  57. count = 0;
  58. me.view.refresh();
  59. me.searchValue = me.getSearchValue();
  60. me.indexes = [];
  61. me.currentIndex = null;
  62. if (me.searchValue !== null) {
  63. me.searchRegExp = new RegExp(me.searchValue, 'g' + (me.caseSensitive ? '' : 'i'));
  64. me.store.each(function(record, idx) {
  65. var td = Ext.fly(me.view.getNode(idx)).down('td'),
  66. cell, matches, cellHTML;
  67. while(td) {
  68. cell = td.down('.x-grid-cell-inner');
  69. matches = cell.dom.innerHTML.match(me.tagsRe);
  70. cellHTML = cell.dom.innerHTML.replace(me.tagsRe, me.tagsProtect);
  71. // populate indexes array, set currentIndex, and replace wrap matched string in a span
  72. cellHTML = cellHTML.replace(me.searchRegExp, function(m) {
  73. count += 1;
  74. if (Ext.Array.indexOf(me.indexes, idx) === -1) {
  75. me.indexes.push(idx);
  76. }
  77. if (me.currentIndex === null) {
  78. me.currentIndex = idx;
  79. }
  80. if(count==currentnum){
  81. return '<span class=" x-livesearch-matchbase">' + m + '</span>';
  82. }
  83. else return '<span class="' + me.matchCls + '">' + m + '</span>';
  84. });
  85. // restore protected tags
  86. Ext.each(matches, function(match) {
  87. cellHTML = cellHTML.replace(me.tagsProtect, match);
  88. });
  89. // update cell html
  90. cell.dom.innerHTML = cellHTML;
  91. td = td.next();
  92. }
  93. }, me);
  94. if (me.currentIndex !== null) {
  95. me.getSelectionModel().select(me.currentIndex);
  96. }
  97. }
  98. // no results found
  99. if (me.currentIndex === null) {
  100. me.getSelectionModel().deselectAll();
  101. }
  102. matchcount=count;
  103. if(count>2){
  104. Ext.getCmp('previous').setDisabled(false);
  105. Ext.getCmp('nextone').setDisabled(false);
  106. }else{
  107. Ext.getCmp('previous').setDisabled(true);
  108. Ext.getCmp('nextone').setDisabled(true);
  109. }
  110. if(count!=0){
  111. Ext.getCmp('matchs').setValue('第 '+currentnum+' 个,共 '+count+' 个');
  112. }else Ext.getCmp('matchs').reset();
  113. Ext.getCmp('search').focus();
  114. },
  115. caseSensitiveToggle: function(me,checkbox) {
  116. Ext.getCmp('grid').caseSensitive = Ext.getCmp('case').checked;
  117. me.onTextFieldChange();
  118. },
  119. regExpToggle: function(me,checkbox, checked) {
  120. Ext.getCmp('grid').regExpMode = Ext.getCmp('regular').checked;
  121. me.onTextFieldChange();
  122. },
  123. onPreviousClick: function() {
  124. var me = Ext.getCmp('grid'),
  125. idx;
  126. if ((idx = Ext.Array.indexOf(me.indexes, me.currentIndex)) !== -1) {
  127. me.currentIndex = me.indexes[idx - 1] || me.indexes[me.indexes.length - 1];
  128. me.getSelectionModel().select(me.currentIndex);
  129. }
  130. },
  131. onNextClick: function() {
  132. var me = Ext.getCmp('grid'),
  133. idx;
  134. if ((idx = Ext.Array.indexOf(me.indexes, me.currentIndex)) !== -1) {
  135. me.currentIndex = me.indexes[idx + 1] || me.indexes[0];
  136. me.getSelectionModel().select(me.currentIndex);
  137. }
  138. },
  139. previous:function(me){
  140. if(currentnum==1){
  141. currentnum=matchcount;
  142. }else currentnum=currentnum-1;
  143. me.onTextFieldChange();
  144. },
  145. next:function(me){
  146. if(currentnum==matchcount){
  147. currentnum=1;
  148. }else currentnum=currentnum+1;
  149. me.onTextFieldChange();
  150. },
  151. onGridItemClick: function(selModel, record){//grid行选择
  152. var me = this;
  153. var scanpersonid=record.data.kl_scanpersonid+'#';
  154. var authorid=record.data.kl_authorid;
  155. if(scanpersonid&&scanpersonid.indexOf(emid)<0&&authorid!=emid){
  156. //说明没有权限查看 需提出申请
  157. var win = new Ext.window.Window(
  158. {
  159. id : 'win',
  160. height : '350',
  161. width : '550',
  162. maximizable : true,
  163. buttonAlign : 'center',
  164. layout : 'anchor',
  165. items : [ {
  166. tag : 'iframe',
  167. frame : true,
  168. anchor : '100% 100%',
  169. layout : 'fit',
  170. html : '<iframe id="iframe_'+ caller+ '" src="'+ basePath+ 'jsps/oa/knowledge/KnowledgeForm.jsp?whoami=KnowledgeApply'+ '" height="100%" width="100%" frameborder="0" scrolling="no"></iframe>'
  171. } ],
  172. });
  173. win.show();
  174. return;
  175. }
  176. if(keyField != null && keyField != ''){//有些datalist不需要打开明细表,这些表在datalist表里面不用配dl_keyField
  177. var value = record.data[keyField];
  178. var formCondition = keyField + "IS" + value ;
  179. var gridCondition = pfField + "IS" + value;
  180. var mappingCondition='kl_kindidIS'+record.data.kl_kindid+' And '+keyField+'NO'+value;
  181. var panel = Ext.getCmp(caller + keyField + "=" + value);
  182. var main = parent.Ext.getCmp("content-panel");
  183. if(!main){
  184. main = parent.parent.Ext.getCmp("content-panel");
  185. }
  186. if(!panel){
  187. var title = "";
  188. if (value.toString().length>4) {
  189. title = value.toString().substring(value.toString().length-4);
  190. } else {
  191. title = value;
  192. }
  193. var myurl = '';
  194. if(me.BaseUtil.contains(url, '?', true)){
  195. myurl = url + '&formCondition='+formCondition+'&gridCondition='+gridCondition+'&mappingCondition='+mappingCondition;
  196. } else {
  197. myurl = url + '?formCondition='+formCondition+'&gridCondition='+gridCondition+'&mappingCondition='+mappingCondition;
  198. }
  199. myurl += "&datalistId=" + main.getActiveTab().id;
  200. main.getActiveTab().currentStore = me.getCurrentStore(value);//用于单据翻页
  201. panel = {
  202. title : me.BaseUtil.getActiveTab().title+'('+title+')',
  203. tag : 'iframe',
  204. tabConfig:{tooltip:me.BaseUtil.getActiveTab().tabConfig.tooltip+'('+keyField + "=" + value+')'},
  205. frame : true,
  206. border : false,
  207. layout : 'fit',
  208. iconCls : 'x-tree-icon-tab-tab1',
  209. html : '<iframe id="iframe_maindetail_'+caller+"_"+value+'" src="' + myurl + '" height="100%" width="100%" frameborder="0" scrolling="auto"></iframe>',
  210. closable : true,
  211. listeners : {
  212. close : function(){
  213. if(!main){
  214. main = parent.parent.Ext.getCmp("content-panel");
  215. }
  216. main.setActiveTab(main.getActiveTab().id);
  217. }
  218. }
  219. };
  220. this.openTab(panel, caller + keyField + "=" + record.data[keyField]);
  221. }else{
  222. main.setActiveTab(panel);
  223. }
  224. }
  225. },
  226. openTab : function (panel,id){
  227. var o = (typeof panel == "string" ? panel : id || panel.id);
  228. var main = parent.Ext.getCmp("content-panel");
  229. /*var tab = main.getComponent(o); */
  230. if(!main) {
  231. main =parent.parent.Ext.getCmp("content-panel");
  232. }
  233. var tab = main.getComponent(o);
  234. if (tab) {
  235. main.setActiveTab(tab);
  236. } else if(typeof panel!="string"){
  237. panel.id = o;
  238. var p = main.add(panel);
  239. main.setActiveTab(p);
  240. }
  241. },
  242. getCurrentStore: function(value){
  243. var grid = Ext.getCmp('grid');
  244. var items = grid.store.data.items;
  245. var array = new Array();
  246. var o = null;
  247. Ext.each(items, function(item, index){
  248. o = new Object();
  249. o.selected = false;
  250. if(index == 0){
  251. o.prev = null;
  252. } else {
  253. o.prev = items[index-1].data[keyField];
  254. }
  255. if(index == items.length - 1){
  256. o.next = null;
  257. } else {
  258. o.next = items[index+1].data[keyField];
  259. }
  260. var v = item.data[keyField];
  261. o.value = v;
  262. if(v == value)
  263. o.selected = true;
  264. array.push(o);
  265. });
  266. return array;
  267. }
  268. });