Commit 3ae1972bfe091554dd0aa61bfe9e84c5322f59f6
Committed by
Parley
1 parent
f9f6d523
Exists in
master
and in
5 other branches
more_inst_for_users: Add more institutions for user registration
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com> Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
Showing
3 changed files
with
60 additions
and
41 deletions
Show diff stats
lib/mpog_software_plugin.rb
... | ... | @@ -41,13 +41,16 @@ class MpogSoftwarePlugin < Noosfero::Plugin |
41 | 41 | content_tag(:div, |
42 | 42 | labelled_form_field( |
43 | 43 | _('Institution'), |
44 | - text_field(:institution, :name, :id => 'input_institution')+ | |
44 | + content_tag(:div, | |
45 | + text_field(:institution, :name, :class=>"input_institution"), | |
46 | + :class => 'institution_container')+ | |
45 | 47 | content_tag( |
46 | 48 | :small, _('Fill with your institution') ,:class => 'signup-form', :id =>'institution-balloon' |
47 | 49 | ) + |
48 | 50 | content_tag(:div, _("The searched institution does not exist"), :id=>"institution_empty_ajax_message", :class=>"errorExplanation hide-field") + |
49 | - link_to(_("Add new institution"), "#", :id=>"create_institution_link", :class=>'button with-text icon-add')+ | |
50 | - hidden_field_tag("user[institution_id]", "", :id => 'user_institution_id')+ | |
51 | + link_to(_("Add new institution"), "#", :class=>'button with-text icon-add add_new_institution') + | |
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')+ | |
51 | 54 | content_tag(:div, "", :id=>"institution_dialog") |
52 | 55 | ), |
53 | 56 | :id => 'signup-institution' | ... | ... |
public/mpog-institution-validations.js
... | ... | @@ -113,6 +113,50 @@ |
113 | 113 | } |
114 | 114 | } |
115 | 115 | |
116 | + | |
117 | + function institution_autocomplete() { | |
118 | + jQuery(".input_institution").autocomplete({ | |
119 | + source : function(request, response){ | |
120 | + jQuery.ajax({ | |
121 | + type: "GET", | |
122 | + url: "/plugin/mpog_software/get_institutions", | |
123 | + data: {query: request.term}, | |
124 | + success: function(result){ | |
125 | + response(result); | |
126 | + | |
127 | + if( result.length == 0 ) { | |
128 | + jQuery('#institution_empty_ajax_message').switchClass("hide-field", "show-field"); | |
129 | + } else { | |
130 | + jQuery('#institution_empty_ajax_message').switchClass("show-field", "hide-field"); | |
131 | + } | |
132 | + }, | |
133 | + error: function(ajax, stat, errorThrown) { | |
134 | + console.log('Link not found : ' + errorThrown); | |
135 | + } | |
136 | + }); | |
137 | + }, | |
138 | + | |
139 | + minLength: 2, | |
140 | + | |
141 | + select : function (event, selected) { | |
142 | + var user_institutions = jQuery(".user_institutions").first().clone(); | |
143 | + user_institutions.val(selected.item.id); | |
144 | + | |
145 | + jQuery(".institution_container").append(user_institutions); | |
146 | + } | |
147 | + }); | |
148 | + } | |
149 | + | |
150 | + function add_new_institution(evt) { | |
151 | + evt.preventDefault(); | |
152 | + var institution_input_field = jQuery(".institution_container .input_institution").first().clone(); | |
153 | + | |
154 | + institution_input_field.val(""); | |
155 | + | |
156 | + jQuery(".institution_container").append(institution_input_field); | |
157 | + institution_autocomplete(); | |
158 | + } | |
159 | + | |
116 | 160 | function set_events() { |
117 | 161 | jQuery("#create_institution_link").click(open_create_institution_modal); |
118 | 162 | |
... | ... | @@ -123,7 +167,16 @@ |
123 | 167 | jQuery('#save_institution_button').click(save_institution); |
124 | 168 | |
125 | 169 | jQuery("#community_name").keyup(institution_already_exists); |
170 | + | |
171 | + jQuery(".add_new_institution").click(add_new_institution); | |
172 | + | |
173 | + institution_autocomplete(); | |
174 | + | |
175 | + jQuery(".input_institution").blur(function(){ | |
176 | + if( this.value == "" ) | |
177 | + jQuery("#user_institution_id").val(""); | |
178 | + }); | |
126 | 179 | } |
127 | 180 | |
128 | 181 | jQuery(document).ready(set_events); |
129 | -})(); | |
130 | 182 | \ No newline at end of file |
183 | +})(); | ... | ... |
public/mpog-user-validations.js
... | ... | @@ -42,36 +42,6 @@ function validate_email_format(){ |
42 | 42 | this.className = ""; |
43 | 43 | } |
44 | 44 | |
45 | -function institution_autocomplete() { | |
46 | - jQuery("#input_institution").autocomplete({ | |
47 | - source : function(request, response){ | |
48 | - jQuery.ajax({ | |
49 | - type: "GET", | |
50 | - url: "/plugin/mpog_software/get_institutions", | |
51 | - data: {query: request.term}, | |
52 | - success: function(result){ | |
53 | - response(result); | |
54 | - | |
55 | - if( result.length == 0 ) { | |
56 | - jQuery('#institution_empty_ajax_message').switchClass("hide-field", "show-field"); | |
57 | - } else { | |
58 | - jQuery('#institution_empty_ajax_message').switchClass("show-field", "hide-field"); | |
59 | - } | |
60 | - }, | |
61 | - error: function(ajax, stat, errorThrown) { | |
62 | - console.log('Link not found : ' + errorThrown); | |
63 | - } | |
64 | - }); | |
65 | - }, | |
66 | - | |
67 | - minLength: 2, | |
68 | - | |
69 | - select : function (event, selected) { | |
70 | - jQuery("#user_institution_id").val(selected.item.id); | |
71 | - } | |
72 | - }); | |
73 | -} | |
74 | - | |
75 | 45 | |
76 | 46 | jQuery(document).ready(function(){ |
77 | 47 | jQuery('#secondary_email_field').blur( |
... | ... | @@ -90,11 +60,4 @@ jQuery(document).ready(function(){ |
90 | 60 | |
91 | 61 | jQuery('#area_interest_field').focus(function() { jQuery('#area-interest-balloon').fadeIn('slow'); }); |
92 | 62 | jQuery('#area_interest_field').blur(function() { jQuery('#area-interest-balloon').fadeOut('slow'); }); |
93 | - | |
94 | - institution_autocomplete(); | |
95 | - | |
96 | - jQuery("#input_institution").blur(function(){ | |
97 | - if( this.value == "" ) | |
98 | - jQuery("#user_institution_id").val(""); | |
99 | - }); | |
100 | 63 | }); | ... | ... |