Labels.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2014, 2017
  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.html'], function (View, Formatter, stringResources, template) {
  8. var Labels = null;
  9. /**
  10. * Display a list of labels. Each label has a name and value.
  11. */
  12. Labels = View.extend({
  13. templateString: template,
  14. init: function init(options) {
  15. Labels.inherited('init', this, arguments);
  16. this.labels = options.labels;
  17. this.title = options.title;
  18. this._formatter = options.formatter || Formatter;
  19. },
  20. /**
  21. * Draws the labels
  22. */
  23. render: function render() {
  24. var labels = [];
  25. if (this.labels) {
  26. for (var i = 0; i < this.labels.length; i++) {
  27. var label = this.labels[i];
  28. var value = this._getValue(label);
  29. var stringResourceName = value ? 'toolbarLabel' : 'toolbarNoValueLabel';
  30. labels.push({
  31. name: stringResources.get(stringResourceName, { labelName: label.name }),
  32. value: value
  33. });
  34. }
  35. }
  36. var sHtml = this.dotTemplate({ title: this.title, labels: labels });
  37. this.$el.addClass('labels');
  38. this.$el.html(sHtml);
  39. },
  40. _getValue: function _getValue(label) {
  41. var value = label.value;
  42. var formatSpec = label.formatSpec;
  43. if (label.dataType === 'date') {
  44. value = this._formatter.formatDateTime(value, formatSpec);
  45. } else if (!isNaN(value) && value !== null) {
  46. value = this._formatter.formatNumber(value, formatSpec);
  47. }
  48. return value;
  49. }
  50. });
  51. return Labels;
  52. });
  53. //# sourceMappingURL=Labels.js.map