From 5320f602f8dea4ea85dc24607b84f219ff95341f Mon Sep 17 00:00:00 2001 From: ahwelp Date: Tue, 24 Jan 2023 20:39:04 +0000 Subject: [PATCH] Changes on javascript behavior --- public/dist/libs.js | 120 ++++++ public/dist/script.js | 862 +++++++++++++++++++----------------------- 2 files changed, 514 insertions(+), 468 deletions(-) create mode 100644 public/dist/libs.js mode change 100755 => 100644 public/dist/script.js diff --git a/public/dist/libs.js b/public/dist/libs.js new file mode 100644 index 0000000..959d07f --- /dev/null +++ b/public/dist/libs.js @@ -0,0 +1,120 @@ +/* + * ============================== - Async Help + * _ _ _ + * /\ | | | | | | + * / \ ___ _ _ _ __ ___ | |__| | ___| |_ __ + * / /\ \ / __| | | | '_ \ / __| | __ |/ _ \ | '_ \ + * / ____ \\__ \ |_| | | | | (__ | | | | __/ | |_) | + * /_/ \_\___/\__, |_| |_|\___| |_| |_|\___|_| .__/ + * __/ | | | + * |___/ |_| + * +*/ + +function asyncRedirect(target, method) { + $('#progress').removeClass('hidden'); + let request = fetch(target, { + method: method, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + 'X-Requested-With': 'fetch' + } + }).then(function (response) { + return response.text(); + }).then(function (data) { + $('body #content').html(data).trigger('reloaded'); + history.replaceState({}, '', target); + }).catch(function (error) { + + }).finally(function () { + $('#progress').addClass('hidden'); + }); +} + +/* + * Fill a given element with content on a + * remote location + * + */ +function asyncFill(target, method, location, callback = function () { }, params = {}, payload = {}) { + fetch(target, { + method: method, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + 'X-Requested-With': 'fetch' + } + }).then(function (response) { + return response.text(); + }).then(function (data) { + $(location).html(data).trigger('filled'); + }).catch(function (error) { + }).finally(function () { + callback(params); + }); +} + +/** + * Search any type of content on a remote location + * + **/ +async function asyncContent(target, method, type, callback = function () { }) { + return fetch(target, { + method: method, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + 'X-Requested-With': 'fetch' + } + }).then(function (response) { + var content = ""; + + if (type == 'text') { + content = response.text(); + } else { + content = response.json(); + } + + return { + "status": response.ok, + "content": content + }; + + }).then(function (data) { + callback(data.content); + return data; + }).finally(function (content) { + + }); + +} + + +/* + * ============================== Modal + * _ __ _ _ + * | \/ | | | | | + * | \ / | ___ __| | __ _| | + * | |\/| |/ _ \ / _` |/ _` | | + * | | | | (_) | (_| | (_| | | + * |_| |_|\___/ \__,_|\__,_|_| + * +*/ + +var scan; + +var modalTarget = {}; // Store field where the modal will place the selected stuff +let modal = new bootstrap.Modal($('#modal'), { keyboard: true }); +var modalClose; + +$('#modal').on('hidden.bs.modal', function (evt) { + $(this).find('.modal-body').html(''); + $(this).find('.modal-title').html(''); + if (typeof modalClose === "function") { + modalClose(); + } +}); + +async function openModal(params) { + modalTarget = params.target; + modalClose = params.close; + modal.toggle(); +} \ No newline at end of file diff --git a/public/dist/script.js b/public/dist/script.js old mode 100755 new mode 100644 index 731ad2b..cae6972 --- a/public/dist/script.js +++ b/public/dist/script.js @@ -6,22 +6,6 @@ var user_config = { allways_ajax: true }; -function log(message, importance = 0) { - if (user_config.log === 0) { - return; - } - - if (importance === 0) { - console.log("LOG:: |" + message + "|"); - } - if (importance === 1) { - console.log(message); - } - if (importance === 2) { - alert("LOG:: |" + message + "|"); - } -} - function isDefined(data) { if (typeof data === 'undefined') { return false; @@ -35,418 +19,26 @@ function definedOr(data, value = '') { return value; } else { return data; -} + } } -//============================== Generic Template Functions - -function revalidate_screen() { - $('[data-format]').each(function () { - $(this).mask($(this).data('format'), {}); - }); - - //$('[data-toggle="popover"]').popover(); - - $('select').each(function () { - if (typeof $(this).data('value') !== "undefined" && $(this).data('value') !== '') { - $(this).val($(this).data('value')); - } - }); - - $('.datepicker').each(function () { - $(this).datepicker({ - format: "dd/mm/yyyy", - todayBtn: "linked", - clearBtn: true, - autoclose: true, - todayHighlight: true - }); - }); - - $('.selectpicker').each(function () { - $(this).select2({ - liveSearch: true - }); - }); - - $(".wysiwyg").each(function () { - $(this).trumbowyg(); - }); - - $(".form-control-range").each(function(i, item){ - $(item).on('change', function(item, i){ - $(item.currentTarget) - .parent() - .find('.range-monitor') - .html(item.currentTarget.value + "%"); - }) - }); - - $('.popup-toggle').each(() => { - var template = '