From 5d6ae4ae86f9898c1091f3cf2f2482b3568ed41c Mon Sep 17 00:00:00 2001 From: Francisco Marcelo de Araújo Lima Júnior Date: Fri, 5 Sep 2014 15:15:26 -0300 Subject: [PATCH] fixes --- app/controllers/public/account_controller.rb | 2 +- app/models/profile.rb | 22 ++++++++++++++++++++-- app/views/account/_signup_form.html.erb | 2 +- app/views/profile_editor/_person_form.html.erb | 57 ++++++++++++++------------------------------------------- public/javascripts/manage-custom-fields.js | 49 +------------------------------------------------ 5 files changed, 37 insertions(+), 95 deletions(-) diff --git a/app/controllers/public/account_controller.rb b/app/controllers/public/account_controller.rb index 25d15f8..ac9428a 100644 --- a/app/controllers/public/account_controller.rb +++ b/app/controllers/public/account_controller.rb @@ -67,7 +67,7 @@ class AccountController < ApplicationController def custom_fields_for_template custom_fields ||= environment.people.templates.find(params[:template_id]).custom_fields.map { |k,v| - { :name => k, :label => v[:label] } if v['signup'] + { :name => k, :title => v[:title] } if v['signup'] }.compact render :text => {:ok => true, :custom_fields => custom_fields}.to_json end diff --git a/app/models/profile.rb b/app/models/profile.rb index 54c67d4..66e92dc 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -25,8 +25,26 @@ class Profile < ActiveRecord::Base settings_items :custom_fields, :default => {} - def custom_field_value(key) - self.custom_fields[key] + def custom_field_value(field) + self.custom_fields[field][:value] + end + + def custom_field_title(field) + if !self.custom_fields.blank? + self.custom_fields[field][:title] + else + '' + end + end + + def custom_fields_template + fields = {} + fields = self.template.custom_fields unless self.template.blank? + fields + end + + def custom_fields_template_title(field) + self.template.custom_fields[field][:title] end def self.default_search_display diff --git a/app/views/account/_signup_form.html.erb b/app/views/account/_signup_form.html.erb index dd6c426..e435eb8 100644 --- a/app/views/account/_signup_form.html.erb +++ b/app/views/account/_signup_form.html.erb @@ -124,7 +124,7 @@ ''; html = html.replace( /{#CUSTOM_FIELD_ID#}/g, field.name ); - html = html.replace( /{#CUSTOM_FIELD_NAME#}/g, field.label ); + html = html.replace( /{#CUSTOM_FIELD_NAME#}/g, field.title ); jQuery('div#signup-form-profile').append(html); }); }; diff --git a/app/views/profile_editor/_person_form.html.erb b/app/views/profile_editor/_person_form.html.erb index a503623..291416e 100644 --- a/app/views/profile_editor/_person_form.html.erb +++ b/app/views/profile_editor/_person_form.html.erb @@ -82,13 +82,13 @@   - <% @person.custom_fields.each { |key,value| %> + <% @person.custom_fields.each { |field,value| %> - <%= text_field_tag( "profile_data[custom_fields][#{key}][label]", value[:label], :style => "display:block") %> + <%= text_field_tag( "profile_data[custom_fields][#{field}][title]", value[:title], :style => "display:block") %> - <%= check_box_tag "profile_data[custom_fields][#{key}][signup]", value['signup'], value['signup'], :onclick => "signup_action('profile_data[custom_fields][#{key}][active]','profile_data[custom_fields][#{key}][required]', 'profile_data[custom_fields][#{key}][signup]')" %> + <%= 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" %> @@ -110,54 +110,25 @@ <% else %> - <% template_custom_fields = Profile.find(@person.template_id).custom_fields %> + <% @person.custom_fields_template.each { |field,value| %> - <% template_custom_fields.each { |key,value| %> +
+
- <% if @person.custom_fields.include?(key) %> - -
-
- - - <%= label_tag value[:label] %> - - -
- <%= hidden_field_tag "profile_data[custom_fields][#{key}[title]", @person.custom_fields[key][:title] %> - <% valor = @person.custom_fields[key] ? @person.custom_fields[key][:value] : "" %> - <%= text_field_tag( "profile_data[custom_fields][#{key}][value]", valor, :size => 30 ) %> -
+ + <%= label_tag @person.custom_fields_template_title(field) %> + +
+ <%= hidden_field_tag "profile_data[custom_fields][#{field}[title]", @person.custom_fields_template_title(field) %> + <%= text_field_tag( "profile_data[custom_fields][#{field}][value]", @person.custom_field_value(field), :size => 30 ) %>
- <%= profile_field_privacy_selector @person, key %> - -
- - <% else %> - -
-
- - - <%= label_tag value[:label] %> - - -
- <%= hidden_field_tag "profile_data[custom_fields][#{key}[title]", value[:label] %> - <% valor = key ? value[:value] : "" %> - <%= text_field_tag( "profile_data[custom_fields][#{key}][value]", valor, :size => 30 ) %> -
- -
- - <%= profile_field_privacy_selector @person, key %> -
+ <%= profile_field_privacy_selector @person, field %> - <% end %> +
<% } %> diff --git a/public/javascripts/manage-custom-fields.js b/public/javascripts/manage-custom-fields.js index 8899d43..be24049 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,50 +70,3 @@ function add_new_field() { jQuery('#custom-fields-container tbody').append(new_custom_field); } - -/** -jQuery(document).ready(function(){ - function check_fields(check, table_id, start) { - var checkboxes = jQuery("#" + table_id + " tbody tr td input[type='checkbox']") - for (var i = start; i < checkboxes.length; i+=3) { - checkboxes[i].checked = check - } - } - - function verify_checked(fields_id){ - var checkboxes = jQuery("#" + fields_id + "_fields_conf tbody tr td input[type='checkbox']") - for (var i = 2; i >= 0; i--) { - var allchecked = true - for (var j = i+3; j < checkboxes.length; j+=3) { - if(!checkboxes[j].checked) { - allchecked = false - break - } - } - - var checkbox = jQuery(checkboxes[i+3]).attr("id").split("_") - jQuery("#" + checkbox.first() + "_" + checkbox.last()).attr("checked", allchecked) - } - } - - function check_all(fields_id) { - jQuery("#" + fields_id + "_active").click(function (){check_fields(this.checked, fields_id + "_fields_conf", 0)}) - jQuery("#" + fields_id + "_required").click(function (){check_fields(this.checked, fields_id + "_fields_conf", 1)}) - jQuery("#" + fields_id +"_signup").click(function (){check_fields(this.checked, fields_id + "_fields_conf", 2)}) - verify_checked(fields_id) - } - - //check_all("person") - //check_all("enterprise") - //check_all("community") - - jQuery("input[type='checkbox']").click(function (){ - var checkbox = jQuery(this).attr("id").split("_") - verify_checked(checkbox.first()) - - if(this.checked == false) { - jQuery("#" + checkbox.first() + "_" + checkbox.last()).attr("checked", false) - } - }) -}) -**/ -- libgit2 0.21.2