form.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. form_parameter = {
  2. first : '(0)',
  3. last : '(0)',
  4. count : 20
  5. };
  6. function form_list_next(id) {
  7. var id = (id ? id : form_parameter.last);
  8. $.ajax({
  9. type : 'get',
  10. dataType : 'json',
  11. url : '../jaxrs/form/list/' + id + '/next/' + form_parameter.count,
  12. xhrFields : {
  13. 'withCredentials' : true
  14. },
  15. crossDomain : true
  16. }).done(function(json) {
  17. if (json.type == 'success') {
  18. if (json.data.length > 0) {
  19. form_parameter.first = json.data[0].id;
  20. form_parameter.last = json.data[json.data.length - 1].id;
  21. } else {
  22. form_parameter.first = '(0)';
  23. }
  24. form_list_grid(json);
  25. }
  26. }).always(function(json) {
  27. $('#result').html(JSON.stringify(json, null, 4));
  28. });
  29. }
  30. function form_list_prev(id) {
  31. var id = (id ? id : form_parameter.first);
  32. $.ajax({
  33. type : 'get',
  34. dataType : 'json',
  35. url : '../jaxrs/form/list/' + id + '/prev/' + form_parameter.count,
  36. xhrFields : {
  37. 'withCredentials' : true
  38. },
  39. crossDomain : true
  40. }).done(function(json) {
  41. if (json.type == 'success') {
  42. if (data.data.length > 0) {
  43. form_parameter.first = json.data[0].id;
  44. form_parameter.last = json.data[json.data.length - 1].id;
  45. } else {
  46. form_parameter.last = '(0)';
  47. }
  48. form_list_grid(json);
  49. }
  50. }).always(function(json) {
  51. $('#result').html(JSON.stringify(json, null, 4));
  52. });
  53. }
  54. function form_list_grid(json) {
  55. var str = '<table border="1" width="100%">';
  56. str += '<tr><td colspan="6"> <a href="#" id="prev">prev</a>&nbsp;<a href="#" id="next">next</a>&nbsp;<span id="total">' + json.count + '</span></td></tr>';
  57. str += '<tr><th>id</th><th>name</th><th>application</th><th>operate</th></tr>';
  58. if (json.data) {
  59. $.each(json.data, function(index, item) {
  60. str += '<tr>';
  61. str += '<td>' + item.id + '</td>';
  62. str += '<td>' + item.name + '</td>';
  63. str += '<td>' + item.application + '</td>';
  64. str += '<td>';
  65. str += '<a href="#" onclick="form_edit(\'' + item.id + '\')">edit</a>&nbsp;';
  66. str += '<a href="#" onclick="form_delete(\'' + item.id + '\')">delete</a>';
  67. str += '</td>';
  68. str += '</tr>';
  69. });
  70. }
  71. str += '</table>';
  72. $('#content').html(str);
  73. $('#next').click(function() {
  74. form_list_next();
  75. });
  76. $('#prev').click(function() {
  77. form_list_prev();
  78. });
  79. }
  80. function form_query() {
  81. str = '<table border="1" width="100%">';
  82. str += '<tr><td colspan="2"><a href="#" id="listWithApplication">listWithApplication</a>&nbsp;<a href="#" id="listFormFieldWithApplication">listFormFieldWithApplication</a>&nbsp;<a href="#" id="listFormFieldWithForm">listFormFieldWithForm</a></td></tr>';
  83. str += '<tr><td>application id</td><td><input type="text" id="applicationId" style="width:95%"></td>';
  84. str += '<tr><td>form id</td><td><input type="text" id="formId" style="width:95%"></td>';
  85. str += '</tr></table>';
  86. $('#content').html(str);
  87. $('#listWithApplication').click(function() {
  88. form_listWithApplication($('#applicationId').val());
  89. });
  90. $('#listFormFieldWithApplication').click(function() {
  91. form_listFormFieldWithApplication($('#applicationId').val());
  92. });
  93. $('#listFormFieldWithForm').click(function() {
  94. form_listFormFieldWithForm($('#formId').val());
  95. });
  96. }
  97. function form_create_init() {
  98. str = '<table border="1" width="100%">';
  99. str += '<tr><td colspan="2"><a href="#" id="post">post</a></td></tr>';
  100. str += '<tr><td>application:</td><td><input type="text" id="application" style="width:95%"/></td></tr>';
  101. str += '<tr><td>name:</td><td><input type="text" id="name" style="width:95%"/></td></tr>';
  102. str += '<tr><td>description:</td><td><textarea id="description" style="width:95%"/></td></tr>';
  103. str += '<tr><td colspan="2">data:</td></tr>';
  104. str += '<tr><td colspan="2"><textarea id="data" style="width:95%;height:500px"/></td></tr>';
  105. str += '<tr><td colspan="2"><textarea id="formFieldList" style="width:95%;height:500px"/></td></tr>';
  106. str += '</table>';
  107. $('#content').html(str);
  108. $('#post').click(function() {
  109. form_post();
  110. });
  111. }
  112. function form_post() {
  113. $.ajax({
  114. type : 'post',
  115. dataType : 'json',
  116. contentType : 'application/json; charset=utf-8',
  117. url : '../jaxrs/form',
  118. data : JSON.stringify({
  119. name : $('#name').val(),
  120. application : $('#application').val(),
  121. description : $('#description').val(),
  122. data : $('#data').val(),
  123. formFieldList : $('#formFieldList').val()
  124. }),
  125. xhrFields : {
  126. 'withCredentials' : true
  127. },
  128. crossDomain : true
  129. }).always(function(json) {
  130. $('#result').html(JSON.stringify(json, null, 4));
  131. });
  132. }
  133. function form_edit(id) {
  134. str = '<table border="1" width="100%">';
  135. str += '<tr><td colspan="2"><a href="#" id="put">put</a></td></tr>';
  136. str += '<tr><td>name:</td><td><input type="text" id="name" style="width:95%"/></td></tr>';
  137. str += '<tr><td>form category:</td><td><select id="formCategory"/></td></tr>';
  138. str += '<tr><td>description:</td><td><textarea id="description" style="width:95%"/></td></tr>';
  139. str += '<tr><td>id:</td><td id="id">&nbsp;</td></tr>';
  140. str += '<tr><td>sequence:</td><td id="sequence">&nbsp;</td></tr>';
  141. str += '<tr><td colspan="2">data:</td></tr>';
  142. str += '<tr><td colspan="2"><textarea id="data" style="width:95%;height:500px"/></td></tr>';
  143. str += '<tr><td colspan="2"><textarea id="formFieldList" style="width:95%;height:500px"/></td></tr>';
  144. str += '</table>';
  145. $('#content').html(str);
  146. $('#put', '#content').click(function() {
  147. form_put(id);
  148. });
  149. $.ajax({
  150. type : 'get',
  151. dataType : 'json',
  152. url : '../jaxrs/form/' + id,
  153. xhrFields : {
  154. 'withCredentials' : true
  155. },
  156. crossDomain : true
  157. }).done(function(json) {
  158. if (json.type == 'success') {
  159. $('#name').val(json.data.name);
  160. $('#application').val(json.data.application);
  161. $('#description').val(json.data.description);
  162. $('#data').val(json.data.data);
  163. $('#formFieldList').val(joinValue(json.data.formFieldList));
  164. $('#id').html(json.data.id);
  165. }
  166. }).always(function(json) {
  167. $('#result').html(JSON.stringify(json, null, 4));
  168. });
  169. }
  170. function form_put(id) {
  171. $.ajax({
  172. type : 'put',
  173. dataType : 'json',
  174. url : '../jaxrs/form/' + id,
  175. contentType : 'application/json; charset=utf-8',
  176. data : JSON.stringify({
  177. name : $('#name').val(),
  178. application : $('#application').val(),
  179. description : $('#description').val(),
  180. data : $('#data').val(),
  181. formFieldList : JSON.parse($('#formFieldList').val())
  182. }),
  183. xhrFields : {
  184. 'withCredentials' : true
  185. },
  186. crossDomain : true
  187. }).always(function(json) {
  188. $('#result').html(JSON.stringify(json, null, 4));
  189. });
  190. }
  191. function form_delete(id) {
  192. $.ajax({
  193. type : 'delete',
  194. dataType : 'json',
  195. url : '../jaxrs/form/' + id,
  196. xhrFields : {
  197. 'withCredentials' : true
  198. },
  199. crossDomain : true
  200. }).always(function(json) {
  201. $('#result').html(JSON.stringify(json, null, 4));
  202. });
  203. }
  204. function form_listWithApplication(id) {
  205. $.ajax({
  206. type : 'get',
  207. dataType : 'json',
  208. url : '../jaxrs/form/application/' + id,
  209. xhrFields : {
  210. 'withCredentials' : true
  211. },
  212. crossDomain : true
  213. }).done(function(data) {
  214. if (data.type == 'success') {
  215. var str = '<table border="1" width="100%">';
  216. str += '<tr><th>id</th><th>name</th><th>application</th><th>operate</th></tr>';
  217. $.each(data.data, function(index, item) {
  218. str += '<tr>';
  219. str += '<td>' + item.id + '</td>';
  220. str += '<td>' + item.name + '</td>';
  221. str += '<td>' + item.application + '</td>';
  222. str += '<td>';
  223. str += '<a href="#" onclick="form_edit(\'' + item.id + '\')">edit</a>&nbsp;';
  224. str += '<a href="#" onclick="form_delete(\'' + item.id + '\')">delete</a>';
  225. str += '</td>';
  226. str += '</tr>';
  227. });
  228. str += '</table>';
  229. $('#content').html(str);
  230. }
  231. }).always(function(json) {
  232. $('#result').html(JSON.stringify(json, null, 4));
  233. });
  234. }
  235. function form_listFormFieldWithApplication(id) {
  236. $.ajax({
  237. type : 'get',
  238. dataType : 'json',
  239. url : '../jaxrs/form/list/formfield/application/' + id,
  240. xhrFields : {
  241. 'withCredentials' : true
  242. },
  243. crossDomain : true
  244. }).always(function(json) {
  245. $('#result').html(JSON.stringify(json, null, 4));
  246. });
  247. }
  248. function form_listFormFieldWithForm(id) {
  249. $.ajax({
  250. type : 'get',
  251. dataType : 'json',
  252. url : '../jaxrs/form/list/' + id + '/formfield',
  253. xhrFields : {
  254. 'withCredentials' : true
  255. },
  256. crossDomain : true
  257. }).always(function(json) {
  258. $('#result').html(JSON.stringify(json, null, 4));
  259. });
  260. }