data.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. data_parameter = {};
  2. function data_getWithWork_init() {
  3. str = '<table border="1" width="100%">';
  4. str += '<tr><td colspan="2"><a href="#" id="get">get</a>&nbsp;<a href="#" id="post">post</a>&nbsp;<a href="#" id="put">put</a>&nbsp;<a href="#" id="delete">delete</a></td></tr>';
  5. str += '<tr><td>workId:</td><td><input type="text" id="workId" style="width:95%"/></td></tr>';
  6. str += '<tr><td>paths:</td><td><input type="text" id="paths" style="width:95%"></input></td></tr>';
  7. str += '<tr><td colspan="2"><textarea id="data" style="width:95%;height:500px"/></td></tr>';
  8. str += '</table>';
  9. $('#content').html(str);
  10. $('#result').html('');
  11. $('#get').click(function() {
  12. data_getWithWork($('#workId').val(), $('#paths').val().replace(/\./g, '\/'));
  13. });
  14. $('#put').click(function() {
  15. data_updateWithWork($('#workId').val(), $('#paths').val().replace(/\./g, '\/'));
  16. });
  17. $('#delete').click(function() {
  18. data_deleteWithWork($('#workId').val(), $('#paths').val().replace(/\./g, '\/'));
  19. });
  20. $('#post').click(function() {
  21. data_createWithWork($('#workId').val(), $('#paths').val().replace(/\./g, '\/'));
  22. });
  23. }
  24. function data_getWithWork(workId, paths) {
  25. $('#data').val('');
  26. $.ajax({
  27. type : 'get',
  28. dataType : 'json',
  29. contentType : 'application/json; charset=utf-8',
  30. url : '../jaxrs/data/work/' + workId + ((paths.length > 0) ? ('/' + paths) : ''),
  31. xhrFields : {
  32. 'withCredentials' : true
  33. },
  34. crossDomain : true
  35. }).done(function(json) {
  36. if (json.type == 'success') {
  37. $('#data').val(JSON.stringify(json.data, null, 4));
  38. }
  39. }).always(function(json) {
  40. $('#result').html(JSON.stringify(json, null, 4));
  41. });
  42. }
  43. function data_updateWithWork(workId, paths) {
  44. $.ajax({
  45. type : 'put',
  46. dataType : 'json',
  47. contentType : 'application/json; charset=utf-8',
  48. url : '../jaxrs/data/work/' + workId + ((paths.length > 0) ? ('/' + paths) : ''),
  49. xhrFields : {
  50. 'withCredentials' : true
  51. },
  52. data : JSON.stringify($.parseJSON($('#data').val())),
  53. crossDomain : true
  54. }).always(function(json) {
  55. $('#result').html(JSON.stringify(json, null, 4));
  56. });
  57. }
  58. function data_deleteWithWork(workId, paths) {
  59. $.ajax({
  60. type : 'delete',
  61. dataType : 'json',
  62. contentType : 'application/json; charset=utf-8',
  63. url : '../jaxrs/data/work/' + workId + ((paths.length > 0) ? ('/' + paths) : ''),
  64. xhrFields : {
  65. 'withCredentials' : true
  66. },
  67. crossDomain : true
  68. }).always(function(json) {
  69. $('#result').html(JSON.stringify(json, null, 4));
  70. });
  71. }
  72. function data_createWithWork(workId, paths) {
  73. $.ajax({
  74. type : 'post',
  75. dataType : 'json',
  76. contentType : 'application/json; charset=utf-8',
  77. url : '../jaxrs/data/work/' + workId + ((paths.length > 0) ? ('/' + paths) : ''),
  78. xhrFields : {
  79. 'withCredentials' : true
  80. },
  81. data : JSON.stringify($.parseJSON($('#data').val())),
  82. crossDomain : true
  83. }).always(function(json) {
  84. $('#result').html(JSON.stringify(json, null, 4));
  85. });
  86. }
  87. function data_getWithWorkCompleted_init() {
  88. str = '<table border="1" width="100%">';
  89. str += '<tr><td colspan="2"><a href="#" id="get">get</a></td></tr>';
  90. str += '<tr><td>workCompletedId:</td><td><input type="text" id="workCompletedId" style="width:95%"/></td></tr>';
  91. str += '<tr><td>paths:</td><td><input type="text" id="paths" style="width:95%"></input></td></tr>';
  92. str += '<tr><td colspan="2"><textarea id="data" style="width:95%;height:500px"/></td></tr>';
  93. str += '</table>';
  94. $('#content').html(str);
  95. $('#result').html('');
  96. $('#get').click(function() {
  97. data_getWithWorkCompleted($('#workCompletedId').val(), $('#paths').val().replace(/\./g, '\/'));
  98. });
  99. }
  100. function data_getWithWorkCompleted(workCompletedId, paths) {
  101. $('#data').val('');
  102. $.ajax({
  103. type : 'get',
  104. dataType : 'json',
  105. contentType : 'application/json; charset=utf-8',
  106. url : '../jaxrs/data/workcompleted/' + workCompletedId + ((paths.length > 0) ? ('/' + paths) : ''),
  107. xhrFields : {
  108. 'withCredentials' : true
  109. },
  110. crossDomain : true
  111. }).done(function(json) {
  112. if (json.type == 'success') {
  113. $('#data').val(JSON.stringify(json.data, null, 4));
  114. }
  115. }).always(function(json) {
  116. $('#result').html(JSON.stringify(json, null, 4));
  117. });
  118. }