UI compoment to add options for the select type field (wip)
This commit is contained in:
parent
d1bb45d7c8
commit
81a6569fe7
@ -9,7 +9,7 @@ GIT
|
||||
|
||||
GIT
|
||||
remote: git://github.com/locomotivecms/custom_fields.git
|
||||
revision: 8bf202d6e0294ca2050ecd7ec44dcc4d570cb7fd
|
||||
revision: 1a8f26a379193c5a60f926eacadc0a9eee7ab5de
|
||||
branch: experimental
|
||||
specs:
|
||||
custom_fields (2.0.0.rc1)
|
||||
|
@ -1,9 +1,15 @@
|
||||
class Locomotive.Models.CustomField extends Backbone.Model
|
||||
|
||||
initialize: ->
|
||||
@_normalize()
|
||||
|
||||
unless @get('name')?
|
||||
@set name: @get('label').slugify()
|
||||
|
||||
_normalize: ->
|
||||
@set
|
||||
select_options: new Locomotive.Models.CustomFieldSelectOptionsCollection(@get('select_options'))
|
||||
|
||||
toJSONForSave: ->
|
||||
_.tap {}, (hash) =>
|
||||
for key, value of @.toJSON()
|
||||
|
@ -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()
|
@ -64,6 +64,7 @@
|
||||
clear: both;
|
||||
|
||||
ol {
|
||||
min-height: 400px;
|
||||
|
||||
li.file {
|
||||
span.file {
|
||||
|
@ -35,11 +35,11 @@ module Locomotive::CustomFieldsHelper
|
||||
end
|
||||
end
|
||||
|
||||
# def options_for_text_formatting
|
||||
# options = %w(none html).map do |option|
|
||||
# [t("locomotive.custom_fields.text_formatting.#{option}"), option]
|
||||
# end
|
||||
# end
|
||||
def options_for_text_formatting
|
||||
%w(none html).map do |option|
|
||||
[t("locomotive.custom_fields.text_formatting.#{option}"), option]
|
||||
end
|
||||
end
|
||||
|
||||
# def options_for_association_target
|
||||
# current_site.reload.content_types.collect { |c| [c.name, c.content_klass.to_s] }
|
||||
|
@ -9,6 +9,14 @@ module Locomotive
|
||||
end
|
||||
end
|
||||
|
||||
def association_primary_key
|
||||
begin
|
||||
super
|
||||
rescue Exception => e
|
||||
# does not work correctly with embedded collections
|
||||
end
|
||||
end
|
||||
|
||||
def wrapper_html_options
|
||||
super.tap do |opts|
|
||||
opts[:class] += ' no-label' unless render_label?
|
||||
|
@ -40,6 +40,10 @@
|
||||
|
||||
= 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
|
||||
= link_to 'toggle', '#', :class => 'toggle'
|
||||
= link_to 'x', '#', :class => 'remove', :confirm => t('locomotive.messages.confirm')
|
@ -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."
|
||||
content_type:
|
||||
raw_item_template: Item template
|
||||
api_accounts: Notified Accounts
|
||||
public_form_accounts: Notified Accounts
|
||||
"custom_fields/field":
|
||||
select_options: "Options"
|
||||
content_instance:
|
||||
_slug: Permalink
|
||||
account:
|
||||
|
4
doc/TODO
4
doc/TODO
@ -45,10 +45,10 @@ x edit my site
|
||||
x display errors
|
||||
x slugify
|
||||
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
|
||||
- select: add/edit/remove options
|
||||
- text: formatting
|
||||
- select: add/edit/remove options
|
||||
- change in main menu
|
||||
- manage contents
|
||||
- list
|
||||
|
@ -4,7 +4,7 @@ require 'mongoid'
|
||||
|
||||
module Mongoid
|
||||
module Document
|
||||
def as_json(options={})
|
||||
def as_json(options = {})
|
||||
attrs = super(options)
|
||||
attrs["id"] = attrs["_id"]
|
||||
attrs
|
||||
|
Loading…
Reference in New Issue
Block a user