Commit 40a4271112d4cfc2e98dfedf122b0323ae26e55a
Committed by
Parley
1 parent
3ae1972b
Exists in
master
and in
5 other branches
more_inst_for_users: Now add the institutions on a unordered list
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com> Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
Showing
2 changed files
with
43 additions
and
17 deletions
Show diff stats
lib/mpog_software_plugin.rb
| ... | ... | @@ -42,15 +42,17 @@ class MpogSoftwarePlugin < Noosfero::Plugin |
| 42 | 42 | labelled_form_field( |
| 43 | 43 | _('Institution'), |
| 44 | 44 | content_tag(:div, |
| 45 | - text_field(:institution, :name, :class=>"input_institution"), | |
| 45 | + text_field(:institution, :name, :id=>"input_institution"), | |
| 46 | 46 | :class => 'institution_container')+ |
| 47 | 47 | content_tag( |
| 48 | 48 | :small, _('Fill with your institution') ,:class => 'signup-form', :id =>'institution-balloon' |
| 49 | 49 | ) + |
| 50 | - content_tag(:div, _("The searched institution does not exist"), :id=>"institution_empty_ajax_message", :class=>"errorExplanation hide-field") + | |
| 51 | - link_to(_("Add new institution"), "#", :class=>'button with-text icon-add add_new_institution') + | |
| 50 | + content_tag(:div, _("The searched institution does not exist"), :id=>"institution_empty_ajax_message", :class=>"errorExplanation hide-field")+ | |
| 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 | 53 | hidden_field_tag("user[institutions][]", "", :class => 'user_institutions')+ |
| 54 | + hidden_field_tag("institution_selected", "")+ | |
| 55 | + content_tag("ul", "",:class=>"institutions_added")+ | |
| 54 | 56 | content_tag(:div, "", :id=>"institution_dialog") |
| 55 | 57 | ), |
| 56 | 58 | :id => 'signup-institution' | ... | ... |
public/mpog-institution-validations.js
| ... | ... | @@ -113,9 +113,15 @@ |
| 113 | 113 | } |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | + function get_clone_institution_data(value) { | |
| 117 | + var user_institutions = jQuery(".user_institutions").first().clone(); | |
| 118 | + user_institutions.val(value); | |
| 119 | + | |
| 120 | + return user_institutions; | |
| 121 | + } | |
| 116 | 122 | |
| 117 | 123 | function institution_autocomplete() { |
| 118 | - jQuery(".input_institution").autocomplete({ | |
| 124 | + jQuery("#input_institution").autocomplete({ | |
| 119 | 125 | source : function(request, response){ |
| 120 | 126 | jQuery.ajax({ |
| 121 | 127 | type: "GET", |
| ... | ... | @@ -139,22 +145,43 @@ |
| 139 | 145 | minLength: 2, |
| 140 | 146 | |
| 141 | 147 | select : function (event, selected) { |
| 142 | - var user_institutions = jQuery(".user_institutions").first().clone(); | |
| 143 | - user_institutions.val(selected.item.id); | |
| 148 | + jQuery("#institution_selected").val(selected.item.id).attr("data-name", selected.item.label); | |
| 144 | 149 | |
| 145 | - jQuery(".institution_container").append(user_institutions); | |
| 146 | 150 | } |
| 147 | 151 | }); |
| 148 | 152 | } |
| 149 | 153 | |
| 154 | + function add_selected_institution_to_list(id, name) { | |
| 155 | + var selected_institution = "<li data-institution='"+id+"'>"+name; | |
| 156 | + selected_institution += "<a href='#' class='button without-text icon-remove remove-institution'></a></li>"; | |
| 157 | + | |
| 158 | + jQuery(".institutions_added").append(selected_institution); | |
| 159 | + } | |
| 160 | + | |
| 150 | 161 | function add_new_institution(evt) { |
| 151 | 162 | evt.preventDefault(); |
| 152 | - var institution_input_field = jQuery(".institution_container .input_institution").first().clone(); | |
| 163 | + var selected = jQuery("#institution_selected"); | |
| 164 | + var institution_already_added = jQuery(".institutions_added li[data-institution='"+selected.val()+"']").length; | |
| 153 | 165 | |
| 154 | - institution_input_field.val(""); | |
| 166 | + if(selected.val().length > 0 && institution_already_added == 0) { | |
| 167 | + //field that send the institutions to the server | |
| 168 | + jQuery(".institution_container").append(get_clone_institution_data(selected.val())); | |
| 155 | 169 | |
| 156 | - jQuery(".institution_container").append(institution_input_field); | |
| 157 | - institution_autocomplete(); | |
| 170 | + // Visualy add the selected institution to the list | |
| 171 | + add_selected_institution_to_list(selected.val(), selected.attr("data-name")); | |
| 172 | + | |
| 173 | + // clean the institution flag | |
| 174 | + selected.val("").attr("data-name", ""); | |
| 175 | + jQuery("#input_institution").val(""); | |
| 176 | + | |
| 177 | + jQuery(".remove-institution").click(remove_institution); | |
| 178 | + } | |
| 179 | + } | |
| 180 | + | |
| 181 | + function remove_institution(evt) { | |
| 182 | + evt.preventDefault(); | |
| 183 | + | |
| 184 | + jQuery(this).parent().remove(); | |
| 158 | 185 | } |
| 159 | 186 | |
| 160 | 187 | function set_events() { |
| ... | ... | @@ -168,14 +195,11 @@ |
| 168 | 195 | |
| 169 | 196 | jQuery("#community_name").keyup(institution_already_exists); |
| 170 | 197 | |
| 171 | - jQuery(".add_new_institution").click(add_new_institution); | |
| 198 | + jQuery("#add_new_institution").click(add_new_institution); | |
| 172 | 199 | |
| 173 | - institution_autocomplete(); | |
| 200 | + jQuery(".remove-institution").click(remove_institution); | |
| 174 | 201 | |
| 175 | - jQuery(".input_institution").blur(function(){ | |
| 176 | - if( this.value == "" ) | |
| 177 | - jQuery("#user_institution_id").val(""); | |
| 178 | - }); | |
| 202 | + institution_autocomplete(); | |
| 179 | 203 | } |
| 180 | 204 | |
| 181 | 205 | jQuery(document).ready(set_events); | ... | ... |