C_HtmlSlider.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. define( ["text!./HtmlSlider.css"], function( sCSS ) {
  2. "use strict";
  3. function C_HtmlSlider()
  4. {
  5. };
  6. C_HtmlSlider.prototype.draw = function( oControlHost )
  7. {
  8. var sValueTextItem = oControlHost.configuration ? oControlHost.configuration["Value text item"] : "";
  9. this.m_oValueTextItem = sValueTextItem ? oControlHost.page.getControlByName( sValueTextItem ) : null;
  10. this.m_sParameter = oControlHost.configuration ? oControlHost.configuration.Parameter : "pMin";
  11. var sRangeType = ( oControlHost.configuration ? oControlHost.configuration["Range type"] : "" ) || "min";
  12. var oParameter = oControlHost.getParameter( this.m_sParameter );
  13. var sParameterValue = ( oParameter && ( oParameter.values.length > 0 ) ) ? oParameter.values[0].use : ( ( sRangeType == "min" ) ? this.m_max : this.m_min ) || 0;
  14. var sHtml = '<style>' + sCSS + '</style>';
  15. sHtml += '<input class="clsHtmlSlider" type="range" min="' + ( this.m_min || 0 ) + '" max="' + ( this.m_max || 100 ) + '" value="' + sParameterValue + '" rangeType="' + sRangeType + '"/>';
  16. var el = oControlHost.container;
  17. el.innerHTML = sHtml;
  18. this.m_input = el.querySelector( "input" );
  19. this.onChange( oControlHost );
  20. this.m_input.onchange = this.onChange.bind( this, oControlHost, false );
  21. this.m_input.onmouseup = this.onMouseUp.bind( this, oControlHost, true );
  22. };
  23. C_HtmlSlider.prototype.onChange = function( oControlHost, bAutoSubmit )
  24. {
  25. oControlHost.valueChanged();
  26. if ( this.m_oValueTextItem )
  27. {
  28. this.m_oValueTextItem.text = this.m_input.value;
  29. }
  30. if ( bAutoSubmit )
  31. {
  32. oControlHost.next();
  33. }
  34. };
  35. C_HtmlSlider.prototype.onMouseUp = function( oControlHost, bAutoSubmit )
  36. {
  37. this.onChange( oControlHost, bAutoSubmit );
  38. };
  39. C_HtmlSlider.prototype.setData = function( oControlHost, oDataStore )
  40. {
  41. this.m_min = oDataStore.getCellValue( 0, 0 );
  42. this.m_max = oDataStore.getCellValue( 0, 1 );
  43. };
  44. C_HtmlSlider.prototype.getParameters = function()
  45. {
  46. var sValue = this.m_input.value;
  47. return [{
  48. "parameter": this.m_sParameter,
  49. "values": [{ "use" : sValue }]
  50. }];
  51. };
  52. return C_HtmlSlider;
  53. });