attachment.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. attachment_parameter = {
  2. list_action : null,
  3. list_action_parameter : null,
  4. first : '(0)',
  5. last : '(0)',
  6. count : 20
  7. };
  8. function attachment_get_init() {
  9. var str = '<table border="1" width="100%">';
  10. str += '<tr><td colspan="2"><a href="#" id="get">get</a>&nbsp;<a href="#" id="getBase64">getBase64</a>&nbsp;<a href="#" id="getImageScaleBase64">getImageScaleBase64</a>&nbsp;<a href="#" id="getImageWidthHeightBase64">getImageWidthHeightBase64</a></td></tr>';
  11. str += '<tr><td>id:</td><td><input type="text" style="width:95%" id="id"></td></tr>';
  12. str += '<tr><td>scale:</td><td><input type="text" style="width:95%" id="scale"></td></tr>';
  13. str += '<tr><td>width:</td><td><input type="text" style="width:95%" id="width"></td></tr>';
  14. str += '<tr><td>height:</td><td><input type="text" style="width:95%" id="height"></td></tr>';
  15. str += '<tr><td colspan="2" id="grid">&nbsp;</td></tr>';
  16. str += '</table>';
  17. $('#content').html(str);
  18. $('#get').click(function() {
  19. attachment_get($('#id').val());
  20. });
  21. $('#getBase64').click(function() {
  22. attachment_getBase64($('#id').val());
  23. });
  24. $('#getImageScaleBase64').click(function() {
  25. attachment_getImageScaleBase64($('#id').val(), $('#scale').val());
  26. });
  27. $('#getImageWidthHeightBase64').click(function() {
  28. attachment_getImageWidthHeightBase64($('#id').val(), $('#width').val(), $('#height').val());
  29. });
  30. }
  31. function attachment_get(id) {
  32. $('#grid').html('');
  33. $('#result').html('');
  34. var str = '<iframe src="../servlet/download/' + id + '"/>';
  35. $('#grid').html(str);
  36. }
  37. function attachment_getBase64(id) {
  38. $('#grid').html('');
  39. $('#result').html('');
  40. $.ajax({
  41. type : 'get',
  42. dataType : 'json',
  43. url : '../jaxrs/attachment/' + id + '/binary/base64',
  44. xhrFields : {
  45. 'withCredentials' : true
  46. },
  47. crossDomain : true
  48. }).done(function(json) {
  49. if (json.type == 'success') {
  50. var str = '<img src="data:image/png;base64,' + json.data.value + '"/>';
  51. $('#grid').html(str);
  52. }
  53. }).always(function(json) {
  54. $('#result').html(JSON.stringify(json, null, 4));
  55. });
  56. }
  57. function attachment_getImageScaleBase64(id, scale) {
  58. $('#grid').html('');
  59. $('#result').html('');
  60. $.ajax({
  61. type : 'get',
  62. dataType : 'json',
  63. url : '../jaxrs/attachment/' + id + '/image/scale/' + scale + '/binary/base64',
  64. xhrFields : {
  65. 'withCredentials' : true
  66. },
  67. crossDomain : true
  68. }).done(function(json) {
  69. if (json.type == 'success') {
  70. var str = '<img src="data:image/png;base64,' + json.data.value + '"/>';
  71. $('#grid').html(str);
  72. }
  73. }).always(function(json) {
  74. $('#result').html(JSON.stringify(json, null, 4));
  75. });
  76. }
  77. function attachment_getImageWidthHeightBase64(id, width, height) {
  78. $('#grid').html('');
  79. $('#result').html('');
  80. $.ajax({
  81. type : 'get',
  82. dataType : 'json',
  83. url : '../jaxrs/attachment/' + id + '/image/width/' + width + '/height/' + height + '/binary/base64',
  84. xhrFields : {
  85. 'withCredentials' : true
  86. },
  87. crossDomain : true
  88. }).done(function(json) {
  89. if (json.type == 'success') {
  90. var str = '<img src="data:image/png;base64,' + json.data.value + '"/>';
  91. $('#grid').html(str);
  92. }
  93. }).always(function(json) {
  94. $('#result').html(JSON.stringify(json, null, 4));
  95. });
  96. }