identity.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. identity_parameter = {
  2. first : '(0)',
  3. last : '(0)',
  4. count : 20
  5. };
  6. function identity_create() {
  7. var str = '<table border="1" width="100%">';
  8. str += '<tr><td colspan="2"><a href="#" id="post">post</a></td></tr>';
  9. str += '<tr><td>name:</td><td><input type="text" id="name" style="width:95%"/></td></tr>';
  10. str += '<tr><td>person:</td><td><input type="text" id="person" style="width:95%"/></td></tr>';
  11. str += '<tr><td>department:</td><td><input type="text" id="department" style="width:95%"/></td></tr>';
  12. str += '<tr><td>unique:</td><td><input type="text" id="unique" style="width:95%"/></td></tr>';
  13. str += '</table>';
  14. $('#content').html(str);
  15. $('#post').click(function() {
  16. identity_post();
  17. });
  18. }
  19. function identity_post() {
  20. $.ajax({
  21. type : 'post',
  22. dataType : 'json',
  23. url : '../jaxrs/identity',
  24. contentType : 'application/json; charset=utf-8',
  25. data : JSON.stringify({
  26. name : $('#name').val(),
  27. person : $('#person').val(),
  28. department : $('#department').val(),
  29. unique : $('#unique').val()
  30. }),
  31. xhrFields : {
  32. 'withCredentials' : true
  33. },
  34. crossDomain : true
  35. }).always(function(json) {
  36. $('#result').html(JSON.stringify(json, null, 4));
  37. });
  38. }
  39. function identity_edit(id) {
  40. var str = '<table border="1" width="100%">';
  41. str += '<tr><td colspan="2"><a href="#" id="put">put</a></td></tr>';
  42. str += '<tr><td>id:</td><td id="id"></td></tr>';
  43. str += '<tr><td>sequence:</td><td id="sequence"></td></tr>';
  44. str += '<tr><td>name:</td><td><input type="text" id="name" style="width:95%"/></td></tr>';
  45. str += '<tr><td>person:</td><td><input type="text" id="person" style="width:95%"/></td></tr>';
  46. str += '<tr><td>department:</td><td><input type="text" id="department" style="width:95%"/></td></tr>';
  47. str += '<tr><td>unique:</td><td><input type="text" id="unique" style="width:95%"/></td></tr>';
  48. str += '</table>';
  49. $('#content').html(str);
  50. $('#put').click(function() {
  51. identity_put(id);
  52. });
  53. $.ajax({
  54. type : 'get',
  55. dataType : 'json',
  56. url : '../jaxrs/identity/' + id,
  57. xhrFields : {
  58. 'withCredentials' : true
  59. },
  60. crossDomain : true
  61. }).done(function(json) {
  62. if (json.type == 'success') {
  63. $('#id').html(json.data.id);
  64. $('#sequence').html(json.data.sequence);
  65. $('#name').val(json.data.name);
  66. $('#person').val(json.data.person);
  67. $('#department').val(json.data.department);
  68. $('#unique').val(json.data.unique);
  69. }
  70. }).always(function(json) {
  71. $('#result').html(JSON.stringify(json, null, 4));
  72. });
  73. }
  74. function identity_put(id) {
  75. $.ajax({
  76. type : 'put',
  77. dataType : 'json',
  78. url : '../jaxrs/identity/' + id,
  79. contentType : 'application/json; charset=utf-8',
  80. data : JSON.stringify({
  81. name : $('#name').val(),
  82. person : $('#person').val(),
  83. department : $('#department').val(),
  84. unique : $('#unique').val()
  85. }),
  86. xhrFields : {
  87. 'withCredentials' : true
  88. },
  89. crossDomain : true
  90. }).always(function(json) {
  91. $('#result').html(JSON.stringify(json, null, 4));
  92. });
  93. }
  94. function identity_delete(id) {
  95. $.ajax({
  96. type : 'delete',
  97. dataType : 'json',
  98. url : '../jaxrs/identity/' + id,
  99. xhrFields : {
  100. 'withCredentials' : true
  101. },
  102. crossDomain : true
  103. }).always(function(json) {
  104. $('#result').html(JSON.stringify(json, null, 4));
  105. });
  106. }
  107. function identity_list_next(id) {
  108. var id = (id ? id : identity_parameter.last);
  109. $.ajax({
  110. type : 'get',
  111. dataType : 'json',
  112. url : '../jaxrs/identity/list/' + id + '/next/' + identity_parameter.count,
  113. xhrFields : {
  114. 'withCredentials' : true
  115. },
  116. crossDomain : true
  117. }).done(function(json) {
  118. if (json.type == 'success') {
  119. if (json.data.length > 0) {
  120. identity_parameter.first = json.data[0].id;
  121. identity_parameter.last = json.data[json.data.length - 1].id;
  122. } else {
  123. identity_parameter.first = '(0)';
  124. }
  125. identity_list_grid(json);
  126. }
  127. }).always(function(json) {
  128. $('#result').html(JSON.stringify(json, null, 4));
  129. });
  130. }
  131. function identity_list_prev(id) {
  132. var id = (id ? id : identity_parameter.first);
  133. $.ajax({
  134. type : 'get',
  135. dataType : 'json',
  136. url : '../jaxrs/identity/list/' + id + '/prev/' + identity_parameter.count,
  137. xhrFields : {
  138. 'withCredentials' : true
  139. },
  140. crossDomain : true
  141. }).done(function(json) {
  142. if (json.type == 'success') {
  143. if (json.data.length > 0) {
  144. identity_parameter.first = json.data[0].id;
  145. identity_parameter.last = json.data[json.data.length - 1].id;
  146. } else {
  147. identity_parameter.last = '(0)';
  148. }
  149. identity_list_grid(json);
  150. }
  151. }).always(function(json) {
  152. $('#result').html(JSON.stringify(json, null, 4));
  153. });
  154. }
  155. function identity_list_grid(json) {
  156. var str = '<table border="1" width="100%">';
  157. 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>';
  158. str += '<tr><th>rank</th><th>id</th><th>name</th><th>person</th><th>department</th><th>operate</th></tr>';
  159. if (json.data) {
  160. $.each(json.data, function(index, item) {
  161. str += '<tr>';
  162. str += '<td>' + item.rank + '</td>';
  163. str += '<td>' + item.id + '</td>';
  164. str += '<td>' + item.name + '</td>';
  165. str += '<td>' + item.person + '</td>';
  166. str += '<td>' + item.department + '</td>';
  167. str += '<td>';
  168. str += '<a href="#" onclick="identity_edit(\'' + item.id + '\')">edit</a>&nbsp;';
  169. str += '<a href="#" onclick="identity_delete(\'' + item.id + '\')">delete</a>';
  170. str += '</td>';
  171. str += '</tr>';
  172. });
  173. }
  174. str += '</table>';
  175. $('#content').html(str);
  176. $('#next').click(function() {
  177. identity_list_next();
  178. });
  179. $('#prev').click(function() {
  180. identity_list_prev();
  181. });
  182. }
  183. function identity_query_init() {
  184. str = '<table border="1" width="100%">';
  185. str += '<tr><td>query:</td><td><input type="text" id="query" style="width:95%"/></td></tr>';
  186. str += '<tr><td colspan="2"><a href="#" id="withPerson">获取个人拥有的身份.</a></td></tr>';
  187. str += '<tr><td colspan="2"><a href="#" id="withDepartment">获取部门的成员的身份.</a></td></tr>';
  188. str += '<tr><td colspan="2"><a href="#" id="pinyinInitial">根据首字母进行查找.</a></td></tr>';
  189. str += '<tr><td colspan="2"><a href="#" id="like">进行模糊查找.</a></td></tr>';
  190. str += '<tr><td colspan="2"><a href="#" id="likePinyin">根据拼音进行查找.</a></td></tr>';
  191. str += '</table>';
  192. $('#content').html(str);
  193. $('#withPerson').click(function() {
  194. identity_query_withPerson($('#query').val());
  195. });
  196. $('#withDepartment').click(function() {
  197. identity_query_withDepartment($('#query').val());
  198. });
  199. $('#like').click(function() {
  200. identity_query_like($('#query').val());
  201. });
  202. $('#pinyinInitial').click(function() {
  203. identity_query_pinyinInitial($('#query').val());
  204. });
  205. $('#likePinyin').click(function() {
  206. identity_query_likePinyin($('#query').val());
  207. });
  208. }
  209. function identity_query_likeWithSubCompanySubDepartment_init() {
  210. str = '<table border="1" width="100%">';
  211. str += '<tr><td>query:</td><td><input type="text" id="query" style="width:95%"/></td></tr>';
  212. str += '<tr><td>companyList:</td><td><textarea id="companyList" style="width:95%"/></td></tr>';
  213. str += '<tr><td>departmentList:</td><td><textarea id="departmentList" style="width:95%"/></td></tr>';
  214. str += '<tr><td colspan="2"><a href="#" id="likeWithSubCompanySubDepartment">查找.</a></td></tr>';
  215. str += '</table>';
  216. $('#content').html(str);
  217. $('#likeWithSubCompanySubDepartment').click(function() {
  218. identity_query_likeWithSubCompanySubDepartment();
  219. });
  220. }
  221. function identity_query_grid(json) {
  222. var str = '<table border="1" width="100%">';
  223. str += '<tr><th>id</th><th>name</th><th>person</th><th>department</th><th>operate</th></tr>';
  224. if (json.data) {
  225. $.each(json.data, function(index, item) {
  226. str += '<tr>';
  227. str += '<td>' + item.id + '</td>';
  228. str += '<td>' + item.name + '</td>';
  229. str += '<td>' + item.person + '</td>';
  230. str += '<td>' + item.department + '</td>';
  231. str += '<td>';
  232. str += '<a href="#" onclick="identity_edit(\'' + item.id + '\')">edit</a>&nbsp;';
  233. str += '<a href="#" onclick="identity_delete(\'' + item.id + '\')">delete</a>';
  234. str += '</td>';
  235. str += '</tr>';
  236. });
  237. }
  238. str += '</table>';
  239. $('#content').html(str);
  240. }
  241. function identity_query_withPerson(id) {
  242. $.ajax({
  243. type : 'get',
  244. dataType : 'json',
  245. url : '../jaxrs/identity/list/person/' + id,
  246. xhrFields : {
  247. 'withCredentials' : true
  248. },
  249. crossDomain : true
  250. }).always(function(json) {
  251. $('#result').html(JSON.stringify(json, null, 4));
  252. });
  253. }
  254. function identity_query_withDepartment(id) {
  255. $.ajax({
  256. type : 'get',
  257. dataType : 'json',
  258. url : '../jaxrs/identity/list/department/' + id,
  259. xhrFields : {
  260. 'withCredentials' : true
  261. },
  262. crossDomain : true
  263. }).always(function(json) {
  264. $('#result').html(JSON.stringify(json, null, 4));
  265. });
  266. }
  267. function identity_query_like(key) {
  268. $.ajax({
  269. type : 'get',
  270. dataType : 'json',
  271. url : '../jaxrs/identity/list/like/' + encodeURIComponent(key),
  272. xhrFields : {
  273. 'withCredentials' : true
  274. },
  275. crossDomain : true
  276. }).always(function(json) {
  277. $('#result').html(JSON.stringify(json, null, 4));
  278. });
  279. }
  280. function identity_query_pinyinInitial(key) {
  281. $.ajax({
  282. type : 'get',
  283. dataType : 'json',
  284. url : '../jaxrs/identity/list/pinyininitial/' + encodeURIComponent(key),
  285. xhrFields : {
  286. 'withCredentials' : true
  287. },
  288. crossDomain : true
  289. }).always(function(json) {
  290. $('#result').html(JSON.stringify(json, null, 4));
  291. });
  292. }
  293. function identity_query_likePinyin(key) {
  294. $.ajax({
  295. type : 'get',
  296. dataType : 'json',
  297. url : '../jaxrs/identity/list/like/pinyin/' + encodeURIComponent(key),
  298. xhrFields : {
  299. 'withCredentials' : true
  300. },
  301. crossDomain : true
  302. }).always(function(json) {
  303. $('#result').html(JSON.stringify(json, null, 4));
  304. });
  305. }
  306. function identity_query_likeWithSubCompanySubDepartment() {
  307. $.ajax({
  308. type : 'post',
  309. dataType : 'json',
  310. url : '../jaxrs/identity/list/company/sub/nest/department/sub/nest/like/' + encodeURIComponent($('#query').val()),
  311. xhrFields : {
  312. 'withCredentials' : true
  313. },
  314. data : JSON.stringify({
  315. companyList : splitValue($('#companyList').val()),
  316. departmentList : splitValue($('#departmentList').val())
  317. }),
  318. crossDomain : true
  319. }).always(function(json) {
  320. $('#result').html(JSON.stringify(json, null, 4));
  321. });
  322. }