dd/resources/js/nasa/components/tomModal.js
2026-07-27 15:25:10 +08:00

133 lines
3.7 KiB
JavaScript

import $ from 'jquery';
$(".tom-modal").removeAttr('hidden');
$(document).on('keydown', '.tom-modal', function(oEvent) {
if (oEvent.which === 27) {
oEvent.preventDefault();
$(this).find('.js-tom-modal-close').click();
return false;
}
});
$(document).on('click', '.js-tom-modal-save', function() {
let iId = $(this).attr('tom-modal-save-id');
let oCurrentBtn = $(this);
let sUrl = $(this).attr('tom-modal-save-url');
let bToClose = $(this).attr('tom-modal-save-close');
let sApiUrl = sUrl;
if (iId) {
sApiUrl = sApiUrl+iId
}
let sApiPath = $('#nasa_api_path').val();
let oParams = {};
$(this).closest(".tom-modal")
.find('.js-tom-modal-save-checked:checked')
.each(function(){
let oCheckbox = $(this);
let sFieldName = oCheckbox.attr('field');
if (!sFieldName) {
return true;
}
let xVal = $('.js-tom-modal-save-input[field="'+sFieldName+'"]').val();
if (typeof xVal === 'string') {
xVal = xVal.trim();
}
oParams[sFieldName] = xVal;
});
let oTomAlert = $('.js-tom-alert-success-simple').first();
oParams['nasa_api_path'] = sApiPath;
oParams['nasa_site_www'] = $("#nasa_site_www").val()
$.ajax({
url: sApiUrl,
type: 'PUT',
dataType: 'json',
data: oParams,
success: function(j) {
if (j && j.sMsg) {
j.sMsg = j.sMsg+'';
oTomAlert.attr('tom-alert-msg', j.sMsg);
oTomAlert.trigger('click');
}
if (bToClose != "false") {
oTomAlert.one('tomAlert:confirmed', function() {
$('.tom-modal.is-active').find('.js-tom-modal-close').trigger('click');
$(".js-custom-condition-filter").trigger('click');
});
}
},
error: function(oXHR, sTextStatus, sErrorThrown) {
if (sTextStatus === 'timeout') {
alert('📡 网络极度拥堵,请求超时,请稍后再试!');
} else {
alert('炸了,错误代码: ' + oXHR.status);
}
},
complete: function() {
oCurrentBtn.prop('disabled', false).removeClass('is-loading');
}
});
});
$(document).on('click', '.js-tom-modal-open', function(oEvent) {
$("body").addClass('overflow-hide');
let sModalName = $(this).attr('tom-modal-open');
tomModalShow(sModalName, $(this).attr('tom-modal-data-id'));
});
$(document).on('click', '.js-tom-modal-close', function() {
$("body").removeClass('overflow-hide');
$(this).closest(".tom-modal").removeClass('is-active');
});
$(document).on('click', '.tom-modal', function(oEvent) {
let oCurrentModal = $(this);
if (oEvent.target !== oEvent.currentTarget) {
return;
}
let sLockValue = oCurrentModal.attr('tom-modal-lock');
if (sLockValue === 'true') {
return;
}
oCurrentModal.removeClass('is-active');
$("body").removeClass('overflow-hide');
});
function tomModalShow(sModalName, iDataId = '')
{
let oCurrentModal = $('.tom-modal[tom-modal-name="' + sModalName + '"]');
oCurrentModal.addClass('is-active');
oCurrentModal.attr('tom-modal-data-id', iDataId);
oCurrentModal.focus();
}
window.tomModalShow = tomModalShow;
function tomModalHide(sModalName)
{
let oCurrentModal = $('.tom-modal[tom-modal-name="' + sModalName + '"]');
oCurrentModal.removeClass('is-active');
}
window.tomModalHide = tomModalHide;