From 620d8b596475906a4d34e3d17df782873bc71c84 Mon Sep 17 00:00:00 2001 From: Geoff Goehle Date: Fri, 23 Aug 2013 16:01:50 -0400 Subject: [PATCH 1/3] Fixed some issues with the timedatepicker functionality. In particular time zones are no loger hard coded. --- .../Instructor/ProblemSetDetail.pm | 27 ++++++++------- .../Instructor/ProblemSetList2.pm | 16 +++------ lib/WeBWorK/Utils/DatePickerScripts.pm | 33 +++++++++++-------- 3 files changed, 40 insertions(+), 36 deletions(-) diff --git a/lib/WeBWorK/ContentGenerator/Instructor/ProblemSetDetail.pm b/lib/WeBWorK/ContentGenerator/Instructor/ProblemSetDetail.pm index 9c330b8d54..baf9886fa8 100644 --- a/lib/WeBWorK/ContentGenerator/Instructor/ProblemSetDetail.pm +++ b/lib/WeBWorK/ContentGenerator/Instructor/ProblemSetDetail.pm @@ -950,10 +950,6 @@ sub initialize { $self->addbadmessage($r->maketext("Error: answer date cannot be more than 10 years from now in set [_1]", $setID)); $error = $r->param('submit_changes'); } - # grab short name for timezone - # used to set proper timezone name in datepicker - - $self->{timezone_shortname} = substr($due_date, -3); #this is fragile } @@ -1498,9 +1494,6 @@ sub initialize { } } - - - # This erases any sticky fields if the user saves changes, resets the form, or reorders problems # It may not be obvious why this is necessary when saving changes or reordering problems # but when the problems are reorder the param problem.1.source_file needs to be the source @@ -1835,6 +1828,22 @@ sub body { print CGI::end_table(); + warn($userSetRecord->open_date); + + my $tempSet; + if ($forUsers) { + $tempSet = $db->getMergedSet($userToShow, $setID); + } else { + $tempSet = $setRecord; + } + + #datepicker scripts + print CGI::start_script({-type=>"text/javascript"}),"\n"; + print q!$(".ui-datepicker").draggable();!,"\n"; + print WeBWorK::Utils::DatePickerScripts::date_scripts($ce, $tempSet),"\n"; + print CGI::end_script(); + + # spacing print CGI::p(); @@ -2210,10 +2219,6 @@ sub output_JS { print CGI::start_script({type=>"text/javascript", src=>"$site_url/js/jquery-ui-1.8.18.custom.min.js"}), CGI::end_script(),"\n"; print CGI::start_script({type=>"text/javascript", src=>"$site_url/js/jquery-ui-timepicker-addon.js"}), CGI::end_script(),"\n"; - print CGI::start_script({-type=>"text/javascript"}),"\n"; - print q!$(".ui-datepicker").draggable();!,"\n"; - print WeBWorK::Utils::DatePickerScripts::date_scripts("set\\\\.$setID",$timezone),"\n"; - print CGI::end_script(); print "\n\n\n\n"; return ""; } diff --git a/lib/WeBWorK/ContentGenerator/Instructor/ProblemSetList2.pm b/lib/WeBWorK/ContentGenerator/Instructor/ProblemSetList2.pm index bad2d04631..443c7abab2 100644 --- a/lib/WeBWorK/ContentGenerator/Instructor/ProblemSetList2.pm +++ b/lib/WeBWorK/ContentGenerator/Instructor/ProblemSetList2.pm @@ -2159,7 +2159,7 @@ EOF ################################################################################ sub fieldEditHTML { - my ($self, $fieldName, $value, $properties, $dateTimeScripts) = @_; + my ($self, $fieldName, $value, $properties) = @_; my $size = $properties->{size}; my $type = $properties->{type}; my $access = $properties->{access}; @@ -2182,23 +2182,19 @@ sub fieldEditHTML { my @temp = split(/.open_date/, $fieldName); $bareName = $temp[0]; $bareName =~ s/\./\\\\\./g; - #$content = WeBWorK::Utils::DatePickerScripts::open_date_script($bareName, $timezone); } elsif(index($fieldName, ".due_date") != -1){ my @temp = split(/.due_date/, $fieldName); $bareName = $temp[0]; $bareName =~ s/\./\\\\\./g; - #$content = WeBWorK::Utils::DatePickerScripts::due_date_script($bareName, $timezone); } elsif(index($fieldName, ".answer_date") != -1){ my @temp = split(/.answer_date/, $fieldName); $bareName = $temp[0]; $bareName =~ s/\./\\\\\./g; - #$content = WeBWorK::Utils::DatePickerScripts::answer_date_script($bareName, $timezone); } - #push @$dateTimeScripts, $content; - push @$dateTimeScripts, WeBWorK::Utils::DatePickerScripts::date_scripts($bareName,$timezone); + return $out; } @@ -2377,10 +2373,6 @@ sub recordEditHTML { # make a hash out of this so we can test membership easily my %nonkeyfields; @nonkeyfields{$Set->NONKEYFIELDS} = (); - my @chooseDateTimeScripts = (); - - #push @chooseDateTimeScripts, "addOnLoadEvent(function() {"; - # Set Fields foreach my $field (@fieldsToShow) { next unless exists $nonkeyfields{$field}; @@ -2392,12 +2384,12 @@ sub recordEditHTML { $fieldValue =~ s/ / /g unless $editMode; $fieldValue = ($fieldValue) ? $r->maketext("Yes") : $r->maketext("No") if $field =~ /visible/ and not $editMode; $fieldValue = ($fieldValue) ? $r->maketext("Yes") : $r->maketext("No") if $field =~ /enable_reduced_scoring/ and not $editMode; - push @tableCells, CGI::font({class=>$visibleClass}, $self->fieldEditHTML($fieldName, $fieldValue, \%properties, \@chooseDateTimeScripts)); + push @tableCells, CGI::font({class=>$visibleClass}, $self->fieldEditHTML($fieldName, $fieldValue, \%properties)); #$fakeRecord{$field} = CGI::font({class=>$visibleClass}, $self->fieldEditHTML($fieldName, $fieldValue, \%properties)); } my $out = CGI::Tr({}, CGI::td({}, \@tableCells)); - my $scripts = CGI::start_script({-type=>"text/javascript"}).(join("", @chooseDateTimeScripts)).CGI::end_script(); + my $scripts = CGI::start_script({-type=>"text/javascript"}).WeBWorK::Utils::DatePickerScripts::date_scripts($ce, $Set).CGI::end_script(); return $out.$scripts; } diff --git a/lib/WeBWorK/Utils/DatePickerScripts.pm b/lib/WeBWorK/Utils/DatePickerScripts.pm index bf22fc609a..a2f98c06a5 100644 --- a/lib/WeBWorK/Utils/DatePickerScripts.pm +++ b/lib/WeBWorK/Utils/DatePickerScripts.pm @@ -16,10 +16,17 @@ package WeBWorK::Utils::DatePickerScripts; use base qw(Exporter); +use WeBWorK::Utils qw(formatDateTime); sub date_scripts { - my $bareName = shift; - my $timezone = shift; + my $ce = shift; + my $set = shift; + my $display_tz ||= $ce->{siteDefaults}{timezone}; + my $bareName = 'set\\\\.'.$set->set_id; + my $open_timezone = substr(formatDateTime($set->open_date, $display_tz), -3); + my $due_timezone = substr(formatDateTime($set->due_date, $display_tz), -3); + my $answer_timezone = substr(formatDateTime($set->answer_date, $display_tz), -3); + my $out = < Date: Fri, 23 Aug 2013 16:15:05 -0400 Subject: [PATCH 2/3] Removed inintended warn --- .../ContentGenerator/Instructor/ProblemSetDetail.pm | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/WeBWorK/ContentGenerator/Instructor/ProblemSetDetail.pm b/lib/WeBWorK/ContentGenerator/Instructor/ProblemSetDetail.pm index baf9886fa8..ac5006f618 100644 --- a/lib/WeBWorK/ContentGenerator/Instructor/ProblemSetDetail.pm +++ b/lib/WeBWorK/ContentGenerator/Instructor/ProblemSetDetail.pm @@ -1828,8 +1828,10 @@ sub body { print CGI::end_table(); - warn($userSetRecord->open_date); - + #datepicker scripts. + # we try to provide the date picker scripts with the global set + # if we aren't looking at a specific students set and the merged + # one otherwise. my $tempSet; if ($forUsers) { $tempSet = $db->getMergedSet($userToShow, $setID); @@ -1837,7 +1839,6 @@ sub body { $tempSet = $setRecord; } - #datepicker scripts print CGI::start_script({-type=>"text/javascript"}),"\n"; print q!$(".ui-datepicker").draggable();!,"\n"; print WeBWorK::Utils::DatePickerScripts::date_scripts($ce, $tempSet),"\n"; From 5a5446dda43a7f8d3c178e91870be271d35ae384 Mon Sep 17 00:00:00 2001 From: Geoff Goehle Date: Tue, 27 Aug 2013 15:35:55 -0400 Subject: [PATCH 3/3] Modified datetimepicker so that it doesn't constrain what people can type. --- lib/WeBWorK/Utils/DatePickerScripts.pm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/WeBWorK/Utils/DatePickerScripts.pm b/lib/WeBWorK/Utils/DatePickerScripts.pm index a2f98c06a5..ee79255555 100644 --- a/lib/WeBWorK/Utils/DatePickerScripts.pm +++ b/lib/WeBWorK/Utils/DatePickerScripts.pm @@ -69,6 +69,7 @@ open_rule.datetimepicker({ timeFormat: 'hh:mmtt', timeSuffix: ' $open_timezone', separator: ' at ', + constrainInput: false, onClose: function(dateText, inst) { update(); }, @@ -85,6 +86,7 @@ due_rule.datetimepicker({ timeFormat: 'hh:mmtt', timeSuffix: ' $due_timezone', separator: ' at ', + constrainInput: false, onClose: function(dateText, inst) { var open_changed=0; if (open_rule.val() == "") { @@ -105,6 +107,7 @@ answer_rule.datetimepicker({ timeFormat: 'hh:mmtt', timeSuffix: ' $answer_timezone', separator: ' at ', + constrainInput: false, onClose: function(dateText, inst) { var open_changed=0; if (open_rule.val() == "") {