2011-11-25 14:10:56 +00:00
|
|
|
#= require ../shared/form_view
|
2011-11-27 16:22:54 +00:00
|
|
|
#= require ../sites/domains_view
|
2011-11-25 14:10:56 +00:00
|
|
|
|
|
|
|
Locomotive.Views.CurrentSite ||= {}
|
|
|
|
|
2011-11-27 16:22:54 +00:00
|
|
|
class Locomotive.Views.CurrentSite.EditView extends Locomotive.Views.Shared.FormView
|
|
|
|
|
|
|
|
el: '#content'
|
|
|
|
|
2011-11-29 01:24:02 +00:00
|
|
|
events:
|
2011-11-29 13:58:19 +00:00
|
|
|
'submit': 'save'
|
2011-11-29 01:24:02 +00:00
|
|
|
|
2011-11-27 16:22:54 +00:00
|
|
|
initialize: ->
|
|
|
|
@model = new Locomotive.Models.CurrentSite(@options.site)
|
|
|
|
|
2012-01-10 01:24:34 +00:00
|
|
|
Backbone.ModelBinding.bind @, checkbox: 'class'
|
2011-11-29 01:24:02 +00:00
|
|
|
|
2011-11-27 16:22:54 +00:00
|
|
|
window.foo = @model
|
|
|
|
|
|
|
|
render: ->
|
|
|
|
super()
|
|
|
|
|
2012-01-10 01:24:34 +00:00
|
|
|
@add_toggle_mode_for_locales()
|
|
|
|
|
|
|
|
@make_locales_sortable()
|
|
|
|
|
2011-11-29 13:58:19 +00:00
|
|
|
@render_domains()
|
2011-11-27 16:22:54 +00:00
|
|
|
|
2011-11-29 13:58:19 +00:00
|
|
|
@render_memberships()
|
2011-11-27 16:22:54 +00:00
|
|
|
|
2011-11-29 13:58:19 +00:00
|
|
|
@enable_liquid_editing()
|
2011-11-29 01:24:02 +00:00
|
|
|
|
2012-01-10 01:24:34 +00:00
|
|
|
add_toggle_mode_for_locales: ->
|
|
|
|
@$('#site_locales_input .list input[type=checkbox]').bind 'change', (event) ->
|
|
|
|
el = $(event.target)
|
|
|
|
if el.is(':checked')
|
|
|
|
el.closest('.entry').addClass('selected')
|
|
|
|
else
|
|
|
|
el.closest('.entry').removeClass('selected')
|
|
|
|
|
|
|
|
make_locales_sortable: ->
|
|
|
|
@sortable_locales_list = @$('#site_locales_input .list').sortable
|
|
|
|
items: '.entry'
|
|
|
|
tolerance: 'pointer'
|
|
|
|
update: =>
|
|
|
|
list = _.map @$('#site_locales_input .list input:checked'), (el) => $(el).val()
|
|
|
|
@model.set locales: list
|
|
|
|
|
2011-11-29 13:58:19 +00:00
|
|
|
render_domains: ->
|
2011-12-02 14:59:41 +00:00
|
|
|
@domains_view = new Locomotive.Views.Sites.DomainsView model: @model, errors: @options.errors
|
2011-11-27 16:22:54 +00:00
|
|
|
|
|
|
|
@$('#site_domains_input label').after(@domains_view.render().el)
|
|
|
|
|
2011-11-29 13:58:19 +00:00
|
|
|
render_memberships: ->
|
2011-12-02 14:59:41 +00:00
|
|
|
@memberships_view = new Locomotive.Views.Sites.MembershipsView model: @model
|
2011-11-29 13:58:19 +00:00
|
|
|
|
|
|
|
@$('#site_memberships_input').append(@memberships_view.render().el)
|
|
|
|
|
2011-11-27 16:22:54 +00:00
|
|
|
enable_liquid_editing: ->
|
2012-05-24 16:06:07 +00:00
|
|
|
if($('#site_robots_txt').length)
|
|
|
|
input = @$('#site_robots_txt')
|
|
|
|
@editor = CodeMirror.fromTextArea input.get()[0],
|
|
|
|
mode: 'liquid'
|
|
|
|
autoMatchParens: false
|
|
|
|
lineNumbers: false
|
|
|
|
passDelay: 50
|
|
|
|
tabMode: 'shift'
|
|
|
|
theme: 'default'
|
|
|
|
onChange: (editor) => @model.set(robots_txt: editor.getValue())
|
2011-11-27 16:22:54 +00:00
|
|
|
|
2011-11-29 13:58:19 +00:00
|
|
|
save: (event) ->
|
|
|
|
if @model.includes_domain(window.location.host)
|
|
|
|
@save_in_ajax(event)
|
|
|
|
|
|
|
|
show_error: (attribute, message, html) ->
|
|
|
|
if attribute == 'domains'
|
|
|
|
@domains_view.show_error(message)
|
|
|
|
else
|
|
|
|
super
|
2011-11-27 16:22:54 +00:00
|
|
|
|
2011-11-29 13:58:19 +00:00
|
|
|
remove: ->
|
|
|
|
@domains_view.remove()
|
|
|
|
@memberships_view.remove()
|
|
|
|
super
|
2011-11-27 16:22:54 +00:00
|
|
|
|