var statusMarketTrends = [];
var statusGlobalSettings = [];
var statusSingleMarketSettings = [];
var checkedMTButtons = false;
var checkedGSButtons = false;
var checkedSMSButtons = false;
const GSStandardTriggerTemplate = ({ settingType, settingName, trendName, marketTrends, minChange, maxChange }) => `
`;
const SMSStandardTriggerTemplate = ({ settingType, settingName, trendName, triggerPrefix, marketTrends, marketTrendRelations, minChange, maxChange }) => `
`;
const CoinAgeTriggerTemplate = ({ settingType, settingName, triggerIndex, coinAgeDays }) => `
`;
const SMS24hVolumeTriggerTemplate = ({ settingType, settingName, triggerIndex, triggerPrefix, mainMarket, min24hVolume, max24hVolume }) => `
`;
const SMSHoursActiveTriggerTemplate = ({ settingType, settingName, triggerIndex, hoursSinceTriggered }) => `
`;
const PropertyTemplate = ({ settingType, settingName, propertyType, propertyKey, propertyKeySimple, value, valueModes}) => `
`;
function checkMTMoveButtons() {
if (!checkedMTButtons) {
$('.btn-move-MT').each(function (index) {
var dataTarget = $(this).data('datatarget');
var dataDirection = $(this).data('datadirection');
var currentElement = $('#' + dataTarget).closest('.settings-markettrend');
if (dataDirection === 'up') {
if ($(currentElement).is('.settings-markettrend:first-child')) {
$(this).addClass('hidden');
} else {
$(this).removeClass('hidden');
}
} else if (dataDirection === 'down') {
if ($(currentElement).is('.settings-markettrend:last-child')) {
$(this).addClass('hidden');
} else {
$(this).removeClass('hidden');
}
}
});
}
checkedMTButtons = true;
}
function checkGSMoveButtons() {
if (!checkedGSButtons) {
$('.btn-move-GS').each(function (index) {
var dataTarget = $(this).data('datatarget');
var dataDirection = $(this).data('datadirection');
var currentElement = $('#' + dataTarget).closest('.settings-globalsetting');
if (dataDirection === 'up') {
if ($(currentElement).is('.settings-globalsetting:first-child')) {
$(this).addClass('hidden');
} else {
$(this).removeClass('hidden');
}
} else if (dataDirection === 'down') {
if ($(currentElement).is('.settings-globalsetting:last-child')) {
$(this).addClass('hidden');
} else {
$(this).removeClass('hidden');
// Get next element
var nextElement = $(currentElement).next('.settings-globalsetting').find('div');
var nextElementId = $(nextElement).attr('id').toLowerCase().replace('globalsetting_', '');
if (nextElementId.startsWith('default')) {
// Hide "Move Down" button when the next setting is the default setting
$(this).addClass('hidden');
}
}
}
});
}
checkedGSButtons = true;
}
function checkSMSMoveButtons() {
if (!checkedSMSButtons) {
$('.btn-move-SMS').each(function (index) {
var dataTarget = $(this).data('datatarget');
var dataDirection = $(this).data('datadirection');
var currentElement = $('#' + dataTarget).closest('.settings-singlemarketsetting');
if (dataDirection === 'up') {
if ($(currentElement).is('.settings-singlemarketsetting:first-child')) {
$(this).addClass('hidden');
} else {
$(this).removeClass('hidden');
}
} else if (dataDirection === 'down') {
if ($(currentElement).is('.settings-singlemarketsetting:last-child')) {
$(this).addClass('hidden');
} else {
$(this).removeClass('hidden');
}
}
});
}
checkedSMSButtons = true;
}
function checkBuildStatus() {
var buildCompleted = true;
for (key in statusMarketTrends) {
if (!statusMarketTrends[key]) {
buildCompleted = false;
}
}
if (buildCompleted) {
for (key in statusGlobalSettings) {
if (!statusGlobalSettings[key]) {
buildCompleted = false;
}
}
}
if (buildCompleted) {
for (key in statusSingleMarketSettings) {
if (!statusSingleMarketSettings[key]) {
buildCompleted = false;
}
}
}
if (buildCompleted) {
$('#div-loading-settings').addClass('hidden');
$('#div-save-settings').removeClass('hidden');
checkMTMoveButtons();
checkGSMoveButtons();
checkSMSMoveButtons();
}
}
$.fn.buildMarketTrendSettings = function () {
return this.each(function (index) {
var element = $(this);
var marketTrendName = $(this).data('trendname');
var rootUrl = $(this).data('rooturl');
if (marketTrendName !== '') {
statusMarketTrends[marketTrendName] = false;
}
$(this).load(rootUrl + '_get/SettingsMarketTrends?mt=' + encodeURIComponent(marketTrendName), '', function (responseText, textStatus, XMLHttpRequest) {
if (textStatus === 'error') {
$.Notification.notify('error', 'top left', 'Build MarketTrendSettings failed!', 'PTMagic Monitor failed to build MarketTrendSettings.')
} else {
statusMarketTrends[marketTrendName] = true;
checkBuildStatus();
$(this).removeClass('new');
$('[data-toggle="tooltip"]').tooltip();
var elems = Array.prototype.slice.call(document.querySelectorAll('[data-plugin="switchery"][data-switchery="false"]'));
elems.forEach(function (html) {
var switchery = new Switchery(html, { size : 'small' });
});
}
});
});
};
$.fn.buildGlobalSettings = function () {
return this.each(function (index) {
var element = $(this);
var settingName = $(this).data('settingname');
var rootUrl = $(this).data('rooturl');
if (settingName !== '') {
statusGlobalSettings[settingName] = false;
}
$(this).load(rootUrl + '_get/SettingsGlobalSettings?gs=' + encodeURIComponent(settingName), '', function (responseText, textStatus, XMLHttpRequest) {
if (textStatus === 'error') {
$.Notification.notify('error', 'top left', 'Build GlobalSettings failed!', 'PTMagic Monitor failed to build GlobalSettings.')
} else {
statusGlobalSettings[settingName] = true;
checkBuildStatus();
$(this).removeClass('new');
$('[data-toggle="tooltip"]').tooltip();
var elems = Array.prototype.slice.call(document.querySelectorAll('[data-plugin="switchery"][data-switchery="false"]'));
elems.forEach(function (html) {
var switchery = new Switchery(html, { size: 'small' });
});
}
});
});
};
$.fn.buildSingleMarketSettings = function () {
return this.each(function (index) {
var element = $(this);
var settingName = $(this).data('settingname');
var rootUrl = $(this).data('rooturl');
if (settingName !== '') {
statusSingleMarketSettings[settingName] = false;
}
$(this).load(rootUrl + '_get/SettingsSingleMarketSettings?gs=' + encodeURIComponent(settingName), '', function (responseText, textStatus, XMLHttpRequest) {
if (textStatus === 'error') {
$.Notification.notify('error', 'top left', 'Build SingleMarketSettings failed!', 'PTMagic Monitor failed to build SingleMarketSettings.')
} else {
statusSingleMarketSettings[settingName] = true;
checkBuildStatus();
$(this).removeClass('new');
$('[data-toggle="tooltip"]').tooltip();
var elems = Array.prototype.slice.call(document.querySelectorAll('[data-plugin="switchery"][data-switchery="false"]'));
elems.forEach(function (html) {
var switchery = new Switchery(html, { size: 'small' });
});
}
});
});
};