DataWidgetSearchView.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2015, 2017
  5. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6. */
  7. /**
  8. * This is a toolbar view for searching in datawidgets
  9. */
  10. define(['../../lib/@waca/dashboard-common/dist/ui/SearchableListView', 'text!./DataWidgetSearch.html', 'app/nls/StringResources', 'jquery', 'underscore'], function (BaseView, Template, resources, $, _) {
  11. var View = null;
  12. View = BaseView.extend({
  13. templateString: Template,
  14. init: function init(options) {
  15. View.inherited('init', this, arguments);
  16. this.visualizations = {};
  17. _.extend(this, options || {});
  18. this.widget = this.content.getFeature('WidgetAPI.deprecated').getVisApi().ownerWidget;
  19. this.visualization = this.content.getFeature('Visualization');
  20. this.currentVis = this.visualization.getDefinition().getId();
  21. this.$el.addClass('searchPopoverContent');
  22. },
  23. onFlyoutDestroyed: function onFlyoutDestroyed() {
  24. this.searchData('');
  25. },
  26. getRenderedHtml: function getRenderedHtml() {
  27. var $content = $('<div class="toolbarPopoverContent"></div>');
  28. $content.append(this.$el);
  29. return $content;
  30. },
  31. getCustomRenderProperties: function getCustomRenderProperties() {
  32. return { searchText: resources.get('search') };
  33. },
  34. notifyRenderComplete: function notifyRenderComplete() {
  35. var $input = this.$el.find('input');
  36. $input.focus();
  37. },
  38. searchData: function searchData(searchTerm) {
  39. var slots = this.visualization.getSlots();
  40. var mappings = slots.getMappingInfoList();
  41. var columnId = mappings[0].dataItem.getColumnId();
  42. var filterKey = this.widget.visModelManager.searchFilters.getCategoryFilterKey(columnId);
  43. // trim leading and trailing space in the search term to match content-navigation search behavior
  44. // eg. searching ' pro ' finds 'product'
  45. searchTerm = searchTerm.trim();
  46. if (searchTerm.length > 0) {
  47. this.widget.visModelManager.searchFilters.updateFilterEntry(filterKey, { values: searchTerm, operator: 'containsignorecase' });
  48. } else {
  49. this.widget.visModelManager.searchFilters.removeFilterEntry(filterKey);
  50. }
  51. this.widget.visModelManager.searchFilters.allFilterModificationComplete({ payloadData: { skipUndoRedo: true } });
  52. }
  53. });
  54. return View;
  55. });
  56. //# sourceMappingURL=DataWidgetSearchView.js.map