Commit b76823b4 authored by Juorder Antonio's avatar Juorder Antonio

fire event to finish loading bar, add json stringify to data to send ajax

parent 876c7e6a
...@@ -14,6 +14,10 @@ export default class SalesForm extends React.Component { ...@@ -14,6 +14,10 @@ export default class SalesForm extends React.Component {
this.buildPurchase = this.buildPurchase.bind(this); this.buildPurchase = this.buildPurchase.bind(this);
this.confirmShipping = this.confirmShipping.bind(this); this.confirmShipping = this.confirmShipping.bind(this);
this.resetCounter = this.resetCounter.bind(this); this.resetCounter = this.resetCounter.bind(this);
this.onChangeValue = this.onChangeValue.bind(this);
this.onKeydownInput = this.onKeydownInput.bind(this);
this.isOnlyNumber = false;
const {name, attrs} = UserStore.getCurrentUser(); const {name, attrs} = UserStore.getCurrentUser();
const {displayName, cn, sn} = attrs._attrs; const {displayName, cn, sn} = attrs._attrs;
...@@ -47,12 +51,15 @@ export default class SalesForm extends React.Component { ...@@ -47,12 +51,15 @@ export default class SalesForm extends React.Component {
resetCounter() { resetCounter() {
const purchase = {}; const purchase = {};
const reset = this.mailboxes.forEach((plan) => { this.mailboxes.forEach((plan) => {
const isValidPlan = !this.avoidPlans.includes(plan);
if (isValidPlan) {
purchase[plan] = 0; purchase[plan] = 0;
}
}); });
this.setState({ this.setState({
purchase: reset purchase
}); });
} }
...@@ -60,12 +67,6 @@ export default class SalesForm extends React.Component { ...@@ -60,12 +67,6 @@ export default class SalesForm extends React.Component {
GlobalActions.emitEndLoading(); GlobalActions.emitEndLoading();
} }
onKeyupInput(event, label) {
const value = event.target.value;
this.checkAmount(label, value);
}
buildFullName(displayName, cn, sn) { buildFullName(displayName, cn, sn) {
const fullname = displayName && displayName.trim() !== '' ? displayName : `${cn} ${sn}`; const fullname = displayName && displayName.trim() !== '' ? displayName : `${cn} ${sn}`;
...@@ -92,11 +93,13 @@ export default class SalesForm extends React.Component { ...@@ -92,11 +93,13 @@ export default class SalesForm extends React.Component {
const allows = [8, 9, 37, 39, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105]; const allows = [8, 9, 37, 39, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105];
if (allows.includes(keycode)) { if (allows.includes(keycode)) {
return true; this.isOnlyNumber = true;
return this.isOnlyNumber;
} }
event.preventDefault(); event.preventDefault();
return null; this.isOnlyNumber = false;
return this.isOnlyNumber;
} }
buildPurchase(purchase) { buildPurchase(purchase) {
...@@ -149,8 +152,8 @@ export default class SalesForm extends React.Component { ...@@ -149,8 +152,8 @@ export default class SalesForm extends React.Component {
data.domain = name; data.domain = name;
data = JSON.stringify(data); data = JSON.stringify(data);
Client.requestMailboxes(data, (response) => { Client.requestMailboxes(data, (response) => {
const text = this.messageCode[response.messageCode];
this.resetCounter(); this.resetCounter();
const text = this.messageCode[response.messageCode];
sweetAlert('Compra éxitosa', text, 'success'); sweetAlert('Compra éxitosa', text, 'success');
}, (error) => { }, (error) => {
const text = this.messageCode[error.messageCode]; const text = this.messageCode[error.messageCode];
...@@ -161,6 +164,14 @@ export default class SalesForm extends React.Component { ...@@ -161,6 +164,14 @@ export default class SalesForm extends React.Component {
}, options); }, options);
} }
onChangeValue(event, input) {
const value = event.target.value;
if (this.isOnlyNumber) {
this.checkAmount(input, value);
}
}
renderInputs() { renderInputs() {
const {purchase} = this.state; const {purchase} = this.state;
return this.mailboxes.map((input, index) => { return this.mailboxes.map((input, index) => {
...@@ -177,8 +188,8 @@ export default class SalesForm extends React.Component { ...@@ -177,8 +188,8 @@ export default class SalesForm extends React.Component {
<input <input
type='text' type='text'
className='form-control' className='form-control'
defaultValue={value} value={value}
onKeyUp={(event) => this.onKeyupInput(event, input)} onChange={(event) => this.onChangeValue(event, input)}
onKeyDown={this.onKeydownInput} onKeyDown={this.onKeydownInput}
/> />
</div> </div>
...@@ -232,3 +243,24 @@ export default class SalesForm extends React.Component { ...@@ -232,3 +243,24 @@ export default class SalesForm extends React.Component {
SalesForm.propTypes = { SalesForm.propTypes = {
params: React.PropTypes.object params: React.PropTypes.object
}; };
>
<button
disabled={disabled}
className='btn btn-info'
onClick={this.confirmShipping}
>Comprar</button>
</div>
</div>
</form>
</Panel>
</div>
</div>
</div>
</div>
);
}
}
SalesForm.propTypes = {
params: React.PropTypes.object
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment