Labels.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2014, 2020
  5. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6. */
  7. define(['../lib/@waca/core-client/js/core-client/ui/core/View', '../lib/@waca/core-client/js/core-client/i18n/Formatter', '../nls/StringResources', 'text!./templates/Labels.template', 'underscore'], function (View, Formatter, stringResources, template, _) {
  8. /**
  9. * Display a list of labels. Each label has a name and value.
  10. */
  11. var Labels = View.extend({
  12. templateString: template,
  13. init: function init(options) {
  14. Labels.inherited('init', this, arguments);
  15. this.labels = options.labels;
  16. this.title = options.title;
  17. this._formatter = options.formatter || Formatter;
  18. },
  19. /**
  20. * Draws the labels
  21. */
  22. render: function render() {
  23. var labels = [];
  24. if (this.labels) {
  25. for (var i = 0; i < this.labels.length; i++) {
  26. var label = this.labels[i];
  27. var value = this._getValue(label);
  28. var stringResourceName = value ? 'toolbarLabel' : 'toolbarNoValueLabel';
  29. labels.push({
  30. name: stringResources.get(stringResourceName, { labelName: _.escape(label.name) }),
  31. value: value
  32. });
  33. }
  34. }
  35. var sHtml = this.dotTemplate({ title: _.escape(this.title), labels: labels });
  36. this.$el.addClass('labels');
  37. this.$el.html(sHtml);
  38. },
  39. _getValue: function _getValue(label) {
  40. var value = label.value;
  41. var formatSpec = label.formatSpec;
  42. if (formatSpec && !isNaN(value)) {
  43. var _formatSpec = formatSpec.validFormatSpec || formatSpec.formatSpec;
  44. if (_formatSpec) {
  45. formatSpec = _formatSpec;
  46. }
  47. return this._formatter.format(value, formatSpec);
  48. } else {
  49. return value;
  50. }
  51. }
  52. });
  53. return Labels;
  54. });
  55. //# sourceMappingURL=Labels.js.map