- . . localStorage, , , . , , .
App.PhotoCategories = Ember.Object.extend
init: ->
@_super()
@loadPhotoCategories
loadPhotoCategories: () ->
@set 'content', @getFromCache("photoCategories")
if @content?
if @content.length == 0
$.ajax
type: "POST"
url: "/api/getCategories"
success: (data) =>
if !data.error
@set 'content', []
for category in data
@pushObject category
@saveToCache("photoCategories", @content)
saveToCache: (key, data) ->
if @supportsHtml5Storage()
localStorage.setItem(key + '_LastUpdatedAt', new Date())
localStorage.setItem(key, JSON.stringify(data))
true
else
false
getFromCache: (key) ->
if @supportsHtml5Storage()
data = localStorage[key]
if data?
JSON.parse(localStorage[key])
else
null
else
null
supportsHtml5Storage: ->
try
return "localStorage" of window and window["localStorage"] isnt null
catch e
return false