UserProfilesPage.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. var UserProfilesPage = {
  2. onPageShow: function () {
  3. UserProfilesPage.loadPageData();
  4. },
  5. loadPageData: function () {
  6. Dashboard.showLoadingMsg();
  7. ApiClient.getAllUsers().done(UserProfilesPage.renderUsers);
  8. },
  9. renderUsers: function (users) {
  10. var html = "";
  11. html += '<li data-role="list-divider"><h3>Users</h3></li>';
  12. for (var i = 0, length = users.length; i < length; i++) {
  13. var user = users[i];
  14. html += "<li>";
  15. html += "<a onclick='Dashboard.navigate(\"editUser.html?userId=" + user.Id + "\");' href='#'>";
  16. if (user.PrimaryImageTag) {
  17. var url = ApiClient.getUserImageUrl(user.Id, {
  18. width: 225,
  19. tag: user.PrimaryImageTag,
  20. type: "Primary"
  21. });
  22. html += "<img src='" + url + "' />";
  23. } else {
  24. html += "<img src='css/images/userFlyoutDefault.png' />";
  25. }
  26. html += "<h3>" + user.Name + "</h3>";
  27. html += "</a>";
  28. html += "<a onclick='UserProfilesPage.deleteUser(this);' data-userid='" + user.Id + "' data-username='" + user.Name + "' href='#'>Delete</a>";
  29. html += "</li>";
  30. }
  31. $('#ulUserProfiles', $('#userProfilesPage')).html(html).listview('refresh');
  32. Dashboard.hideLoadingMsg();
  33. },
  34. deleteUser: function (link) {
  35. var name = link.getAttribute('data-username');
  36. var msg = "Are you sure you wish to delete " + name + "?";
  37. Dashboard.confirm(msg, "Delete User", function (result) {
  38. if (result) {
  39. Dashboard.showLoadingMsg();
  40. var id = link.getAttribute('data-userid');
  41. ApiClient.deleteUser(id).done(function () {
  42. Dashboard.validateCurrentUser();
  43. UserProfilesPage.loadPageData();
  44. });
  45. }
  46. });
  47. }
  48. };
  49. $(document).on('pageshow', "#userProfilesPage", UserProfilesPage.onPageShow);