Show:

File: ia\factories\TextBoxFactory.js

  1. /**
  2. * Factory for creating text boxes.
  3. *
  4. * @author J Clare
  5. * @class ia.TextBoxFactory
  6. * @param {ia.ComponentConfig} config The component config.
  7. * @param {ia.Report} report The report object.
  8. * @param {Object} componentGroup Hash table containing the Data and Interaction Groups that the component belongs to:
  9. * {dataGroup:ia.DataGroup, interactionGroup:ia.InteractionGroup, comparisonInteractionGroup:ia.InteractionGroup}.
  10. */
  11. ia.TextBoxFactory = function(config, report, componentGroup)
  12. {
  13. var me = this;
  14.  
  15. // Data and Interaction groups that the components belongs to.
  16. var interactionGroup = componentGroup.interactionGroup;
  17. var dataGroup = componentGroup.dataGroup;
  18. var comparisonInteractionGroup = componentGroup.comparisonInteractionGroup;
  19.  
  20. // Event handlers.
  21.  
  22. // This code executes every time the data groups data has changed.
  23. dataGroup.addEventListener(ia.DataEvent.DATA_CHANGED, function(event)
  24. {
  25. me.update();
  26. });
  27.  
  28. // Components.
  29.  
  30. // Panel.
  31. var panel = report.getWidget(config.id);
  32.  
  33. // Text box.
  34. var textBox;
  35.  
  36. /**
  37. * Builds the component.
  38. *
  39. * @method build
  40. * @param {Function} callbackFunction Called on completion of function, with the component id as the parameter.
  41. */
  42. this.build = function(callbackFunction)
  43. {
  44. // Empty panel.
  45. panel.content.empty();
  46. textBox = new ia.TextBox(config.id);
  47. panel.append(textBox.container);
  48. report.addComponent(config.id, textbox);
  49.  
  50. if (callbackFunction !== undefined) callbackFunction.call(null, config.id);
  51. };
  52.  
  53. /**
  54. * Updates the component.
  55. *
  56. * @method update
  57. * @param {Function} callbackFunction Called on completion of function, with the component id as the parameter.
  58. */
  59. this.update = function(callbackFunction)
  60. {
  61. var text = '';
  62.  
  63. var propertyKey = config.getProperty("propertyKey");
  64. if (propertyKey !== undefined)
  65. {
  66. var indicator = dataGroup.indicator;
  67. var property = indicator.getProperty(propertyKey);
  68. if (property !== undefined) text = property;
  69. else text = '';
  70. }
  71. else if (config.getProperty("text"))
  72. {
  73. text = report.textSubstitution.formatMessage(config.getProperty("text"));
  74. }
  75. textBox.setHtml(text);
  76.  
  77. if (callbackFunction !== undefined) callbackFunction.call(null, config.id);
  78. };
  79.  
  80. /**
  81. * Renders the component.
  82. *
  83. * @method render
  84. * @param {Function} callbackFunction Called on completion of function, with the component id as the parameter.
  85. */
  86. this.render = function(callbackFunction)
  87. {
  88. if (callbackFunction !== undefined) callbackFunction.call(null, config.id);
  89. };
  90. };