1/** 2 * UI Toasts 3 */ 4 5'use strict'; 6 7(function () { 8 // Bootstrap toasts example 9 // -------------------------------------------------------------------- 10 const toastAnimationExample = document.querySelector('.toast-ex'), 11 toastPlacementExample = document.querySelector('.toast-placement-ex'), 12 toastAnimationBtn = document.querySelector('#showToastAnimation'), 13 toastPlacementBtn = document.querySelector('#showToastPlacement'); 14 let selectedType, selectedAnimation, selectedPlacement, toast, toastAnimation, toastPlacement; 15 16 // Animation Button click 17 if (toastAnimationBtn) { 18 toastAnimationBtn.onclick = function () { 19 if (toastAnimation) { 20 toastDispose(toastAnimation); 21 } 22 selectedType = document.querySelector('#selectType').value; 23 selectedAnimation = document.querySelector('#selectAnimation').value; 24 25 toastAnimationExample.querySelector('i.mdi').classList.add(selectedType); 26 toastAnimationExample.classList.add(selectedAnimation); 27 toastAnimation = new bootstrap.Toast(toastAnimationExample); 28 toastAnimation.show(); 29 }; 30 } 31 32 // Dispose toast when open another 33 function toastDispose(toast) { 34 if (toast && toast._element !== null) { 35 if (toastPlacementExample) { 36 toastPlacementExample.querySelector('i.mdi').classList.remove(selectedType); 37 DOMTokenList.prototype.remove.apply(toastPlacementExample.classList, selectedPlacement); 38 } 39 if (toastAnimationExample) { 40 toastAnimationExample.querySelector('i.mdi').classList.remove(selectedType); 41 toastAnimationExample.classList.remove(selectedAnimation); 42 } 43 toast.dispose(); 44 } 45 } 46 // Placement Button click 47 if (toastPlacementBtn) { 48 toastPlacementBtn.onclick = function () { 49 if (toastPlacement) { 50 toastDispose(toastPlacement); 51 } 52 selectedType = document.querySelector('#selectTypeOpt').value; 53 selectedPlacement = document.querySelector('#selectPlacement').value.split(' '); 54 55 toastPlacementExample.querySelector('i.mdi').classList.add(selectedType); 56 DOMTokenList.prototype.add.apply(toastPlacementExample.classList, selectedPlacement); 57 toastPlacement = new bootstrap.Toast(toastPlacementExample); 58 toastPlacement.show(); 59 }; 60 } 61})(); 62 63//Toastr (jquery) 64// -------------------------------------------------------------------- 65
66var i = -1; 67var toastCount = 0; 68var $toastlast; 69var getMessage = function () { 70 var msgs = [ 71 "Você precisa implementar uma mensagem de retorno.", 72 '<div class="mb-3"><input class="input-small form-control" value="Textbox"/> <a href="http://johnpapa.net" target="_blank">This is a hyperlink</a></div><div class="d-flex"><button type="button" id="okBtn" class="btn btn-primary btn-sm me-2">Close me</button><button type="button" id="surpriseBtn" class="btn btn-sm btn-secondary">Surprise me</button></div>', 73 'Live the Life of Your Dreams', 74 'Believe in Your Self!', 75 'Be mindful. Be grateful. Be positive.', 76 'Accept yourself, love yourself!' 77 ]; 78 i++; 79 if (i === msgs.length) { 80 i = 0; 81 } 82 return msgs[i]; 83}; 84 85var getMessageWithClearButton = function (msg) { 86 msg = msg ? msg : 'Clear itself?'; 87 msg += '<br /><br /><button type="button" class="btn btn-secondary clear">Yes</button>'; 88 return msg; 89}; 90 91$('#closeButton').on('click', function () { 92 if ($(this).is(':checked')) { 93 $('#addBehaviorOnToastCloseClick').prop('disabled', false); 94 } else { 95 $('#addBehaviorOnToastCloseClick').prop('disabled', true); 96 $('#addBehaviorOnToastCloseClick').prop('checked', false); 97 } 98}); 99 100function notify(_title = '', _msg = '', _toastType, _positionClass, _showDuration = 300, _hideDuration = 1000, _timeOut = 5000, _extendedTimeOut = 1000, _showEasing = 'swing', _hideEasing = 'linear', _showMethod = 'fadeIn', _hideMethod = 'fadeOut') { 101 let title = _title, 102 msg = _msg, 103 toastType = _toastType, 104 positionClass = _positionClass, 105 showDuration = _showDuration, 106 hideDuration = _hideDuration, 107 timeOut = _timeOut, 108 extendedTimeOut = _extendedTimeOut, 109 showEasing = _showEasing, 110 hideEasing = _hideEasing, 111 showMethod = _showMethod, 112 hideMethod = _hideMethod; 113 114 var shortCutFunction = toastType, //$('#toastTypeGroup input:radio:checked').val(), 115 isRtl = $('html').attr('dir') === 'rtl', 116 // msg = $('#message').val(), 117 // title = $('#title').val() || '', 118 // $showDuration = $('#showDuration'), 119 // $hideDuration = $('#hideDuration'), 120 // $timeOut = $('#timeOut'), 121 // $extendedTimeOut = $('#extendedTimeOut'), 122 // $showEasing = $('#showEasing'), 123 // $hideEasing = $('#hideEasing'), 124 // $showMethod = $('#showMethod'), 125 // $hideMethod = $('#hideMethod'), 126 toastIndex = toastCount++, 127 // addClear = $('#addClear').prop('checked'), 128 prePositionClass = 'toast-top-right'; 129 130 prePositionClass = 131 typeof toastr.options.positionClass === 'undefined' ? 'toast-top-right' : toastr.options.positionClass; 132 133 toastr.options = { 134 maxOpened: 1, 135 autoDismiss: true, 136 closeButton: true, 137 debug: false, 138 newestOnTop: true, 139 progressBar: true, 140 positionClass: positionClass || 'toast-top-right', 141 preventDuplicates: true, 142 onclick: null, 143 rtl: isRtl 144 }; 145 146 // POSITION 147 /** 148 * toast-top-right 149 * toast-bottom-right 150 * toast-bottom-left 151 * toast-top-left 152 * toast-top-full-width 153 * toast-bottom-full-width 154 * toast-top-center 155 * toast-bottom-center 156 */ 157 158 //Add fix for multiple toast open while changing the position 159 if (prePositionClass != toastr.options.positionClass) { 160 toastr.options.hideDuration = 0; 161 toastr.clear(); 162 } 163 164 // if ($('#addBehaviorOnToastClick').prop('checked')) { 165 // toastr.options.onclick = function () { 166 // alert('You can perform some custom action after a toast goes away'); 167 // }; 168 // } 169 // if ($('#addBehaviorOnToastCloseClick').prop('checked')) { 170 // toastr.options.onCloseClick = function () { 171 // alert('You can perform some custom action when the close button is clicked'); 172 // }; 173 // } 174 if (showDuration.length) { 175 toastr.options.showDuration = parseInt(showDuration); 176 } 177 if (hideDuration.length) { 178 toastr.options.hideDuration = parseInt(hideDuration); 179 } 180 if (timeOut.length) { 181 toastr.options.timeOut = addClear ? 0 : parseInt(timeOut); 182 } 183 if (extendedTimeOut.length) { 184 toastr.options.extendedTimeOut = addClear ? 0 : parseInt(extendedTimeOut); 185 } 186 if (showEasing.length) { 187 toastr.options.showEasing = showEasing; 188 } 189 if (hideEasing.length) { 190 toastr.options.hideEasing = hideEasing; 191 } 192 if (showMethod.length) { 193 toastr.options.showMethod = showMethod; 194 } 195 if (hideMethod.length) { 196 toastr.options.hideMethod = hideMethod; 197 } 198 // if (addClear) { 199 // msg = getMessageWithClearButton(msg); 200 // toastr.options.tapToDismiss = false;
201 // } 202 if (!msg) { 203 msg = getMessage(); 204 } 205 var $toast = toastr[shortCutFunction](msg, title); // Wire up an event handler to a button in the toast, if it exists 206 $toastlast = $toast; 207 if (typeof $toast === 'undefined') { 208 return; 209 } 210 // if ($toast.find('#okBtn').length) { 211 // $toast.delegate('#okBtn', 'click', function () { 212 // alert('you clicked me. i was toast #' + toastIndex + '. goodbye!'); 213 // $toast.remove(); 214 // }); 215 // } 216 // if ($toast.find('#surpriseBtn').length) { 217 // $toast.delegate('#surpriseBtn', 'click', function () { 218 // alert('Surprise! you clicked me. i was toast #' + toastIndex + '. You could perform an action here.'); 219 // }); 220 // } 221 // if ($toast.find('.clear').length) { 222 // $toast.delegate('.clear', 'click', function () { 223 // toastr.clear($toast, { 224 // force: true 225 // }); 226 // }); 227 // } 228} 229 230function getLastToast() { 231 return $toastlast; 232} 233$('#clearlasttoast').on('click', function () { 234 toastr.clear(getLastToast()); 235}); 236$('#cleartoasts').on('click', function () { 237 toastr.clear(); 238}); 239 240 241 242// FORM AJAX 243function sendForm(post_url, request_method, form_data, callback, msgLoading = "Aguarde carregando...") { 244 $.ajax({ 245 url: post_url, 246 type: request_method, 247 data: form_data, 248 enctype: 'multipart/form-data', 249 cache: false, 250 crossDomain: true, 251 beforeSend: function () { 252 notify('Aguarde!', msgLoading, 'info', 'toast-bottom-right'); 253 }, 254 success: function (result) { 255 toastr.clear(getLastToast()); 256 callback(result); 257 }, 258 error: function (result) { 259 callback(result); 260 } 261 }); 262} 263 264function _open(_url, element, size = '') { 265 $("#" + element).html('<div class="card"><div class="card-body text-center"><i class="fa fa-spinner fa-spin font-size-16"></i> carregando...</div></div>'); 266 if (size != '') { 267 var width = size + "px"; 268 $("#" + element).css({ 269 'width': width 270 }); 271 } 272 sendForm(_url, request_method = "POST", form_data = "", function (e) { 273 if (e != '' || e != null) { 274 $("#" + element).html(e); 275 toastr.clear(); 276 } else { 277 notify('Atenção!', 'Ops!<br /> Tivemos um probleminha ao processar sua solicitação de cadastro.<br />Por favor, tente novamente!', 'error', 'toast-bottom-right'); 278 // notify('Ops!<br /> Tivemos um probleminha ao processar sua solicitação de cadastro.<br />Por favor, tente novamente!', 'error', 'true'); 279 } 280 }); 281} 282 283function clearMsg(_time = 2000) { 284 setTimeout(function () { 285 toastr.clear(); 286 }, _time); 287} 288 289 290function copyToClipboard(element) { 291 var $temp = $("<input>"); 292 $("body").append($temp); 293 $temp.val(element).select(); 294 document.execCommand("copy"); 295 $temp.remove(); 296 toastr.info('Item copiado para a área de transferência!'); 297} 298 299function forceLower(strInput) { 300 strInput.value = strInput.value.toLowerCase(); 301} 302 303 304function getGeolocate() { 305 if (navigator.geolocation) { 306 navigator.geolocation.getCurrentPosition(function (position) { 307 _coords = { 308 session_id: _session_id 309 , locale: { 310 latitude: position.coords.latitude 311 , longitude: position.coords.longitude 312 } 313 }; 314 localStorage.setItem("navigation", JSON.stringify(_coords)); 315 }, function () { 316 notify('Atenção!', 'Atenção!!! Para acessar o sistema você precisa permitir a geo-localização.', 'error', 'toast-bottom-left'); 317 // notify('Atenção!!! Para acessar o sistema você precisa permitir a geo-localização.', 'danger', view_div = '', time = 5000, align = 'top-right'); 318 }); 319 } else { 320 notify('Atenção!', 'Navegador não suporta geolocalização.', 'error', 'toast-bottom-left'); 321 // notify('Atenção', 'Navegador não suporta geolocalização.', 'danger', view_div = '', time = 5000, align = 'top-right'); 322 } 323} 324 325function getCoords() { 326 $("#bt_geo").html(''); 327 $("#bt_geo").html('<span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span><span class="ms-25 align-middle">carregando...</span>'); 328 if (_coords) { 329 $("#latlong").html('<strong>Sua localização</strong><br />' + _coords.locale.latitude + ', ' + _coords.locale.longitude); 330 $("#geo_tag").hide(); 331 $("#form_auth").show(); 332 $("#form_auth").append('<input type="hidden" name="latitude" id="latitude" value="' + _coords.locale.latitude + '" /><input type="hidden" name="longitude" id="longitude" value="' + _coords.locale.longitude + '" />'); 333 } else { 334 $("#geo_tag").show(); 335 getGeolocate(); 336 setTimeout(function () { 337 getCoords(); 338 }, 5000); 339 } 340} 341 342function callAPI(post_url, type, callback) { 343 var json; 344 $.ajax({ 345 url: post_url, 346 type: type, 347 crossDomain: true, 348 cache: false, 349 beforeSend: function () { 350 notify('Aguarde!', msgLoading, 'info', 'toast-bottom-right'); 351 }, 352 success: function (result) { 353 json = result; 354 callback(json); 355 }, 356 error: function (result) { 357 json = result; 358 notify('Ops!', 'Ocorreu um erro: ' + result, 'error', 'toast-bottom-right'); 359 } 360 }); 361} 362 363function getCep(cep) { 364 if (cep != '_____-___') { 365 var post_url = 'https://viacep.com.br/ws/' + cep + '/json/'; 366 callAPI(post_url, 'GET', function (e) { 367 // console.log(e); 368 var cep = e; 369 $("#district").val((cep.uf).trim()); 370 $("#city").val((cep.localidade).trim()); 371 $("#neighborhood").val((cep.bairro).trim()); 372 $("#address").val((cep.logradouro).trim()); 373 $("#complement").val((cep.complemento).trim()); 374 toastr.clear(); 375 376 }); 377 } else { 378 toastr.error('Informe um CEP corretamente!'); 379 } 380} 381 382 383const getDateFormatted = (date) => { 384 let newDate = new Date(date) 385 let currentTimeZoneOffsetInHours = newDate.getTimezoneOffset() / 60 386 newDate.setHours(newDate.getHours() - currentTimeZoneOffsetInHours)
387 return newDate.toLocaleString('pt-BR') 388}; 389 390function formatDateBR(date) { 391 if (date) { 392 let data_string = date; 393 let date_format = new Date(date); 394 let _data = date_format.toLocaleDateString(); 395 console.log(data_string); 396 let _hora = (data_string).split(" ")[1]; 397 if (_hora) { 398 _data + ' ' + _hora.substring(0, 5); 399 } 400 return _data; 401 } else { 402 return ''; 403 } 404} 405 406function confirmRemove(e) { 407 console.log(e.data('href')); 408 console.log(e.data('row')); 409 $("#url-confirm").val(e.data('href')); 410 $("#row-remove").val(e.data('row')); 411 $('.debug-url').html('Confirma a exclusão do registro?'); 412} 413 414function removeThis(url, elemento) { 415 416 $.ajax({ 417 url: url, 418 type: "POST", 419 dataType: "text", 420 cache: false, 421 beforeSend: function () { }, 422 success: function (e) { 423 if (e != '' || e != null) { 424 var retorno = $.parseJSON(e); 425 console.log(retorno); 426 if (retorno != 'undefined') { 427 if (retorno.msg.error != '') { 428 notify('Atenção!', retorno.msg.error, 'error', 'toast-bottom-full-width', 1500); 429 } else { 430 notify('Sucesso!', retorno.msg.success, 'success', 'toast-bottom-right'); 431 $('#' + elemento).fadeOut(400, function () { 432 $('#' + elemento).remove(); 433 $('#confirmDelete').modal('hide'); 434 435 }); 436 } 437 } else { 438 notify('Ops!', 'Ocorreu um erro... Por favor, tente novamente!', 'error', 'toast-bottom-full-width'); 439 } 440 } else { 441 notify('Ops!', 'Tivemos um probleminha ao processar sua solicitação de cadastro.<br />Por favor, tente novamente!', 'error', 'toast-bottom-full-width'); 442 } 443 }, 444 error: function (e) { 445 notify('Ops!', 'Ocorreu um erro... Por favor, tente novamente!<br />' + console.log(e), 'error', 'toast-bottom-full-width'); 446 } 447 }); 448} 449 450function updateItem(e, url) { 451 var data = e[0].dataset; 452 var param = data.param; 453 var post_url = url; //get form action url 454 var request_method = 'post'; //get form GET/POST method 455 var form_data = param; //Encode form elements for submission 456 sendForm(post_url, request_method, form_data, function (e) { 457 if (e != '' || e != null) { 458 var retorno = e; //$.parseJSON(e); 459 if (retorno != 'undefined') { 460 if (retorno.msg.error != '') { 461 notify('Atenção!', retorno.msg.error, 'error', 'toast-bottom-full-width'); 462 } else { 463 notify('Sucesso!', retorno.msg.success, 'success', 'toast-bottom-right'); 464 } 465 } else { 466 notify('Ops!', 'Ocorreu um erro... Por favor, tente novamente!', 'error', 'toast-bottom-right'); 467 } 468 } else { 469 notify('Ops!', 'Ocorreu um erro... Tivemos um probleminha ao processar sua solicitação!', 'error', 'toast-bottom-right'); 470 } 471 }); 472} 473 474 475async function consultaCep(cep) { 476 // console.log(cep); 477 if (cep !== "" && cep.search("_") < 0) { 478 var post_url = "https://viacep.com.br/ws/" + cep + "/json/"; 479 var response = {}; 480 await callAPIAsync(post_url, "GET", function (e) { 481 $("#uf").val(e.uf.trim()); 482 $("#cidade").val(e.localidade.trim()); 483 $("#bairro").val(e.bairro.trim()); 484 $("#logradouro").val(e.logradouro.trim()); 485 $("#complemento").val(e.complemento.trim()); 486 response = { ...e }; 487 }); 488 return response; 489 } else { 490 toastr.error("Ops! Informe um CEP corretamente!"); 491 } 492 return null; 493} 494 495 496function callAPIAsync(post_url, type, callback) { 497 return $.ajax({ 498 url: post_url, 499 type: type, 500 crossDomain: true, 501 cache: false, 502 headers: { 503 "Access-Control-Allow-Origin": "*" 504 }, 505 beforeSend: function () { 506 notify('Aguarde!', "Consultando CEP!", 'success', 'toast-bottom-right'); 507 }, 508 success: function (result) { 509 callback(result); 510 }, 511 error: function (result) { 512 notify('Atenção!', "Ocorreu um erro: " + result, 'error', 'toast-bottom-right'); 513 }, 514 }); 515}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.