building.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. building_parameter = {
  2. };
  3. function building_grid(items, gridRoom) {
  4. var str = '<table border="1" width="100%"><tbody>';
  5. str += '<tr><th>id</th><th>name</th><th>address</th><th>operate</th></tr>';
  6. if (items) {
  7. $.each(items, function(index, item) {
  8. str += '<tr>';
  9. str += '<td>' + item.id + '</td>';
  10. str += '<td>' + item.name + '</td>';
  11. str += '<td>' + item.address + '</td>';
  12. str += '<td>';
  13. str += '<a href="#" onclick="building_put_init(\'' + item.id + '\')">edit</a>&nbsp;';
  14. str += '<a href="#" onclick="building_delete(\'' + item.id + '\')">delete</a>';
  15. str += '</td>';
  16. str += '</tr>';
  17. if (gridRoom) {
  18. str += building_grid_room(item.roomList);
  19. }
  20. });
  21. }
  22. str += '</tobdy></table>';
  23. $('#content').html(str);
  24. }
  25. function building_grid_room(items) {
  26. var str = "";
  27. if (items) {
  28. $.each(items, function(index, item) {
  29. str += '<tr>';
  30. str += '<td>' + item.name + '</td>';
  31. str += '<td>' + item.id + '</td><td>';
  32. if (item.photo && item.photo != '') {
  33. str += '<img src="data:image/png;base64,' + item.photo + '"/>';
  34. } else {
  35. str += '&nbsp;';
  36. }
  37. str += '</td><td>';
  38. str += '<a href="#" onclick="room_put_select(\'' + item.id + '\')">edit</a>&nbsp;';
  39. str += '<a href="#" onclick="room_delete_select(\'' + item.id + '\')">delete</a>&nbsp;';
  40. str += '<a href="#" onclick="room_update_photo_init(\'' + item.id + '\')">photo</a>';
  41. str += '</td>';
  42. str += '</tr>';
  43. });
  44. }
  45. return str;
  46. }
  47. function building_list() {
  48. $('#result').html('');
  49. $.ajax({
  50. type : 'get',
  51. dataType : 'json',
  52. url : '../jaxrs/building/list',
  53. xhrFields : {
  54. 'withCredentials' : true
  55. },
  56. crossDomain : true
  57. }).done(function(json) {
  58. $('#result').html(JSON.stringify(json, null, 4));
  59. if (json.type == 'success') {
  60. building_grid(json.data, true);
  61. }
  62. });
  63. }
  64. function building_listCheckRoomIdle_select() {
  65. $('#result').html('');
  66. var str = '<table border="1" width="100%">';
  67. str += '<tr><td colspan="2"><a href="#" id="list">list</a>';
  68. str += '</td></tr>';
  69. str += '<tr><td>start(yyyy-MM-dd HH:mm):</td><td><input type="text" id="start" style="width:95%"/></td></tr>';
  70. str += '<tr><td>completed(yyyy-MM-dd HH:mm):</td><td><input type="text" id="completed" style="width:95%"/></td></tr>';
  71. str += '</table>';
  72. $('#content').html(str);
  73. $('#list').click(function() {
  74. building_listCheckRoomIdle($('#start').val(), $('#completed').val());
  75. });
  76. }
  77. function building_listCheckRoomIdle(start, completed) {
  78. $('#result').html('');
  79. $.ajax({
  80. type : 'get',
  81. dataType : 'json',
  82. url : '../jaxrs/building/list/start/' + start + '/completed/' + completed,
  83. xhrFields : {
  84. 'withCredentials' : true
  85. },
  86. crossDomain : true
  87. }).done(function(json) {
  88. $('#result').html(JSON.stringify(json, null, 4));
  89. if (json.type == 'success') {
  90. building_grid(json.data, true);
  91. }
  92. });
  93. }
  94. function building_post_select() {
  95. $('#result').html('');
  96. var str = '<table border="1" width="100%">';
  97. str += '<tr><td colspan="2"><a href="#" id="post">post</a></td></tr>';
  98. str += '<tr><td>name:</td><td><input type="text" id="name" style="width:95%"/></td></tr>';
  99. str += '<tr><td>address:</td><td><input type="text" id="address" style="width:95%"/></td></tr>';
  100. str += '</table>';
  101. $('#content').html(str);
  102. $('#post').click(function() {
  103. building_post();
  104. });
  105. }
  106. function building_post() {
  107. $('#result').html('');
  108. $.ajax({
  109. type : 'post',
  110. dataType : 'json',
  111. url : '../jaxrs/building',
  112. contentType : 'application/json; charset=utf-8',
  113. data : JSON.stringify({
  114. name : $('#name').val(),
  115. address : $('#address').val()
  116. }),
  117. xhrFields : {
  118. 'withCredentials' : true
  119. },
  120. crossDomain : true
  121. }).done(function(json) {
  122. $('#result').html(JSON.stringify(json, null, 4));
  123. });
  124. }
  125. function building_put_select() {
  126. $('#result').html('');
  127. var str = '<table border="1" width="100%">';
  128. str += '<tr><td colspan="2">';
  129. str += '<a href="#" id="select">select</a>';
  130. str += '</td></tr>';
  131. str += '<tr><td>id:</td><td><input type="text" id="id" style="width:95%"/></td></tr>';
  132. str += '</table>';
  133. $('#content').html(str);
  134. $('#select').click(function() {
  135. building_put_init($('#id').val());
  136. });
  137. }
  138. function building_put_init(id) {
  139. $('#result').html('');
  140. var str = '<table border="1" width="100%">';
  141. str += '<tr><td colspan="2"><a href="#" id="put">put</a></td></tr>';
  142. str += '<tr><td>id:</td><td id="id"></td></tr>';
  143. str += '<tr><td>name:</td><td><input type="text" id="name" style="width:95%"/></td></tr>';
  144. str += '<tr><td>address:</td><td><input type="text" id="address" style="width:95%"/></td></tr>';
  145. str += '</table>';
  146. $('#content').html(str);
  147. $('#put').click(function() {
  148. building_put(id);
  149. });
  150. $.ajax({
  151. type : 'get',
  152. dataType : 'json',
  153. url : '../jaxrs/building/' + id,
  154. xhrFields : {
  155. 'withCredentials' : true
  156. },
  157. crossDomain : true
  158. }).done(function(json) {
  159. $('#result').html(JSON.stringify(json, null, 4));
  160. if (json.type == 'success') {
  161. $('#id').html(json.data.id);
  162. $('#name').val(json.data.name);
  163. $('#address').val(json.data.address);
  164. }
  165. });
  166. }
  167. function building_put(id) {
  168. $('#result').html('');
  169. $.ajax({
  170. type : 'put',
  171. dataType : 'json',
  172. url : '../jaxrs/building/' + id,
  173. contentType : 'application/json; charset=utf-8',
  174. data : JSON.stringify({
  175. name : $('#name').val(),
  176. address : $('#address').val()
  177. }),
  178. xhrFields : {
  179. 'withCredentials' : true
  180. },
  181. crossDomain : true
  182. }).done(function(json) {
  183. $('#result').html(JSON.stringify(json, null, 4));
  184. });
  185. }
  186. function building_delete_select() {
  187. $('#result').html('');
  188. var str = '<table border="1" width="100%">';
  189. str += '<tr><td colspan="2">';
  190. str += '<a href="#" id="delete">delete</a>';
  191. str += '</td></tr>';
  192. str += '<tr><td>id:</td><td><input type="text" id="id" style="width:95%"/></td></tr>';
  193. str += '</table>';
  194. $('#content').html(str);
  195. $('#select').click(function() {
  196. building_delete($('#id').val());
  197. });
  198. }
  199. function building_delete(id) {
  200. $('#result').html('');
  201. $.ajax({
  202. type : 'delete',
  203. dataType : 'json',
  204. url : '../jaxrs/building/' + id,
  205. xhrFields : {
  206. 'withCredentials' : true
  207. },
  208. crossDomain : true
  209. }).done(function(json) {
  210. $('#result').html(JSON.stringify(json, null, 4));
  211. });
  212. }
  213. function building_search_select() {
  214. $('#result').html('');
  215. var str = '<table border="1" width="100%">';
  216. str += '<tr><td colspan="2">';
  217. str += '<a href="#" id="listPinyinInitial">listPinyinInitial</a>';
  218. str += '&nbsp;';
  219. str += '<a href="#" id="listLike">listLike</a>';
  220. str += '&nbsp;';
  221. str += '<a href="#" id="listLikePinyin">listLikePinyin</a>';
  222. str += '</td></tr>';
  223. str += '<tr><td>key:</td><td><input type="text" id="key" style="width:95%"/></td></tr>';
  224. str += '</table>';
  225. $('#content').html(str);
  226. $('#listPinyinInitial').click(function() {
  227. building_listPinyinInitial($('#key').val());
  228. });
  229. $('#listLike').click(function() {
  230. building_listLike($('#key').val());
  231. });
  232. $('#listLikePinyin').click(function() {
  233. building_listLikePinyin($('#key').val());
  234. });
  235. }
  236. function building_listPinyinInitial(key) {
  237. $('#result').html('');
  238. $.ajax({
  239. type : 'get',
  240. dataType : 'json',
  241. url : '../jaxrs/building/list/pinyininitial/' + key,
  242. xhrFields : {
  243. 'withCredentials' : true
  244. },
  245. crossDomain : true
  246. }).done(function(json) {
  247. $('#result').html(JSON.stringify(json, null, 4));
  248. building_grid(json.data, false);
  249. });
  250. }
  251. function building_listLike(key) {
  252. $('#result').html('');
  253. $.ajax({
  254. type : 'get',
  255. dataType : 'json',
  256. url : '../jaxrs/building/list/like/' + key,
  257. xhrFields : {
  258. 'withCredentials' : true
  259. },
  260. crossDomain : true
  261. }).done(function(json) {
  262. $('#result').html(JSON.stringify(json, null, 4));
  263. building_grid(json.data, false);
  264. });
  265. }
  266. function building_listLikePinyin(key) {
  267. $('#result').html('');
  268. $.ajax({
  269. type : 'get',
  270. dataType : 'json',
  271. url : '../jaxrs/building/list/like/pinyin/' + key,
  272. xhrFields : {
  273. 'withCredentials' : true
  274. },
  275. crossDomain : true
  276. }).done(function(json) {
  277. $('#result').html(JSON.stringify(json, null, 4));
  278. building_grid(json.data, false);
  279. });
  280. }