Commit c89067165b0d31f42565daa2c76fee60c3f526b7
1 parent
03935b39
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
add infra
Showing
2 changed files
with
35 additions
and
1 deletions
Show diff stats
app/controllers/public/account_controller.rb
| @@ -65,6 +65,17 @@ class AccountController < ApplicationController | @@ -65,6 +65,17 @@ class AccountController < ApplicationController | ||
| 65 | render :text => { :ok=>true, :key=>key }.to_json | 65 | render :text => { :ok=>true, :key=>key }.to_json |
| 66 | end | 66 | end |
| 67 | 67 | ||
| 68 | + def custom_fields_for_template | ||
| 69 | + custom_fields ||= environment.people.templates.find(params[:template_id]).custom_fields.keys | ||
| 70 | + #raise custom_fields.inspect | ||
| 71 | + | ||
| 72 | + custom_fields = [{ :name => "custom_field_4", :label => "bli"}, | ||
| 73 | + { :name => "custom_field_5", :label => "ajsdfh"}, | ||
| 74 | + { :name => "custom_field_6", :label => "ytytyty"}] | ||
| 75 | + | ||
| 76 | + render :text => {:ok => true, :custom_fields => custom_fields}.to_json | ||
| 77 | + end | ||
| 78 | + | ||
| 68 | # action to register an user to the application | 79 | # action to register an user to the application |
| 69 | def signup | 80 | def signup |
| 70 | if @plugins.dispatch(:allow_user_registration).include?(false) | 81 | if @plugins.dispatch(:allow_user_registration).include?(false) |
app/views/account/_signup_form.html.erb
| @@ -31,7 +31,30 @@ | @@ -31,7 +31,30 @@ | ||
| 31 | 31 | ||
| 32 | <script> | 32 | <script> |
| 33 | function show_fields_for_template(element) { | 33 | function show_fields_for_template(element) { |
| 34 | - // code here | 34 | + jQuery('div#signup-form-profile div.formfieldline').remove(); |
| 35 | + var selected_template = element.options[element.selectedIndex].value; | ||
| 36 | + jQuery.ajax({ | ||
| 37 | + type: "GET", | ||
| 38 | + url: "<%= url_for :controller=>'account', :action=>'custom_fields_for_template' %>", | ||
| 39 | + dataType: 'json', | ||
| 40 | + data: { template_id : selected_template }, | ||
| 41 | + success: function(data) { | ||
| 42 | + if (data.ok) { | ||
| 43 | + data.custom_fields.each(function(field) { | ||
| 44 | + html = '<div class="formfieldline">' + | ||
| 45 | + '<label class="formlabel" for="profile_data_custom_fields_{#CUSTOM_FIELD_ID#}">{#CUSTOM_FIELD_NAME#}</label>' + | ||
| 46 | + '<div class="formfield type-text">' + | ||
| 47 | + '<input type="text" name="profile_data[custom_fields][{#CUSTOM_FIELD_ID#}]" id="profile_data_custom_fields_{#CUSTOM_FIELD_ID#}" />' + | ||
| 48 | + '</div>' + | ||
| 49 | + '</div>'; | ||
| 50 | + | ||
| 51 | + html = html.replace( /{#CUSTOM_FIELD_ID#}/g, field.name ); | ||
| 52 | + html = html.replace( /{#CUSTOM_FIELD_NAME#}/g, field.label ); | ||
| 53 | + jQuery('div#signup-form-profile').append(html); | ||
| 54 | + }); | ||
| 55 | + }; | ||
| 56 | + } | ||
| 57 | + }); | ||
| 35 | } | 58 | } |
| 36 | </script> | 59 | </script> |
| 37 | 60 |