C_HtmlSelect.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. define( function() {
  2. "use strict";
  3. function C_HtmlSelect()
  4. {
  5. };
  6. C_HtmlSelect.prototype.draw = function( oControlHost )
  7. {
  8. var oParameter = oControlHost.getParameter( "pl" );
  9. var sParameterValue = ( oParameter && ( oParameter.values.length > 0 ) ) ? oParameter.values[0].use : "";
  10. var sHtml = '<select size="1" style="font-size:12pt;">';
  11. sHtml += '<option disabled="true">(Choose a product line)</option>';
  12. var iRowCount = this.m_oDataStore.rowCount;
  13. for ( var iRow = 0; iRow < iRowCount; iRow++ )
  14. {
  15. var sValue = this.m_oDataStore.getCellValue( iRow, 0 );
  16. var bSelected = sParameterValue && ( sValue == sParameterValue );
  17. sHtml += '<option ' + ( bSelected ? ' selected="true"' : '' ) + '>' + sValue + '</option>';
  18. }
  19. sHtml += '</select>';
  20. var el = oControlHost.container;
  21. el.innerHTML = sHtml;
  22. this.m_sel = el.querySelector( "*" );
  23. if ( !sParameterValue )
  24. {
  25. this.m_sel.selectedIndex = 0;
  26. }
  27. this.f_onChange( oControlHost );
  28. this.m_sel.onchange = this.f_onChange.bind( this, oControlHost, true );
  29. };
  30. C_HtmlSelect.prototype.f_onChange = function( oControlHost, bAutoSubmit )
  31. {
  32. oControlHost.valueChanged();
  33. if ( bAutoSubmit )
  34. {
  35. oControlHost.next();
  36. }
  37. };
  38. C_HtmlSelect.prototype.setData = function( oControlHost, oDataStore )
  39. {
  40. this.m_oDataStore = oDataStore;
  41. };
  42. C_HtmlSelect.prototype.getParameters = function()
  43. {
  44. if ( this.m_sel.selectedIndex < 1 )
  45. {
  46. return null;
  47. }
  48. var sValue = this.m_sel.options[this.m_sel.selectedIndex].value;
  49. return [{
  50. "parameter": "pl",
  51. "values": [{ "use" : sValue }]
  52. }];
  53. };
  54. C_HtmlSelect.prototype.isInValidState = function()
  55. {
  56. return ( this.m_sel.selectedIndex > 0 );
  57. };
  58. return C_HtmlSelect;
  59. });