2011-11-10 01:43:19 +00:00
|
|
|
class Locomotive.Models.Site extends Backbone.Model
|
2011-11-27 16:22:54 +00:00
|
|
|
|
2011-11-29 13:58:19 +00:00
|
|
|
paramRoot: 'site'
|
2011-11-27 16:22:54 +00:00
|
|
|
|
2012-01-14 13:54:01 +00:00
|
|
|
urlRoot: "#{Locomotive.mounted_on}/sites"
|
2011-11-27 16:22:54 +00:00
|
|
|
|
|
|
|
initialize: ->
|
|
|
|
# Be careful, domains_without_subdomain becomes domains
|
|
|
|
domains = _.map @get('domains_without_subdomain'), (name) =>
|
|
|
|
new Locomotive.Models.Domain(name: name)
|
|
|
|
|
2011-11-29 13:58:19 +00:00
|
|
|
memberships = new Locomotive.Models.MembershipsCollection(@get('memberships'))
|
|
|
|
|
|
|
|
@set domains: domains, memberships: memberships
|
|
|
|
|
|
|
|
includes_domain: (name) ->
|
|
|
|
name == @domain_with_domain() || _.any(@get('domains'), (domain) -> domain.get('name') == name)
|
|
|
|
|
|
|
|
domain_with_domain: ->
|
|
|
|
"#{@get('subdomain')}.#{@get('domain_name')}"
|
|
|
|
|
|
|
|
toJSON: ->
|
|
|
|
_.tap super, (hash) =>
|
2012-02-01 14:15:20 +00:00
|
|
|
delete hash.memberships
|
|
|
|
hash.memberships_attributes = @get('memberships').toJSONForSave() if @get('memberships')? && @get('memberships').length > 0
|
2012-02-09 10:36:10 +00:00
|
|
|
delete hash.domains
|
2012-04-02 13:11:30 +00:00
|
|
|
hash.domains = _.map(@get('domains'), (domain) -> domain.get('name'))
|
2011-11-27 16:22:54 +00:00
|
|
|
|
|
|
|
class Locomotive.Models.CurrentSite extends Locomotive.Models.Site
|
|
|
|
|
2012-01-14 13:54:01 +00:00
|
|
|
url: "#{Locomotive.mounted_on}/current_site"
|
2011-11-27 16:22:54 +00:00
|
|
|
|
|
|
|
|