From 8ce124f6d6c93d62ab44827c330d2ab15033b441 Mon Sep 17 00:00:00 2001 From: Khalid Ibrahim Date: Mon, 27 May 2019 13:37:02 +0800 Subject: [PATCH 1/9] fixed dragging issues --- src/windows/tracker.es6 | 3 +++ src/windows/windows.es6 | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/windows/tracker.es6 b/src/windows/tracker.es6 index 9ed4cc4404..a26569fa9a 100644 --- a/src/windows/tracker.es6 +++ b/src/windows/tracker.es6 @@ -225,6 +225,9 @@ export const track = (options, blankWindow) => { save_states(); }); blankWindow.on('dialogextendrestore',() => { + dialog.draggable({ + containment: false, + }) state.position.offset = dialog.offset(); state.position.mode = 'normal'; save_states(); diff --git a/src/windows/windows.es6 b/src/windows/windows.es6 index 73b2839e36..71fc906a97 100644 --- a/src/windows/windows.es6 +++ b/src/windows/windows.es6 @@ -331,13 +331,18 @@ export const createBlankWindow = function($html,options) { dialog.on('dragstop', () => { const top = dialog.offset().top; const left = dialog.offset().left; + const dialogWidth = blankWindow.dialog( "option", "width" ); + const windowWidth = $(window).width(); - if (top < 0) { - dialog.animate({ top: '0px' }, 300, dialog.trigger.bind(dialog, 'animated')); + if (top < 106) { + dialog.animate({ top: '106px' }, 300, dialog.trigger.bind(dialog, 'animated')); } if (left < 0) { dialog.animate({ left: '0px' }, 300, dialog.trigger.bind(dialog, 'animated')); } + if (left + dialogWidth > windowWidth) { + dialog.animate({ left: `${windowWidth - dialogWidth - 20}px` }, 300, dialog.trigger.bind(dialog, 'animated')); + } }); if(options.destroy) { /* register for destroy event which have been patched */ From 8d7b78d466688b17694078fafbc4da8dbab57f52 Mon Sep 17 00:00:00 2001 From: Khalid Ibrahim Date: Mon, 27 May 2019 16:04:11 +0800 Subject: [PATCH 2/9] cleaner code --- src/windows/tracker.es6 | 4 +--- src/windows/windows.es6 | 11 ++++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/windows/tracker.es6 b/src/windows/tracker.es6 index a26569fa9a..904dce58f9 100644 --- a/src/windows/tracker.es6 +++ b/src/windows/tracker.es6 @@ -225,9 +225,7 @@ export const track = (options, blankWindow) => { save_states(); }); blankWindow.on('dialogextendrestore',() => { - dialog.draggable({ - containment: false, - }) + dialog.draggable({ containment: false }) state.position.offset = dialog.offset(); state.position.mode = 'normal'; save_states(); diff --git a/src/windows/windows.es6 b/src/windows/windows.es6 index 71fc906a97..e03bbaf680 100644 --- a/src/windows/windows.es6 +++ b/src/windows/windows.es6 @@ -329,19 +329,20 @@ export const createBlankWindow = function($html,options) { dialog.draggable( "option", "scroll", true ); } dialog.on('dragstop', () => { - const top = dialog.offset().top; - const left = dialog.offset().left; + const top = dialog.offset().top; + const left = dialog.offset().left; const dialogWidth = blankWindow.dialog( "option", "width" ); const windowWidth = $(window).width(); + const navHeight = $('#nav-menu .container').height(); - if (top < 106) { - dialog.animate({ top: '106px' }, 300, dialog.trigger.bind(dialog, 'animated')); + if (top < navHeight + 36) { + dialog.animate({ top: `${navHeight + 36}px` }, 300, dialog.trigger.bind(dialog, 'animated')); } if (left < 0) { dialog.animate({ left: '0px' }, 300, dialog.trigger.bind(dialog, 'animated')); } if (left + dialogWidth > windowWidth) { - dialog.animate({ left: `${windowWidth - dialogWidth - 20}px` }, 300, dialog.trigger.bind(dialog, 'animated')); + dialog.animate({ left: `${windowWidth - dialogWidth - 10}px` }, 300, dialog.trigger.bind(dialog, 'animated')); } }); From 73a18834d88966ee269693881fde48b6e88064c4 Mon Sep 17 00:00:00 2001 From: Khalid Ibrahim Date: Thu, 30 May 2019 16:25:14 +0800 Subject: [PATCH 3/9] changed datatype of relevant variables --- src/common/rivetsExtra.es6 | 2 +- src/viewtransaction/viewTransaction.es6 | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/common/rivetsExtra.es6 b/src/common/rivetsExtra.es6 index 1e17043177..b4c1a5fce5 100644 --- a/src/common/rivetsExtra.es6 +++ b/src/common/rivetsExtra.es6 @@ -61,7 +61,7 @@ rv.formatters['gt'] = (vlaue, other) => vlaue > other; /* rivets formatter for < operator */ rv.formatters['lt'] = (vlaue, other) => vlaue < other; /* localise price format*/ -rv.formatters['format-price'] = (value, currency) => (value) ? formatPrice(value, currency) : undefined; +rv.formatters['format-price'] = (value, currency) => (value != undefined) ? formatPrice(value, currency) : undefined; /* comma added format*/ rv.formatters['add-comma'] = (value, decimal_points) => (value) ? addComma(value, decimal_points) : undefined; /* rivets formater to capitalize string */ diff --git a/src/viewtransaction/viewTransaction.es6 b/src/viewtransaction/viewTransaction.es6 index a22f7387f7..de5f0573a3 100644 --- a/src/viewtransaction/viewTransaction.es6 +++ b/src/viewtransaction/viewTransaction.es6 @@ -240,9 +240,9 @@ const updateIndicative = (data, state) => { state.proposal_open_contract.exit_tick = contract.exit_tick; state.proposal_open_contract.exit_tick_time = contract.exit_tick_time; state.proposal_open_contract.date_expiry = contract.date_expiry; - state.proposal_open_contract.sell_price = contract.sell_price; + state.proposal_open_contract.sell_price = contract.sell_price.toString(); state.proposal_open_contract.is_valid_to_sell = contract.is_valid_to_sell; - state.proposal_open_contract.barrier = contract.barrier; + state.proposal_open_contract.barrier = parseFloat(contract.barrier); state.proposal_open_contract.high_barrier = contract.high_barrier; state.proposal_open_contract.low_barrier = contract.low_barrier; @@ -487,6 +487,8 @@ const initState = (proposal, root) => { }, proposal_open_contract: { ...proposal, + sell_price: proposal.sell_price.toString(), + barrier: parseFloat(proposal.barrier), currency: (proposal.currency || 'USD') + ' ', is_ended: proposal.is_settleable || proposal.is_sold || proposal.status !== 'open', is_sold_at_market: false, From 4d90c5199a8394860e09de671abac505363cb4bf Mon Sep 17 00:00:00 2001 From: Khalid Ibrahim Date: Thu, 30 May 2019 17:24:57 +0800 Subject: [PATCH 4/9] removed unnecessary condition --- src/common/rivetsExtra.es6 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/rivetsExtra.es6 b/src/common/rivetsExtra.es6 index b4c1a5fce5..1e17043177 100644 --- a/src/common/rivetsExtra.es6 +++ b/src/common/rivetsExtra.es6 @@ -61,7 +61,7 @@ rv.formatters['gt'] = (vlaue, other) => vlaue > other; /* rivets formatter for < operator */ rv.formatters['lt'] = (vlaue, other) => vlaue < other; /* localise price format*/ -rv.formatters['format-price'] = (value, currency) => (value != undefined) ? formatPrice(value, currency) : undefined; +rv.formatters['format-price'] = (value, currency) => (value) ? formatPrice(value, currency) : undefined; /* comma added format*/ rv.formatters['add-comma'] = (value, decimal_points) => (value) ? addComma(value, decimal_points) : undefined; /* rivets formater to capitalize string */ From 5ea24a0a5045a80ab50d7e793f2319857cde8828 Mon Sep 17 00:00:00 2001 From: Khalid Ibrahim Date: Fri, 31 May 2019 15:05:57 +0800 Subject: [PATCH 5/9] changed conditions --- src/common/rivetsExtra.es6 | 8 +++++--- src/viewtransaction/viewTransaction.es6 | 7 +++---- src/viewtransaction/viewTransaction.html | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/common/rivetsExtra.es6 b/src/common/rivetsExtra.es6 index 1e17043177..47351cbebc 100644 --- a/src/common/rivetsExtra.es6 +++ b/src/common/rivetsExtra.es6 @@ -60,10 +60,12 @@ rv.formatters['and-not'] = (vlaue, other) => vlaue && !other; rv.formatters['gt'] = (vlaue, other) => vlaue > other; /* rivets formatter for < operator */ rv.formatters['lt'] = (vlaue, other) => vlaue < other; +/* rivets formatter to check if a variable has value */ +rv.formatters['has-value'] = (value) => value != null; /* localise price format*/ -rv.formatters['format-price'] = (value, currency) => (value) ? formatPrice(value, currency) : undefined; +rv.formatters['format-price'] = (value, currency) => (value != null) ? formatPrice(value, currency) : undefined; /* comma added format*/ -rv.formatters['add-comma'] = (value, decimal_points) => (value) ? addComma(value, decimal_points) : undefined; +rv.formatters['add-comma'] = (value, decimal_points) => (parseFloat(value)) ? addComma(value, decimal_points) : undefined; /* rivets formater to capitalize string */ rv.formatters.capitalize = { read: (value) => _.capitalize(value), @@ -151,7 +153,7 @@ rv.formatters['bold-last-character'] = (str) => { } /* formatter to calcualte the percent of a value of another value */ rv.formatters['percent-of'] = (changed, original) => { - if(!changed || !original) return undefined; + if(!(changed != null) || !original) return undefined; const percentage_of_amount = (100*(changed - original)/original).toFixed(2); if (percentage_of_amount > 0) { return `+${percentage_of_amount}%`; diff --git a/src/viewtransaction/viewTransaction.es6 b/src/viewtransaction/viewTransaction.es6 index de5f0573a3..47a0f5efb3 100644 --- a/src/viewtransaction/viewTransaction.es6 +++ b/src/viewtransaction/viewTransaction.es6 @@ -240,9 +240,9 @@ const updateIndicative = (data, state) => { state.proposal_open_contract.exit_tick = contract.exit_tick; state.proposal_open_contract.exit_tick_time = contract.exit_tick_time; state.proposal_open_contract.date_expiry = contract.date_expiry; - state.proposal_open_contract.sell_price = contract.sell_price.toString(); + state.proposal_open_contract.sell_price = contract.sell_price; state.proposal_open_contract.is_valid_to_sell = contract.is_valid_to_sell; - state.proposal_open_contract.barrier = parseFloat(contract.barrier); + state.proposal_open_contract.barrier = contract.barrier; state.proposal_open_contract.high_barrier = contract.high_barrier; state.proposal_open_contract.low_barrier = contract.low_barrier; @@ -487,8 +487,7 @@ const initState = (proposal, root) => { }, proposal_open_contract: { ...proposal, - sell_price: proposal.sell_price.toString(), - barrier: parseFloat(proposal.barrier), + sell_price: proposal.sell_price, currency: (proposal.currency || 'USD') + ' ', is_ended: proposal.is_settleable || proposal.is_sold || proposal.status !== 'open', is_sold_at_market: false, diff --git a/src/viewtransaction/viewTransaction.html b/src/viewtransaction/viewTransaction.html index 2d0f6dbafe..2c03d2cdf3 100644 --- a/src/viewtransaction/viewTransaction.html +++ b/src/viewtransaction/viewTransaction.html @@ -95,7 +95,7 @@

Exit spot

rv-data-balloon='"return"' class="dotted-underline smaller"> -
+

Final Price


From e3f1656ddaff93ff2ba5d976b94d3881846d007d Mon Sep 17 00:00:00 2001 From: Khalid Ibrahim Date: Fri, 31 May 2019 15:07:56 +0800 Subject: [PATCH 6/9] Update viewTransaction.es6 --- src/viewtransaction/viewTransaction.es6 | 1 - 1 file changed, 1 deletion(-) diff --git a/src/viewtransaction/viewTransaction.es6 b/src/viewtransaction/viewTransaction.es6 index 47a0f5efb3..a22f7387f7 100644 --- a/src/viewtransaction/viewTransaction.es6 +++ b/src/viewtransaction/viewTransaction.es6 @@ -487,7 +487,6 @@ const initState = (proposal, root) => { }, proposal_open_contract: { ...proposal, - sell_price: proposal.sell_price, currency: (proposal.currency || 'USD') + ' ', is_ended: proposal.is_settleable || proposal.is_sold || proposal.status !== 'open', is_sold_at_market: false, From d8ec3b3fb7a5adee3255c93619ed55b620ccb07c Mon Sep 17 00:00:00 2001 From: Khalid Ibrahim Date: Fri, 7 Jun 2019 17:33:12 +0800 Subject: [PATCH 7/9] better conditions --- src/common/rivetsExtra.es6 | 40 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/common/rivetsExtra.es6 b/src/common/rivetsExtra.es6 index 47351cbebc..560bb5c0c2 100644 --- a/src/common/rivetsExtra.es6 +++ b/src/common/rivetsExtra.es6 @@ -24,7 +24,7 @@ rivets._.View.prototype.observe = function (keypath, callback) { /* rivets formatter to translate strings to 18n */ rv.formatters['i18n'] = (value) => { - if(typeof value === 'string') return value.i18n(); + if (typeof value === 'string') return value.i18n(); return value; }; rv.formatters['sanitize'] = (value) => value.replace(/("|'|\&|\(|\)|\<|\>)/g, ''); @@ -36,7 +36,7 @@ rv.formatters['prop'] = (value, prop) => { rv.formatters['one-of'] = (...args) => { const value = args[0]; for (let i = 1; i < args.length ; ++i) - if(args[i] === value) + if (args[i] === value) return true; return false; } @@ -61,9 +61,9 @@ rv.formatters['gt'] = (vlaue, other) => vlaue > other; /* rivets formatter for < operator */ rv.formatters['lt'] = (vlaue, other) => vlaue < other; /* rivets formatter to check if a variable has value */ -rv.formatters['has-value'] = (value) => value != null; +rv.formatters['has-value'] = (value) => value === 0 ? true : Boolean(value); /* localise price format*/ -rv.formatters['format-price'] = (value, currency) => (value != null) ? formatPrice(value, currency) : undefined; +rv.formatters['format-price'] = (value, currency) => (!isNaN(value)) ? formatPrice(value, currency) : undefined; /* comma added format*/ rv.formatters['add-comma'] = (value, decimal_points) => (parseFloat(value)) ? addComma(value, decimal_points) : undefined; /* rivets formater to capitalize string */ @@ -73,7 +73,7 @@ rv.formatters.capitalize = { }; /* call toFixed on a fload number */ rv.formatters['to-fixed'] = (value, digits) => { - if(!$.isNumeric(value) || !$.isNumeric(digits)){ + if (!$.isNumeric(value) || !$.isNumeric(digits)){ return; } return (value * 1).toFixed(digits || 2); @@ -111,7 +111,7 @@ rv.formatters.currency = (value, currency) => { 'PYG': '₲', /* Paraguayan Guarani */ 'THB': '฿', /* Thai Baht */ 'UAH': '₴', /* Ukrainian Hryvnia */ 'VND': '₫', /* Vietnamese Dong */ }; - if(value) + if (value) return (currency_symbols[currency] || currency) + value; return value; } @@ -128,7 +128,7 @@ rv.formatters['moment'] = (epoch, format) => { } /* human readable difference of two epoch values */ rv.formatters['moment-humanize'] = (from_epoch, till_epoch) => { - if(!from_epoch || !till_epoch) { + if (!from_epoch || !till_epoch) { return undefined; } @@ -153,7 +153,7 @@ rv.formatters['bold-last-character'] = (str) => { } /* formatter to calcualte the percent of a value of another value */ rv.formatters['percent-of'] = (changed, original) => { - if(!(changed != null) || !original) return undefined; + if (!(changed != null) || !original) return undefined; const percentage_of_amount = (100*(changed - original)/original).toFixed(2); if (percentage_of_amount > 0) { return `+${percentage_of_amount}%`; @@ -193,7 +193,7 @@ rv.binders.selectmenu = { routine: (el, value) => { el = $(el); el.val(value); - if(el.find("option[value='" + value + "']").length > 0) + if (el.find("option[value='" + value + "']").length > 0) el.selectmenu('refresh'); } }; @@ -221,7 +221,7 @@ rv.binders['is-valid-number'] = { /* bindar for jqueyr ui selectmenu options */ rv.binders['dom-*'] = function (el, value) { const method = this.args[0]; - if(value) + if (value) setTimeout(() => el[method](), 0); }; @@ -240,9 +240,9 @@ rv.binders.selectrefresh = { priority: 99, routine: (el,array_or_value) => { el = $(el); - if(typeof array_or_value === 'string') { + if (typeof array_or_value === 'string') { el.val(array_or_value); - if(el.find("option[value='" + array_or_value+ "']").length === 0) + if (el.find("option[value='" + array_or_value+ "']").length === 0) return; } el.selectmenu('refresh'); @@ -277,7 +277,7 @@ rv.binders.chosendisable = (el, value) => { const inputElement = chosenContainer.find('.chosen-choices input'); const chosenDrop = chosenContainer.find('.chosen-drop'); const chosenDisableElement = chosenContainer.find('.webtrader-chosen-disable'); - if(value) { + if (value) { inputElement.attr('disabled', value); chosenDrop.hide(); chosenDisableElement.addClass('chosen-disable'); @@ -345,7 +345,7 @@ rv.binders['input-enter'] = { publishes: false, routine: (el, callback) => { $(el).keyup(function(event){ - if(event.keyCode == 13){ + if (event.keyCode == 13){ callback(el); } }); @@ -462,7 +462,7 @@ rv.binders.datepicker = { closeText: 'Done'.i18n(), currentText: 'Today'.i18n() }; - if(model.yearRange) + if (model.yearRange) options.yearRange = model.yearRange; else { options.maxDate = model.maxDate || null; @@ -537,7 +537,7 @@ rv.binders['jq-class'] = { /* rv binder to active click event on another button when Enter key is pressed */ rv.binders['input-default-btn'] = (el, jquery_selector) => { $(el).keyup((event) => { - if(event.keyCode == 13) { + if (event.keyCode == 13) { $(jquery_selector).click(); } }); @@ -579,7 +579,7 @@ rv.binders['visible'] = (el, value) => { }; /* binder to add or remove disabled attribute */ rv.binders.disabled = (el,value) => { - if(value) $(el).attr('disabled', 'disabled'); + if (value) $(el).attr('disabled', 'disabled'); else $(el).removeAttr('disabled'); } @@ -691,10 +691,10 @@ rv.binders['indicative-color'] = (el, value) => { const red = '#d71818'; const green = '#02920e'; const black = 'black'; - if(!$.isNumeric(value)) { + if (!$.isNumeric(value)) { $(el).css({color: black}); } - else if(perv !== value*1) { + else if (perv !== value*1) { $(el).css({color: perv < value*1 ? green : red}); } el._perv_indicative_color = value; @@ -708,7 +708,7 @@ const component_twoway_bind = (self, data, keypathes) => { const keypath = keypathes[i]; const key = _.last(keypath.split('.')); const observer = self.observers[key]; - if(observer) { + if (observer) { observer.options.adapters['.'].observe(observer.target, _.last(observer.keypath.split('.')), () => { const updated = observer.target[_.last(observer.keypath.split('.'))]; data[key] = updated; From a52d7b1ceeafb23fc5dc0c433332ff54108f4304 Mon Sep 17 00:00:00 2001 From: Khalid Ibrahim Date: Mon, 10 Jun 2019 12:11:51 +0800 Subject: [PATCH 8/9] added value-checking function --- src/common/rivetsExtra.es6 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/common/rivetsExtra.es6 b/src/common/rivetsExtra.es6 index 560bb5c0c2..b737e11c8c 100644 --- a/src/common/rivetsExtra.es6 +++ b/src/common/rivetsExtra.es6 @@ -7,6 +7,8 @@ import 'jquery-sparkline'; import 'chosen'; import 'color-picker'; +const hasValue = value => value === 0 ? true : Boolean(value); + /* Rivets js does not allow manually observing properties from javascript, Use "rv.bind().observe('path.to.object', callback)" to subscribe */ rivets._.View.prototype.observe = function (keypath, callback) { @@ -61,9 +63,9 @@ rv.formatters['gt'] = (vlaue, other) => vlaue > other; /* rivets formatter for < operator */ rv.formatters['lt'] = (vlaue, other) => vlaue < other; /* rivets formatter to check if a variable has value */ -rv.formatters['has-value'] = (value) => value === 0 ? true : Boolean(value); +rv.formatters['has-value'] = (value) => hasValue(value); /* localise price format*/ -rv.formatters['format-price'] = (value, currency) => (!isNaN(value)) ? formatPrice(value, currency) : undefined; +rv.formatters['format-price'] = (value, currency) => hasValue(value) ? formatPrice(value, currency) : undefined; /* comma added format*/ rv.formatters['add-comma'] = (value, decimal_points) => (parseFloat(value)) ? addComma(value, decimal_points) : undefined; /* rivets formater to capitalize string */ From 3a6311ed773de855a1bd39f8b2b61b0523041d46 Mon Sep 17 00:00:00 2001 From: Khalid Ibrahim Date: Mon, 10 Jun 2019 12:16:09 +0800 Subject: [PATCH 9/9] better assignment --- src/common/rivetsExtra.es6 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/rivetsExtra.es6 b/src/common/rivetsExtra.es6 index b737e11c8c..965c75a4fb 100644 --- a/src/common/rivetsExtra.es6 +++ b/src/common/rivetsExtra.es6 @@ -63,7 +63,7 @@ rv.formatters['gt'] = (vlaue, other) => vlaue > other; /* rivets formatter for < operator */ rv.formatters['lt'] = (vlaue, other) => vlaue < other; /* rivets formatter to check if a variable has value */ -rv.formatters['has-value'] = (value) => hasValue(value); +rv.formatters['has-value'] = hasValue; /* localise price format*/ rv.formatters['format-price'] = (value, currency) => hasValue(value) ? formatPrice(value, currency) : undefined; /* comma added format*/