Commit 8d44bb72ac48574c38cff49b8ed311c037eff950
1 parent
c8906716
Exists in
staging
and in
7 other branches
add infra
Showing
5 changed files
with
82 additions
and
107 deletions
Show diff stats
app/controllers/my_profile/profile_editor_controller.rb
@@ -11,6 +11,9 @@ class ProfileEditorController < MyProfileController | @@ -11,6 +11,9 @@ class ProfileEditorController < MyProfileController | ||
11 | 11 | ||
12 | # edits the profile info (posts back) | 12 | # edits the profile info (posts back) |
13 | def edit | 13 | def edit |
14 | + | ||
15 | + #raise params.inspect | ||
16 | + | ||
14 | @profile_data = profile | 17 | @profile_data = profile |
15 | @possible_domains = profile.possible_domains | 18 | @possible_domains = profile.possible_domains |
16 | if request.post? | 19 | if request.post? |
app/controllers/public/account_controller.rb
@@ -66,12 +66,9 @@ class AccountController < ApplicationController | @@ -66,12 +66,9 @@ class AccountController < ApplicationController | ||
66 | end | 66 | end |
67 | 67 | ||
68 | def custom_fields_for_template | 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"}] | 69 | + custom_fields ||= environment.people.templates.find(params[:template_id]).custom_fields.map {|k,v| |
70 | + { :name => k, :label => v[:label] } | ||
71 | + } | ||
75 | 72 | ||
76 | render :text => {:ok => true, :custom_fields => custom_fields}.to_json | 73 | render :text => {:ok => true, :custom_fields => custom_fields}.to_json |
77 | end | 74 | end |
app/views/account/_signup_form.html.erb
@@ -29,37 +29,6 @@ | @@ -29,37 +29,6 @@ | ||
29 | 29 | ||
30 | <div id='signup-form-header'> | 30 | <div id='signup-form-header'> |
31 | 31 | ||
32 | - <script> | ||
33 | - function show_fields_for_template(element) { | ||
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 | - }); | ||
58 | - } | ||
59 | - </script> | ||
60 | - | ||
61 | - <%= template_options(:people, 'profile_data') %> | ||
62 | - | ||
63 | <div id='signup-formfield-group'> | 32 | <div id='signup-formfield-group'> |
64 | <%= label(:user, :login, _('Username'), {:class => 'formlabel'}) %> | 33 | <%= label(:user, :login, _('Username'), {:class => 'formlabel'}) %> |
65 | <span id="signup-domain"><%= environment.default_hostname %>/</span> | 34 | <span id="signup-domain"><%= environment.default_hostname %>/</span> |
@@ -134,9 +103,41 @@ | @@ -134,9 +103,41 @@ | ||
134 | 103 | ||
135 | <div id="signup-form-profile"> | 104 | <div id="signup-form-profile"> |
136 | 105 | ||
137 | - <%= labelled_fields_for :profile_data, @person do |f| %> | ||
138 | - <%= render :partial => 'profile_editor/person_form', :locals => {:f => f} %> | ||
139 | - <% end %> | 106 | + <script> |
107 | + function show_fields_for_template(element) { | ||
108 | + jQuery('div#signup-form-profile div.formfieldline').remove(); | ||
109 | + var selected_template = element.options[element.selectedIndex].value; | ||
110 | + jQuery.ajax({ | ||
111 | + type: "GET", | ||
112 | + url: "<%= url_for :controller=>'account', :action=>'custom_fields_for_template' %>", | ||
113 | + dataType: 'json', | ||
114 | + data: { template_id : selected_template }, | ||
115 | + success: function(data) { | ||
116 | + if (data.ok) { | ||
117 | + data.custom_fields.each(function(field) { | ||
118 | + html = '<div class="formfieldline">' + | ||
119 | + '<label class="formlabel" for="profile_data_custom_fields_{#CUSTOM_FIELD_ID#}">{#CUSTOM_FIELD_NAME#}</label>' + | ||
120 | + '<input type="hidden" name="profile_data[custom_fields][{#CUSTOM_FIELD_ID#}][label]" id="profile_data_custom_fields_{#CUSTOM_FIELD_ID#}_label" value="{#CUSTOM_FIELD_NAME#}" />' + | ||
121 | + '<div class="formfield type-text">' + | ||
122 | + '<input type="text" name="profile_data[custom_fields][{#CUSTOM_FIELD_ID#}][value]" id="profile_data_custom_fields_{#CUSTOM_FIELD_ID#}_value" />' + | ||
123 | + '</div>' + | ||
124 | + '</div>'; | ||
125 | + | ||
126 | + html = html.replace( /{#CUSTOM_FIELD_ID#}/g, field.name ); | ||
127 | + html = html.replace( /{#CUSTOM_FIELD_NAME#}/g, field.label ); | ||
128 | + jQuery('div#signup-form-profile').append(html); | ||
129 | + }); | ||
130 | + }; | ||
131 | + } | ||
132 | + }); | ||
133 | + } | ||
134 | + </script> | ||
135 | + | ||
136 | + <%= template_options(:people, 'profile_data') %> | ||
137 | + | ||
138 | + <%#= labelled_fields_for :profile_data, @person do |f| %> | ||
139 | + <%#= render :partial => 'profile_editor/person_form', :locals => {:f => f} %> | ||
140 | + <%# end %> | ||
140 | 141 | ||
141 | <%= @plugins.dispatch(:signup_extra_contents).collect { |content| instance_eval(&content) }.join("") %> | 142 | <%= @plugins.dispatch(:signup_extra_contents).collect { |content| instance_eval(&content) }.join("") %> |
142 | 143 |
app/views/profile_editor/_person_form.html.erb
@@ -7,17 +7,6 @@ | @@ -7,17 +7,6 @@ | ||
7 | </div> | 7 | </div> |
8 | <% end %> | 8 | <% end %> |
9 | 9 | ||
10 | -<% @environment.custom_person_fields_customs.each { |k| %> | ||
11 | - <% optional_field(@person, k) do %> | ||
12 | - <div class="formfieldline"> | ||
13 | - <%= label_tag environment.custom_person_field_name(k), nil, class: 'formlabel' %> | ||
14 | - <div class="formfield type-select"> | ||
15 | - <%= text_field_tag("profile_data[custom_fields][#{k}]", @person.custom_field_value(k)) %> | ||
16 | - </div> | ||
17 | - </div> | ||
18 | - <% end %> | ||
19 | -<% } %> | ||
20 | - | ||
21 | <%= optional_field(@person, 'description', f.text_area(:description, :rows => 5, :rel => _('Description'))) %> | 10 | <%= optional_field(@person, 'description', f.text_area(:description, :rows => 5, :rel => _('Description'))) %> |
22 | <%= optional_field(@person, 'preferred_domain', select_preferred_domain(:profile_data)) %> | 11 | <%= optional_field(@person, 'preferred_domain', select_preferred_domain(:profile_data)) %> |
23 | <%= optional_field(@person, 'contact_information', f.text_field(:contact_information, :rel => _('Contact information'))) %> | 12 | <%= optional_field(@person, 'contact_information', f.text_field(:contact_information, :rel => _('Contact information'))) %> |
@@ -76,3 +65,31 @@ | @@ -76,3 +65,31 @@ | ||
76 | <%= optional_field(@person, 'organization', f.text_field(:organization, :rel => _('Organization'))) %> | 65 | <%= optional_field(@person, 'organization', f.text_field(:organization, :rel => _('Organization'))) %> |
77 | <%= optional_field(@person, 'organization_website', f.text_field(:organization_website, :rel => _('Organization website'))) %> | 66 | <%= optional_field(@person, 'organization_website', f.text_field(:organization_website, :rel => _('Organization website'))) %> |
78 | 67 | ||
68 | +<br /> | ||
69 | + | ||
70 | +<h2><%= _('Custom fields') %></h2> | ||
71 | + | ||
72 | +<%= javascript_include_tag "manage-fields.js" %> | ||
73 | + | ||
74 | +<div id="custom-fields-container" style="border:1px solid red; margin-bottom: 10px;"> | ||
75 | +<% @person.custom_fields.each { |key,value| %> | ||
76 | + <div class="field-with-privacy-selector"> | ||
77 | + <div class="formfieldline"> | ||
78 | + <%= text_field_tag( "profile_data[custom_fields][#{key}][label]", value[:label], :style => "display:block") %> | ||
79 | + <div class="formfield type-text" style="display: inline-block;"> | ||
80 | + <%= text_field_tag( "profile_data[custom_fields][#{key}][value]", "", :size => 30 ) %> | ||
81 | + </div><a href="#" class="button icon-delete" title="Delete" onclick="return remove_custom_field(this);"> | ||
82 | + <span>Delete</span> | ||
83 | + </a> | ||
84 | + </div> | ||
85 | + </div> | ||
86 | +<% } %> | ||
87 | +</div> | ||
88 | + | ||
89 | +<% if @person.is_template? %> | ||
90 | + <span> | ||
91 | + <%= link_to_function(_('Add field'), "add_new_field('person');", :class => 'button icon-add with-text') %> | ||
92 | + </span> | ||
93 | +<% end %> | ||
94 | + | ||
95 | +<br /><br /> |
public/javascripts/manage-fields.js
@@ -119,69 +119,26 @@ function new_field_action(){ | @@ -119,69 +119,26 @@ function new_field_action(){ | ||
119 | 119 | ||
120 | function remove_custom_field(element) { | 120 | function remove_custom_field(element) { |
121 | jQuery(element).parent().parent().remove(); | 121 | jQuery(element).parent().parent().remove(); |
122 | + //field = jQuery(element).parent().parent(); | ||
123 | + //console.log( field ); | ||
122 | return false; | 124 | return false; |
123 | } | 125 | } |
124 | 126 | ||
125 | function add_new_field(profile_type) { | 127 | function add_new_field(profile_type) { |
126 | 128 | ||
127 | - console.log( profile_type ); | ||
128 | - | ||
129 | - last_row = jQuery('#' + profile_type + '_fields_conf > tbody:last tr:last'); | ||
130 | - | ||
131 | - if ( last_row.find('label').length == 1 ) { | ||
132 | - | ||
133 | - var row = '<tr>' + | ||
134 | - '<td>' + | ||
135 | - '<input id="' + profile_type + '_fields_custom_field_1_name" maxlength="20" name="' + profile_type + '_fields[custom_field_1][name]" type="text" />' + | ||
136 | - '</td>' + | ||
137 | - '<td align="center"> ' + | ||
138 | - '<input id="' + profile_type + '_fields_custom_field_1_active" name="' + profile_type + '_fields[custom_field_1][active]" type="hidden" value="false" /> ' + | ||
139 | - '<input id="' + profile_type + '_fields_custom_field_1_active" name="' + profile_type + '_fields[custom_field_1][active]" type="checkbox" value="false" /> ' + | ||
140 | - '</td> ' + | ||
141 | - '<td align="center"> ' + | ||
142 | - '<input id="' + profile_type + '_fields_custom_field_1_required" name="' + profile_type + '_fields[custom_field_1][required]" type="hidden" value="false" /> ' + | ||
143 | - '<input id="' + profile_type + '_fields_custom_field_1_required" name="' + profile_type + '_fields[custom_field_1][required]" type="checkbox" value="true" /> ' + | ||
144 | - '</td> ' + | ||
145 | - '<td align="center"> ' + | ||
146 | - '<input id="' + profile_type + '_fields_custom_field_1_signup" name="' + profile_type + '_fields[custom_field_1][signup]" type="hidden" value="false" /> ' + | ||
147 | - '<input id="' + profile_type + '_fields_custom_field_1_signup" name="' + profile_type + '_fields[custom_field_1][signup]" type="checkbox" value="true" /> ' + | ||
148 | - '</td> ' + | ||
149 | - '<td> ' + | ||
150 | - '<a href="#" class="button icon-delete delete-link-list-row" title="Delete" onclick="return remove_custom_field(this);"><span>Delete</span></a> ' + | ||
151 | - '</td> ' + | ||
152 | - '</tr>'; | ||
153 | - | ||
154 | - jQuery('#' + profile_type + '_fields_conf > tbody:last').append(row); | 129 | + var custom_field_counter = jQuery('#custom-fields-container').find("div.field-with-privacy-selector").length + 1; |
155 | 130 | ||
156 | - } | ||
157 | - else { | ||
158 | - | ||
159 | - var new_field = jQuery('#' + profile_type + '_fields_conf > tbody:last tr:last').clone(); | ||
160 | - | ||
161 | - var field = new_field.find('input'); | ||
162 | - //var chkboxes = field.filter(':checkbox'); | ||
163 | - | ||
164 | - var re = new RegExp( '\\d', 'g' ); | ||
165 | - var id = field.attr('id').match(re); | ||
166 | - var next_id = parseInt(id) + 1; | ||
167 | - | ||
168 | - jQuery.each( field, function( k, v ) { | ||
169 | - v.id = v.id.replace(id, next_id); | ||
170 | - v.name = v.name.replace(id, next_id); | ||
171 | - if (v.type == 'text') { v.value = '' } | ||
172 | - if (v.type == 'checkbox') { v.value = true; } | ||
173 | - if (v.type == 'hidden') { v.value = false; } | 131 | + var row = '<div class="field-with-privacy-selector">' + |
132 | + '<div class="formfieldline">' + | ||
133 | + '<input id="profile_data_custom_fields_custom_field_' + custom_field_counter + '_label" name="profile_data[custom_fields][custom_field_' + custom_field_counter + '][label]" value="label" style="display:block" />' + | ||
134 | + '<div class="formfield type-text" style="display: inline-block;">' + | ||
135 | + '<input id="profile_data_custom_fields_custom_field_' + custom_field_counter + '_value" name="profile_data[custom_fields][custom_field_' + custom_field_counter + '][value]" size="30" type="text">' + | ||
136 | + '</div>' + | ||
137 | + '<a href="#" class="button icon-delete delete-link-list-row" title="Delete" onclick="return remove_custom_field(this);"><span>Delete</span></a> ' + | ||
138 | + '</div>' + | ||
139 | + '</div>'; | ||
174 | 140 | ||
175 | - }); | ||
176 | - | ||
177 | - //field.val(''); | ||
178 | - | ||
179 | - //chkboxes.attr('onclick', chkboxes.attr('onclick').replace(id, next_id)); | ||
180 | - //console.log( chkboxes ); | ||
181 | - | ||
182 | - jQuery('#' + profile_type + '_fields_conf > tbody').append(new_field); | ||
183 | - | ||
184 | - } | 141 | + jQuery('#custom-fields-container').append(row); |
185 | 142 | ||
186 | } | 143 | } |
187 | 144 |