group.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. group_parameter = {
  2. root : common_parameter.host + '/x_organization_assemble_control/jaxrs/group',
  3. list_action : null,
  4. list_action_parameter : null,
  5. first : '(0)',
  6. last : '(0)',
  7. count : 20
  8. };
  9. function group_list_reload() {
  10. if (group_parameter.list_action) {
  11. group_parameter.list_action.call(window, group_parameter.list_action_parameter);
  12. } else {
  13. group_list_next('(0)');
  14. }
  15. }
  16. function group_create() {
  17. var str = '<table border="1" width="100%">';
  18. str += '<tr><td colspan="2"><a href="#" id="post">post</a></td></tr>';
  19. str += '<tr><td>name:</td><td><input type="text" id="name" style="width:95%"/></td></tr>';
  20. str += '<tr><td>personList:</td><td><textarea id="personList" style="width:95%;height:200px"/></td></tr>';
  21. str += '<tr><td>groupList:</td><td><textarea id="groupList" style="width:95%;height:200px"/></td></tr>';
  22. str += '<tr><td>unique:</td><td><input type="text" id="unique" style="width:95%"/></td></tr>';
  23. str += '</table>';
  24. $('#content').html(str);
  25. $('#post', '#content').click(function() {
  26. group_post();
  27. });
  28. }
  29. function group_post() {
  30. $.ajax({
  31. type : 'post',
  32. dataType : 'json',
  33. url : group_parameter.root,
  34. contentType : 'application/json; charset=utf-8',
  35. data : JSON.stringify({
  36. name : $('#name', '#content').val(),
  37. personList : splitValue($('#personList', '#content').val()),
  38. groupList : splitValue($('#groupList', '#content').val()),
  39. unique : $('#unique', '#content').val()
  40. }),
  41. xhrFields : {
  42. 'withCredentials' : true
  43. },
  44. crossDomain : true
  45. }).done(function(data) {
  46. if (data.type == 'success') {
  47. group_list_reload();
  48. } else {
  49. failure(data);
  50. }
  51. });
  52. }
  53. function group_edit(id) {
  54. var str = '<table border="1" width="100%">';
  55. str += '<tr><td colspan="2"><a href="#" id="put">put</a></td></tr>';
  56. str += '<tr><td>id:</td><td id="id"></td></tr>';
  57. str += '<tr><td>sequence:</td><td id="sequence"></td></tr>';
  58. str += '<tr><td>name:</td><td><input type="text" id="name" style="width:95%"/></td></tr>';
  59. str += '<tr><td>personList:</td><td><textarea id="personList" style="width:95%;height:200px"/></td></tr>';
  60. str += '<tr><td>groupList:</td><td><textarea id="groupList" style="width:95%;height:200px"/></td></tr>';
  61. str += '<tr><td>unique:</td><td><input type="text" id="unique" style="width:95%"/></td></tr>';
  62. str += '</table>';
  63. $('#content').html(str);
  64. $('#put', '#content').click(function() {
  65. group_put(id);
  66. });
  67. $.ajax({
  68. type : 'get',
  69. dataType : 'json',
  70. url : group_parameter.root + '/' + id,
  71. xhrFields : {
  72. 'withCredentials' : true
  73. },
  74. crossDomain : true
  75. }).done(function(data) {
  76. if (data.type == 'success') {
  77. $('#id', '#content').html(data.data.id);
  78. $('#sequence', '#content').html(data.data.sequence);
  79. $('#name', '#content').val(data.data.name);
  80. $('#personList', '#content').val(data.data.personList.join(','));
  81. $('#groupList', '#content').val(data.data.groupList.join(','));
  82. $('#unique', '#content').val(data.data.unique);
  83. } else {
  84. failure(data);
  85. }
  86. });
  87. }
  88. function group_put(id) {
  89. $.ajax({
  90. type : 'put',
  91. dataType : 'json',
  92. url : group_parameter.root + '/' + id,
  93. contentType : 'application/json; charset=utf-8',
  94. data : JSON.stringify({
  95. name : $('#name', '#content').val(),
  96. personList : splitValue($('#personList', '#content').val()),
  97. groupList : splitValue($('#groupList', '#content').val()),
  98. unique : $('#unique', '#content').val()
  99. }),
  100. xhrFields : {
  101. 'withCredentials' : true
  102. },
  103. crossDomain : true
  104. }).done(function(data) {
  105. if (data.type == 'success') {
  106. group_list_reload();
  107. } else {
  108. failure(data);
  109. }
  110. });
  111. }
  112. function group_delete(id) {
  113. $.ajax({
  114. type : 'delete',
  115. dataType : 'json',
  116. url : group_parameter.root + '/' + id,
  117. xhrFields : {
  118. 'withCredentials' : true
  119. },
  120. crossDomain : true
  121. }).done(function(data) {
  122. if (data.type == 'success') {
  123. group_list_next('(0)');
  124. } else {
  125. failure(data);
  126. }
  127. });
  128. }
  129. function group_list_next(id) {
  130. var id = ( id ? id : group_parameter.last);
  131. group_parameter.list_action = group_list_next;
  132. group_parameter.list_action_parameter = id;
  133. $.ajax({
  134. type : 'get',
  135. dataType : 'json',
  136. url : group_parameter.root + '/list/' + id + '/next/' + group_parameter.count,
  137. xhrFields : {
  138. 'withCredentials' : true
  139. },
  140. crossDomain : true
  141. }).done(function(data) {
  142. if (data.type == 'success') {
  143. if (data.data.length > 0) {
  144. group_parameter.first = data.data[0].id;
  145. group_parameter.last = data.data[data.data.length - 1].id;
  146. } else {
  147. group_parameter.first = '(0)';
  148. }
  149. $('#content').html(group_list_grid(data.data));
  150. $('#total', '#content').html(data.count);
  151. group_list_init();
  152. } else {
  153. failure(data);
  154. }
  155. });
  156. }
  157. function group_list_prev(id) {
  158. var id = ( id ? id : group_parameter.first);
  159. group_parameter.list_action = group_list_prev;
  160. group_parameter.list_action_parameter = id;
  161. $.ajax({
  162. type : 'get',
  163. dataType : 'json',
  164. url : group_parameter.root + '/list/' + id + '/prev/' + group_parameter.count,
  165. xhrFields : {
  166. 'withCredentials' : true
  167. },
  168. crossDomain : true
  169. }).done(function(data) {
  170. if (data.type == 'success') {
  171. if (data.data.length > 0) {
  172. group_parameter.first = data.data[0].id;
  173. group_parameter.last = data.data[data.data.length - 1].id;
  174. } else {
  175. group_parameter.last = '(0)';
  176. }
  177. $('#content').html(group_list_grid(data.data));
  178. $('#total', '#content').html(data.count);
  179. group_list_init();
  180. } else {
  181. failure(data);
  182. }
  183. });
  184. }
  185. function group_list_grid(items) {
  186. var str = '<table border="1" width="100%">';
  187. str += '<tr><td colspan="4"> <a href="#" id="prev">prev</a>&nbsp;<a href="#" id="next">next</a>&nbsp;<span id="total">0</span></td></tr>';
  188. str += '<tr><th>rank</th><th>id</th><th>name</th><th>operate</th></tr>';
  189. $.each(items, function(index, item) {
  190. str += '<tr>';
  191. str += '<td>' + item.rank + '</td>';
  192. str += '<td>' + item.id + '</td>';
  193. str += '<td>' + item.name + '</td>';
  194. str += '<td>';
  195. str += '<a href="#" onclick="group_edit(\'' + item.id + '\')">edit</a>&nbsp;';
  196. str += '<a href="#" onclick="group_delete(\'' + item.id + '\')">delete</a>';
  197. str += '</td>';
  198. str += '</tr>';
  199. });
  200. str += '</table>';
  201. return str;
  202. }
  203. function group_list_init() {
  204. $('#next', '#content').click(function() {
  205. group_list_next();
  206. });
  207. $('#prev', '#content').click(function() {
  208. group_list_prev();
  209. });
  210. }
  211. function group_query_init() {
  212. var str = '<table border="1" width="100%">';
  213. str += '<tr><td>query:</td><td><input type="text" id="query" style="width:95%"/></td></tr>';
  214. str += '<tr><td colspan="2"><a href="#" id="supDirect">获取群组的直接上级群组.</a></td></tr>';
  215. str += '<tr><td colspan="2"><a href="#" id="supNested">获取群组的嵌套上级群组.</a></td></tr>';
  216. str += '<tr><td colspan="2"><a href="#" id="supDirectWithPerson">获取人员所在的直接群组.</a></td></tr>';
  217. str += '<tr><td colspan="2"><a href="#" id="supNestedWithPerson">获取人员所在的群组,包括嵌套的群组.</a></td></tr>';
  218. str += '<tr><td colspan="2"><a href="#" id="subDirect">获取群组的直接下级群组.</a></td></tr>';
  219. str += '<tr><td colspan="2"><a href="#" id="subNested">获取群组的下级群组,包括嵌套的群组.</a></td></tr>';
  220. str += '<tr><td colspan="2"><a href="#" id="pinyinInitial">根据首字母进行查找.</a></td></tr>';
  221. str += '<tr><td colspan="2"><a href="#" id="like">进行模糊查找.</a></td></tr>';
  222. str += '<tr><td colspan="2"><a href="#" id="likePinyin">根据拼音进行查找.</a></td></tr>';
  223. str += '</table>';
  224. $('#content').html(str);
  225. $('#supDirect', '#content').click(function() {
  226. group_query_supDirect($('#query', '#content').val());
  227. });
  228. $('#supNested', '#content').click(function() {
  229. group_query_supNested($('#query', '#content').val());
  230. });
  231. $('#supDirectWithPerson', '#content').click(function() {
  232. group_query_supDirectWithPerson($('#query', '#content').val());
  233. });
  234. $('#supNestedWithPerson', '#content').click(function() {
  235. group_query_supNestedWithPerson($('#query', '#content').val());
  236. });
  237. $('#subDirect', '#content').click(function() {
  238. group_query_subDirect($('#query', '#content').val());
  239. });
  240. $('#subNested', '#content').click(function() {
  241. group_query_subNested($('#query', '#content').val());
  242. });
  243. $('#pinyinInitial', '#content').click(function() {
  244. group_query_pinyinInitial($('#query', '#content').val());
  245. });
  246. $('#like', '#content').click(function() {
  247. group_query_like($('#query', '#content').val());
  248. });
  249. $('#likePinyin', '#content').click(function() {
  250. group_query_likePinyin($('#query', '#content').val());
  251. });
  252. }
  253. function group_query_grid(items) {
  254. var str = '<table border="1" width="100%">';
  255. str += '<tr><th>id</th><th>name</th><th>operate</th></tr>';
  256. $.each(items, function(index, item) {
  257. str += '<tr>';
  258. str += '<td>' + item.id + '</td>';
  259. str += '<td>' + item.name + '</td>';
  260. str += '<td>';
  261. str += '<a href="#" onclick="group_edit(\'' + item.id + '\')">edit</a>&nbsp;';
  262. str += '<a href="#" onclick="group_delete(\'' + item.id + '\')">delete</a>';
  263. str += '</td>';
  264. str += '</tr>';
  265. });
  266. str += '</table>';
  267. return str;
  268. }
  269. function group_query_supDirect(id) {
  270. group_parameter.list_action = group_query_supDirect;
  271. group_parameter.list_action_parameter = id;
  272. $.ajax({
  273. type : 'get',
  274. dataType : 'json',
  275. url : group_parameter.root + '/list/' + id + '/sup/direct',
  276. xhrFields : {
  277. 'withCredentials' : true
  278. },
  279. crossDomain : true
  280. }).done(function(data) {
  281. if (data.type == 'success') {
  282. $('#content').html(group_query_grid(data.data));
  283. } else {
  284. failure(data);
  285. }
  286. });
  287. }
  288. function group_query_supNested(id) {
  289. group_parameter.list_action = group_query_supNested;
  290. group_parameter.list_action_parameter = id;
  291. $.ajax({
  292. type : 'get',
  293. dataType : 'json',
  294. url : group_parameter.root + '/list/' + id + '/sup/nested',
  295. xhrFields : {
  296. 'withCredentials' : true
  297. },
  298. crossDomain : true
  299. }).done(function(data) {
  300. if (data.type == 'success') {
  301. $('#content').html(group_query_grid(data.data));
  302. } else {
  303. failure(data);
  304. }
  305. });
  306. }
  307. function group_query_supDirectWithPerson(id) {
  308. group_parameter.list_action = group_query_supDirectWithPerson;
  309. group_parameter.list_action_parameter = id;
  310. $.ajax({
  311. type : 'get',
  312. dataType : 'json',
  313. url : group_parameter.root + '/list/person/' + id + '/sup/direct',
  314. xhrFields : {
  315. 'withCredentials' : true
  316. },
  317. crossDomain : true
  318. }).done(function(data) {
  319. if (data.type == 'success') {
  320. $('#content').html(group_query_grid(data.data));
  321. } else {
  322. failure(data);
  323. }
  324. });
  325. }
  326. function group_query_supNestedWithPerson(id) {
  327. group_parameter.list_action = group_query_supNestedWithPerson;
  328. group_parameter.list_action_parameter = id;
  329. $.ajax({
  330. type : 'get',
  331. dataType : 'json',
  332. url : group_parameter.root + '/list/person/' + id + '/sup/nested',
  333. xhrFields : {
  334. 'withCredentials' : true
  335. },
  336. crossDomain : true
  337. }).done(function(data) {
  338. if (data.type == 'success') {
  339. $('#content').html(group_query_grid(data.data));
  340. } else {
  341. failure(data);
  342. }
  343. });
  344. }
  345. function group_query_subDirect(id) {
  346. group_parameter.list_action = group_query_subDirect;
  347. group_parameter.list_action_parameter = id;
  348. $.ajax({
  349. type : 'get',
  350. dataType : 'json',
  351. url : group_parameter.root + '/list/' + id + '/sub/direct',
  352. xhrFields : {
  353. 'withCredentials' : true
  354. },
  355. crossDomain : true
  356. }).done(function(data) {
  357. if (data.type == 'success') {
  358. $('#content').html(group_query_grid(data.data));
  359. } else {
  360. failure(data);
  361. }
  362. });
  363. }
  364. function group_query_subNested(id) {
  365. group_parameter.list_action = group_query_subNested;
  366. group_parameter.list_action_parameter = id;
  367. $.ajax({
  368. type : 'get',
  369. dataType : 'json',
  370. url : group_parameter.root + '/list/' + id + '/sub/nested',
  371. xhrFields : {
  372. 'withCredentials' : true
  373. },
  374. crossDomain : true
  375. }).done(function(data) {
  376. if (data.type == 'success') {
  377. $('#content').html(group_query_grid(data.data));
  378. } else {
  379. failure(data);
  380. }
  381. });
  382. }
  383. function group_query_like(key) {
  384. group_parameter.list_action = group_query_like;
  385. group_parameter.list_action_parameter = key;
  386. $.ajax({
  387. type : 'get',
  388. dataType : 'json',
  389. url : group_parameter.root + '/list/like/' + encodeURIComponent(key),
  390. xhrFields : {
  391. 'withCredentials' : true
  392. },
  393. crossDomain : true
  394. }).done(function(data) {
  395. if (data.type == 'success') {
  396. $('#content').html(group_query_grid(data.data));
  397. } else {
  398. failure(data);
  399. }
  400. });
  401. }
  402. function group_query_pinyinInitial(key) {
  403. group_parameter.list_action = group_query_pinyinInitial;
  404. group_parameter.list_action_parameter = key;
  405. $.ajax({
  406. type : 'get',
  407. dataType : 'json',
  408. url : group_parameter.root + '/list/pinyininitial/' + encodeURIComponent(key),
  409. xhrFields : {
  410. 'withCredentials' : true
  411. },
  412. crossDomain : true
  413. }).done(function(data) {
  414. if (data.type == 'success') {
  415. $('#content').html(group_query_grid(data.data));
  416. } else {
  417. failure(data);
  418. }
  419. });
  420. }
  421. function group_query_likePinyin(key) {
  422. group_parameter.list_action = group_query_likePinyin;
  423. group_parameter.list_action_parameter = key;
  424. $.ajax({
  425. type : 'get',
  426. dataType : 'json',
  427. url : group_parameter.root + '/list/like/pinyin/' + encodeURIComponent(key),
  428. xhrFields : {
  429. 'withCredentials' : true
  430. },
  431. crossDomain : true
  432. }).done(function(data) {
  433. if (data.type == 'success') {
  434. $('#content').html(group_query_grid(data.data));
  435. } else {
  436. failure(data);
  437. }
  438. });
  439. }