the has_many ui component is done
This commit is contained in:
parent
1703c05693
commit
9e9fe49ccf
BIN
app/assets/images/locomotive/list/icons/pencil.png
Normal file
BIN
app/assets/images/locomotive/list/icons/pencil.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 352 B |
BIN
app/assets/images/locomotive/list/icons/pencil_off.png
Normal file
BIN
app/assets/images/locomotive/list/icons/pencil_off.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 350 B |
BIN
app/assets/images/locomotive/list/icons/popup.png
Normal file
BIN
app/assets/images/locomotive/list/icons/popup.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 347 B |
BIN
app/assets/images/locomotive/list/icons/popup_off.png
Normal file
BIN
app/assets/images/locomotive/list/icons/popup_off.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 351 B |
@ -28,4 +28,21 @@ window.Locomotive.tinyMCE =
|
|||||||
theme_advanced_toolbar_align: 'left'
|
theme_advanced_toolbar_align: 'left'
|
||||||
height: '20'
|
height: '20'
|
||||||
width: '709'
|
width: '709'
|
||||||
convert_urls: false
|
convert_urls: false
|
||||||
|
|
||||||
|
popupSettings:
|
||||||
|
theme: 'advanced'
|
||||||
|
skin: 'locomotive'
|
||||||
|
plugins: 'safari,jqueryinlinepopups,locomotive_media,fullscreen'
|
||||||
|
extended_valid_elements: 'iframe[width|height|frameborder|allowfullscreen|src|title]'
|
||||||
|
theme_advanced_buttons1: 'fullscreen,code,|,bold,italic,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,|,outdent,indent,blockquote,|,link,unlink,|,locomotive_media'
|
||||||
|
theme_advanced_buttons2: 'formatselect,fontselect,fontsizeselect'
|
||||||
|
theme_advanced_buttons3: ''
|
||||||
|
theme_advanced_toolbar_location: 'top'
|
||||||
|
theme_advanced_toolbar_align: 'left'
|
||||||
|
height: '300'
|
||||||
|
width: '545'
|
||||||
|
convert_urls: false
|
||||||
|
fullscreen_new_window: false
|
||||||
|
fullscreen_settings:
|
||||||
|
theme_advanced_path_location: 'top'
|
@ -14,7 +14,7 @@ class Locomotive.Views.ContentEntries.FormView extends Locomotive.Views.Shared.F
|
|||||||
'submit': 'save'
|
'submit': 'save'
|
||||||
|
|
||||||
initialize: ->
|
initialize: ->
|
||||||
@model = new Locomotive.Models.ContentEntry(@options.content_entry)
|
@model ||= new Locomotive.Models.ContentEntry(@options.content_entry)
|
||||||
|
|
||||||
window.foo = @model
|
window.foo = @model
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ class Locomotive.Views.ContentEntries.FormView extends Locomotive.Views.Shared.F
|
|||||||
|
|
||||||
enable_richtexteditor: ->
|
enable_richtexteditor: ->
|
||||||
_.each @$('li.input.rte textarea.html'), (textarea) =>
|
_.each @$('li.input.rte textarea.html'), (textarea) =>
|
||||||
settings = _.extend {}, window.Locomotive.tinyMCE.defaultSettings,
|
settings = _.extend {}, @tinyMCE_settings(),
|
||||||
onchange_callback: (editor) =>
|
onchange_callback: (editor) =>
|
||||||
$(textarea).val(editor.getBody().innerHTML).trigger('change')
|
$(textarea).val(editor.getBody().innerHTML).trigger('change')
|
||||||
|
|
||||||
@ -62,7 +62,8 @@ class Locomotive.Views.ContentEntries.FormView extends Locomotive.Views.Shared.F
|
|||||||
enable_has_many_fields: ->
|
enable_has_many_fields: ->
|
||||||
_.each @model.get('_has_many_fields'), (field) =>
|
_.each @model.get('_has_many_fields'), (field) =>
|
||||||
name = field[0]; inverse_of = field[1]
|
name = field[0]; inverse_of = field[1]
|
||||||
view = new Locomotive.Views.Shared.Fields.HasManyView model: @model, name: name, inverse_of: inverse_of
|
new_entry = new Locomotive.Models.ContentEntry(@options["#{name}_new_entry"])
|
||||||
|
view = new Locomotive.Views.Shared.Fields.HasManyView model: @model, name: name, new_entry: new_entry, inverse_of: inverse_of
|
||||||
|
|
||||||
@_has_many_field_views.push(view)
|
@_has_many_field_views.push(view)
|
||||||
|
|
||||||
@ -74,8 +75,21 @@ class Locomotive.Views.ContentEntries.FormView extends Locomotive.Views.Shared.F
|
|||||||
refresh_file_fields: ->
|
refresh_file_fields: ->
|
||||||
_.each @_file_field_views, (view) => view.refresh()
|
_.each @_file_field_views, (view) => view.refresh()
|
||||||
|
|
||||||
|
refresh: ->
|
||||||
|
@$('li.input.toggle input[type=checkbox]').checkToggle('sync')
|
||||||
|
_.each @_file_field_views, (view) => view.refresh()
|
||||||
|
|
||||||
|
reset: ->
|
||||||
|
@$('li.input.string input[type=text], li.input.text textarea, li.input.date input[type=text]').val('').trigger('change')
|
||||||
|
_.each @$('li.input.rte textarea.html'), (textarea) => $(textarea).tinymce().setContent(''); $(textarea).trigger('change')
|
||||||
|
_.each @_file_field_views, (view) => view.reset()
|
||||||
|
@$('li.input.toggle input[type=checkbox]').checkToggle('sync')
|
||||||
|
|
||||||
remove: ->
|
remove: ->
|
||||||
_.each @_file_field_views, (view) => view.remove()
|
_.each @_file_field_views, (view) => view.remove()
|
||||||
_.each @_has_many_field_views, (view) => view.remove()
|
_.each @_has_many_field_views, (view) => view.remove()
|
||||||
super
|
super
|
||||||
|
|
||||||
|
tinyMCE_settings: ->
|
||||||
|
window.Locomotive.tinyMCE.defaultSettings
|
||||||
|
|
@ -0,0 +1,77 @@
|
|||||||
|
#= require ../shared/form_view
|
||||||
|
|
||||||
|
Locomotive.Views.ContentEntries ||= {}
|
||||||
|
|
||||||
|
class Locomotive.Views.ContentEntries.PopupFormView extends Locomotive.Views.ContentEntries.FormView
|
||||||
|
|
||||||
|
initialize: ->
|
||||||
|
@create_dialog()
|
||||||
|
|
||||||
|
super()
|
||||||
|
|
||||||
|
render: ->
|
||||||
|
super()
|
||||||
|
|
||||||
|
return @
|
||||||
|
|
||||||
|
save: (event) ->
|
||||||
|
@save_in_ajax event,
|
||||||
|
headers: { 'X-Flash': true }
|
||||||
|
on_success: (response, xhr) =>
|
||||||
|
entry = new Locomotive.Models.ContentEntry(response)
|
||||||
|
@options.parent_view.insert_or_update_entry(entry)
|
||||||
|
@close()
|
||||||
|
on_error: =>
|
||||||
|
@shake()
|
||||||
|
|
||||||
|
create_dialog: ->
|
||||||
|
@dialog = $(@el).dialog
|
||||||
|
autoOpen: false
|
||||||
|
modal: true
|
||||||
|
zIndex: 998
|
||||||
|
width: 770,
|
||||||
|
create: (event, ui) =>
|
||||||
|
$('.ui-widget-overlay').bind 'click', => @close()
|
||||||
|
|
||||||
|
$(@el).prev().find('.ui-dialog-title').html(@$('h2').html())
|
||||||
|
@$('h2').remove()
|
||||||
|
actions = @$('.dialog-actions').appendTo($(@el).parent()).addClass('ui-dialog-buttonpane ui-widget-content ui-helper-clearfix')
|
||||||
|
|
||||||
|
actions.find('#close-link').click (event) => @close(event)
|
||||||
|
actions.find('input[type=submit]').click (event) => @save(event)
|
||||||
|
|
||||||
|
open: (event, ui, extra) =>
|
||||||
|
# nothing to do
|
||||||
|
|
||||||
|
open: ->
|
||||||
|
parent_el = $(@el).parent()
|
||||||
|
if @model.isNew()
|
||||||
|
parent_el.find('.edit-section').hide()
|
||||||
|
parent_el.find('.new-section').show()
|
||||||
|
else
|
||||||
|
parent_el.find('.new-section').hide()
|
||||||
|
parent_el.find('.edit-section').show()
|
||||||
|
|
||||||
|
$(@el).dialog('open')
|
||||||
|
|
||||||
|
close: (event) ->
|
||||||
|
event.stopPropagation() & event.preventDefault() if event?
|
||||||
|
$(@el).dialog('close')
|
||||||
|
|
||||||
|
shake: ->
|
||||||
|
$(@el).parents('.ui-dialog').effect('shake', { times: 4 }, 100)
|
||||||
|
|
||||||
|
center: ->
|
||||||
|
$(@el).dialog('option', 'position', 'center')
|
||||||
|
|
||||||
|
reset: (entry) =>
|
||||||
|
@model.set entry.attributes
|
||||||
|
|
||||||
|
if entry.isNew()
|
||||||
|
@model.id = null
|
||||||
|
super()
|
||||||
|
else
|
||||||
|
@refresh()
|
||||||
|
|
||||||
|
tinyMCE_settings: ->
|
||||||
|
window.Locomotive.tinyMCE.popupSettings
|
@ -39,13 +39,14 @@ class Locomotive.Views.Shared.Fields.FileView extends Backbone.View
|
|||||||
return @
|
return @
|
||||||
|
|
||||||
refresh: ->
|
refresh: ->
|
||||||
# @remove()
|
|
||||||
@$('input[type=file]').unbind 'change'
|
@$('input[type=file]').unbind 'change'
|
||||||
@states = { 'change': false, 'delete': false }
|
@states = { 'change': false, 'delete': false }
|
||||||
@render()
|
@render()
|
||||||
# @$('input[type=file]').unbind 'change'
|
|
||||||
# @states = { 'change': false, 'delete': false }
|
reset: ->
|
||||||
# @render()
|
@model.set_attribute @options.name, null
|
||||||
|
@model.set_attribute "#{@options.name}_url", null
|
||||||
|
@refresh()
|
||||||
|
|
||||||
toggle_change: (event) ->
|
toggle_change: (event) ->
|
||||||
@_toggle event, 'change',
|
@_toggle event, 'change',
|
||||||
|
@ -8,6 +8,8 @@ class Locomotive.Views.Shared.Fields.HasManyView extends Backbone.View
|
|||||||
className: 'list'
|
className: 'list'
|
||||||
|
|
||||||
events:
|
events:
|
||||||
|
'click p.actions a.add': 'open_new_entry_view'
|
||||||
|
'click ul span.actions a.edit': 'edit_entry'
|
||||||
'click ul span.actions a.remove': 'remove_entry'
|
'click ul span.actions a.remove': 'remove_entry'
|
||||||
|
|
||||||
template: ->
|
template: ->
|
||||||
@ -21,8 +23,7 @@ class Locomotive.Views.Shared.Fields.HasManyView extends Backbone.View
|
|||||||
|
|
||||||
@collection = @model.get(@options.name)
|
@collection = @model.get(@options.name)
|
||||||
|
|
||||||
window.model = @model
|
@build_target_entry_view()
|
||||||
window.bar = @collection
|
|
||||||
|
|
||||||
render: ->
|
render: ->
|
||||||
$(@el).html(@template()())
|
$(@el).html(@template()())
|
||||||
@ -40,9 +41,12 @@ class Locomotive.Views.Shared.Fields.HasManyView extends Backbone.View
|
|||||||
@$('.empty').show()
|
@$('.empty').show()
|
||||||
|
|
||||||
insert_entry: (entry) ->
|
insert_entry: (entry) ->
|
||||||
|
unless @collection.get(entry.get('_id'))?
|
||||||
|
@collection.add(entry)
|
||||||
|
|
||||||
@$('.empty').hide()
|
@$('.empty').hide()
|
||||||
entry_html = $(@entry_template()(label: entry.get('_label')))
|
entry_html = $(@entry_template()(label: entry.get('_label')))
|
||||||
entry_html.data('data-entry-cid', entry.cid)
|
entry_html.data('data-entry-id', entry.id)
|
||||||
@$('> ul').append(entry_html)
|
@$('> ul').append(entry_html)
|
||||||
|
|
||||||
make_entries_sortable: ->
|
make_entries_sortable: ->
|
||||||
@ -54,20 +58,63 @@ class Locomotive.Views.Shared.Fields.HasManyView extends Backbone.View
|
|||||||
|
|
||||||
refresh_position_entries: ->
|
refresh_position_entries: ->
|
||||||
@$('> ul > li').each (index, entry_html) =>
|
@$('> ul > li').each (index, entry_html) =>
|
||||||
cid = $(entry_html).data('data-entry-cid')
|
id = $(entry_html).data('data-entry-id')
|
||||||
entry = @collection.getByCid(cid)
|
entry = @collection.get(id)
|
||||||
entry.set_attribute "position_in_#{@options.inverse_of}", index
|
entry.set_attribute "position_in_#{@options.inverse_of}", index
|
||||||
|
|
||||||
|
build_target_entry_view: ->
|
||||||
|
@target_entry_view = new Locomotive.Views.ContentEntries.PopupFormView
|
||||||
|
el: $("##{@options.name}-template-entry")
|
||||||
|
parent_view: @
|
||||||
|
model: @options.new_entry.clone() # by default, it does not matter
|
||||||
|
|
||||||
|
@target_entry_view.render()
|
||||||
|
|
||||||
|
edit_entry: (event) ->
|
||||||
|
event.stopPropagation() & event.preventDefault()
|
||||||
|
|
||||||
|
entry = @get_entry_from_element($(event.target))
|
||||||
|
|
||||||
|
@target_entry_view.reset(entry)
|
||||||
|
@target_entry_view.open()
|
||||||
|
|
||||||
|
update_entry: (entry) ->
|
||||||
|
entry_html = $(_.detect @$('> ul > li'), (_entry_html) -> $(_entry_html).data('data-entry-id') == entry.id)
|
||||||
|
|
||||||
|
new_entry_html = $(@entry_template()(label: entry.get('_label')))
|
||||||
|
new_entry_html.data('data-entry-id', entry.id)
|
||||||
|
|
||||||
|
entry_html.replaceWith(new_entry_html)
|
||||||
|
|
||||||
|
insert_or_update_entry: (entry) ->
|
||||||
|
if @collection.get(entry.id)?
|
||||||
|
@update_entry(entry)
|
||||||
|
else
|
||||||
|
@insert_entry(entry)
|
||||||
|
|
||||||
remove_entry: (event) ->
|
remove_entry: (event) ->
|
||||||
event.stopPropagation() & event.preventDefault()
|
event.stopPropagation() & event.preventDefault()
|
||||||
|
|
||||||
if confirm($(event.target).attr('data-confirm'))
|
if confirm($(event.target).attr('data-confirm'))
|
||||||
entry_html = $(event.target).closest('li')
|
entry = @get_entry_from_element($(event.target))
|
||||||
cid = $(entry_html).data('data-entry-cid')
|
|
||||||
entry = @collection.getByCid(cid)
|
|
||||||
entry.set _destroy: true
|
entry.set _destroy: true
|
||||||
|
|
||||||
entry_html.remove()
|
$(event.target).closest('li').remove()
|
||||||
@$('.empty').show() if @$('> ul > li').size() == 0
|
@$('.empty').show() if @$('> ul > li').size() == 0
|
||||||
@refresh_position_entries()
|
@refresh_position_entries()
|
||||||
|
|
||||||
|
open_new_entry_view: (event) ->
|
||||||
|
event.stopPropagation() & event.preventDefault()
|
||||||
|
|
||||||
|
@target_entry_view.reset(@options.new_entry.clone())
|
||||||
|
@target_entry_view.open()
|
||||||
|
|
||||||
|
get_entry_from_element: (element) =>
|
||||||
|
entry_html = $(element).closest('li')
|
||||||
|
id = $(entry_html).data('data-entry-id')
|
||||||
|
@collection.get(id)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,11 +23,12 @@ class Locomotive.Views.Shared.FormView extends Backbone.View
|
|||||||
|
|
||||||
@clear_errors()
|
@clear_errors()
|
||||||
|
|
||||||
options ||= { on_success: null, on_error: null }
|
options ||= { headers: {}, on_success: null, on_error: null }
|
||||||
|
|
||||||
previous_attributes = _.clone @model.attributes
|
previous_attributes = _.clone @model.attributes
|
||||||
|
|
||||||
@model.save {},
|
@model.save {},
|
||||||
|
headers: options.headers
|
||||||
success: (model, response, xhr) =>
|
success: (model, response, xhr) =>
|
||||||
model.attributes = previous_attributes
|
model.attributes = previous_attributes
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@
|
|||||||
|
|
||||||
.ui-dialog-content {
|
.ui-dialog-content {
|
||||||
position: relative;
|
position: relative;
|
||||||
z-index: 101;
|
z-index: 999;
|
||||||
|
|
||||||
text-align: left;
|
text-align: left;
|
||||||
|
|
||||||
@ -71,6 +71,22 @@
|
|||||||
overflow: auto;
|
overflow: auto;
|
||||||
height: 360px;
|
height: 360px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
form.formtastic {
|
||||||
|
fieldset {
|
||||||
|
legend, ol {
|
||||||
|
width: 748px;
|
||||||
|
}
|
||||||
|
|
||||||
|
ol {
|
||||||
|
li.string {
|
||||||
|
input[type=text] {
|
||||||
|
width: 530px;
|
||||||
|
}
|
||||||
|
} // li.string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // .form.formtastic
|
||||||
} // .ui-dialog-content
|
} // .ui-dialog-content
|
||||||
|
|
||||||
|
|
||||||
@ -104,7 +120,7 @@
|
|||||||
|
|
||||||
z-index: 1003;
|
z-index: 1003;
|
||||||
|
|
||||||
a {
|
a, input[type=submit] {
|
||||||
@include light-button;
|
@include light-button;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ form.formtastic {
|
|||||||
padding-left: 10px;
|
padding-left: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
a.remove, a.toggle, a.drag {
|
a.edit, a.remove, a.toggle, a.drag {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
width: 16px;
|
width: 16px;
|
||||||
height: 16px;
|
height: 16px;
|
||||||
@ -138,6 +138,13 @@ form.formtastic {
|
|||||||
outline: none;
|
outline: none;
|
||||||
text-indent: -9999px;
|
text-indent: -9999px;
|
||||||
|
|
||||||
|
&.edit {
|
||||||
|
background: transparent image-url("locomotive/list/icons/pencil_off.png") repeat 0 0;
|
||||||
|
&:hover {
|
||||||
|
background-image: image-url("locomotive/list/icons/pencil.png");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
&.remove {
|
&.remove {
|
||||||
background: transparent image-url("locomotive/list/icons/trash_off.png") repeat 0 0;
|
background: transparent image-url("locomotive/list/icons/trash_off.png") repeat 0 0;
|
||||||
&:hover {
|
&:hover {
|
||||||
|
@ -59,7 +59,7 @@ module Locomotive::BaseHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
def backbone_view_data
|
def backbone_view_data
|
||||||
content_for?(:backbone_view_data) ? content_for(:backbone_view_data) : 'null'
|
content_for?(:backbone_view_data) ? content_for(:backbone_view_data) : ''
|
||||||
end
|
end
|
||||||
|
|
||||||
def nocoffee_tag
|
def nocoffee_tag
|
||||||
|
@ -1,11 +1,7 @@
|
|||||||
module Locomotive::ContentEntriesHelper
|
module Locomotive::ContentEntriesHelper
|
||||||
|
|
||||||
def options_for_belongs_to_custom_field(class_name)
|
def options_for_belongs_to_custom_field(class_name)
|
||||||
content_type = nil
|
content_type = Locomotive::ContentType.class_name_to_content_type(class_name, current_site)
|
||||||
|
|
||||||
if class_name =~ /^Locomotive::Entry(.*)/
|
|
||||||
content_type = current_site.content_types.find($1)
|
|
||||||
end
|
|
||||||
|
|
||||||
if content_type
|
if content_type
|
||||||
content_type.ordered_entries.map { |entry| [entry._label, entry._id] }
|
content_type.ordered_entries.map { |entry| [entry._label, entry._id] }
|
||||||
|
@ -74,6 +74,26 @@ module Locomotive
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def class_name_to_content_type(class_name)
|
||||||
|
self.class.class_name_to_content_type(class_name, self.site)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Retrieve from a class name the associated content type within the scope of a site.
|
||||||
|
# If no content type is found, the method returns nil
|
||||||
|
#
|
||||||
|
# @param [ String ] class_name The class name
|
||||||
|
# @param [ Locomotive::Site ] site The Locomotive site
|
||||||
|
#
|
||||||
|
# @return [ Locomotive::ContentType ] The content type matching the class_name
|
||||||
|
#
|
||||||
|
def self.class_name_to_content_type(class_name, site)
|
||||||
|
if class_name =~ /^Locomotive::Entry(.*)/
|
||||||
|
site.content_types.find($1)
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def to_presenter
|
def to_presenter
|
||||||
Locomotive::ContentTypePresenter.new(self)
|
Locomotive::ContentTypePresenter.new(self)
|
||||||
end
|
end
|
||||||
|
@ -86,7 +86,6 @@ module Locomotive
|
|||||||
when :date then "formatted_#{name}"
|
when :date then "formatted_#{name}"
|
||||||
when :file then "#{name}_url"
|
when :file then "#{name}_url"
|
||||||
when :belongs_to then "#{name}_id"
|
when :belongs_to then "#{name}_id"
|
||||||
# when :has_many then nil
|
|
||||||
else
|
else
|
||||||
name
|
name
|
||||||
end
|
end
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
- content_for :backbone_view_data do
|
- content_for :backbone_view_data do
|
||||||
:plain
|
:plain
|
||||||
{ content_entry: #{@content_entry.to_json} }
|
content_entry: #{@content_entry.to_json}
|
||||||
|
|
||||||
= f.inputs :name => :attributes do
|
= f.inputs :name => :attributes do
|
||||||
- @content_type.ordered_entries_custom_fields.each_with_index do |field, index|
|
- @content_type.ordered_entries_custom_fields.each_with_index do |field, index|
|
||||||
|
@ -3,10 +3,8 @@
|
|||||||
|
|
||||||
- content_for :backbone_view_data do
|
- content_for :backbone_view_data do
|
||||||
:plain
|
:plain
|
||||||
{
|
content_type: #{@content_type.persisted? ? @content_type.to_json : 'null'},
|
||||||
content_type: #{@content_type.persisted? ? @content_type.to_json : 'null'},
|
inverse_of_list: #{options_for_content_type_inverse_of.to_json}
|
||||||
inverse_of_list: #{options_for_content_type_inverse_of.to_json}
|
|
||||||
}
|
|
||||||
|
|
||||||
= f.inputs :name => :information do
|
= f.inputs :name => :information do
|
||||||
|
|
||||||
|
@ -4,7 +4,8 @@
|
|||||||
|
|
||||||
- content_for :backbone_view_data do
|
- content_for :backbone_view_data do
|
||||||
:plain
|
:plain
|
||||||
{ site: #{@site.to_json(:current_account => current_locomotive_account, :current_site => current_site)}, errors: #{@site.errors.to_json} }
|
site: #{@site.to_json(:current_account => current_locomotive_account, :current_site => current_site)},
|
||||||
|
errors: #{@site.errors.to_json}
|
||||||
|
|
||||||
= f.inputs :name => :information do
|
= f.inputs :name => :information do
|
||||||
= f.input :name, :wrapper_html => { :style => 'display: none' }
|
= f.input :name, :wrapper_html => { :style => 'display: none' }
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
|
|
||||||
= g.input :hint, :input_html => { :class => 'hint' }
|
= g.input :hint, :input_html => { :class => 'hint' }
|
||||||
|
|
||||||
= g.input :localized, :as => :'Locomotive::Toggle', :wrapper_html => { :class => 'extra localized' }, :input_html => { :class => 'localized' }
|
= g.input :localized, :as => :'Locomotive::Toggle', :wrapper_html => { :class => 'localized' }, :input_html => { :class => 'localized' }
|
||||||
|
|
||||||
= g.input :select_options, :as => :'Locomotive::Empty', :wrapper_html => { :class => 'extra select-options', :style => 'display: none' }
|
= g.input :select_options, :as => :'Locomotive::Empty', :wrapper_html => { :class => 'extra select-options', :style => 'display: none' }
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
= f.input name,
|
= f.input name,
|
||||||
:label => field.label,
|
:label => field.label,
|
||||||
:hint => field.hint,
|
:hint => field.hint,
|
||||||
:as => :'Locomotive::Toggle'
|
:as => :'Locomotive::Toggle'
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
- if !f.object.new_record? && field.ui_enabled?
|
- if !f.object.new_record? && field.ui_enabled?
|
||||||
|
|
||||||
|
- target_content_type = Locomotive::ContentType.class_name_to_content_type(field.class_name, current_site)
|
||||||
|
- new_target_content_entry = target_content_type.entries.build(field.inverse_of => f.object)
|
||||||
|
|
||||||
= f.input name.to_sym,
|
= f.input name.to_sym,
|
||||||
:label => field.label,
|
:label => field.label,
|
||||||
:hint => field.hint,
|
:hint => field.hint,
|
||||||
@ -16,8 +19,8 @@
|
|||||||
|
|
||||||
%hr
|
%hr
|
||||||
|
|
||||||
%p
|
%p.actions
|
||||||
= link_to t('.new_entry'), '#'
|
= link_to t('.new_entry'), '#', :class => 'add'
|
||||||
|
|
||||||
%script{ :type => 'text/html', :id => "#{name}_entry" }
|
%script{ :type => 'text/html', :id => "#{name}_entry" }
|
||||||
%li
|
%li
|
||||||
@ -28,43 +31,40 @@
|
|||||||
{{label}}
|
{{label}}
|
||||||
|
|
||||||
%span.actions
|
%span.actions
|
||||||
|
= link_to 'e', '#', :class => 'edit'
|
||||||
= link_to 'x', '#', :class => 'remove', :confirm => t('locomotive.messages.confirm')
|
= link_to 'x', '#', :class => 'remove', :confirm => t('locomotive.messages.confirm')
|
||||||
|
|
||||||
|
|
||||||
/ - collection = f.object.send(name.to_sym)
|
- content_for :backbone_view_data do
|
||||||
|
:plain
|
||||||
|
, #{name}_new_entry: #{new_target_content_entry.to_json}
|
||||||
|
|
||||||
|
- content_for :foot do
|
||||||
|
|
||||||
|
%div{ :id => "#{name}-template-entry", :style => 'display: none' }
|
||||||
|
|
||||||
|
%h2
|
||||||
|
%span.new-section= t('locomotive.content_entries.new.title', :type => name.capitalize).html_safe
|
||||||
|
%span.edit-section= t('locomotive.content_entries.edit.title', :type => name.capitalize).html_safe
|
||||||
|
|
||||||
|
= semantic_form_for new_target_content_entry, :as => :content_entry, :url => content_entries_url(target_content_type.slug), :html => { :multipart => true } do |form|
|
||||||
|
|
||||||
|
= form.inputs :name => :attributes do
|
||||||
|
- target_content_type.ordered_entries_custom_fields.each_with_index do |_field, index|
|
||||||
|
|
||||||
|
- next if _field.name == field.inverse_of || _field.type == 'has_many'
|
||||||
|
|
||||||
|
= render "locomotive/custom_fields/types/#{_field.type}",
|
||||||
|
:f => form,
|
||||||
|
:name => _field.name.to_sym,
|
||||||
|
:field => _field,
|
||||||
|
:highlighted => _field._id == target_content_type.label_field_id
|
||||||
|
|
||||||
|
|
||||||
|
.dialog-actions
|
||||||
|
= link_to t('locomotive.buttons.close'), '#', :id => 'close-link'
|
||||||
|
|
||||||
|
.button-wrapper
|
||||||
|
%span.new-section= submit_tag t('locomotive.shared.form_actions.create')
|
||||||
|
%span.edit-section= submit_tag t('locomotive.shared.form_actions.update')
|
||||||
|
|
||||||
/ = form.custom_input field._alias.to_sym, :label => field.label, :hint => field.hint, :css => 'has-many', :required => required do
|
|
||||||
/
|
|
||||||
/ .has-many-selector
|
|
||||||
/
|
|
||||||
/ %p{ :style => form.object.send(field._alias.to_sym).empty? ? '' : 'display: none' }
|
|
||||||
/ = t('.empty')
|
|
||||||
/
|
|
||||||
/ %ul
|
|
||||||
/
|
|
||||||
/ %script{ :type => 'text/x-mustache-template', :name => 'template', :'data-base-input-name' => "content[#{field._alias.to_sym}]" }
|
|
||||||
/ %li{ :class => "item {{behaviour_flag}}" }
|
|
||||||
/ %span.handle
|
|
||||||
/ = image_tag 'admin/form/icons/drag.png'
|
|
||||||
/
|
|
||||||
/ {{^if_template}}
|
|
||||||
/ %input{ :name => '{{base_name}}[]', :value => '{{{id}}}', :type => 'hidden', :'data-field' => 'id' }
|
|
||||||
/ {{/if_template}}
|
|
||||||
/
|
|
||||||
/ %strong {{label}}
|
|
||||||
/
|
|
||||||
/ {{#if_template}}
|
|
||||||
/ = select_tag 'label', ''
|
|
||||||
/ {{/if_template}}
|
|
||||||
/
|
|
||||||
/ %span.actions
|
|
||||||
/ - if field.reverse_lookup?
|
|
||||||
/ = link_to image_tag('admin/form/pen.png'), '#', :class => 'edit first'
|
|
||||||
/ = link_to image_tag('admin/form/icons/trash.png'), '#', :class => 'remove'
|
|
||||||
/ %button{ :class => 'button light mini add', :type => 'button' }
|
|
||||||
/ %span!= t('locomotive.buttons.new_item')
|
|
||||||
/
|
|
||||||
/ %script{ :type => 'text/javascript', :name => 'data' }
|
|
||||||
/ != has_many_data_to_js(field, form.object)
|
|
@ -1,14 +0,0 @@
|
|||||||
- field.target.constantize.reload_parent! # to make sure all the contents from the parent are loaded
|
|
||||||
|
|
||||||
- if breadcrumb_root && params[:breadcrumb_alias] == field._alias
|
|
||||||
|
|
||||||
= form.hidden_field field._name.to_sym
|
|
||||||
|
|
||||||
= hidden_field_tag 'breadcrumb_alias', field._alias
|
|
||||||
|
|
||||||
- else
|
|
||||||
|
|
||||||
- selected_id = form.object.send(field._alias.to_sym).try(:_id)
|
|
||||||
|
|
||||||
= form.input field._alias.to_sym, :label => field.label, :hint => field.hint, :input_html => { :class => 'has_one' }, :as => :select, :collection => options_for_has_one(field, selected_id), :selected => selected_id, :required => required
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
= f.input name,
|
= f.input name,
|
||||||
:label => field.label,
|
:label => field.label,
|
||||||
:hint => field.hint,
|
:hint => field.hint,
|
||||||
:wrapper_html => { :class => "#{'highlighted' if highlighted}" }
|
:wrapper_html => { :class => "#{'highlighted' if highlighted}" }
|
||||||
|
@ -29,4 +29,6 @@
|
|||||||
= yield
|
= yield
|
||||||
|
|
||||||
#footer
|
#footer
|
||||||
= render 'locomotive/shared/footer'
|
= render 'locomotive/shared/footer'
|
||||||
|
|
||||||
|
= yield :foot
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
- content_for :backbone_view_data do
|
- content_for :backbone_view_data do
|
||||||
:plain
|
:plain
|
||||||
{ account: #{@account.to_json} }
|
account: #{@account.to_json}
|
||||||
|
|
||||||
- content_for :submenu do
|
- content_for :submenu do
|
||||||
= render_cell 'locomotive/settings_menu', :show
|
= render_cell 'locomotive/settings_menu', :show
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
- content_for :backbone_view_data do
|
- content_for :backbone_view_data do
|
||||||
:plain
|
:plain
|
||||||
{ page: #{@page.to_presenter.as_json_for_html_view.to_json} }
|
page: #{@page.to_presenter.as_json_for_html_view.to_json}
|
||||||
|
|
||||||
- if can?(:manage, @page)
|
- if can?(:manage, @page)
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
window.application_view = new Locomotive.Views.ApplicationView({
|
window.application_view = new Locomotive.Views.ApplicationView({
|
||||||
flash: #{flash.to_json},
|
flash: #{flash.to_json},
|
||||||
view: #{backbone_view_class_name},
|
view: #{backbone_view_class_name},
|
||||||
view_data: #{backbone_view_data}
|
view_data: { #{backbone_view_data} }
|
||||||
});
|
});
|
||||||
window.application_view.render();
|
window.application_view.render();
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
- content_for :backbone_view_data do
|
- content_for :backbone_view_data do
|
||||||
:plain
|
:plain
|
||||||
{ snippet: #{@snippet.persisted? ? @snippet.to_presenter.as_json_for_html_view.to_json : 'null'} }
|
snippet: #{@snippet.persisted? ? @snippet.to_presenter.as_json_for_html_view.to_json : 'null'}
|
||||||
|
|
||||||
= f.inputs :name => :information do
|
= f.inputs :name => :information do
|
||||||
= f.input :name, :wrapper_html => { :class => 'highlighted' }
|
= f.input :name, :wrapper_html => { :class => 'highlighted' }
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
- content_for :backbone_view_data do
|
- content_for :backbone_view_data do
|
||||||
:plain
|
:plain
|
||||||
{ theme_asset: #{@theme_asset.persisted? ? @theme_asset.to_json : 'null'} }
|
theme_asset: #{@theme_asset.persisted? ? @theme_asset.to_json : 'null'}
|
||||||
|
|
||||||
= f.hidden_field :performing_plain_text
|
= f.hidden_field :performing_plain_text
|
||||||
|
|
||||||
|
@ -16,13 +16,11 @@
|
|||||||
|
|
||||||
- content_for :backbone_view_data do
|
- content_for :backbone_view_data do
|
||||||
:plain
|
:plain
|
||||||
{
|
snippets: #{can?(:manage, Locomotive::Snippet) ? @snippets.to_json : 'null'},
|
||||||
snippets: #{can?(:manage, Locomotive::Snippet) ? @snippets.to_json : 'null'},
|
images: #{@assets[:images].to_json},
|
||||||
images: #{@assets[:images].to_json},
|
media: #{@assets[:media].to_json},
|
||||||
media: #{@assets[:media].to_json},
|
js_and_css_assets: #{can?(:manage, Locomotive::ThemeAsset) ? @js_and_css_assets.to_json : 'null'},
|
||||||
js_and_css_assets: #{can?(:manage, Locomotive::ThemeAsset) ? @js_and_css_assets.to_json : 'null'},
|
fonts: #{can?(:manage, Locomotive::ThemeAsset) ? @assets[:fonts].to_json : 'null'}
|
||||||
fonts: #{can?(:manage, Locomotive::ThemeAsset) ? @assets[:fonts].to_json : 'null'}
|
|
||||||
}
|
|
||||||
|
|
||||||
- content_for :submenu do
|
- content_for :submenu do
|
||||||
= render_cell 'locomotive/settings_menu', :show
|
= render_cell 'locomotive/settings_menu', :show
|
||||||
|
@ -80,7 +80,9 @@ en:
|
|||||||
file:
|
file:
|
||||||
delete_file: Delete file
|
delete_file: Delete file
|
||||||
has_many:
|
has_many:
|
||||||
empty: Empty
|
empty: The list is empty
|
||||||
|
new_entry: + Add a new entry
|
||||||
|
|
||||||
form:
|
form:
|
||||||
required: Required
|
required: Required
|
||||||
optional: Optional
|
optional: Optional
|
||||||
|
2
doc/TODO
2
doc/TODO
@ -107,7 +107,7 @@ x script to migrate existing site
|
|||||||
- upgrade to rails 3.2 (https://github.com/locomotivecms/engine/pull/281/files)
|
- upgrade to rails 3.2 (https://github.com/locomotivecms/engine/pull/281/files)
|
||||||
- missing custom_fields
|
- missing custom_fields
|
||||||
x belongs_to
|
x belongs_to
|
||||||
- has_many
|
x has_many
|
||||||
- many_to_many
|
- many_to_many
|
||||||
- heroku module for locomotive
|
- heroku module for locomotive
|
||||||
- refactoring
|
- refactoring
|
||||||
|
@ -8,6 +8,10 @@ module CustomFields
|
|||||||
class Field
|
class Field
|
||||||
field :ui_enabled, :type => Boolean, :default => true
|
field :ui_enabled, :type => Boolean, :default => true
|
||||||
|
|
||||||
|
def class_name_to_content_type
|
||||||
|
self._parent.send :class_name_to_content_type, self.class_name
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def ensure_class_name_security
|
def ensure_class_name_security
|
||||||
|
@ -183,7 +183,10 @@ Backbone.ModelBinding = (function(Backbone, _, $){
|
|||||||
}
|
}
|
||||||
// console.log(attribute_name);
|
// console.log(attribute_name);
|
||||||
|
|
||||||
var modelChange = function(changed_model, val){ element.val(val); };
|
var modelChange = function(changed_model, val){
|
||||||
|
val = val == null ? '' : val;
|
||||||
|
element.val(val);
|
||||||
|
};
|
||||||
|
|
||||||
var setModelValue = function(attr_name, value){
|
var setModelValue = function(attr_name, value){
|
||||||
var data = {};
|
var data = {};
|
||||||
|
83
vendor/assets/javascripts/locomotive/toggle.js
vendored
83
vendor/assets/javascripts/locomotive/toggle.js
vendored
@ -26,7 +26,12 @@
|
|||||||
* @param Bool settings[bypass_skin] Flags whether to bypass the inclusion of the skin.css file. Used if you've included the skin styles somewhere else already.
|
* @param Bool settings[bypass_skin] Flags whether to bypass the inclusion of the skin.css file. Used if you've included the skin styles somewhere else already.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$.fn.checkToggle = function(settings) {
|
$.fn.checkToggle = function(action, settings) {
|
||||||
|
|
||||||
|
if (typeof(action) == 'object' || typeof(action) == 'undefined') {
|
||||||
|
settings = action || {};
|
||||||
|
action = 'initialize';
|
||||||
|
}
|
||||||
|
|
||||||
settings = $.extend({
|
settings = $.extend({
|
||||||
on_label : 'Yes',
|
on_label : 'Yes',
|
||||||
@ -48,14 +53,24 @@
|
|||||||
settings.off_label = 'Non';
|
settings.off_label = 'Non';
|
||||||
}
|
}
|
||||||
|
|
||||||
// append the skin styles
|
function showUncheckedState(element) {
|
||||||
// if(settings.bypass_skin == false){
|
element.parent().prev().css("color",settings.off_label_color);
|
||||||
// $("head").append('<link type="text/css" rel="stylesheet" href="'+settings.skin_dir+'skin.css" media="screen" />');
|
element.parent().next().css("color",settings.on_label_color);
|
||||||
// }
|
element.parent().css("background-color", settings.off_bg_color).removeClass('on');
|
||||||
|
element.parent().parent().prev().removeAttr("checked").trigger('change');
|
||||||
|
element.removeClass("left").addClass("right");
|
||||||
|
}
|
||||||
|
|
||||||
|
function showCheckedState(element) {
|
||||||
|
element.parent().prev().css("color",settings.on_label_color);
|
||||||
|
element.parent().next().css("color",settings.off_label_color);
|
||||||
|
element.parent().css("background-color", settings.on_bg_color).addClass('on');
|
||||||
|
element.parent().parent().prev().attr("checked", "checked").trigger('change');
|
||||||
|
element.removeClass("right").addClass("left");
|
||||||
|
}
|
||||||
|
|
||||||
function toggle(element){
|
function toggle(element){
|
||||||
|
var checked = $(element).parent().parent().prev().is(':checked');
|
||||||
var checked = $(element).parent().parent().prev().attr("checked");
|
|
||||||
|
|
||||||
// if it's set to on
|
// if it's set to on
|
||||||
if(checked){
|
if(checked){
|
||||||
@ -64,11 +79,7 @@
|
|||||||
|
|
||||||
// callback function
|
// callback function
|
||||||
function(){
|
function(){
|
||||||
$(element).parent().prev().css("color",settings.off_label_color);
|
showUncheckedState($(element));
|
||||||
$(element).parent().next().css("color",settings.on_label_color);
|
|
||||||
$(element).parent().css("background-color", settings.off_bg_color).removeClass('on');
|
|
||||||
$(element).parent().parent().prev().removeAttr("checked").trigger('change');
|
|
||||||
$(element).removeClass("left").addClass("right");
|
|
||||||
|
|
||||||
if (typeof $.fn.publish != 'undefined')
|
if (typeof $.fn.publish != 'undefined')
|
||||||
$.publish('toggle.' + $(element).parent().parent().prev().attr('id') + '.unchecked', []);
|
$.publish('toggle.' + $(element).parent().parent().prev().attr('id') + '.unchecked', []);
|
||||||
@ -76,48 +87,56 @@
|
|||||||
settings.off_callback();
|
settings.off_callback();
|
||||||
});
|
});
|
||||||
|
|
||||||
}else{
|
} else {
|
||||||
|
|
||||||
$(element).animate({marginLeft: '15px'}, 100,
|
$(element).animate({marginLeft: '15px'}, 100,
|
||||||
|
|
||||||
// callback function
|
// callback function
|
||||||
function(){
|
function(){
|
||||||
$(element).parent().prev().css("color",settings.on_label_color);
|
showCheckedState($(element));
|
||||||
$(element).parent().next().css("color",settings.off_label_color);
|
|
||||||
$(element).parent().css("background-color", settings.on_bg_color).addClass('on');
|
|
||||||
$(element).parent().parent().prev().attr("checked", "checked").trigger('change');
|
|
||||||
$(element).removeClass("right").addClass("left");
|
|
||||||
|
|
||||||
if (typeof $.fn.publish != 'undefined')
|
if (typeof $.fn.publish != 'undefined')
|
||||||
$.publish('toggle.' + $(element).parent().parent().prev().attr('id') + '.checked', []);
|
$.publish('toggle.' + $(element).parent().parent().prev().attr('id') + '.checked', []);
|
||||||
|
|
||||||
settings.on_callback();
|
settings.on_callback();
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return this.each(function () {
|
return this.each(function () {
|
||||||
|
|
||||||
if ($(this).hasClass('simple')) return;
|
if (action == 'initialize') {// initialize the UI element
|
||||||
|
|
||||||
// hide the checkbox
|
if ($(this).hasClass('simple')) return;
|
||||||
$(this).css('display','none');
|
|
||||||
|
|
||||||
// insert the new toggle markup
|
// hide the checkbox
|
||||||
if($(this).attr("checked") == "checked" || $(this).attr("checked") == true){
|
$(this).css('display','none');
|
||||||
$(this).after('<div class="toggleSwitch"><span class="leftLabel">'+settings.on_label+'<\/span><div class="switchArea on" style="background-color: '+settings.on_bg_color+'"><span class="switchHandle left" style="margin-left: 15px;"><\/span><\/div><span class="rightLabel" style="color:#cccccc">'+settings.off_label+'<\/span><\/div>');
|
|
||||||
}else{
|
// insert the new toggle markup
|
||||||
$(this).after('<div class="toggleSwitch"><span class="leftLabel" style="color:#cccccc;">'+settings.on_label+'<\/span><div class="switchArea" style="background-color: '+settings.off_bg_color+'"><span class="switchHandle right" style="margin-left:0px"><\/span><\/div><span class="rightLabel">'+settings.off_label+'<\/span><\/div>');
|
if($(this).attr("checked") == "checked" || $(this).attr("checked") == true){
|
||||||
|
$(this).after('<div class="toggleSwitch"><span class="leftLabel">'+settings.on_label+'<\/span><div class="switchArea on" style="background-color: '+settings.on_bg_color+'"><span class="switchHandle left" style="margin-left: 15px;"><\/span><\/div><span class="rightLabel" style="color:#cccccc">'+settings.off_label+'<\/span><\/div>');
|
||||||
|
}else{
|
||||||
|
$(this).after('<div class="toggleSwitch"><span class="leftLabel" style="color:#cccccc;">'+settings.on_label+'<\/span><div class="switchArea" style="background-color: '+settings.off_bg_color+'"><span class="switchHandle right" style="margin-left:0px"><\/span><\/div><span class="rightLabel">'+settings.off_label+'<\/span><\/div>');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bind the switchHandle click events to the internal toggle function
|
||||||
|
$(this).next().find('div.switchArea').bind("click", function () {
|
||||||
|
toggle($(this).find('.switchHandle'));
|
||||||
|
})
|
||||||
|
|
||||||
|
} else if (action == 'sync') {
|
||||||
|
element = $(this).next().find('.switchHandle');
|
||||||
|
|
||||||
|
if ($(this).is(':checked'))
|
||||||
|
showCheckedState(element);
|
||||||
|
else
|
||||||
|
showUncheckedState(element);
|
||||||
|
} else {
|
||||||
|
console.log('unknown action for the checkToggle plugin')
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bind the switchHandle click events to the internal toggle function
|
|
||||||
$(this).next().find('div.switchArea').bind("click", function () {
|
|
||||||
toggle($(this).find('.switchHandle')); })
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
})(jQuery);
|
})(jQuery);
|
Loading…
Reference in New Issue
Block a user