v1.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * Get the search Type according to the current module and the current method.
  3. *
  4. * @access public
  5. * @return string
  6. */
  7. window.getGlobalSearchType = function()
  8. {
  9. if(vision == 'lite') return 'story';
  10. const appInfo = $.apps.getLastApp();
  11. if(!appInfo) return;
  12. const pageWindow = appInfo.iframe.contentWindow;
  13. if(pageWindow.globalSearchType)
  14. {
  15. if(typeof pageWindow.globalSearchType === 'function') return pageWindow.globalSearchType();
  16. return pageWindow.globalSearchType;
  17. }
  18. const moduleName = pageWindow.config.rawModule;
  19. const methodName = pageWindow.config.rawMethod;
  20. if(moduleName == 'product' && methodName == 'browse') return 'story';
  21. if(moduleName == 'my' || moduleName == 'user') return methodName;
  22. const projectMethod = 'task|story|bug|build';
  23. if(moduleName == 'project' && projectMethod.indexOf(methodName) != -1) return methodName;
  24. if(moduleName == 'execution' && projectMethod.indexOf(methodName) != -1) return methodName;
  25. if(!this.props.items.some(x => x.key === moduleName)) return 'bug';
  26. if(moduleName == 'search') return '';
  27. return moduleName;
  28. }
  29. function getSearchUrl(searchType, searchValue, callback)
  30. {
  31. if(typeof searchValue !== 'string') return;
  32. searchValue = searchValue.trim();
  33. if(!searchValue.length) return;
  34. let searchUrl = $.createLink('search', 'index');
  35. searchUrl += (searchUrl.indexOf('?') >= 0 ? '&' : '?') + 'words=' + encodeURIComponent(searchValue) + '&type=all';
  36. if(!searchType || searchType == 'all' || searchType == 'search' || /[^0-9]/.test(searchValue)) return callback(searchUrl);
  37. const types = searchType.split('-');
  38. const searchModule = types[0];
  39. const searchMethod = typeof(types[1]) == 'undefined' ? 'view' : types[1];
  40. searchUrl = $.createLink(searchModule, searchMethod, "id=" + searchValue);
  41. const assetType = ',story,issue,risk,opportunity,doc,';
  42. if(edition != 'max' || assetType.indexOf(',' + searchModule + ',') == -1) return callback(searchUrl);
  43. const link = $.createLink('index', 'ajaxGetViewMethod' , 'objectID=' + searchValue + '&objectType=' + searchModule);
  44. $.get(link, function(data)
  45. {
  46. if(data)
  47. {
  48. callback($.createLink('assetlib', data, "id=" + searchValue));
  49. }
  50. else
  51. {
  52. return callback(searchUrl);
  53. }
  54. });
  55. }
  56. window.handleGlobalSearch = function(type, search)
  57. {
  58. if(type == 'program') type = 'program-product';
  59. if(type == 'deploystep') type = 'deploy-viewstep';
  60. if(type == 'feedback' && vision != 'lite') type = 'feedback-adminView';
  61. getSearchUrl(type, search, searchUrl => openPage(searchUrl, null, {success: function(data)
  62. {
  63. if(data && typeof data === 'object' && !Array.isArray(data) && data.load && typeof data.load === 'object' && data.load.locate) data.load.locate = null;
  64. }}));
  65. };