Annotation of loncom/html/res/adm/pages/annotator/admannotations.pm, revision 1.36

1.17      albertel    1: # The LearningOnline Network with CAPA
                      2: # This will take annotations and then plug them into a page.
                      3: #
1.36    ! raeburn     4: # $Id: admannotations.pm,v 1.35 2009/03/20 10:04:53 bisitz Exp $
1.17      albertel    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.
1.1       tyszkabe   14: #
1.17      albertel   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/
1.1       tyszkabe   27: #
                     28: ##################
                     29: 
1.29      jms        30: 
1.2       tyszkabe   31: package Apache::admannotations;
1.1       tyszkabe   32: 
                     33: use strict;
                     34: use Apache::Constants qw(:common);
1.20      albertel   35: use Apache::loncommon();
1.19      albertel   36: use Apache::lonnet;
1.23      albertel   37: use Apache::lonlocal;
1.1       tyszkabe   38: 
                     39: # --------------------------------------------------------------Put annotation
                     40: 
                     41: sub write_annotation {
1.27      albertel   42:     my ($symb, $enc, $annotation) = @_;
                     43: 
1.31      raeburn    44:     $annotation=~s/^\s*$//;
1.27      albertel   45:     my $key = $symb;
                     46:     if (!$enc) {
                     47: 	$key = 
                     48: 	    &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
1.11      www        49:     }
1.27      albertel   50: 
                     51:     &Apache::lonnet::put('nohist_annotations',{$key => $annotation});
1.1       tyszkabe   52:     return;
                     53: }
                     54: 
                     55: 
                     56: # ------------------------------------------------------------Construct editor
1.27      albertel   57: sub js_get_symb {
1.26      albertel   58:     return <<ENDJS;
1.27      albertel   59: function get_symb() {
                     60:     var symb;
1.26      albertel   61:     if (typeof(window.opener.clientwindow) != 'undefined') {
1.27      albertel   62: 	symb=window.opener.clientwindow.location.href;
1.26      albertel   63:     } else {
1.27      albertel   64: 	symb=window.opener.location.href;
1.26      albertel   65:     }
1.27      albertel   66:     symb=window.opener.currentSymb;
                     67:     return symb;
1.26      albertel   68: }
                     69: ENDJS
                     70: }
1.1       tyszkabe   71: 
                     72: sub construct_editor {
1.27      albertel   73:     my ($annotation,$symbnew) = @_;
1.13      www        74:     if ($annotation=~/^error:/) { $annotation=''; }
1.21      albertel   75: 
1.27      albertel   76:     my $get_symb = &js_get_symb();
1.26      albertel   77: 
1.35      bisitz     78:     my %lt = &Apache::lonlocal::texthash(
                     79:         'close no save' => 'Close',
                     80:         'save'          => 'Save',
                     81:         'cancel'        => 'Cancel',
                     82:     );
1.34      schafran   83: 
1.24      albertel   84:     my $js = <<ENDJS;
1.20      albertel   85: <script type="text/javascript">
1.12      www        86: var timeout;
                     87: 
1.27      albertel   88: $get_symb
1.26      albertel   89: 
1.12      www        90: function changed() {
1.27      albertel   91:     var symbnew=get_symb();
                     92:     if (symbnew!=document.annotInfo.symbold.value) {
                     93: 	document.annotInfo.symbnew.value=symbnew;
1.12      www        94:         document.annotInfo.submit();
                     95:     }
                     96:     timeout=setTimeout('changed();','1000');
1.2       tyszkabe   97: }
1.34      schafran   98: 
                     99: function renameButton(){
                    100:     document.getElementById("close").value="$lt{'cancel'}";
                    101: }
                    102: 
1.1       tyszkabe  103: </script>
1.20      albertel  104: ENDJS
                    105: 
                    106:     my %load_items = ('onload'   => "timeout=setTimeout('changed()','1000')",
                    107: 		      'onunload' => 'clearTimeout(timeout);');
                    108:     my $start_page =
                    109: 	&Apache::loncommon::start_page('Annotations',$js,
                    110: 				       {'only_body'   => 1,
                    111: 					'add_entries' => \%load_items,});
                    112: 
                    113:     my $end_page =
                    114:         &Apache::loncommon::end_page();
1.23      albertel  115:     
                    116: 	 
1.20      albertel  117:     return(<<END_HTML)
                    118: $start_page
1.5       tyszkabe  119:  <center>
1.36    ! raeburn   120:   <form name="annotInfo" method="post" action="">
1.34      schafran  121:     <textarea name="annotation" wrap="on" rows="12" cols="36" onfocus="javascript:renameButton();">$annotation</textarea><br />
1.27      albertel  122:     <input type="hidden" name="symbold" value="$symbnew" />
                    123:     <input type="hidden" name="symbnew" value="" />
1.23      albertel  124:     <input type="button" name="send" value="$lt{'save'}"
1.27      albertel  125:            onclick="javascript:this.form.symbnew.value=get_symb();this.form.submit();" />
1.34      schafran  126:     <input type="button" id="close" name="close" value="$lt{'close no save'}" 
1.22      albertel  127:            onclick="javascript:window.close();" />
                    128:   </form>
1.5       tyszkabe  129:  </center>
1.20      albertel  130: $end_page
1.1       tyszkabe  131: END_HTML
                    132: }
                    133: 
1.7       tyszkabe  134: # ----------------------------------------------------Constructs error window
1.5       tyszkabe  135: 
1.6       tyszkabe  136: sub construct_error {
1.21      albertel  137:     my ($annot_error,$button_name) = @_;
1.26      albertel  138: 
1.27      albertel  139:     my $get_symb = &js_get_symb();
1.26      albertel  140:     my $js = <<ENDJS;
                    141: <script type="text/javascript">
1.27      albertel  142: $get_symb
1.26      albertel  143: </script>
                    144: ENDJS
                    145: 
                    146:     my $start_page = &Apache::loncommon::start_page('Annotations',$js,
1.21      albertel  147: 						    {'only_body'   => 1,});
                    148:     my $end_page =  &Apache::loncommon::end_page();
1.20      albertel  149: 
1.35      bisitz    150:     my %lt = &Apache::lonlocal::texthash(
                    151:         'close'  => 'Close',
                    152:         'button' => $button_name,
                    153:     );
1.23      albertel  154: 
1.21      albertel  155:     return(<<END_HTML2)
1.20      albertel  156: $start_page
1.5       tyszkabe  157:  <center>
1.36    ! raeburn   158:   <form name="annotInfo" method="post" action="">
1.6       tyszkabe  159: <table bgcolor="#FFFFFF" width="100%" height="90%" align="center">
1.5       tyszkabe  160: <td>
1.22      albertel  161: <font size="+1"><i>
1.6       tyszkabe  162: $annot_error
1.12      www       163: </i></font>
1.5       tyszkabe  164: </td>
                    165: </table>
1.27      albertel  166:     <input type="hidden" name="symbold" value="" />
                    167:     <input type="hidden" name="symbnew" value="" />
1.23      albertel  168:     <input type="button" name="send" value="$lt{'button'}"
1.27      albertel  169:            onclick="javascript:this.form.symbnew.value=get_symb();this.form.submit();" />
1.23      albertel  170:     <input type="button" name="close" value="$lt{'close'}" 
1.22      albertel  171:            onclick="javascript:window.close();" />
                    172:   </form>
1.5       tyszkabe  173:  </center>
1.20      albertel  174: $end_page
1.5       tyszkabe  175: END_HTML2
                    176: }
                    177: 
1.27      albertel  178: 
1.7       tyszkabe  179: # ---------------------------------------------------------------Main Handler
1.1       tyszkabe  180: 
                    181: sub handler {
1.25      albertel  182:     my ($r) = @_;
                    183: 
                    184:     &Apache::loncommon::content_type($r,'text/html');
1.21      albertel  185:     $r->send_http_header;
                    186:     return OK if $r->header_only;
                    187: 
                    188:     my $page;
                    189: 
1.32      raeburn   190:     my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($env{'form.symbold'},1);
                    191:     my ($symb_new,$symb_new_enc) = &Apache::loncommon::clean_symb($env{'form.symbnew'},1);
1.27      albertel  192: 
1.21      albertel  193:     my $annotation=$env{'form.annotation'};
                    194: 
1.27      albertel  195:     if ($symb_old) {
                    196: 	&write_annotation($symb_old,$symb_old_enc,$annotation);
1.21      albertel  197:     }
1.27      albertel  198:     if (exists($env{'form.symbnew'})) {
                    199: 	unless ($symb_new) {
1.25      albertel  200: 	    $page=&construct_error(&mt("Cannot annotate current window. Please point your browser to a LON-CAPA page and then 'continue'."),"continue");
1.21      albertel  201: 	} else {
1.27      albertel  202: 	    if ($symb_old ne $symb_new) {
1.28      tempelho  203: 		$annotation=&Apache::loncommon::get_annotation($symb_new,$symb_new_enc);
1.21      albertel  204: 	    }
1.27      albertel  205: 	    # pass same symb through.
                    206: 	    $page=&construct_editor($annotation,$env{'form.symbnew'});
1.21      albertel  207: 	}
                    208:     }
                    209:     $r->print($page);
                    210:     return OK;
1.1       tyszkabe  211: }
                    212: 
                    213: 1;
                    214: __END__
1.8       tyszkabe  215: 
1.30      jms       216: =pod
                    217: 
                    218: =head1 NAME
                    219: 
                    220: Apache::admannotations
                    221: 
                    222: =head1 SYNOPSIS
                    223: 
                    224: This will take annotations and then plug them into a page.
                    225: 
                    226: This is part of the LearningOnline Network with CAPA project
                    227: described at http://www.lon-capa.org.
                    228: 
                    229: =head1 OVERVIEW
                    230: 
                    231: (empty)
                    232: 
                    233: =head1 SUBROUTINES
                    234: 
                    235: =over write_annotation()
                    236: 
                    237: Put annotation
                    238: 
                    239: =item js_get_symb()
                    240: 
                    241: Construct editor
                    242: 
                    243: =item construct_editor()
                    244: 
                    245: =item construct_error()
                    246: 
                    247: =item handler()
                    248: 
                    249: =back
                    250: 
                    251: =cut
                    252: 
                    253: 

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