Commit b06e2399a4a9aec1b7811351037f156efc96b2c0
1 parent
4c3176e0
Exists in
profile_api_improvements
Custom Fields Improvements
Signed-off-by: Tallys Martins <tallysmartins@gmail.com>
Showing
3 changed files
with
11 additions
and
2 deletions
Show diff stats
app/helpers/forms_helper.rb
@@ -7,7 +7,7 @@ module FormsHelper | @@ -7,7 +7,7 @@ module FormsHelper | ||
7 | 7 | ||
8 | def labelled_check_box( human_name, name, value = "1", checked = false, options = {} ) | 8 | def labelled_check_box( human_name, name, value = "1", checked = false, options = {} ) |
9 | options[:id] ||= 'checkbox-' + FormsHelper.next_id_number | 9 | options[:id] ||= 'checkbox-' + FormsHelper.next_id_number |
10 | - html = options[:add_hidden] == false ? "" : hidden_field_tag(name, '0') | 10 | + html = options[:add_hidden] == false ? "".html_safe : hidden_field_tag(name, '0') |
11 | 11 | ||
12 | html += check_box_tag( name, value, checked, options ) + | 12 | html += check_box_tag( name, value, checked, options ) + |
13 | content_tag( 'label', human_name, :for => options[:id] ) | 13 | content_tag( 'label', human_name, :for => options[:id] ) |
app/models/concerns/customizable.rb
@@ -115,6 +115,14 @@ module Customizable | @@ -115,6 +115,14 @@ module Customizable | ||
115 | return_list | 115 | return_list |
116 | end | 116 | end |
117 | 117 | ||
118 | + def custom_values_hash | ||
119 | + hash = {} | ||
120 | + self.custom_field_values.includes(:custom_field).each do |cfv| | ||
121 | + hash[cfv.custom_field.name.to_sym] = cfv.value | ||
122 | + end | ||
123 | + hash | ||
124 | + end | ||
125 | + | ||
118 | def save_custom_values | 126 | def save_custom_values |
119 | parse_custom_values.each(&:save) | 127 | parse_custom_values.each(&:save) |
120 | end | 128 | end |
app/models/person.rb
@@ -577,7 +577,8 @@ class Person < Profile | @@ -577,7 +577,8 @@ class Person < Profile | ||
577 | 577 | ||
578 | # by default, all fields are private | 578 | # by default, all fields are private |
579 | def public_fields | 579 | def public_fields |
580 | - self.fields_privacy.nil? ? [] : self.fields_privacy.reject{ |k, v| v != 'public' }.keys.map(&:to_s) | 580 | + (self.fields_privacy.nil? ? [] : self.fields_privacy.reject{ |k, v| v != 'public' }.keys.map(&:to_s) + |
581 | + self.custom_field_values.includes(:custom_field).reject{ |c| !c.public }.collect{ |f| f.custom_field.name }) | ||
581 | end | 582 | end |
582 | 583 | ||
583 | include Noosfero::Gravatar | 584 | include Noosfero::Gravatar |