Best Practices

Best Practices

Hi Guys,

Im learning JQM and playing with Parse.com to make a customer database.  This is the starting structure of my code which is working but I just wanted to ask if im doing things correctly at the moment or if anyone can give me some tips... 

  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5.         <title></title>
  6.         <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no" />

  7.         <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0-rc.1/jquery.mobile-1.3.0-rc.1.min.css" />
  8. <link rel="stylesheet" href="assets/css/main.css" />

  9.         <script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
  10. <script src="http://code.jquery.com/mobile/1.3.0-rc.1/jquery.mobile-1.3.0-rc.1.min.js"></script>
  11. <script type="text/javascript" src="http://www.parsecdn.com/js/parse-1.2.0.min.js"></script>
  12. <script src="assets/js/jquery.toastmessage.js" type="text/javascript"></script>
  13. <link href="assets/css/jquery.toastmessage.css" rel="stylesheet" type="text/css" />
  14.   

  15.         <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  16.         <meta name="apple-mobile-web-app-capable" content="yes">

  17.         <link href="assets/images/apple-touch-icon-57x57.png" sizes="57x57" rel="apple-touch-icon">
  18.         <link href="assets/images/apple-touch-icon-72x72.png" sizes="72x72" rel="apple-touch-icon">
  19.         <link href="assets/images/apple-touch-icon-114x114.png" sizes="114x114" rel="apple-touch-icon">
  20.         <link href="assets/images/apple-touch-icon-144x144.png" sizes="144x144" rel="apple-touch-icon">

  21.         <link href="assets/images/apple-touch-startup-image-320x460.png" media="(device-width: 320px)" rel="apple-touch-startup-image">
  22.         <link href="assets/images/apple-touch-startup-image-640x920.png" media="(device-width: 320px) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image">
  23.         <link href="assets/images/apple-touch-startup-image-768x1004.png" media="(device-width: 768px) and (orientation: portrait)" rel="apple-touch-startup-image">
  24.         <link href="assets/images/apple-touch-startup-image-748x1024.png" media="(device-width: 768px) and (orientation: landscape)" rel="apple-touch-startup-image">
  25.         <link href="assets/images/apple-touch-startup-image-1536x2008.png" media="screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait) and (-webkit-min-device-pixel-ratio: 2)" rel="apple-touch-startup-image" />`
  26.         <link href="assets/images/apple-touch-startup-image-1496x2048.png" media="screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape) and (-webkit-min-device-pixel-ratio: 2)" rel="apple-touch-startup-image" />
  27.     </head>
  28.     <body>

  29. <!-- Blank Initial Page.  Jquery will change to either the Login Page or Home Page depending on User Login State -->
  30.         
  31. <div data-role="page" id="startPage">
  32.             <div data-role="content">
  33.             </div><!-- End Content -->
  34.         </div><!-- End startPage -->
  35. <div data-role="page" id="loginPage">
  36. <div data-role="header">
  37. <h1>Login</h1>
  38. </div><!-- End Header -->
  39. <div data-role="content">
  40. <form onSubmit="userLogin();" method="POST">
  41. <div data-role="fieldcontain">
  42. <label for="username" >Username:</label>
  43. <input type="text" name="username" id="username" />
  44. </div>    
  45. <div data-role="fieldcontain">
  46. <label for="password" >Password:</label>
  47. <input type="password" name="password" id="password" />
  48. </div>    
  49. <input id='btLogin' type="submit" name="Login" value="Login"/>
  50. </form>
  51. </div><!-- End Content -->
  52. </div><!-- End loginPage -->
  53. <div data-role="page" id="homePage">
  54. <div data-role="panel" id="pnlSettings">
  55.                 <h2>My Settings</h2>
  56.                 <button data-role="button" data-icon="bars" onclick="userLogout();">Log Out</button>
  57.             </div><!-- End Panel -->
  58.             <div data-role="header" data-position="fixed">
  59.                 <h1>INSITE touch</h1>
  60.                 <a href="#pnlSettings" data-icon="info" data-role="button" id="btSettings" >Settings</a>
  61.             </div><!-- End Header -->
  62.             <div data-role="content">
  63.                 <label for="search-basic" class="ui-hidden-accessible">Search Jobs:</label>
  64.                 <input type="search" name="search" id="search-basic" value="" placeholder="Search Jobs" />
  65.                 <br>
  66.                 <br>
  67.             </div><!-- End Content -->
  68.             <div data-role="footer" data-position="fixed">
  69.                 <div data-role="navbar">
  70.                     <ul>
  71.                         <li><a href="#page-CustomerList" data-role="button" data-icon="gear">Customers</a></li>
  72.                         <li><a href="#" onClick="createCustomer();" data-role="button" data-icon="bars">Jobs</a></li>
  73.                         <li><a href="#" onClick="showPartsList();" data-role="button" data-icon="gear">Parts</a></li>
  74.                     </ul>
  75.                 </div><!-- End NavBar -->
  76. </div><!-- End Footer -->
  77. </div><!-- End homePage -->
  78. <script type="text/javascript">
  79. Parse.initialize("of0fIcF9zlpGEwVVAUH7Sq10nwhvcGASDrwt4trU", "C8KLwbKPjzsBf4xCX0Z90hfkz6lvN0gXePHYadIp");
  80.   
  81. /*
  82. *
  83. * Check that the startPage has loaded and re-direct to either the #loginPage or #homePage
  84. * based on whether the user is logged into Parse
  85. *
  86. *
  87. * NOTE: this doesn't check other pages yet.  There might not be a need as Parse wont give
  88. * any data if not logged in.
  89. *
  90. */
  91.   
  92. $('#startPage').bind('pageshow', function() {
  93. var LoggedIn = Parse.User.current(); // * Get the current User state from Parse.
  94. if (LoggedIn) {
  95. $.mobile.changePage("#homePage"); // User logged in, go to #homePage
  96. } else {
  97. $.mobile.changePage("#loginPage"); // User not logged in, go to #loginPage
  98. }
  99. });
  100. /*
  101. * Authenticate against Parse. 
  102. *
  103. */
  104. function userLogin() {
  105. // Throw up a spinner message that we are checking login
  106. $.mobile.loading( 'show', {
  107. text: 'Authenticating Login',
  108. textVisible: true,
  109. theme: 'a',
  110. html: ""
  111. });
  112. // Attempt to log into Parse using supplied credentials.
  113. Parse.User.logIn($("#username").val(), $("#password").val(), {
  114. success: function(user) {
  115. // Successful login. 
  116. $.mobile.loading( 'hide' ); // Hide the Spinner
  117. $().toastmessage('showSuccessToast', "Login Successful!"); // Show Success Message
  118. $.mobile.changePage('#homePage'); // Change to #homePage
  119. },
  120. error: function(user, error) {
  121. // Unsuccessful login.
  122. $.mobile.loading( 'hide' ); // Hide the Spinner
  123. $().toastmessage('showSuccessToast', "Login Failed, Check your details.!"); // Show Failed Message
  124. }
  125. });
  126. };
  127. /* 
  128. *
  129. * Log Out Function.
  130. *
  131. * TODO: Check if Parse has a way of confirming logout was successful.
  132. *
  133. */
  134. function userLogout() {
  135. Parse.User.logOut(); // Call the Parse logout
  136. $().toastmessage('showSuccessToast', "Logout Successful!"); // Show Logout Successful message (currently assumed)
  137. $.mobile.changePage("#loginPage"); // Change to #loginPage
  138. }
  139. /*
  140. *
  141. * Customer Functions
  142. *
  143. */
  144. function showCustomers() { // Brings up all customers in the listview.
  145. var LoggedIn = Parse.User.current(); // * Get the current User state from Parse.
  146. if (LoggedIn) {
  147. $.mobile.changePage('#customerListPage');
  148. }
  149. }
  150. function CreateCustomer() { // Used to load up the create Customer Page.
  151. var LoggedIn = Parse.User.current(); // * Get the current User state from Parse.
  152. if (LoggedIn) {
  153. $.mobile.changePage('#createCustomerPage');
  154. }
  155. }
  156. function saveCustomer() { // Used to save the customer after user clicks save.
  157. var LoggedIn = Parse.User.current(); // * Get the current User state from Parse.
  158. if (LoggedIn) {
  159. // get values from form, validate and save.
  160. // If unsuccessful, throw up friendly error.  If successful, go customers list.
  161. }
  162. }
  163. function editCustomer() {
  164. }
  165. function updateCustomer() {
  166. }
  167. </script>
  168. </body>
  169. </html>