PageRenderTime 46ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/podpress/js/jquery/podpress_jquery_ui_generalsettings_upgrade.js

https://github.com/AJenbo/ubuntudanmark.dk
JavaScript | 291 lines | 266 code | 12 blank | 13 comment | 104 complexity | 8a6cc50d9b5088c0a4fcf17936941294 MD5 | raw file
  1. /**
  2. * actions of the upgrade dialog on the General Settings page of podPress during the upgrade to 8.8.10.14
  3. * since 8.8.10.14
  4. */
  5. var podPress_dont_init_stats_upgr = true;
  6. podPress_jQuery(document).ready( function() {
  7. var table = 'statcounts';
  8. var w = Math.round(window.innerWidth-(window.innerWidth * 0.1));
  9. if (w > 900) {
  10. w = 1000;
  11. }
  12. var h = Math.round(window.innerHeight-(window.innerHeight * 0.1));
  13. if (h > 700) {
  14. h = 700;
  15. }
  16. podPress_jQuery("#podpress_dialog_stats_upgr").dialog({
  17. modal: true,
  18. closeOnEscape: false, // close when the ESC button has been pressed
  19. resizable: true,
  20. minWidth: 400,
  21. minHeight: 200,
  22. width: w,
  23. height: h,
  24. open: function(event, ui) {
  25. jQuery('.ui-dialog-buttonset').prepend('<img src="'+podPressBackendURL + 'images/ajax-loader.gif" alt="Working ..." style="display:none;" id="podpress_upgr_ajax_loader_img" /> ');
  26. podPress_jQuery(window).bind('beforeunload', function() {
  27. podpress_stats_status('start');
  28. });
  29. // stop the download counter
  30. podpress_stats_status('stop');
  31. // check whether the statcounts table has rows -> if yes then show the statcounts part otherwise show the stats part
  32. if ( 'true' == jQuery('#podpress_is_statcounts_upgr').val() ) {
  33. table = 'statcounts';
  34. jQuery('#podpress_upgr_header_table_name').text(table);
  35. podpress_initial_db_upgrade(table);
  36. }
  37. var rows_to_go = parseInt(jQuery('#podpress_upgr_'+table+'_to_process').text());
  38. if ( 'true' == jQuery('#podpress_is_stats_upgr').val() && (isNaN(rows_to_go) || 0 >= rows_to_go) ) {
  39. table = 'stats';
  40. jQuery('#podpress_upgr_header_table_name').text(table);
  41. jQuery('#podpress_upgr_part_counter_current').text('2');
  42. podpress_initial_db_upgrade(table);
  43. }
  44. },
  45. close: function( event, ui ) {
  46. // start the download counter again
  47. podpress_stats_status('start');
  48. },
  49. buttons: [
  50. {
  51. id: 'podpressbutton',
  52. text: podPress_jQuery('input[name="podPress_upgrade_stats_table_Submit"]').val(),
  53. click: function() {
  54. var rows_to_go = parseInt(jQuery('#podpress_upgr_'+table+'_to_process').text());
  55. if ( 0 < rows_to_go ) {
  56. podpress_upgr_stats(table);
  57. } else {
  58. if ( 'statcounts' == table && 'true' == jQuery('#podpress_is_stats_upgr').val() ) {
  59. table = 'stats';
  60. jQuery('#podpress_upgr_header_table_name').text(table);
  61. jQuery('#podpress_upgr_part_counter_current').text('2');
  62. podpress_initial_db_upgrade(table);
  63. } else {
  64. // hide Close button of the dialog
  65. podPress_jQuery(".ui-dialog-titlebar-close").hide();
  66. podPress_jQuery(this).dialog('close');
  67. location.reload();
  68. }
  69. }
  70. }
  71. }
  72. ]
  73. });
  74. });
  75. function podpress_initial_db_upgrade(table) {
  76. if ('stats' == table || 'statcounts' == table) {
  77. var rows = podpress_current_nr_of_rows(table);
  78. if (rows > 0) {
  79. podpress_print_upgrade_form(table, 'true');
  80. jQuery('#podPress_upgrade_'+table+'_table').show();
  81. podpress_upgr_stats(table, 'true');
  82. }
  83. }
  84. }
  85. function podpress_stats_status(action) {
  86. if ( typeof action == 'undefined' ) { var action = 'stop'; }
  87. var result = 'failed';
  88. var upgr_process_nr = parseInt(jQuery('#podpress_upgr_process_nr').val());
  89. jQuery.ajax({
  90. async: false,
  91. url: podPressBackendURL + '/podpress_backend.php',
  92. type: 'POST',
  93. dataType: 'text',
  94. data: '&action=upgradeaction&upgr_process_nr=' + encodeURIComponent(upgr_process_nr) + '&podpress_upgr_misc[startstopstats]=' + encodeURIComponent(action) + '&_ajax_nonce=' + encodeURIComponent(jQuery.trim(jQuery('#podpress_ajax_nonce_key').val())),
  95. success: function(data, textStatus, XMLHttpRequest) {
  96. var podpress_result_obj = jQuery.parseJSON(XMLHttpRequest.responseText);
  97. if ( '' != podpress_result_obj.code ) {
  98. result = 'success';
  99. }
  100. },
  101. complete: function (jqXHR, textStatus) {
  102. //~ alert('stats start stop complete' + '\n' + result);
  103. }
  104. });
  105. }
  106. function podpress_upgr_stats(table, isinit) {
  107. if ('stats' == table || 'statcounts' == table) {
  108. if ( typeof isinit == 'undefined' || ('false' != isinit && 'true' != isinit) ) { var isinit = 'false'; }
  109. if ( 'true' == isinit ) {
  110. var asyncmethod = false;
  111. } else {
  112. var asyncmethod = true;
  113. }
  114. podPress_jQuery('#podpressbutton').attr("disabled", true);
  115. jQuery('#podpress_upgr_'+table+'_increment').attr("disabled", true);
  116. jQuery('#podpress_upgr_ajax_loader_img').css('display', 'inline');
  117. var upgr_process_nr = parseInt(jQuery('#podpress_upgr_process_nr').val());
  118. var totalrows = parseInt(jQuery('#podpress_upgr_'+table+'_total_rows').text());
  119. jQuery.ajax({
  120. async: asyncmethod,
  121. url: podPressBackendURL + '/podpress_backend.php',
  122. type: 'POST',
  123. dataType: 'text',
  124. data: '&action=upgradeaction&upgr_process_nr=' + encodeURIComponent(upgr_process_nr) + '&podpress_upgr_misc[tablename]=' + encodeURIComponent(table) + '&podpress_upgr_misc[totalrows]=' + encodeURIComponent(totalrows) + '&podpress_upgr_misc[increment]=' + encodeURIComponent(parseInt(jQuery('#podpress_upgr_'+table+'_increment').val())) + '&_ajax_nonce=' + encodeURIComponent(jQuery.trim(jQuery('#podpress_ajax_nonce_key').val())),
  125. success: function(data, textStatus, XMLHttpRequest){
  126. var podpress_result_obj = jQuery.parseJSON(XMLHttpRequest.responseText);
  127. if ( '' != podpress_result_obj.code ) {
  128. jQuery('#podpress_upgr_elapsed_time').text(podpress_result_obj.time);
  129. var max_execution_time = parseFloat(jQuery('#podpress_upgr_max_execution_time').text());
  130. var max_steps = Math.floor(max_execution_time / ((parseFloat(podpress_result_obj.time)+2.0) / parseFloat(podpress_result_obj.increment)));
  131. jQuery('#podpress_upgr_'+table+'_increment_limit').text(max_steps);
  132. var increment_options = jQuery('#podpress_upgr_'+table+'_increment').children();
  133. var increment_options_nr = increment_options.length;
  134. var total_rows = parseInt(jQuery('#podpress_upgr_'+table+'_total_rows').text());
  135. if (max_steps > total_rows) {
  136. max_steps = total_rows;
  137. }
  138. var last_enabled_option = 0;
  139. var selectedval = -1;
  140. for (i=0; i < increment_options_nr; i++) {
  141. if ( i==0 && increment_options[i].value > max_steps ) {
  142. var newoption = jQuery('<option></option>').attr('value', max_steps).text(max_steps);
  143. newoption.prependTo(jQuery('#podpress_upgr_'+table+'_increment:first'));
  144. } else if ( i > 0 && increment_options[(i-1)].value < max_steps && max_steps < increment_options[i].value ) {
  145. var newoption = jQuery('<option></option>').attr('value', max_steps).text(max_steps);
  146. newoption.insertAfter(jQuery(increment_options[(i-1)]));
  147. } else if ( i == (increment_options_nr-1) && increment_options[i].value < max_steps ) {
  148. jQuery('#podpress_upgr_'+table+'_increment').append(jQuery('<option></option>').attr('value', max_steps).text(max_steps));
  149. }
  150. if (increment_options[i].value > max_steps) {
  151. increment_options[i].disabled = true;
  152. } else {
  153. increment_options[i].disabled = false;
  154. }
  155. if ( increment_options[i].disabled == false ) {
  156. last_enabled_option = i;
  157. }
  158. if ( increment_options[i].selected == true ) {
  159. selectedval = i;
  160. }
  161. }
  162. jQuery('#podpress_upgr_used_increment').text(podpress_result_obj.increment);
  163. jQuery('#podpress_upgr_'+table+'_increment').attr("disabled", false);
  164. // select a enabled option (if none has been selected or if the previous value is now disabled)
  165. if ( selectedval > last_enabled_option || selectedval == -1 ) {
  166. increment_options[last_enabled_option].selected = true;
  167. }
  168. podpress_result_obj.increment = parseInt(jQuery('#podpress_upgr_'+table+'_increment').val());
  169. var rows_to_go = total_rows - podpress_result_obj.lastpos;
  170. if ( 0 > rows_to_go ) {
  171. var rows_to_go = 0;
  172. }
  173. jQuery('#podpress_upgr_'+table+'_lastpos').val(podpress_result_obj.lastpos);
  174. jQuery('#podpress_upgr_'+table+'_to_process').text(rows_to_go);
  175. if ( 0 < rows_to_go ) {
  176. if ( total_rows < (podpress_result_obj.lastpos+podpress_result_obj.increment) ) {
  177. var newbuttontext = podPress_jQuery('input[name="podPress_upgrade_stats_table_Submit"]').val().replace(/\.{3}/, String(podpress_result_obj.lastpos) + ' - ' + String(total_rows));
  178. } else {
  179. var newbuttontext = podPress_jQuery('input[name="podPress_upgrade_stats_table_Submit"]').val().replace(/\.{3}/, String(podpress_result_obj.lastpos) + ' - ' + String((podpress_result_obj.lastpos+podpress_result_obj.increment)));
  180. }
  181. } else {
  182. var newbuttontext = podPress_jQuery('input[name="podPress_upgrade_stats_table_finished"]').val();
  183. podpress_finish_upgrade(table);
  184. }
  185. podPress_jQuery('#podpressbutton').text(newbuttontext);
  186. podPress_jQuery('#podpressbutton').attr("disabled", false);
  187. } else {
  188. Alert('error\n'+XMLHttpRequest.responseText);
  189. }
  190. jQuery('#podpress_upgr_ajax_loader_img').css('display', 'none');
  191. }
  192. });
  193. }
  194. }
  195. function podpress_update_button_text_on_increment_change(table, increment) {
  196. if ('stats' == table || 'statcounts' == table) {
  197. if ( typeof increment == 'undefined' ) {
  198. var increment = 1;
  199. } else {
  200. increment = parseInt(increment);
  201. if (increment < 1) { increment = 1; }
  202. }
  203. var lastpos = parseInt(jQuery('#podpress_upgr_'+table+'_lastpos').val());
  204. var total_rows = parseInt(jQuery('#podpress_upgr_'+table+'_total_rows').text());
  205. var rows_to_go = parseInt(jQuery('#podpress_upgr_'+table+'_to_process').text());
  206. if ( 0 < rows_to_go ) {
  207. if ( total_rows < (lastpos+increment) ) {
  208. var newbuttontext = podPress_jQuery('input[name="podPress_upgrade_stats_table_Submit"]').val().replace(/\.{3}/, String(lastpos) + ' - ' + String(total_rows));
  209. } else {
  210. var newbuttontext = podPress_jQuery('input[name="podPress_upgrade_stats_table_Submit"]').val().replace(/\.{3}/, String(lastpos) + ' - ' + String((lastpos+increment)));
  211. }
  212. } else {
  213. var newbuttontext = podPress_jQuery('input[name="podPress_upgrade_stats_table_finished"]').val();
  214. }
  215. podPress_jQuery('#podpressbutton').text(newbuttontext);
  216. }
  217. }
  218. function podpress_current_nr_of_rows(table, isinit) {
  219. var result = 'failed';
  220. if ('stats' == table || 'statcounts' == table) {
  221. if ( typeof isinit == 'undefined' || ('false' != isinit && 'true' != isinit) ) { var isinit = 'false'; }
  222. var upgr_process_nr = parseInt(jQuery('#podpress_upgr_process_nr').val());
  223. jQuery.ajax({
  224. async: false,
  225. url: podPressBackendURL + '/podpress_backend.php',
  226. type: 'POST',
  227. dataType: 'text',
  228. data: '&action=curnrofrows&upgr_process_nr=' + encodeURIComponent(upgr_process_nr) + '&podpress_upgr_misc[table]=' + encodeURIComponent(table) + '&podpress_upgr_misc[isinit]=' + encodeURIComponent(isinit) + '&_ajax_nonce=' + encodeURIComponent(jQuery.trim(jQuery('#podpress_ajax_nonce_key').val())),
  229. success: function(data, textStatus, XMLHttpRequest) {
  230. var podpress_result_obj = jQuery.parseJSON(XMLHttpRequest.responseText);
  231. if ( '' != podpress_result_obj.code ) {
  232. result = 'success';
  233. }
  234. result = podpress_result_obj.rows;
  235. },
  236. complete: function (jqXHR, textStatus) {
  237. //~ alert('current nr of rows complete' + '\n' + result);
  238. }
  239. });
  240. }
  241. return Number(result);
  242. }
  243. function podpress_print_upgrade_form(table, isinit) {
  244. if ('stats' == table || 'statcounts' == table) {
  245. if ( typeof isinit == 'undefined' || ('false' != isinit && 'true' != isinit) ) { var isinit = 'false'; }
  246. var upgr_process_nr = parseInt(jQuery('#podpress_upgr_process_nr').val());
  247. jQuery.ajax({
  248. async: false,
  249. url: podPressBackendURL + '/podpress_backend.php',
  250. type: 'POST',
  251. dataType: 'text',
  252. data: '&action=printupgradeform&upgr_process_nr=' + encodeURIComponent(upgr_process_nr) + '&podpress_upgr_misc[table]=' + encodeURIComponent(table) + '&podpress_upgr_misc[isinit]=' + encodeURIComponent(isinit) + '&_ajax_nonce=' + encodeURIComponent(jQuery.trim(jQuery('#podpress_ajax_nonce_key').val())),
  253. success: function(data, textStatus, XMLHttpRequest) {
  254. jQuery('#podPress_upgrade_form').html(XMLHttpRequest.responseText);
  255. },
  256. complete: function (jqXHR, textStatus) {
  257. //~ alert('podpress_print_upgrade_form complete');
  258. }
  259. });
  260. }
  261. }
  262. function podpress_finish_upgrade(table) {
  263. if ('stats' == table || 'statcounts' == table) {
  264. var upgr_process_nr = parseInt(jQuery('#podpress_upgr_process_nr').val());
  265. jQuery.ajax({
  266. async: false,
  267. url: podPressBackendURL + '/podpress_backend.php',
  268. type: 'POST',
  269. dataType: 'text',
  270. data: '&action=finishupgradeaction&upgr_process_nr=' + encodeURIComponent(upgr_process_nr) + '&podpress_upgr_misc[table]=' + encodeURIComponent(table) + '&_ajax_nonce=' + encodeURIComponent(jQuery.trim(jQuery('#podpress_ajax_nonce_key').val())),
  271. success: function(data, textStatus, XMLHttpRequest) {
  272. jQuery('#podPress_upgrade_form').html(XMLHttpRequest.responseText);
  273. },
  274. complete: function (jqXHR, textStatus) {
  275. //~ alert('podpress_print_upgrade_form complete');
  276. }
  277. });
  278. }
  279. }