/
home
/
vianto5
/
duettowers.mx
/
wp-content
/
plugins
/
hm-site-monitor-supabase
/
assets
/
js
/
/home/vianto5/duettowers.mx/wp-content/plugins/hm-site-monitor-supabase/assets/js
mkdir
upload
Name
Size
Mode
Actions
admin.js
5731
0644
edit
dl
rm
Edit:
/home/vianto5/duettowers.mx/wp-content/plugins/hm-site-monitor-supabase/assets/js/admin.js
(5731B)
/** * JavaScript de administración para HM Site Monitor - Supabase */ (function($) { 'use strict'; var HMSMSB = { init: function() { this.bindEvents(); }, bindEvents: function() { $('#hmsmsb-sync-now').on('click', this.syncNow.bind(this)); $('#hmsmsb-test-connection').on('click', this.testConnection.bind(this)); $('#hmsmsb-regenerate-key').on('click', this.regenerateApiKey.bind(this)); }, showNotice: function(message, type) { var $notice = $('#hmsmsb-sync-result'); $notice .removeClass('hidden success error loading') .addClass(type) .html(message); }, setButtonLoading: function($button, loading) { if (loading) { $button.prop('disabled', true).find('.dashicons').addClass('hmsmsb-spinner'); } else { $button.prop('disabled', false).find('.dashicons').removeClass('hmsmsb-spinner'); } }, syncNow: function(e) { e.preventDefault(); var self = this; var $button = $('#hmsmsb-sync-now'); this.setButtonLoading($button, true); this.showNotice(hmsmsbAjax.strings.syncing, 'loading'); $.ajax({ url: hmsmsbAjax.ajaxUrl, type: 'POST', data: { action: 'hmsmsb_manual_sync', nonce: hmsmsbAjax.nonce }, success: function(response) { self.setButtonLoading($button, false); if (response.success) { self.showNotice( '<strong>' + hmsmsbAjax.strings.success + '</strong><br>' + 'Última sincronización: ' + response.data.last_sync, 'success' ); self.updateLastSyncDisplay(response.data.last_sync); } else { self.showNotice( '<strong>' + hmsmsbAjax.strings.error + '</strong><br>' + response.data.message, 'error' ); } }, error: function(xhr, status, error) { self.setButtonLoading($button, false); self.showNotice( '<strong>' + hmsmsbAjax.strings.error + '</strong><br>' + 'Error de conexión: ' + error, 'error' ); } }); }, testConnection: function(e) { e.preventDefault(); var self = this; var $button = $('#hmsmsb-test-connection'); this.setButtonLoading($button, true); this.showNotice('Probando conexión con Supabase...', 'loading'); $.ajax({ url: hmsmsbAjax.ajaxUrl, type: 'POST', data: { action: 'hmsmsb_test_connection', nonce: hmsmsbAjax.nonce }, success: function(response) { self.setButtonLoading($button, false); if (response.success) { self.showNotice( '<strong>Conexión exitosa</strong><br>' + response.data.message, 'success' ); } else { self.showNotice( '<strong>Error de conexión</strong><br>' + response.data.message, 'error' ); } }, error: function(xhr, status, error) { self.setButtonLoading($button, false); self.showNotice('<strong>Error</strong><br>Error de red: ' + error, 'error'); } }); }, regenerateApiKey: function(e) { e.preventDefault(); if (!confirm('¿Regenerar la API Key? La key anterior dejará de funcionar.')) { return; } var self = this; $.ajax({ url: hmsmsbAjax.ajaxUrl, type: 'POST', data: { action: 'hmsmsb_regenerate_api_key', nonce: hmsmsbAjax.nonce }, success: function(response) { if (response.success) { $('#hmsmsb_api_key_display').val(response.data.api_key); self.showNotice( '<strong>API Key regenerada</strong><br>' + response.data.message, 'success' ); } else { self.showNotice('<strong>Error</strong><br>' + response.data.message, 'error'); } } }); }, updateLastSyncDisplay: function(timestamp) { var $card = $('.hmsmsb-status-card').filter(function() { return $(this).find('strong').text().indexOf('Última sincronización') !== -1; }); if ($card.length) { $card.removeClass('neutral error').addClass('success'); $card.find('.hmsmsb-status-info span').text(timestamp); } } }; $(document).ready(function() { HMSMSB.init(); }); })(jQuery);
Save
cmd:
run