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