Commit c94eae3431916aaa19cf85c8c35238cddd52180a

Authored by Fabio Teixeira
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>
public/views/create-institution.js
... ... @@ -223,6 +223,11 @@ modulejs.define(&#39;CreateInstitution&#39;, [&#39;jquery&#39;, &#39;NoosferoRoot&#39;, &#39;SelectElement&#39;]
223 223  
224 224 select : function (event, selected) {
225 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(&#39;CreateInstitution&#39;, [&#39;jquery&#39;, &#39;NoosferoRoot&#39;, &#39;SelectElement&#39;]
236 241 }
237 242  
238 243  
239   - function add_new_institution(evt) {
240   - evt.preventDefault();
  244 + function add_new_institution() {
241 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 249 //field that send the institutions to the server
246 250 $(".institution_container").append(get_clone_institution_data(selected.val()));
247 251  
248 252 // Visualy add the selected institution to the list
249 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 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 265 function remove_institution(evt) {
261 266 evt.preventDefault();
262 267 var code = $(this).parent().attr("data-institution");
... ... @@ -371,8 +376,6 @@ modulejs.define(&#39;CreateInstitution&#39;, [&#39;jquery&#39;, &#39;NoosferoRoot&#39;, &#39;SelectElement&#39;]
371 376  
372 377 $("#community_name").keyup(institution_already_exists);
373 378  
374   - $("#add_new_institution").click(add_new_institution);
375   -
376 379 $(".remove-institution").click(remove_institution);
377 380  
378 381 $("#community_country").change(function(){
... ...
views/person_editor_extras.html.erb
... ... @@ -19,8 +19,7 @@
19 19 </div>
20 20  
21 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 23 <%= content_tag(:div, "", :id=>"institution_dialog") %>
25 24  
26 25 <%= hidden_field_tag("user[institution_ids][]", "", :class => 'user_institutions') %>
... ...