Profile.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // Profile.js
  2. // The OnClickLogin function is called when
  3. // the user clicks the Login button.
  4. // It calls the AuthenticationService.login to
  5. // authenticates the user.
  6. function OnClickLogin()
  7. {
  8. Sys.Services.AuthenticationService.login(
  9. document.form1.userId.value,
  10. document.form1.userPwd.value,false,null,null,
  11. OnLoginComplete, OnAuthenticationFailed,
  12. "User context information.");
  13. }
  14. // The OnClickLogout function is called when
  15. // the user clicks the Logout button.
  16. // It logs out the current authenticated user.
  17. function OnClickLogout()
  18. {
  19. Sys.Services.AuthenticationService.logout(
  20. null, OnLogoutComplete, OnAuthenticationFailed,null);
  21. }
  22. function OnLogoutComplete(result,
  23. userContext, methodName)
  24. {
  25. // Code that performs logout
  26. // housekeeping goes here.
  27. }
  28. // This function is called after the user is
  29. // authenticated. It loads the user's profile.
  30. // This is the callback function called
  31. // if the authentication completed successfully.
  32. function OnLoginComplete(validCredentials,
  33. userContext, methodName)
  34. {
  35. if(validCredentials == true)
  36. {
  37. DisplayInformation("Welcome " + document.form1.userId.value);
  38. LoadProfile();
  39. // Hide or make visible page display elements.
  40. GetElementById("loginId").style.visibility = "hidden";
  41. GetElementById("setProfProps").style.visibility = "visible";
  42. GetElementById("logoutId").style.visibility = "visible";
  43. }
  44. else
  45. {
  46. DisplayInformation("Could not login");
  47. }
  48. }
  49. // This is the callback function called
  50. // if the authentication failed.
  51. function OnAuthenticationFailed(error_object,
  52. userContext, methodName)
  53. {
  54. DisplayInformation("Authentication failed with this error: " +
  55. error_object.get_message());
  56. }
  57. // Loads the profile of the current
  58. // authenticated user.
  59. function LoadProfile()
  60. {
  61. Sys.Services.ProfileService.load(null,
  62. OnLoadCompleted, OnProfileFailed, null);
  63. }
  64. // Saves the new profile
  65. // information entered by the user.
  66. function SaveProfile()
  67. {
  68. Sys.Services.ProfileService.properties.Backgroundcolor =
  69. GetElementById("bgcolor").value;
  70. // document.getElementById('bgcolor').value;
  71. Sys.Services.ProfileService.properties.Foregroundcolor =
  72. GetElementById("fgcolor").value;
  73. // document.getElementById('fgcolor').value;
  74. Sys.Services.ProfileService.save(null,
  75. OnSaveCompleted, OnProfileFailed, null);
  76. }
  77. // Reads the profile information and displays it.
  78. function OnLoadCompleted(numProperties, userContext, methodName)
  79. {
  80. document.bgColor =
  81. Sys.Services.ProfileService.properties.Backgroundcolor;
  82. document.fgColor =
  83. Sys.Services.ProfileService.properties.Foregroundcolor;
  84. }
  85. // This is the callback function called
  86. // if the profile was saved successfully.
  87. function OnSaveCompleted(numProperties, userContext, methodName)
  88. {
  89. LoadProfile();
  90. // Hide the area that contains
  91. // the controls to set the profile properties.
  92. SetProfileControlsVisibility("hidden");
  93. }
  94. // This is the callback function called
  95. // if the profile load or save operations failed.
  96. function OnProfileFailed(error_object, userContext, methodName)
  97. {
  98. alert("Profile service failed with message: " +
  99. error_object.get_message());
  100. }
  101. // Utility functions.
  102. // This function sets the visibilty for the
  103. // area containing the page elements for settings
  104. // profiles.
  105. function SetProfileControlsVisibility(currentVisibility)
  106. {
  107. GetElementById("setProfileProps").style.visibility =
  108. currentVisibility;
  109. }
  110. // Utility function to display user's information.
  111. function DisplayInformation(text)
  112. {
  113. document.getElementById('placeHolder').innerHTML +=
  114. "<br/>"+ text;
  115. }
  116. function GetElementById(elementId)
  117. {
  118. var element = document.getElementById(elementId);
  119. return element;
  120. }
  121. if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();