IconPlaceholderView.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: Storytelling (C) Copyright IBM Corp. 2018, 2020
  5. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6. */
  7. define(['./PlaceholderView', 'text!./IconPlaceholder.html', '../../util/TextFitUtil', '../../../lib/@waca/core-client/js/core-client/utils/Utils', '../../../app/nls/StringResources', '../../../lib/@waca/dashboard-common/dist/lib/@ba-ui-toolkit/ba-graphics/dist/illustrations-js/text-widget_128', '../../../lib/@waca/dashboard-common/dist/lib/@ba-ui-toolkit/ba-graphics/dist/illustrations-js/build-visualization_200'], function (BaseClass, Template, TextFitUtil, Utils, stringResources, textWidget128, buildVis200) {
  8. var IconPlaceholderView = null;
  9. var ICON_PLACEHOLDERS = {
  10. text: {
  11. iconName: textWidget128.default.id,
  12. text: stringResources.get('textWidgetIconPlaceholderText')
  13. },
  14. list: {
  15. iconName: textWidget128.default.id,
  16. text: '\u2022 ' + stringResources.get('textWidgetIconPlaceholderText')
  17. },
  18. vis: {
  19. iconName: buildVis200.default.id,
  20. text: stringResources.get('visIconPlaceholderText')
  21. }
  22. };
  23. IconPlaceholderView = BaseClass.extend({
  24. templateString: Template,
  25. init: function init() {
  26. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  27. IconPlaceholderView.inherited('init', this, arguments);
  28. this.type = options.iconType || 'text';
  29. },
  30. render: function render() {
  31. var sHtml = this.dotTemplate({
  32. placeholderText: ICON_PLACEHOLDERS[this.type].text
  33. });
  34. this.$el.append(sHtml);
  35. this.resize();
  36. Utils.setIcon(this.$el.find('.placeholder .iconContainer'), ICON_PLACEHOLDERS[this.type].iconName);
  37. },
  38. show: function show() {
  39. IconPlaceholderView.inherited('show', this, arguments);
  40. this.fillText();
  41. },
  42. resize: function resize() {
  43. var maxHeight = 170;
  44. var maxWidth = 180;
  45. if (this.$el.height() < maxHeight || this.$el.width() < maxWidth) {
  46. this.$el.find('.placeholder').addClass('compact');
  47. } else {
  48. this.$el.find('.placeholder').removeClass('compact');
  49. }
  50. this.fillText();
  51. },
  52. fillText: function fillText() {
  53. var node = this.el.querySelector('.instructionText');
  54. // Return if node doesn't exist or its parent is hidden
  55. if (!node || node.parentElement.style.display === 'none') {
  56. return;
  57. }
  58. var options = {
  59. maxFontSize: 14,
  60. minFontSize: 1,
  61. multiLine: false,
  62. detectMultiLine: false,
  63. alignHoriz: true,
  64. widthOnly: true
  65. };
  66. TextFitUtil.fillText(node, options);
  67. }
  68. });
  69. return IconPlaceholderView;
  70. });
  71. //# sourceMappingURL=IconPlaceholderView.js.map