Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

admin-search.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. $(function(){
  2. function isMatch(candidate, text) {
  3. if (candidate.name.toLowerCase().includes(text))
  4. return true;
  5. if (candidate.username.toLowerCase().includes(text))
  6. return true;
  7. if (("" + candidate.skymanager_id).includes(text))
  8. return true;
  9. if (candidate.voting_id && ("" + candidate.voting_id).includes(text))
  10. return true;
  11. return false;
  12. }
  13. function createChild(candidate) {
  14. var li = document.createElement('li');
  15. li.className = 'candidate';
  16. var profileimgsect = document.createElement('div');
  17. profileimgsect.className = 'profile-icon';
  18. var profileimg = document.createElement('img');
  19. profileimg.src = 'https://www.gravatar.com/avatar/' + candidate.gravatar_hash + '.png?d=mp&s=64';
  20. profileimgsect.appendChild(profileimg);
  21. var profiletext = document.createElement('div');
  22. profiletext.className = 'profile';
  23. var profilename = document.createElement('h2');
  24. profilename.className = 'profile-name';
  25. profilename.textContent = candidate.name;
  26. var profileid = document.createElement('h4');
  27. profileid.className = 'profile-id';
  28. profileid.textContent = candidate.voting_id;
  29. if (!candidate.voting_id || candidate.delegate) {
  30. profiletext.className += ' ineligible';
  31. profileid.textContent += " (Ineligible)";
  32. }
  33. profiletext.appendChild(profilename);
  34. profiletext.appendChild(profileid);
  35. if (candidate.proxies) {
  36. var proxies = document.createElement('div');
  37. proxies.className = 'proxies';
  38. proxies.textContent = 'Proxy Votes: ' + candidate.proxies.replace(',', ', ');
  39. profiletext.appendChild(proxies);
  40. }
  41. li.appendChild(profileimgsect);
  42. li.appendChild(profiletext);
  43. li.addEventListener('click', function() {
  44. var csc = document.getElementById("selectedVoter");
  45. while (csc.firstChild) {
  46. csc.removeChild(csc.firstChild);
  47. }
  48. csc.appendChild(profileimgsect);
  49. csc.appendChild(profiletext);
  50. var smid = document.getElementById('voter-smid');
  51. if (smid) smid.value = candidate.skymanager_id;
  52. document.getElementById('voter-input').value = candidate.voting_id;
  53. document.getElementById('voter-searchbox').value = "";
  54. search('');
  55. });
  56. return li;
  57. }
  58. function search(text) {
  59. var list = document.createElement('ul');
  60. var matches = 0;
  61. for (var i = 0; text.length > 0 && i < voters.length; i++) {
  62. if (isMatch(voters[i], text.toLowerCase())) {
  63. list.appendChild(createChild(voters[i]));
  64. if (++matches > 4)
  65. break;
  66. }
  67. }
  68. var container = document.getElementById('voter-results');
  69. while (container.firstChild) {
  70. container.removeChild(container.firstChild);
  71. }
  72. if (matches)
  73. container.appendChild(list);
  74. }
  75. $('#voter-searchbox').bind('textInput input', function() { search(this.value); });
  76. });