gamemanager.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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 ).removeClass('sizeText').addClass('sizeText');
  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. // Allow admin users to set game server order
  145. handleOrderingGameServers();
  146. });
  147. function handleOrderingGameServers(){
  148. var elemBeingDragged = null;
  149. var childExpanderRow = null;
  150. var helperItemBeingDragged = null;
  151. if($('h2.isAdminUser').length){
  152. $('table#servermonitor tbody').sortable({
  153. handle: '.sortHandle', // https://stackoverflow.com/questions/15554951/sortable-rows-only-when-a-specific-column-is-dragged#answer-16753297
  154. delay: 250, // https://stackoverflow.com/questions/22913592/jquery-ui-sortable-any-event-to-trigger-once-delay-completed
  155. start: function( event, ui ) {
  156. $('.expand-child td').css('display', 'none');
  157. $('td', ui.item).removeClass('expanded');
  158. ui.helper.css('cursor', 'move');
  159. elemBeingDragged = ui.item;
  160. childExpanderRow = elemBeingDragged.nextAll('tr.expand-child').first();
  161. helperItemBeingDragged = ui.helper;
  162. },
  163. stop: function( event, ui ) {
  164. if(childExpanderRow && childExpanderRow.length && elemBeingDragged && elemBeingDragged.length){
  165. elemBeingDragged.after(childExpanderRow.detach());
  166. if(childExpanderRow.next('tr.expand-child').length){
  167. elemBeingDragged.before(childExpanderRow.next('tr.expand-child').detach());
  168. }
  169. }
  170. if(helperItemBeingDragged.length){
  171. helperItemBeingDragged.css('cursor', '');
  172. }
  173. },
  174. update: function(event, ui){
  175. saveGameServerOrder();
  176. }
  177. });
  178. }
  179. }
  180. function saveGameServerOrder(){
  181. var i = 0;
  182. var postData = {order: new Array()};
  183. var homeId = null;
  184. if(userAPIKey){
  185. // Build the data
  186. $('table#servermonitor tbody .maintr:visible').each(function(e){
  187. homeId = $('td.serverId', $(this)).text();
  188. if(homeId){
  189. postData.order.push({home_id: homeId, order: i});
  190. i++;
  191. }
  192. });
  193. // Make the call
  194. $.ajax({
  195. type: "POST",
  196. url: "ogp_api.php?gamemanager_admin/reorder&token=" + userAPIKey,
  197. data: JSON.stringify(postData),
  198. success: function(e){
  199. logToConsole("Game server order successfully saved!");
  200. }
  201. });
  202. }
  203. }