--- loncom/interface/lonextresedit.pm 2016/01/26 14:30:25 1.9 +++ loncom/interface/lonextresedit.pm 2017/02/19 00:15:51 1.14 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: lonextresedit.pm,v 1.9 2016/01/26 14:30:25 raeburn Exp $ +# $Id: lonextresedit.pm,v 1.14 2017/02/19 00:15:51 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -259,38 +259,50 @@ sub process_changes { sub update_exttool { my ($marker,$cdom,$cnum,$args) = @_; my %toolhash=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum); - my (%newhash,$changed,$errormsg); - ($newhash{'target'},$newhash{'width'},$newhash{'height'}) = split(/:/,$args); + my (%newhash,$changed,@deleted,$errormsg); + ($newhash{'target'},$newhash{'width'},$newhash{'height'},$newhash{'crslabel'},$newhash{'crstitle'}) = split(/:/,$args); + $newhash{'crslabel'} = &unescape($newhash{'crslabel'}); + $newhash{'crstitle'} = &unescape($newhash{'crstitle'}); my %toolhash=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum); - foreach my $item ('target','width','height') { + foreach my $item ('target','width','height','crslabel','crstitle') { $newhash{$item} =~ s/^\s+//; $newhash{$item} =~ s/\s+$//; - unless ($item eq 'target') { + if (($item eq 'width') || ($item eq 'height')) { if ($newhash{'target'} eq 'iframe') { $newhash{$item} = ''; } } if ($toolhash{$item} ne $newhash{$item}) { if ($newhash{$item} eq '') { - delete($toolhash{$item}); + unless (($item eq 'target') || + ((($item eq 'width') || ($item eq 'height')) && + (($newhash{'target'} eq 'window') || + (($newhash{'target'} eq '') && ($toolhash{'target'} eq 'window'))))) { + delete($toolhash{$item}); + push(@deleted,$item); + $changed = 1; + } } else { $toolhash{$item} = $newhash{$item}; + $changed = 1; } - $changed = 1; } } if ($changed) { my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$cdom,$cnum); unless ($putres eq 'ok') { - $errormsg = &mt('Failed to save updated settings.').' '.&mt('Error: [_1].',$putres); + $errormsg = &mt('Failed to save updated settings.').' '.&mt('Error: [_1].',$putres); } } + if (@deleted) { + &Apache::lonnet::del('exttool_'.$marker,\@deleted,$cdom,$cnum); + } return ($changed,$errormsg); } sub extedit_form { my ($supplementalflag,$residx,$orig_url,$orig_title,$pathitem,$helpitem,$caller, - $symb,$type,$cdom,$cnum,$ltitools) = @_; + $symb,$type,$cdom,$cnum,$ltitools,$disabled) = @_; if ($type ne 'tool') { $type = 'ext'; } @@ -313,14 +325,17 @@ sub extedit_form { $tabid = 'ee'; } my ($formname,$formid,$toggle,$fieldsetid,$urlid,$dispdivstyle,$dimendivstyle, - $legend,$urlelem,$toolelem,%toolattr); + $labelstyle,$titlestyle,$legend,$urlelem,$toolelem,%toolattr); $formname = 'new'.$type; $toggle = $type; $fieldsetid = 'upload'.$type.'form'; $urlid = $type.'url'; - map { $toolattr{$_} = $type.$_; } ('dispdiv','dimendiv','dimenwidth','dimenheight'); + map { $toolattr{$_} = $type.$_; } ('dispdiv','dimendiv','dimenwidth','dimenheight', + 'crstitlediv','crslabeldiv','crstitle','crslabel'); $dispdivstyle = 'display:none'; $dimendivstyle = 'display:none'; + $labelstyle = 'display:none'; + $titlestyle = 'display:none'; if ($supplementalflag) { $formname = 'newsupp'.$type; $toggle = 'supp'.$type; @@ -328,10 +343,11 @@ sub extedit_form { $urlid = 'supp'.$type.'url'; map { $toolattr{$_} = 'supp'.$toolattr{$_}; } (keys(%toolattr)); } - my ($link,$legend,$active,$srcclass,$extsrc,$preview,$title,$save, + my ($link,$legend,$active,$srcclass,$extsrc,$preview,$title,$save,$crstitle,$crslabel, $fieldsetstyle,$action,$hiddenelem,$form,$width,$height,$tooltarget,%chkstate); $fieldsetstyle = 'display: none;'; $action = '/adm/coursedocs'; + my $protocol = ($ENV{'SERVER_PORT'} == 443?'https':'http'); if ($residx) { if ($caller eq 'direct') { $fieldsetstyle = 'display: block;'; @@ -362,7 +378,7 @@ sub extedit_form { $srcclass = ' class="LC_nobreak"'; if ($type eq 'ext') { $extsrc = ''.$lt{'ul'}.' '; - $preview = ' '.$lt{'pr'}.''; + $preview = ' '.$lt{'pr'}.''; } $title = ''.$lt{'ti'}.' '; $save = $lt{'sv'}; @@ -384,7 +400,7 @@ sub extedit_form { $orig_url = 'http://'; $orig_title = $lt{'ex'}; $extsrc = $lt{'ul'}.':
'; - $preview = ''; + $preview = ''; $save = $lt{'al'}; } else { $orig_title = $lt{'et'}; @@ -395,7 +411,7 @@ sub extedit_form { } $formid = $formname; if ($type eq 'ext') { - $urlelem = ''; + $urlelem = ''; } else { my $class = 'LC_nobreak'; if ($residx) { @@ -404,7 +420,6 @@ sub extedit_form { my $marker = $1; my %toolhash=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum); if ($toolhash{'id'}) { - $dispdivstyle = 'display:block'; if (ref($ltitools) eq 'HASH') { if (keys(%{$ltitools})) { if (ref($ltitools->{$toolhash{'id'}}) eq 'HASH') { @@ -423,6 +438,19 @@ sub extedit_form { } $width = $toolhash{'width'}; $height = $toolhash{'height'}; + if (ref($ltitools->{$toolhash{'id'}}->{'crsconf'}) eq 'HASH') { + if ($ltitools->{$toolhash{'id'}}->{'crsconf'}->{'title'}) { + $crstitle = $toolhash{'crstitle'}; + $titlestyle = 'display:inline'; + } + if ($ltitools->{$toolhash{'id'}}->{'crsconf'}->{'label'}) { + $crslabel = $toolhash{'crslabel'}; + $labelstyle = 'display:inline'; + } + if ($ltitools->{$toolhash{'id'}}->{'crsconf'}->{'target'}) { + $dispdivstyle = 'display:block'; + } + } $toolelem = ''.$image.' '.$tooltitle.'
'; } } @@ -432,7 +460,7 @@ sub extedit_form { } else { $toolelem = ''."\n". ''; + $toolelem .= '
'; + $crslabel = $env{'course.'.$cdom.'_'.$cnum.'.internal.coursecode'}; + $crstitle = $env{'course.'.$cdom.'_'.$cnum.'.description'}; } $toolelem .= '
'. ''.&mt('Display target:').' '. ''.(' 'x2). + "'$toolattr{dimendiv}','$toolattr{dimenwidth}','$toolattr{dimenheight}'".');"'.$disabled.'>'.&mt('iframe').''.(' 'x2). ''. + "'$toolattr{dimendiv}','$toolattr{dimenwidth}','$toolattr{dimenheight}'".');"'.$disabled.'>'.&mt('window').''. '
'. ''. - &mt('Width').''.(' 'x2). - &mt('Height').''."\n". - '
'; + &mt('Width').''.(' 'x2). + &mt('Height').''."\n". + ''. + '
'. + ''.&mt('Course label:').' '. + '
'. + '
'. + '
'. + ''.&mt('Course title:').' '. + '
'. + '
'; } my $chooser = $toolelem; if ($type eq 'ext') { @@ -487,11 +525,11 @@ $chooser
$title - + $pathitem $hiddenelem - +
@@ -506,7 +544,7 @@ ENDFORM sub display_editor { my ($url,$folderpath,$symb,$idx,$type,$cdom,$cnum) = @_; - my ($residx,$supplementalflag,$title,$pathitem,$output,$js); + my ($residx,$supplementalflag,$title,$pathitem,$output,$js,$navmap); if ($folderpath =~ /^supplemental/) { $supplementalflag = 1; $residx = $idx; @@ -516,7 +554,7 @@ sub display_editor { (my $map,$residx,my $res) = &Apache::lonnet::decode_symb($symb); $title = &Apache::lonnet::gettitle($symb); - my $path = &Apache::loncommon::symb_to_docspath($symb); + my $path = &Apache::loncommon::symb_to_docspath($symb,\$navmap); $pathitem = ''; } my %ltitools; @@ -545,7 +583,10 @@ sub extedit_javascript { $toolsjs = " var ltitools = new Array($num);\n". " var ltitoolsTarget = new Array($num);\n". " var ltitoolsWidth = new Array($num);\n". - " var ltitoolsHeight = new Array($num);\n"; + " var ltitoolsHeight = new Array($num);\n". + " var ltitoolsDisplay = new Array($num);\n". + " var ltitoolsLabel = new Array($num);\n". + " var ltitoolsTitle = new Array($num);\n"; my $i = 0; foreach my $key (sort { $a <=> $b } keys(%{$toolsref})) { if (ref($toolsref->{$key})) { @@ -556,6 +597,15 @@ sub extedit_javascript { ' ltitoolsTarget['.$i.'] = '."'$target';\n". ' ltitoolsWidth['.$i.'] = '."'$width';\n". ' ltitoolsHeight['.$i.'] = '."'$height';\n"; + my %courseconfig; + if (ref($toolsref->{$key}->{'crsconf'}) eq 'HASH') { + my $display = $toolsref->{$key}->{'crsconf'}->{'target'}; + $toolsjs .= ' ltitoolsDisplay['.$i.'] = '."'$display';\n"; + my $label = $toolsref->{$key}->{'crsconf'}->{'label'}; + $toolsjs .= ' ltitoolsLabel['.$i.'] = '."'$label';\n"; + my $title = $toolsref->{$key}->{'crsconf'}->{'title'}; + $toolsjs .= ' ltitoolsTitle['.$i.'] = '."'$title';\n"; + } $i++; } } @@ -575,7 +625,7 @@ ENDREGEXP var regexp = $urlregexp; -function setExternal(extform,residx,type,exttoolurl) { +function setExternal(extform,residx,type,exttoolurl,supplementalflag) { var title=extform.exttitle.value; if (!String.trim) { String.prototype.trim = function() {return this.replace(\/^\\s+|\\s+$\/g, "");}; } @@ -610,20 +660,56 @@ function setExternal(extform,residx,type } info += ':'+toolid; } - if (extform.exttooltarget.length) { - for (var i=0; i 0) { + dispdiv += '_'+residx; + } + if (document.getElementById(dispdiv)) { + if (document.getElementById(dispdiv).style.display == 'block') { + if (extform.exttooltarget.length) { + for (var i=0; i 0) { + labelinput += '_'+residx; + titleinput += '_'+residx; + } + if (document.getElementById(labelinput)) { + var crslabel = document.getElementById(labelinput).value; + crslabel.trim(); + info += ':'+escape(crslabel); + } else { + info += ':'; + } + if (document.getElementById(titleinput)) { + var crstitle = document.getElementById(titleinput).value; + crstitle.trim(); + info += ':'+escape(crstitle); + } else { + info += ':'; } info=escape(info); if (residx > 0) { @@ -648,11 +734,16 @@ function editext(residx,type) { return; } -function extUrlPreview(caller) { +function extUrlPreview(caller,protocol) { if (document.getElementById(caller)) { var url = document.getElementById(caller).value; if (regexp.test(url)) { - openMyModal(url,500,400,'yes'); + var http_regex = /^http\:\/\//gi; + if ((protocol == 'https') && (http_regex.test(url))) { + window.open(url,"externalpreview","height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1"); + } else { + openMyModal(url,500,400,'yes'); + } } else { alert("$js_lt{'invurl'}"); } @@ -668,6 +759,10 @@ function updateExttool(caller,form,suppl dimendiv = prefix+'tooldimendiv'; widthinput = prefix+'toolwidth'; heightinput = prefix+'toolheight'; + labeldiv = prefix+'toolcrslabeldiv'; + titlediv = prefix+'toolcrstitlediv'; + labelinput = prefix+'toolcrslabel'; + titleinput = prefix+'toolcrstitle'; if (document.getElementById(dispdiv)) { var toolpick = caller.options[caller.selectedIndex].value; $toolsjs @@ -678,41 +773,63 @@ function updateExttool(caller,form,suppl if (document.getElementById(dimendiv)) { document.getElementById(dimendiv).style.display = 'none'; } - } else { - if (document.getElementById(dispdiv)) { - document.getElementById(dispdiv).style.display = 'block'; + if (document.getElementById(labeldiv)) { + document.getElementById(labeldiv).style.display = 'none'; + } + if (document.getElementById(titlediv)) { + document.getElementById(titlediv).style.display = 'none'; } + } else { if (ltitools.length > 0) { for (var j=0; j