/root/projects/slingshot/config/alfresco/site-webscripts/org/alfresco/components/profile/userprofiletoolbar.get.js

https://github.com/deas/alfresco · JavaScript · 99 lines · 72 code · 14 blank · 13 comment · 21 complexity · 61d26541e761dba274667168f2e74df6 MD5 · raw file

  1. /**
  2. * User Profile - Toolbar Component GET method
  3. */
  4. function main()
  5. {
  6. var userId = page.url.templateArgs["userid"];
  7. if (userId == null)
  8. {
  9. userId = user.name;
  10. }
  11. model.activeUserProfile = (userId == user.name);
  12. model.activePage = (page.url.templateArgs.pageid || "");
  13. model.following = -1;
  14. model.followers = -1;
  15. var following = remote.call("/api/subscriptions/" + encodeURIComponent(userId) + "/following/count");
  16. if (following.status == 200)
  17. {
  18. model.following = JSON.parse(following).count;
  19. if (model.activeUserProfile)
  20. {
  21. var followers = remote.call("/api/subscriptions/" + encodeURIComponent(userId) + "/followers/count");
  22. if(followers.status == 200)
  23. {
  24. model.followers = JSON.parse(followers).count;
  25. }
  26. }
  27. }
  28. if (model.activeUserProfile)
  29. {
  30. model.syncEnabled = (syncMode.getValue() != "OFF");
  31. }
  32. model.links = [];
  33. // Add Profile link
  34. addLink("profile-link", "profile", "link.info");
  35. // Add User Sites link
  36. addLink("user-sites-link", "user-sites", "link.sites");
  37. // Add User Content link
  38. addLink("user-content-link", "user-content", "link.content");
  39. if (model.activeUserProfile)
  40. {
  41. if (model.following != -1)
  42. {
  43. // Add Following link
  44. addLink("following-link", "following", "link.following", [model.following]);
  45. }
  46. if (model.followers != -1)
  47. {
  48. // Add Followers link
  49. addLink("followers-link", "followers", "link.followers", [model.followers]);
  50. }
  51. if (user.capabilities.isMutable)
  52. {
  53. // Add Change Password link
  54. addLink("change-password-link", "change-password", "link.changepassword");
  55. }
  56. // Add Notifications links
  57. addLink("user-notifications-link", "user-notifications", "link.notifications");
  58. if (model.syncEnabled)
  59. {
  60. // Add Cloud Sync
  61. addLink("user-cloud-auth-link", "user-cloud-auth", "link.cloud-auth");
  62. }
  63. // Add Trashcan link
  64. addLink("user-trashcan-link", "user-trashcan", "link.trashcan");
  65. }
  66. else
  67. {
  68. if (model.following != -1)
  69. {
  70. // Add Following link
  71. addLink("otherfollowing-link", "following", "link.otherfollowing", [model.following]);
  72. }
  73. }
  74. }
  75. function addLink(id, href, msgId, msgArgs)
  76. {
  77. model.links.push(
  78. {
  79. id: id,
  80. href: href,
  81. cssClass: (model.activePage == href) ? "theme-color-4" : null,
  82. label: msg.get(msgId, msgArgs ? msgArgs : null)
  83. });
  84. }
  85. main();