From 6505b7ab25d1ce7f36ff7255d8c6b8b763e8a6b3 Mon Sep 17 00:00:00 2001 From: did Date: Mon, 28 Nov 2011 13:50:24 -0800 Subject: [PATCH] add missing js files --- .../views/sites/domain_entry_view.js.coffee | 25 ++++++++ .../views/sites/domains_view.js.coffee | 57 +++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 app/assets/javascripts/locomotive/views/sites/domain_entry_view.js.coffee create mode 100644 app/assets/javascripts/locomotive/views/sites/domains_view.js.coffee diff --git a/app/assets/javascripts/locomotive/views/sites/domain_entry_view.js.coffee b/app/assets/javascripts/locomotive/views/sites/domain_entry_view.js.coffee new file mode 100644 index 00000000..fdd4902e --- /dev/null +++ b/app/assets/javascripts/locomotive/views/sites/domain_entry_view.js.coffee @@ -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() \ No newline at end of file diff --git a/app/assets/javascripts/locomotive/views/sites/domains_view.js.coffee b/app/assets/javascripts/locomotive/views/sites/domains_view.js.coffee new file mode 100644 index 00000000..7849af75 --- /dev/null +++ b/app/assets/javascripts/locomotive/views/sites/domains_view.js.coffee @@ -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) + + +