Annotation of loncom/homework/daxepage.pm, revision 1.9
1.1 damieng 1: # The LearningOnline Network
2: # Page with Daxe on the left side and the preview on the right side
3: #
1.9 ! raeburn 4: # $Id: daxepage.pm,v 1.8 2023/11/26 02:15:29 raeburn Exp $
1.1 damieng 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: ###
29:
30: package Apache::daxepage;
1.5 raeburn 31: use strict;
1.1 damieng 32:
1.6 raeburn 33: use Apache::loncommon();
34: use Apache::lonhtmlcommon();
1.9 ! raeburn 35: use Apache::lonxml();
! 36: use Apache::edit();
1.6 raeburn 37: use Apache::lonmenu();
38: use Apache::lonlocal;
39: use Apache::Constants qw(:common);
1.9 ! raeburn 40: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 41: use HTML::Entities();
1.1 damieng 42:
43: sub handler {
44: my $request = shift;
45: my $uri = $request->uri;
1.5 raeburn 46: $uri =~ s{^/daxepage}{};
1.4 raeburn 47: &Apache::loncommon::content_type($request,'text/html');
1.9 ! raeburn 48: my ($is_not_assess,$is_assess);
! 49: if ($uri =~/\.(xml|html|htm|xhtml|xhtm)$/) {
! 50: $is_not_assess = 1;
! 51: } elsif ($uri =~ /$LONCAPA::assess_re/) {
! 52: unless ($uri =~ /\.form$/) {
! 53: $is_assess = 1;
! 54: }
! 55: }
! 56: unless ($is_not_assess || $is_assess) {
1.1 damieng 57: $request->status(406);
58: return OK;
59: }
1.6 raeburn 60: my %editors = &Apache::loncommon::permitted_editors();
61: unless ($editors{'daxe'}) {
62: my $msg = '<p class="LC_warning">'.
63: &mt('Daxe editor is not enabled for this Authoring Space.').'</p>';
64: &do_redirect($request,$uri,$msg);
65: return OK;
66: }
1.9 ! raeburn 67: if ($is_not_assess) {
! 68: delete($editors{'xml'});
! 69: $editors{'edit'} = 1;
! 70: }
1.6 raeburn 71: my %lt = &Apache::lonlocal::texthash(
72: 'noif' => 'No iframe support.',
73: 'show' => 'Show content in pop-up window',
1.9 ! raeburn 74: 'oeds' => 'other editors',
! 75: 'othe' => 'other editor',
! 76: 'edit' => 'Edit',
1.6 raeburn 77: );
1.1 damieng 78: my $name = $uri;
79: $name =~ s/^.*\/([^\/]+)$/$1/;
1.6 raeburn 80: my $daxeurl = '/adm/daxe/daxe.html?config=config/loncapa_config.xml&save=/daxesave'.
81: '&file=/daxeopen'.$uri;
82: my $headjs = &Apache::loncommon::iframe_wrapper_headjs().
1.9 ! raeburn 83: &toggle_LCmenus_js().
! 84: &Apache::edit::js_change_detection();
! 85: if ($is_assess) {
! 86: $headjs .= &Apache::lonxml::setmode_javascript();
! 87: } else {
! 88: $headjs .= &Apache::lonxml::seteditor_javascript();
! 89: }
! 90: my $form_events = &Apache::edit::form_change_detection();
! 91: my $editheader = '<form '.$form_events.' method="post" name="daxeedit" action="'.$uri.'">'.
! 92: '<input type="hidden" name="problemmode" value="daxe" />'."\n".
! 93: '<div class="LC_edit_problem_editxml_header">'."\n";
! 94: if ($editors{'edit'} || $editors{'xml'}) {
! 95: my $other = (($editors{'edit'} && $editors{'xml'})? $lt{'oeds'} : $lt{'othe'});
! 96: $editheader .= '<table class="LC_edit_problem_header_title"><tr><td>'.
! 97: $uri.
! 98: '</td><td align="right"><span class="LC_nobreak">'.$other.': ';
! 99: if ($is_not_assess) {
! 100: $editheader .= '<input type="hidden" name="editmode" value="" />'."\n".
! 101: '<input type="button" name="editordefault" value="'.$lt{'edit'}.
! 102: '" onclick="seteditmode(this.form,'."'edit'".');" />'."\n";
! 103: } else {
! 104: if ($editors{'edit'}) {
! 105: $editheader .= '<input type="button" name="submitmode" accesskey="e" value="'.&mt('Edit').'" '.
! 106: 'onclick="javascript:setmode(this.form,'."'edit'".')" />'."\n";
! 107: }
! 108: if ($editors{'xml'}) {
! 109: $editheader .= '<input type="button" name="submitmode" accesskey="x" value="'.&mt('EditXML').'" '.
! 110: 'onclick="javascript:setmode(this.form,'."'editxml'".')" />'."\n";
! 111: }
! 112: }
! 113: $editheader .= '</span></td></tr></table>';
! 114: } else {
! 115: $editheader .= '<table class="LC_edit_problem_header_title"><tr><td>'.
! 116: $uri.
! 117: '</td></tr></table>';
! 118: }
! 119: $editheader .= '</div></form>'."\n";
1.6 raeburn 120: my $args = {
1.9 ! raeburn 121: 'collapsible_header' => $editheader,
1.6 raeburn 122: };
123: my $startpage = &Apache::loncommon::start_page('Daxe: '.$name,$headjs,$args).
124: &Apache::lonmenu::constspaceform();
125: my $endpage = &Apache::loncommon::end_page();
126:
127: # javascript will position the iframe if window was resized (or zoomed)
128: my $script = &Apache::loncommon::iframe_wrapper_resizejs();
129: my $dest = &HTML::Entities::encode($daxeurl,'&<>"');
130: my $noiframe = &Apache::loncommon::modal_link($dest,$lt{'show'},500,400);
131:
132: $request->print(<<"ENDFRAME");
133: $startpage
134: $script
135: <div class="LC_iframecontainer" style="padding-right: 5px">
136: <iframe src="$dest">$lt{'noif'} $noiframe</iframe>
137: </div>
138: $endpage
139: ENDFRAME
1.1 damieng 140: return OK;
141: }
142:
1.6 raeburn 143: sub toggle_LCmenus_js {
144: my %lt = &Apache::lonlocal::texthash(
145: altc => 'menu state: collapsed',
146: alte => 'menu state: explanded',
147: ttlc => 'display standard menus',
148: ttle => 'hide standard menus',
149: );
150: return <<"ENDJS";
151: <script type="text/javascript">
152: //<![CDATA[
153: \$(document).ready (function () {
154: \$(".LC_collapse_trigger").on("click", function (e) {
155: var id = this.id;
156: var \$content = \$(this).next (".LC_menus_content");
157: var expanded = \$content.hasClass ("shown");
158: if (expanded) {
159: \$content.removeClass ("shown");
160: \$content.addClass ("hidden");
161: } else {
162: \$content.removeClass ("hidden");
163: \$content.addClass ("shown");
164: }
165:
166: \$(this).find ("[aria-expanded]")
167: .attr ("aria-expanded", !expanded);
168:
169: \$(this).find ("[aria-pressed]")
170: .attr ("aria-pressed", !expanded);
171:
172: \$(this).find (".LC_collapsible_indicator").attr ({
173: "src":
174: (expanded)? "/res/adm/pages/collapsed.png" : "/res/adm/pages/expanded.png",
175: "alt":
176: (expanded)? "$lt{altc}" : "$lt{alte}",
177: "title":
1.7 raeburn 178: (expanded)? "$lt{ttlc}" : "$lt{ttle}"
1.6 raeburn 179: });
180:
181: \$(window).trigger('resize');
182: \$(this).focus ();
183: });
184:
185: \$("#LC_expandingContainer").attr ("aria-live", "off");
186: });
187: //]]>
188: </script>
189: ENDJS
190:
191: }
192:
193: sub do_redirect {
194: my ($request,$uri,$msg) = @_;
195: &Apache::lonhtmlcommon::clear_breadcrumbs();
196: $request->print(
197: &Apache::loncommon::start_page('Authoring Space',undef,
198: {'redirect' => [2,$uri]}).
199:
200: '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
201: "$msg\n".
202: &Apache::loncommon::end_page());
203: return;
204: }
205:
1.1 damieng 206: 1;
207: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>