diff --git a/src/common/rivetsExtra.es6 b/src/common/rivetsExtra.es6 index 1e17043177..965c75a4fb 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) { @@ -24,7 +26,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 +38,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; } @@ -60,10 +62,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'] = hasValue; /* localise price format*/ -rv.formatters['format-price'] = (value, currency) => (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) => (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), @@ -71,7 +75,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); @@ -109,7 +113,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; } @@ -126,7 +130,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; } @@ -151,7 +155,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}%`; @@ -191,7 +195,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'); } }; @@ -219,7 +223,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); }; @@ -238,9 +242,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'); @@ -275,7 +279,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'); @@ -343,7 +347,7 @@ rv.binders['input-enter'] = { publishes: false, routine: (el, callback) => { $(el).keyup(function(event){ - if(event.keyCode == 13){ + if (event.keyCode == 13){ callback(el); } }); @@ -460,7 +464,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; @@ -535,7 +539,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(); } }); @@ -577,7 +581,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'); } @@ -689,10 +693,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; @@ -706,7 +710,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; 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 @@
Final Price