attachment.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. attachment_parameter = {
  2. first : '(0)',
  3. last : '(0)',
  4. count : 20
  5. };
  6. function attachment_list_next(id) {
  7. var id = (id ? id : attachment_parameter.last);
  8. $.ajax({
  9. type : 'get',
  10. dataType : 'json',
  11. url : '../jaxrs/attachment/list/' + id + '/next/' + attachment_parameter.count,
  12. xhrFields : {
  13. 'withCredentials' : true
  14. },
  15. crossDomain : true
  16. }).done(function(json) {
  17. $('#result').html(JSON.stringify(json, null, 4));
  18. if (json.type == 'success') {
  19. if (json.data.length > 0) {
  20. attachment_parameter.first = json.data[0].id;
  21. attachment_parameter.last = json.data[json.data.length - 1].id;
  22. } else {
  23. attachment_parameter.first = '(0)';
  24. }
  25. attachment_grid(json.data);
  26. } else {
  27. failure(data);
  28. }
  29. });
  30. }
  31. function attachment_list_prev(id) {
  32. var id = (id ? id : attachment_parameter.first);
  33. $.ajax({
  34. type : 'get',
  35. dataType : 'json',
  36. url : '../jaxrs/attachment/list/' + id + '/prev/' + attachment_parameter.count,
  37. xhrFields : {
  38. 'withCredentials' : true
  39. },
  40. crossDomain : true
  41. }).done(function(json) {
  42. $('#result').html(JSON.stringify(json, null, 4));
  43. if (json.type == 'success') {
  44. if (json.data.length > 0) {
  45. attachment_parameter.first = json.data[0].id;
  46. attachment_parameter.last = json.data[json.data.length - 1].id;
  47. } else {
  48. attachment_parameter.last = '(0)';
  49. }
  50. attachment_grid(json.data);
  51. } else {
  52. failure(data);
  53. }
  54. });
  55. }
  56. function attachment_grid(items) {
  57. var str = '<table border="1" width="100%"><tobdy>';
  58. str += '<tr><th>rank</th><th>id</th><th>name</th><th>fileName</th><th>summary</th><th>length</th><th>operate</th></tr>';
  59. $.each(items, function(index, item) {
  60. str += '<tr>';
  61. str += '<td>' + item.rank + '</td>';
  62. str += '<td>' + item.id + '</td>';
  63. str += '<td>' + item.name + '</td>';
  64. str += '<td>' + item.fileName + '</td>';
  65. str += '<td>' + item.summary + '</td>';
  66. str += '<td>' + item.length + '</td>';
  67. str += '<td>';
  68. str += '<a href="#" onclick="attachment_download_select(\'' + item.id + '\')">download</a>&nbsp;';
  69. str += '<a href="#" onclick="attachment_update_select(\'' + item.id + '\')">update</a>&nbsp;';
  70. str += '<a href="#" onclick="attachment_delete_select(\'' + item.id + '\')">delete</a>';
  71. str += '</td>';
  72. str += '</tr>';
  73. });
  74. str += '</tobdy></table>';
  75. $('#content').html(str);
  76. }
  77. function attachment_get_select() {
  78. $('#result').html('');
  79. var str = '<table border="1" width="100%">';
  80. str += '<tr><td colspan="2"><a href="#" id="get">get</a></td></tr>';
  81. str += '<tr><td>id:</td><td><input type="text" id="id" style="width:95%" /></td></tr>';
  82. str += '</table>';
  83. $('#content').html(str);
  84. $('#get').click(function() {
  85. attachment_get($('#id').val());
  86. });
  87. }
  88. function attachment_get(id) {
  89. $.ajax({
  90. type : 'get',
  91. dataType : 'json',
  92. url : '../jaxrs/attachment/' + id,
  93. xhrFields : {
  94. 'withCredentials' : true
  95. },
  96. crossDomain : true
  97. }).done(function(json) {
  98. $('#result').html(JSON.stringify(json, null, 4));
  99. });
  100. }
  101. function attachment_listWithMeeting_select() {
  102. $('#result').html('');
  103. var str = '<table border="1" width="100%">';
  104. str += '<tr><td colspan="2"><a href="#" id="get">get</a></td></tr>';
  105. str += '<tr><td>meeting:</td><td><input type="text" id="meeting" style="width:95%" ></td></tr>';
  106. str += '</table>';
  107. $('#content').html(str);
  108. $('#get').click(function() {
  109. attachment_listWithMeeting($('#meeting').val());
  110. });
  111. }
  112. function attachment_listWithMeeting(id) {
  113. $('#result').html('');
  114. $.ajax({
  115. type : 'get',
  116. dataType : 'json',
  117. url : '../jaxrs/attachment/list/meeting/' + id,
  118. xhrFields : {
  119. 'withCredentials' : true
  120. },
  121. crossDomain : true
  122. }).done(function(json) {
  123. $('#result').html(JSON.stringify(json, null, 4));
  124. if (json.type == 'success') {
  125. attachment_grid(json.data);
  126. }
  127. });
  128. }
  129. function attachment_post_select() {
  130. $('#result').html('');
  131. var str = '<table border="1" width="100%">';
  132. str += '<tr><td colspan="2"><a href="#" id="post">post</a></td></tr>';
  133. str += '<tr><td>meeting:</td><td><input type="text" id="meeting" style="width:95%" /></td></tr>';
  134. str += '<tr><td>type:</td><td><select id="type"><option value="attachment">attachment</option><option value="summary">summary</option></select></td></tr>';
  135. str += '<tr><td>file:</td><td><input type="file" id="file" style="width:95%" ></td></tr>';
  136. str += '</table>';
  137. $('#content').html(str);
  138. $('#post').click(function() {
  139. attachment_post();
  140. });
  141. }
  142. function attachment_post() {
  143. var formData = new FormData();
  144. $.each($('input[type=file]'), function(index, item) {
  145. formData.append('file', item.files[0]);
  146. });
  147. var url = '../servlet/attachment/upload/meeting/' + $('#meeting').val();
  148. url += $('#type').val() == 'summary' ? '/summary' : '';
  149. $.ajax({
  150. type : 'POST',
  151. url : url,
  152. data : formData,
  153. contentType : false,
  154. processData : false,
  155. xhrFields : {
  156. 'withCredentials' : true
  157. },
  158. crossDomain : true
  159. });
  160. }
  161. function attachment_put_select(id) {
  162. $('#result').html('');
  163. var str = '<table border="1" width="100%">';
  164. str += '<tr><td colspan="2"><a href="#" id="put">put</a></td></tr>';
  165. str += '<tr><td>id:</td><td><input type="text" id="id" style="width:95%" ></td></tr>';
  166. str += '<tr><td>file:</td><td><input type="file" id="file" style="width:95%" ></td></tr>';
  167. str += '</table>';
  168. $('#content').html(str);
  169. if (id) {
  170. $('#id').val(id);
  171. }
  172. $('#put').click(function() {
  173. attachment_put();
  174. });
  175. }
  176. function attachment_put() {
  177. $('#result').html('');
  178. var formData = new FormData();
  179. $.each($('input[type=file]'), function(index, item) {
  180. formData.append('file', item.files[0]);
  181. });
  182. $.ajax({
  183. type : 'POST',
  184. url : '../servlet/attachment/update/' + $('#id').val(),
  185. data : formData,
  186. contentType : false,
  187. processData : false,
  188. xhrFields : {
  189. 'withCredentials' : true
  190. },
  191. crossDomain : true
  192. });
  193. }
  194. function attachment_download_select(id) {
  195. $('#result').html('');
  196. var str = '<table border="1" width="100%">';
  197. str += '<tr><td colspan="2"><a href="#" id="get">get</a></td></tr>';
  198. str += '<tr><td>id:</td><td><input type="text" id="id" style="width:95%" ></td></tr>';
  199. str += '<tr><td>type:</td><td><select id="type"><option value="stream">stream</option><option value="contentType">contentType</option></select></td></tr>';
  200. str += '</table>';
  201. $('#content').html(str);
  202. if (id) {
  203. $('#id').val(id);
  204. }
  205. $('#get').click(function() {
  206. attachment_download();
  207. });
  208. }
  209. function attachment_download() {
  210. var url = '../servlet/attachment/download/' + $('#id').val();
  211. if ($('#type').val() == 'stream') {
  212. url += '/stream';
  213. }
  214. window.open(url, '_blank');
  215. }
  216. function attachment_delete_select(id) {
  217. $('#result').html('');
  218. var str = '<table border="1" width="100%">';
  219. str += '<tr><td colspan="2"><a href="#" id="delete">delete</a></td></tr>';
  220. str += '<tr><td>id:</td><td><input type="text" id="id" style="width:95%" ></td></tr>';
  221. str += '</table>';
  222. $('#content').html(str);
  223. if (id) {
  224. $('#id').val(id);
  225. }
  226. $('#delete').click(function() {
  227. attachment_delete($('#id').val());
  228. });
  229. }
  230. function attachment_delete(id) {
  231. $('#result').html('');
  232. $.ajax({
  233. type : 'delete',
  234. dataType : 'json',
  235. url : '../jaxrs/attachment/' + id,
  236. xhrFields : {
  237. 'withCredentials' : true
  238. },
  239. crossDomain : true
  240. }).done(function(json) {
  241. $('#result').html(JSON.stringify(json, null, 4));
  242. });
  243. }