Commit c2f10b561bdf2bfe26a4e28953881a8ee88e0d70
Committed by
Parley
1 parent
50b08148
Exists in
master
and in
5 other branches
Add relation between user and instituions properly
(more_inst_for_users) Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com> Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Showing
1 changed file
with
11 additions
and
5 deletions
Show diff stats
lib/mpog_software_plugin.rb
| ... | ... | @@ -40,7 +40,7 @@ class MpogSoftwarePlugin < Noosfero::Plugin |
| 40 | 40 | |
| 41 | 41 | content_tag(:div, |
| 42 | 42 | labelled_form_field( |
| 43 | - _('Institution'), | |
| 43 | + _('Institutions'), | |
| 44 | 44 | content_tag(:div, |
| 45 | 45 | text_field(:institution, :name, :id=>"input_institution"), |
| 46 | 46 | :class => 'institution_container')+ |
| ... | ... | @@ -50,7 +50,7 @@ class MpogSoftwarePlugin < Noosfero::Plugin |
| 50 | 50 | content_tag(:div, _("The searched institution does not exist"), :id=>"institution_empty_ajax_message", :class=>"errorExplanation hide-field")+ |
| 51 | 51 | link_to(_("Add new institution"), "#", :class=>'button with-text icon-add', :id => 'add_new_institution') + |
| 52 | 52 | link_to(_("Create new institution"), "#", :id=>"create_institution_link", :class=>'button with-text icon-add')+ |
| 53 | - hidden_field_tag("user[institutions][]", "", :class => 'user_institutions')+ | |
| 53 | + hidden_field_tag("user[institution_ids][]", "", :class => 'user_institutions')+ | |
| 54 | 54 | hidden_field_tag("institution_selected", "")+ |
| 55 | 55 | content_tag("ul", "",:class=>"institutions_added")+ |
| 56 | 56 | content_tag(:div, "", :id=>"institution_dialog") |
| ... | ... | @@ -168,10 +168,16 @@ class MpogSoftwarePlugin < Noosfero::Plugin |
| 168 | 168 | end |
| 169 | 169 | |
| 170 | 170 | |
| 171 | - def custom_user_registration_attributes user, ids | |
| 172 | - ids.each do |id| | |
| 173 | - user.institutions << Institution.find(id) if !id.empty? | |
| 171 | + def custom_user_registration_attributes user | |
| 172 | + unless context.params[:user][:institution_ids].nil? | |
| 173 | + context.params[:user][:institution_ids].delete("") | |
| 174 | + | |
| 175 | + context.params[:user][:institution_ids].each do |institution_id| | |
| 176 | + institution = Institution.find institution_id | |
| 177 | + user.institutions << institution | |
| 178 | + end | |
| 174 | 179 | end |
| 180 | + user.save unless user.institution_ids.empty? | |
| 175 | 181 | |
| 176 | 182 | user.institutions.each do |institution| |
| 177 | 183 | community = institution.community | ... | ... |