common-script.html 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <style>
  2. #ds-export{
  3. margin-bottom:3em;
  4. }
  5. .message-complete, .ds-exported .message-start, .ds-exporting .message-start, .status{
  6. display:none;
  7. }
  8. .ds-exported .message-complete, .message-start, .ds-exporting .status{
  9. display:block;
  10. }
  11. </style>
  12. <script type="text/javascript">
  13. function fireSyncLog(progress){
  14. var $ = jQuery, total = 0;
  15. $('#ds-sync .status').empty();
  16. $('#ds-sync').addClass('ds-exporting');
  17. var syncProgress = function () {
  18. $.ajax({
  19. url:ajaxurl,
  20. data:{action: 'duoshuo_sync_log'},
  21. error:duoshuoOnError,
  22. success:function(response) {
  23. if (response.code == 0){
  24. if (response.count){
  25. total += response.count;
  26. $('#ds-sync .status').html('已经同步了' + total + '条记录');
  27. syncProgress();
  28. }
  29. else{
  30. $('#ds-sync .status').html('全部同步完成');
  31. }
  32. }
  33. else{
  34. alert(response.errorMessage);
  35. }
  36. },
  37. dataType:'json'
  38. });
  39. };
  40. syncProgress();
  41. }
  42. function fireExport(){
  43. var $ = jQuery;
  44. $('#ds-export .status').empty();//.removeClass('ds-export-fail').html('处理中...');
  45. $('#ds-export').addClass('ds-exporting');
  46. $('#ds-export .status').html('开始同步 <img src="<?php echo $this->pluginDirUrl . 'images/waiting.gif';?>" />');
  47. var exportProgress = function (){
  48. var rdigit = /\d/;
  49. $.ajax({
  50. url:ajaxurl,
  51. data:{action: 'duoshuo_export'},
  52. error:duoshuoOnError,
  53. success:function(response) {
  54. if (response.code == 0){
  55. if (rdigit.test(response.progress) && !isNaN(response.progress)){
  56. $('#ds-export').removeClass('ds-exporting').addClass('ds-exported');
  57. }
  58. else{
  59. var lang = {'user':'用户', 'post':'文章', 'comment':'评论'}, progress = response.progress.split('/');
  60. $('#ds-export .status').html('正在同步' + lang[progress[0]] + '/' + progress[1] + ' <img src="<?php echo $this->pluginDirUrl . 'images/waiting.gif';?>" />');
  61. exportProgress();
  62. }
  63. }
  64. else{
  65. alert(response.errorMessage);
  66. }
  67. },
  68. dataType:'json'
  69. });
  70. };
  71. exportProgress();
  72. return false;
  73. }
  74. function duoshuoOnError(jqXHR, textStatus){
  75. switch(textStatus){
  76. case 'parsererror':
  77. alert('解析错误,联系多说客服帮助解决问题:' + jqXHR.responseText);
  78. break;
  79. case "abort":
  80. break;
  81. case "notmodified":
  82. case "error":
  83. case "timeout":
  84. default:
  85. var dict = {
  86. notmodified : '没有变化',
  87. error : '出错了',
  88. timeout : '超时了'
  89. };
  90. alert(dict[textStatus] + ', 联系多说客服帮助解决问题');
  91. }
  92. }
  93. </script>