queryView.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. queryView_parameter = {
  2. first : '(0)',
  3. last : '(0)',
  4. count : 20
  5. };
  6. function queryView_list_next(id) {
  7. $('#result').html('');
  8. $('#content').html('');
  9. var id = (id ? id : queryView_parameter.last);
  10. $.ajax({
  11. type : 'get',
  12. dataType : 'json',
  13. url : '../jaxrs/queryview/list/' + id + '/next/' + queryView_parameter.count,
  14. xhrFields : {
  15. 'withCredentials' : true
  16. },
  17. crossDomain : true
  18. }).done(function(json) {
  19. if (json.type == 'success') {
  20. if (json.data.length > 0) {
  21. queryView_parameter.first = json.data[0].id;
  22. queryView_parameter.last = json.data[json.data.length - 1].id;
  23. } else {
  24. queryView_parameter.first = '(0)';
  25. }
  26. $('#content').html(queryView_list_grid(json));
  27. }
  28. }).always(function(json) {
  29. $('#result').html(JSON.stringify(json, null, 4));
  30. });
  31. }
  32. function queryView_list_prev(id) {
  33. $('#result').html('');
  34. $('#content').html('');
  35. var id = (id ? id : queryView_parameter.first);
  36. $.ajax({
  37. type : 'get',
  38. dataType : 'json',
  39. url : '../jaxrs/queryview/list/' + id + '/prev/' + queryView_parameter.count,
  40. xhrFields : {
  41. 'withCredentials' : true
  42. },
  43. crossDomain : true
  44. }).done(function(json) {
  45. if (json.type == 'success') {
  46. if (json.data.length > 0) {
  47. queryView_parameter.first = json.data[0].id;
  48. queryView_parameter.last = json.data[json.data.length - 1].id;
  49. } else {
  50. queryView_parameter.last = '(0)';
  51. }
  52. queryView_list_grid(json);
  53. }
  54. }).always(function(json) {
  55. $('#result').html(JSON.stringify(json, null, 4));
  56. });
  57. }
  58. function queryView_list_grid(json) {
  59. var str = '<table border="1" width="100%">';
  60. 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>';
  61. str += '<tr><th>id</th><th>name</th><th>alias</th><th>application</th><th>operate</th></tr>';
  62. $.each(json.data, function(index, item) {
  63. str += '<tr>';
  64. str += '<td>' + item.id + '</td>';
  65. str += '<td>' + item.name + '</td>';
  66. str += '<td>' + item.alias + '</td>';
  67. str += '<td>' + item.application + '</td>';
  68. str += '<td>';
  69. str += '<a href="#" onclick="queryView_edit(\'' + item.id + '\')">edit</a>&nbsp;';
  70. str += '<a href="#" onclick="queryView_delete(\'' + item.id + '\')">delete</a>';
  71. str += '</td>';
  72. str += '</tr>';
  73. });
  74. str += '</table>';
  75. $('#content').html(str);
  76. $('#next').click(function() {
  77. queryView_list_next();
  78. });
  79. $('#prev').click(function() {
  80. queryView_list_prev();
  81. });
  82. }
  83. function queryView_simulate_init() {
  84. $('#result').html('');
  85. $('#content').html('');
  86. var str = '<table border="1" width="100%">';
  87. str += '<tr><td colspan="2"><a href="#" id="simulate">simulate</a>&nbsp;<a href="#" id="get">get</a></td></tr>';
  88. str += '<tr><td>id:</td><td><input type="text" id="id" style="width:95%"/></td></tr>';
  89. str += '<tr><td>filter:</td><td><input type="text" id="filter" style="width:95%"/></td></tr>';
  90. str += '<tr><td>where:</td><td><input type="text" id="where" style="width:95%"/></td></tr>';
  91. str += '</table>';
  92. $('#content').html(str);
  93. $('#simulate').click(function() {
  94. queryView_simulate($('#id').val());
  95. });
  96. $('#flag').click(function() {
  97. queryView_get($('#id').val());
  98. });
  99. }
  100. function queryView_simulate(id) {
  101. $.ajax({
  102. type : 'put',
  103. dataType : 'json',
  104. url : '../jaxrs/queryview/' + id + '/simulate?' + Math.random(),
  105. contentType : 'application/json; charset=utf-8',
  106. data : JSON.stringify({
  107. filter : $('#filter').val(),
  108. where : $('#where').val()
  109. }),
  110. xhrFields : {
  111. 'withCredentials' : true
  112. },
  113. crossDomain : true
  114. }).always(function(json) {
  115. $('#result').html(JSON.stringify(json, null, 4));
  116. });
  117. }
  118. function queryView_create() {
  119. $('#result').html('');
  120. $('#content').html('');
  121. var str = '<table border="1" width="100%">';
  122. str += '<tr><td colspan="2"><a href="#" id="post">post</a></td></tr>';
  123. str += '<tr><td>application:</td><td><input type="text" id="application" style="width:95%"/></td></tr>';
  124. str += '<tr><td>name:</td><td><input type="text" id="name" style="width:95%"/></td></tr>';
  125. str += '<tr><td>alias:</td><td><input type="text" id="alias" style="width:95%"/></td></tr>';
  126. str += '<tr><td>description:</td><td><input type="text" id="description" style="width:95%"/></td></tr>';
  127. str += '<tr><td>allowPersonList:</td><td><textarea id="allowPersonList" style="width:95%"/></td></tr>';
  128. str += '<tr><td>allowIdentityList:</td><td><textarea id="allowIdentityList" style="width:95%"/></td></tr>';
  129. str += '<tr><td>allowDepartmentList:</td><td><textarea id="allowDepartmentList" style="width:95%"/></td></tr>';
  130. str += '<tr><td>allowCompanyList:</td><td><textarea id="allowCompanyList" style="width:95%"/></td></tr>';
  131. str += '<tr><td colspan="2">data:</td></tr>';
  132. str += '<tr><td colspan="2"><textarea id="data" style="width:95%;height:500px"/></td></tr>';
  133. str += '</table>';
  134. $('#content').html(str);
  135. $('#post').click(function() {
  136. queryView_post();
  137. });
  138. }
  139. function queryView_post() {
  140. $.ajax({
  141. type : 'post',
  142. dataType : 'json',
  143. contentType : 'application/json; charset=utf-8',
  144. url : '../jaxrs/queryview',
  145. data : JSON.stringify({
  146. application : $('#application').val(),
  147. name : $('#name').val(),
  148. alias : $('#alias').val(),
  149. description : $('#description').val(),
  150. allowPersonList : splitValue($('#allowPersonList').val()),
  151. allowIdentityList : splitValue($('#allowIdentityList').val()),
  152. allowDepartmentList : splitValue($('#allowDepartmentList').val()),
  153. allowCompanyList : splitValue($('#allowCompanyList').val()),
  154. data : $('#data').val()
  155. }),
  156. xhrFields : {
  157. 'withCredentials' : true
  158. },
  159. crossDomain : true
  160. }).always(function(json) {
  161. $('#result').html(JSON.stringify(json, null, 4));
  162. });
  163. }
  164. function queryView_edit(id) {
  165. $('#result').html('');
  166. $('#content').html('');
  167. var str = '<table border="1" width="100%">';
  168. str += '<tr><td colspan="2"><a href="#" id="put">put</a></td></tr>';
  169. str += '<tr><td>createTime:</td><td id="createTime">&nbsp;</td></tr>';
  170. str += '<tr><td>updateTime:</td><td id="updateTime">&nbsp;</td></tr>';
  171. str += '<tr><td>sequence:</td><td id="sequence">&nbsp;</td></tr>';
  172. str += '<tr><td>id:</td><td id="id">&nbsp;</td></tr>';
  173. str += '<tr><td>lastUpdatePerson:</td><td id="lastUpdatePerson">&nbsp;</td></tr>';
  174. str += '<tr><td>lastUpdateTime:</td><td id="lastUpdateTime">&nbsp;</td></tr>';
  175. str += '<tr><td>name:</td><td><input type="text" id="name" style="width:95%"/></td></tr>';
  176. str += '<tr><td>alias:</td><td><input type="text" id="alias" style="width:95%"/></td></tr>';
  177. str += '<tr><td>description:</td><td><input type="text" id="description" style="width:95%"/></td></tr>';
  178. str += '<tr><td>allowPersonList:</td><td><textarea id="allowPersonList" style="width:95%"/></td></tr>';
  179. str += '<tr><td>allowIdentityList:</td><td><textarea id="allowIdentityList" style="width:95%"/></td></tr>';
  180. str += '<tr><td>allowDepartmentList:</td><td><textarea id="allowDepartmentList" style="width:95%"/></td></tr>';
  181. str += '<tr><td>allowCompanyList:</td><td><textarea id="allowCompanyList" style="width:95%"/></td></tr>';
  182. str += '<tr><td colspan="2">data:</td></tr>';
  183. str += '<tr><td colspan="2"><textarea id="data" style="width:95%;height:500px"/></td></tr>';
  184. str += '</table>';
  185. $('#content').html(str);
  186. $('#put').click(function() {
  187. queryView_put(id);
  188. });
  189. $.ajax({
  190. type : 'get',
  191. dataType : 'json',
  192. url : '../jaxrs/queryview/' + id,
  193. xhrFields : {
  194. 'withCredentials' : true
  195. },
  196. crossDomain : true
  197. }).done(function(json) {
  198. $('#result').html(JSON.stringify(json, null, 4));
  199. if (json.type == 'success') {
  200. $('#createTime').html(json.data.createTime);
  201. $('#updateTime').html(json.data.updateTime);
  202. $('#sequence').html(json.data.sequence);
  203. $('#id').html(json.data.id);
  204. $('#lastUpdatePerson').html(json.data.lastUpdatePerson);
  205. $('#lastUpdateTime').html(json.data.lastUpdateTime);
  206. $('#name').val(json.data.name);
  207. $('#application').val(json.data.application);
  208. $('#description').val(json.data.description);
  209. $('#allowPersonList').val(joinValue(json.data.allowPersonList));
  210. $('#allowIdentityList').val(joinValue(json.data.allowIdentityList));
  211. $('#allowDepartmentList').val(joinValue(json.data.allowDepartmentList));
  212. $('#allowCompanyList').val(joinValue(json.data.allowCompanyList));
  213. $('#data').val(json.data.data);
  214. }
  215. }).always(function(json) {
  216. $('#result').html(JSON.stringify(json, null, 4));
  217. });
  218. }
  219. function queryView_put(id) {
  220. $.ajax({
  221. type : 'put',
  222. dataType : 'json',
  223. url : '../jaxrs/queryview/' + id,
  224. contentType : 'application/json; charset=utf-8',
  225. data : JSON.stringify({
  226. application : $('#application').val(),
  227. name : $('#name').val(),
  228. alias : $('#alias').val(),
  229. description : $('#description').val(),
  230. allowPersonList : splitValue($('#allowPersonList').val()),
  231. allowIdentityList : splitValue($('#allowIdentityList').val()),
  232. allowDepartmentList : splitValue($('#allowDepartmentList').val()),
  233. allowCompanyList : splitValue($('#allowCompanyList').val()),
  234. data : $('#data').val()
  235. }),
  236. xhrFields : {
  237. 'withCredentials' : true
  238. },
  239. crossDomain : true
  240. }).always(function(json) {
  241. $('#result').html(JSON.stringify(json, null, 4));
  242. });
  243. }
  244. function queryView_delete(id) {
  245. $.ajax({
  246. type : 'delete',
  247. dataType : 'json',
  248. url : '../jaxrs/queryview/' + id,
  249. xhrFields : {
  250. 'withCredentials' : true
  251. },
  252. crossDomain : true
  253. }).always(function(json) {
  254. $('#result').html(JSON.stringify(json, null, 4));
  255. });
  256. }
  257. function queryView_get(id) {
  258. $.ajax({
  259. type : 'get',
  260. dataType : 'json',
  261. url : '../jaxrs/queryview/' + id,
  262. xhrFields : {
  263. 'withCredentials' : true
  264. },
  265. crossDomain : true
  266. }).always(function(json) {
  267. $('#result').html(JSON.stringify(json, null, 4));
  268. });
  269. }
  270. function queryView_listWithApplication_init() {
  271. var str = '<table border="1" width="100%">';
  272. str += '<tr><td colspan="2"><a href="#" id="list">list</a></td></tr>';
  273. str += '<tr><td>application flag:</td><td><input type="text" id="applicationFlag" style="width:95%"/></td></tr>';
  274. str += '<tr><td colspan="2" id="gird">&nbsp;</td></tr>';
  275. str += '</table>';
  276. $('#content').html(str);
  277. $('#post').click(function() {
  278. queryView_listWithApplication($('#applicationFlag').val());
  279. });
  280. }
  281. function queryView_listWithApplication(id) {
  282. $.ajax({
  283. type : 'get',
  284. dataType : 'json',
  285. url : '../jaxrs/queryview/list/application/' + id,
  286. xhrFields : {
  287. 'withCredentials' : true
  288. },
  289. crossDomain : true
  290. }).done(function(json) {
  291. if (json.type == 'success') {
  292. var str = '<table border="1" width="100%">';
  293. str += '<tr><th>id</th><th>name</th><th>alias</th><th>application</th><th>operate</th></tr>';
  294. $.each(json.data, function(index, item) {
  295. str += '<tr>';
  296. str += '<td>' + item.id + '</td>';
  297. str += '<td>' + item.name + '</td>';
  298. str += '<td>' + item.alias + '</td>';
  299. str += '<td>' + item.application + '</td>';
  300. str += '<td>';
  301. str += '<a href="#" onclick="queryView_edit(\'' + item.id + '\')">edit</a>&nbsp;';
  302. str += '<a href="#" onclick="queryView_delete(\'' + item.id + '\')">delete</a>';
  303. str += '</td>';
  304. str += '</tr>';
  305. });
  306. str += '</table>';
  307. $('#gird').html(str);
  308. }
  309. }).always(function(json) {
  310. $('#result').html(JSON.stringify(json, null, 4));
  311. });
  312. }