PageRenderTime 25ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/assets/js/dashboard/projectuserlist.js

https://gitlab.com/oytunistrator/92five
JavaScript | 74 lines | 73 code | 0 blank | 1 comment | 13 complexity | a20f387d580d51f6127ca5a8a76ba556 MD5 | raw file
  1. $(function() {
  2. var Plugin = Backbone.Model.extend({
  3. label: function() {
  4. return this.get("first_name") + " " + this.get("last_name");
  5. },
  6. email: function() {
  7. return this.get("email");
  8. }
  9. });
  10. var PluginCollection = Backbone.Collection.extend({
  11. model: Plugin,
  12. url: '/dashboard/users',
  13. });
  14. var plugins = new PluginCollection();
  15. plugins.fetch({
  16. update: true
  17. });
  18. new AutoCompleteView({
  19. input: $("#plugin"),
  20. model: plugins,
  21. keyup: function() {
  22. if ($('#projectlist').val() == 'null') {
  23. var url = window.location.href;
  24. var tempurl = url.split('dashboard')[0];
  25. this.model.url = tempurl + 'dashboard/users';
  26. this.model.fetch({
  27. update: true
  28. });
  29. } else {
  30. var url = window.location.href;
  31. var tempurl = url.split('dashboard')[0];
  32. this.model.reset();
  33. this.model.url = tempurl + 'dashboard/users/project/' + $('#projectlist').val();
  34. this.model.fetch({
  35. update: true
  36. });
  37. }
  38. var keyword = this.input.val();
  39. if (this.isChanged(keyword)) {
  40. if (this.isValid(keyword)) {
  41. this.filter(keyword);
  42. } else {
  43. this.hide()
  44. }
  45. }
  46. },
  47. onSelect: function(model) {
  48. var name = model.label();
  49. var email = model.email();
  50. var collablist = new Array();
  51. var arr = new Array();
  52. $('#list li').parent().children().each(function() {
  53. arr.push(this.innerHTML);
  54. })
  55. var flag = true;
  56. for (var j = 0; j < arr.length; j++) {
  57. if (arr[j].match(name)) flag = false;
  58. }
  59. if (flag == true) {
  60. var tmpemaillist = $('#tagsinput').val();
  61. $("#list").append('<li id="userlist" class="userlist" email=' + email + ' >' + name + '<a class="removeme" id="removeme" href="#">X</a></li>');
  62. if ($('#tagsinput').val() === "") {
  63. $('#tagsinput').val(email);
  64. } else {
  65. var tempstring = ',' + email;
  66. var emaillist = tmpemaillist.concat(tempstring);
  67. $('#tagsinput').val(emaillist);
  68. }
  69. } else {
  70. //Do Nothing
  71. }
  72. },
  73. }).render();
  74. });