summaryrefslogtreecommitdiff
path: root/StoneIsland/www/js/lib/products/CollectionView.js
blob: 987804fc86c3c45b5a4ffdeb60ed30bd9cdad46b (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
var CollectionView = View.extend({
  
  el: "#collection",
  template: $("#collection .template").html(),
  loaded: false,
  data: null,
  items: {},

  events: {
    "click .item": "pick",
  },
  
  initialize: function(){
    this.$content = this.$(".content")
    this.$loader = this.$(".loader")
    this.scroller = new IScroll('#collection .scroll')
  },

  show: function(){
    document.body.className = "collection"
    if (this.loaded) {
      return this.populate(this.data)
    }
    this.fetch()
  },
  
  fetch: function(){
    this.$loader.show()
    sdk.product.collection({
      gallery_id: 31617,
      success: this.populate.bind(this)
    })
  },

  populate: function(data){
    this.$loader.hide()
    this.$content.empty()
    // DefaultCode10
    console.log(data)
    data.SearchResponseFull.Results.Items.forEach(function(item){
      this.items[ item['Code8'] ] = item
      var t = this.template.replace(/{{image}}/, sdk.image(item['DefaultCode10']))
                           .replace(/{{code8}}/, item['Code8'])
      this.$content.append(t)
      
    }.bind(this))
  },
  
  pick: function(e){
    var code = $(e.currentTarget).data("code")
    var data = this.items[code]
    app.product.load(data)
  },

})