Commit ff489c4b83e5c38750dca3e20a743c4b60346fc0
Exists in
staging
and in
42 other branches
Merge branch 'AI2962-check_all_manage_fields' of https://gitlab.com/unb-gama/noo…
…sfero into AI2962-check_all_manage_fields
Showing
6 changed files
with
222 additions
and
21 deletions
Show diff stats
app/views/features/_manage_community_fields.rhtml
| ... | ... | @@ -9,21 +9,37 @@ |
| 9 | 9 | <th><%= _('Required') %></th> |
| 10 | 10 | <th><%= _('Display on creation?') %></th> |
| 11 | 11 | </tr> |
| 12 | + | |
| 13 | + <tr style="border-bottom:solid 2px #000"> | |
| 14 | + <td> | |
| 15 | + <%= _("Check/Uncheck All")%> | |
| 16 | + </td> | |
| 17 | + <td> | |
| 18 | + <input type="checkbox" id="community_active" /> | |
| 19 | + </td> | |
| 20 | + <td> | |
| 21 | + <input type="checkbox" id="community_required" /> | |
| 22 | + </td> | |
| 23 | + <td> | |
| 24 | + <input type="checkbox" id="community_signup" /> | |
| 25 | + </td> | |
| 26 | + </tr> | |
| 27 | + | |
| 12 | 28 | <% @community_fields.each do |field| %> |
| 13 | 29 | <tr> |
| 14 | 30 | <td><label for="community_fields[<%= field %>][active]"><%= _(field.humanize) %></label></td> |
| 15 | 31 | |
| 16 | 32 | <td> |
| 17 | 33 | <%= hidden_field_tag "community_fields[#{field}][active]", false %> |
| 18 | - <%= check_box_tag "community_fields[#{field}][active]", true, environment.custom_community_field(field, 'active'), :onclick => "$('community_fields[#{field}][required]').disabled=$('community_fields[#{field}][signup]').disabled=!this.checked;" %> | |
| 34 | + <%= check_box_tag "community_fields[#{field}][active]", true, environment.custom_community_field(field, 'active'), :onclick => "active_action(this, 'community_fields[#{field}][required]', 'community_fields[#{field}][signup]')" %> | |
| 19 | 35 | </td> |
| 20 | 36 | <td> |
| 21 | 37 | <%= hidden_field_tag "community_fields[#{field}][required]", false %> |
| 22 | - <%= check_box_tag "community_fields[#{field}][required]", true, environment.custom_community_field(field, 'required'), :onclick => "if(this.checked) $('community_fields[#{field}][signup]').checked = true;" %> | |
| 38 | + <%= check_box_tag "community_fields[#{field}][required]", true, environment.custom_community_field(field, 'required'), :onclick => "required_action('community_fields[#{field}][active]','community_fields[#{field}][required]', 'community_fields[#{field}][signup]')" %> | |
| 23 | 39 | </td> |
| 24 | 40 | <td> |
| 25 | 41 | <%= hidden_field_tag "community_fields[#{field}][signup]", false %> |
| 26 | - <%= check_box_tag "community_fields[#{field}][signup]", true, environment.custom_community_field(field, 'signup'), :onclick => "if(!this.checked) $('community_fields[#{field}][required]').checked = false;" %> | |
| 42 | + <%= check_box_tag "community_fields[#{field}][signup]", true, environment.custom_community_field(field, 'signup'), :onclick => "signup_action('community_fields[#{field}][active]','community_fields[#{field}][required]', 'community_fields[#{field}][signup]')" %> | |
| 27 | 43 | </td> |
| 28 | 44 | |
| 29 | 45 | </tr> |
| ... | ... | @@ -31,18 +47,18 @@ |
| 31 | 47 | </table> |
| 32 | 48 | |
| 33 | 49 | <script type='text/javascript'> |
| 34 | - var trs = $$('#community_fields_conf tr'); | |
| 50 | + var trs = jQuery('#community_fields_conf tr'); | |
| 35 | 51 | var tr, td2; |
| 36 | - for ( var i=0; tr=trs[i]; i++ ) { | |
| 52 | + for ( var i=2; tr=trs[i]; i++ ) { | |
| 37 | 53 | if ( td2 = tr.getElementsByTagName('td')[1] ) { |
| 38 | - td2.getElementsByTagName('input')[0].onclick(); | |
| 54 | + td2.getElementsByTagName('input')[1].onclick(); | |
| 39 | 55 | } |
| 40 | 56 | } |
| 41 | 57 | </script> |
| 42 | 58 | |
| 43 | 59 | <div> |
| 44 | 60 | <% button_bar do %> |
| 45 | - <%= submit_button('save', _('Save changes')) %> | |
| 61 | + <%= submit_button('save', _('Save changes'), :id=>"save_community_fields") %> | |
| 46 | 62 | <%= button :back, _('Back to admin panel'), :controller => 'admin_panel', :action => 'index' %> |
| 47 | 63 | <% end %> |
| 48 | 64 | </div> | ... | ... |
app/views/features/_manage_enterprise_fields.rhtml
| ... | ... | @@ -9,21 +9,37 @@ |
| 9 | 9 | <th><%= _('Required') %></th> |
| 10 | 10 | <th><%= _('Display on registration?') %></th> |
| 11 | 11 | </tr> |
| 12 | + | |
| 13 | + <tr style="border-bottom:solid 2px #000"> | |
| 14 | + <td> | |
| 15 | + <%= _("Check/Uncheck All")%> | |
| 16 | + </td> | |
| 17 | + <td> | |
| 18 | + <input type="checkbox" id="enterprise_active" /> | |
| 19 | + </td> | |
| 20 | + <td> | |
| 21 | + <input type="checkbox" id="enterprise_required" /> | |
| 22 | + </td> | |
| 23 | + <td> | |
| 24 | + <input type="checkbox" id="enterprise_signup" /> | |
| 25 | + </td> | |
| 26 | + </tr> | |
| 27 | + | |
| 12 | 28 | <% @enterprise_fields.each do |field| %> |
| 13 | 29 | <tr> |
| 14 | 30 | |
| 15 | 31 | <td><label for="enterprise_fields[<%= field %>][active]"><%= _(field.humanize) %></label></td> |
| 16 | 32 | <td> |
| 17 | 33 | <%= hidden_field_tag "enterprise_fields[#{field}][active]", false %> |
| 18 | - <%= check_box_tag "enterprise_fields[#{field}][active]", true, environment.custom_enterprise_field(field, 'active'), :onclick => "$('enterprise_fields[#{field}][required]').disabled=$('enterprise_fields[#{field}][signup]').disabled=!this.checked;" %> | |
| 34 | + <%= check_box_tag "enterprise_fields[#{field}][active]", true, environment.custom_enterprise_field(field, 'active'), :onclick => "active_action(this, 'enterprise_fields[#{field}][required]', 'enterprise_fields[#{field}][signup]')" %> | |
| 19 | 35 | </td> |
| 20 | 36 | <td> |
| 21 | 37 | <%= hidden_field_tag "enterprise_fields[#{field}][required]", false %> |
| 22 | - <%= check_box_tag "enterprise_fields[#{field}][required]", true, environment.custom_enterprise_field(field, 'required'), :onclick => "if(this.checked) $('enterprise_fields[#{field}][signup]').checked = true;" %> | |
| 38 | + <%= check_box_tag "enterprise_fields[#{field}][required]", true, environment.custom_enterprise_field(field, 'required'), :onclick => "required_action('enterprise_fields[#{field}][active]','enterprise_fields[#{field}][required]', 'enterprise_fields[#{field}][signup]')" %> | |
| 23 | 39 | </td> |
| 24 | 40 | <td> |
| 25 | 41 | <%= hidden_field_tag "enterprise_fields[#{field}][signup]", false %> |
| 26 | - <%= check_box_tag "enterprise_fields[#{field}][signup]", true, environment.custom_enterprise_field(field, 'signup'), :onclick => "if(!this.checked) $('enterprise_fields[#{field}][required]').checked = false;" %> | |
| 42 | + <%= check_box_tag "enterprise_fields[#{field}][signup]", true, environment.custom_enterprise_field(field, 'signup'), :onclick => "signup_action('enterprise_fields[#{field}][active]','enterprise_fields[#{field}][required]', 'enterprise_fields[#{field}][signup]')" %> | |
| 27 | 43 | </td> |
| 28 | 44 | |
| 29 | 45 | </tr> |
| ... | ... | @@ -31,18 +47,18 @@ |
| 31 | 47 | </table> |
| 32 | 48 | |
| 33 | 49 | <script type='text/javascript'> |
| 34 | - var trs = $$('#enterprise_fields_conf tr'); | |
| 50 | + var trs = jQuery('#enterprise_fields_conf tr'); | |
| 35 | 51 | var tr, td2; |
| 36 | - for ( var i=0; tr=trs[i]; i++ ) { | |
| 52 | + for ( var i=2; tr=trs[i]; i++ ) { | |
| 37 | 53 | if ( td2 = tr.getElementsByTagName('td')[1] ) { |
| 38 | - td2.getElementsByTagName('input')[0].onclick(); | |
| 54 | + td2.getElementsByTagName('input')[1].onclick(); | |
| 39 | 55 | } |
| 40 | 56 | } |
| 41 | 57 | </script> |
| 42 | 58 | |
| 43 | 59 | <div> |
| 44 | 60 | <% button_bar do %> |
| 45 | - <%= submit_button('save', _('Save changes')) %> | |
| 61 | + <%= submit_button('save', _('Save changes'), :id=>"save_enterprise_fields") %> | |
| 46 | 62 | <%= button :back, _('Back to admin panel'), :controller => 'admin_panel', :action => 'index' %> |
| 47 | 63 | <% end %> |
| 48 | 64 | </div> | ... | ... |
app/views/features/_manage_person_fields.rhtml
| ... | ... | @@ -9,31 +9,48 @@ |
| 9 | 9 | <th><%= _('Required') %></th> |
| 10 | 10 | <th><%= _('Display on signup?') %></th> |
| 11 | 11 | </tr> |
| 12 | + | |
| 13 | + <tr style="border-bottom:solid 2px #000"> | |
| 14 | + <td> | |
| 15 | + <%= _("Check/Uncheck All")%> | |
| 16 | + </td> | |
| 17 | + <td> | |
| 18 | + <input type="checkbox" id="person_active" /> | |
| 19 | + </td> | |
| 20 | + <td> | |
| 21 | + <input type="checkbox" id="person_required" /> | |
| 22 | + </td> | |
| 23 | + <td> | |
| 24 | + <input type="checkbox" id="person_signup" /> | |
| 25 | + </td> | |
| 26 | + </tr> | |
| 27 | + | |
| 12 | 28 | <% @person_fields.each do |field| %> |
| 13 | 29 | <tr> |
| 14 | 30 | <td><label for="person_fields[<%= field %>][active]"><%= _(field.humanize) %></label></td> |
| 15 | 31 | <td> |
| 16 | 32 | <%= hidden_field_tag "person_fields[#{field}][active]", false %> |
| 17 | - <%= check_box_tag "person_fields[#{field}][active]", true, environment.custom_person_field(field, 'active'), :onclick => "$('person_fields[#{field}][required]').disabled=$('person_fields[#{field}][signup]').disabled=!this.checked;" %> | |
| 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]')" %> | |
| 18 | 34 | </td> |
| 19 | 35 | <td> |
| 20 | 36 | <%= hidden_field_tag "person_fields[#{field}][required]", false %> |
| 21 | - <%= check_box_tag "person_fields[#{field}][required]", true, environment.custom_person_field(field, 'required'), :onclick => "if(this.checked) $('person_fields[#{field}][signup]').checked = true;" %> | |
| 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]')" %> | |
| 22 | 38 | </td> |
| 23 | 39 | <td> |
| 24 | 40 | <%= hidden_field_tag "person_fields[#{field}][signup]", false %> |
| 25 | - <%= check_box_tag "person_fields[#{field}][signup]", true, environment.custom_person_field(field, 'signup'), :onclick => "if(!this.checked) $('person_fields[#{field}][required]').checked = false;" %> | |
| 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]')" %> | |
| 26 | 42 | </td> |
| 27 | 43 | </tr> |
| 28 | 44 | <% end %> |
| 29 | 45 | </table> |
| 30 | 46 | |
| 31 | 47 | <script type='text/javascript'>// <!-- |
| 32 | - var trs = $$('#person_fields_conf tr'); | |
| 48 | + var trs = jQuery('#person_fields_conf tr'); | |
| 49 | + | |
| 33 | 50 | var tr, td2; |
| 34 | - for ( var i=0; tr=trs[i]; i++ ) { | |
| 51 | + for ( var i=2; tr=trs[i]; i++ ) { | |
| 35 | 52 | if ( td2 = tr.getElementsByTagName('td')[1] ) { |
| 36 | - td2.getElementsByTagName('input')[0].onclick(); | |
| 53 | + td2.getElementsByTagName('input')[1].onclick(); | |
| 37 | 54 | } |
| 38 | 55 | } |
| 39 | 56 | // --> |
| ... | ... | @@ -41,7 +58,7 @@ |
| 41 | 58 | |
| 42 | 59 | <div> |
| 43 | 60 | <% button_bar do %> |
| 44 | - <%= submit_button('save', _('Save changes')) %> | |
| 61 | + <%= submit_button('save', _('Save changes'), :id=>"save_person_fields") %> | |
| 45 | 62 | <%= button :back, _('Back to admin panel'), :controller => 'admin_panel', :action => 'index' %> |
| 46 | 63 | <% end %> |
| 47 | 64 | </div> | ... | ... |
app/views/features/manage_fields.rhtml
| ... | ... | @@ -0,0 +1,67 @@ |
| 1 | +Feature: check all manage fields | |
| 2 | + As an administrator | |
| 3 | + I want to check and uncheck all person, enterprise and community's fields | |
| 4 | + | |
| 5 | + Background: | |
| 6 | + Given the following users | |
| 7 | + | login | name | | |
| 8 | + | mariasilva | Maria Silva | | |
| 9 | + And the following enterprises | |
| 10 | + | identifier | owner | name | contact_email | contact_phone | enabled | | |
| 11 | + | paper-street | mariasilva | Paper Street | marial.silva@workerbees.org | (288) 555-0153 | true | | |
| 12 | + And the following community | |
| 13 | + | identifier | name | | |
| 14 | + | mycommunity | My Community | | |
| 15 | + And "Maria Silva" is admin of "My Community" | |
| 16 | + And I am logged in as admin | |
| 17 | + And I go to /admin/features/manage_fields | |
| 18 | + | |
| 19 | + @selenium | |
| 20 | + Scenario: check all active person fields | |
| 21 | + Given I check "person_active" | |
| 22 | + And I press "save_person_fields" | |
| 23 | + And I follow "Control panel" | |
| 24 | + When I follow "Edit Profile" | |
| 25 | + Then I should see "Custom area of study" | |
| 26 | + | |
| 27 | + @selenium | |
| 28 | + Scenario: check all active enterprise fields | |
| 29 | + Given I check "enterprise_active" | |
| 30 | + And I press "save_enterprise_fields" | |
| 31 | + When I go to /myprofile/paper-street/profile_editor/edit | |
| 32 | + Then I should see "Historic and current context" | |
| 33 | + | |
| 34 | + @selenium | |
| 35 | + Scenario: check all active community fields | |
| 36 | + Given I check "community_active" | |
| 37 | + And I press "save_community_fields" | |
| 38 | + When I go to /myprofile/mycommunity/profile_editor/edit | |
| 39 | + Then I should see "Economic activity" | |
| 40 | + | |
| 41 | + @selenium | |
| 42 | + Scenario: uncheck Check/Uncheck All active person field | |
| 43 | + Given I check "person_active" | |
| 44 | + And I press "save_person_fields" | |
| 45 | + And I uncheck "person_active" | |
| 46 | + And I press "save_person_fields" | |
| 47 | + And I follow "Control panel" | |
| 48 | + When I follow "Edit Profile" | |
| 49 | + Then I should not see "Custom area of study" | |
| 50 | + | |
| 51 | + @selenium | |
| 52 | + Scenario: uncheck Check/Uncheck All active community field | |
| 53 | + Given I check "community_active" | |
| 54 | + And I press "save_community_fields" | |
| 55 | + And I uncheck "community_active" | |
| 56 | + And I press "save_community_fields" | |
| 57 | + When I go to /myprofile/mycommunity/profile_editor/edit | |
| 58 | + Then I should not see "Economic activity" | |
| 59 | + | |
| 60 | + @selenium | |
| 61 | + Scenario: uncheck Check/Uncheck All active enterprise field | |
| 62 | + Given I check "enterprise_active" | |
| 63 | + And I press "save_enterprise_fields" | |
| 64 | + And I uncheck "enterprise_active" | |
| 65 | + And I press "save_enterprise_fields" | |
| 66 | + When I go to /myprofile/paper-street/profile_editor/edit | |
| 67 | + Then I should not see "Historic and current context" | |
| 0 | 68 | \ No newline at end of file | ... | ... |
| ... | ... | @@ -0,0 +1,83 @@ |
| 1 | +function update_active(name_active, name_required, name_signup) { | |
| 2 | + var required = jQuery("input[name='" + name_required + "']")[1] | |
| 3 | + var signup = jQuery("input[name='" + name_signup + "']")[1] | |
| 4 | + var active = jQuery("input[name='" + name_active + "']")[1] | |
| 5 | + | |
| 6 | + if(required.checked || signup.checked) | |
| 7 | + active.checked = true | |
| 8 | +} | |
| 9 | + | |
| 10 | +function active_action(obj_active, name_required, name_signup) { | |
| 11 | + var required = jQuery("input[name='" + name_required + "']")[0] | |
| 12 | + var signup = jQuery("input[name='" + name_signup + "']")[0] | |
| 13 | + | |
| 14 | + required.disabled = signup.disabled = !obj_active.checked | |
| 15 | +} | |
| 16 | + | |
| 17 | +function required_action(name_active, name_required, name_signup) { | |
| 18 | + var obj_required = jQuery("input[name='" + name_required + "']")[1] | |
| 19 | + | |
| 20 | + if(obj_required.checked) { | |
| 21 | + jQuery("input[name='" + name_signup + "']")[0].checked = true | |
| 22 | + jQuery("input[name='" + name_signup + "']")[1].checked = true | |
| 23 | + } | |
| 24 | + | |
| 25 | + update_active(name_active, name_required, name_signup) | |
| 26 | +} | |
| 27 | + | |
| 28 | +function signup_action(name_active, name_required, name_signup) { | |
| 29 | + var obj_signup = jQuery("input[name='" + name_signup + "']")[1] | |
| 30 | + | |
| 31 | + if(!obj_signup.checked) { | |
| 32 | + jQuery("input[name='" + name_required + "']")[0].checked = false | |
| 33 | + jQuery("input[name='" + name_required + "']")[1].checked = false | |
| 34 | + } | |
| 35 | + | |
| 36 | + update_active(name_active, name_required, name_signup) | |
| 37 | +} | |
| 38 | + | |
| 39 | + | |
| 40 | +jQuery(document).ready(function(){ | |
| 41 | + function check_fields(check, table_id, start) { | |
| 42 | + var checkboxes = jQuery("#" + table_id + " tbody tr td input[type='checkbox']") | |
| 43 | + for (var i = start; i < checkboxes.length; i+=3) { | |
| 44 | + checkboxes[i].checked = check | |
| 45 | + } | |
| 46 | + } | |
| 47 | + | |
| 48 | + function verify_checked(fields_id){ | |
| 49 | + var checkboxes = jQuery("#" + fields_id + "_fields_conf tbody tr td input[type='checkbox']") | |
| 50 | + for (var i = 2; i >= 0; i--) { | |
| 51 | + var allchecked = true | |
| 52 | + for (var j = i+3; j < checkboxes.length; j+=3) { | |
| 53 | + if(!checkboxes[j].checked) { | |
| 54 | + allchecked = false | |
| 55 | + break | |
| 56 | + } | |
| 57 | + } | |
| 58 | + | |
| 59 | + var checkbox = jQuery(checkboxes[i+3]).attr("id").split("_") | |
| 60 | + jQuery("#" + checkbox.first() + "_" + checkbox.last()).attr("checked", allchecked) | |
| 61 | + } | |
| 62 | + } | |
| 63 | + | |
| 64 | + function check_all(fields_id) { | |
| 65 | + jQuery("#" + fields_id + "_active").click(function (){check_fields(this.checked, fields_id + "_fields_conf", 0)}) | |
| 66 | + jQuery("#" + fields_id + "_required").click(function (){check_fields(this.checked, fields_id + "_fields_conf", 1)}) | |
| 67 | + jQuery("#" + fields_id +"_signup").click(function (){check_fields(this.checked, fields_id + "_fields_conf", 2)}) | |
| 68 | + verify_checked(fields_id) | |
| 69 | + } | |
| 70 | + | |
| 71 | + check_all("person") | |
| 72 | + check_all("enterprise") | |
| 73 | + check_all("community") | |
| 74 | + | |
| 75 | + jQuery("input[type='checkbox']").click(function (){ | |
| 76 | + var checkbox = jQuery(this).attr("id").split("_") | |
| 77 | + verify_checked(checkbox.first()) | |
| 78 | + | |
| 79 | + if(this.checked == false) { | |
| 80 | + jQuery("#" + checkbox.first() + "_" + checkbox.last()).attr("checked", false) | |
| 81 | + } | |
| 82 | + }) | |
| 83 | +}) | ... | ... |