LoginPage.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. var LoginPage = {
  2. onPageShow: function () {
  3. Dashboard.showLoadingMsg();
  4. ApiClient.getAllUsers().done(LoginPage.loadUserList);
  5. },
  6. getLastSeenText: function (lastActivityDate) {
  7. if (!lastActivityDate) {
  8. return "";
  9. }
  10. return "Last seen " + humane_date(lastActivityDate);
  11. },
  12. getImagePath: function (user) {
  13. if (!user.PrimaryImageTag) {
  14. return "css/images/logindefault.png";
  15. }
  16. return ApiClient.getUserImageUrl(user.Id, {
  17. width: 240,
  18. tag: user.PrimaryImageTag,
  19. type: "Primary"
  20. });
  21. },
  22. authenticateUserLink: function (link) {
  23. LoginPage.authenticateUser(link.getAttribute('data-username'), link.getAttribute('data-userid'));
  24. },
  25. authenticateUser: function (username, userId, password) {
  26. Dashboard.showLoadingMsg();
  27. ApiClient.authenticateUser(userId, password).done(function () {
  28. Dashboard.setCurrentUser(userId);
  29. window.location = "index.html?u=" + userId;
  30. }).fail(function () {
  31. Dashboard.hideLoadingMsg();
  32. setTimeout(function () {
  33. Dashboard.showError("Invalid user or password.");
  34. }, 300);
  35. });
  36. },
  37. loadUserList: function (users) {
  38. var html = "";
  39. for (var i = 0, length = users.length; i < length; i++) {
  40. var user = users[i];
  41. var linkId = "lnkUser" + i;
  42. var background = Dashboard.getRandomMetroColor();
  43. html += '<div class="posterViewItem posterViewItemWithDualText">';
  44. if (user.HasPassword) {
  45. html += "<a id='" + linkId + "' data-userid='" + user.Id + "' data-username='" + user.Name + "' href='#popupLogin' data-rel='popup' onclick='LoginPage.authenticatingLinkId=this.id;' \">";
  46. } else {
  47. html += "<a id='" + linkId + "' data-userid='" + user.Id + "' data-username='" + user.Name + "' href='#' onclick='LoginPage.authenticateUserLink(this);' \">";
  48. }
  49. if (user.PrimaryImageTag) {
  50. var imgUrl = ApiClient.getUserImageUrl(user.Id, {
  51. width: 500,
  52. tag: user.PrimaryImageTag,
  53. type: "Primary"
  54. });
  55. html += '<img src="' + imgUrl + '" />';
  56. } else {
  57. html += '<img style="background:' + background + ';" src="css/images/logindefault.png"/>';
  58. }
  59. html += '<div class="posterViewItemText posterViewItemPrimaryText">' + user.Name + '</div>';
  60. html += '<div class="posterViewItemText">';
  61. var lastSeen = LoginPage.getLastSeenText(user.LastActivityDate);
  62. if (lastSeen != "") {
  63. html += lastSeen;
  64. }
  65. else {
  66. html += "&nbsp;";
  67. }
  68. html += '</div>';
  69. html += '</a>';
  70. html += '</div>';
  71. }
  72. $('#divUsers', '#loginPage').html(html);
  73. Dashboard.hideLoadingMsg();
  74. },
  75. onSubmit: function () {
  76. $('#popupLogin', '#loginPage').popup('close');
  77. var link = $('#' + LoginPage.authenticatingLinkId)[0];
  78. LoginPage.authenticateUser(link.getAttribute('data-username'), link.getAttribute('data-userid'), $('#pw', '#loginPage').val());
  79. // Disable default form submission
  80. return false;
  81. }
  82. };
  83. $(document).on('pageshow', "#loginPage", LoginPage.onPageShow);