file.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. file_parameter = {
  2. first : '(0)',
  3. last : '(0)',
  4. count : 20
  5. };
  6. function file_get_init() {
  7. $('#content').html('');
  8. $('#result').html('');
  9. var str = '<table border="1" width="100%">';
  10. str += '<tr><td colspan="2"><a href="#" id="get">get</a></td></tr>';
  11. str += '<tr><td>id:</td><td><input type="text" style="width:95%" id="id"></td></tr>';
  12. str += '</table>';
  13. $('#content').html(str);
  14. $('#get').click(function() {
  15. file_get($('#id').val());
  16. });
  17. }
  18. function file_get(id) {
  19. $('#result').html('');
  20. $.ajax({
  21. type : 'get',
  22. dataType : 'json',
  23. url : '../jaxrs/file/' + id,
  24. contentType : 'application/json; charset=utf-8',
  25. xhrFields : {
  26. 'withCredentials' : true
  27. },
  28. crossDomain : true
  29. }).always(function(json) {
  30. $('#result').html(JSON.stringify(json, null, 4));
  31. });
  32. }
  33. function file_list_referenceType() {
  34. $('#content').html('');
  35. $('#result').html('');
  36. $.ajax({
  37. type : 'get',
  38. dataType : 'json',
  39. url : '../jaxrs/file/list/referencetype',
  40. contentType : 'application/json; charset=utf-8',
  41. xhrFields : {
  42. 'withCredentials' : true
  43. },
  44. crossDomain : true
  45. }).always(function(json) {
  46. $('#result').html(JSON.stringify(json, null, 4));
  47. });
  48. }
  49. function file_list_next(id) {
  50. var id = (id ? id : file_parameter.last);
  51. $.ajax({
  52. type : 'get',
  53. dataType : 'json',
  54. url : '../jaxrs/file/list/' + id + '/next/' + file_parameter.count,
  55. contentType : 'application/json; charset=utf-8',
  56. xhrFields : {
  57. 'withCredentials' : true
  58. },
  59. crossDomain : true
  60. }).done(function(json) {
  61. if (json.type == 'success') {
  62. if (json.data.length > 0) {
  63. file_parameter.first = json.data[0].id;
  64. file_parameter.last = json.data[json.data.length - 1].id;
  65. } else {
  66. file_parameter.first = '(0)';
  67. }
  68. file_list_grid(json);
  69. }
  70. }).always(function(json) {
  71. $('#result').html(JSON.stringify(json, null, 4));
  72. });
  73. }
  74. function file_list_prev(id) {
  75. var id = (id ? id : file_parameter.first);
  76. $.ajax({
  77. type : 'get',
  78. dataType : 'json',
  79. url : '../jaxrs/file/list/' + id + '/prev/' + file_parameter.count,
  80. contentType : 'application/json; charset=utf-8',
  81. xhrFields : {
  82. 'withCredentials' : true
  83. },
  84. crossDomain : true
  85. }).done(function(json) {
  86. if (json.type == 'success') {
  87. if (json.data.length > 0) {
  88. file_parameter.first = json.data[0].id;
  89. file_parameter.last = json.data[json.data.length - 1].id;
  90. } else {
  91. file_parameter.last = '(0)';
  92. }
  93. file_list_grid(json);
  94. }
  95. }).always(function(json) {
  96. $('#result').html(JSON.stringify(json, null, 4));
  97. });
  98. }
  99. function file_list_grid(json) {
  100. var str = '<table border="1" width="100%">';
  101. str += '<tr><td colspan="5"> <a href="#" id="prev">prev</a>&nbsp;<a href="#" id="next">next</a>&nbsp;<span id="total">' + json.count + '</span></td></tr>';
  102. str += '<tr><th>id</th><th>name</th><th>person</th><th>referenceType</th><th>reference</th></tr>';
  103. if (json.data) {
  104. $.each(json.data, function(index, item) {
  105. str += '<tr>';
  106. str += '<td>' + item.id + '</td>';
  107. str += '<td>' + item.name + '</td>';
  108. str += '<td>' + item.person + '</td>';
  109. str += '<td>' + item.referenceType + '</td>';
  110. str += '<td>' + item.reference + '</td>';
  111. str += '</tr>';
  112. });
  113. }
  114. str += '</table>';
  115. $('#content').html(str);
  116. $('#next').click(function() {
  117. file_list_next();
  118. });
  119. $('#prev').click(function() {
  120. file_list_prev();
  121. });
  122. }
  123. function file_list_next_all(id) {
  124. var id = (id ? id : file_parameter.last);
  125. $.ajax({
  126. type : 'get',
  127. dataType : 'json',
  128. url : '../jaxrs/file/list/' + id + '/next/' + file_parameter.count + '/all',
  129. contentType : 'application/json; charset=utf-8',
  130. xhrFields : {
  131. 'withCredentials' : true
  132. },
  133. crossDomain : true
  134. }).done(function(json) {
  135. if (json.type == 'success') {
  136. if (json.data.length > 0) {
  137. file_parameter.first = json.data[0].id;
  138. file_parameter.last = json.data[json.data.length - 1].id;
  139. } else {
  140. file_parameter.first = '(0)';
  141. }
  142. file_list_all_grid(json);
  143. }
  144. }).always(function(json) {
  145. $('#result').html(JSON.stringify(json, null, 4));
  146. });
  147. }
  148. function file_list_prev_all(id) {
  149. var id = (id ? id : file_parameter.first);
  150. $.ajax({
  151. type : 'get',
  152. dataType : 'json',
  153. url : '../jaxrs/file/list/' + id + '/prev/' + file_parameter.count + '/all',
  154. contentType : 'application/json; charset=utf-8',
  155. xhrFields : {
  156. 'withCredentials' : true
  157. },
  158. crossDomain : true
  159. }).done(function(json) {
  160. if (json.type == 'success') {
  161. if (json.data.length > 0) {
  162. file_parameter.first = json.data[0].id;
  163. file_parameter.last = json.data[json.data.length - 1].id;
  164. } else {
  165. file_parameter.last = '(0)';
  166. }
  167. file_list_all_grid(json);
  168. }
  169. }).always(function(json) {
  170. $('#result').html(JSON.stringify(json, null, 4));
  171. });
  172. }
  173. function file_list_all_grid(json) {
  174. var str = '<table border="1" width="100%">';
  175. str += '<tr><td colspan="5"> <a href="#" id="prev">prev</a>&nbsp;<a href="#" id="next">next</a>&nbsp;<span id="total">' + json.count + '</span></td></tr>';
  176. str += '<tr><th>id</th><th>name</th><th>person</th><th>referenceType</th><th>reference</th></tr>';
  177. if (json.data) {
  178. $.each(json.data, function(index, item) {
  179. str += '<tr>';
  180. str += '<td>' + item.id + '</td>';
  181. str += '<td>' + item.name + '</td>';
  182. str += '<td>' + item.person + '</td>';
  183. str += '<td>' + item.referenceType + '</td>';
  184. str += '<td>' + item.reference + '</td>';
  185. str += '</tr>';
  186. });
  187. }
  188. str += '</table>';
  189. $('#content').html(str);
  190. $('#next').click(function() {
  191. file_list_next_all();
  192. });
  193. $('#prev').click(function() {
  194. file_list_prev_all();
  195. });
  196. }
  197. function file_list_withReferenceTypeWithReference_init() {
  198. $('#content').html('');
  199. $('#result').html('');
  200. var str = '<table border="1" width="100%">';
  201. str += '<thead>';
  202. str += '<tr><td colspan="5"><a href="#" id="list">list</a></td></tr>';
  203. str += '<tr><td>referenceType:</td><td colspan="4"><input type="text" style="width:95%" id="referenceType"></td></tr>';
  204. str += '<tr><td>reference:</td><td colspan="4"><input type="text" style="width:95%" id="referenceType"></td></tr>';
  205. str += '<tr><th>id</th><th>name</th><th>person</th><th>referenceType</th><th>reference</th></tr>';
  206. str += '</thead><tbody id="grid"></tbody>';
  207. str += '</table>';
  208. $('#content').html(str);
  209. $('#list').click(function() {
  210. file_list_withReferenceTypeWithReference();
  211. });
  212. }
  213. function file_list_withReferenceTypeWithReference(referenceType, reference) {
  214. $('#grid').html('');
  215. $.ajax({
  216. type : 'get',
  217. dataType : 'json',
  218. url : '../jaxrs/file/list/referencetype/' + referenceType + '/reference/' + reference,
  219. contentType : 'application/json; charset=utf-8',
  220. xhrFields : {
  221. 'withCredentials' : true
  222. },
  223. crossDomain : true
  224. }).done(function(json) {
  225. if (json.type == 'success') {
  226. if (json.data) {
  227. var str = '';
  228. $.each(json.data, function(index, item) {
  229. str += '<tr>';
  230. str += '<td>' + item.person + '</td>';
  231. str += '<td>' + item.id + '</td>';
  232. str += '<td>' + item.name + '</td>';
  233. str += '<td>' + item.referenceType + '</td>';
  234. str += '<td>' + item.reference + '</td>';
  235. str += '</tr>';
  236. });
  237. $('#total').html(json.count);
  238. $('#grid').html(str);
  239. }
  240. }
  241. }).always(function(json) {
  242. $('#result').html(JSON.stringify(json, null, 4));
  243. });
  244. }
  245. function file_list_withReferenceType_init() {
  246. $('#content').html('');
  247. $('#result').html('');
  248. file_parameter.first = '(0)';
  249. file_parameter.last = '(0)';
  250. var str = '<table border="1" width="100%">';
  251. str += '<thead>';
  252. str += '<tr><td colspan="5"><a href="#" id="prev">prev</a>&nbsp;<a href="#" id="next">next</a>&nbsp;<span id="total">0</span></td></tr>';
  253. str += '<tr><td>referenceType:</td><td colspan="4"><input type="text" style="width:95%" id="referenceType"></td></tr>';
  254. str += '<tr><th>id</th><th>name</th><th>person</th><th>referenceType</th><th>reference</th></tr>';
  255. str += '</thead><tbody id="grid"></tbody>';
  256. str += '</table>';
  257. $('#content').html(str);
  258. $('#next').click(function() {
  259. file_list_next_withReferenceType();
  260. });
  261. $('#prev').click(function() {
  262. file_list_prev_withReferenceType();
  263. });
  264. }
  265. function file_list_next_withReferenceType(id) {
  266. var id = (id ? id : file_parameter.last);
  267. $.ajax({
  268. type : 'get',
  269. dataType : 'json',
  270. url : '../jaxrs/file/list/' + id + '/next/' + file_parameter.count + '/referencetype/' + $('#referenceType').val(),
  271. contentType : 'application/json; charset=utf-8',
  272. xhrFields : {
  273. 'withCredentials' : true
  274. },
  275. crossDomain : true
  276. }).done(function(json) {
  277. if (json.type == 'success') {
  278. if (json.data.length > 0) {
  279. file_parameter.first = json.data[0].id;
  280. file_parameter.last = json.data[json.data.length - 1].id;
  281. } else {
  282. file_parameter.first = '(0)';
  283. }
  284. file_list_withReference_grid(json);
  285. }
  286. }).always(function(json) {
  287. $('#result').html(JSON.stringify(json, null, 4));
  288. });
  289. }
  290. function file_list_prev_withReferenceType(id) {
  291. var id = (id ? id : file_parameter.first);
  292. $.ajax({
  293. type : 'get',
  294. dataType : 'json',
  295. url : '../jaxrs/file/list/' + id + '/prev/' + file_parameter.count + '/referencetype/' + $('#referenceType').val(),
  296. contentType : 'application/json; charset=utf-8',
  297. xhrFields : {
  298. 'withCredentials' : true
  299. },
  300. crossDomain : true
  301. }).done(function(json) {
  302. if (json.type == 'success') {
  303. if (json.data.length > 0) {
  304. file_parameter.first = json.data[0].id;
  305. file_parameter.last = json.data[json.data.length - 1].id;
  306. } else {
  307. file_parameter.last = '(0)';
  308. }
  309. file_list_withReference_grid(json);
  310. }
  311. }).always(function(json) {
  312. $('#result').html(JSON.stringify(json, null, 4));
  313. });
  314. }
  315. function file_list_withReference_grid(json) {
  316. if (json.data) {
  317. var str = '';
  318. $.each(json.data, function(index, item) {
  319. str += '<tr>';
  320. str += '<td>' + item.person + '</td>';
  321. str += '<td>' + item.id + '</td>';
  322. str += '<td>' + item.name + '</td>';
  323. str += '<td>' + item.referenceType + '</td>';
  324. str += '<td>' + item.reference + '</td>';
  325. str += '</tr>';
  326. });
  327. $('#total').html(json.count);
  328. $('#grid').html(str);
  329. }
  330. }
  331. function file_upload_init() {
  332. $('#content').html('');
  333. $('#result').html('');
  334. var str = '<table border="1" width="100%">';
  335. str += '<tr><td colspan="2"><a href="#" id="post">post</a></td></tr>';
  336. str += '<tr><td>referenceType:</td><td><input type="text" style="width:95%" id= "referenceType"/></td></tr>';
  337. str += '<tr><td>reference:</td><td><input type="text" style="width:95%" id= "reference"/></td></tr>';
  338. str += '<tr><td>scale:</td><td><input type="text" value="200" style="width:95%" id= "scale"/></td></tr>';
  339. str += '<tr><td>file:</td><td><form><input type="file" name="file" style="width:95%" id= "file"/></form></td></tr>';
  340. str += '</table>';
  341. $('#content').html(str);
  342. $('#post').click(function() {
  343. file_upload($('#referenceType').val(), $('#reference').val(), $('#scale').val());
  344. });
  345. }
  346. function file_upload(referenceType, reference, scale) {
  347. var formData = new FormData($('form')[0]);
  348. $.ajax({
  349. type : 'post',
  350. dataType : 'json',
  351. url : '../servlet/file/upload/referencetype/' + referenceType + '/reference/' + reference + '/scale/' + scale,
  352. data : formData,
  353. contentType : false,
  354. cache : false,
  355. processData : false,
  356. xhrFields : {
  357. 'withCredentials' : true
  358. },
  359. crossDomain : true
  360. }).success(function(json) {
  361. $('#result').html(JSON.stringify(json, null, 4));
  362. });
  363. }
  364. function file_download_init() {
  365. $('#content').html('');
  366. $('#result').html('');
  367. var str = '<table border="1" width="100%">';
  368. str += '<tr><td colspan="2"><a href="#" id="get">get</a></td></tr>';
  369. str += '<tr><td>id:</td><td><input type="text" style="width:95%" id= "id"/></td></tr>';
  370. str += '</table>';
  371. $('#content').html(str);
  372. $('#get').click(function() {
  373. file_download($('#id').val());
  374. });
  375. }
  376. function file_download(id) {
  377. window.open('../servlet/file/download/' + id, '_blank');
  378. }
  379. function file_copy_init() {
  380. $('#content').html('');
  381. $('#result').html('');
  382. var str = '<table border="1" width="100%">';
  383. str += '<tr><td colspan="2"><a href="#" id="get">get</a></td></tr>';
  384. str += '<tr><td>attachmentId:</td><td><input type="text" style="width:95%" id= "attachmentId"/</td></tr>';
  385. str += '<tr><td>referenceType:</td><td><input type="text" style="width:95%" id= "referenceType"/></td></tr>';
  386. str += '<tr><td>reference:</td><td><input type="text" style="width:95%" id= "reference"/></td></tr>';
  387. str += '<tr><td>scale:</td><td><input type="text" value="200" style="width:95%" id= "scale"/></td></tr>';
  388. str += '</table>';
  389. $('#content').html(str);
  390. $('#get').click(function() {
  391. file_copy($('#attachmentId').val(), $('#referenceType').val(), $('#reference').val(), $('#scale').val());
  392. });
  393. }
  394. function file_copy(attachmentId, referenceType, reference, scale) {
  395. $.ajax({
  396. type : 'get',
  397. dataType : 'json',
  398. url : '../jaxrs/file/copy/attachment/' + attachmentId + '/referencetype/' + referenceType + '/reference/' + reference + '/scale/' + scale,
  399. contentType : 'application/json; charset=utf-8',
  400. xhrFields : {
  401. 'withCredentials' : true
  402. },
  403. crossDomain : true
  404. }).always(function(json) {
  405. $('#result').html(JSON.stringify(json, null, 4));
  406. });
  407. }
  408. function file_delete_init() {
  409. $('#content').html('');
  410. $('#result').html('');
  411. var str = '<table border="1" width="100%">';
  412. str += '<tr><td colspan="2"><a href="#" id="delete">delete</a></td></tr>';
  413. str += '<tr><td>referenceType:</td><td><input type="text" style="width:95%" id= "referenceType"/></td></tr>';
  414. str += '<tr><td>reference:</td><td><input type="text" style="width:95%" id= "reference"/></td></tr>';
  415. str += '</table>';
  416. $('#content').html(str);
  417. $('#delete').click(function() {
  418. file_delete($('#referenceType').val(), $('#reference').val());
  419. });
  420. }
  421. function file_delete(referenceType, reference, scale) {
  422. $.ajax({
  423. type : 'delete',
  424. dataType : 'json',
  425. url : '../jaxrs/file/referencetype/' + referenceType + '/reference/' + reference,
  426. contentType : 'application/json; charset=utf-8',
  427. xhrFields : {
  428. 'withCredentials' : true
  429. },
  430. crossDomain : true
  431. }).always(function(json) {
  432. $('#result').html(JSON.stringify(json, null, 4));
  433. });
  434. }