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 | |
18 | 18 | def manage_fields |
19 | 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 | 22 | @enterprise_fields = Enterprise.fields |
21 | 23 | @community_fields = Community.fields |
22 | 24 | end |
23 | 25 | |
24 | 26 | def manage_person_fields |
25 | 27 | environment.custom_person_fields = params[:person_fields] |
28 | + | |
29 | + #raise params[:person_fields].inspect | |
30 | + | |
26 | 31 | if environment.save! |
27 | 32 | session[:notice] = _('Person fields updated successfully.') |
28 | 33 | else |
29 | 34 | flash[:error] = _('Person fields not updated successfully.') |
30 | 35 | end |
36 | + | |
31 | 37 | redirect_to :action => 'manage_fields' |
32 | 38 | end |
33 | 39 | ... | ... |
app/helpers/application_helper.rb
... | ... | @@ -809,6 +809,12 @@ module ApplicationHelper |
809 | 809 | form_for(name, { :builder => NoosferoFormBuilder }.merge(options), &proc) |
810 | 810 | end |
811 | 811 | |
812 | + def optional_custom_field(profile) | |
813 | + result = "" | |
814 | + | |
815 | + result | |
816 | + end | |
817 | + | |
812 | 818 | def optional_field(profile, name, field_html = nil, only_required = false, &block) |
813 | 819 | result = "" |
814 | 820 | ... | ... |
app/models/environment.rb
... | ... | @@ -429,7 +429,9 @@ class Environment < ActiveRecord::Base |
429 | 429 | schooling_status = values['schooling'] |
430 | 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 | 435 | self.settings[:custom_person_fields].each_pair do |key, value| |
434 | 436 | if value['required'] == 'true' |
435 | 437 | self.settings[:custom_person_fields][key]['active'] = 'true' |
... | ... | @@ -445,6 +447,16 @@ class Environment < ActiveRecord::Base |
445 | 447 | end |
446 | 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 | 460 | def custom_person_field(field, status) |
449 | 461 | if (custom_person_fields[field] && custom_person_fields[field][status] == 'true') |
450 | 462 | return true | ... | ... |
app/models/person.rb
app/views/features/_manage_person_fields.html.erb
1 | 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 | 4 | <tr> |
5 | 5 | <th><%= _('Field') %></th> |
6 | 6 | <th><%= _('Active') %></th> |
7 | 7 | <th><%= _('Required') %></th> |
8 | 8 | <th><%= _('Display on signup?') %></th> |
9 | + <th> </th> | |
9 | 10 | </tr> |
10 | 11 | |
11 | 12 | <tr class='manage-fields-batch-actions'> |
12 | 13 | <td> |
13 | 14 | <%= _("Check/Uncheck All")%> |
14 | 15 | </td> |
15 | - <td> | |
16 | + <td align="center"> | |
16 | 17 | <input type="checkbox" id="person_active" /> |
17 | 18 | </td> |
18 | - <td> | |
19 | + <td align="center"> | |
19 | 20 | <input type="checkbox" id="person_required" /> |
20 | 21 | </td> |
21 | - <td> | |
22 | + <td align="center"> | |
22 | 23 | <input type="checkbox" id="person_signup" /> |
23 | 24 | </td> |
25 | + <td> </td> | |
24 | 26 | </tr> |
25 | 27 | |
26 | 28 | <% @person_fields.each do |field| %> |
27 | 29 | <tr> |
28 | 30 | <td><label for="person_fields[<%= field %>][active]"><%= _(field.humanize) %></label></td> |
29 | - <td> | |
31 | + <td align="center"> | |
30 | 32 | <%= hidden_field_tag "person_fields[#{field}][active]", false %> |
31 | 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 | 34 | </td> |
33 | - <td> | |
35 | + <td align="center"> | |
34 | 36 | <%= hidden_field_tag "person_fields[#{field}][required]", false %> |
35 | 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 | 38 | </td> |
37 | - <td> | |
39 | + <td align="center"> | |
38 | 40 | <%= hidden_field_tag "person_fields[#{field}][signup]", false %> |
39 | 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 | 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 | 67 | </tr> |
42 | 68 | <% end %> |
69 | + | |
43 | 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 | 78 | <script type='text/javascript'>// <!-- |
46 | 79 | var trs = jQuery('#person_fields_conf tr'); |
47 | 80 | ... | ... |
app/views/profile_editor/_person_form.html.erb
... | ... | @@ -64,3 +64,14 @@ |
64 | 64 | <%= optional_field(@person, 'professional_activity', f.text_field(:professional_activity, :rel => _('Professional activity'))) %> |
65 | 65 | <%= optional_field(@person, 'organization', f.text_field(:organization, :rel => _('Organization'))) %> |
66 | 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 | 10 | </div> |
11 | 11 | <% end %> |
12 | 12 | |
13 | + <hr /> | |
14 | + | |
13 | 15 | <%= render :partial => partial_for_class(@profile.class), :locals => { :f => f } %> |
14 | 16 | |
17 | + <hr /> | |
18 | + | |
15 | 19 | <div id="profile_change_picture_title"> |
16 | 20 | <h2><%= _('Change picture') %></h2> |
17 | 21 | <span><%= unchangeable_privacy_field @profile %></span> | ... | ... |
... | ... | @@ -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 | +}); | ... | ... |