2011-12-19 13:15:11 +00:00
|
|
|
Locomotive.Views.ContentTypes ||= {}
|
|
|
|
|
|
|
|
class Locomotive.Views.ContentTypes.CustomFieldEntryView extends Backbone.View
|
|
|
|
|
|
|
|
tagName: 'li'
|
|
|
|
|
|
|
|
className: 'custom-field'
|
|
|
|
|
|
|
|
events:
|
2011-12-21 14:24:39 +00:00
|
|
|
'click a.toggle': 'toggle'
|
2011-12-19 13:15:11 +00:00
|
|
|
'click a.remove': 'remove'
|
|
|
|
|
2011-12-22 15:45:42 +00:00
|
|
|
initialize: ->
|
|
|
|
@model.bind 'change', (custom_field) =>
|
|
|
|
@switch_to_type() if @model.hasChanged('type')
|
|
|
|
|
2011-12-19 13:15:11 +00:00
|
|
|
render: ->
|
|
|
|
$(@el).html(ich.custom_field_entry(@model.toJSON()))
|
|
|
|
|
|
|
|
Backbone.ModelBinding.bind @, all: 'class'
|
|
|
|
|
2011-12-22 15:45:42 +00:00
|
|
|
@make_fields_editable()
|
|
|
|
|
|
|
|
@enable_behaviours()
|
|
|
|
|
|
|
|
@switch_to_type()
|
2011-12-21 14:24:39 +00:00
|
|
|
|
2011-12-19 13:15:11 +00:00
|
|
|
return @
|
|
|
|
|
2011-12-22 15:45:42 +00:00
|
|
|
enable_behaviours: ->
|
2012-01-14 00:38:09 +00:00
|
|
|
@$('li.input.toggle input[type=checkbox]').checkToggle()
|
2011-12-22 15:45:42 +00:00
|
|
|
@render_select_options_view()
|
|
|
|
|
|
|
|
switch_to_type: ->
|
|
|
|
@$('li.input.extra').hide() # reset
|
|
|
|
|
|
|
|
switch @model.get('type')
|
|
|
|
when 'select'
|
|
|
|
@$('li.input.select-options').show()
|
|
|
|
when 'text'
|
|
|
|
@$('li.input.text-formatting').show()
|
|
|
|
|
|
|
|
render_select_options_view: ->
|
|
|
|
@select_options_view = new Locomotive.Views.ContentTypes.SelectOptionsView
|
|
|
|
model: @model
|
|
|
|
collection: @model.get('select_options')
|
|
|
|
|
|
|
|
@$('#content_type_contents_custom_field_select_options_input').append(@select_options_view.render().el)
|
|
|
|
|
|
|
|
make_fields_editable: ->
|
|
|
|
@$('span.label-input input[type=text], span.type-input select').editableField()
|
|
|
|
|
2011-12-21 14:24:39 +00:00
|
|
|
toggle: (event) ->
|
2011-12-19 13:15:11 +00:00
|
|
|
event.stopPropagation() & event.preventDefault()
|
|
|
|
form = @$('ol')
|
|
|
|
|
|
|
|
if form.is(':hidden')
|
|
|
|
form.slideDown()
|
|
|
|
else
|
|
|
|
form.slideUp()
|
|
|
|
|
2011-12-21 14:24:39 +00:00
|
|
|
show_error: (message) ->
|
|
|
|
html = $("<span class=\"inline-errors\">#{message}</div>")
|
|
|
|
@$('span.required-input').after(html)
|
|
|
|
|
2011-12-19 13:15:11 +00:00
|
|
|
remove: (event) ->
|
|
|
|
event.stopPropagation() & event.preventDefault()
|
|
|
|
|
|
|
|
if confirm($(event.target).attr('data-confirm'))
|
2011-12-21 14:24:39 +00:00
|
|
|
@$('span.label-input input[type=text], span.type-input select').editableField('destroy')
|
2011-12-19 13:15:11 +00:00
|
|
|
super()
|
|
|
|
@options.parent_view.remove_entry(@model, @)
|