# HG changeset patch # User luisf # Date 1296481260 0 # Node ID bad82329a115ff86be4d7bc40c515238ea3a20f2 # Parent 7eb2194ee428feedcb838a0a1ae35b76d5f94d04 new javascript for institution field handling. diff -r 7eb2194ee428 -r bad82329a115 app/controllers/users_controller.rb --- a/app/controllers/users_controller.rb Fri Jan 28 18:44:56 2011 +0000 +++ b/app/controllers/users_controller.rb Mon Jan 31 13:41:00 2011 +0000 @@ -144,9 +144,15 @@ @notification_option = @user.mail_notification @ssamr_user_details = @user.ssamr_user_detail - - @selected_institution_id = @user.ssamr_user_detail.institution_id.to_i - @institution_type = @ssamr_user_details.institution_type + + if @ssamr_user_details.institution_type.blank? + @selected_institution_id = @user.ssamr_user_detail.institution_id.to_i + @institution_type = @ssamr_user_details.institution_type + else + @selected_institution_id = false + @institution_type = true + end + @auth_sources = AuthSource.find(:all) @membership ||= Member.new diff -r 7eb2194ee428 -r bad82329a115 app/views/account/register.rhtml --- a/app/views/account/register.rhtml Fri Jan 28 18:44:56 2011 +0000 +++ b/app/views/account/register.rhtml Mon Jan 31 13:41:00 2011 +0000 @@ -1,3 +1,5 @@ +<%= javascript_include_tag "ssamr_institutions" %> +

<%=l(:label_register)%> <%=link_to l(:label_login_with_open_id_option), signin_url if Setting.openid? %>

<% form_tag({:action => 'register'}, :class => "tabular") do %> diff -r 7eb2194ee428 -r bad82329a115 app/views/users/_form.rhtml --- a/app/views/users/_form.rhtml Fri Jan 28 18:44:56 2011 +0000 +++ b/app/views/users/_form.rhtml Mon Jan 31 13:41:00 2011 +0000 @@ -1,5 +1,5 @@ -<%= javascript_include_tag :defaults %> +<%= javascript_include_tag "ssamr_institutions" %> <%= error_messages_for 'user' %> @@ -29,14 +29,14 @@ <%= ssamr_user_detail.text_area :description, :rows => 3, :cols => 40, :required => true, :class => 'wiki-edit' %>

- <%= ssamr_user_detail.radio_button :institution_type, true, :onchange => "enable_disable_institution_field($('ssamr_user_details_institution_type_true')); enable_disable_institution_field('ssamr_user_details_institution_type_false');" %> + <%= ssamr_user_detail.radio_button :institution_type, true %> <%= ssamr_user_detail.collection_select(:institution_id, Institution.all, :id, :name, {:selected => @selected_institution_id} ) %>

<%= ssamr_user_detail.radio_button :institution_type, false %> Other: - <%= ssamr_user_detail.text_field(:other_institution) %> + <%= ssamr_user_detail.text_field :other_institution %>

<% end %> diff -r 7eb2194ee428 -r bad82329a115 public/javascripts/application.js --- a/public/javascripts/application.js Fri Jan 28 18:44:56 2011 +0000 +++ b/public/javascripts/application.js Mon Jan 31 13:41:00 2011 +0000 @@ -241,28 +241,5 @@ Event.observe(window, 'load', hideOnLoad); -/* SSAMR specific functions */ -/* institution related functions */ -Event.observe(window, 'load', - function() { - if($('ssamr_user_details_institution_type_true').checked) - $('ssamr_user_details_other_institution').disable(); - else if($('ssamr_user_details_institution_type_false').checked) - $('ssamr_user_details_institution_id').disable(); - } -); - -function enable_disable_institution_field(field){ - - // if($(field).enabled) - // field.disable(); - // else - field.enable(); - -} - - - - diff -r 7eb2194ee428 -r bad82329a115 public/javascripts/ssamr_institutions.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/public/javascripts/ssamr_institutions.js Mon Jan 31 13:41:00 2011 +0000 @@ -0,0 +1,26 @@ + + +/* SSAMR specific functions */ + +/* institution related functions */ +Event.observe(window, 'load', + function() { + $('ssamr_user_details_institution_type_true').observe('click', function(e, el) { + $('ssamr_user_details_other_institution').disable(); + $('ssamr_user_details_institution_id').enable(); + }); + + $('ssamr_user_details_institution_type_false').observe('click', function(e, el) { + $('ssamr_user_details_other_institution').enable(); + $('ssamr_user_details_institution_id').disable(); + }); + + if($('ssamr_user_details_institution_type_true').checked) + $('ssamr_user_details_other_institution').disable(); + else if($('ssamr_user_details_institution_type_false').checked) + $('ssamr_user_details_institution_id').disable(); + } +); + + +