Guest User

Untitled

a guest
Apr 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. // create the module and name it scotchApp
  2. var scotchApp = angular.module('scotchApp', ['ngRoute']);
  3.  
  4. // configure our routes
  5. scotchApp.config(function($routeProvider) {
  6. $routeProvider
  7.  
  8. // route for the home page
  9. .when('/', {
  10. templateUrl : 'pages/home.html',
  11. controller : 'mainController'
  12. })
  13.  
  14. // route for the book page
  15. .when('/books', {
  16. templateUrl : 'pages/book.html',
  17. controller : 'booksController'
  18. })
  19.  
  20. // route for the client page
  21. .when('/books/:id', {
  22. templateUrl : 'pages/book.html',
  23. controller : 'booksController'
  24. })
  25.  
  26. .otherwise({ redirectTo : "/"});
  27. });
  28.  
  29. // create the controller and inject Angular's $scope
  30. scotchApp.controller('mainController', function($scope) {
  31. // create a message to display in our view
  32. $scope.message = 'Everyone come and see how good I look!';
  33. });
  34.  
  35. scotchApp.controller('booksController', function($scope,$http,$routeParams) {
  36. $http.get('script/list.php').then (function(response){$scope.datos = response.data.tasks;});
  37. // Add new task
  38. $scope.addTask = function () {
  39. var add = confirm('desear adicionar datos ?');
  40. if (add==true) {
  41. $http.post('script/create.php', {
  42. dato: $scope.dato
  43. })
  44. .then(function success(e) {
  45.  
  46. $scope.errors = [];
  47.  
  48. $scope.datos.push(e.data.dato);
  49.  
  50. }, function error(e) {
  51. $scope.errors = e.data.errors;
  52. });
  53. $scope.dato = {};
  54. $scope.edit = false;
  55. }
  56. };
  57.  
  58. $scope.editData = function(index){
  59. var edt = confirm('desea editar dato');
  60. if (edt==true) {
  61.  
  62. $scope.dato = $scope.datos[index];
  63. $scope.edit = true;
  64.  
  65. }
  66. };
  67.  
  68. // update the task
  69. $scope.updateTask = function () {
  70. var upd= confirm("estas seguro editar");
  71. if (upd==true) {
  72.  
  73.  
  74. $http.post('script/update.php', {
  75. dato: $scope.dato
  76. })
  77. .then(function success(e) {
  78. $scope.errors = [];
  79.  
  80. }, function error(e) {
  81. $scope.errors = e.data.errors;
  82.  
  83. });
  84. $scope.dato = {};
  85. $scope.edit = false;
  86. };
  87. }
  88.  
  89. // delete the task
  90. $scope.deletData = function (index) {
  91.  
  92. var conf = confirm("Estas seguro querer eliminar estos datos" + index );
  93.  
  94. if (conf == true) {
  95. $http.post('script/delete.php', {
  96. dato: $scope.datos[index]
  97. })
  98. .then(function success(e) {
  99.  
  100. $scope.errors = [];
  101. $scope.datos.splice(index, 1);
  102.  
  103.  
  104. }, function error(e) {
  105. $scope.errors = e.data.errors;
  106. });
  107.  
  108. }
  109. };
  110.  
  111. $scope.deleteData = function( nom ) {
  112. //alert (nom);
  113. if ( confirm("Seguro?") ) {
  114. $http.get('script/delete.php?dato='+ nom ).success(function(data){
  115. if( data.err !== undefined ){
  116. window.location = "#/books";
  117. return;
  118. }
  119. $scope.alumno = data;
  120. });
  121. }
  122. }
  123.  
  124.  
  125. });
  126.  
  127. scotchApp.controller('bookController', function($scope, $routeParams, $http) {
  128. var id = $routeParams.id;
  129.  
  130. $scope.myCallback = function (valueFromDirective) {
  131. console.log(valueFromDirective);
  132. };
  133.  
  134. $scope.alumno = {};
  135. });
Add Comment
Please, Sign In to add comment