Пример моего кода на PHP... И не только.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

162 lines
5.3KB

  1. jQuery( document ).ready( function ()
  2. {
  3. jQuery('#options-changed').hide();
  4. jQuery('#site_id').mask("09999")
  5. .blur(function()
  6. {
  7. if( jQuery(this).val().match(/^\d+$/gm) ) {
  8. jQuery(this).removeClass('error');
  9. } else {
  10. jQuery(this).addClass('error');
  11. }
  12. });
  13. jQuery('#api_ip').mask("099.099.099.099")
  14. .blur(function()
  15. {
  16. 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) ) {
  17. jQuery(this).removeClass('error');
  18. } else {
  19. jQuery(this).addClass('error');
  20. }
  21. });
  22. jQuery('#api_port').mask("99999")
  23. .blur(function()
  24. {
  25. if( jQuery(this).val().match(/^\d{5}$/gm) ) {
  26. jQuery(this).removeClass('error');
  27. } else {
  28. jQuery(this).addClass('error');
  29. }
  30. });
  31. jQuery('#api_secret').mask("ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ", {translation: {'Z': {pattern: /[a-zA-Z0-9]/, optional: true}}})
  32. .blur(function()
  33. {
  34. if( '' !== jQuery(this).val() ) {
  35. jQuery(this).removeClass('error');
  36. } else {
  37. jQuery(this).addClass('error');
  38. }
  39. });
  40. jQuery('#chiefred-options input, #chiefred-options select').trigger( "blur" );
  41. jQuery("#site_ip,#sync_script_url,#canonical_script_url").click(function()
  42. {
  43. jQuery(this).select();
  44. });
  45. jQuery('#chiefred-options #site_id, #chiefred-options #api_ip , #chiefred-options #api_port, #chiefred-options #api_secret').change(function()
  46. {
  47. jQuery('.utils').hide();
  48. jQuery('#options-changed').show();
  49. });
  50. jQuery('.chiefred-options-cancel-btn').click(function()
  51. {
  52. location.reload();
  53. });
  54. jQuery('.chiefred-options-save-btn').click(function()
  55. {
  56. jQuery('#chiefred-options').submit();
  57. });
  58. jQuery('.chiefred-synchronize-log-btn').click(function()
  59. {
  60. jQuery.ajax({
  61. type: "POST",
  62. url: ajaxurl,
  63. data: {
  64. action: 'display_synchronize_log',
  65. },
  66. success: function(data)
  67. {
  68. jQuery('#TB_ajaxWindowTitle').text('Журнал последней синхронизации');
  69. jQuery('#TB_ajaxContent').html('<pre class="synchronize_log">' + data + '</pre>');
  70. },
  71. error: function(data)
  72. {
  73. console.log('error:', data);
  74. },
  75. });
  76. });
  77. setInterval(
  78. function()
  79. {
  80. if(jQuery('pre.synchronize_log').is(":visible")) {
  81. jQuery.ajax({
  82. type: "POST",
  83. url: ajaxurl,
  84. data: {
  85. action: 'display_synchronize_log',
  86. },
  87. success: function(data)
  88. {
  89. jQuery('pre.synchronize_log').html(data);
  90. },
  91. error: function(data)
  92. {
  93. console.log('error:', data);
  94. },
  95. });
  96. }
  97. }
  98. , 3000
  99. );
  100. jQuery('.chiefred-synchronize-btn').click(function()
  101. {
  102. jQuery.ajax({
  103. type: "POST",
  104. url: location.href,
  105. data: {
  106. chiefred_action: 'synchronize',
  107. chiefred_token: jQuery('#chiefred_token').val()
  108. },
  109. beforeSend: function (xhr) {
  110. xhr.setRequestHeader('X-WP-Nonce', jQuery('#chiefred_token').val());
  111. },
  112. success: function(data)
  113. {
  114. if('ok'==data){
  115. alert('Внеплановая синхронизация успешно инициирована');
  116. } else {
  117. alert('Не удалось инициировать синхронизацию');
  118. }
  119. },
  120. error: function(data)
  121. {
  122. console.log('error:', data);
  123. },
  124. });
  125. });
  126. jQuery('.chiefred-clear-synchronize-btn').click(function()
  127. {
  128. jQuery.ajax({
  129. type: "POST",
  130. url: location.href,
  131. data: {
  132. chiefred_action: 'clear_synchronize',
  133. chiefred_token: jQuery('#chiefred_token').val()
  134. },
  135. beforeSend: function (xhr) {
  136. xhr.setRequestHeader('X-WP-Nonce', jQuery('#chiefred_token').val());
  137. },
  138. success: function(data)
  139. {
  140. if('ok'==data){
  141. alert('Внеплановая синхронизация успешно отменена');
  142. } else {
  143. alert('Не удалось отменить внеплановую синхронизацию');
  144. }
  145. },
  146. error: function(data)
  147. {
  148. console.log('error:', data);
  149. },
  150. });
  151. });
  152. });