Guest User

Untitled

a guest
Dec 9th, 2016
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. function startApp() {
  2. sessionStorage.clear();
  3.  
  4. showHideMenuLinks();
  5.  
  6. showView('viewHome');
  7.  
  8. $("#linkHome").click(showHomeView);
  9.  
  10. $("#formLogin").submit(loginUser);
  11.  
  12. $("form").submit(function(e) { e.preventDefault() });
  13.  
  14. $("#linkHome").click(showHomeView);
  15. $("#linkLogin").click(showLoginView);
  16. $("#linkRegister").click(showRegisterView);
  17. $("#linkListBooks").click(listBooks);
  18. $("#linkCreateBook").click(showCreateBookView);
  19. $("#linkLogout").click(logoutUser);
  20.  
  21. $("#buttonLoginUser").click(loginUser);
  22. $("#buttonRegisterUser").click(registerUser);
  23. $("#buttonCreateBook").click(createBook);
  24. $("#buttonEditBook").click(editBook);
  25.  
  26. $("#infoBox, #errorBox").click(function() {
  27. $(this).fadeOut();
  28. });
  29.  
  30. $(document).on({
  31. ajaxStart: function() { $("#loadingBox").show() },
  32. ajaxStop: function() { $("#loadingBox").hide() }
  33. });
  34.  
  35. const kinveyBaseUrl = "https://baas.kinvey.com/";
  36. const kinveyAppKey = "kid_rJgqxWyml";
  37. const kinveyAppSecret = "a69a6d3222ce4cca9f4d2c075d6090fb";
  38. const kinveyAppAuthHeaders = {
  39. 'Authorization': "Basic " +
  40. btoa(kinveyAppKey + ":" + kinveyAppSecret)
  41. };
  42.  
  43. function showHideMenuLinks() {
  44. $("#linkHome").show();
  45. if (sessionStorage.getItem('authToken')) {
  46. // We have logged in user
  47. $("#linkLogin").hide();
  48. $("#linkRegister").hide();
  49. $("#linkListBooks").show();
  50. $("#linkCreateBook").show();
  51. $("#linkLogout").show();
  52. } else {
  53. // No logged in user
  54. $("#linkLogin").show();
  55. $("#linkRegister").show();
  56. $("#linkListBooks").hide();
  57. $("#linkCreateBook").hide();
  58. $("#linkLogout").hide();
  59. }
  60.  
  61.  
  62. }
  63.  
  64. function showView(viewName) {
  65. $('main > section').hide();
  66. $('#' + viewName).show();
  67.  
  68. }
  69.  
  70. function showHomeView() {
  71. showView('viewHome');
  72. }
  73.  
  74. function showLoginView() {
  75. showView('viewLogin');
  76. $('#formLogin').trigger('reset');
  77.  
  78. }
  79.  
  80. function showRegisterView() {
  81. $('#formRegister').trigger('reset');
  82. showView('viewRegister');
  83.  
  84. }
  85.  
  86. function listBooks() {
  87.  
  88. }
  89.  
  90. function showCreateBookView() {
  91. $('#formCreateBook').trigger('reset');
  92. showView('viewCreateBook');
  93. }
  94.  
  95. function logoutUser() {
  96.  
  97. }
  98.  
  99. function loginUser() {
  100.  
  101. }
  102.  
  103. function registerUser() {
  104. let userData = {
  105. username: $('#formRegister input[name=username]').val(),
  106. password: $('#formRegister input[name=passwd]').val()
  107. };
  108. console.dir(userData)
  109.  
  110. $.ajax({
  111. method: "POST",
  112. url: kinveyBaseUrl + "user/" + kinveyAppKey + "/",
  113. headers: kinveyAppAuthHeaders,
  114. data: Json.stringify(userData),
  115. contentType: 'application/json',
  116. success: registerSuccess,
  117. error: handleAjaxError
  118. });
  119.  
  120. function registerSuccess() {
  121. alert('ok');
  122. //saveAuthInSession(userInfo);
  123. //showHideMenuLinks();
  124. //listBooks();
  125. //showInfo('User registration successful.');
  126. }
  127. }
  128.  
  129. function createBook() {
  130.  
  131. }
  132.  
  133. function editBook() {
  134.  
  135. }
  136.  
  137. function handleAjaxError() {
  138. alert('error')
  139. }
  140. }
Add Comment
Please, Sign In to add comment