[LON-CAPA-cvs] cvs: loncom /homework daxepage.pm

raeburn raeburn at source.lon-capa.org
Sat Mar 23 19:11:52 EDT 2024


raeburn		Sat Mar 23 23:11:52 2024 EDT

  Modified files:              
    /loncom/homework	daxepage.pm 
  Log:
  - Buttons above Daxe Editor iframe include: "Save and Edit", "Save and View",
    and "Discard and View" for consistency with UI for other editors.
  
  
Index: loncom/homework/daxepage.pm
diff -u loncom/homework/daxepage.pm:1.11 loncom/homework/daxepage.pm:1.12
--- loncom/homework/daxepage.pm:1.11	Sun Mar  3 18:16:27 2024
+++ loncom/homework/daxepage.pm	Sat Mar 23 23:11:52 2024
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Page with Daxe on the left side and the preview on the right side
 #
-# $Id: daxepage.pm,v 1.11 2024/03/03 18:16:27 raeburn Exp $
+# $Id: daxepage.pm,v 1.12 2024/03/23 23:11:52 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -72,37 +72,50 @@
     my %lt = &Apache::lonlocal::texthash(
                                           'noif' => 'No iframe support.',
                                           'show' => 'Show content in pop-up window',
+                                          'save' => 'Save',
                                           'oeds' => 'other editors',
                                           'othe' => 'other editor',
-                                          'edit' => 'Edit',
-                                          'exit' => 'Exit Daxe',
+                                          'edit' => 'Save and Edit',
+                                          'disc' => 'Discard and View',
+                                          'save' => 'Save and View',
                                         );
     my $name = $uri;
     $name =~ s/^.*\/([^\/]+)$/$1/;
+    my $filearg = '/daxeopen'.$uri;
     my $daxeurl = '/adm/daxe/daxe.html?config=config/loncapa_config.xml&save=/daxesave'.
-                  '&file=/daxeopen'.$uri;
+                  '&file='.$filearg;
     my $headjs = &Apache::loncommon::iframe_wrapper_headjs().
-                 &toggle_LCmenus_js().
+                 &listener_js($filearg).
+                 &toggle_LCmenus_js().&saveandview_js().
                  &Apache::edit::js_change_detection();
-    my $clickexit; 
+
+    my ($clickexit,$clicksave,$clickedit);
     if ($is_assess) {
         $headjs .= &Apache::lonxml::setmode_javascript();
-        $clickexit = "javascript:setmode(this.form,'view')";
+        $clickexit = "javascript:setmode(this.form,'view');";
     } else {
         $headjs .= &Apache::lonxml::seteditor_javascript();
-        $clickexit = "javascript:seteditmode(this.form,'view')";
+        $clickexit = "javascript:seteditmode(this.form,'view');";
     }
+    $clicksave = "javascript:daxesave('exit');";
+    $clickedit = "javascript:daxesave();";
     my $form_events = &Apache::edit::form_change_detection();
     my $editheader = '<form '.$form_events.' method="post" name="daxeedit" action="'.$uri.'">'.
                      '<input type="hidden" name="problemmode" value="daxe" />'."\n".
                      '<div class="LC_edit_problem_editxml_header">'."\n";
-    my $exitbutton = '<input type="button" name="submitmode" accesskey="t" value="'.$lt{'exit'}.
+    my $saveeditbutton = '<input type="button" name="submitmode" accesskey="s" value="'.$lt{'edit'}.
+                     '" onclick="'.$clickedit.'" />'."\n";
+    my $exitbutton = '<input type="button" name="submitmode" accesskey="d" value="'.$lt{'disc'}.
                      '" onclick="'.$clickexit.'" />'."\n";
+    my $saveexitbutton = '<input type="button" name="submitmode" accesskey="v" value="'.$lt{'save'}.
+                     '" onclick="'.$clicksave.'" />'."\n";
+    $editheader .= '<table class="LC_edit_problem_header_title"><tr><td>'.
+                   $uri.'</td><td align="right"><span class="LC_nobreak">'.
+                   $saveeditbutton.$saveexitbutton.$exitbutton.'</span>';
     if ($editors{'edit'} || $editors{'xml'}) {
         my $other = (($editors{'edit'} && $editors{'xml'})? $lt{'oeds'} : $lt{'othe'});
-        $editheader .= '<table class="LC_edit_problem_header_title"><tr><td>'.
-                       $uri.
-                       '</td><td align="right"><span class="LC_nobreak">'.$other.': ';
+        $editheader .= '  |  <span class="LC_nobreak">'.$other.':</span> '.
+                       '<span class="LC_nobreak">';
         if ($is_not_assess) {
             $editheader .= '<input type="hidden" name="editmode" value="" />'."\n".
                            '<input type="button" name="editordefault" value="'.$lt{'edit'}.
@@ -117,14 +130,9 @@
                                'onclick="javascript:setmode(this.form,'."'editxml'".')" />'."\n";
             }
         }
-        $editheader .= '  |  '.$exitbutton.'</span></td></tr></table>';
-    } else {
-        $editheader .= '<table class="LC_edit_problem_header_title"><tr><td>'.
-                       $uri.
-                       '</td><td align="right"><span class="LC_nobreak">'.
-                       $exitbutton.'</span></td></tr></table>';
+        $editheader .= '</span>';
     }
-    $editheader .= '</div></form>'."\n";
+    $editheader .= '</td></tr></table></div></form>'."\n";
     my $start_collapsed = &collapsible_std_LCmenus();
     my $args = {
                 'collapsible_header' => $editheader,
@@ -143,13 +151,57 @@
 $startpage
 $script
 <div class="LC_iframecontainer" style="padding-right: 5px">
-<iframe src="$dest">$lt{'noif'} $noiframe</iframe>
+<iframe src="$dest" id="lcdiframe">$lt{'noif'} $noiframe</iframe>
 </div>
 $endpage
 ENDFRAME
     return OK;
 }
 
+sub listener_js {
+    my ($filearg) = @_;
+    return <<"ENDJS";
+<script type="text/javascript">
+//<![CDATA[
+
+var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
+var eventer = window[eventMethod];
+var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message";
+
+eventer(messageEvent,function(e) {
+    var reqdOrigin = window.location.protocol+'//'+window.location.hostname;
+    if (e.origin == reqdOrigin) {
+        if (e.data == '$filearg') {
+            setmode(document.daxeedit,'view');
+        }
+        return;
+    }
+},false);
+
+//]]>
+</script>
+ENDJS
+
+}
+
+sub saveandview_js {
+    return <<"ENDJS";
+
+<script type="text/javascript">
+//<![CDATA[
+
+function daxesave(exit) {
+    window.myIframe = document.getElementById("lcdiframe").contentWindow;
+    window.myIframe.focus();
+    window.myIframe.savelcdoc(exit);
+    return;
+}
+
+//]]>
+</script>
+ENDJS
+}
+
 sub toggle_LCmenus_js {
     my %lt = &Apache::lonlocal::texthash(
                                          altc => 'menu state: collapsed',




More information about the LON-CAPA-cvs mailing list