--- loncom/xml/lonxml.pm 2023/07/13 19:38:43 1.561 +++ loncom/xml/lonxml.pm 2024/03/31 01:50:18 1.569 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # XML Parser Module # -# $Id: lonxml.pm,v 1.561 2023/07/13 19:38:43 raeburn Exp $ +# $Id: lonxml.pm,v 1.569 2024/03/31 01:50:18 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1613,8 +1613,9 @@ FULLPAGE my %lt=&Apache::lonlocal::texthash('st' => 'Save and Edit', 'vi' => 'Save and View', 'dv' => 'Discard Edits and View', - 'un' => 'undo', - 'ed' => 'Edit'); + 'un' => 'Undo', + 'ed' => 'Edit', + 'ew' => 'Edit with Daxe'); my $spelllink = &Apache::lonhtmlcommon::spelllink('xmledit','filecont'); my $textarea_events = &Apache::edit::element_change_detection(); my $form_events = &Apache::edit::form_change_detection(); @@ -1622,7 +1623,7 @@ FULLPAGE if ($filetype eq 'html') { $htmlerror=&verify_html($filecontents); if ($htmlerror) { - $htmlerror='<span class="LC_error">'.$htmlerror.'</span>'; + $htmlerror=(' 'x3).' <span class="LC_error">'.$htmlerror.'</span>'; } if (&Apache::lonhtmlcommon::htmlareabrowser()) { unless ($textareaclass) { @@ -1630,14 +1631,30 @@ FULLPAGE } } } - my $undo; + my ($undo,$daxebutton,%onclick); + foreach my $item ('discard','undo','daxe') { + $onclick{$item} = 'onclick="still_ask=true;setmode(this.form,'."'$item'".')"'; + } + foreach my $item ('saveedit','saveview') { + $onclick{$item} = 'onclick="is_submit=true;setmode(this.form,'."'$item'".')"'; + } unless ($uri =~ m{^/uploaded/}) { - $undo = '<input type="submit" name="Undo" accesskey="u" value="'.$lt{'un'}.'" />'."\n"; + $undo = '<input type="button" name="Undo" accesskey="u" value="'.$lt{'un'}.'" '. + $onclick{'undo'}.' />'."\n"; + } + $initialize .= &setmode_javascript(); + if ($filetype eq 'html') { + my %editors = &Apache::loncommon::permitted_editors(); + if ($editors{'daxe'}) { + $daxebutton = '<input type="button" name="editwithdaxe" accesskey="w" value="'.$lt{'ew'}.'" '. + $onclick{'daxe'}.' />'."\n"; + } } my $editfooter=(<<ENDFOOTER); $initialize <a name="editsection" /> <form $form_events method="post" name="xmledit" action="$action"> + <input type="hidden" name="problemmode" value="edit" /> <div class="LC_edit_problem_editxml_header"> <table class="LC_edit_problem_header_title"><tr><td> $filename @@ -1645,13 +1662,13 @@ $initialize $xml_help </td></tr> </table> - <div> - <input type="submit" name="discardview" accesskey="d" value="$lt{'dv'}" /> - $undo $htmlerror $deps_button $dragmath_button - </div> <div style="float:right"> - <input type="submit" name="savethisfile" accesskey="s" value="$lt{'st'}" /> - <input type="submit" name="viewmode" accesskey="v" value="$lt{'vi'}" /> + <input type="button" name="savethisfile" accesskey="s" value="$lt{'st'}" $onclick{'saveedit'} /> + <input type="button" name="viewmode" accesskey="v" value="$lt{'vi'}" $onclick{'saveview'} /> + </div> + <div> + <input type="button" name="discardview" accesskey="d" value="$lt{'dv'}" $onclick{'discard'} /> + $undo $deps_button $daxebutton $dragmath_button $htmlerror </div> </div> <textarea $textarea_events style="width:100%" cols="80" rows="44" name="filecont" id="filecont" $textareaclass>$filecontents</textarea><br />$spelllink @@ -1661,7 +1678,49 @@ $initialize </div> </form> ENDFOOTER - return ($editfooter,$add_to_onload,$add_to_onresize);; + return ($editfooter,$add_to_onload,$add_to_onresize); +} + +sub setmode_javascript { + return <<"ENDSCRIPT"; +<script type="text/javascript"> +// <![CDATA[ +function setmode(form,probmode) { + if (probmode == 'daxe') { + var url = new URL(document.location.href); + window.location = url.protocol+'//'+url.hostname+'/daxepage'+url.pathname; + } else { + var initial = form.problemmode.value; + form.problemmode.value = probmode; + form.submit(); + form.problemmode.value = initial; + } +} +// ]]> +</script> +ENDSCRIPT +} + +sub seteditor_javascript { + return <<"ENDSCRIPT"; +<script type="text/javascript"> +// <![CDATA[ +function seteditmode(form,editor) { + if (editor == 'daxe') { + var url = new URL(document.location.href); + window.location = url.protocol+'//'+url.hostname+'/daxepage'+url.pathname; + } else { + if (editor == 'edit') { + form.editmode.value = editor; + } else { + form.editmode.value = ''; + } + form.submit(); + } +} +// ]]> +</script> +ENDSCRIPT } sub get_target { @@ -1766,11 +1825,13 @@ sub handler { # Edit action? Save file. # if (!($env{'request.state'} eq 'published')) { - if ($env{'form.savethisfile'} || $env{'form.viewmode'} || $env{'form.Undo'}) { + if (($env{'form.problemmode'} eq 'saveedit') || + ($env{'form.problemmode'} eq 'saveview') || + ($env{'form.problemmode'} eq 'undo')) { my $html_file=&Apache::lonnet::getfile($file); my $error = &Apache::lonhomework::handle_save_or_undo($request, \$html_file, \$env{'form.filecont'}); - if ($env{'form.savethisfile'}) { - $env{'form.editmode'}='Edit'; #force edit mode + if ($env{'form.problemmode'} eq 'saveedit') { + $env{'form.editmode'}='edit'; #force edit mode } } } @@ -1799,7 +1860,7 @@ ENDNOTFOUND } elsif ($filetype ne 'css' && $filetype ne 'txt' && $filetype ne 'tex') { $filecontents=&createnewhtml(); } - $env{'form.editmode'}='Edit'; #force edit mode + $env{'form.editmode'}='edit'; #force edit mode } } else { unless ($env{'request.state'} eq 'published') { @@ -1811,7 +1872,9 @@ ENDNOTFOUND &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['editmode']); } - if (!$env{'form.editmode'} || $env{'form.viewmode'} || $env{'form.discardview'}) { + if ((!$env{'form.editmode'}) || + ($env{'form.problemmode'} eq 'saveview') || + ($env{'form.problemmode'} eq 'discard')) { if ($filetype eq 'html' || $filetype eq 'sty') { &Apache::structuretags::reset_problem_globals(); $result = &Apache::lonxml::xmlparse($request,$target, @@ -1867,7 +1930,7 @@ ENDNOTFOUND } } $brcrum = [{'href' => $href, - 'text' => $text, + 'text' => $text,}, {'href' => '', 'text' => $breadcrumbtext}]; } else { @@ -1888,8 +1951,9 @@ ENDNOTFOUND # Edit action? Insert editing commands # unless (($env{'request.state'} eq 'published') || ($inhibit_menu)) { - if ($env{'form.editmode'} && (!($env{'form.viewmode'})) && (!($env{'form.discardview'}))) - { + if (($env{'form.editmode'}) && + (!($env{'form.problemmode'} eq 'saveview')) && + (!($env{'form.problemmode'} eq 'discard'))) { my ($displayfile,$url,$symb,$itemtitle,$action); $displayfile=$request->uri; if ($request->uri =~ m{^/uploaded/}) {