v1.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * 添加联系人后重新渲染联系人部件。
  3. * Render contact list after adding a contact.
  4. *
  5. * @access public
  6. * @return void
  7. */
  8. renderContactList = function()
  9. {
  10. if(config.debug) console.log('[ZIN] Rendering contact list');
  11. const link = $.createLink('user', 'ajaxGetContactList');
  12. $.getJSON(link, function(contacts)
  13. {
  14. $('.contactBox').addClass('p-0 w-24 input-group-addon').removeClass('input-group-btn');
  15. $('.contactBox #manageContact').addClass('hidden');
  16. $('.contactBox .picker-box').each(function()
  17. {
  18. $(this).removeClass('hidden').zui('picker').render({items: contacts});
  19. });
  20. });
  21. }
  22. /**
  23. * 选择联系人列表后加载联系人。
  24. * Load contact users after selecting contact list.
  25. *
  26. * @param string target
  27. * @access public
  28. * @return void
  29. */
  30. window.loadContactUsers = function(target)
  31. {
  32. const picker = event.target;
  33. const $picker = $(picker).zui('picker');
  34. if($picker === undefined)
  35. {
  36. if(config.debug) console.log('[ZIN] Contact picker not found');
  37. return;
  38. }
  39. const $target = target ? $("[name^='" + target + "']") : $(picker).closest('.contactBox').prev();
  40. const $targetPicker = $target.zui('picker');
  41. if($targetPicker === undefined)
  42. {
  43. if(config.debug) console.log('[ZIN] Target picker not found');
  44. return;
  45. }
  46. const listID = $picker.$.value;
  47. if(!listID)
  48. {
  49. $targetPicker.$.setValue('');
  50. return;
  51. }
  52. const link = $.createLink('user', 'ajaxGetContactUsers', 'listID=' + listID);
  53. $.getJSON(link, function(users)
  54. {
  55. const targetUsers = $targetPicker.$.valueList.concat(users.map(user => user.value));
  56. $targetPicker.$.setValue(targetUsers);
  57. });
  58. }