server.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. function server_list() {
  2. $('#content').html('');
  3. $('#result').html('');
  4. $.ajax({
  5. type : 'get',
  6. dataType : 'json',
  7. contentType : 'application/json; charset=utf-8',
  8. url : '../jaxrs/server/list',
  9. xhrFields : {
  10. 'withCredentials' : true
  11. },
  12. crossDomain : true
  13. }).done(function(data) {
  14. if (data.type == 'success') {
  15. var str = '<table border="1" width="100%">';
  16. str += '<tr><th>host</th><th>port</th><th>username</th><th>operate</th></tr>';
  17. if (data.data) {
  18. $.each(data.data, function(typeIndex, item) {
  19. str += '<tr>';
  20. str += '<td>' + item.host + '</td>';
  21. str += '<td>' + item.port + '</td>';
  22. str += '<td>' + item.username + '</td>';
  23. str += '<td>';
  24. str += '<a href="#" onclick="server_edit(' + item.order + ')">edit</a>&nbsp;';
  25. str += '<a href="#" onclick="server_delete(' + item.order + ')">delete</a>';
  26. str += '</td>';
  27. str += '</tr>';
  28. });
  29. }
  30. str += '</table>';
  31. $('#content').html(str);
  32. $('#result').html(JSON.stringify(data.data, null, 4));
  33. } else {
  34. failure(data);
  35. }
  36. });
  37. }
  38. function server_edit(order) {
  39. $('#result').html('');
  40. $('#content').html('');
  41. var str = '<table border="1" width="100%">';
  42. str += '<tr><td colspan="2"><a href="#" id="put">put</a></td></tr>';
  43. str += '<tr><td>host:</td><td><input type="text" style="width:95%" id="host"/></td></tr>';
  44. str += '<tr><td>port:</td><td><input type="text" style="width:95%" id="port"/></td></tr>';
  45. str += '<tr><td>username:</td><td><input type="text" style="width:95%" id="username"/></td></tr>';
  46. str += '<tr><td>password:</td><td><input type="text" style="width:95%" id="password"/></td></tr>';
  47. str += '<tr><td>containerType:</td><td><select id="containerType"><option value="tomcat8">tomcat8</option></select></td></tr>';
  48. str += '<tr><td>order:</td><td><input type="text" style="width:95%" id="order"/></td></tr>';
  49. str += '</table>';
  50. $('#content').html(str);
  51. $.ajax({
  52. type : 'get',
  53. dataType : 'json',
  54. contentType : 'application/json; charset=utf-8',
  55. url : '../jaxrs/server/order/' + order,
  56. xhrFields : {
  57. 'withCredentials' : true
  58. },
  59. crossDomain : true
  60. }).done(function(data) {
  61. if (data.type == 'success') {
  62. $('#host', '#content').val(data.data.host);
  63. $('#port', '#content').val(data.data.port);
  64. $('#username', '#content').val(data.data.username);
  65. $('#password', '#content').val(data.data.password);
  66. $('#containerType', '#content').val(data.data.containerType);
  67. $('#order', '#content').val(data.data.order);
  68. } else {
  69. failure(data);
  70. }
  71. $('#result').html(JSON.stringify(data.data, null, 4));
  72. });
  73. $('#put', '#content').click(function() {
  74. server_put(order);
  75. });
  76. }
  77. function server_put(order) {
  78. $('#result').html('');
  79. $.ajax({
  80. type : 'put',
  81. dataType : 'json',
  82. url : '../jaxrs/server/order/' + order,
  83. contentType : 'application/json; charset=utf-8',
  84. data : JSON.stringify({
  85. host : $('#host', '#content').val(),
  86. port : $('#port', '#content').val(),
  87. username : $('#username', '#content').val(),
  88. password : $('#password', '#content').val(),
  89. containerType : $('#containerType', '#content').val(),
  90. order : $('#order', '#content').val()
  91. }),
  92. xhrFields : {
  93. 'withCredentials' : true
  94. },
  95. crossDomain : true
  96. }).done(function(data) {
  97. if (data.type == 'success') {
  98. } else {
  99. failure(data);
  100. }
  101. $('#result').html(JSON.stringify(data.data, null, 4));
  102. });
  103. }
  104. function server_create_init() {
  105. $('#result').html('');
  106. var str = '<table border="1" width="100%">';
  107. str += '<tr><td colspan="2"><a href="#" id="post">post</a></td></tr>';
  108. str += '<tr><td>host:</td><td><input type="text" style="width:95%" id="host"/></td></tr>';
  109. str += '<tr><td>port:</td><td><input type="text" style="width:95%" id="port"/></td></tr>';
  110. str += '<tr><td>username:</td><td><input type="text" style="width:95%" id="username"/></td></tr>';
  111. str += '<tr><td>password:</td><td><input type="text" style="width:95%" id="password"/></td></tr>';
  112. str += '<tr><td>containerType:</td><td><select id="containerType"><option value="tomcat8">tomcat8</option></select></td></tr>';
  113. str += '</table>';
  114. $('#content').html(str);
  115. $('#post', '#content').click(function() {
  116. server_post();
  117. });
  118. }
  119. function server_post() {
  120. $.ajax({
  121. type : 'post',
  122. dataType : 'json',
  123. url : '../jaxrs/server',
  124. contentType : 'application/json; charset=utf-8',
  125. data : JSON.stringify({
  126. host : $('#host', '#content').val(),
  127. port : $('#port', '#content').val(),
  128. username : $('#username', '#content').val(),
  129. password : $('#password', '#content').val(),
  130. containerType : $('#containerType', '#content').val()
  131. }),
  132. xhrFields : {
  133. 'withCredentials' : true
  134. },
  135. crossDomain : true
  136. }).done(function(data) {
  137. if (data.type == 'success') {
  138. } else {
  139. failure(data);
  140. }
  141. $('#result').html(JSON.stringify(data.data, null, 4));
  142. });
  143. }
  144. function server_delete(order) {
  145. $.ajax({
  146. type : 'delete',
  147. dataType : 'json',
  148. url : '../jaxrs/server/order/' + order,
  149. contentType : 'application/json; charset=utf-8',
  150. xhrFields : {
  151. 'withCredentials' : true
  152. },
  153. crossDomain : true
  154. }).done(function(data) {
  155. if (data.type == 'success') {
  156. } else {
  157. failure(data);
  158. }
  159. $('#result').html(JSON.stringify(data.data, null, 4));
  160. });
  161. }