Commit c94eae3431916aaa19cf85c8c35238cddd52180a
1 parent
38483ba7
Exists in
gov_user_refactory
User no more need to click add institution once it is already selected
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Showing
2 changed files
with
14 additions
and
12 deletions
Show diff stats
public/views/create-institution.js
| @@ -223,6 +223,11 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] | @@ -223,6 +223,11 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] | ||
| 223 | 223 | ||
| 224 | select : function (event, selected) { | 224 | select : function (event, selected) { |
| 225 | $("#institution_selected").val(selected.item.id).attr("data-name", selected.item.label); | 225 | $("#institution_selected").val(selected.item.id).attr("data-name", selected.item.label); |
| 226 | + | ||
| 227 | + // +("") -> 0; +("1") -> 1... | ||
| 228 | + if (+($("#institution_selected").val()) !== 0) { | ||
| 229 | + add_new_institution(); | ||
| 230 | + } | ||
| 226 | } | 231 | } |
| 227 | }); | 232 | }); |
| 228 | } | 233 | } |
| @@ -236,27 +241,27 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] | @@ -236,27 +241,27 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] | ||
| 236 | } | 241 | } |
| 237 | 242 | ||
| 238 | 243 | ||
| 239 | - function add_new_institution(evt) { | ||
| 240 | - evt.preventDefault(); | 244 | + function add_new_institution() { |
| 241 | var selected = $("#institution_selected"); | 245 | var selected = $("#institution_selected"); |
| 242 | - var institution_already_added = $(".institutions_added li[data-institution='"+selected.val()+"']").length; | 246 | + var already_added_to_list = is_institution_already_added_to_list(selected.val()); |
| 243 | 247 | ||
| 244 | - if(selected.val().length > 0 && institution_already_added === 0) { | 248 | + if(selected.val().length > 0 && !already_added_to_list) { |
| 245 | //field that send the institutions to the server | 249 | //field that send the institutions to the server |
| 246 | $(".institution_container").append(get_clone_institution_data(selected.val())); | 250 | $(".institution_container").append(get_clone_institution_data(selected.val())); |
| 247 | 251 | ||
| 248 | // Visualy add the selected institution to the list | 252 | // Visualy add the selected institution to the list |
| 249 | add_selected_institution_to_list(selected.val(), selected.attr("data-name")); | 253 | add_selected_institution_to_list(selected.val(), selected.attr("data-name")); |
| 250 | 254 | ||
| 251 | - // clean the institution flag | ||
| 252 | - selected.val("").attr("data-name", ""); | ||
| 253 | - $("#input_institution").val(""); | ||
| 254 | - | ||
| 255 | $(".remove-institution").click(remove_institution); | 255 | $(".remove-institution").click(remove_institution); |
| 256 | } | 256 | } |
| 257 | } | 257 | } |
| 258 | 258 | ||
| 259 | 259 | ||
| 260 | + function is_institution_already_added_to_list(institution_id) { | ||
| 261 | + return $(".institutions_added li[data-institution='"+institution_id+"']").length !== 0; | ||
| 262 | + } | ||
| 263 | + | ||
| 264 | + | ||
| 260 | function remove_institution(evt) { | 265 | function remove_institution(evt) { |
| 261 | evt.preventDefault(); | 266 | evt.preventDefault(); |
| 262 | var code = $(this).parent().attr("data-institution"); | 267 | var code = $(this).parent().attr("data-institution"); |
| @@ -371,8 +376,6 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] | @@ -371,8 +376,6 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] | ||
| 371 | 376 | ||
| 372 | $("#community_name").keyup(institution_already_exists); | 377 | $("#community_name").keyup(institution_already_exists); |
| 373 | 378 | ||
| 374 | - $("#add_new_institution").click(add_new_institution); | ||
| 375 | - | ||
| 376 | $(".remove-institution").click(remove_institution); | 379 | $(".remove-institution").click(remove_institution); |
| 377 | 380 | ||
| 378 | $("#community_country").change(function(){ | 381 | $("#community_country").change(function(){ |
views/person_editor_extras.html.erb
| @@ -19,8 +19,7 @@ | @@ -19,8 +19,7 @@ | ||
| 19 | </div> | 19 | </div> |
| 20 | 20 | ||
| 21 | <%= content_tag(:div, _("No institution found"), :id=>"institution_empty_ajax_message", :class=>"errorExplanation hide-field") %> | 21 | <%= content_tag(:div, _("No institution found"), :id=>"institution_empty_ajax_message", :class=>"errorExplanation hide-field") %> |
| 22 | - <%= link_to(_("Add new institution"), "#", :class=>'button with-text icon-add', :id => 'add_new_institution') %> | ||
| 23 | - <%= link_to(_("Create new institution"), "#", :id=>"create_institution_link", :class=>'button with-text icon-add') %> | 22 | + <%= link_to(_("Create new institution"), "#", :id=>"create_institution_link", :class=>'button with-text icon-add') %> |
| 24 | <%= content_tag(:div, "", :id=>"institution_dialog") %> | 23 | <%= content_tag(:div, "", :id=>"institution_dialog") %> |
| 25 | 24 | ||
| 26 | <%= hidden_field_tag("user[institution_ids][]", "", :class => 'user_institutions') %> | 25 | <%= hidden_field_tag("user[institution_ids][]", "", :class => 'user_institutions') %> |