summaryrefslogtreecommitdiff
path: root/StoneIsland/platforms/ios/www/js/lib/account/ConsentModal.js
blob: c9235498bb5fddedf222427eceaf8ef4611b3846 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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")
  },

})