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

/assets/js/dashboard/projectusers.js

https://gitlab.com/oytunistrator/92five
JavaScript | 44 lines | 44 code | 0 blank | 0 comment | 7 complexity | 31d16c6d89522074d568922b2cda4cfe MD5 | raw file
  1. var UserModel = Backbone.Model.extend({
  2. name: function() {
  3. return this.get("first_name") + " " + this.get("last_name");
  4. },
  5. email: function() {
  6. return this.get("email");
  7. },
  8. userid: function() {
  9. return this.get("id");
  10. }
  11. });
  12. var UserCollection = Backbone.Collection.extend({
  13. model: UserModel,
  14. url: '/dashboard/users',
  15. });
  16. var UserView = Backbone.View.extend({
  17. el: $('#myModal-monthlyuserproject'),
  18. model: UserCollection,
  19. events: {
  20. "change #projectmonth": "userChange"
  21. },
  22. initialize: function() {
  23. this.model.on('add', this.addOne, this);
  24. },
  25. userChange: function() {
  26. if (($('#projectmonth').val() == 'null') || ($('#projectmonth').val() == 'others') || ($('#projectmonth').val() == '')) {
  27. $("#userprojectreportid").empty();
  28. $("#userprojectreportid").prop("disabled", true);
  29. } else {
  30. $("#userprojectreportid").prop("disabled", false);
  31. $("#userprojectreportid").empty();
  32. var url = window.location.href;
  33. var tempurl = url.split('dashboard')[0];
  34. this.model.reset();
  35. this.model.url = tempurl + 'dashboard/users/project/' + $('#projectmonth').val();
  36. this.model.fetch({
  37. update: true
  38. });
  39. }
  40. },
  41. addOne: function(model) {
  42. $('#userprojectreportid').append($("<option></option>").attr("value", model.userid()).text(model.name()));
  43. }
  44. });