| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- /*
- * ============================== - 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();
- }
|