Advertisement
Guest User

Untitled

a guest
Jul 18th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.46 KB | None | 0 0
  1. //(function () {
  2. // var app = angular.module('faqs', []);
  3.  
  4. // app.controller('FAQController', function () {
  5. // console.log("hej");
  6. // this.faq = faq;
  7. // });
  8.  
  9. // var faq = [
  10. // {
  11. // title: 'firstFAQ',
  12. // text: 'How do i Angular?',
  13. // author: 'Jag',
  14. // upvotes: 0,
  15. // },
  16. // {
  17. // title: 'firstFAQ',
  18. // text: 'How do i Angular?',
  19. // author: 'Jag',
  20. // upvotes: 0,
  21. // },
  22. // {
  23. // title: 'firstFAQ',
  24. // text: 'How do i Angular?',
  25. // author: 'Jag',
  26. // upvotes: 0,
  27. // },
  28. // ]
  29.  
  30. //})();
  31.  
  32. (function () {
  33. var app = angular.module('faqs', ['ngRoute']);
  34.  
  35. app.controller('FAQController', ['$http', function ($http) {
  36. var fc = this;
  37. fc.allFAQs = [];
  38. fc.ClickedUpvote = ClickedUpvote;
  39. fc.ClickedDownvote = ClickedDownvote;
  40.  
  41. fc.searchString = searchString;
  42. fc.CreateFAQ = CreateFAQ;
  43. fc.search = "";
  44.  
  45. fc.GetAllFAQs = GetAllFAQs;
  46.  
  47.  
  48. function searchString(search) {
  49. console.log(search);
  50. GetAllFAQs(search);
  51. }
  52.  
  53. function GetAllFAQs(search) {
  54.  
  55. $http({
  56. url: "http://localhost:53227/WebServiceFAQ.asmx/GetAllFAQs",
  57. data: {search: search},
  58. dataType: "json",
  59. method: "POST",
  60. headers: {
  61. "Content-Type": "application/json"
  62. }
  63. }).success(function (data) {
  64. //console.log("hejhej");
  65. fc.allFAQs = data.d;
  66. console.log(fc.allFAQs);
  67. });
  68. }
  69.  
  70. function CreateFAQ(author, title, text) {
  71. $http({
  72. url: "http://localhost:53227/WebServiceFAQ.asmx/CreateFAQ",
  73. data: { author: author, title: title, text: text },
  74. dataType: "json",
  75. method: "POST",
  76. headers: {
  77. "Content-Type": "application/json"
  78. }
  79. }).success(function (data) {
  80. //console.log("FAQ Created");
  81. });
  82. }
  83.  
  84. function ClickedUpvote(faqID) {
  85. $http({
  86. url: "http://localhost:53227/WebServiceFAQ.asmx/Upvote",
  87. data: '',
  88. dataType: "json",
  89. method: "POST",
  90. headers: {
  91. "Content-Type": "application/json"
  92. }
  93. }).success(function (data) {
  94. console.log("Upvoted");
  95. if (data.d)
  96. {
  97. }
  98. //fc.allFAQs = data.d;
  99. });
  100. }
  101. function ClickedDownvote() {
  102. }
  103.  
  104. //data: { test: 'test', test: 'test'}
  105. //.success bla bla if(data.d) sätt en bool till true som ger användaren access till dom andra sidorna
  106.  
  107.  
  108. fc.GetAllFAQs("");
  109. }]);
  110.  
  111. app.controller('SignInController', ['$http', function ($http) {
  112. var fc = this;
  113.  
  114. fc.Register = Register;
  115.  
  116. function Register(firstname, lastname, email, phonenumber, username, password) {
  117. console.log("registeredededed");
  118. $http({
  119. url: "http://localhost:53227/WebServiceLogin.asmx/Register",
  120. data: { firstname: firstname, lastname: lastname, email: email, phonenumber: phonenumber, username: username, password: password },
  121. dataType: "json",
  122. method: "POST",
  123. headers: {
  124. "Content-Type": "application/json"
  125. }
  126. }).success(function (data) {
  127. console.log("User added" + username);
  128. });
  129. }
  130. //den returnerade boolen skall sättar i data:''?
  131. function SignIn(username, password) {
  132. $http({
  133. url: "http://localhost:53227/WebServiceLogin.asmx/TryToSignIn",
  134. data: {username: username, password: password},
  135. dataType: "json",
  136. method: "POST",
  137. headers: {
  138. "Content-Type": "application/json"
  139. }
  140. }).success(function (data) {
  141. //Byt sida? ändra en bool som aktiverar sidorna som kräver att man är inloggad? jag vet inte?
  142. });
  143. }
  144. }]);
  145.  
  146. app.config(function ($routeProvider) {
  147. $routeProvider.when('/ShowFAQs', {
  148. templateUrl: 'HtmlTemplates/ShowFAQs.html',
  149. controller: 'FAQController',
  150. controllerAs: 'fc'
  151.  
  152. })
  153. .when('/CreateFAQ', {
  154. templateUrl: 'HtmlTemplates/CreateFAQ.html',
  155. controller: 'FAQController',
  156. controllerAs: 'fc'
  157. })
  158. .when('/Registration', {
  159. templateUrl: 'HtmlTemplates/Registration.html',
  160. controller: 'SignInController',
  161. controllerAs: 'fc'
  162. })
  163. .when('/SignIn', {
  164. templateUrl: 'HtmlTemplates/SignIn.html',
  165. controller: 'SignInController',
  166. controllerAs: 'fc'
  167. })
  168. .when('/', {
  169. templateUrl: 'HtmlTemplates/SignIn.html',
  170. controller: 'SignInController',
  171. controllerAs: 'fc'
  172. })
  173. .otherwise({
  174. redirectTo: '/'});
  175.  
  176. });
  177. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement