Annotation of loncom/homework/daxepage.pm, revision 1.10
1.1 damieng 1: # The LearningOnline Network
2: # Page with Daxe on the left side and the preview on the right side
3: #
1.10 ! raeburn 4: # $Id: daxepage.pm,v 1.9 2023/11/27 23:24:04 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();
1.10 ! raeburn 34: use Apache::lonnet();
1.6 raeburn 35: use Apache::lonhtmlcommon();
1.9 raeburn 36: use Apache::lonxml();
37: use Apache::edit();
1.6 raeburn 38: use Apache::lonmenu();
39: use Apache::lonlocal;
40: use Apache::Constants qw(:common);
1.9 raeburn 41: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 42: use HTML::Entities();
1.1 damieng 43:
44: sub handler {
45: my $request = shift;
46: my $uri = $request->uri;
1.5 raeburn 47: $uri =~ s{^/daxepage}{};
1.4 raeburn 48: &Apache::loncommon::content_type($request,'text/html');
1.9 raeburn 49: my ($is_not_assess,$is_assess);
50: if ($uri =~/\.(xml|html|htm|xhtml|xhtm)$/) {
51: $is_not_assess = 1;
52: } elsif ($uri =~ /$LONCAPA::assess_re/) {
53: unless ($uri =~ /\.form$/) {
54: $is_assess = 1;
55: }
56: }
57: unless ($is_not_assess || $is_assess) {
1.1 damieng 58: $request->status(406);
59: return OK;
60: }
1.6 raeburn 61: my %editors = &Apache::loncommon::permitted_editors();
62: unless ($editors{'daxe'}) {
63: my $msg = '<p class="LC_warning">'.
64: &mt('Daxe editor is not enabled for this Authoring Space.').'</p>';
65: &do_redirect($request,$uri,$msg);
66: return OK;
67: }
1.9 raeburn 68: if ($is_not_assess) {
69: delete($editors{'xml'});
70: $editors{'edit'} = 1;
71: }
1.6 raeburn 72: my %lt = &Apache::lonlocal::texthash(
73: 'noif' => 'No iframe support.',
74: 'show' => 'Show content in pop-up window',
1.9 raeburn 75: 'oeds' => 'other editors',
76: 'othe' => 'other editor',
77: 'edit' => 'Edit',
1.6 raeburn 78: );
1.1 damieng 79: my $name = $uri;
80: $name =~ s/^.*\/([^\/]+)$/$1/;
1.6 raeburn 81: my $daxeurl = '/adm/daxe/daxe.html?config=config/loncapa_config.xml&save=/daxesave'.
82: '&file=/daxeopen'.$uri;
83: my $headjs = &Apache::loncommon::iframe_wrapper_headjs().
1.9 raeburn 84: &toggle_LCmenus_js().
85: &Apache::edit::js_change_detection();
86: if ($is_assess) {
87: $headjs .= &Apache::lonxml::setmode_javascript();
88: } else {
89: $headjs .= &Apache::lonxml::seteditor_javascript();
90: }
91: my $form_events = &Apache::edit::form_change_detection();
92: my $editheader = '<form '.$form_events.' method="post" name="daxeedit" action="'.$uri.'">'.
93: '<input type="hidden" name="problemmode" value="daxe" />'."\n".
94: '<div class="LC_edit_problem_editxml_header">'."\n";
95: if ($editors{'edit'} || $editors{'xml'}) {
96: my $other = (($editors{'edit'} && $editors{'xml'})? $lt{'oeds'} : $lt{'othe'});
97: $editheader .= '<table class="LC_edit_problem_header_title"><tr><td>'.
98: $uri.
99: '</td><td align="right"><span class="LC_nobreak">'.$other.': ';
100: if ($is_not_assess) {
101: $editheader .= '<input type="hidden" name="editmode" value="" />'."\n".
102: '<input type="button" name="editordefault" value="'.$lt{'edit'}.
103: '" onclick="seteditmode(this.form,'."'edit'".');" />'."\n";
104: } else {
105: if ($editors{'edit'}) {
106: $editheader .= '<input type="button" name="submitmode" accesskey="e" value="'.&mt('Edit').'" '.
107: 'onclick="javascript:setmode(this.form,'."'edit'".')" />'."\n";
108: }
109: if ($editors{'xml'}) {
110: $editheader .= '<input type="button" name="submitmode" accesskey="x" value="'.&mt('EditXML').'" '.
111: 'onclick="javascript:setmode(this.form,'."'editxml'".')" />'."\n";
112: }
113: }
114: $editheader .= '</span></td></tr></table>';
115: } else {
116: $editheader .= '<table class="LC_edit_problem_header_title"><tr><td>'.
117: $uri.
118: '</td></tr></table>';
119: }
120: $editheader .= '</div></form>'."\n";
1.10 ! raeburn 121: my $start_collapsed = &collapsible_std_LCmenus();
1.6 raeburn 122: my $args = {
1.9 raeburn 123: 'collapsible_header' => $editheader,
1.10 ! raeburn 124: 'start_collapsed' => $start_collapsed,
1.6 raeburn 125: };
126: my $startpage = &Apache::loncommon::start_page('Daxe: '.$name,$headjs,$args).
127: &Apache::lonmenu::constspaceform();
128: my $endpage = &Apache::loncommon::end_page();
129:
130: # javascript will position the iframe if window was resized (or zoomed)
131: my $script = &Apache::loncommon::iframe_wrapper_resizejs();
132: my $dest = &HTML::Entities::encode($daxeurl,'&<>"');
133: my $noiframe = &Apache::loncommon::modal_link($dest,$lt{'show'},500,400);
134:
135: $request->print(<<"ENDFRAME");
136: $startpage
137: $script
138: <div class="LC_iframecontainer" style="padding-right: 5px">
139: <iframe src="$dest">$lt{'noif'} $noiframe</iframe>
140: </div>
141: $endpage
142: ENDFRAME
1.1 damieng 143: return OK;
144: }
145:
1.6 raeburn 146: sub toggle_LCmenus_js {
147: my %lt = &Apache::lonlocal::texthash(
148: altc => 'menu state: collapsed',
149: alte => 'menu state: explanded',
150: ttlc => 'display standard menus',
151: ttle => 'hide standard menus',
152: );
153: return <<"ENDJS";
154: <script type="text/javascript">
155: //<![CDATA[
156: \$(document).ready (function () {
157: \$(".LC_collapse_trigger").on("click", function (e) {
158: var id = this.id;
159: var \$content = \$(this).next (".LC_menus_content");
160: var expanded = \$content.hasClass ("shown");
161: if (expanded) {
162: \$content.removeClass ("shown");
163: \$content.addClass ("hidden");
164: } else {
165: \$content.removeClass ("hidden");
166: \$content.addClass ("shown");
167: }
168:
169: \$(this).find ("[aria-expanded]")
170: .attr ("aria-expanded", !expanded);
171:
172: \$(this).find ("[aria-pressed]")
173: .attr ("aria-pressed", !expanded);
174:
175: \$(this).find (".LC_collapsible_indicator").attr ({
176: "src":
177: (expanded)? "/res/adm/pages/collapsed.png" : "/res/adm/pages/expanded.png",
178: "alt":
179: (expanded)? "$lt{altc}" : "$lt{alte}",
180: "title":
1.7 raeburn 181: (expanded)? "$lt{ttlc}" : "$lt{ttle}"
1.6 raeburn 182: });
183:
184: \$(window).trigger('resize');
185: \$(this).focus ();
186: });
187:
188: \$("#LC_expandingContainer").attr ("aria-live", "off");
189: });
190: //]]>
191: </script>
192: ENDJS
193:
194: }
195:
196: sub do_redirect {
197: my ($request,$uri,$msg) = @_;
198: &Apache::lonhtmlcommon::clear_breadcrumbs();
199: $request->print(
200: &Apache::loncommon::start_page('Authoring Space',undef,
201: {'redirect' => [2,$uri]}).
202:
203: '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
204: "$msg\n".
205: &Apache::loncommon::end_page());
206: return;
207: }
208:
1.10 ! raeburn 209: sub collapsible_std_LCmenus {
! 210: my $daxecollapse = $Apache::lonnet::env{'environment.daxecollapse'};
! 211: unless ($daxecollapse) {
! 212: my %domdefs = &Apache::lonnet::get_domain_defaults($Apache::lonnet::env{'user.domain'});
! 213: if ($domdefs{'daxecollapse'}) {
! 214: $daxecollapse = 'yes';
! 215: }
! 216: }
! 217: if ($daxecollapse eq 'yes') {
! 218: return 1;
! 219: }
! 220: return;
! 221: }
! 222:
1.1 damieng 223: 1;
224: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>