LabeledValueView.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2019
  5. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6. */
  7. define(['jquery', 'underscore', 'doT', '../../../lib/@waca/core-client/js/core-client/ui/core/View', 'text!./LabeledValue.html'], function ($, _, dot, View, LabeledValueTemplate) {
  8. var LabeledValueView = View.extend({
  9. templateString: LabeledValueTemplate,
  10. init: function init(options) {
  11. LabeledValueView.inherited('init', this, arguments);
  12. this.$el.addClass('labeled-value');
  13. this.dashboardApi = options.dashboardApi;
  14. this._value = options.value;
  15. this._valueStyle = options.valueStyle;
  16. this._showValueTranslationIcon = !!options.showValueTranslationIcon;
  17. this._label = options.label;
  18. this._labelStyle = options.labelStyle;
  19. this._showLabel = options.showLabel !== undefined ? options.showLabel : true;
  20. this._showLabelTranslationIcon = !!options.showLabelTranslationIcon;
  21. this._conditionalFormatting = options.conditionalFormatting;
  22. },
  23. remove: function remove() {
  24. this.$el.removeClass('labeled-value');
  25. LabeledValueView.inherited('remove', this, arguments);
  26. },
  27. render: function render() {
  28. this.$el.empty();
  29. this.$el.prepend(this.dotTemplate({
  30. value: this._value,
  31. valueStyle: this._valueStyle,
  32. label: this._label,
  33. labelStyle: this._labelStyle,
  34. showLabel: this._showLabel,
  35. shapeId: this._conditionalFormatting && this._conditionalFormatting.shapeId,
  36. shapeColor: this._conditionalFormatting && this._conditionalFormatting.color
  37. }));
  38. this._valueNode = this.$el.find('.labeled-value-value');
  39. this._labelNode = this.$el.find('.labeled-value-label');
  40. if (this.dashboardApi && (this._showValueTranslationIcon || this._showLabelTranslationIcon)) {
  41. var translationService = this.dashboardApi.getDashboardCoreSvc('TranslationService');
  42. if (this._showValueTranslationIcon) {
  43. translationService.appendTranslationIcon(this.$el.find('.labeled-value-value > span'));
  44. }
  45. if (this._showLabelTranslationIcon && this._showLabel) {
  46. translationService.appendTranslationIcon(this.$el.find('.labeled-value-label > span'));
  47. }
  48. }
  49. return Promise.resolve(this);
  50. },
  51. setValue: function setValue(value) {
  52. this._value = value;
  53. },
  54. setValueStyle: function setValueStyle(valueStyle) {
  55. this._valueStyle = valueStyle;
  56. },
  57. setShowValueTranslationIcon: function setShowValueTranslationIcon(iconPresent) {
  58. this._showValueTranslationIcon = iconPresent;
  59. },
  60. setLabel: function setLabel(label) {
  61. this._label = label;
  62. },
  63. setLabelStyle: function setLabelStyle(labelStyle) {
  64. this._labelStyle = labelStyle;
  65. },
  66. setShowLabel: function setShowLabel(showLabel) {
  67. this._showLabel = showLabel;
  68. },
  69. setShowLabelTranslationIcon: function setShowLabelTranslationIcon(iconPresent) {
  70. this._showLabelTranslationIcon = iconPresent;
  71. },
  72. setConditionalFormatting: function setConditionalFormatting(conditionalFormatting) {
  73. this._conditionalFormatting = conditionalFormatting;
  74. },
  75. getShowLabel: function getShowLabel() {
  76. return this._showLabel;
  77. },
  78. getValueNode: function getValueNode() {
  79. return this._valueNode;
  80. },
  81. getLabelNode: function getLabelNode() {
  82. return this._labelNode;
  83. },
  84. hasShape: function hasShape() {
  85. return !!(this._conditionalFormatting && this._conditionalFormatting.shapeId);
  86. }
  87. });
  88. return LabeledValueView;
  89. });
  90. //# sourceMappingURL=LabeledValueView.js.map