rename namespace for the sites backbone views + create backbone view for the creation of a new site

This commit is contained in:
did 2011-12-02 06:59:41 -08:00
parent fb0e87c64d
commit 87a04aafe9
12 changed files with 105 additions and 45 deletions

View File

@ -27,12 +27,12 @@ class Locomotive.Views.CurrentSite.EditView extends Locomotive.Views.Shared.Form
@enable_liquid_editing()
render_domains: ->
@domains_view = new Locomotive.Views.Site.DomainsView model: @model, errors: @options.errors
@domains_view = new Locomotive.Views.Sites.DomainsView model: @model, errors: @options.errors
@$('#site_domains_input label').after(@domains_view.render().el)
render_memberships: ->
@memberships_view = new Locomotive.Views.Site.MembershipsView model: @model
@memberships_view = new Locomotive.Views.Sites.MembershipsView model: @model
@$('#site_memberships_input').append(@memberships_view.render().el)

View File

@ -29,6 +29,9 @@ class Locomotive.Views.Shared.FormView extends Backbone.View
@model.save {},
success: (model, response, xhr) =>
console.log(response)
console.log(xhr)
$.growl('success', xhr.getResponseHeader('X-Message'))
model.attributes = previous_attributes
@ -38,6 +41,8 @@ class Locomotive.Views.Shared.FormView extends Backbone.View
error: (model, xhr) =>
$.growl('error', xhr.getResponseHeader('X-Message'))
console.log(xhr)
errors = JSON.parse(xhr.responseText)
@show_errors errors

View File

@ -1,6 +1,6 @@
Locomotive.Views.Site ||= {}
Locomotive.Views.Sites ||= {}
class Locomotive.Views.Site.DomainEntryView extends Backbone.View
class Locomotive.Views.Sites.DomainEntryView extends Backbone.View
tagName: 'li'

View File

@ -1,6 +1,6 @@
Locomotive.Views.Site ||= {}
Locomotive.Views.Sites ||= {}
class Locomotive.Views.Site.DomainsView extends Backbone.View
class Locomotive.Views.Sites.DomainsView extends Backbone.View
tagName: 'div'
@ -72,7 +72,7 @@ class Locomotive.Views.Site.DomainsView extends Backbone.View
@$('.domain input[type=text]').editableField()
_insert_entry: (domain) ->
view = new Locomotive.Views.Site.DomainEntryView model: domain, parent_view: @
view = new Locomotive.Views.Sites.DomainEntryView model: domain, parent_view: @
(@_entry_views ||= []).push(view)

View File

@ -1,6 +1,6 @@
Locomotive.Views.Site ||= {}
Locomotive.Views.Sites ||= {}
class Locomotive.Views.Site.MembershipEntryView extends Backbone.View
class Locomotive.Views.Sites.MembershipEntryView extends Backbone.View
className: 'entry'

View File

@ -1,6 +1,6 @@
Locomotive.Views.Site ||= {}
Locomotive.Views.Sites ||= {}
class Locomotive.Views.Site.MembershipsView extends Backbone.View
class Locomotive.Views.Sites.MembershipsView extends Backbone.View
tagName: 'div'
@ -29,7 +29,7 @@ class Locomotive.Views.Site.MembershipsView extends Backbone.View
@$('.entry select').editableField()
_insert_entry: (membership, index) ->
view = new Locomotive.Views.Site.MembershipEntryView model: membership, parent_view: @, index: index
view = new Locomotive.Views.Sites.MembershipEntryView model: membership, parent_view: @, index: index
(@_entry_views ||= []).push(view)

View File

@ -0,0 +1,43 @@
#= require ../shared/form_view
#= require ../sites/domains_view
Locomotive.Views.Sites ||= {}
class Locomotive.Views.Sites.NewView extends Locomotive.Views.Shared.FormView
el: '#content'
events:
'submit': 'save'
initialize: ->
@model = new Locomotive.Models.Site()
Backbone.ModelBinding.bind @
window.foo = @model
render: ->
super()
@render_domains()
render_domains: ->
@domains_view = new Locomotive.Views.Sites.DomainsView model: @model, errors: @options.errors
@$('#site_domains_input label').after(@domains_view.render().el)
save: (event) ->
@save_in_ajax(event)
show_error: (attribute, message, html) ->
if attribute == 'domains'
@domains_view.show_error(message)
else
super
remove: ->
@domains_view.remove()
super

View File

@ -3,6 +3,8 @@ module Locomotive
sections 'settings'
respond_to :json, :only => [:create]
def new
@site = Site.new
respond_with @site

View File

@ -6,8 +6,8 @@
:plain
{ site: #{@site.to_json(:current_account => current_locomotive_account, :current_site => current_site)}, errors: #{@site.errors.to_json} }
= f.inputs :name => :information, :style => "#{'display: none' unless @site.new_record?}" do
= f.input :name, :required => false
= f.inputs :name => :information, :style => 'display: none' do
= f.input :name
= f.inputs :name => :seo, :class => "inputs foldable #{'folded' if inputs_folded?(@site)}" do
= f.input :seo_title

View File

@ -1,37 +1,45 @@
- content_for :head do
= include_javascripts :site
= render 'locomotive/sites/domains'
= f.foldable_inputs :name => :information, :style => "#{'display: none' unless @site.new_record?}" do
= f.input :name, :required => false
= f.inputs :name => :information do
= f.input :name
- if manage_subdomain_or_domains?
= f.foldable_inputs :name => :access_points, :class => 'editable-list off' do
= f.custom_input :subdomain, :css => 'path' do
%em
http://
= f.text_field :subdomain
\.
%em
= application_domain
= f.inputs :name => :access_points do
= f.input :subdomain, :as => :'Locomotive::Subdomain', :domain => application_domain, :input_html => { :readonly => !manage_subdomain? }
- if manage_domains?
- @site.domains_without_subdomain.each_with_index do |name, index|
%li{ :class => "item added #{'last' if index == @site.domains.size - 1}" }
%em
http://
= text_field_tag 'site[domains][]', name, :class => 'string label void domain'
 
= error_on_domain(@site, name)
%span.actions
= link_to image_tag('admin/form/icons/trash.png'), '#', :class => 'remove first', :confirm => t('locomotive.messages.confirm')
= f.input :domains, :as => :'Locomotive::Empty'
%li.item.template
%em
http://
= text_field_tag 'label', t('formtastic.hints.site.domain_name'), :class => 'string label void domain'
 
%span.actions
= link_to image_tag('admin/form/icons/trash.png'), '#', :class => 'remove first', :confirm => t('locomotive.messages.confirm')
%button{ :class => 'button light add', :type => 'button' }
%span!= t('locomotive.buttons.new_item')
/ - if manage_subdomain_or_domains?
/ = f.foldable_inputs :name => :access_points, :class => 'editable-list off' do
/
/ = f.custom_input :subdomain, :css => 'path' do
/ %em
/ http://
/ = f.text_field :subdomain
/ \.
/ %em
/ = application_domain
/
/ - if manage_domains?
/ - @site.domains_without_subdomain.each_with_index do |name, index|
/ %li{ :class => "item added #{'last' if index == @site.domains.size - 1}" }
/ %em
/ http://
/ = text_field_tag 'site[domains][]', name, :class => 'string label void domain'
/  
/ = error_on_domain(@site, name)
/ %span.actions
/ = link_to image_tag('admin/form/icons/trash.png'), '#', :class => 'remove first', :confirm => t('locomotive.messages.confirm')
/
/ %li.item.template
/ %em
/ http://
/ = text_field_tag 'label', t('formtastic.hints.site.domain_name'), :class => 'string label void domain'
/  
/ %span.actions
/ = link_to image_tag('admin/form/icons/trash.png'), '#', :class => 'remove first', :confirm => t('locomotive.messages.confirm')
/ %button{ :class => 'button light add', :type => 'button' }
/ %span!= t('locomotive.buttons.new_item')

View File

@ -21,8 +21,9 @@ x edit my site
x roles
x save
- fix other sections
- edit my account
x edit my account
- create a new site
- create a new account
- theme assets
- content types

View File

@ -9,6 +9,7 @@ module Locomotive
end
def to_json
Rails.logger.debug "TO JSON !!!!"
if get?
display resource
elsif has_errors?