Commit 2ecc71beb12189129a5aa0547f8344f391103fd0
1 parent
12664f27
Exists in
institution_modal_on_rating
Display modal to create a new institution
Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com> Signed-off-by: Pedro de Lyra <pedrodelyra@gmail.com>
Showing
5 changed files
with
58 additions
and
22 deletions
Show diff stats
src/noosfero-spb/gov_user/public/style.css
src/noosfero-spb/gov_user/public/views/create-institution.js
| ... | ... | @@ -34,6 +34,7 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] |
| 34 | 34 | close: function() { |
| 35 | 35 | $("#institution_dialog").html(""); |
| 36 | 36 | $('#institution_empty_ajax_message').switchClass("show-field", "hide-field"); |
| 37 | + toggle_extra_fields_style_status(false); | |
| 37 | 38 | } |
| 38 | 39 | }); |
| 39 | 40 | }); |
| ... | ... | @@ -196,6 +197,16 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] |
| 196 | 197 | return user_institutions; |
| 197 | 198 | } |
| 198 | 199 | |
| 200 | + function toggle_extra_fields_style_status(status) { | |
| 201 | + if(status) { | |
| 202 | + $('.extra-fields-container').css({ marginTop: "55px" }); | |
| 203 | + $('.button-bar').css({ marginTop: "55px" }); | |
| 204 | + } else { | |
| 205 | + $('.extra-fields-container').css({ marginTop: "0px" }); | |
| 206 | + $('.button-bar').css({ marginTop: "20px" }); | |
| 207 | + } | |
| 208 | + } | |
| 209 | + | |
| 199 | 210 | |
| 200 | 211 | function institution_autocomplete() { |
| 201 | 212 | $("#input_institution").autocomplete({ |
| ... | ... | @@ -209,8 +220,17 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] |
| 209 | 220 | |
| 210 | 221 | if( result.length === 0 ) { |
| 211 | 222 | $('#institution_empty_ajax_message').switchClass("hide-field", "show-field"); |
| 223 | + | |
| 224 | + if(!$('#institution_empty_ajax_message').has('a').length) { | |
| 225 | + $('#institution_empty_ajax_message').append("<a id='create_institution_link' class='button with-text icon-save submit' href='#'>Adicionar</a>"); | |
| 226 | + } | |
| 227 | + | |
| 228 | + toggle_extra_fields_style_status(true); | |
| 229 | + $("#create_institution_link").click(open_create_institution_modal); | |
| 212 | 230 | } else { |
| 213 | 231 | $('#institution_empty_ajax_message').switchClass("show-field", "hide-field"); |
| 232 | + $("#create_institution_link").remove(); | |
| 233 | + toggle_extra_fields_style_status(false); | |
| 214 | 234 | } |
| 215 | 235 | }, |
| 216 | 236 | error: function(ajax, stat, errorThrown) { |
| ... | ... | @@ -223,11 +243,6 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] |
| 223 | 243 | |
| 224 | 244 | select : function (event, selected) { |
| 225 | 245 | $("#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 | - } | |
| 231 | 246 | } |
| 232 | 247 | }); |
| 233 | 248 | } |
| ... | ... | @@ -241,27 +256,27 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] |
| 241 | 256 | } |
| 242 | 257 | |
| 243 | 258 | |
| 244 | - function add_new_institution() { | |
| 259 | + function add_new_institution(evt) { | |
| 260 | + evt.preventDefault(); | |
| 245 | 261 | var selected = $("#institution_selected"); |
| 246 | - var already_added_to_list = is_institution_already_added_to_list(selected.val()); | |
| 262 | + var institution_already_added = $(".institutions_added li[data-institution='"+selected.val()+"']").length; | |
| 247 | 263 | |
| 248 | - if(selected.val().length > 0 && !already_added_to_list) { | |
| 264 | + if(selected.val().length > 0 && institution_already_added === 0) { | |
| 249 | 265 | //field that send the institutions to the server |
| 250 | 266 | $(".institution_container").append(get_clone_institution_data(selected.val())); |
| 251 | 267 | |
| 252 | 268 | // Visualy add the selected institution to the list |
| 253 | 269 | add_selected_institution_to_list(selected.val(), selected.attr("data-name")); |
| 254 | 270 | |
| 271 | + // clean the institution flag | |
| 272 | + selected.val("").attr("data-name", ""); | |
| 273 | + $("#input_institution").val(""); | |
| 274 | + | |
| 255 | 275 | $(".remove-institution").click(remove_institution); |
| 256 | 276 | } |
| 257 | 277 | } |
| 258 | 278 | |
| 259 | 279 | |
| 260 | - function is_institution_already_added_to_list(institution_id) { | |
| 261 | - return $(".institutions_added li[data-institution='"+institution_id+"']").length !== 0; | |
| 262 | - } | |
| 263 | - | |
| 264 | - | |
| 265 | 280 | function remove_institution(evt) { |
| 266 | 281 | evt.preventDefault(); |
| 267 | 282 | var code = $(this).parent().attr("data-institution"); |
| ... | ... | @@ -365,6 +380,7 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] |
| 365 | 380 | } |
| 366 | 381 | |
| 367 | 382 | function set_events() { |
| 383 | + | |
| 368 | 384 | $("#create_institution_link").click(open_create_institution_modal); |
| 369 | 385 | |
| 370 | 386 | $("input[name='institutions[type]']").click(function(){ |
| ... | ... | @@ -376,6 +392,8 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] |
| 376 | 392 | |
| 377 | 393 | $("#community_name").keyup(institution_already_exists); |
| 378 | 394 | |
| 395 | + $("#add_new_institution").click(add_new_institution); | |
| 396 | + | |
| 379 | 397 | $(".remove-institution").click(remove_institution); |
| 380 | 398 | |
| 381 | 399 | $("#community_country").change(function(){ | ... | ... |
src/noosfero-spb/gov_user/views/ratings_extra_field.html.erb
src/noosfero-spb/software_communities/public/style.css
src/noosfero-spb/software_communities/views/comments_extra_fields.html.erb
| ... | ... | @@ -7,15 +7,18 @@ |
| 7 | 7 | </div> |
| 8 | 8 | |
| 9 | 9 | <div class="comments-software-extra-fields"> |
| 10 | - <div class="comments-software-people-benefited"> | |
| 11 | - <%= label_tag "comments_people_benefited", _("Number of Beneficiaries")%> | |
| 12 | - <span class="star-tooltip" title="Quantidade de pessoas beneficiadas com a utilização do software"></span> | |
| 13 | - <%= text_field_tag "organization_rating[people_benefited]", "" %> | |
| 14 | - </div> | |
| 15 | 10 | |
| 16 | - <div class="comments-software-saved-values"> | |
| 17 | - <%= label_tag "comments_saved_value", _("Saved resources")%> | |
| 18 | - <span class="star-tooltip" title="Valores em “Real” economizados com a utilização do software"></span> | |
| 19 | - <%= text_field_tag "organization_rating[saved_value]", "", :placeholder=>"R$"%> | |
| 11 | + <div class="extra-fields-container"> | |
| 12 | + <div class="comments-software-people-benefited"> | |
| 13 | + <%= label_tag "comments_people_benefited", _("Number of Beneficiaries")%> | |
| 14 | + <span class="star-tooltip" title="Estimativa do número de pessoas beneficiadas com a utilização do software"></span> | |
| 15 | + <%= text_field_tag "organization_rating[people_benefited]", "" %> | |
| 16 | + </div> | |
| 17 | + | |
| 18 | + <div class="comments-software-saved-values"> | |
| 19 | + <%= label_tag "comments_saved_value", _("Saved resources")%> | |
| 20 | + <span class="star-tooltip" title='Estimativa dos valores em "Real" economizados com a utilização do software'></span> | |
| 21 | + <%= text_field_tag "organization_rating[saved_value]", "", :placeholder=>"R$"%> | |
| 22 | + </div> | |
| 20 | 23 | </div> |
| 21 | 24 | </div> | ... | ... |