|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- jQuery( document ).ready( function ()
- {
- jQuery('#options-changed').hide();
-
- jQuery('#site_id').mask("09999")
- .blur(function()
- {
- if( jQuery(this).val().match(/^\d+$/gm) ) {
- jQuery(this).removeClass('error');
- } else {
- jQuery(this).addClass('error');
- }
- });
- jQuery('#api_ip').mask("099.099.099.099")
- .blur(function()
- {
- if( jQuery(this).val().match(/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/gm) ) {
- jQuery(this).removeClass('error');
- } else {
- jQuery(this).addClass('error');
- }
- });
- jQuery('#api_port').mask("99999")
- .blur(function()
- {
- if( jQuery(this).val().match(/^\d{5}$/gm) ) {
- jQuery(this).removeClass('error');
- } else {
- jQuery(this).addClass('error');
- }
- });
- jQuery('#api_secret').mask("ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ", {translation: {'Z': {pattern: /[a-zA-Z0-9]/, optional: true}}})
- .blur(function()
- {
- if( '' !== jQuery(this).val() ) {
- jQuery(this).removeClass('error');
- } else {
- jQuery(this).addClass('error');
- }
- });
-
- jQuery('#chiefred-options input, #chiefred-options select').trigger( "blur" );
-
- jQuery("#site_ip,#sync_script_url,#canonical_script_url").click(function()
- {
- jQuery(this).select();
- });
-
- jQuery('#chiefred-options #site_id, #chiefred-options #api_ip , #chiefred-options #api_port, #chiefred-options #api_secret').change(function()
- {
- jQuery('.utils').hide();
- jQuery('#options-changed').show();
- });
-
- jQuery('.chiefred-options-cancel-btn').click(function()
- {
- location.reload();
- });
-
- jQuery('.chiefred-options-save-btn').click(function()
- {
- jQuery('#chiefred-options').submit();
- });
-
- jQuery('.chiefred-synchronize-log-btn').click(function()
- {
- jQuery.ajax({
- type: "POST",
- url: ajaxurl,
- data: {
- action: 'display_synchronize_log',
- },
- success: function(data)
- {
- jQuery('#TB_ajaxWindowTitle').text('Журнал последней синхронизации');
- jQuery('#TB_ajaxContent').html('<pre class="synchronize_log">' + data + '</pre>');
- },
- error: function(data)
- {
- console.log('error:', data);
- },
- });
- });
-
- setInterval(
- function()
- {
- if(jQuery('pre.synchronize_log').is(":visible")) {
- jQuery.ajax({
- type: "POST",
- url: ajaxurl,
- data: {
- action: 'display_synchronize_log',
- },
- success: function(data)
- {
- jQuery('pre.synchronize_log').html(data);
- },
- error: function(data)
- {
- console.log('error:', data);
- },
- });
- }
- }
- , 3000
- );
-
- jQuery('.chiefred-synchronize-btn').click(function()
- {
- jQuery.ajax({
- type: "POST",
- url: location.href,
- data: {
- chiefred_action: 'synchronize',
- chiefred_token: jQuery('#chiefred_token').val()
- },
- beforeSend: function (xhr) {
- xhr.setRequestHeader('X-WP-Nonce', jQuery('#chiefred_token').val());
- },
- success: function(data)
- {
- if('ok'==data){
- alert('Внеплановая синхронизация успешно инициирована');
- } else {
- alert('Не удалось инициировать синхронизацию');
- }
- },
- error: function(data)
- {
- console.log('error:', data);
- },
- });
- });
-
- jQuery('.chiefred-clear-synchronize-btn').click(function()
- {
- jQuery.ajax({
- type: "POST",
- url: location.href,
- data: {
- chiefred_action: 'clear_synchronize',
- chiefred_token: jQuery('#chiefred_token').val()
- },
- beforeSend: function (xhr) {
- xhr.setRequestHeader('X-WP-Nonce', jQuery('#chiefred_token').val());
- },
- success: function(data)
- {
- if('ok'==data){
- alert('Внеплановая синхронизация успешно отменена');
- } else {
- alert('Не удалось отменить внеплановую синхронизацию');
- }
- },
- error: function(data)
- {
- console.log('error:', data);
- },
- });
- });
- });
|