luisruiz

servicioProblem

Nov 10th, 2015
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. HTML /////////////////////////////
  2.  
  3.  
  4. <div class="modal-footer">
  5. <div class="col-xs-4"> {{servicio.horaSelect.horaInicioFin.hora }}</div>
  6. <div class="col-xs-4"></div>
  7.  
  8. <div class="col-xs-4">
  9. </div>
  10.  
  11. </div>
  12.  
  13. //////////////////77
  14.  
  15.  
  16. .controller('modalNewCitaController', function ($scope, servicio) {
  17.  
  18. $scope.servicio = servicio;
  19.  
  20. })
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29. .factory('servicio', function ($rootScope) {
  30.  
  31. //esta haciendo el servicio para ver si me resultava ..
  32.  
  33. var nuevaCita = {};
  34. var horaSelect = [];
  35. var horaInicioFin ={};
  36.  
  37.  
  38.  
  39.  
  40. function activo(dia, hora, eventos) {
  41. var c = moment(dia).format('MM/DD/YYYY');
  42. var valor = false;
  43. angular.forEach(eventos, function (value, key) {
  44.  
  45. var fechaEv = moment(value.startsAt).format('MM/DD/YYYY');
  46. if (fechaEv === c) {
  47. var horaEv = moment(value.startsAt).format('HH:mm');
  48.  
  49. if (horaEv === hora.hora) {
  50. valor = true;
  51.  
  52. } else {
  53.  
  54. }
  55. }
  56.  
  57.  
  58. });
  59.  
  60. return valor;
  61. }
  62.  
  63. function select(dia,hora,$index) {
  64.  
  65. if(!hora.selected){
  66. hora.selected = true;
  67. hora.index = $index;
  68.  
  69.  
  70. horaSelect.push({
  71.  
  72. hora:hora.hora,
  73. fecha: moment(dia).format('MM/DD/YYYY')
  74.  
  75. }
  76. );
  77.  
  78. // var desde = moment([2010,10,10,8,00]);
  79. // var to = moment([2010,10,10,9,46]);
  80. // console.log(to.diff(desde, 'minute'));
  81.  
  82.  
  83. var inicio = horaSelect.sort(function(a, b){return a.hora.replace(':','') - b.hora.replace(':','')}) ;
  84.  
  85. var fin = horaSelect[horaSelect.length - 1];;
  86. var cadena = fin.hora.split(':');
  87. var finMenosUno = parseInt(cadena[1]) + 14;
  88.  
  89. horaSelect.horaInicioFin = {};
  90. horaSelect.horaInicioFin = {hora:inicio[0].hora + ' - ' +cadena[0]+':'+finMenosUno};
  91.  
  92.  
  93.  
  94. if(horaSelect.length > 0)
  95. {
  96. $rootScope.siguiente = true;
  97. }
  98.  
  99. }
  100. else
  101. {
  102. hora.selected = false;
  103. angular.forEach(horaSelect, function (value, key) {
  104. if(value.hora === hora.hora){
  105. horaSelect.splice(key, 1);
  106. }
  107. });
  108. if(horaSelect.length == 0){
  109.  
  110. $rootScope.siguiente = false;
  111. }
  112. }
  113. }
  114.  
  115.  
  116.  
  117. return {
  118. horaSelect : horaSelect,
  119. horaInicioFin:horaInicioFin,
  120.  
  121. Activo: activo,
  122. Select: select
  123. };
  124.  
  125.  
  126.  
  127. })
Advertisement
Add Comment
Please, Sign In to add comment