meteoric / meteor-ionic

Ionic components for Meteor. No Angular!
http://meteoric.github.io
MIT License
1.51k stars 219 forks source link

Errors after adding a subFooter #337

Closed jerocosio closed 8 years ago

jerocosio commented 8 years ago

Hi, I am having trouble on my app, everything works fine, but when I add a sub-footer dinamically with a variable I start getting this errors, any idea what may be the cause of this?

Exception from Tracker recompute function:
debug.js:41 TypeError: Cannot read property 'removeClass' of null
debug.js:41 Exception from Tracker recompute function:
debug.js:41 TypeError: Cannot read property 'removeClass' of null
debug.js:41 Exception in setTimeout callback: Error: Expected template rendered with Blaze.render
    at Object.Blaze.remove (http://localhost:3000/packages/blaze.js?9391df93ba5076c2cfc61ee68724eb79b65f00d9:2352:11)
    at Object.<anonymous> (http://localhost:3000/packages/meteoric_ionic.js?0d5f3c45dbd8d07e3d31ddeb3ab440279c0ec17f:4079:15)
    at _.extend.withValue (http://localhost:3000/packages/meteor.js?9730f4ff059088b3f7f14c0672d155218a1802d4:971:17)
    at http://localhost:3000/packages/meteor.js?9730f4ff059088b3f7f14c0672d155218a1802d4:428:45
    at http://localhost:3000/packages/meteor.js?9730f4ff059088b3f7f14c0672d155218a1802d4:999:22
jerocosio commented 8 years ago

Actually after reviewing my code this error appears after I open and close a modal and move to another route... Sorry about that, but the error is still there, the code for the modal is a little large but here it is, maybe someone can help me find where the error might be:

<template name="_producto">
{{#ionModal customTemplate=true}}
      <div class="bar bar-header bar-stable">
        <h2 class="title">{{#with producto}}{{nombre}}{{/with}}</h2>
        <button data-dismiss="modal" class="button button-icon"><i class="icon ion-ios-close-empty"></i></button>
      </div>
      <div class="content has-header has-footer overflow-scroll">
          {{#with producto}}
            <img src="{{imagen}}" class="imagenDetalleProducto">
          {{tituloNav}}
          <div class="row infoProductoRow">
            <div class="col col-67">{{nombre}}</div>
            <div class="col col-center infoProductoPrecio">{{formatoDinero precio}}</div>
          </div>
          <div class="row infoProductoContador">
            <div class="col col-33 contadorMenos">-</div>
            <div class="col ">{{ contadorProducto }}</div>
            <div class="col contadorMas">+</div>
          </div>
          <div class="row infoProductoTamano">
            <div class="col col-50 textoTamano">Tamaño: </div>
            <div class="col tamanoProducto">{{tamano}}</div>
          </div>
          <div class="descripcionDetalleProducto">{{descripcion}}</div>
            {{/with}}
          </div>
        {{#ionFooterBar class="bar-balanced botonAgregarProducto"}}
      {{#with producto}}
      <h1 class="title" id="botonProducto" data-id="{{_id}}">AGREGAR {{ contadorProducto }} AL CARRITO</h1>
      {{/with}}
   {{/ionFooterBar}}
  {{/ionModal}}
</template>
Template._producto.helpers({
  contadorProducto: function () {
    return Session.get("contadorProducto");
  },
  producto: function () {
    var template = Template.instance();
    return Productos.findOne({_id: template.data.id});
  }
});

Template._producto.rendered = function () {
  Session.set("contadorProducto", 1);
  var diaActual = moment().isoWeekday();
  var horaActual = moment().hour();
  var minutoActual = moment().minute();
  var configuracion = Configuracion.findOne({});

  if(configuracion){
    var horariosOperacion = configuracion.horariosOperacion;
  }

  var horariosOperacionHoy = _.filter(horariosOperacion,
    function(horario){
      return horario.dia == diaActual;
    });

    var horarios = [];

    _.each(horariosOperacionHoy, function(horario){
      var valoresHoraEmpieza = horario.horaEmpieza.split(':');
      var valoresHoraTermina = horario.horaTermina.split(':');
      var horaEmpieza = moment().set({'hour': valoresHoraEmpieza[0], 'minute': valoresHoraEmpieza[1],'second':0});
      horaEmpieza.subtract(1,'minute');
      var horaTermina = moment().set({'hour': valoresHoraTermina[0], 'minute': valoresHoraTermina[1],'second':0});
      horaTermina.add(1,'minute');
      horarios.push({
        empieza: horaEmpieza,
        termina: horaTermina
      });
    });

    var horarioAbierto = _.find(horarios, function(horario){
      return moment().isBetween(horario.empieza, horario.termina);
    });

    if(horarioAbierto){
      Session.set('abiertoOCerrado','abierto')
    }else{
      Session.set('abiertoOCerrado','cerrado')
    }
};

Template._producto.events({
  'click .contadorMenos': function () {
    if(Session.get("contadorProducto") <= 1){
      Session.set("contadorProducto", 1);
    }else{
      Session.set("contadorProducto", Session.get("contadorProducto") - 1);
    }
  },
  'click .contadorMas': function () {
    Session.set("contadorProducto", Session.get("contadorProducto") + 1);
  },
  'click .botonAgregarProducto': function () {
    Session.set('agregandoProducto',true);
    IonModal.close();
    //IonLoading.show();
    if(Session.get('abiertoOCerrado')=='cerrado'){
      //IonLoading.hide();
      IonModal.close();
      Session.set('agregandoProducto',false);
      swal('','VNO se encuentra cerrado por el momento, por favor vuelve más tarde.','info');
    }else{
      var template = Template.instance();
      var idProducto = template.data.id;
      var cantidadProducto = Session.get("contadorProducto");
      var carrito = CarritoUsuario.findOne({idUsuario: Meteor.userId()});
      var idCedis = carrito.idCedis;
      //Checamos si hay suficientes productos
      var producto = Productos.findOne({
        _id: idProducto,
        stock: { $elemMatch: { idCedis: idCedis, cantidad: { $gte: cantidadProducto } } }
      });

      if(producto === undefined || producto.length == 0){
        //IonLoading.hide();
        IonModal.close();
        Session.set('agregandoProducto',false);
        swal({   title: "Poco stock",   text: "Selecciona menos cantidad de este producto y vuelve a intentarlo.",   timer: 2000,   showConfirmButton: false, type:"warning" });
      }else{
        Meteor.call("agregarProductos", idProducto, cantidadProducto, idCedis, function(err,res){
          if(!err){
            swal({
              title: "Producto agregado",
              text: "Agregamos tu(s) producto(s) al carrito.",
              timer: 1500,
              showConfirmButton: false,
              closeOnCancel: true,
              closeOnConfirm: true,
              type:"success"
            });
            //IonLoading.hide();
            IonModal.close();
            Session.set('agregandoProducto',false);
            setTimeout(
              function(){
                $('.barraAbajoOrden').addClass('animated tada');
                $('.barraAbajoOrden').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(){
                  if($('.barraAbajoOrden').hasClass('animated')){
                    //$('.barraAbajoOrden').removeClass('animated tada');
                  }
                });
              },
              2000);
            }else{
              //IonLoading.hide();
              IonModal.close();
              Session.set('agregandoProducto',false);
              swal({   title: "No pudimos agregar el producto al carrito",   text: "Por favor vuelve a intentarlo.",   timer: 2000,   showConfirmButton: false, type:"error" });
            }
          });
        }
    }

    }
  });