Advertisement
Guest User

Untitled

a guest
Aug 14th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.73 KB | None | 0 0
  1. var currentTab = "";
  2. function showHometab() {
  3. if (currentTab != "TabA") {
  4. currentTab = "TabA";
  5. showNoTabs();
  6. document.getElementById("TabA").style.backgroundColor = "lightBlue";
  7. document.getElementById("SectionA").style.display = "inline";
  8. }
  9. }
  10.  
  11. function showTabB() {
  12. if (currentTab != "TabB") {
  13. currentTab = "TabB";
  14. showNoTabs();
  15. document.getElementById("TabB").style.backgroundColor = "lightBlue";
  16. document.getElementById("SectionB").style.display = "inline";
  17. }
  18. var uri = "http://redsox.uoa.auckland.ac.nz/BC/Open/Service.svc/brlist";
  19. var list = new XMLHttpRequest();
  20. list.open("GET", uri, true);
  21. list.setRequestHeader('Accept', 'application/json');
  22. list.onload = function () {
  23. var version_d = document.getElementById("showbrTab");
  24. version_d.innerHTML = list.responseText;
  25. console.log(list.responseText);
  26. var res = JSON.parse(list.responseText);
  27. console.log(JSON.stringify(res))
  28. showbrlist(res);
  29. }
  30. list.send(null);
  31. }
  32.  
  33. function showTabC() {
  34. if (currentTab != "TabC") {
  35. currentTab = "TabC";
  36. showNoTabs();
  37. document.getElementById("TabC").style.backgroundColor = "lightBlue";
  38. document.getElementById("SectionC").style.display = "inline";
  39. }
  40. var uri2 = "http://redsox.uoa.auckland.ac.nz/BC/Open/Service.svc/booklist";
  41. var list = new XMLHttpRequest();
  42. list.open("GET", uri2, true);
  43. list.setRequestHeader('Accept', 'application/json');
  44. list.onload = function () {
  45. var version_d = document.getElementById("bookl");
  46. version_d.innerHTML = list.responseText;
  47. console.log(list.responseText);
  48. var res = JSON.parse(list.responseText);
  49. console.log(JSON.stringify(res))
  50. showbooklist(res);
  51. }
  52. list.send(null);
  53. }
  54.  
  55. function showTabD() {
  56. if (currentTab != "TabD") {
  57. currentTab = "TabD";
  58. showNoTabs();
  59. document.getElementById("TabD").style.backgroundColor = "lightBlue";
  60. document.getElementById("SectionD").style.display = "inline";
  61. }
  62. }
  63.  
  64. function showTabE() {
  65. if (currentTab != "TabE") {
  66. currentTab = "TabE";
  67. showNoTabs();
  68. document.getElementById("TabE").style.backgroundColor = "lightBlue";
  69. document.getElementById("SectionE").style.display = "inline";
  70. }
  71. }
  72.  
  73. function showNoTabs() {
  74. document.getElementById("TabA").style.backgroundColor = "transparent";
  75. document.getElementById("TabB").style.backgroundColor = "transparent";
  76. document.getElementById("TabC").style.backgroundColor = "transparent";
  77. document.getElementById("TabD").style.backgroundColor = "transparent";
  78. document.getElementById("TabE").style.backgroundColor = "transparent";
  79.  
  80. document.getElementById("SectionA").style.display = "none";
  81. document.getElementById("SectionB").style.display = "none";
  82. document.getElementById("SectionC").style.display = "none";
  83. document.getElementById("SectionD").style.display = "none";
  84. document.getElementById("SectionE").style.display = "none";
  85. }
  86.  
  87. window.onload = function () {
  88. showHometab();
  89. }
  90.  
  91. function searchbluray() {
  92. document.getElementById("showbrTab").innerHTML = null;
  93. action = document.getElementById("searchbr").value;
  94. var uri = "http://redsox.uoa.auckland.ac.nz/BC/Open/Service.svc/brsearch?term=" + action;
  95. var list = new XMLHttpRequest();
  96. list.open("GET", uri, true);
  97. list.setRequestHeader('Accept', 'application/json');
  98. list.onload = function () {
  99. var version_d = document.getElementById("showbrTab");
  100. version_d.innerHTML = list.responseText;
  101. console.log(list.responseText);
  102. var res = JSON.parse(list.responseText);
  103. console.log(JSON.stringify(res))
  104. showbrlist(res);
  105. }
  106. list.send(null);
  107. }
  108.  
  109. function searchbooklist() {
  110. document.getElementById("bookl").innerHTML = null;
  111. action = document.getElementById("searchbl").value;
  112. var uri = "http://redsox.uoa.auckland.ac.nz/BC/Open/Service.svc/booksearch?term=" + action;
  113. var list = new XMLHttpRequest();
  114. list.open("GET", uri, true);
  115. list.setRequestHeader('Accept', 'application/json');
  116. list.onload = function () {
  117. var version_d = document.getElementById("bookl");
  118. version_d.innerHTML = list.responseText;
  119. console.log(list.responseText);
  120. var res = JSON.parse(list.responseText);
  121. console.log(JSON.stringify(res))
  122. showbooklist(res);
  123. }
  124. list.send(null);
  125. }
  126.  
  127. function showbrlist(li) {
  128. var tableContent = "<tr class='blurays'></tr>\n";
  129. for (var i = 0; i < li.length; ++i) {
  130. var record = li[i];
  131. var addrs = record.Title;
  132. if (i & 1 == 1) { // odd row
  133. tableContent += "<tr class='orderOdd'>";
  134. }
  135. else { // even row
  136. tableContent += "<tr class='orderEven'>";
  137. }
  138. tableContent += "<td>" + "<img src=http://redsox.uoa.auckland.ac.nz/BC/Open/Service.svc/brimg?id="+ record.Id +"></td><td>" + addrs + "</td><td>" + "<button onclick=Buybr(" + JSON.stringify(record.Id) + ")>Buy</button><br><br>" + "</td></tr>\n";
  139. }
  140. document.getElementById("showbrTab").innerHTML = tableContent;
  141. }
  142.  
  143. function showbooklist(dest) {
  144. var tableContent = "<tr class='bookTitles'></tr>\n";
  145. for (var i = 0; i < dest.length; ++i) {
  146. var record = dest[i];
  147. var addrs = record.Title;
  148. if (i & 1 == 1) { // odd row
  149. tableContent += "<tr class='orderOdd'>";
  150. }
  151. else { // even row
  152. tableContent += "<tr class='orderEven'>";
  153. }
  154. tableContent += "<td>" + "<img src=http://redsox.uoa.auckland.ac.nz/BC/Open/Service.svc/bookimg?id="+ record.Id + "></td><td>" + addrs + "</td><td>" + "<button onclick=Buy(" + JSON.stringify(record.Id) + ")>Buy</button><br><br>" + "</td></tr>\n";
  155. }
  156. document.getElementById("bookl").innerHTML = tableContent;
  157. }
  158.  
  159. function Buy(item) {
  160. window.open("http://redsox.uoa.auckland.ac.nz/BC/Closed/Service.svc/bookbuy?id=" + item );
  161. }
  162.  
  163. function Buybr(item) {
  164. window.open("http://redsox.uoa.auckland.ac.nz/BC/Closed/Service.svc/brbuy?id=" + item );
  165. }
  166.  
  167. function Register() {
  168. Username = document.getElementById("Username").value;
  169. Pw = document.getElementById("Pw").value;
  170. Address = document.getElementById("Address").value;
  171. var uri= "http://redsox.uoa.auckland.ac.nz/BC/Open/Service.svc/register";
  172. var xhr= new XMLHttpRequest();
  173. xhr.open("POST", uri, true);
  174. xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
  175. var info = "{\"Address\":" + "\"" + Address + "\" , \"Name\":" + "\"" + Username + "\" , \"Password\":" + "\"" + Pw + "\"}";
  176. xhr.onload= function() {
  177. window.alert("you have been registered!")
  178. }
  179. xhr.send(info);
  180. }
  181.  
  182. function Save() {
  183. comment = document.getElementById("comment").value;
  184. name = document.getElementById("name").value;
  185. var uri= "http://redsox.uoa.auckland.ac.nz/BC/Open/Service.svc/comment?name=" + name;
  186. var xhr= new XMLHttpRequest();
  187. xhr.open("POST", uri, true);
  188. xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
  189. xhr.onload= function() {
  190. document.getElementById("com").src = document.getElementById("com").src
  191. }
  192. xhr.send(JSON.stringify(comment));
  193. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement