storage.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. function storage_create(storageType) {
  2. var str = '<table border="1" width="100%">';
  3. str += '<tr><td colspan="2"><a href="#" id="post">post</a></td></tr>';
  4. str += '<tr><td>storageType:</td><td id="storageType">' + storageType + '</td></tr>';
  5. str += '<tr><td>storageServer:</td><td><input type="text" style="width:95%" id="storageServer"/></td></tr>';
  6. str += '<tr><td>enable:</td><td><select id="enable"><option value="true">true</option><option value="false">false</option></select></td></tr>';
  7. str += '<tr><td>weight:</td><td><input type="text" style="width:95%" id="weight"/></td></tr>';
  8. str += '<tr><td>order:</td><td><input type="text" style="width:95%" id="order"/></td></tr>';
  9. str += '</table>';
  10. $('#content').html(str);
  11. $('#post', '#content').click(function() {
  12. storage_post(storageType);
  13. });
  14. }
  15. function storage_post(storageType) {
  16. $.ajax({
  17. type : 'post',
  18. dataType : 'json',
  19. url : '../jaxrs/storage/storagetype/' + storageType,
  20. contentType : 'application/json; charset=utf-8',
  21. data : JSON.stringify({
  22. enable : $('#enable').val(),
  23. weight : $('#weight').val(),
  24. order : $('#order').val(),
  25. storageServer : $('#storageServer').val()
  26. }),
  27. xhrFields : {
  28. 'withCredentials' : true
  29. },
  30. crossDomain : true
  31. }).done(function(json) {
  32. $('#result').html(JSON.stringify(json, null, 4));
  33. });
  34. }
  35. function storage_edit(storageType, storageServer) {
  36. $('#result').html('');
  37. $('#content').html('');
  38. var str = '<table border="1" width="100%">';
  39. str += '<tr><td colspan="2"><a href="#" id="put">put</a></td></tr>';
  40. str += '<tr><td>storageType:</td><td id="storageType">' + storageType + '</td></tr>';
  41. str += '<tr><td>storageServer:</td><td><input type="text" style="width:95%" id="storageServer"/></td></tr>';
  42. str += '<tr><td>enable:</td><td><select id="enable"><option value="true">true</option><option value="false">false</option></select></td></tr>';
  43. str += '<tr><td>weight:</td><td><input type="text" style="width:95%" id="weight"/></td></tr>';
  44. str += '<tr><td>order:</td><td><input type="text" style="width:95%" id="order"/></td></tr>';
  45. str += '</table>';
  46. $('#content').html(str);
  47. $.ajax({
  48. type : 'get',
  49. dataType : 'json',
  50. contentType : 'application/json; charset=utf-8',
  51. url : '../jaxrs/storage/storagetype/' + storageType + '/storageserver/' + storageServer,
  52. xhrFields : {
  53. 'withCredentials' : true
  54. },
  55. crossDomain : true
  56. }).done(function(json) {
  57. $('#result').html(JSON.stringify(json, null, 4));
  58. if (json.type == 'success') {
  59. if (json.data) {
  60. $('#storageServer').val(json.data.storageServer);
  61. $('#enable').val(json.data.enable);
  62. $('#weight').val(json.data.weight);
  63. $('#order').val(json.data.order);
  64. }
  65. } else {
  66. failure(json);
  67. }
  68. });
  69. $('#put').click(function() {
  70. storage_put(storageType, storageServer);
  71. });
  72. }
  73. function storage_put(storageType, storageServer) {
  74. $.ajax({
  75. type : 'put',
  76. dataType : 'json',
  77. url : '../jaxrs/storage/storagetype/' + storageType + '/storageserver/' + storageServer,
  78. contentType : 'application/json; charset=utf-8',
  79. data : JSON.stringify({
  80. enable : $('#enable').val(),
  81. weight : $('#weight').val(),
  82. order : $('#order').val(),
  83. storageServer : $('#storageServer').val()
  84. }),
  85. xhrFields : {
  86. 'withCredentials' : true
  87. },
  88. crossDomain : true
  89. }).done(function(json) {
  90. $('#result').html(JSON.stringify(json, null, 4));
  91. });
  92. }
  93. function storage_delete(storageType, storageServer) {
  94. $.ajax({
  95. type : 'delete',
  96. dataType : 'json',
  97. url : '../jaxrs/storage/storagetype/' + storageType + '/storageserver/' + storageServer,
  98. contentType : 'application/json; charset=utf-8',
  99. xhrFields : {
  100. 'withCredentials' : true
  101. },
  102. crossDomain : true
  103. }).done(function(json) {
  104. $('#result').html(JSON.stringify(json, null, 4));
  105. });
  106. }