Cdn_RackSpaceCdn_Page_View.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. jQuery(function($) {
  2. function w3tc_rackspace_resize(o) {
  3. o.resize();
  4. }
  5. function w3tc_rackspace_created(o) {
  6. w3tc_rackspace_resize(o);
  7. w3tc_rackspace_check_service_state();
  8. }
  9. function w3tc_rackspace_check_service_state() {
  10. var service_id = jQuery('input[name="service_id"]').val();
  11. var access_token = jQuery('input[name="access_token"]').val();
  12. var access_region_descriptor = jQuery('input[name="access_region_descriptor"]').val();
  13. jQuery.post(ajaxurl,
  14. {
  15. 'action': 'w3tc_ajax',
  16. '_wpnonce': w3tc_nonce,
  17. 'service_id': service_id,
  18. 'access_token': access_token,
  19. 'access_region_descriptor': access_region_descriptor,
  20. 'w3tc_action': 'cdn_rackspace_service_get_state'
  21. }, function(data) {
  22. var state = 'unknown';
  23. if (data && data['status'])
  24. status = data['status'];
  25. jQuery('.w3tc_rackspace_created_status').html(status);
  26. if (status == 'deployed')
  27. w3tc_rackspace_service_created_done(data);
  28. else
  29. setTimeout(w3tc_rackspace_check_service_state, 5000);
  30. }, 'json'
  31. ).fail(function() {
  32. jQuery('.w3tc_rackspace_created_state').html('Failed to obtain state');
  33. setTimeout(w3tc_rackspace_check_service_state, 5000);
  34. });
  35. }
  36. function w3tc_rackspace_service_created_done(data) {
  37. jQuery('.w3tc_rackspace_cname').html(data['cname']);
  38. jQuery('.w3tc_rackspace_access_url').html(data['access_url']);
  39. jQuery('.w3tc_rackspace_created_in_progress').css('display', 'none');
  40. jQuery('.w3tc_rackspace_created_done').css('display', '');
  41. w3tc_rackspace_resize(W3tc_Lightbox);
  42. }
  43. $('body')
  44. /**
  45. * Authorize popup
  46. */
  47. .on('click', '.w3tc_cdn_rackspace_authorize', function() {
  48. W3tc_Lightbox.open({
  49. id:'w3tc-overlay',
  50. close: '',
  51. width: 800,
  52. height: 300,
  53. url: ajaxurl + '?action=w3tc_ajax&_wpnonce=' + w3tc_nonce +
  54. '&w3tc_action=cdn_rackspace_intro',
  55. callback: w3tc_rackspace_resize
  56. });
  57. })
  58. .on('click', '.w3tc_popup_submit', function() {
  59. var url = ajaxurl + '?action=w3tc_ajax&_wpnonce=' + w3tc_nonce;
  60. W3tc_Lightbox.load_form(url, '.w3tc_cdn_rackspace_form',
  61. w3tc_rackspace_resize);
  62. })
  63. .on('click', '.w3tc_cdn_rackspace_service_create_done', function() {
  64. var url = ajaxurl + '?action=w3tc_ajax&_wpnonce=' + w3tc_nonce +
  65. '&w3tc_action=cdn_rackspace_service_create_done';
  66. W3tc_Lightbox.load_form(url, '.w3tc_cdn_rackspace_form',
  67. w3tc_rackspace_created);
  68. })
  69. .on('click', '.w3tc_cdn_rackspace_protocol', function() {
  70. var protocol = '';
  71. $('body').find('.w3tc_cdn_rackspace_protocol').each(function(i) {
  72. if (!jQuery(this).prop('checked'))
  73. return;
  74. protocol = $(this).val();
  75. });
  76. //alert('ha ' + protocol);
  77. $('.w3tc_cdn_rackspace_cname_http').css('display',
  78. (protocol == 'http' ? '' : 'none'));
  79. $('.w3tc_cdn_rackspace_cname_https').css('display',
  80. (protocol == 'https' ? '' : 'none'));
  81. })
  82. /**
  83. * CNAMEs popup
  84. */
  85. .on('click', '.w3tc_cdn_rackspace_configure_domains', function() {
  86. W3tc_Lightbox.open({
  87. id:'w3tc-overlay',
  88. close: '',
  89. width: 1000,
  90. height: 400,
  91. url: ajaxurl + '?action=w3tc_ajax&_wpnonce=' + w3tc_nonce +
  92. '&w3tc_action=cdn_rackspace_configure_domains',
  93. callback: function(o) {
  94. w3tc_rackspace_resize(o);
  95. w3tc_cdn_cnames_assign();
  96. }
  97. });
  98. })
  99. .on('click', '.w3tc_cdn_rackspace_configure_domains_done', function() {
  100. var url = ajaxurl + '?action=w3tc_ajax&_wpnonce=' + w3tc_nonce +
  101. '&w3tc_action=cdn_rackspace_configure_domains_done';
  102. var v = $('.w3tc_cdn_rackspace_form').find('input').each(function(i) {
  103. var name = $(this).attr('name');
  104. if (name)
  105. url += '&' + encodeURIComponent(name) + '=' +
  106. encodeURIComponent($(this).val());
  107. });
  108. W3tc_Lightbox.load(url, function(o) {
  109. w3tc_rackspace_resize(o);
  110. w3tc_cdn_cnames_assign();
  111. });
  112. })
  113. .on('size_change', '#cdn_cname_add', function() {
  114. w3tc_rackspace_resize(W3tc_Lightbox);
  115. })
  116. });