application.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. application_parameter = {
  2. applications : null
  3. };
  4. function application_list() {
  5. $('#content').html('');
  6. $.ajax({
  7. type : 'get',
  8. dataType : 'json',
  9. contentType : 'application/json; charset=utf-8',
  10. url : '../jaxrs/applications',
  11. xhrFields : {
  12. 'withCredentials' : true
  13. },
  14. crossDomain : true
  15. }).done(function(data) {
  16. if (data.type == 'success') {
  17. if (data.data && data.data.applicationTypes) {
  18. application_parameter.applications = data.data;
  19. var str = '<table border="1" width="100%">';
  20. str += '<tr><th>host</th><th>port</th><th>contextPath</th><th>available</th><th>weight</th><th>operate</th></tr>';
  21. $.each(data.data.applicationTypes, function(index, item) {
  22. str += '<tr><td colspan="6">' + item.type + '</td></tr>';
  23. $.each(item.applications, function(index, o) {
  24. str += '<tr>';
  25. str += '<td>' + o.host + '</td>';
  26. str += '<td>' + o.port + '</td>';
  27. str += '<td>' + o.contextPath + '</td>';
  28. str += '<td>' + o.available + '</td>';
  29. str += '<td>' + o.weight + '</td>';
  30. str += '<td>';
  31. str += '<a href="#" onclick="application_edit(\'' + o.token + '\')">edit</a>&nbsp;';
  32. str += '</td>';
  33. str += '</tr>';
  34. });
  35. });
  36. str += '</table>';
  37. $('#content').html(str);
  38. }
  39. } else {
  40. failure(data);
  41. }
  42. $('#result').html(JSON.stringify(data.data, null, 4));
  43. });
  44. }
  45. function application_edit(token) {
  46. $('#result').html('');
  47. var str = '<table border="1" width="100%">';
  48. str += '<tr><td colspan="2"><a href="#" id="put">put</a></td></tr>';
  49. str += '<tr><td>token:</td><td id="token">&nbsp;</td></tr>';
  50. str += '<tr><td>available:</td><td id="available"/>&nbsp;</td></tr>';
  51. str += '<tr><td>reportDate:</td><td id="reportDate"/>&nbsp;</td></tr>';
  52. str += '<tr><td>contextPath:</td><td id="contextPath">&nbsp;</td></tr>';
  53. str += '<tr><td>enable:</td><td><select id="enable"><option value ="true">true</option><option value ="false">false</option></select></td></tr>';
  54. str += '<tr><td>host:</td><td><input type="text" style="width:95%" id= "host"/></td></tr>';
  55. str += '<tr><td>port:</td><td><input type="text" style="width:95%" id= "port"/></td></tr>';
  56. str += '<tr><td>weight:</td><td><input type="text" style="width:95%" id= "weight"/></td></tr>';
  57. str += '</table>';
  58. $('#content').html(str);
  59. $('#put', '#content').click(function() {
  60. application_put(token);
  61. });
  62. $.each(application_parameter.applications.applicationTypes, function(index, item) {
  63. $.each(item.applications, function(index, o) {
  64. if (o.token == token) {
  65. $('#token', '#content').html(o.token);
  66. $('#available', '#content').html(o.available + '');
  67. $('#reportDate', '#content').html(o.reportDate);
  68. $('#contextPath', '#content').html(o.contextPath);
  69. $('#enable', '#content').val(o.enable + '');
  70. $('#host', '#content').val(o.host);
  71. $('#port', '#content').val(o.port);
  72. $('#weight', '#content').val(o.weight);
  73. }
  74. });
  75. });
  76. }
  77. function application_put(token) {
  78. $('#result').html('');
  79. $.ajax({
  80. type : 'put',
  81. dataType : 'json',
  82. url : '../jaxrs/application/' + token,
  83. contentType : 'application/json; charset=utf-8',
  84. data : JSON.stringify({
  85. enable : $('#enable', '#content').val(),
  86. host : $('#host', '#content').val(),
  87. port : $('#port', '#content').val(),
  88. weight : $('#weight', '#content').val()
  89. }),
  90. xhrFields : {
  91. 'withCredentials' : true
  92. },
  93. crossDomain : true
  94. }).done(function(data) {
  95. if (data.type == 'success') {
  96. application_list();
  97. } else {
  98. failure(data);
  99. }
  100. });
  101. }