Commit 40a4271112d4cfc2e98dfedf122b0323ae26e55a

Authored by Gabriela Navarro
Committed by Parley
1 parent 3ae1972b
Exists in master and in 79 other branches add_sisp_to_chef, add_super_archives_plugin, api_for_colab, automates_core_packing, backup_not_prod, changes_in_buttons_on_content_panel, colab_automated_login, colab_spb_plugin_recipe, colab_widgets_settings, design_validation, dev_env_minimal, disable_email_dev, fix_breadcrumbs_position, fix_categories_software_link, fix_edit_institution, fix_edit_software_with_another_license, fix_get_license_info, fix_gitlab_assets_permission, fix_list_style_inside_article, fix_list_style_on_folder_elements, fix_members_pagination, fix_merge_request_url, fix_models_translations, fix_no_license, fix_software_api, fix_software_block_migration, fix_software_communities_translations, fix_software_communities_unit_test, fix_style_create_institution_admin_panel, fix_superarchives_imports, fix_sym_links_noosfero, focus_search_field_theme, gov-user-refactoring, gov-user-refactoring-rails4, header_fix, institution_modal_on_rating, kalibro-conf-refactoring, kalibro-processor-package, lxc_settings, margin_fix, mezuro_cookbook, prezento, refactor_download_block, refactor_software_communities, refactor_software_for_sisp, register_page, release-process, release-process-v2, remove-unused-images, remove_broken_theme, remove_secondary_email_from_user, remove_sisp_buttons, removing_super_archives_email, review_message, scope2method, signals_user_noosfero, sisp_catalog_header, sisp_colab_config, sisp_dev, sisp_dev_master, sisp_simple_version, software_as_organization, software_catalog_style_fix, software_communities_html_refactor, software_infos_api, spb_minimal_env, spb_to_rails4, spec_refactor, stable-4.1, stable-4.2, stable-4.x, temp_soft_comm_refactoring, theme_header, theme_javascript_refactory, thread_dropdown, thread_page, update_search_by_categories, update_software_api, update_softwares_boxes

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>
lib/mpog_software_plugin.rb
@@ -42,15 +42,17 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin @@ -42,15 +42,17 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
42 labelled_form_field( 42 labelled_form_field(
43 _('Institution'), 43 _('Institution'),
44 content_tag(:div, 44 content_tag(:div,
45 - text_field(:institution, :name, :class=>"input_institution"), 45 + text_field(:institution, :name, :id=>"input_institution"),
46 :class => 'institution_container')+ 46 :class => 'institution_container')+
47 content_tag( 47 content_tag(
48 :small, _('Fill with your institution') ,:class => 'signup-form', :id =>'institution-balloon' 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 link_to(_("Create new institution"), "#", :id=>"create_institution_link", :class=>'button with-text icon-add')+ 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[institutions][]", "", :class => 'user_institutions')+
  54 + hidden_field_tag("institution_selected", "")+
  55 + content_tag("ul", "",:class=>"institutions_added")+
54 content_tag(:div, "", :id=>"institution_dialog") 56 content_tag(:div, "", :id=>"institution_dialog")
55 ), 57 ),
56 :id => 'signup-institution' 58 :id => 'signup-institution'
public/mpog-institution-validations.js
@@ -113,9 +113,15 @@ @@ -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 function institution_autocomplete() { 123 function institution_autocomplete() {
118 - jQuery(".input_institution").autocomplete({ 124 + jQuery("#input_institution").autocomplete({
119 source : function(request, response){ 125 source : function(request, response){
120 jQuery.ajax({ 126 jQuery.ajax({
121 type: "GET", 127 type: "GET",
@@ -139,22 +145,43 @@ @@ -139,22 +145,43 @@
139 minLength: 2, 145 minLength: 2,
140 146
141 select : function (event, selected) { 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 function add_new_institution(evt) { 161 function add_new_institution(evt) {
151 evt.preventDefault(); 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 function set_events() { 187 function set_events() {
@@ -168,14 +195,11 @@ @@ -168,14 +195,11 @@
168 195
169 jQuery("#community_name").keyup(institution_already_exists); 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 jQuery(document).ready(set_events); 205 jQuery(document).ready(set_events);