Annotation of loncom/homework/daxepage.pm, revision 1.6

1.1       damieng     1: # The LearningOnline Network
                      2: # Page with Daxe on the left side and the preview on the right side
                      3: #
1.6     ! raeburn     4: # $Id: daxepage.pm,v 1.5 2023/08/23 20:58:32 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();
        !            34: use Apache::lonhtmlcommon();
        !            35: use Apache::lonmenu();
        !            36: use Apache::lonlocal;
        !            37: use Apache::Constants qw(:common);
        !            38: use HTML::Entities();
1.1       damieng    39: 
                     40: sub handler {
                     41:     my $request = shift;
                     42:     my $uri = $request->uri;
1.5       raeburn    43:     $uri =~ s{^/daxepage}{};
1.4       raeburn    44:     &Apache::loncommon::content_type($request,'text/html');
1.2       damieng    45:     if ($uri !~ /\.(task|problem|exam|quiz|assess|survey|library|xml|html|htm|xhtml|xhtm)$/) {
1.1       damieng    46:         $request->status(406);
                     47:         return OK;
                     48:     }
1.6     ! raeburn    49:     my %editors = &Apache::loncommon::permitted_editors();
        !            50:     unless ($editors{'daxe'}) {
        !            51:         my $msg = '<p class="LC_warning">'.
        !            52:                   &mt('Daxe editor is not enabled for this Authoring Space.').'</p>';
        !            53:         &do_redirect($request,$uri,$msg);
        !            54:         return OK;
        !            55:     }
        !            56:     my %lt = &Apache::lonlocal::texthash(
        !            57:                                           'noif' => 'No iframe support.',
        !            58:                                           'show' => 'Show content in pop-up window',
        !            59:                                         );
1.1       damieng    60:     my $name = $uri;
                     61:     $name =~ s/^.*\/([^\/]+)$/$1/;
1.6     ! raeburn    62:     my $daxeurl = '/adm/daxe/daxe.html?config=config/loncapa_config.xml&save=/daxesave'.
        !            63:                   '&file=/daxeopen'.$uri;
        !            64:     my $headjs = &Apache::loncommon::iframe_wrapper_headjs().
        !            65:                  &toggle_LCmenus_js();
        !            66:     my $args = {
        !            67:                 'collapsible_header' => 1,
        !            68:                };
        !            69:     my $startpage = &Apache::loncommon::start_page('Daxe: '.$name,$headjs,$args).
        !            70:                     &Apache::lonmenu::constspaceform();
        !            71:     my $endpage = &Apache::loncommon::end_page();
        !            72: 
        !            73:     # javascript will position the iframe if window was resized (or zoomed)
        !            74:     my $script = &Apache::loncommon::iframe_wrapper_resizejs();
        !            75:     my $dest = &HTML::Entities::encode($daxeurl,'&<>"');
        !            76:     my $noiframe = &Apache::loncommon::modal_link($dest,$lt{'show'},500,400);
        !            77: 
        !            78:     $request->print(<<"ENDFRAME");
        !            79: $startpage
        !            80: $script
        !            81: <div class="LC_iframecontainer" style="padding-right: 5px">
        !            82: <iframe src="$dest">$lt{'noif'} $noiframe</iframe>
        !            83: </div>
        !            84: $endpage
        !            85: ENDFRAME
1.1       damieng    86:     return OK;
                     87: }
                     88: 
1.6     ! raeburn    89: sub toggle_LCmenus_js {
        !            90:     my %lt = &Apache::lonlocal::texthash(
        !            91:                                          altc => 'menu state: collapsed',
        !            92:                                          alte => 'menu state: explanded',
        !            93:                                          ttlc => 'display standard menus',
        !            94:                                          ttle => 'hide standard menus',
        !            95:     );
        !            96:     return <<"ENDJS";
        !            97: <script type="text/javascript">
        !            98: //<![CDATA[
        !            99: \$(document).ready (function () {
        !           100:     \$(".LC_collapse_trigger").on("click", function (e) {
        !           101:         var id = this.id;
        !           102:         var \$content = \$(this).next (".LC_menus_content");
        !           103:         var expanded = \$content.hasClass ("shown");
        !           104:         var frameleftpos;
        !           105:         if (expanded) {
        !           106:             \$content.removeClass ("shown");
        !           107:             \$content.addClass ("hidden");
        !           108:         } else {
        !           109:             \$content.removeClass ("hidden");
        !           110:             \$content.addClass ("shown");
        !           111:         }
        !           112: 
        !           113:         \$(this).find ("[aria-expanded]")
        !           114:         .attr ("aria-expanded", !expanded);
        !           115: 
        !           116:         \$(this).find ("[aria-pressed]")
        !           117:         .attr ("aria-pressed", !expanded);
        !           118: 
        !           119:         \$(this).find (".LC_collapsible_indicator").attr ({
        !           120:         "src":
        !           121:         (expanded)? "/res/adm/pages/collapsed.png" : "/res/adm/pages/expanded.png",
        !           122:         "alt":
        !           123:         (expanded)? "$lt{altc}" : "$lt{alte}",
        !           124:         "title":
        !           125:         (expanded)? "$lt{ttlc}" : "$lt(ttle}"
        !           126:         });
        !           127: 
        !           128:         \$(window).trigger('resize');
        !           129:         \$(this).focus ();
        !           130:     });
        !           131: 
        !           132:     \$("#LC_expandingContainer").attr ("aria-live", "off");
        !           133: });
        !           134: //]]>
        !           135: </script>
        !           136: ENDJS
        !           137: 
        !           138: }
        !           139: 
        !           140: sub do_redirect {
        !           141:     my ($request,$uri,$msg) = @_;
        !           142:     &Apache::lonhtmlcommon::clear_breadcrumbs();
        !           143:     $request->print(
        !           144:         &Apache::loncommon::start_page('Authoring Space',undef,
        !           145:                                        {'redirect'       => [2,$uri]}).
        !           146: 
        !           147:         '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
        !           148:         "$msg\n".
        !           149:         &Apache::loncommon::end_page());
        !           150:     return;
        !           151: }
        !           152: 
1.1       damieng   153: 1;
                    154: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>