var ConsentModal = View.extend({ el: "#consent_modal", events: { "change [name=AccountTermsConsent]": "changeConsent", "click #consent_proceed": "proceed", "click #consent_logout": "logout", "click a": "navigate", }, initialize: function(){ this.$form = this.$(".form") this.$msg = this.$(".msg") this.$checkbox = this.$("[name=AccountTermsConsent]") this.$consentError = this.$("#consent_error") }, check: function(){ var status = localStorage.getItem('account_terms.consent') console.log('account_terms.consent', status) if (status !== 'true') { console.log('we demand consent!') app.demand_consent = true this.show() return true } else { console.log('already received consent!') this.hide() app.demand_consent = false return false } }, show: function(){ app.demand_consent = true this.$el.show() setTimeout(function(){ this.$el.addClass('visible') }.bind(this), 20) app.curtain.show('opaque') setTimeout(function(){ app.curtain.show('opaque') }, 300) }, hide: function(){ app.curtain.hide() this.$el.removeClass('visible') setTimeout(function(){ this.$el.hide() app.curtain.$el.removeClass('opaque') }.bind(this), 300) }, navigate: function(e){ var href = $(e.currentTarget).attr('href').replace('#', '') console.log(href) this.hide() app.router.go(href) }, changeConsent: function(){ var state = this.$checkbox.prop("checked") if (state) { this.$consentError.removeClass('visible') } else { this.$consentError.addClass('visible') } }, proceed: function(){ var state = this.$checkbox.prop("checked") if (!state) { this.$consentError.addClass('visible') return } app.demand_consent = false this.hide() localStorage.setItem('account_terms.consent', 'true') }, logout: function(){ app.demand_consent = false this.hide() localStorage.setItem('account_terms.consent', 'false') app.router.go("account/logout") }, })