Skip to content

Instantly share code, notes, and snippets.

@dagda1
Created July 1, 2011 08:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dagda1/1058112 to your computer and use it in GitHub Desktop.
Save dagda1/1058112 to your computer and use it in GitHub Desktop.
backbone.coffeescript
class Observation extends Backbone.Model
class Observations extends Backbone.Collection
model: Observation
constructor: ->
@url = _observationsUrl
class ObservationView extends Backbone.View
initialize: ->
_.bindAll @
#@template = app.templates["observation"]
render: =>
@el = $('#observation').tmpl(@model)
@
class ObservationsView extends Backbone.View
initialize: ->
_.bindAll @
that = @
@collection.bind 'refresh', @collectionRefreshed
@collection.bind 'add', @elementAdded
@collection.view = @
getRequest = $.getJSON(@collection.url)
getRequest.complete(stopWorking())
getRequest.success (data) ->
that.collection.refresh(data)
events:
'click': "closeObservationButton",
'click #newObservation': "showNewObservation"
showNewObservation: =>
showFloatingDialog('newObservationDiv')
closeObservationButton: =>
hideFloatingDialog('newObservationDiv')
collectionRefreshed: (collection) =>
self = @
if(collection.length == 0)
return
@el.empty()
@collection.each (item) ->
self._renderItem(item)
$('.iconNewRecommendation').click ->
observationuid = $(@).parent().parent().data('uid')
$('#dv_error1').html('');
$('#hiddenobservationuid').val(observationuid);
$('#recommendation').focus()
showFloatingDialog('NewRecommendationDiv')
_renderItem: (item) =>
@el.prepend(new ObservationView(model: item.attributes).render().el)
elementAdded: (item) =>
alert('added')
class ObservationsController extends Backbone.Controller
initialize: ->
observations = new Observations()
observationsView = new ObservationsView(collection: observations, el: $("#observations, #newObservationDiv, #Question"))
#newObservationView = new NewObservationView(el: $('#newObservationDiv'))
class App
init: ->
@Views = {}
@Collections = {}
@Controllers = {}
#@templates = Utils.loadTemplates()
@Controllers.Main = new ObservationsController()
$ ->
window.app = new App()
window.app.init()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment