File:
[LON-CAPA] /
loncom /
homework /
daxepage.pm
Revision
1.14:
download - view:
text,
annotated -
select for diffs
Sun Mar 31 01:50:18 2024 UTC (15 months, 1 week ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Support "Save and Edit", "Save and View", and "Discard and View" buttons
above Daxe Editor iframe, when editing HTML file in Daxe, for consistency
with UI for standard "Text" Editor for this type of file.
1: # The LearningOnline Network
2: # Page with Daxe on the left side and the preview on the right side
3: #
4: # $Id: daxepage.pm,v 1.14 2024/03/31 01:50:18 raeburn Exp $
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;
31: use strict;
32:
33: use Apache::loncommon();
34: use Apache::lonnet();
35: use Apache::lonhtmlcommon();
36: use Apache::lonxml();
37: use Apache::edit();
38: use Apache::lonmenu();
39: use Apache::lonlocal;
40: use Apache::Constants qw(:common);
41: use LONCAPA qw(:DEFAULT :match);
42: use HTML::Entities();
43:
44: sub handler {
45: my $request = shift;
46: my $uri = $request->uri;
47: $uri =~ s{^/daxepage}{};
48: &Apache::loncommon::content_type($request,'text/html');
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) {
58: $request->status(406);
59: return OK;
60: }
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: }
68: if ($is_not_assess) {
69: delete($editors{'xml'});
70: $editors{'edit'} = 1;
71: }
72: my %lt = &Apache::lonlocal::texthash(
73: 'noif' => 'No iframe support.',
74: 'show' => 'Show content in pop-up window',
75: 'save' => 'Save',
76: 'text' => 'Text Editor',
77: 'oeds' => 'other editors',
78: 'othe' => 'other editor',
79: 'edit' => 'Save and Edit',
80: 'disc' => 'Discard and View',
81: 'save' => 'Save and View',
82: );
83: my $name = $uri;
84: $name =~ s/^.*\/([^\/]+)$/$1/;
85: my $lang = &Apache::lonlocal::current_language();
86: my $filearg = '/daxeopen'.$uri;
87: my $daxeurl = '/adm/daxe/daxe.html?config=config/loncapa_config.xml&save=/daxesave'.
88: '&file='.$filearg;
89: my $headjs = &Apache::loncommon::iframe_wrapper_headjs().
90: &listener_js($lang,$filearg,$is_assess).
91: &toggle_LCmenus_js().&saveandview_js().
92: &Apache::edit::js_change_detection();
93:
94: my ($clickexit,$clicksave,$clickedit);
95: if ($is_assess) {
96: $headjs .= &Apache::lonxml::setmode_javascript();
97: $clickexit = "javascript:setmode(this.form,'view');";
98: } else {
99: $headjs .= &Apache::lonxml::seteditor_javascript();
100: $clickexit = "javascript:seteditmode(this.form,'view');";
101: }
102: $clicksave = "javascript:daxesave('exit');";
103: $clickedit = "javascript:daxesave();";
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";
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'}.
111: '" onclick="'.$clickexit.'" />'."\n";
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>';
117: if ($editors{'edit'} || $editors{'xml'}) {
118: my $other = (($editors{'edit'} && $editors{'xml'})? $lt{'oeds'} : $lt{'othe'});
119: $editheader .= ' | <span class="LC_nobreak">'.$other.':</span> '.
120: '<span class="LC_nobreak">';
121: if ($is_not_assess) {
122: $editheader .= '<input type="hidden" name="editmode" value="" />'."\n".
123: '<input type="button" name="editordefault" value="'.$lt{'text'}.
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: }
135: $editheader .= '</span>';
136: }
137: $editheader .= '</td></tr></table></div></form>'."\n";
138: my $start_collapsed = &collapsible_std_LCmenus();
139: my $args = {
140: 'collapsible_header' => $editheader,
141: 'start_collapsed' => $start_collapsed,
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">
156: <iframe src="$dest" id="lcdiframe">$lt{'noif'} $noiframe</iframe>
157: </div>
158: $endpage
159: ENDFRAME
160: return OK;
161: }
162:
163: sub listener_js {
164: my ($lang,$filearg,$is_assess) = @_;
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;
175: var is_assess = '$is_assess';
176: if (e.origin == reqdOrigin) {
177: if (e.data == '$filearg') {
178: if (is_assess) {
179: setmode(document.daxeedit,'view');
180: } else {
181: seteditmode(document.daxeedit,'view');
182: }
183: } else if ((e.data == 'userlclang') || (e.data == 'userlang')) {
184: window.myIframe = document.getElementById("lcdiframe").contentWindow;
185: window.myIframe.postMessage(e.data+':$lang',reqdOrigin);
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:
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":
250: (expanded)? "$lt{ttlc}" : "$lt{ttle}"
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:
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:
292: 1;
293: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>