gamemanager.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. function uploadMapImg(button) {
  2. var home_id = $(button).attr('id');
  3. var mod_id = $(button).attr('data-mod_id');
  4. var map = $(button).attr('data-map');
  5. var title = $('#translation').attr('data-title');
  6. var upload_button = $('#translation').attr('data-upload_button');
  7. var bad_file = $('#translation').attr('data-bad_file');
  8. var upload_failure = $('#translation').attr('data-upload_failure');
  9. $('div.main-content').append('<div class="dialog-form'+home_id+'" title="'+title+'" >\
  10. <form class="upload-mapImage-form'+home_id+'" enctype="multipart/form-data" >\
  11. <input type="hidden" name="map" value="'+map+'" />\
  12. <input type="file" name="map-image" class="'+home_id+'" value="" />\
  13. <input type="hidden" name="home_id" value="'+home_id+'" />\
  14. <input type="hidden" name="mod_id" value="'+mod_id+'" />\
  15. </form>\
  16. </div>');
  17. $( ".dialog-form"+home_id ).dialog({
  18. autoOpen: true,
  19. height: 145,
  20. width: 350,
  21. modal: true,
  22. buttons: [{ text: upload_button, click: function(){
  23. var filename = $('input[name=map-image].'+home_id).val().split('\\').pop(),
  24. extension = filename.split('.').pop();
  25. if(extension.match(/png|jpg|gif/) != null)
  26. {
  27. filesize = $('input[name=map-image].'+home_id)[0].files[0].fileSize;
  28. if(filesize > 1048576)
  29. {
  30. alert(bad_file);
  31. }
  32. else
  33. {
  34. $(".upload-mapImage-form"+home_id).append('<input type="hidden" name="extension" value="'+extension+'" />');
  35. $('.status'+home_id).remove();
  36. $( ".dialog-form"+home_id ).append('<center class="status'+home_id+'" ><img style="height:10px;" src="images/loading.gif" /></center>');
  37. data = new FormData($(".upload-mapImage-form"+home_id)[0]);
  38. console.log('Submitting');
  39. $.ajax({
  40. type: 'POST',
  41. url: 'home.php?m=gamemanager&p=upload_map_image&type=cleared',
  42. data: data,
  43. cache: false,
  44. contentType: false,
  45. processData: false
  46. }).done(function(data) {
  47. $('.status'+home_id).remove();
  48. $( ".dialog-form"+home_id ).append('<center class="status'+home_id+'" >'+$.trim(data)+'</center>');
  49. }).fail(function(jqXHR,status, errorThrown) {
  50. $('.status'+home_id).remove();
  51. $( ".dialog-form"+home_id ).append('<center class="status'+home_id+'" >'+upload_failure+'</center>');
  52. console.log(errorThrown);
  53. console.log(jqXHR.responseText);
  54. console.log(jqXHR.status);
  55. });
  56. }
  57. }
  58. else
  59. {
  60. alert(bad_file);
  61. }
  62. }
  63. }],
  64. close: function() {
  65. $( ".dialog-form"+home_id ).remove();
  66. }
  67. });
  68. }
  69. $(document).ready(function(){
  70. $('input#search').quicksearch('table#servermonitor tbody tr.maintr');
  71. $("#servermonitor")
  72. .collapsible("td.collapsible", {collapse: true})
  73. .tablesorter({sortList: [[0,0], [1,0]] , widgets: ['zebra']});
  74. $("div#server_icon").click(function(){
  75. var id = $(this).attr('class');
  76. if($("input[type=radio]."+id).attr('checked'))
  77. {
  78. $("input[type=radio]."+id).attr('checked', false).prop('checked', false);
  79. }
  80. else
  81. {
  82. $("input[type=radio]."+id).attr('checked', true).prop('checked', true);
  83. }
  84. });
  85. $('.size').click(function(){
  86. var id = $(this).attr('data-home_id');
  87. $.post( "home.php?m=user_games&type=cleared&p=get_size&home_id="+id, function( data ) {
  88. $('.size[data-home_id='+id+']').text( data ).css("font-size", "16pt");
  89. });
  90. });
  91. $('#execute_operations').click(function(){
  92. var addpost = {};
  93. $('input[type=radio]:checked').each(function( ){
  94. var name = $(this).attr('name');
  95. var value = $(this).val();
  96. addpost[ name ] = value;
  97. });
  98. $('.right.bloc').html('<img src="images/loading.gif" />');
  99. $.ajax({
  100. type: "POST",
  101. url: "home.php?m=gamemanager&p=game_monitor",
  102. data: addpost,
  103. complete: function(){
  104. document.location.reload();
  105. }
  106. });
  107. });
  108. $('img#action-stop').click(function(){
  109. $('input[type=radio]#action-stop').each(function( ){
  110. if( this.checked )
  111. {
  112. $(this).attr('checked', false).prop('checked', false);
  113. }
  114. else
  115. {
  116. $(this).attr('checked', true).prop('checked', true);
  117. }
  118. });
  119. });
  120. $('img#action-restart').click(function(){
  121. $('input[type=radio]#action-restart').each(function( ){
  122. if( this.checked )
  123. {
  124. $(this).attr('checked', false).prop('checked', false);
  125. }
  126. else
  127. {
  128. $(this).attr('checked', true).prop('checked', true);
  129. }
  130. });
  131. });
  132. $('img#action-start').click(function(){
  133. $('input[type=radio]#action-start').each(function( ){
  134. if( this.checked )
  135. {
  136. $(this).attr('checked', false).prop('checked', false);
  137. }
  138. else
  139. {
  140. $(this).attr('checked', true).prop('checked', true);
  141. }
  142. });
  143. });
  144. $('.masterserver_update').click(function(e) {
  145. e.preventDefault();
  146. var updatePage = (this.getAttribute('data-page') == 'rsync_install' ? 'rsync_install' : 'update');
  147. var homeId = this.getAttribute('data-home-id');
  148. var modId = this.getAttribute('data-mod-id');
  149. var masterServerValue = this.getAttribute('data-masterserver-id');
  150. var pageAction = '?m=gamemanager&p=' + updatePage + '&home_id=' + homeId + '&mod_id=' + modId + '&update=update';
  151. var masterServer = (masterServerValue == null ? '' : '<input type="hidden" name="master_server_home_id" value="' + masterServerValue + '">');
  152. var updateForm = $('<form action="' + pageAction + '" method="POST">' + masterServer + '</form>');
  153. $('body').append(updateForm);
  154. updateForm.submit();
  155. });
  156. });