summaryrefslogtreecommitdiff
path: root/StoneIsland/platforms/ios/www/js/lib/_router.js
blob: 91f29b55c9b60cb84e8973c5f2a6bdd828175f20 (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
var SiteRouter = Router.extend({

	el: 'body',
	routeByHash: true,
	
	routes: {
		'/':                   'intro',
		'/intro':              'intro',
    '/hub':                'hub',
    '/story':              'story',
    '/archive':            'archive',

    '/store':              'collection',
    '/store/closed':       'closed',
    '/store/:code':        'product',

    '/account/login':      'login',
    '/account/logout':     'logout',
    '/account/signup':     'signup',
    '/account/profile':    'profile',
    '/account/payment':    'payment',
    '/account/shipping':   'shipping',
    '/account/orders':     'orders',
    '/account/settings':   'settings',

    '/page/terms':         'terms',
    '/page/account_terms': 'account_terms',
    '/page/privacy':       'privacy',
    '/page/returns':       'returns',
    '/page/care':          'care',
    
    '/search':             'search',

    '/cart':               'cart.summary',
    '/cart/summary':       'cart.summary',
    '/cart/payment':       'cart.payment',
    '/cart/shipping':      'cart.shipping',
    '/cart/confirm':       'cart.confirm',
    '/cart/thanks':        'cart.thanks',
    '/cart/error':         'cart.error',
	},

  terms_routes: ['terms','account_terms','privacy','returns','care','logout'],

	initialize: function(){
	  var fn
    for (var route in this.routes) {
      fn = this.routes[route]
      if (! this[fn]) {
        this[fn] = this.default_view(fn)
      }
    }
	},
	
  initial_route: null,
	launch: function(){
    console.log("LAUNCH!")
	  if (this.initial_route) {
      this.parseRoute( this.initial_route )
	  }
	  else {
      this.route()
	  }
	  this.initial_route = null

    app.finished_launching()
	},

  go: function(url){
    if (app.view && app.view.hide) {
      app.view.hide()
    }
    window.location.href = "#/" + url
    this.parseRoute(url)
  },
  
  default_view: function(name){
    var fn = function(){
      console.log(name)
      var n = [name]
      if (app.view != app.login && app.view != app.signin) {
        app.last_view = app.view
      }
      if (app.view && app.view.hide) {
        app.view.hide()
      }
      if (name.match(/\./)) {
        n = name.split(".")
        console.log(name, n)
        app.view = app[n[0]][n[1]]
      }
      else {
        app.view = app[name]
      }

      // window.FirebasePlugin && window.FirebasePlugin.setScreenName(name)
      console.log("view >>", app.view)
      app.header.set_back( !! app.view.back )
      app.view.show()

      // var isTermsRoute = this.terms_routes.indexOf(name) !== -1
      // var isCartRoute = n[0] === 'cart'
      // if ( (isCartRoute || app.demand_consent && !isTermsRoute) && app.account.consent.check()) {
      //   console.log('showed consent modal')
      //   return
      // }

      var isTermsRoute = this.terms_routes.indexOf(name) !== -1
      if (app.demand_consent && !isTermsRoute && app.account.consent.check()) {
        console.log('showed consent modal')
        return
      }
    }.bind(this)
    return fn
  },

	product: function(code){
    if (app.view && app.view.hide) {
      app.view.hide()
    }
	  app.view = app.product
    app.header.set_back( true )
	  app.product.load(code)
	  app.product.show()
	},

})