Advertisement
Guest User

Class.coreFunction.js

a guest
May 2nd, 2015
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.72 KB | None | 0 0
  1. //***** Core Functions for whole app *******
  2. //Notes:
  3. //1. Now using Yii for serverside PHP framework
  4.  
  5. //++++++++++++Main Navigation Function+++++++++++++++//
  6. function changeAppPage(functionCall)
  7. {
  8.  
  9.  
  10. if(functionCall!="null")
  11. {
  12.  
  13.  
  14.  
  15.  
  16. //Start Switch Statement - this controls how the next page displays
  17. switch(functionCall)
  18. {
  19.  
  20.  
  21. //Case goes here
  22. case 'viewAllBugs':
  23.  
  24. $.mobile.loading('show', {text: 'Loading Bugs - Please Wait',textVisible: true,theme: 'a'});
  25.  
  26.  
  27. $.mobile.changePage('#viewAllBugs');
  28.  
  29. GetAllBugs();
  30.  
  31. break;
  32.  
  33.  
  34.  
  35.  
  36.  
  37. }
  38.  
  39.  
  40.  
  41. }else{
  42.  
  43. //Null Function
  44.  
  45. }
  46.  
  47.  
  48. $('#loginForm').submit(function(){
  49.  
  50.  
  51.  
  52. var postData = $('#loginForm').serialize();
  53.  
  54. console.log(postData);
  55.  
  56. //Show Page Loading Message
  57.  
  58. $.mobile.loading('show', {text: 'Logging Into Dashboard - Please Wait',textVisible: true,theme: 'a'});
  59.  
  60.  
  61. //*****Ajax JSON call will SEND and RECEIVE data back from the controller****
  62. $.ajax({
  63. type: 'POST',
  64. dataType: "json",
  65. data: postData,
  66. url: 'https://m2052626.scm.tees.ac.uk/AST_14/Bugg.ly2/index.php/Site/loginUserFromClient',
  67.  
  68.  
  69. success: function(data){
  70.  
  71.  
  72.  
  73. //data from controller
  74. if(data.action=="login"){
  75.  
  76. console.log('login user to dashboard');
  77. $('#msg').empty();
  78. $('#displayName').empty();
  79. $('<p></p>').html(data.name).appendTo('#displayName')
  80. $.mobile.changePage('#dashboard');
  81.  
  82. }else{
  83.  
  84.  
  85. $.mobile.loading('hide');
  86. $('#msg').empty();
  87. $('<span class="e-wurf-error"></span>').html(data.message).appendTo('#msg');
  88.  
  89.  
  90. }
  91.  
  92.  
  93.  
  94.  
  95. },
  96. error: function(){
  97.  
  98. alert('There was an error handeling your login authentication!');
  99. }
  100.  
  101. });
  102.  
  103.  
  104. return false;
  105.  
  106. });//End Login Function
  107. }//End Page Control
  108.  
  109.  
  110.  
  111. //GetAllProperties function below here
  112. function GetAllBugs()
  113. {
  114.  
  115.  
  116. //Web service call to get the data
  117. var getAllBugsData = $.get("https://m2052626.scm.tees.ac.uk/AST_14/Bugg.ly2/index.php/bug/GetAllBugs",
  118.  
  119.  
  120.  
  121. function(data)
  122. {
  123.  
  124. var j = 0;
  125. var myTotal = data.length ;
  126.  
  127.  
  128.  
  129. for(var i =0; i < data.length;i++)
  130. {
  131.  
  132. var item = data[i];
  133.  
  134.  
  135. bug_id = item.bug_id;
  136.  
  137. BugType = item.BugType;
  138.  
  139.  
  140. Bugaddress = item.Bugaddress;
  141. admin_id = item.admin_id;
  142. status = item.status;
  143.  
  144. Description = item.description;
  145. type = item.type;
  146.  
  147.  
  148. var bugDetails = '<div class="PropDetails">Property Num: '+bug_id+'</div><div class="PropDetails">Number of Bedrooms: '+BugType+'</div><div class="PropDetails">Price: £'+admin_id+'</div><div class="PropDetails">Type Of Property: '+type+'</div>';
  149.  
  150.  
  151.  
  152. $('.listAllBugs').append('<tr class="table-stroke"><td class="images_'+j+'"</td><td>'+bugDetails+'</td></tr>');
  153.  
  154.  
  155.  
  156. /*var getLength = function(obj)
  157. {
  158. var i = 0, key;
  159. for (key in obj) {
  160. if (obj.hasOwnProperty(key)){
  161. i++;
  162. }
  163. }
  164. return i;
  165. };*/
  166.  
  167.  
  168.  
  169.  
  170. //var nestedArrayLength = getLength(item.images);
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177. //alert(item.images[n].alt);
  178. //Get the first image in the array to display
  179.  
  180. $('.images_'+j).append('<img src="'+item.images[0].img_thumb+'" alt="'+item.images[0].alt+'" width="300" height="300" />' );
  181. j = j +1;
  182.  
  183.  
  184.  
  185. }//close loop
  186.  
  187.  
  188. }, "json");
  189.  
  190.  
  191.  
  192.  
  193. getAllBugsData.done(function()
  194. {
  195. $.mobile.loading('hide');
  196. //alert( "Wow we got the data" );
  197. })
  198.  
  199. getAllBugsData.fail(function()
  200. {
  201. $.mobile.loading('hide');
  202.  
  203. alert('Failed to connect to the web service! – check your URL to the web service API')
  204. })
  205.  
  206. };//close function
  207.  
  208. function changeAppPage(functionCall)
  209. {
  210.  
  211.  
  212. if(functionCall!="null")
  213. {
  214.  
  215.  
  216.  
  217.  
  218. //Start Switch Statement - this controls how the next page displays
  219. switch(functionCall)
  220. {
  221.  
  222.  
  223.  
  224. case 'dashboard':
  225.  
  226.  
  227. console.log('dashboard page call')
  228.  
  229. $.mobile.loading('show', {text: 'Loading - Please Wait',textVisible: true,theme: 'a'});
  230.  
  231.  
  232. $.mobile.changePage('#dashboard');
  233.  
  234.  
  235. break;
  236.  
  237.  
  238. }
  239.  
  240.  
  241.  
  242. }else{
  243.  
  244. //Null Function
  245.  
  246. }
  247.  
  248.  
  249.  
  250. }//End Page Control
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement