Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // =========================
  2. // Application bootstrapper
  3. // =========================
  4.  
  5. // =========================
  6. // Config, preferably loaded from the back-end
  7. // =========================
  8. var config = {
  9.     title:     'forum',
  10.     version:   '0.1.0',
  11.  
  12.     // Other config options, server address etc.
  13.  
  14.     misc: {
  15.         floatingMenu: true
  16.     }
  17. };
  18.  
  19. // =========================
  20. // User account, also loaded from the back-end
  21. // after the login authentication
  22. // =========================
  23. var user = {};
  24.  
  25. // =========================
  26. // Initial function
  27. // =========================
  28. $(function(){
  29.     // Here the app launches
  30.  
  31.     // Configure menu
  32.     navigationCtrl.setNavigationFloating( config.misc.floatingMenu );
  33.  
  34.     utils.loadTemplate(
  35.         'tpl/testTemplate.html',
  36.         {},
  37.         function(template){
  38.  
  39.             // After the template is loaded on to the page,
  40.             // select the 'submit' button from it via jQuery.
  41.             // The button in the template has a class 'submit-button'
  42.             // Also, select the fields, so that you can read the
  43.             // values from them.
  44.             var $submitButton = $('.submit-button'),
  45.                     $formLogin = $('.input-fields > #user-name'),
  46.                     $formPassword = $('.input-fields > #user-password'),
  47.                     $formEmail = $('.input-fields > #user-email');
  48.  
  49.             // Now add an event to the button
  50.             $submitButton.on('click',function(eventData){
  51.  
  52.                 // On click, the button sends data to the back-end server.
  53.                 // jQuery.val() Reference - http://api.jquery.com/val/
  54.                 utils.sendData('http://backend.com/user',{
  55.                     login: $formLogin.val(),
  56.                     password: $formPassword.val(),
  57.                     email: $formEmail.val()
  58.                 }, function(response){
  59.  
  60.                     // When you get the responseh, it can be a JSON,
  61.                     // check if everything is ok and react.
  62.                     if( response.success === true ){
  63.  
  64.                         // Show a happy message to the user, maybe load another template
  65.                         alert('Registered!');
  66.                     } else {
  67.  
  68.                         // Show some error to the user
  69.                         alert('Error - back-end is fucked');
  70.                     }
  71.                 });
  72.             });
  73.         }
  74.     );
  75. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement