package react.order; import react.ReactDOM; import react.ReactComponent; import react.ReactMacro.jsx; import Common; import react.product.Product; /** * A User order * @author fbarbut */ class Order extends react.ReactComponentOfPropsAndState<{order:UserOrder,onUpdate:UserOrder->Void,parentBox:react.order.OrderBox},{order:UserOrder,inputValue:String}> { var hasPayments :Bool; var currency : String; public function new(props) { super(props); state = {order:props.order,inputValue:null}; hasPayments = props.parentBox.props.hasPayments; currency = props.parentBox.props.currency; if (state.order.productUnit == null) state.order.productUnit = Piece; if (state.order.productQt == null) state.order.productQt = 1; state.inputValue = if ( isSmartQtInput(state.order) ){ Std.string(round(state.order.quantity * state.order.productQt)); }else{ Std.string(state.order.quantity); } } override public function render(){ var o = state.order; /*var unit = if (o.productHasFloatQt || o.productHasVariablePrice){ jsx('
${Formatting.unit(o.productUnit)}
'); }else{ jsx('
'); }*/ /* //use smart qt only if hasFloatQt var productName = if (o.productHasFloatQt || o.productHasVariablePrice){ jsx('
${o.productName}
'); }else{ jsx('
${o.productName} ${o.productQt} ${Formatting.unit(o.productUnit)}
'); } */ /*var productName = if (o.productHasFloatQt || o.productHasVariablePrice){ jsx('
${o.productName}
');*/ var input = if (isSmartQtInput(o)){ jsx('
${Formatting.unit(o.productUnit)}
'); }else{ jsx('
'); } var alternated = if(props.parentBox.props.contractType==0 && props.parentBox.state.users!=null){ //constant orders var options = props.parentBox.state.users.map(function(x) return jsx('') ); var checkbox = if(o.invertSharedOrder){ jsx(''); }else{ jsx(''); } jsx('
$checkbox
'); }else{ null; } return jsx('
<$Product productInfo=${o.product} />
${o.productRef}
${round(o.quantity * o.productPrice)} ${currency}
$input ${makeInfos()}
${paidInput()}
$alternated
'); } function round(f){ return Formatting.formatNum(f); } function paidInput(){ if(hasPayments) return null; if(state.order.paid){ return jsx('
'); }else{ return jsx('
'); } } function makeInfos(){ var o = state.order; return if ( isSmartQtInput(o) ){ jsx('
${round(o.quantity)} x ${o.productQt} ${Formatting.unit(o.productUnit)} ${o.productName}
'); }else{ null; } } function isSmartQtInput(o:UserOrder):Bool{ return o.product.hasFloatQt || o.product.variablePrice || o.product.wholesale; } function onChange(e:js.html.Event){ e.preventDefault(); var value :String = untyped (e.target.value == "") ? "0" : e.target.value; state.inputValue = value; var v = Formatting.parseFloat(value); var o = state.order; if ( isSmartQtInput(o) ){ //the value is a smart qt, so we need re-compute the quantity o.quantity = v / o.productQt; }else{ o.quantity = v; } this.setState(state); if (props.onUpdate != null) props.onUpdate(state.order); } function onChangePaid(e:js.html.Event){ state.order.paid = untyped e.target.checked; this.setState(state); if (props.onUpdate != null) props.onUpdate(state.order); } function onChangeInvert(e:js.html.Event){ state.order.invertSharedOrder = untyped e.target.checked; this.setState(state); if (props.onUpdate != null) props.onUpdate(state.order); } function onChangeUser2(e:js.html.Event){ var v = Std.parseInt(untyped e.target.value); state.order.userId2 = v==0 ? null : v; this.setState(state); if (props.onUpdate != null) props.onUpdate(state.order); } function onKeyPress(event:js.html.KeyboardEvent){ /*if(event.key == 'Enter'){ trace('enter !'); }*/ } }