Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- act: (context, f, keyPaths...) ->
- ok = true
- for k in keyPaths
- if !context.get(k)?
- ok = false
- context.observe k, (newValue, oldValue, keyPath) =>
- ok = true
- for k in keyPaths
- ok = context.get(k)?
- return unless ok
- f.apply(context) if ok
- f.apply(context) if ok
- setupCalendar: ->
- @set '$', App.stateManager
- @act @, @getCalendar, '$.user.grade', '$.user.program'
- getCalendar: ->
- _grade = App.stateManager.get('user.grade')
- _program = App.stateManager.get('user.program')
- console.log 'getCalendar', _grade, _program
- App.CouchStorage.view 'calendar', {key: ["#{_grade}", "#{_program}", App.Calendar.unit(_program)]}, (err, results) ->
- if err?
- throw err
- if !results?.length
- alert 'Creating new calendar document'
- App.calendar = new App.Calendar
- setTimeout (=> App.calendar.save()), 1000
- App.fire 'calendar_ready'
- else
- App.calendar = results.toArray()[0]
- console.log 'Calendar pre-existed', App.calendar.get('id')
- App.fire 'calendar_ready'
Add Comment
Please, Sign In to add comment