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