| … | |
… | |
| 13 | # FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the |
13 | # FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the |
| 14 | # Artistic License for more details. |
14 | # Artistic License for more details. |
| 15 | ################################################################################ |
15 | ################################################################################ |
| 16 | |
16 | |
| 17 | package WeBWorK::ContentGenerator::Instructor::PGProblemEditor; |
17 | package WeBWorK::ContentGenerator::Instructor::PGProblemEditor; |
|
|
18 | use base qw(WeBWorK); |
| 18 | use base qw(WeBWorK::ContentGenerator::Instructor); |
19 | use base qw(WeBWorK::ContentGenerator::Instructor); |
| 19 | |
20 | |
| 20 | use constant DEFAULT_SEED => 123456; |
21 | use constant DEFAULT_SEED => 123456; |
| 21 | |
22 | |
| 22 | =head1 NAME |
23 | =head1 NAME |
| … | |
… | |
| 590 | |
591 | |
| 591 | # Define parameters for textarea |
592 | # Define parameters for textarea |
| 592 | # FIXME |
593 | # FIXME |
| 593 | # Should the seed be set from some particular user instance?? |
594 | # Should the seed be set from some particular user instance?? |
| 594 | my $rows = 20; |
595 | my $rows = 20; |
| 595 | my $columns = 80; |
596 | my $columns = 65; |
| 596 | my $mode_list = $ce->{pg}->{displayModes}; |
597 | my $mode_list = $ce->{pg}->{displayModes}; |
| 597 | my $displayMode = $self->{displayMode}; |
598 | my $displayMode = $self->{displayMode}; |
| 598 | my $problemSeed = $self->{problemSeed}; |
599 | my $problemSeed = $self->{problemSeed}; |
| 599 | my $uri = $r->uri; |
600 | my $uri = $r->uri; |
| 600 | my $edit_level = $r->param('edit_level') || 0; |
601 | my $edit_level = $r->param('edit_level') || 0; |
| … | |
… | |
| 655 | # )," | ", |
656 | # )," | ", |
| 656 | # CGI::a({-href=>$BUGZILLA,-target=>"bugs_window"}, |
657 | # CGI::a({-href=>$BUGZILLA,-target=>"bugs_window"}, |
| 657 | # ' report problem bugs ', |
658 | # ' report problem bugs ', |
| 658 | # )," | ", |
659 | # )," | ", |
| 659 | # ), |
660 | # ), |
| 660 | CGI::p( |
661 | CGI::hr(), |
| 661 | CGI::textarea( |
662 | CGI::p({-id=>"problemContents_p"}, |
|
|
663 | WeBWorK::CGI_labeled_input( |
|
|
664 | -type => "textarea", |
|
|
665 | -id => "problemContents_id", |
|
|
666 | -label_text => "Problem Source Code:", |
|
|
667 | -label_attr => { |
|
|
668 | -id => "problemContents_label", |
|
|
669 | }, |
|
|
670 | -input_attr => { |
| 662 | -name => 'problemContents', -default => $problemContents, |
671 | -name => 'problemContents', -default => $problemContents, |
| 663 | -rows => $rows, -cols => $columns, -override => 1, |
672 | -rows => $rows, -cols => $columns, -override => 1, |
|
|
673 | } |
| 664 | ), |
674 | ), |
| 665 | ); |
675 | ); |
| 666 | |
676 | |
| 667 | |
677 | |
| 668 | |
678 | |
| 669 | ######### print action forms |
679 | ######### print action forms |
| 670 | |
680 | |
| 671 | print CGI::start_table({}); |
681 | print CGI::start_div({-id=>"form_div"}); |
|
|
682 | print "Select action below:".CGI::br().CGI::br(); |
| 672 | #print CGI::Tr({}, CGI::td({-colspan=>2}, "Select an action to perform:")); |
683 | #print CGI::Tr({}, CGI::td({-colspan=>2}, "Select an action to perform:")); |
| 673 | |
684 | |
| 674 | my @formsToShow = @{ ACTION_FORMS() }; |
685 | my @formsToShow = @{ ACTION_FORMS() }; |
| 675 | my $default_choice = $formsToShow[0]; |
686 | my $default_choice = $formsToShow[0]; |
| 676 | my $i = 0; |
687 | my $i = 0; |
| … | |
… | |
| 684 | my $line_contents = $self->$actionForm($onChange, %actionParams); |
695 | my $line_contents = $self->$actionForm($onChange, %actionParams); |
| 685 | my $radio_params = {-type=>"radio", -name=>"action", -value=>$actionID}; |
696 | my $radio_params = {-type=>"radio", -name=>"action", -value=>$actionID}; |
| 686 | $radio_params->{checked}=1 if ($actionID eq $default_choice) ; |
697 | $radio_params->{checked}=1 if ($actionID eq $default_choice) ; |
| 687 | $radio_params->{onclick} = "setTarget($newWindow)"; |
698 | $radio_params->{onclick} = "setTarget($newWindow)"; |
| 688 | $radio_params->{id} = "action$i"; |
699 | $radio_params->{id} = "action$i"; |
| 689 | print CGI::Tr({-valign=>"top"}, |
700 | print WeBWorK::CGI_labeled_input(-type=>"radio", -id=>$actionID."_id", -label_text=>ucfirst(WeBWorK::underscore_to_whitespace(WeBWorK::split_cap($actionID))), -input_attr=>$radio_params), CGI::br(), CGI::div({-class=>"editor_form"},$line_contents), CGI::br() if $line_contents; |
| 690 | CGI::td({}, CGI::input($radio_params)), |
|
|
| 691 | CGI::td({}, $line_contents) |
|
|
| 692 | ) if $line_contents; |
|
|
| 693 | |
701 | |
| 694 | $i++; |
702 | $i++; |
| 695 | } |
703 | } |
| 696 | my $checkbox = CGI::input({-type=>"checkbox", -id=>"newWindow", -checked=>"checked", |
704 | my $checkbox = WeBWorK::CGI_labeled_input(-type=>"checkbox", -id=>"newWindow", -label_text=>"Show in another window", -input_attr=>{-checked=>"checked", -onchange=>"updateTarget()"}); |
| 697 | -onchange=>"updateTarget()"}); |
|
|
| 698 | $checkbox =~ s/\n//; # remove unwanted linebreak |
705 | $checkbox =~ s/\n//; # remove unwanted linebreak |
| 699 | print CGI::Tr({}, CGI::td({-colspan=>2}, "Select above then:", |
706 | print $checkbox,CGI::br(),WeBWorK::CGI_labeled_input(-type=>"submit", id=>"none", -input_attr=>{-name=>'submit', -value=>"Take Action!"}),CGI::br(),CGI::br(); |
| 700 | CGI::submit(-name=>'submit', -value=>"Take Action!"), |
|
|
| 701 | CGI::script("document.write('$checkbox in another window')"))); |
|
|
| 702 | print CGI::end_table(); |
707 | print CGI::end_div(); |
| 703 | |
708 | |
| 704 | |
709 | |
| 705 | print CGI::end_form(); |
710 | print CGI::end_form(); |
| 706 | |
711 | |
| 707 | print CGI::script("updateTarget()"); |
712 | print CGI::script("updateTarget()"); |
| … | |
… | |
| 1214 | } |
1219 | } |
| 1215 | sub view_form { |
1220 | sub view_form { |
| 1216 | my ($self, $onChange, %actionParams) = @_; |
1221 | my ($self, $onChange, %actionParams) = @_; |
| 1217 | my $file_type = $self->{file_type}; |
1222 | my $file_type = $self->{file_type}; |
| 1218 | return "" if $file_type eq 'hardcopy_header'; # these can't yet be edited from temporary files #FIXME |
1223 | return "" if $file_type eq 'hardcopy_header'; # these can't yet be edited from temporary files #FIXME |
| 1219 | my $output_string = "View"; |
1224 | my $output_string = ""; |
| 1220 | unless ($file_type eq 'course_info' || $file_type eq 'options_info') { |
1225 | unless ($file_type eq 'course_info' || $file_type eq 'options_info') { |
| 1221 | |
1226 | |
| 1222 | $output_string .= join(" ", |
1227 | $output_string .= join(" ", |
|
|
1228 | CGI::br(), |
| 1223 | " using seed ", |
1229 | # " using seed ", |
| 1224 | CGI::textfield(-name=>'action.view.seed',-value=>$self->{problemSeed},-onfocus=>$onChange), |
1230 | WeBWorK::CGI_labeled_input(-type=>"text", -id=>"seed_text_id", -label_text=>"View Using Seed Number: ", -input_attr=>{-name=>'action.view.seed',-value=>$self->{problemSeed},-onfocus=>$onChange}), |
|
|
1231 | CGI::br(), |
| 1225 | "and display mode ", |
1232 | # "and display mode ", |
| 1226 | CGI::popup_menu(-name=>'action.view.displayMode', -values=>$self->r->ce->{pg}->{displayModes}, |
1233 | WeBWorK::CGI_labeled_input(-type=>"select", -id=>"display_mode_select_id", -label_text=>"Display Mode: ", -input_attr=>{-name=>'action.view.displayMode', -values=>$self->r->ce->{pg}->{displayModes}, -default=>$self->{displayMode}, -onmousedown=>$onChange}), |
| 1227 | -default=>$self->{displayMode}, -onmousedown=>$onChange) |
1234 | CGI::br(), |
| 1228 | ); |
1235 | ); |
| 1229 | } |
1236 | } |
| 1230 | |
1237 | |
| 1231 | return $output_string; #FIXME add -labels to the pop up menu |
1238 | return $output_string; #FIXME add -labels to the pop up menu |
| 1232 | } |
1239 | } |
| … | |
… | |
| 1380 | set_header => 'set header', |
1387 | set_header => 'set header', |
| 1381 | hardcopy_header => 'hardcopy header', |
1388 | hardcopy_header => 'hardcopy header', |
| 1382 | }; |
1389 | }; |
| 1383 | return "" if $self->{file_type} eq 'course_info' || $self->{file_type} eq 'options_info'; |
1390 | return "" if $self->{file_type} eq 'course_info' || $self->{file_type} eq 'options_info'; |
| 1384 | return join(" ", |
1391 | return join(" ", |
|
|
1392 | CGI::br(), |
| 1385 | "Add to set " , |
1393 | # "Add to set " , |
| 1386 | CGI::popup_menu({name=>'action.add_problem.target_set', values=>\@allSetNames, default=>$setName, onmousedown=>$onChange}), |
1394 | WeBWorK::CGI_labeled_input(-type=>"select", -id=>"set_select_id", -label_text=>"Add to which set?: ", -input_attr=>{name=>'action.add_problem.target_set', values=>\@allSetNames, default=>$setName, onmousedown=>$onChange}), |
|
|
1395 | CGI::br(), |
| 1387 | " as ", |
1396 | # " as ", |
| 1388 | CGI::popup_menu({name=>'action.add_problem.file_type', values=>['problem','set_header', 'hardcopy_header'], labels=>$labels, default=>$self->{file_type}, onmousedown=>$onChange}), |
1397 | WeBWorK::CGI_labeled_input(-type=>"select", -id=>"filetype_select_id", -label_text=>"Add as what filetype?: ", -input_attr=>{name=>'action.add_problem.file_type', values=>['problem','set_header', 'hardcopy_header'], labels=>$labels, default=>$self->{file_type}, onmousedown=>$onChange}), |
| 1389 | |
1398 | CGI::br(), |
| 1390 | ); #FIXME add -lables to the pop up menu |
1399 | ); #FIXME add -lables to the pop up menu |
| 1391 | return ""; |
1400 | return ""; |
| 1392 | } |
1401 | } |
| 1393 | |
1402 | |
| 1394 | sub add_problem_handler { |
1403 | sub add_problem_handler { |
| … | |
… | |
| 1700 | |
1709 | |
| 1701 | my $can_add_problem_to_set = not_blank($setID) && $setID ne 'Undefined_Set' && $self->{file_type} ne 'blank_problem'; |
1710 | my $can_add_problem_to_set = not_blank($setID) && $setID ne 'Undefined_Set' && $self->{file_type} ne 'blank_problem'; |
| 1702 | # don't addor replace problems to sets if the set is the Undefined_Set or if the problem is the blank_problem. |
1711 | # don't addor replace problems to sets if the set is the Undefined_Set or if the problem is the blank_problem. |
| 1703 | |
1712 | |
| 1704 | my $replace_problem_in_set = ($can_add_problem_to_set)? |
1713 | my $replace_problem_in_set = ($can_add_problem_to_set)? |
| 1705 | CGI::input({ |
1714 | WeBWorK::CGI_labeled_input( |
| 1706 | -type => 'radio', |
1715 | -type => 'radio', |
|
|
1716 | -id => "replace_radio_id", |
|
|
1717 | -label_text=> "Replace ".CGI::b("set $fullSetID$probNum").": ", |
|
|
1718 | -input_attr=> { |
| 1707 | -name => "action.save_as.saveMode", |
1719 | -name => "action.save_as.saveMode", |
| 1708 | -value => "rename", |
1720 | -value => "rename", |
| 1709 | -label => '', |
1721 | -label => '', |
| 1710 | },"and replace ".CGI::b("set $fullSetID$probNum").',') : '' |
1722 | } |
|
|
1723 | ).CGI::br() : '' |
| 1711 | ; |
1724 | ; |
| 1712 | my $add_problem_to_set = ($can_add_problem_to_set)? |
1725 | my $add_problem_to_set = ($can_add_problem_to_set)? |
| 1713 | CGI::input({ |
1726 | WeBWorK::CGI_labeled_input( |
| 1714 | -type => 'radio', |
1727 | -type => 'radio', |
|
|
1728 | -id => "append_radio_id", |
|
|
1729 | -label_text=> "Append to end of set $fullSetID: ", |
|
|
1730 | -input_attr=> { |
| 1715 | -name => "action.save_as.saveMode", |
1731 | -name => "action.save_as.saveMode", |
| 1716 | -value => 'add_to_set_as_new_problem', |
1732 | -value => 'add_to_set_as_new_problem', |
| 1717 | -label => '', |
1733 | -label => '', |
| 1718 | -onfocus => $onChange, |
1734 | -onfocus => $onChange, |
| 1719 | },"and append to end of set $fullSetID",) : '' |
1735 | }).CGI::br() : '' |
| 1720 | ; |
1736 | ; |
| 1721 | my $rh_new_problem_options = { |
1737 | my $create_new_problem = WeBWorK::CGI_labeled_input( |
| 1722 | -type => 'radio', |
1738 | -type => 'radio', |
|
|
1739 | -id => "independent_radio_id", |
|
|
1740 | -label_text=> "Save as new independent problem", |
|
|
1741 | -input_attr=> $can_add_problem_to_set ? |
|
|
1742 | { |
| 1723 | -name => "action.save_as.saveMode", |
1743 | -name => "action.save_as.saveMode", |
| 1724 | -value => "new_independent_problem", |
1744 | -value => "new_independent_problem", |
| 1725 | -onfocus => $onChange, |
1745 | -onfocus => $onChange, |
| 1726 | }; |
1746 | } |
| 1727 | $rh_new_problem_options->{checked}=1 unless $can_add_problem_to_set; |
1747 | : |
| 1728 | my $create_new_problem = CGI::input($rh_new_problem_options,"as a new independent problem"); |
1748 | { |
|
|
1749 | -name => "action.save_as.saveMode", |
|
|
1750 | -value => "new_independent_problem", |
|
|
1751 | -onfocus => $onChange, |
|
|
1752 | -checked => "checked", |
|
|
1753 | } |
|
|
1754 | ).CGI::br(); |
| 1729 | |
1755 | |
| 1730 | $andRelink = CGI::br(). $replace_problem_in_set . $add_problem_to_set . $create_new_problem; |
1756 | $andRelink = CGI::br(). $replace_problem_in_set . $add_problem_to_set . $create_new_problem; |
| 1731 | |
1757 | |
| 1732 | return 'Save AS [TMPL]/'. |
1758 | return WeBWorK::CGI_labeled_input( |
| 1733 | CGI::textfield( |
1759 | -type=>"text", |
|
|
1760 | -id=>"target_file_text_id", |
|
|
1761 | -label_text=>"Save AS [TMPL]/ ", |
|
|
1762 | -input_attr=> { |
| 1734 | -name=>'action.save_as.target_file', -size=>60, -value=>"$shortFilePath", |
1763 | -name=>'action.save_as.target_file', -size=>60, -value=>"$shortFilePath", |
| 1735 | -onfocus=>$onChange |
1764 | -onfocus=>$onChange } |
| 1736 | ).",". |
1765 | ). |
| 1737 | CGI::hidden(-name=>'action.save_as.source_file', -value=>$editFilePath ). |
1766 | CGI::hidden(-name=>'action.save_as.source_file', -value=>$editFilePath ). |
| 1738 | CGI::hidden(-name=>'action.save_as.file_type',-value=>$self->{file_type}). |
1767 | CGI::hidden(-name=>'action.save_as.file_type',-value=>$self->{file_type}). |
| 1739 | $andRelink; |
1768 | $andRelink; |
| 1740 | } |
1769 | } |
| 1741 | # suggestions for improvement |
1770 | # suggestions for improvement |
| … | |
… | |
| 1943 | # no redirect is needed |
1972 | # no redirect is needed |
| 1944 | } |
1973 | } |
| 1945 | |
1974 | |
| 1946 | |
1975 | |
| 1947 | |
1976 | |
| 1948 | |
|
|
| 1949 | 1; |
1977 | 1; |