Annotation of loncom/homework/daxepage.pm, revision 1.17
1.1 damieng 1: # The LearningOnline Network
2: # Page with Daxe on the left side and the preview on the right side
3: #
1.17 ! raeburn 4: # $Id: daxepage.pm,v 1.16 2024/04/17 14:15:45 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.15 raeburn 49: my ($is_not_assess,$is_assess,$is_course_doc,$is_supp,$supp_path,$supp_title);
1.9 raeburn 50: if ($uri =~/\.(xml|html|htm|xhtml|xhtm)$/) {
51: $is_not_assess = 1;
1.15 raeburn 52: if ($Apache::lonnet::env{'request.course.id'}) {
53: my $cid = $Apache::lonnet::env{'request.course.id'};
54: my $cdom = $Apache::lonnet::env{'course.'.$cid.'.domain'};
55: my $cnum = $Apache::lonnet::env{'course.'.$cid.'.num'};
56: if ($uri =~ m{^/uploaded/\Q$cdom/$cnum\E/(docs|supplemental)/}) {
57: if ($1 eq 'supplemental') {
58: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
59: ['folderpath','title']);
60: $is_supp = 1;
61: $supp_path = &escape(&HTML::Entities::decode($Apache::lonnet::env{'form.folderpath'}));
62: $supp_title = &escape(&HTML::Entities::decode($Apache::lonnet::env{'form.title'}));
63: }
64: $is_course_doc = 1;
65: $Apache::lonnet::env{'form.forceedit'} = 1;
66: }
67: }
1.9 raeburn 68: } elsif ($uri =~ /$LONCAPA::assess_re/) {
69: unless ($uri =~ /\.form$/) {
70: $is_assess = 1;
71: }
72: }
73: unless ($is_not_assess || $is_assess) {
1.1 damieng 74: $request->status(406);
75: return OK;
76: }
1.15 raeburn 77: my %editors = &Apache::loncommon::permitted_editors($uri);
1.6 raeburn 78: unless ($editors{'daxe'}) {
79: my $msg = '<p class="LC_warning">'.
80: &mt('Daxe editor is not enabled for this Authoring Space.').'</p>';
81: &do_redirect($request,$uri,$msg);
82: return OK;
83: }
1.9 raeburn 84: if ($is_not_assess) {
85: delete($editors{'xml'});
86: $editors{'edit'} = 1;
1.17 ! raeburn 87: $Apache::lonnet::env{'form.editmode'} = 'daxe';
! 88: } else {
! 89: $Apache::lonnet::env{'form.problemmode'} = 'daxe';
1.9 raeburn 90: }
1.16 raeburn 91: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.6 raeburn 92: my %lt = &Apache::lonlocal::texthash(
93: 'noif' => 'No iframe support.',
94: 'show' => 'Show content in pop-up window',
1.12 raeburn 95: 'save' => 'Save',
1.15 raeburn 96: 'text' => 'Text Editor',
1.9 raeburn 97: 'oeds' => 'other editors',
98: 'othe' => 'other editor',
1.12 raeburn 99: 'edit' => 'Save and Edit',
100: 'disc' => 'Discard and View',
101: 'save' => 'Save and View',
1.6 raeburn 102: );
1.1 damieng 103: my $name = $uri;
104: $name =~ s/^.*\/([^\/]+)$/$1/;
1.13 raeburn 105: my $lang = &Apache::lonlocal::current_language();
1.12 raeburn 106: my $filearg = '/daxeopen'.$uri;
1.6 raeburn 107: my $daxeurl = '/adm/daxe/daxe.html?config=config/loncapa_config.xml&save=/daxesave'.
1.12 raeburn 108: '&file='.$filearg;
1.6 raeburn 109: my $headjs = &Apache::loncommon::iframe_wrapper_headjs().
1.14 raeburn 110: &listener_js($lang,$filearg,$is_assess).
1.12 raeburn 111: &toggle_LCmenus_js().&saveandview_js().
1.9 raeburn 112: &Apache::edit::js_change_detection();
1.12 raeburn 113:
114: my ($clickexit,$clicksave,$clickedit);
1.9 raeburn 115: if ($is_assess) {
116: $headjs .= &Apache::lonxml::setmode_javascript();
1.12 raeburn 117: $clickexit = "javascript:setmode(this.form,'view');";
1.9 raeburn 118: } else {
1.15 raeburn 119: $headjs .= &Apache::lonxml::seteditor_javascript($is_course_doc,$is_supp,
120: $supp_path,$supp_title);
1.12 raeburn 121: $clickexit = "javascript:seteditmode(this.form,'view');";
1.9 raeburn 122: }
1.12 raeburn 123: $clicksave = "javascript:daxesave('exit');";
124: $clickedit = "javascript:daxesave();";
1.9 raeburn 125: my $form_events = &Apache::edit::form_change_detection();
1.15 raeburn 126: my $editheader = '<form '.$form_events.' method="post" name="daxeedit" action="'.$uri.'">';
127: if ($is_assess) {
128: $editheader .= '<input type="hidden" name="problemmode" value="daxe" />'."\n";
129: }
130: $editheader .= '<div class="LC_edit_problem_editxml_header">'."\n";
1.12 raeburn 131: my $saveeditbutton = '<input type="button" name="submitmode" accesskey="s" value="'.$lt{'edit'}.
132: '" onclick="'.$clickedit.'" />'."\n";
133: my $exitbutton = '<input type="button" name="submitmode" accesskey="d" value="'.$lt{'disc'}.
1.11 raeburn 134: '" onclick="'.$clickexit.'" />'."\n";
1.12 raeburn 135: my $saveexitbutton = '<input type="button" name="submitmode" accesskey="v" value="'.$lt{'save'}.
136: '" onclick="'.$clicksave.'" />'."\n";
137: $editheader .= '<table class="LC_edit_problem_header_title"><tr><td>'.
138: $uri.'</td><td align="right"><span class="LC_nobreak">'.
139: $saveeditbutton.$saveexitbutton.$exitbutton.'</span>';
1.9 raeburn 140: if ($editors{'edit'} || $editors{'xml'}) {
141: my $other = (($editors{'edit'} && $editors{'xml'})? $lt{'oeds'} : $lt{'othe'});
1.12 raeburn 142: $editheader .= ' | <span class="LC_nobreak">'.$other.':</span> '.
143: '<span class="LC_nobreak">';
1.9 raeburn 144: if ($is_not_assess) {
1.17 ! raeburn 145: $editheader .= '<input type="hidden" name="editmode" value="daxe" />'."\n".
1.14 raeburn 146: '<input type="button" name="editordefault" value="'.$lt{'text'}.
1.15 raeburn 147: '" onclick="javascript:seteditmode(this.form,'."'edit'".');" />'."\n";
1.9 raeburn 148: } else {
149: if ($editors{'edit'}) {
150: $editheader .= '<input type="button" name="submitmode" accesskey="e" value="'.&mt('Edit').'" '.
151: 'onclick="javascript:setmode(this.form,'."'edit'".')" />'."\n";
152: }
153: if ($editors{'xml'}) {
154: $editheader .= '<input type="button" name="submitmode" accesskey="x" value="'.&mt('EditXML').'" '.
155: 'onclick="javascript:setmode(this.form,'."'editxml'".')" />'."\n";
156: }
157: }
1.12 raeburn 158: $editheader .= '</span>';
1.9 raeburn 159: }
1.12 raeburn 160: $editheader .= '</td></tr></table></div></form>'."\n";
1.10 raeburn 161: my $start_collapsed = &collapsible_std_LCmenus();
1.6 raeburn 162: my $args = {
1.9 raeburn 163: 'collapsible_header' => $editheader,
1.10 raeburn 164: 'start_collapsed' => $start_collapsed,
1.6 raeburn 165: };
166: my $startpage = &Apache::loncommon::start_page('Daxe: '.$name,$headjs,$args).
167: &Apache::lonmenu::constspaceform();
168: my $endpage = &Apache::loncommon::end_page();
169:
170: # javascript will position the iframe if window was resized (or zoomed)
171: my $script = &Apache::loncommon::iframe_wrapper_resizejs();
172: my $dest = &HTML::Entities::encode($daxeurl,'&<>"');
173: my $noiframe = &Apache::loncommon::modal_link($dest,$lt{'show'},500,400);
174:
175: $request->print(<<"ENDFRAME");
176: $startpage
177: $script
178: <div class="LC_iframecontainer" style="padding-right: 5px">
1.12 raeburn 179: <iframe src="$dest" id="lcdiframe">$lt{'noif'} $noiframe</iframe>
1.6 raeburn 180: </div>
181: $endpage
182: ENDFRAME
1.1 damieng 183: return OK;
184: }
185:
1.12 raeburn 186: sub listener_js {
1.14 raeburn 187: my ($lang,$filearg,$is_assess) = @_;
1.12 raeburn 188: return <<"ENDJS";
189: <script type="text/javascript">
190: //<![CDATA[
191:
192: var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
193: var eventer = window[eventMethod];
194: var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message";
195:
196: eventer(messageEvent,function(e) {
197: var reqdOrigin = window.location.protocol+'//'+window.location.hostname;
1.14 raeburn 198: var is_assess = '$is_assess';
1.12 raeburn 199: if (e.origin == reqdOrigin) {
200: if (e.data == '$filearg') {
1.14 raeburn 201: if (is_assess) {
202: setmode(document.daxeedit,'view');
203: } else {
204: seteditmode(document.daxeedit,'view');
205: }
1.13 raeburn 206: } else if ((e.data == 'userlclang') || (e.data == 'userlang')) {
207: window.myIframe = document.getElementById("lcdiframe").contentWindow;
208: window.myIframe.postMessage(e.data+':$lang',reqdOrigin);
1.12 raeburn 209: }
210: return;
211: }
212: },false);
213:
214: //]]>
215: </script>
216: ENDJS
217:
218: }
219:
220: sub saveandview_js {
221: return <<"ENDJS";
222:
223: <script type="text/javascript">
224: //<![CDATA[
225:
226: function daxesave(exit) {
227: window.myIframe = document.getElementById("lcdiframe").contentWindow;
228: window.myIframe.focus();
229: window.myIframe.savelcdoc(exit);
230: return;
231: }
232:
233: //]]>
234: </script>
235: ENDJS
236: }
237:
1.6 raeburn 238: sub toggle_LCmenus_js {
239: my %lt = &Apache::lonlocal::texthash(
240: altc => 'menu state: collapsed',
241: alte => 'menu state: explanded',
242: ttlc => 'display standard menus',
243: ttle => 'hide standard menus',
244: );
245: return <<"ENDJS";
246: <script type="text/javascript">
247: //<![CDATA[
248: \$(document).ready (function () {
249: \$(".LC_collapse_trigger").on("click", function (e) {
250: var id = this.id;
251: var \$content = \$(this).next (".LC_menus_content");
252: var expanded = \$content.hasClass ("shown");
253: if (expanded) {
254: \$content.removeClass ("shown");
255: \$content.addClass ("hidden");
256: } else {
257: \$content.removeClass ("hidden");
258: \$content.addClass ("shown");
259: }
260:
261: \$(this).find ("[aria-expanded]")
262: .attr ("aria-expanded", !expanded);
263:
264: \$(this).find ("[aria-pressed]")
265: .attr ("aria-pressed", !expanded);
266:
267: \$(this).find (".LC_collapsible_indicator").attr ({
268: "src":
269: (expanded)? "/res/adm/pages/collapsed.png" : "/res/adm/pages/expanded.png",
270: "alt":
271: (expanded)? "$lt{altc}" : "$lt{alte}",
272: "title":
1.7 raeburn 273: (expanded)? "$lt{ttlc}" : "$lt{ttle}"
1.6 raeburn 274: });
275:
276: \$(window).trigger('resize');
277: \$(this).focus ();
278: });
279:
280: \$("#LC_expandingContainer").attr ("aria-live", "off");
281: });
282: //]]>
283: </script>
284: ENDJS
285:
286: }
287:
288: sub do_redirect {
289: my ($request,$uri,$msg) = @_;
290: &Apache::lonhtmlcommon::clear_breadcrumbs();
291: $request->print(
292: &Apache::loncommon::start_page('Authoring Space',undef,
293: {'redirect' => [2,$uri]}).
294:
295: '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
296: "$msg\n".
297: &Apache::loncommon::end_page());
298: return;
299: }
300:
1.10 raeburn 301: sub collapsible_std_LCmenus {
302: my $daxecollapse = $Apache::lonnet::env{'environment.daxecollapse'};
303: unless ($daxecollapse) {
304: my %domdefs = &Apache::lonnet::get_domain_defaults($Apache::lonnet::env{'user.domain'});
305: if ($domdefs{'daxecollapse'}) {
306: $daxecollapse = 'yes';
307: }
308: }
309: if ($daxecollapse eq 'yes') {
310: return 1;
311: }
312: return;
313: }
314:
1.1 damieng 315: 1;
316: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>