Skip to content

Instantly share code, notes, and snippets.

@abigoroth
Created April 21, 2012 05:07
Show Gist options
  • Save abigoroth/2434185 to your computer and use it in GitHub Desktop.
Save abigoroth/2434185 to your computer and use it in GitHub Desktop.
class Dnscell.Collections.Domains extends Backbone.Collection
url: "/api/zones"
model: Dnscell.Models.Domain
class Dnscell.Routers.Domains extends Backbone.Router
routes: {
'dns_management/domains/': 'index'
'dns_management/domains': 'index'
'hosts/:id': 'hosts'
'dns_management/domains/:id': 'show_zone'
}
# initialize: ->
# @collection = new Dnscell.Collections.Domains()
# index: ->
# #view = new Dnscell.Views.DomainsIndex(collection: @collection)
# #view.render()
# @collection.fetch({
# success: ->
# view = new Dnscell.Views.DomainsIndex(collection: @collection)
# view.render()
# })
initialize: (id) ->
@collection = new Dnscell.Collections.Domains()
@collection.fetch({
success: =>
@render_sidebar()
# I can use @collection.at(0) here
})
index: =>
console.log @collection.at(0) # but it is undefine here
#Backbone.history.navigate("dns_management/domains/#{@collection.at(0).get('combine')}".replace(/\./g, '_') , true)
hosts: (id) ->
show_zone: (id) ->
@render_sidebar(id)
#console.log "#domain_#{@collection.at(0).get('id')}"
#@collection.fetch({
# success: =>
# #alert collection.length
# $('#domains').html("")
# view = new Dnscell.Views.DomainsIndex(collection: @collection)
# view.render()
#})
hosts = new Backbone.Collection;
hosts.url = "/api/hosts/#{id}/hosts"
hosts.fetch({
success: =>
hostsView = new Dnscell.Views.Hosts(collection: hosts)
hostsView.render()
error: ->
# alert 'ko'
$('.host_list').html('<td>No host(s)</td>')
})
render_sidebar: =>
$('#domains').html("")
view = new Dnscell.Views.DomainsIndex(collection: @collection)
view.render()
$("a[href='#{@id}']").parent().addClass('current')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment