2018-04-09 23:33:42 -04:00
|
|
|
|
function hideLoader() {
|
2022-04-19 19:43:58 -04:00
|
|
|
|
$('#mainLoadingBar').fadeOut();
|
2022-04-21 13:39:09 -04:00
|
|
|
|
$('.modal-loading-bar').fadeOut();
|
2018-04-09 23:33:42 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showLoader() {
|
2022-04-19 19:43:58 -04:00
|
|
|
|
$('#mainLoadingBar').fadeIn();
|
2022-04-21 13:39:09 -04:00
|
|
|
|
$('.modal-loading-bar').fadeIn();
|
2018-04-09 23:33:42 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function errorLoader() {
|
2022-04-19 19:43:58 -04:00
|
|
|
|
$('#mainLoadingBar').addClass('bg-danger').delay(2000).fadeOut();
|
2018-04-09 23:33:42 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-04 00:22:10 -04:00
|
|
|
|
function staleLoader() {
|
2022-04-19 19:43:58 -04:00
|
|
|
|
$('#mainLoadingBar').addClass('bg-grey');
|
2018-05-04 00:22:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-19 19:43:58 -04:00
|
|
|
|
function getUrlParameter(sParam) {
|
|
|
|
|
let sPageURL = window.location.search.substring(1),
|
|
|
|
|
sURLVariables = sPageURL.split('&'),
|
|
|
|
|
sParameterName,
|
|
|
|
|
i;
|
2018-04-09 23:33:42 -04:00
|
|
|
|
|
2022-04-19 19:43:58 -04:00
|
|
|
|
for (i = 0; i < sURLVariables.length; i++) {
|
|
|
|
|
sParameterName = sURLVariables[i].split('=');
|
|
|
|
|
|
|
|
|
|
if (sParameterName[0] === sParam) {
|
2022-07-09 17:32:23 -04:00
|
|
|
|
return sParameterName[1] === undefined ? true : decodeURIComponent(unescape(sParameterName[1]));
|
2022-04-19 19:43:58 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function clearQueryString() {
|
|
|
|
|
const uri = window.location.href.toString();
|
|
|
|
|
if (uri.indexOf("?") > 0) {
|
|
|
|
|
const cleanUri = uri.substring(0, uri.indexOf("?"));
|
|
|
|
|
window.history.replaceState({}, document.title, cleanUri);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const entityMap = {
|
|
|
|
|
'&': '&',
|
|
|
|
|
'<': '<',
|
|
|
|
|
'>': '>',
|
|
|
|
|
'"': '"',
|
|
|
|
|
"'": ''',
|
|
|
|
|
'/': '/',
|
|
|
|
|
'`': '`',
|
|
|
|
|
'=': '='
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function escapeHtml (string) {
|
|
|
|
|
return String(string).replace(/[&<>"'`=\/]/g, function (s) {
|
|
|
|
|
return entityMap[s];
|
2018-04-09 23:33:42 -04:00
|
|
|
|
});
|
2022-04-19 19:43:58 -04:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-28 11:03:05 -04:00
|
|
|
|
function buildToastUri(message, duration) {
|
|
|
|
|
let uri = '&';
|
|
|
|
|
if (window.location.href.toString().indexOf('?') <= 0) {
|
|
|
|
|
uri = '?';
|
|
|
|
|
}
|
|
|
|
|
uri += `toastMessage=${escape(message)}${duration ? `&duration=${duration}` : ''}`;
|
|
|
|
|
return uri;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-19 19:43:58 -04:00
|
|
|
|
$(document).ready(function () {
|
|
|
|
|
|
|
|
|
|
let toastMessage = getUrlParameter('toastMessage');
|
2022-04-22 17:56:29 -04:00
|
|
|
|
const duration = parseInt(getUrlParameter('duration'));
|
2022-04-19 19:43:58 -04:00
|
|
|
|
|
|
|
|
|
if (toastMessage) {
|
|
|
|
|
toastMessage = unescape(toastMessage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (toastMessage) {
|
|
|
|
|
clearQueryString();
|
|
|
|
|
halfmoon.initStickyAlert({
|
|
|
|
|
content: toastMessage,
|
2022-07-05 13:02:43 -04:00
|
|
|
|
title: _localization['WEBFRONT_SCRIPT_ACTION_SUCCESS'],
|
2022-04-19 19:43:58 -04:00
|
|
|
|
alertType: 'alert-success',
|
2022-04-22 17:56:29 -04:00
|
|
|
|
fillType: 'filled',
|
|
|
|
|
timeShown: duration
|
2022-04-19 19:43:58 -04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hideLoader();
|
2018-04-09 23:33:42 -04:00
|
|
|
|
|
2020-07-14 15:13:40 -04:00
|
|
|
|
$(document).off('click', '.profile-action');
|
2022-04-22 17:56:29 -04:00
|
|
|
|
$(document).on('click', '.profile-action', function (e) {
|
|
|
|
|
e.preventDefault();
|
2022-09-08 16:03:38 -04:00
|
|
|
|
const action = $(this).data('action');
|
2019-07-13 21:45:25 -04:00
|
|
|
|
const actionId = $(this).data('action-id');
|
2022-09-08 16:03:38 -04:00
|
|
|
|
const actionMeta = $(this).data('action-meta');
|
2022-04-22 17:56:29 -04:00
|
|
|
|
const responseDuration = $(this).data('response-duration') || 5000;
|
2022-09-08 16:03:38 -04:00
|
|
|
|
let actionKeys = actionId === undefined ? '' : `?id=${actionId}`;
|
|
|
|
|
|
|
|
|
|
if (actionMeta !== undefined) {
|
|
|
|
|
actionKeys = actionKeys + '&meta=' + JSON.stringify(actionMeta);
|
|
|
|
|
}
|
2022-04-19 19:43:58 -04:00
|
|
|
|
showLoader();
|
2022-09-08 16:03:38 -04:00
|
|
|
|
|
|
|
|
|
$.get(`/Action/${action}Form/${actionKeys}`)
|
2018-04-04 15:38:34 -04:00
|
|
|
|
.done(function (response) {
|
2022-04-22 17:56:29 -04:00
|
|
|
|
$('#actionModal .modal-message').fadeOut('fast')
|
|
|
|
|
$('#actionModal').attr('data-response-duration', responseDuration);
|
2022-04-19 19:43:58 -04:00
|
|
|
|
$('#actionModalContent').html(response);
|
|
|
|
|
hideLoader();
|
2022-04-22 17:56:29 -04:00
|
|
|
|
halfmoon.toggleModal('actionModal');
|
2018-04-04 15:38:34 -04:00
|
|
|
|
})
|
|
|
|
|
.fail(function (jqxhr, textStatus, error) {
|
2022-04-19 19:43:58 -04:00
|
|
|
|
halfmoon.initStickyAlert({
|
|
|
|
|
content: jqxhr.responseText,
|
2022-07-05 13:02:43 -04:00
|
|
|
|
title: _localization['WEBFRONT_SCRIPT_ACTION_ERROR'],
|
2022-04-19 19:43:58 -04:00
|
|
|
|
alertType: 'alert-danger',
|
|
|
|
|
fillType: 'filled'
|
|
|
|
|
});
|
2018-04-04 15:38:34 -04:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* handle action submit
|
|
|
|
|
*/
|
|
|
|
|
$(document).on('submit', '.action-form', function (e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
$(this).append($('#target_id input'));
|
2022-04-19 19:43:58 -04:00
|
|
|
|
const modal = $('#actionModal');
|
|
|
|
|
const shouldRefresh = modal.data('should-refresh', modal.find('.refreshable').length !== 0);
|
2018-04-04 15:38:34 -04:00
|
|
|
|
const data = $(this).serialize();
|
2022-04-22 17:56:29 -04:00
|
|
|
|
const duration = modal.data('response-duration');
|
2018-04-09 23:33:42 -04:00
|
|
|
|
showLoader();
|
2022-04-19 19:43:58 -04:00
|
|
|
|
|
2018-04-04 15:38:34 -04:00
|
|
|
|
$.get($(this).attr('action') + '/?' + data)
|
|
|
|
|
.done(function (response) {
|
2018-04-09 23:33:42 -04:00
|
|
|
|
hideLoader();
|
2018-04-04 15:38:34 -04:00
|
|
|
|
// success without content
|
|
|
|
|
if (response.length === 0) {
|
|
|
|
|
location.reload();
|
2022-04-19 19:43:58 -04:00
|
|
|
|
} else {
|
|
|
|
|
let message = response;
|
|
|
|
|
try {
|
|
|
|
|
message = response.map(r => escapeHtml(r.response));
|
|
|
|
|
}
|
|
|
|
|
catch{}
|
|
|
|
|
if (shouldRefresh) {
|
2022-06-28 11:03:05 -04:00
|
|
|
|
window.location = `${window.location.href.replace('#', '')}${buildToastUri(message, duration)}`;
|
2022-04-19 19:43:58 -04:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
modal.modal();
|
|
|
|
|
halfmoon.initStickyAlert({
|
|
|
|
|
content: escapeHtml(message),
|
2022-07-05 13:02:43 -04:00
|
|
|
|
title: _localization['WEBFRONT_SCRIPT_ACTION_EXECUTED'],
|
2022-04-19 19:43:58 -04:00
|
|
|
|
alertType: 'alert-primary',
|
|
|
|
|
fillType: 'filled'
|
|
|
|
|
});
|
|
|
|
|
}
|
2018-04-04 15:38:34 -04:00
|
|
|
|
}
|
|
|
|
|
})
|
2022-04-19 19:43:58 -04:00
|
|
|
|
.fail(function (jqxhr) {
|
2018-04-09 23:33:42 -04:00
|
|
|
|
hideLoader();
|
2022-04-19 19:43:58 -04:00
|
|
|
|
|
|
|
|
|
let message = jqxhr.responseText;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const jsonMessage = $.parseJSON(message);
|
|
|
|
|
|
|
|
|
|
if (jsonMessage) {
|
|
|
|
|
message = jsonMessage.map(r => escapeHtml(r.response));
|
|
|
|
|
}
|
2018-04-04 15:38:34 -04:00
|
|
|
|
}
|
2022-04-19 19:43:58 -04:00
|
|
|
|
|
|
|
|
|
catch{}
|
|
|
|
|
|
2022-04-21 13:39:09 -04:00
|
|
|
|
if (message instanceof Array)
|
|
|
|
|
{
|
|
|
|
|
message = message.join("<br/>");
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-19 19:43:58 -04:00
|
|
|
|
halfmoon.initStickyAlert({
|
2022-04-21 13:39:09 -04:00
|
|
|
|
content: message,
|
2022-07-05 13:02:43 -04:00
|
|
|
|
title: _localization['WEBFRONT_SCRIPT_ACTION_ERROR'],
|
2022-04-19 19:43:58 -04:00
|
|
|
|
alertType: 'alert-danger',
|
|
|
|
|
fillType: 'filled'
|
|
|
|
|
});
|
2018-04-04 15:38:34 -04:00
|
|
|
|
});
|
|
|
|
|
});
|
2022-04-19 19:43:58 -04:00
|
|
|
|
});
|