From c94eae3431916aaa19cf85c8c35238cddd52180a Mon Sep 17 00:00:00 2001 From: Fabio Teixeira Date: Tue, 29 Sep 2015 11:53:05 -0300 Subject: [PATCH] User no more need to click add institution once it is already selected --- public/views/create-institution.js | 23 +++++++++++++---------- views/person_editor_extras.html.erb | 3 +-- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/public/views/create-institution.js b/public/views/create-institution.js index e9f7777..2da1926 100644 --- a/public/views/create-institution.js +++ b/public/views/create-institution.js @@ -223,6 +223,11 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] select : function (event, selected) { $("#institution_selected").val(selected.item.id).attr("data-name", selected.item.label); + + // +("") -> 0; +("1") -> 1... + if (+($("#institution_selected").val()) !== 0) { + add_new_institution(); + } } }); } @@ -236,27 +241,27 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] } - function add_new_institution(evt) { - evt.preventDefault(); + function add_new_institution() { var selected = $("#institution_selected"); - var institution_already_added = $(".institutions_added li[data-institution='"+selected.val()+"']").length; + var already_added_to_list = is_institution_already_added_to_list(selected.val()); - if(selected.val().length > 0 && institution_already_added === 0) { + if(selected.val().length > 0 && !already_added_to_list) { //field that send the institutions to the server $(".institution_container").append(get_clone_institution_data(selected.val())); // Visualy add the selected institution to the list add_selected_institution_to_list(selected.val(), selected.attr("data-name")); - // clean the institution flag - selected.val("").attr("data-name", ""); - $("#input_institution").val(""); - $(".remove-institution").click(remove_institution); } } + function is_institution_already_added_to_list(institution_id) { + return $(".institutions_added li[data-institution='"+institution_id+"']").length !== 0; + } + + function remove_institution(evt) { evt.preventDefault(); var code = $(this).parent().attr("data-institution"); @@ -371,8 +376,6 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] $("#community_name").keyup(institution_already_exists); - $("#add_new_institution").click(add_new_institution); - $(".remove-institution").click(remove_institution); $("#community_country").change(function(){ diff --git a/views/person_editor_extras.html.erb b/views/person_editor_extras.html.erb index a3a11fc..163bf21 100644 --- a/views/person_editor_extras.html.erb +++ b/views/person_editor_extras.html.erb @@ -19,8 +19,7 @@ <%= content_tag(:div, _("No institution found"), :id=>"institution_empty_ajax_message", :class=>"errorExplanation hide-field") %> - <%= link_to(_("Add new institution"), "#", :class=>'button with-text icon-add', :id => 'add_new_institution') %> - <%= link_to(_("Create new institution"), "#", :id=>"create_institution_link", :class=>'button with-text icon-add') %> + <%= link_to(_("Create new institution"), "#", :id=>"create_institution_link", :class=>'button with-text icon-add') %> <%= content_tag(:div, "", :id=>"institution_dialog") %> <%= hidden_field_tag("user[institution_ids][]", "", :class => 'user_institutions') %> -- libgit2 0.21.2