summaryrefslogtreecommitdiff
path: root/StoneIsland/platforms/android/assets/www/js/lib/blogs/BlogView.js
blob: 5ee7f64119475a53fc06ff17b1850ecbca78a829 (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
var BlogView = View.extend({

  data: null,
  loaded: false,
  initialize: function(){
    this.loader = new Loader ()
  },
  
  fetch: function(fn){
    $.ajax({
      method: "GET",
//       url: sdk.env == 'test' ? '/db.json' : "https://stone.sup.land/db.json",
      url: "https://stone.sup.land/db.json",
      success: function(data){
        this.success(data)
        fn && fn()
      }.bind(this),
      cache: true,
    })
  },
  
  refresh: function(){
    this.loaded = false
    this.fetch()
  },
  
  success: function(data){

    if (this.loaded) return

    this.loaded = true
    this.data = data = typeof data == "string" ? JSON.parse(data) : data

    switch (data.store[0].DepartmentStoreStatus) {
      case "open":
        app.closed.storeIsClosed = false
        break
      case "closed":
        app.closed.storeIsClosed = true
        app.closed.storeClosedMessageOne = data.store[0].StoreClosedMessageOne
        app.closed.storeClosedMessageTwo = data.store[0].StoreClosedMessageTwo
        break
    }
    
    if (app.closed.storeIsClosed) {
      app.closed.populate(data.store[0].ClosedStoreImages)
    }
    else {
      app.departments = data.store[0].Departments
      app.department_id = data.store[0].Departments[0].uri
      app.collection.setCollectionName( data.store[0].Departments[0].text )
      app.collection.loaded = false
      app.collection.fetch()
    }

    app.archive.populate(data.archive)
    this.loader.preloadImage(data.hub[0].image[0].uri, function(img){
      app.hub.populate(data.hub)
    }.bind(this))
    this.loader.preloadImage(data.story[0].image.uri, function(img){
      app.story.populate(data.story)
      setTimeout(function(){
        this.loader.preloadImage(data.story[1].image.uri)
        this.loader.preloadImage(data.story[2].image.uri)
      }.bind(this), 2000)
    }.bind(this))

    data.page.forEach(function(page){
      app[page.tag].populate(page)
    })

    console.log(data.store[0].StoreStatus)

    app.product.fitLargeCodes = {}
    if (data.store[0].FittingCodes.length) {
      data.store[0].FittingCodes.split("\n").forEach(function(code){
        app.product.fitLargeCodes[code] = true
      })
    }
        
    if (data.store[0].BackgroundIsGray === "true") {
      app.collection.$el.addClass("gray")
      app.product.gallery.$el.addClass("gray")
    }
  },

})