From 0fa86f7224d9c014f203366307fd206da446b987 Mon Sep 17 00:00:00 2001 From: Jon Jensen Date: Mon, 23 Jul 2012 17:38:16 -0600 Subject: [PATCH] use dropdowns for birthdate in registration form change to dropdowns since the datepicker control is not very friendly for selecting the year test plan: 1. go to sign up as a student (w/ course code) 2. it should not let you sign up without putting in a birthdate 3. it should save the birthdate correctly 4. go to sign up as a higher-ed student 5. it should not let you sign up without putting in a birthdate, or if you are under 13 6. it should save the birthdate correctly Change-Id: I68fb35afa179ab57aaff22624282f218791b10e0 Reviewed-on: https://gerrit.instructure.com/12437 Tested-by: Jenkins Reviewed-by: Zach Pendleton --- app/coffeescripts/handlebars_helpers.coffee | 7 +- .../registration/signupDialog.coffee | 6 +- app/coffeescripts/util/dateSelect.coffee | 65 +++++++++++++++++++ app/stylesheets/registration.scss | 10 +-- .../jst/registration/studentDialog.handlebars | 2 +- .../studentHigherEdDialog.handlebars | 2 +- public/javascripts/i18nObj.js | 3 + spec/selenium/users_spec.rb | 8 ++- 8 files changed, 93 insertions(+), 10 deletions(-) create mode 100644 app/coffeescripts/util/dateSelect.coffee diff --git a/app/coffeescripts/handlebars_helpers.coffee b/app/coffeescripts/handlebars_helpers.coffee index a59156d808d..03b451f060a 100644 --- a/app/coffeescripts/handlebars_helpers.coffee +++ b/app/coffeescripts/handlebars_helpers.coffee @@ -6,10 +6,11 @@ define [ 'underscore' 'str/htmlEscape' 'compiled/util/semanticDateRange' + 'compiled/util/dateSelect' 'jquery.instructure_date_and_time' 'jquery.instructure_misc_helpers' 'jquery.instructure_misc_plugins' -], (ENV, Handlebars, I18n, $, _, htmlEscape, semanticDateRange) -> +], (ENV, Handlebars, I18n, $, _, htmlEscape, semanticDateRange, dateSelect) -> Handlebars.registerHelper name, fn for name, fn of { t : (key, defaultValue, options) -> @@ -162,5 +163,9 @@ define [ toSentence: (context, options) -> results = _.map(context, (c) -> options.fn(c)) $.toSentence(results) + + dateSelect: (name, options) -> + new Handlebars.SafeString dateSelect(name, options.hash).html() + } return Handlebars diff --git a/app/coffeescripts/registration/signupDialog.coffee b/app/coffeescripts/registration/signupDialog.coffee index dcff31dec27..b86b3d370c3 100644 --- a/app/coffeescripts/registration/signupDialog.coffee +++ b/app/coffeescripts/registration/signupDialog.coffee @@ -44,11 +44,15 @@ define [ class: 'btn-primary' ] return - $form.formErrors flatten + errors = flatten user: User::normalizeErrors(errors.user) pseudonym: Pseudonym::normalizeErrors(errors.pseudonym) observee: Pseudonym::normalizeErrors(errors.observee) , arrays: false + if errors['user[birthdate]'] + errors['user[birthdate(1)]'] = errors['user[birthdate]'] + delete errors['user[birthdate]'] + $form.formErrors errors $node.dialog resizable: false diff --git a/app/coffeescripts/util/dateSelect.coffee b/app/coffeescripts/util/dateSelect.coffee new file mode 100644 index 00000000000..539ebbcc1cb --- /dev/null +++ b/app/coffeescripts/util/dateSelect.coffee @@ -0,0 +1,65 @@ +define [ + 'i18n!instructure', + 'jquery' + 'underscore', + 'str/htmlEscape' +], (I18n, $, _, h) -> + + builders = + year: (options, htmlOptions) -> + step = if options.startYear < options.endYear then 1 else -1 + $result = $('', htmlOptions) + $result.append('')) + $result + day: (options, htmlOptions) -> + $result = $(' + {{dateSelect "user[birthdate]" id="student_birthdate" type="birthdate" class="select-birthdate"}}
diff --git a/app/views/jst/registration/studentHigherEdDialog.handlebars b/app/views/jst/registration/studentHigherEdDialog.handlebars index f86d449e4f9..da52fa92f33 100644 --- a/app/views/jst/registration/studentHigherEdDialog.handlebars +++ b/app/views/jst/registration/studentHigherEdDialog.handlebars @@ -15,7 +15,7 @@
- + {{dateSelect "user[birthdate]" id="student_higher_ed_birthdate" type="birthdate" class="select-birthdate"}}
diff --git a/public/javascripts/i18nObj.js b/public/javascripts/i18nObj.js index c4ad521079a..49b9df401c7 100644 --- a/public/javascripts/i18nObj.js +++ b/public/javascripts/i18nObj.js @@ -563,6 +563,9 @@ I18n.scope.prototype = { }, toPercentage: function(number, options) { return I18n.toPercentage(number, options); + }, + lookup: function(scope, options) { + return I18n.lookup(this.resolveScope(scope), options); } }; I18n.scope.prototype.t = I18n.scope.prototype.translate; diff --git a/spec/selenium/users_spec.rb b/spec/selenium/users_spec.rb index 0cfe7b894c5..df55e53def1 100644 --- a/spec/selenium/users_spec.rb +++ b/spec/selenium/users_spec.rb @@ -129,7 +129,9 @@ describe "user selenium tests" do form = fj('.ui-dialog:visible form') f('#student_join_code').send_keys(@course.self_enrollment_code) f('#student_name').send_keys('student!') - f('#student_birthdate').send_keys('1/1/1980') + form.find_element(:css, "select[name='user[birthdate(1)]'] option[value='#{Time.now.year - 20}']").click + form.find_element(:css, "select[name='user[birthdate(2)]'] option[value='1']").click + form.find_element(:css, "select[name='user[birthdate(3)]'] option[value='1']").click f('#student_username').send_keys('student') f('#student_password').send_keys('asdfasdf') f('#student_password_confirmation').send_keys('asdfasdf') @@ -147,7 +149,9 @@ describe "user selenium tests" do form = fj('.ui-dialog:visible form') f('#student_higher_ed_name').send_keys('student!') f('#student_higher_ed_email').send_keys('student@example.com') - f('#student_higher_ed_birthdate').send_keys('1/1/1980') + form.find_element(:css, "select[name='user[birthdate(1)]'] option[value='#{Time.now.year - 20}']").click + form.find_element(:css, "select[name='user[birthdate(2)]'] option[value='1']").click + form.find_element(:css, "select[name='user[birthdate(3)]'] option[value='1']").click form.find_element(:css, 'input[name="user[terms_of_use]"]').click expect_new_page_load { form.submit }