add missing js files

This commit is contained in:
did 2011-11-28 13:50:24 -08:00
parent 4a2ae180a9
commit 6505b7ab25
2 changed files with 82 additions and 0 deletions

View File

@ -0,0 +1,25 @@
Locomotive.Views.CurrentSite ||= {}
class Locomotive.Views.Site.DomainEntryView extends Backbone.View
tagName: 'li'
className: 'domain'
events:
'change input[type=text]' : 'change'
'click a.remove': 'remove'
render: ->
$(@el).html(ich.domain_entry(@model.toJSON()))
return @
change: (event) ->
value = $(event.target).val()
@options.parent_view.change_entry(@model, value)
remove: (event) ->
event.stopPropagation() & event.preventDefault()
@options.parent_view.remove_entry(@model)
super()

View File

@ -0,0 +1,57 @@
Locomotive.Views.Site ||= {}
class Locomotive.Views.Site.DomainsView extends Backbone.View
tagName: 'div'
className: 'list'
_entry_views = []
events:
'click .new-entry a.add': 'add_entry'
render: ->
$(@el).html(ich.domains_list(@model.toJSON()))
@render_entries()
return @
add_entry: (event) ->
event.stopPropagation() & event.preventDefault()
input = @$('.new-entry input[name=domain]')
if input.val() != ''
domain = new Locomotive.Models.Domain name: input.val()
@model.get('domains').push(domain)
@_insert_entry(domain)
input.val('') # reset for further entries
change_entry: (domain, value) ->
domain.set name: value
remove_entry: (domain) ->
list = _.reject @model.get('domains'), (_domain) => _domain == domain
@model.set domains: list
render_entries: ->
_.each @model.get('domains'), (domain) =>
_.each @options.errors.domain || [], (message) =>
domain.error = message if message.test /^#{domain.get('name')} /
@_insert_entry(domain)
_insert_entry: (domain) ->
view = new Locomotive.Views.Site.DomainEntryView model: domain, parent_view: @
(@_entry_views ||= []).push(view)
@$('ul').append(view.render().el)