mardi 13 septembre 2016

Ember template not reloading after i set cookie

I have a little problem. I have a "use-button" which sets a cookie, telling that this deal is used. The button switch state to disabled.

The problem is that, if you go back and forwards, the button is no longer disabled and you can still use the button. If you refresh the page the button will be disabled.

This is my code:

  actions: {
    markSwiped: function() {
      var cookies;
      if (confirm("Er du sikker?")){
        if (this.cookie.getCookie('gp_pv') === undefined){
          cookies = {};
        } else {
          cookies = JSON.parse(this.cookie.getCookie('gp_pv'));
        }
        var pack_id = this.get('goodie.packContents.firstObject.id');
        if (cookies[String(pack_id)] !== 1){
          cookies[String(pack_id)] = 1;
        }
        jQuery("#itemUsable").hide();
        jQuery("#itemUsed").show(); 

        this.get('tracker').trackGoodieExternalLinkClick(this.get('goodie'));       

        this.cookie.setCookie('gp_pv', JSON.stringify(cookies), { expires: 50000, path: '/' }); 

        this.container.lookup('view:toplevel').rerender();
        route.transitionTo("index")
      }      
    }



Aucun commentaire:

Enregistrer un commentaire