diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index ceeb03e..b279d52 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1301,11 +1301,23 @@ module ApplicationHelper
end
def template_options(kind, field_name)
- templates = environment.send(kind).templates
+ templates = environment.send(kind).templates.order('name')
return '' if templates.count == 0
- return hidden_field_tag("#{field_name}[template_id]", templates.first.id) if templates.count == 1
- options = options_for_select(templates.collect{ |template| [template.name, template.id]})
- content_tag('div', content_tag('label', _('Profile organization'), :class => 'formlabel') + (select_tag 'profile_data[template_id]', options, :onchange => 'show_fields_for_template(this);'))
+ if templates.count == 1
+ if templates.first.custom_fields == {}
+ return hidden_field_tag("#{field_name}[template_id]", templates.first.id)
+ else
+ custom_fields = ""
+ templates.first.custom_fields.each { |field, value|
+ custom_fields += content_tag('div', content_tag('label', value[:title].capitalize, :class => 'formlabel') +
+ content_tag('div', text_field_tag( "profile_data[custom_fields][#{field}][title]", ''), :class => 'formfield type-text'), :class => "formfieldline" ) if value[:signup] == 'on'
+ }
+ content_tag('div', custom_fields)
+ end
+ else
+ options = options_for_select(templates.collect{ |template| [template.name, template.id]})
+ content_tag('div', content_tag('label', _('Profile organization'), :class => 'formlabel') + (select_tag 'profile_data[template_id]', options, :onchange => 'show_fields_for_template(this);'))
+ end
end
def expirable_content_reference(content, action, text, url, options = {})
diff --git a/app/models/profile.rb b/app/models/profile.rb
index 66e92dc..13989f2 100644
--- a/app/models/profile.rb
+++ b/app/models/profile.rb
@@ -26,7 +26,11 @@ class Profile < ActiveRecord::Base
settings_items :custom_fields, :default => {}
def custom_field_value(field)
- self.custom_fields[field][:value]
+ if !self.custom_fields.blank?
+ self.custom_fields[field][:value]
+ else
+ ''
+ end
end
def custom_field_title(field)
diff --git a/app/views/account/_signup_form.html.erb b/app/views/account/_signup_form.html.erb
index e435eb8..8df0df2 100644
--- a/app/views/account/_signup_form.html.erb
+++ b/app/views/account/_signup_form.html.erb
@@ -103,41 +103,9 @@
-
-
- <%= template_options(:people, 'profile_data') %>
-
- <%#= labelled_fields_for :profile_data, @person do |f| %>
- <%#= render :partial => 'profile_editor/person_form', :locals => {:f => f} %>
- <%# end %>
+ <%= labelled_fields_for :profile_data, @person do |f| %>
+ <%= render :partial => 'profile_editor/person_form', :locals => {:f => f} %>
+ <% end %>
<%= @plugins.dispatch(:signup_extra_contents).collect { |content| instance_eval(&content) }.join("") %>
@@ -155,6 +123,11 @@
<% end %>
+
+ <%= javascript_include_tag "manage-custom-fields" %>
+ <%= template_options(:people, 'profile_data') %>
+
+
<%= recaptcha_tags :ajax => true, :display => {:theme => 'clean'} if @block_bot %>
diff --git a/app/views/profile_editor/_person.html.erb b/app/views/profile_editor/_person.html.erb
index 604964d..1c9dfc6 100644
--- a/app/views/profile_editor/_person.html.erb
+++ b/app/views/profile_editor/_person.html.erb
@@ -20,6 +20,8 @@
<%= render :partial => 'person_form', :locals => {:f => f} %>
+ <%= render :partial => 'person_form_custom_fields', :locals => {:f => f} %>
+
<%= _('Notification options') %>
<%= select_tag 'profile_data[notification_time]', options_for_select([[_('Disabled'), 0], [_('Hourly'), 1], [_('Half Day'), 12], [_('Daily'), 24]], @profile.notification_time) %>
diff --git a/app/views/profile_editor/_person_form.html.erb b/app/views/profile_editor/_person_form.html.erb
index 291416e..ca25acf 100644
--- a/app/views/profile_editor/_person_form.html.erb
+++ b/app/views/profile_editor/_person_form.html.erb
@@ -64,74 +64,3 @@
<%= optional_field(@person, 'professional_activity', f.text_field(:professional_activity, :rel => _('Professional activity'))) %>
<%= optional_field(@person, 'organization', f.text_field(:organization, :rel => _('Organization'))) %>
<%= optional_field(@person, 'organization_website', f.text_field(:organization_website, :rel => _('Organization website'))) %>
-
-
-
-
-
-
<%= _('Custom fields') %>
-
- <% if @person.is_template? %>
-
- <%= javascript_include_tag "manage-custom-fields.js" %>
-
-
-
- <%= _('Field name') %> |
- <%= _('Display on signup?') %> |
- |
-
-
- <% @person.custom_fields.each { |field,value| %>
-
-
- <%= text_field_tag( "profile_data[custom_fields][#{field}][title]", value[:title], :style => "display:block") %>
- |
-
- <%= check_box_tag "profile_data[custom_fields][#{field}][signup]", value['signup'], value['signup'], :onclick => "signup_action('profile_data[custom_fields][#{field}][active]','profile_data[custom_fields][#{field}][required]', 'profile_data[custom_fields][#{field}][signup]')" %>
- |
-
- <%= link_to content_tag(:span, _('Delete')), '#', onclick: "return remove_custom_field(this);", title: "Delete", class: "button icon-delete" %>
- |
-
- <% } %>
-
-
-
- <% if @person.custom_fields.length > 0 %>
-
- <% end %>
-
-
- <%= link_to_function(_('Add field'), "add_new_field('person');", :class => 'button icon-add with-text') %>
-
-
- <% else %>
-
- <% @person.custom_fields_template.each { |field,value| %>
-
-
-
-
- <%= profile_field_privacy_selector @person, field %>
-
-
-
- <% } %>
-
- <% end %>
-
-
diff --git a/app/views/profile_editor/_person_form_custom_fields.html.erb b/app/views/profile_editor/_person_form_custom_fields.html.erb
new file mode 100644
index 0000000..6ece734
--- /dev/null
+++ b/app/views/profile_editor/_person_form_custom_fields.html.erb
@@ -0,0 +1,76 @@
+<% @person ||= @profile %>
+
+<% if @person.custom_fields_template != {} || @person.is_template? %>
+
+
+
+
+
+
<%= _('Custom fields') %>
+
+ <% if @person.is_template? %>
+
+ <%= javascript_include_tag "manage-custom-fields.js" %>
+
+
+
+ <%= _('Field name') %> |
+ <%= _('Display on signup?') %> |
+ |
+
+
+ <% @person.custom_fields.each { |field,value| %>
+
+
+ <%= text_field_tag( "profile_data[custom_fields][#{field}][title]", value[:title], :style => "display:block", :size => 30, :maxlength => 30) %>
+ |
+
+ <%= check_box_tag "profile_data[custom_fields][#{field}][signup]", value['signup'], value['signup'], :onclick => "signup_action('profile_data[custom_fields][#{field}][active]','profile_data[custom_fields][#{field}][required]', 'profile_data[custom_fields][#{field}][signup]')" %>
+ |
+
+ <%= link_to content_tag(:span, _('Delete')), '#', onclick: "return remove_custom_field(this);", title: "Delete", class: "button icon-delete" %>
+ |
+
+ <% } %>
+
+
+
+ <% if @person.custom_fields.length > 0 %>
+
+ <% end %>
+
+
+ <%= link_to_function(_('Add field'), "add_new_field('person');", :class => 'button icon-add with-text') %>
+
+
+ <% else %>
+
+ <% @person.custom_fields_template.each { |field,value| %>
+
+
+
+
+ <%= profile_field_privacy_selector @person, field %>
+
+
+
+ <% } %>
+
+ <% end %>
+
+
+
+<% end %>
diff --git a/public/javascripts/manage-custom-fields.js b/public/javascripts/manage-custom-fields.js
index be24049..b12acb5 100644
--- a/public/javascripts/manage-custom-fields.js
+++ b/public/javascripts/manage-custom-fields.js
@@ -58,7 +58,7 @@ function add_new_field() {
new_custom_field = '' +
'
' +
'' +
- '' +
+ '' +
' | ' +
'' +
'' +
@@ -70,3 +70,32 @@ function add_new_field() {
jQuery('#custom-fields-container tbody').append(new_custom_field);
}
+
+function show_fields_for_template(element) {
+ jQuery('div#signup-form-custom-fields div.formfieldline').remove();
+ var selected_template = element.options[element.selectedIndex].value;
+ jQuery.ajax({
+ type: "GET",
+ url: "/account/custom_fields_for_template",
+ dataType: 'json',
+ data: { template_id : selected_template },
+ success: function(data) {
+ if (data.ok) {
+ data.custom_fields.each(function(field) {
+ html = '';
+
+ html = html.replace( /{#CUSTOM_FIELD_ID#}/g, field.name );
+ html = html.replace( /{#CUSTOM_FIELD_NAME#}/g, field.title );
+ jQuery('div#signup-form-custom-fields').append(html);
+ });
+ };
+ }
+ });
+}
+
--
libgit2 0.21.2 |