var BlogView = View.extend({ data: null, loaded: false, us_states: $("#us_states").html(), ca_states: $("#ca_states").html(), initialize: function(){ this.loader = new Loader () }, fetch: function(fn){ $.ajax({ method: "GET", url: sdk.env === 'test' ? '/db.json' : sdk.cms() + '/db.json', // url: "https://stone.giraffe.life/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 // sdk.env = 'test' if (sdk.env === 'test') { app.store = data.store[1] } else { app.store = data.store[0] } switch (app.store.DepartmentStoreStatus) { case "open": app.closed.storeIsClosed = false break case "closed": app.closed.storeIsClosed = true app.closed.storeClosedMessageOne = app.store.StoreClosedMessageOne app.closed.storeClosedMessageTwo = app.store.StoreClosedMessageTwo break } console.log(data) if (app.closed.storeIsClosed && sdk.env !== 'test') { app.closed.populate(app.store.ClosedStoreImages) } else { app.departments = app.store.Departments app.department_id = app.store.Departments[0].uri $("#collections h1").toggleClass("single-dept", app.store.Departments.length == 1) app.collection.setCollectionName( app.store.Departments[0].text ) //// demo department for shoes with weird SizeTypeId // app.department_id = "NKDrtSC" if (sdk.env === 'test') { app.department_id = window.location.search.substr(1) || app.department_id console.log('using test department id', app.department_id) // app.department_id = 'TSTSZS' } 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] && app[page.tag].populate(page) }) console.log(app.store.StoreStatus) app.product.fitLargeCodes = {} if (app.store.FittingCodes.length) { app.store.FittingCodes.split("\n").forEach(function(code){ app.product.fitLargeCodes[code] = true }) } if (app.store.BackgroundIsGray === "true") { app.collection.$el.addClass("gray") app.product.gallery.$el.addClass("gray") } var states = this.us_states if (! app.store.NotAvailableInCanada) { states += this.ca_states } $('[name=Province]').html(states) }, })