Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 24 additions & 20 deletions src/common/rivetsExtra.es6
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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, '');
Expand All @@ -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;
}
Expand All @@ -60,18 +62,20 @@ 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),
publish: (value) => value.toLowerCase()
};
/* 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);
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}

Expand All @@ -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}%`;
Expand Down Expand Up @@ -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');
}
};
Expand Down Expand Up @@ -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);
};

Expand All @@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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);
}
});
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
});
Expand Down Expand Up @@ -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');
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/viewtransaction/viewTransaction.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ <h3>Exit spot</h3>
rv-data-balloon='"return"'
class="dotted-underline smaller"></span>
</div>
<div rv-if="proposal_open_contract.sell_price">
<div rv-if="proposal_open_contract.sell_price | has-value">
<div rv-class-center="proposal_open_contract.user_sold | or proposal_open_contract.barrier_count | eq 2"> <p>Final Price</p>
<span rv-html="proposal_open_contract.sell_price | format-price proposal_open_contract.currency | or '-'"></span>
<br/>
Expand Down
1 change: 1 addition & 0 deletions src/windows/tracker.es6
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ 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();
Expand Down
16 changes: 11 additions & 5 deletions src/windows/windows.es6
Original file line number Diff line number Diff line change
Expand Up @@ -329,15 +329,21 @@ export const createBlankWindow = function($html,options) {
dialog.draggable( "option", "scroll", true );
}
dialog.on('dragstop', () => {
const top = dialog.offset().top;
const left = dialog.offset().left;

if (top < 0) {
dialog.animate({ top: '0px' }, 300, dialog.trigger.bind(dialog, 'animated'));
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 < 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 - 10}px` }, 300, dialog.trigger.bind(dialog, 'animated'));
}
});

if(options.destroy) { /* register for destroy event which have been patched */
Expand Down