PropertyUIControlView.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. 'use strict';
  2. /*
  3. *+------------------------------------------------------------------------+
  4. *| Licensed Materials - Property of IBM
  5. *| IBM Cognos Products: Content Explorer
  6. *| (C) Copyright IBM Corp. 2017, 2019
  7. *|
  8. *| US Government Users Restricted Rights - Use, duplication or disclosure
  9. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  10. *+------------------------------------------------------------------------+
  11. */
  12. define(['../../lib/@waca/core-client/js/core-client/ui/core/View', '../../lib/@waca/core-client/js/core-client/ui/properties/PropertyUIControl'], function (View, PropertyUIControl) {
  13. /**
  14. Class that will takes a propertyUIControl spec and renders it
  15. **/
  16. var PropertyUIControlView = View.extend({
  17. /**
  18. options.glassContext
  19. options.items
  20. **/
  21. init: function init(options) {
  22. PropertyUIControlView.inherited('init', this, arguments);
  23. this.options = options || {};
  24. this._propertyUIControl = null;
  25. this._isMainPropertyUIControl = this.options.items && this.options.items[0].type === 'Banner';
  26. this.setFocus = this.options.onSetFocus;
  27. this.node = this.options.node;
  28. this.setPropertySpec(this.options.items);
  29. },
  30. setPropertySpec: function setPropertySpec(properties) {
  31. this._propertySpec = {
  32. 'el': this.node || this.$el,
  33. 'glassContext': this.options.glassContext,
  34. 'items': properties
  35. };
  36. if (this._isMainPropertyUIControl && properties && properties.length) {
  37. this._propertySpec.ariaLabel = properties[0].value;
  38. }
  39. this._propertySpec.primaryUIControl = false;
  40. if (this.options) {
  41. this._propertySpec.onCloseCb = this.options.onCloseCb || null;
  42. this._propertySpec.closeCallback = this.options.closeCallback || null;
  43. }
  44. },
  45. render: function render(isRefresh) {
  46. var _this = this;
  47. this.$el.parent().addClass('dashboardPropertiesPane');
  48. var promise = null;
  49. if (this._propertyUIControl) {
  50. promise = this._propertyUIControl.onClose().then(function () {
  51. _this._propertyUIControl.remove();
  52. _this.$el.empty();
  53. });
  54. } else {
  55. promise = Promise.resolve();
  56. }
  57. return promise.then(function () {
  58. if (!_this._propertySpec || !_this._propertySpec.items || !_this._propertySpec.items.length) {
  59. return Promise.resolve();
  60. }
  61. _this._propertyUIControl = new PropertyUIControl(_this._propertySpec);
  62. return _this._propertyUIControl.render().then(function () {
  63. if (_this._isMainPropertyUIControl && !isRefresh) {
  64. _this._propertyUIControl.focus();
  65. }
  66. if (_this.options && _this.options.renderCallback) {
  67. _this.options.renderCallback();
  68. }
  69. if (_this._propertySpec) {
  70. _this._showMissingTranslationsIcon(_this._propertySpec.items);
  71. }
  72. return _this._propertyUIControl;
  73. });
  74. });
  75. },
  76. getPropertyUIControl: function getPropertyUIControl() {
  77. return this._propertyUIControl;
  78. },
  79. onClose: function onClose() {
  80. return this._propertyUIControl.onClose();
  81. },
  82. /**
  83. * recursively go through the properties. If a property has a method called 'appedTranslationIcon' defined,
  84. * then call it passing the property node. Note, that method will only be defined when we're in translation mode
  85. * and the translation for the current locale is missing.
  86. */
  87. _showMissingTranslationsIcon: function _showMissingTranslationsIcon(items) {
  88. items.forEach(function (property) {
  89. if (property.items) {
  90. this._showMissingTranslationsIcon(property.items);
  91. } else if (property.appendTranslationIcon && (!property.translationIconNode || property.translationIconNode.length === 0)) {
  92. // Save the node so we can use it to remove the marker on property change
  93. property.translationIconNode = this.$el.find('.property_' + property.id);
  94. property.appendTranslationIcon(property.translationIconNode);
  95. }
  96. }.bind(this));
  97. },
  98. remove: function remove() {
  99. if (this._propertyUIControl) {
  100. this._propertyUIControl.remove();
  101. this._propertyUIControl = null;
  102. }
  103. this._propertySpec = null;
  104. this.options = null;
  105. }
  106. });
  107. return PropertyUIControlView;
  108. });
  109. //# sourceMappingURL=PropertyUIControlView.js.map