From 4f2a7ab1200c24043e4353e76afb314ee3964902 Mon Sep 17 00:00:00 2001 From: Amam Mustofa Date: Mon, 18 Feb 2019 11:33:36 +0800 Subject: [PATCH 1/6] fix issue 1 about the default for duration date --- src/trade/tradeDialog.es6 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/trade/tradeDialog.es6 b/src/trade/tradeDialog.es6 index 8104bec3df..c7ec12954a 100644 --- a/src/trade/tradeDialog.es6 +++ b/src/trade/tradeDialog.es6 @@ -586,6 +586,9 @@ function init_state(available,root, dialog, symbol, contracts_for_spot) { .then(function(times){ const value_hour = times.close !== '--' ? times.close : '23:59:59'; state.date_expiry.value_hour = moment.utc(value_hour, 'HH:mm:ss').format('HH:mm'); + if (state.duration.value === 'Duration') { + state.date_expiry.value_date = moment.utc().format('YYYY-MM-DD'); + } state.date_expiry.value = moment.utc(state.date_expiry.value_date + ' ' + value_hour).unix(); state.barriers.update(); debounce(state.date_expiry.value, state.proposal.onchange); From a4e166aa00b7ce2398c4b59154d551fed2dd867e Mon Sep 17 00:00:00 2001 From: Amam Mustofa Date: Mon, 18 Feb 2019 18:31:33 +0800 Subject: [PATCH 2/6] add rivets binder to edit mindatepicker --- src/common/rivetsExtra.es6 | 4 ++++ src/trade/tradeDialog.es6 | 15 +++++++++++++++ src/trade/tradeDialog.html | 3 ++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/common/rivetsExtra.es6 b/src/common/rivetsExtra.es6 index 479b8b6134..407abeb54b 100644 --- a/src/common/rivetsExtra.es6 +++ b/src/common/rivetsExtra.es6 @@ -432,6 +432,10 @@ rv.binders.slider = { } } +rv.binders.mindatepicker = { + routine: (el, value) => $(el).datepicker('option', 'minDate', value) +} + /* trun input element in jquery-ui-datepicker */ rv.binders.datepicker = { priority: 94, diff --git a/src/trade/tradeDialog.es6 b/src/trade/tradeDialog.es6 index c7ec12954a..1a97ca0e64 100644 --- a/src/trade/tradeDialog.es6 +++ b/src/trade/tradeDialog.es6 @@ -286,6 +286,7 @@ function init_state(available,root, dialog, symbol, contracts_for_spot) { value_hour: moment.utc().format('HH:mm'), /* now utc in hh:mm format */ value: 0, /* epoch value of date+hour */ today_times: { open: '--', close: '--', disabled: false }, /* trading times for today */ + min_date: 0, onHourShow: function(hour) { /* for timepicker */ return validateHour({ hour, @@ -580,10 +581,16 @@ function init_state(available,root, dialog, symbol, contracts_for_spot) { /* contracts that are more not today must end at the market close time */ const { value_date } = state.date_expiry; const is_today = !moment.utc(value_date).isAfter(moment.utc(), 'day'); + if (!is_today) { state.date_expiry.today_times.disabled = true; trading_times_for(value_date, state.proposal.symbol) .then(function(times){ + if (state.duration_unit.array[0] && !hasIntradayUnit(state.duration_unit.array)) { + state.date_expiry.min_date = 1; + } else { + state.date_expiry.min_date = 0; + } const value_hour = times.close !== '--' ? times.close : '23:59:59'; state.date_expiry.value_hour = moment.utc(value_hour, 'HH:mm:ss').format('HH:mm'); if (state.duration.value === 'Duration') { @@ -596,6 +603,10 @@ function init_state(available,root, dialog, symbol, contracts_for_spot) { } else { if (date_or_hour !== state.date_expiry.value_hour) { state.date_expiry.update_times(); } + if (state.duration_unit.array[0] && !hasIntradayUnit(state.duration_unit.array)) { + state.date_expiry.min_date = 1; + state.date_expiry.value_date = moment.utc().add(1, 'days').format('YYYY-MM-DD'); + } state.date_expiry.value = moment.utc(state.date_expiry.value_date + ' ' + state.date_expiry.value_hour).unix(); state.barriers.update(); debounce(state.date_expiry.value, state.proposal.onchange); @@ -916,6 +927,10 @@ function init_state(available,root, dialog, symbol, contracts_for_spot) { return barrier && (barrier.startsWith('+') || barrier.startsWith('-')) ? true : false; } + function hasIntradayUnit(duration_unit_array) { + return duration_unit_array.some(unit => ['minutes', 'hours'].indexOf(unit) !== -1) + } + state.purchase.onclick = async function() { const categories_with_tick_chart = ['digits', 'callput', 'callputequal', 'asian', 'touchnotouch']; state.purchase.loading = true; diff --git a/src/trade/tradeDialog.html b/src/trade/tradeDialog.html index ddf03eebd9..1e403cd943 100644 --- a/src/trade/tradeDialog.html +++ b/src/trade/tradeDialog.html @@ -24,7 +24,7 @@