From 8d44bb72ac48574c38cff49b8ed311c037eff950 Mon Sep 17 00:00:00 2001 From: Francisco Marcelo de Araújo Lima Júnior Date: Mon, 25 Aug 2014 17:03:41 -0300 Subject: [PATCH] add infra --- app/controllers/my_profile/profile_editor_controller.rb | 3 +++ app/controllers/public/account_controller.rb | 9 +++------ app/views/account/_signup_form.html.erb | 69 +++++++++++++++++++++++++++++++++++---------------------------------- app/views/profile_editor/_person_form.html.erb | 39 ++++++++++++++++++++++++++++----------- public/javascripts/manage-fields.js | 69 +++++++++++++-------------------------------------------------------- 5 files changed, 82 insertions(+), 107 deletions(-) diff --git a/app/controllers/my_profile/profile_editor_controller.rb b/app/controllers/my_profile/profile_editor_controller.rb index 3ee21a3..0ee1bec 100644 --- a/app/controllers/my_profile/profile_editor_controller.rb +++ b/app/controllers/my_profile/profile_editor_controller.rb @@ -11,6 +11,9 @@ class ProfileEditorController < MyProfileController # edits the profile info (posts back) def edit + + #raise params.inspect + @profile_data = profile @possible_domains = profile.possible_domains if request.post? diff --git a/app/controllers/public/account_controller.rb b/app/controllers/public/account_controller.rb index ea9a9cf..946a626 100644 --- a/app/controllers/public/account_controller.rb +++ b/app/controllers/public/account_controller.rb @@ -66,12 +66,9 @@ class AccountController < ApplicationController end def custom_fields_for_template - custom_fields ||= environment.people.templates.find(params[:template_id]).custom_fields.keys - #raise custom_fields.inspect - - custom_fields = [{ :name => "custom_field_4", :label => "bli"}, - { :name => "custom_field_5", :label => "ajsdfh"}, - { :name => "custom_field_6", :label => "ytytyty"}] + custom_fields ||= environment.people.templates.find(params[:template_id]).custom_fields.map {|k,v| + { :name => k, :label => v[:label] } + } render :text => {:ok => true, :custom_fields => custom_fields}.to_json end diff --git a/app/views/account/_signup_form.html.erb b/app/views/account/_signup_form.html.erb index ff2f46f..a926d26 100644 --- a/app/views/account/_signup_form.html.erb +++ b/app/views/account/_signup_form.html.erb @@ -29,37 +29,6 @@
- - - <%= template_options(:people, 'profile_data') %> -
<%= label(:user, :login, _('Username'), {:class => 'formlabel'}) %> <%= environment.default_hostname %>/ @@ -134,9 +103,41 @@
- <%= labelled_fields_for :profile_data, @person do |f| %> - <%= render :partial => 'profile_editor/person_form', :locals => {:f => f} %> - <% end %> + + + <%= template_options(:people, 'profile_data') %> + + <%#= 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("") %> diff --git a/app/views/profile_editor/_person_form.html.erb b/app/views/profile_editor/_person_form.html.erb index fe3cc6e..bc3771a 100644 --- a/app/views/profile_editor/_person_form.html.erb +++ b/app/views/profile_editor/_person_form.html.erb @@ -7,17 +7,6 @@
<% end %> -<% @environment.custom_person_fields_customs.each { |k| %> - <% optional_field(@person, k) do %> -
- <%= label_tag environment.custom_person_field_name(k), nil, class: 'formlabel' %> -
- <%= text_field_tag("profile_data[custom_fields][#{k}]", @person.custom_field_value(k)) %> -
-
- <% end %> -<% } %> - <%= optional_field(@person, 'description', f.text_area(:description, :rows => 5, :rel => _('Description'))) %> <%= optional_field(@person, 'preferred_domain', select_preferred_domain(:profile_data)) %> <%= optional_field(@person, 'contact_information', f.text_field(:contact_information, :rel => _('Contact information'))) %> @@ -76,3 +65,31 @@ <%= 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') %>

+ +<%= javascript_include_tag "manage-fields.js" %> + +
+<% @person.custom_fields.each { |key,value| %> +
+
+ <%= text_field_tag( "profile_data[custom_fields][#{key}][label]", value[:label], :style => "display:block") %> +
+ <%= text_field_tag( "profile_data[custom_fields][#{key}][value]", "", :size => 30 ) %> +
+ Delete + +
+
+<% } %> +
+ +<% if @person.is_template? %> + + <%= link_to_function(_('Add field'), "add_new_field('person');", :class => 'button icon-add with-text') %> + +<% end %> + +

diff --git a/public/javascripts/manage-fields.js b/public/javascripts/manage-fields.js index 2cfafe0..617a97a 100644 --- a/public/javascripts/manage-fields.js +++ b/public/javascripts/manage-fields.js @@ -119,69 +119,26 @@ function new_field_action(){ function remove_custom_field(element) { jQuery(element).parent().parent().remove(); + //field = jQuery(element).parent().parent(); + //console.log( field ); return false; } function add_new_field(profile_type) { - console.log( profile_type ); - - last_row = jQuery('#' + profile_type + '_fields_conf > tbody:last tr:last'); - - if ( last_row.find('label').length == 1 ) { - - var row = '' + - '' + - '' + - '' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - 'Delete ' + - ' ' + - ''; - - jQuery('#' + profile_type + '_fields_conf > tbody:last').append(row); + var custom_field_counter = jQuery('#custom-fields-container').find("div.field-with-privacy-selector").length + 1; - } - else { - - var new_field = jQuery('#' + profile_type + '_fields_conf > tbody:last tr:last').clone(); - - var field = new_field.find('input'); - //var chkboxes = field.filter(':checkbox'); - - var re = new RegExp( '\\d', 'g' ); - var id = field.attr('id').match(re); - var next_id = parseInt(id) + 1; - - jQuery.each( field, function( k, v ) { - v.id = v.id.replace(id, next_id); - v.name = v.name.replace(id, next_id); - if (v.type == 'text') { v.value = '' } - if (v.type == 'checkbox') { v.value = true; } - if (v.type == 'hidden') { v.value = false; } + var row = '
' + + '
' + + '' + + '
' + + '' + + '
' + + 'Delete ' + + '
' + + '
'; - }); - - //field.val(''); - - //chkboxes.attr('onclick', chkboxes.attr('onclick').replace(id, next_id)); - //console.log( chkboxes ); - - jQuery('#' + profile_type + '_fields_conf > tbody').append(new_field); - - } + jQuery('#custom-fields-container').append(row); } -- libgit2 0.21.2