You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
2.2 KiB

  1. package react;
  2. import api.react.ReactMacro.jsx;
  3. import js.html.InputElement;
  4. import Common;
  5. typedef ComposerAppState = {
  6. products:Array<{id:Int,name:String,qt:Float,unit:UnitType}>
  7. }
  8. typedef ComposerAppRefs = {
  9. pi:ProductInput,
  10. productContainer:js.html.DivElement,
  11. qt:InputElement,
  12. unit:js.html.SelectElement,
  13. }
  14. /**
  15. * Composite product composer
  16. *
  17. */
  18. class ComposerApp extends ReactComponentOfStateAndRefs<ComposerAppState, ComposerAppRefs>
  19. {
  20. /*var products:Array<{id:Int,name:String,?qt:Float,?unit:UnitType}>;
  21. public function new(props:Dynamic)
  22. {
  23. super(props);
  24. products = [{id:1,name:"pipo"},{id:2,name:"Loclac"}];
  25. }
  26. override public function render(){
  27. return jsx('
  28. <div className="ComposerApp" style={{margin:"10px"}} >
  29. <div className="form-inline">
  30. <ProductInput ref="pi"/>
  31. <input ref="qt" onChange="$onChange" className="form-control" type="text" name="qt" placeholder="Quantité" />
  32. <select ref="unit" className="form-control" name="unit">
  33. ${getUnits()}
  34. </select>
  35. <a className="btn btn-primary" onClick=$addItem>
  36. <span className="glyphicon glyphicon-plus"></span> Ajouter
  37. </a>
  38. </div>
  39. <div className="container" ref="productContainer">
  40. ${createChildren()}
  41. </div>
  42. </div>
  43. ');
  44. }
  45. function onChange(){
  46. }
  47. function getUnits(){
  48. var out = [];
  49. for ( c in Unit.createAll()){
  50. out.push(jsx( '<option value="{c.getIndex()}"> {Std.string(c)} </option>'));
  51. }
  52. return out;
  53. }
  54. function createChildren()
  55. {
  56. return [for (p in products) jsx('<ProductComp key={p.id} name={p.name} qt={p.qt} unit={p.unit}/>')];
  57. }
  58. function addItem(){
  59. var text :String = refs.pi.refs.input.value;
  60. if (text.length > 0)
  61. {
  62. trace("add " + text);
  63. trace("qt " + this.refs.qt.value);
  64. trace("unit " + this.refs.unit.selectedIndex);
  65. var qt = Std.parseFloat(this.refs.qt.value);
  66. var unit = UnitType.createByIndex(this.refs.unit.selectedIndex);
  67. var id = Std.random(999);
  68. products.push( {id:id, name:text,qt:qt,unit:unit});
  69. setState({products:[{id:id,name:text, qt:qt, unit:unit}]});
  70. //this.forceUpdate();
  71. }
  72. }*/
  73. }