UI compoment to add options for the select type field (wip)

This commit is contained in:
did 2011-12-22 02:59:30 +01:00
parent d1bb45d7c8
commit 81a6569fe7
10 changed files with 44 additions and 10 deletions

View File

@ -9,7 +9,7 @@ GIT
GIT GIT
remote: git://github.com/locomotivecms/custom_fields.git remote: git://github.com/locomotivecms/custom_fields.git
revision: 8bf202d6e0294ca2050ecd7ec44dcc4d570cb7fd revision: 1a8f26a379193c5a60f926eacadc0a9eee7ab5de
branch: experimental branch: experimental
specs: specs:
custom_fields (2.0.0.rc1) custom_fields (2.0.0.rc1)

View File

@ -1,9 +1,15 @@
class Locomotive.Models.CustomField extends Backbone.Model class Locomotive.Models.CustomField extends Backbone.Model
initialize: -> initialize: ->
@_normalize()
unless @get('name')? unless @get('name')?
@set name: @get('label').slugify() @set name: @get('label').slugify()
_normalize: ->
@set
select_options: new Locomotive.Models.CustomFieldSelectOptionsCollection(@get('select_options'))
toJSONForSave: -> toJSONForSave: ->
_.tap {}, (hash) => _.tap {}, (hash) =>
for key, value of @.toJSON() for key, value of @.toJSON()

View File

@ -0,0 +1,13 @@
class Locomotive.Models.CustomFieldSelectOption extends Backbone.Model
toJSONForSave: ->
_.tap {}, (hash) =>
for key, value of @.toJSON()
hash[key] = value unless _.include(['created_at', 'updated_at'], key)
class Locomotive.Models.CustomFieldSelectOptionsCollection extends Backbone.Collection
model: Locomotive.Models.CustomFieldSelectOption
toJSONForSave: ->
@map (model) => model.toJSONForSave()

View File

@ -64,6 +64,7 @@
clear: both; clear: both;
ol { ol {
min-height: 400px;
li.file { li.file {
span.file { span.file {

View File

@ -35,11 +35,11 @@ module Locomotive::CustomFieldsHelper
end end
end end
# def options_for_text_formatting def options_for_text_formatting
# options = %w(none html).map do |option| %w(none html).map do |option|
# [t("locomotive.custom_fields.text_formatting.#{option}"), option] [t("locomotive.custom_fields.text_formatting.#{option}"), option]
# end end
# end end
# def options_for_association_target # def options_for_association_target
# current_site.reload.content_types.collect { |c| [c.name, c.content_klass.to_s] } # current_site.reload.content_types.collect { |c| [c.name, c.content_klass.to_s] }

View File

@ -9,6 +9,14 @@ module Locomotive
end end
end end
def association_primary_key
begin
super
rescue Exception => e
# does not work correctly with embedded collections
end
end
def wrapper_html_options def wrapper_html_options
super.tap do |opts| super.tap do |opts|
opts[:class] += ' no-label' unless render_label? opts[:class] += ' no-label' unless render_label?

View File

@ -40,6 +40,10 @@
= g.input :hint, :input_html => { :class => 'hint' } = g.input :hint, :input_html => { :class => 'hint' }
= g.input :select_options, :as => :'Locomotive::Empty', :wrapper_html => { :style => 'display: none' }
= g.input :text_formatting, :as => :select, :collection => options_for_text_formatting, :include_blank => false, :wrapper_html => { :style => 'display: none' }
%span.actions %span.actions
= link_to 'toggle', '#', :class => 'toggle' = link_to 'toggle', '#', :class => 'toggle'
= link_to 'x', '#', :class => 'remove', :confirm => t('locomotive.messages.confirm') = link_to 'x', '#', :class => 'remove', :confirm => t('locomotive.messages.confirm')

View File

@ -41,7 +41,9 @@ en:
default_site_template: "Use the default site template. Click <a href='#'>here</a> to upload a site template as a zip file instead." default_site_template: "Use the default site template. Click <a href='#'>here</a> to upload a site template as a zip file instead."
content_type: content_type:
raw_item_template: Item template raw_item_template: Item template
api_accounts: Notified Accounts public_form_accounts: Notified Accounts
"custom_fields/field":
select_options: "Options"
content_instance: content_instance:
_slug: Permalink _slug: Permalink
account: account:

View File

@ -45,10 +45,10 @@ x edit my site
x display errors x display errors
x slugify x slugify
x refactor highlighted_field (field id instead of name) x refactor highlighted_field (field id instead of name)
- other content type options x other content type options
- show / hide options of a field based on its type - show / hide options of a field based on its type
- select: add/edit/remove options
- text: formatting - text: formatting
- select: add/edit/remove options
- change in main menu - change in main menu
- manage contents - manage contents
- list - list