var CollectionView = ScrollableView.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', app.iscroll_options) }, show: function(){ document.body.className = "collection" if (this.loaded) { return this.populate(this.data) } this.fetch() }, fetch: function(){ if (this.loaded) return this.$loader.show() sdk.product.collection({ gallery_id: 32780, success: this.populate.bind(this) }) }, populate: function(data){ if (this.loaded && ! data) { data = this.data } else { this.data = data } this.loaded = true this.$loader.hide() this.$content.empty() // DefaultCode10 data.SearchResponseFull.Results.Items.forEach(function(item){ this.items[ item['Code8'] ] = item var t = this.template.replace(/{{image}}/, sdk.image(item['DefaultCode10'], '11_f')) .replace(/{{code8}}/, item['Code8']) this.$content.append(t) }.bind(this)) this.deferScrollToTop() this.afterFetchCallback && this.afterFetchCallback() }, pick: function(e){ var code = $(e.currentTarget).data("code") var data = this.items[code] app.product.load(code, data) }, })