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