add missing js files
This commit is contained in:
parent
4a2ae180a9
commit
6505b7ab25
@ -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()
|
@ -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)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user