Sha256: 4674d9b51104b8b4d29713aca38b0e9ac254e54a65df4124b09d0dd1ce79229b

Contents?: true

Size: 1.35 KB

Versions: 5

Compression:

Stored size: 1.35 KB

Contents

class Locomotive.Models.Site extends Backbone.Model

  paramRoot: 'site'

  urlRoot: "#{Locomotive.mounted_on}/sites"

  initialize: ->
    @_fix_attributes()

    # After save, need to fix the attributes again
    this.on 'sync', ->
      @_fix_attributes()

  includes_domain: (name_with_port) ->
    name = name_with_port.replace(/:[0-9]*/, '')
    name == @domain_with_domain() || _.any(@get('domains'), (domain) -> domain.get('name') == name)

  domain_with_domain: ->
    "#{@get('subdomain')}.#{@get('domain_name')}"

  toJSON: ->
    _.tap super, (hash) =>
      _.each ['locales_text'], (key) => delete hash[key]
      delete hash.memberships
      hash.memberships_attributes = @get('memberships').toJSONForSave() if @get('memberships')? && @get('memberships').length > 0
      delete hash.domains
      hash.domains = _.map(@get('domains'), (domain) -> domain.get('name'))
      hash.locales = _.flatten([@get('locales')])

  _fix_attributes: ->
    # Be careful, domains_without_subdomain becomes domains
    domains = _.map @get('domains_without_subdomain'), (name) =>
      new Locomotive.Models.Domain(name: name)

    memberships = new Locomotive.Models.MembershipsCollection(@get('memberships'))

    @set domains: domains, memberships: memberships


class Locomotive.Models.CurrentSite extends Locomotive.Models.Site

  url: "#{Locomotive.mounted_on}/current_site"


Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
locomotive_cms-2.1.4 app/assets/javascripts/locomotive/models/site.js.coffee
locomotive_cms-2.1.3 app/assets/javascripts/locomotive/models/site.js.coffee
locomotive_cms-2.1.2 app/assets/javascripts/locomotive/models/site.js.coffee
locomotive_cms-2.1.1 app/assets/javascripts/locomotive/models/site.js.coffee
locomotive_cms-2.1.0 app/assets/javascripts/locomotive/models/site.js.coffee