ConditionalStyle.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2016, 2019
  5. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6. */
  7. define(['../../lib/@waca/dashboard-common/dist/core/Model', '../../util/ColorUtils', 'jquery'], function (Model, ColorUtils, $) {
  8. 'use strict';
  9. /**
  10. * Model which represents a single color in a conditional format
  11. */
  12. var ConditionalStyle = Model.extend({
  13. whitelistAttrs: ['value'],
  14. init: function init() /* options */{
  15. ConditionalStyle.inherited('init', this, arguments);
  16. },
  17. getValue: function getValue() {
  18. return this.value;
  19. },
  20. setValue: function setValue(value, options) {
  21. this.set({ value: value }, options);
  22. },
  23. getColor: function getColor() {
  24. return this.color;
  25. },
  26. setColor: function setColor(color) {
  27. this.color = color;
  28. if (!this.color && this.bgcolor) {
  29. this.color = ColorUtils.invertColor(this.bgcolor);
  30. }
  31. },
  32. getBackgroundColor: function getBackgroundColor() {
  33. return this.bgcolor;
  34. },
  35. setBackgroundColor: function setBackgroundColor(bgcolor) {
  36. this.bgcolor = bgcolor;
  37. },
  38. getPattern: function getPattern() {
  39. return this.pattern;
  40. },
  41. setPattern: function setPattern(pattern) {
  42. if (pattern && pattern.indexOf(',') > -1) {
  43. var parts = pattern.split(', ');
  44. this.pattern = parts[0];
  45. this.patternSize = parts[1];
  46. } else {
  47. this.pattern = pattern;
  48. }
  49. },
  50. applyStyle: function applyStyle(element) {
  51. $(element).css('color', this.color);
  52. if (this.pattern) {
  53. $(element).css('background-image', 'url(dashboard-core/images/patterns/' + this.pattern + '.svg)');
  54. $(element).css('background-repeat', 'repeat');
  55. $(element).css('text-shadow', '2px 2px 2px ' + this.bgcolor + ', 2px -2px 2px' + this.bgcolor + ', 2px 0px 2px' + this.bgcolor + ',-2px 2px 2px' + this.bgcolor + ',-2px -2px 2px' + this.bgcolor + ',-2px 0px 2px' + this.bgcolor + ', 0px 2px 2px' + this.bgcolor + ', 0px -2px 2px' + this.bgcolor + ', 0px 0px 2px' + this.bgcolor);
  56. if (this.patternSize) {
  57. $(element).css('background-size', this.patternSize);
  58. }
  59. } else {
  60. $(element).css('background-color', this.bgcolor);
  61. }
  62. },
  63. //TODO: once the new grid is on, we should remove the applyStyle function
  64. getStyle: function getStyle() {
  65. var style = {
  66. 'color': this.color
  67. };
  68. if (this.pattern) {
  69. style['background-image'] = 'url(dashboard-core/images/patterns/' + this.pattern + '.svg)';
  70. style['background-repeat'] = 'repeat';
  71. style['text-shadow'] = '2px 2px 2px ' + this.bgcolor + ', 2px -2px 2px' + this.bgcolor + ', 2px 0px 2px' + this.bgcolor + ',-2px 2px 2px' + this.bgcolor + ',-2px -2px 2px' + this.bgcolor + ',-2px 0px 2px' + this.bgcolor + ', 0px 2px 2px' + this.bgcolor + ', 0px -2px 2px' + this.bgcolor + ', 0px 0px 2px' + this.bgcolor;
  72. if (this.patternSize) {
  73. style['background-size'] = this.patternSize;
  74. }
  75. } else {
  76. style['background-color'] = this.bgcolor;
  77. }
  78. return style;
  79. },
  80. clearStyle: function clearStyle() {
  81. this.setBackgroundColor('');
  82. this.setPattern('');
  83. this.setColor('');
  84. }
  85. });
  86. ConditionalStyle.clearStyleFromElement = function (element) {
  87. $(element).css({
  88. 'background-color': '',
  89. 'background-image': '',
  90. 'background-repeat': '',
  91. 'background-size': '',
  92. 'color': '',
  93. 'text-shadow': ''
  94. });
  95. };
  96. return ConditionalStyle;
  97. });
  98. //# sourceMappingURL=ConditionalStyle.js.map