Commit a4bfc4d910327642e65561d9c28dd32b636e4895
1 parent
13f3dd76
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
add infra
Showing
8 changed files
with
186 additions
and
9 deletions
Show diff stats
app/controllers/admin/features_controller.rb
@@ -17,17 +17,23 @@ class FeaturesController < AdminController | @@ -17,17 +17,23 @@ class FeaturesController < AdminController | ||
17 | 17 | ||
18 | def manage_fields | 18 | def manage_fields |
19 | @person_fields = Person.fields | 19 | @person_fields = Person.fields |
20 | + @custom_person_fields = [] | ||
21 | + @environment.settings[:custom_person_fields].each{|k,v| @custom_person_fields << k if k =~ /^custom_field/ && ! @custom_person_fields.include?(k) } | ||
20 | @enterprise_fields = Enterprise.fields | 22 | @enterprise_fields = Enterprise.fields |
21 | @community_fields = Community.fields | 23 | @community_fields = Community.fields |
22 | end | 24 | end |
23 | 25 | ||
24 | def manage_person_fields | 26 | def manage_person_fields |
25 | environment.custom_person_fields = params[:person_fields] | 27 | environment.custom_person_fields = params[:person_fields] |
28 | + | ||
29 | + #raise params[:person_fields].inspect | ||
30 | + | ||
26 | if environment.save! | 31 | if environment.save! |
27 | session[:notice] = _('Person fields updated successfully.') | 32 | session[:notice] = _('Person fields updated successfully.') |
28 | else | 33 | else |
29 | flash[:error] = _('Person fields not updated successfully.') | 34 | flash[:error] = _('Person fields not updated successfully.') |
30 | end | 35 | end |
36 | + | ||
31 | redirect_to :action => 'manage_fields' | 37 | redirect_to :action => 'manage_fields' |
32 | end | 38 | end |
33 | 39 |
app/helpers/application_helper.rb
@@ -809,6 +809,12 @@ module ApplicationHelper | @@ -809,6 +809,12 @@ module ApplicationHelper | ||
809 | form_for(name, { :builder => NoosferoFormBuilder }.merge(options), &proc) | 809 | form_for(name, { :builder => NoosferoFormBuilder }.merge(options), &proc) |
810 | end | 810 | end |
811 | 811 | ||
812 | + def optional_custom_field(profile) | ||
813 | + result = "" | ||
814 | + | ||
815 | + result | ||
816 | + end | ||
817 | + | ||
812 | def optional_field(profile, name, field_html = nil, only_required = false, &block) | 818 | def optional_field(profile, name, field_html = nil, only_required = false, &block) |
813 | result = "" | 819 | result = "" |
814 | 820 |
app/models/environment.rb
@@ -429,7 +429,9 @@ class Environment < ActiveRecord::Base | @@ -429,7 +429,9 @@ class Environment < ActiveRecord::Base | ||
429 | schooling_status = values['schooling'] | 429 | schooling_status = values['schooling'] |
430 | end | 430 | end |
431 | 431 | ||
432 | - self.settings[:custom_person_fields] = values.delete_if { |key, value| ! Person.fields.include?(key)} | 432 | + self.settings[:custom_person_fields] = values.delete_if { |key, value| |
433 | + ! ( Person.fields.include?(key) || key =~ /^custom_field/ ) | ||
434 | + } | ||
433 | self.settings[:custom_person_fields].each_pair do |key, value| | 435 | self.settings[:custom_person_fields].each_pair do |key, value| |
434 | if value['required'] == 'true' | 436 | if value['required'] == 'true' |
435 | self.settings[:custom_person_fields][key]['active'] = 'true' | 437 | self.settings[:custom_person_fields][key]['active'] = 'true' |
@@ -445,6 +447,16 @@ class Environment < ActiveRecord::Base | @@ -445,6 +447,16 @@ class Environment < ActiveRecord::Base | ||
445 | end | 447 | end |
446 | end | 448 | end |
447 | 449 | ||
450 | + def custom_person_fields_customs() | ||
451 | + custom_fields = [] | ||
452 | + self.settings[:custom_person_fields].each{ |k,v| custom_fields << k if k =~ /^custom_field/ } | ||
453 | + custom_fields | ||
454 | + end | ||
455 | + | ||
456 | + def custom_person_field_name(field) | ||
457 | + self.settings[:custom_person_fields][field]['name'] | ||
458 | + end | ||
459 | + | ||
448 | def custom_person_field(field, status) | 460 | def custom_person_field(field, status) |
449 | if (custom_person_fields[field] && custom_person_fields[field][status] == 'true') | 461 | if (custom_person_fields[field] && custom_person_fields[field][status] == 'true') |
450 | return true | 462 | return true |
app/models/person.rb
@@ -152,7 +152,7 @@ class Person < Profile | @@ -152,7 +152,7 @@ class Person < Profile | ||
152 | organization | 152 | organization |
153 | organization_website | 153 | organization_website |
154 | contact_phone | 154 | contact_phone |
155 | - contact_information | 155 | + contact_informatioin |
156 | ] | 156 | ] |
157 | 157 | ||
158 | validates_multiparameter_assignments | 158 | validates_multiparameter_assignments |
app/views/features/_manage_person_fields.html.erb
1 | <%= labelled_form_for(:environment, :url => {:action => 'manage_person_fields'}) do |f| %> | 1 | <%= labelled_form_for(:environment, :url => {:action => 'manage_person_fields'}) do |f| %> |
2 | 2 | ||
3 | -<table id='person_fields_conf'> | 3 | +<table id='person_fields_conf' border="0"> |
4 | <tr> | 4 | <tr> |
5 | <th><%= _('Field') %></th> | 5 | <th><%= _('Field') %></th> |
6 | <th><%= _('Active') %></th> | 6 | <th><%= _('Active') %></th> |
7 | <th><%= _('Required') %></th> | 7 | <th><%= _('Required') %></th> |
8 | <th><%= _('Display on signup?') %></th> | 8 | <th><%= _('Display on signup?') %></th> |
9 | + <th> </th> | ||
9 | </tr> | 10 | </tr> |
10 | 11 | ||
11 | <tr class='manage-fields-batch-actions'> | 12 | <tr class='manage-fields-batch-actions'> |
12 | <td> | 13 | <td> |
13 | <%= _("Check/Uncheck All")%> | 14 | <%= _("Check/Uncheck All")%> |
14 | </td> | 15 | </td> |
15 | - <td> | 16 | + <td align="center"> |
16 | <input type="checkbox" id="person_active" /> | 17 | <input type="checkbox" id="person_active" /> |
17 | </td> | 18 | </td> |
18 | - <td> | 19 | + <td align="center"> |
19 | <input type="checkbox" id="person_required" /> | 20 | <input type="checkbox" id="person_required" /> |
20 | </td> | 21 | </td> |
21 | - <td> | 22 | + <td align="center"> |
22 | <input type="checkbox" id="person_signup" /> | 23 | <input type="checkbox" id="person_signup" /> |
23 | </td> | 24 | </td> |
25 | + <td> </td> | ||
24 | </tr> | 26 | </tr> |
25 | 27 | ||
26 | <% @person_fields.each do |field| %> | 28 | <% @person_fields.each do |field| %> |
27 | <tr> | 29 | <tr> |
28 | <td><label for="person_fields[<%= field %>][active]"><%= _(field.humanize) %></label></td> | 30 | <td><label for="person_fields[<%= field %>][active]"><%= _(field.humanize) %></label></td> |
29 | - <td> | 31 | + <td align="center"> |
30 | <%= hidden_field_tag "person_fields[#{field}][active]", false %> | 32 | <%= hidden_field_tag "person_fields[#{field}][active]", false %> |
31 | <%= check_box_tag "person_fields[#{field}][active]", true, environment.custom_person_field(field, 'active'), :onclick => "active_action(this, 'person_fields[#{field}][required]', 'person_fields[#{field}][signup]')" %> | 33 | <%= check_box_tag "person_fields[#{field}][active]", true, environment.custom_person_field(field, 'active'), :onclick => "active_action(this, 'person_fields[#{field}][required]', 'person_fields[#{field}][signup]')" %> |
32 | </td> | 34 | </td> |
33 | - <td> | 35 | + <td align="center"> |
34 | <%= hidden_field_tag "person_fields[#{field}][required]", false %> | 36 | <%= hidden_field_tag "person_fields[#{field}][required]", false %> |
35 | <%= check_box_tag "person_fields[#{field}][required]", true, environment.custom_person_field(field, 'required'), :onclick => "required_action('person_fields[#{field}][active]','person_fields[#{field}][required]', 'person_fields[#{field}][signup]')" %> | 37 | <%= check_box_tag "person_fields[#{field}][required]", true, environment.custom_person_field(field, 'required'), :onclick => "required_action('person_fields[#{field}][active]','person_fields[#{field}][required]', 'person_fields[#{field}][signup]')" %> |
36 | </td> | 38 | </td> |
37 | - <td> | 39 | + <td align="center"> |
38 | <%= hidden_field_tag "person_fields[#{field}][signup]", false %> | 40 | <%= hidden_field_tag "person_fields[#{field}][signup]", false %> |
39 | <%= check_box_tag "person_fields[#{field}][signup]", true, environment.custom_person_field(field, 'signup'), :onclick => "signup_action('person_fields[#{field}][active]','person_fields[#{field}][required]', 'person_fields[#{field}][signup]')" %> | 41 | <%= check_box_tag "person_fields[#{field}][signup]", true, environment.custom_person_field(field, 'signup'), :onclick => "signup_action('person_fields[#{field}][active]','person_fields[#{field}][required]', 'person_fields[#{field}][signup]')" %> |
40 | </td> | 42 | </td> |
43 | + <td> </td> | ||
44 | + </tr> | ||
45 | + <% end %> | ||
46 | + | ||
47 | + <% @custom_person_fields.each do |field| %> | ||
48 | + <tr> | ||
49 | + <td> | ||
50 | + <%= text_field_tag "person_fields[#{field}][name]", environment.custom_person_field_name(field) %> | ||
51 | + </td> | ||
52 | + <td align="center"> | ||
53 | + <%= hidden_field_tag "person_fields[#{field}][active]", false %> | ||
54 | + <%= check_box_tag "person_fields[#{field}][active]", true, environment.custom_person_field(field, 'active'), :onclick => "active_action(this, 'person_fields[#{field}][required]', 'person_fields[#{field}][signup]')" %> | ||
55 | + </td> | ||
56 | + <td align="center"> | ||
57 | + <%= hidden_field_tag "person_fields[#{field}][required]", false %> | ||
58 | + <%= check_box_tag "person_fields[#{field}][required]", true, environment.custom_person_field(field, 'required'), :onclick => "required_action('person_fields[#{field}][active]','person_fields[#{field}][required]', 'person_fields[#{field}][signup]')" %> | ||
59 | + </td> | ||
60 | + <td align="center"> | ||
61 | + <%= hidden_field_tag "person_fields[#{field}][signup]", false %> | ||
62 | + <%= check_box_tag "person_fields[#{field}][signup]", true, environment.custom_person_field(field, 'signup'), :onclick => "required_action('person_fields[#{field}][active]','person_fields[#{field}][required]', 'person_fields[#{field}][signup]')" %> | ||
63 | + </td> | ||
64 | + <td> | ||
65 | + <a href="#" class="button icon-delete delete-link-list-row" title="Delete" onclick="return remove_custom_field(this);"><span>Delete</span></a> | ||
66 | + </td> | ||
41 | </tr> | 67 | </tr> |
42 | <% end %> | 68 | <% end %> |
69 | + | ||
43 | </table> | 70 | </table> |
44 | 71 | ||
72 | +<br /> | ||
73 | + | ||
74 | +<%= link_to_function(_('Add field'), 'add_new_field();', :class => 'button icon-add with-text') %> | ||
75 | + | ||
76 | +<%= javascript_include_tag 'edit-profile-fields.js' %> | ||
77 | + | ||
45 | <script type='text/javascript'>// <!-- | 78 | <script type='text/javascript'>// <!-- |
46 | var trs = jQuery('#person_fields_conf tr'); | 79 | var trs = jQuery('#person_fields_conf tr'); |
47 | 80 |
app/views/profile_editor/_person_form.html.erb
@@ -64,3 +64,14 @@ | @@ -64,3 +64,14 @@ | ||
64 | <%= optional_field(@person, 'professional_activity', f.text_field(:professional_activity, :rel => _('Professional activity'))) %> | 64 | <%= optional_field(@person, 'professional_activity', f.text_field(:professional_activity, :rel => _('Professional activity'))) %> |
65 | <%= optional_field(@person, 'organization', f.text_field(:organization, :rel => _('Organization'))) %> | 65 | <%= optional_field(@person, 'organization', f.text_field(:organization, :rel => _('Organization'))) %> |
66 | <%= 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'))) %> |
67 | + | ||
68 | +<hr /> | ||
69 | + | ||
70 | +<% @environment.custom_person_fields_customs.each { |k| %> | ||
71 | + <br /> | ||
72 | + <%= label_tag environment.custom_person_field_name(k) %> | ||
73 | + <%= optional_field(@person, k, text_field_tag("profile_data[#{k}]")) %> | ||
74 | + <br /> | ||
75 | +<% } %> | ||
76 | + | ||
77 | +<hr /> |
app/views/profile_editor/edit.html.erb
@@ -10,8 +10,12 @@ | @@ -10,8 +10,12 @@ | ||
10 | </div> | 10 | </div> |
11 | <% end %> | 11 | <% end %> |
12 | 12 | ||
13 | + <hr /> | ||
14 | + | ||
13 | <%= render :partial => partial_for_class(@profile.class), :locals => { :f => f } %> | 15 | <%= render :partial => partial_for_class(@profile.class), :locals => { :f => f } %> |
14 | 16 | ||
17 | + <hr /> | ||
18 | + | ||
15 | <div id="profile_change_picture_title"> | 19 | <div id="profile_change_picture_title"> |
16 | <h2><%= _('Change picture') %></h2> | 20 | <h2><%= _('Change picture') %></h2> |
17 | <span><%= unchangeable_privacy_field @profile %></span> | 21 | <span><%= unchangeable_privacy_field @profile %></span> |
@@ -0,0 +1,105 @@ | @@ -0,0 +1,105 @@ | ||
1 | +function send_ajax(source_url) { | ||
2 | + jQuery(".link-address").autocomplete({ | ||
3 | + source : function(request, response){ | ||
4 | + jQuery.ajax({ | ||
5 | + type: "GET", | ||
6 | + url: source_url, | ||
7 | + data: {query: request.term}, | ||
8 | + success: function(result){ | ||
9 | + response(result); | ||
10 | + }, | ||
11 | + error: function(ajax, stat, errorThrown) { | ||
12 | + console.log('Link not found : ' + errorThrown); | ||
13 | + } | ||
14 | + }); | ||
15 | + }, | ||
16 | + | ||
17 | + minLength: 3 | ||
18 | + }); | ||
19 | +} | ||
20 | + | ||
21 | +function new_field_action(){ | ||
22 | + send_ajax(jQuery("#page_url").val()); | ||
23 | + | ||
24 | + jQuery(".delete-link-list-row").click(function(){ | ||
25 | + jQuery(this).parent().parent().remove(); | ||
26 | + return false; | ||
27 | + }); | ||
28 | + | ||
29 | + jQuery(document).scrollTop(jQuery('#dropable-link-list').scrollTop()); | ||
30 | +} | ||
31 | + | ||
32 | +function remove_custom_field(element) { | ||
33 | + jQuery(element).parent().parent().remove(); | ||
34 | + return false; | ||
35 | +} | ||
36 | + | ||
37 | +function add_new_field() { | ||
38 | + | ||
39 | + last_row = jQuery('#person_fields_conf > tbody:last tr:last'); | ||
40 | + | ||
41 | + if ( last_row.find('label').length == 1 ) { | ||
42 | + | ||
43 | + var row = '<tr>' + | ||
44 | + '<td>' + | ||
45 | + '<input id="person_fields_custom_field_1_name" maxlength="20" name="person_fields[custom_field_1][name]" type="text" />' + | ||
46 | + '</td>' + | ||
47 | + '<td align="center"> ' + | ||
48 | + '<input id="person_fields_custom_field_1_active" name="person_fields[custom_field_1][active]" type="hidden" value="false" /> ' + | ||
49 | + '<input id="person_fields_custom_field_1_active" name="person_fields[custom_field_1][active]" type="checkbox" value="false" /> ' + | ||
50 | + '</td> ' + | ||
51 | + '<td align="center"> ' + | ||
52 | + '<input id="person_fields_custom_field_1_required" name="person_fields[custom_field_1][required]" type="hidden" value="false" /> ' + | ||
53 | + '<input id="person_fields_custom_field_1_required" name="person_fields[custom_field_1][required]" type="checkbox" value="true" /> ' + | ||
54 | + '</td> ' + | ||
55 | + '<td align="center"> ' + | ||
56 | + '<input id="person_fields_custom_field_1_signup" name="person_fields[custom_field_1][signup]" type="hidden" value="false" /> ' + | ||
57 | + '<input id="person_fields_custom_field_1_signup" name="person_fields[custom_field_1][signup]" type="checkbox" value="true" /> ' + | ||
58 | + '</td> ' + | ||
59 | + '<td> ' + | ||
60 | + '<a href="#" class="button icon-delete delete-link-list-row" title="Delete" onclick="return remove_custom_field(this);"><span>Delete</span></a> ' + | ||
61 | + '</td> ' + | ||
62 | + '</tr>'; | ||
63 | + | ||
64 | + jQuery('#person_fields_conf > tbody:last').append(row); | ||
65 | + | ||
66 | + } | ||
67 | + else { | ||
68 | + | ||
69 | + var new_field = jQuery('#person_fields_conf > tbody:last tr:last').clone(); | ||
70 | + | ||
71 | + var field = new_field.find('input'); | ||
72 | + //var chkboxes = field.filter(':checkbox'); | ||
73 | + | ||
74 | + var re = new RegExp( '\\d', 'g' ); | ||
75 | + var id = field.attr('id').match(re); | ||
76 | + var next_id = parseInt(id) + 1; | ||
77 | + | ||
78 | + jQuery.each( field, function( k, v ) { | ||
79 | + v.id = v.id.replace(id, next_id); | ||
80 | + v.name = v.name.replace(id, next_id); | ||
81 | + if (v.type == 'text') { v.value = '' } | ||
82 | + if (v.type == 'checkbox') { v.value = true; } | ||
83 | + if (v.type == 'hidden') { v.value = false; } | ||
84 | + | ||
85 | + }); | ||
86 | + | ||
87 | + //field.val(''); | ||
88 | + | ||
89 | + //chkboxes.attr('onclick', chkboxes.attr('onclick').replace(id, next_id)); | ||
90 | + //console.log( chkboxes ); | ||
91 | + | ||
92 | + jQuery('#person_fields_conf > tbody').append(new_field); | ||
93 | + | ||
94 | + } | ||
95 | + | ||
96 | +} | ||
97 | + | ||
98 | +jQuery(document).ready(function(){ | ||
99 | + new_field_action(); | ||
100 | + | ||
101 | + //jQuery("#dropable-link-list").sortable({ | ||
102 | + // revert: true, | ||
103 | + // axis: "y" | ||
104 | + //}); | ||
105 | +}); |