[LON-CAPA-cvs] cvs: doc /loncapafiles loncapafiles.lpml loncom/interface londocs.pm lonextresedit.pm
raeburn
raeburn at source.lon-capa.org
Tue Nov 27 18:34:48 EST 2012
raeburn Tue Nov 27 23:34:48 2012 EDT
Added files:
/loncom/interface lonextresedit.pm
Modified files:
/loncom/interface londocs.pm
/doc/loncapafiles loncapafiles.lpml
Log:
- Consistent interface for templated pages and External Resource.
- Move editing form and javascript functions from londocs.pm to
lonextresedit.pm to facilitate re-use.
- Will allow direct editing of External Resource (i.e., without
entering Content Editor.
-------------- next part --------------
Index: loncom/interface/londocs.pm
diff -u loncom/interface/londocs.pm:1.509 loncom/interface/londocs.pm:1.510
--- loncom/interface/londocs.pm:1.509 Fri Nov 16 23:37:15 2012
+++ loncom/interface/londocs.pm Tue Nov 27 23:34:41 2012
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.509 2012/11/16 23:37:15 raeburn Exp $
+# $Id: londocs.pm,v 1.510 2012/11/27 23:34:41 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -41,6 +41,7 @@
use Apache::lonnavmaps;
use Apache::lonnavdisplay();
use Apache::lonuserstate();
+use Apache::lonextresedit();
use HTML::Entities;
use HTML::TokeParser;
use GDBM_File;
@@ -1693,10 +1694,12 @@
$supplementalflag,$orderhash,$iconpath,$pathitem)=@_;
my $container= ($env{'form.pagepath'}) ? 'page'
: 'sequence';
-
- my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,$is_random_order) =
- &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
- $r->print($breadcrumbtrail);
+ my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order);
+ if ($allowed) {
+ (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,$is_random_order) =
+ &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
+ $r->print($breadcrumbtrail);
+ }
my $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
@@ -1864,30 +1867,56 @@
$shown++;
}
&Apache::loncommon::end_data_table_count();
-
- if ($shown) {
- $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
- .&Apache::loncommon::start_data_table(undef,'contentlist');
- if ($allowed) {
- $to_show .= &Apache::loncommon::start_data_table_header_row()
- .'<th colspan="2">'.&mt('Move').'</th>'
- .'<th>'.&mt('Actions').'</th>'
- .'<th colspan="2">'.&mt('Document').'</th>';
- if ($folder !~ /^supplemental/) {
- $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
+
+ if (($allowed) || ($supplementalflag && $folder eq 'supplemental')) {
+ if ($shown) {
+ if ($allowed) {
+ $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
+ .&Apache::loncommon::start_data_table(undef,'contentlist')
+ .&Apache::loncommon::start_data_table_header_row()
+ .'<th colspan="2">'.&mt('Move').'</th>'
+ .'<th>'.&mt('Actions').'</th>'
+ .'<th colspan="2">'.&mt('Document').'</th>';
+ if ($folder !~ /^supplemental/) {
+ $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
+ }
+ $to_show .= &Apache::loncommon::end_data_table_header_row()
+ .$output.' '
+ .&Apache::loncommon::end_data_table()
+ .'<br style="line-height:2px;" />'
+ .&Apache::loncommon::end_scrollbox();
+ } else {
+ $to_show = '<table><tr><td>'.&Apache::loncommon::help_open_menu('Navigation Screen','Navigation_Screen',undef,'RAT')
+ .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
+ .'<td align="left"><ul id="LC_toolbar">'
+ .'<li><a href="/adm/coursedocs?forcesupplement=1" '
+ .'id="LC_content_toolbar_edittoplevel" '
+ .'class="LC_toolbarItem" '
+ .'title="'.&mt('Supplemental Content Editor').'">'
+ .'</a></li></ul></td></tr></table><br />'
+ .&Apache::loncommon::start_data_table('LC_tableOfContent')
+ .$output.' '
+ .&Apache::loncommon::end_data_table();
}
- $to_show .= &Apache::loncommon::end_data_table_header_row();
+ } else {
+ $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
+ .'<div class="LC_info" id="contentlist">'
+ .&mt('Currently no documents.')
+ .'</div>'
+ .&Apache::loncommon::end_scrollbox();
}
- $to_show .= $output.' '
- .&Apache::loncommon::end_data_table()
- .'<br style="line-height:2px;" />'
- .&Apache::loncommon::end_scrollbox();
} else {
- $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
- .'<div class="LC_info" id="contentlist">'
- .&mt('Currently no documents.')
- .'</div>'
- .&Apache::loncommon::end_scrollbox();
+ if ($shown) {
+ $to_show = '<div>'
+ .&Apache::loncommon::start_data_table('LC_tableOfContent')
+ .$output
+ .&Apache::loncommon::end_data_table()
+ .'</div>';
+ } else {
+ $to_show = '<div class="LC_info" id="contentlist">'
+ .&mt('Currently no documents.')
+ .'</div>'
+ }
}
my $tid = 1;
if ($supplementalflag) {
@@ -1899,19 +1928,6 @@
$readfile));
&print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
} else {
- if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
- #Function Box for Supplemental Content for users with mdc priv.
- my $funcname = &mt('Folder Editor');
- $r->print(
- &Apache::loncommon::head_subbox(
- &Apache::lonhtmlcommon::start_funclist().
- &Apache::lonhtmlcommon::add_item_funclist(
- '<a href="/adm/coursedocs?command=direct&forcesupplement=1&'.
- 'supppath='.&HTML::Entities::encode($env{'form.folderpath'}).'">'.
- '<img src="/res/adm/pages/docs-22x22.png" alt="'.$funcname.'" class="LC_icon" />'.
- '<span class="LC_menubuttons_inline_text">'.$funcname.'</span></a>').
- &Apache::lonhtmlcommon::end_funclist()));
- }
$r->print($to_show);
}
return;
@@ -2111,18 +2127,20 @@
$path = &HTML::Entities::encode($env{'form.pagepath'},'<>&"');
}
my $isexternal;
- if (!$supplementalflag && $residx) {
+ if ($residx) {
my $currurl = $url;
$currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
if ($currurl =~ m{^/adm/wrapper/ext/}) {
$isexternal = 1;
}
- my $path = 'uploaded/'.
- $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
- $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
- $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
- $residx,
- &Apache::lonnet::declutter($currurl));
+ if (!$supplementalflag) {
+ my $path = 'uploaded/'.
+ $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
+ $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
+ $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
+ $residx,
+ &Apache::lonnet::declutter($currurl));
+ }
}
my %lt;
if ($allowed) {
@@ -2338,7 +2356,7 @@
my $editlink;
my $orig_url = $url;
$orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
- my $external = ($url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/});
+ $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
if (!$supplementalflag && $residx && $symb) {
if ($container eq 'page') {
$url=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
@@ -2359,7 +2377,6 @@
}
} elsif ($url=~m|^/ext/|) {
$url='/adm/wrapper'.$url;
- $external = 1;
}
if (&Apache::lonnet::symbverify($symb,$url)) {
$url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
@@ -2373,9 +2390,14 @@
my $foldername=&escape($foldertitle);
my $folderpath=$env{'form.folderpath'};
if ($folderpath) { $folderpath.='&' };
+ if (!$allowed && $supplementalflag) {
+ $folderpath.=$folderarg.'&'.$foldername;
+ $url.='folderpath='.&escape($folderpath);
+ } else {
# Append randompick number, hidden, and encrypted with ":" to foldername,
# so it gets transferred between levels
- $folderpath.=$folderarg.'&'.$foldername.':'.(&LONCAPA::map::getparameter($orderidx,
+ $folderpath.=$folderarg.'&'.$foldername.
+ ':'.(&LONCAPA::map::getparameter($orderidx,
'parameter_randompick'))[0]
.':'.((&LONCAPA::map::getparameter($orderidx,
'parameter_hiddenresource'))[0]=~/^yes$/i)
@@ -2383,31 +2405,38 @@
'parameter_encrypturl'))[0]=~/^yes$/i)
.':'.((&LONCAPA::map::getparameter($orderidx,
'parameter_randomorder'))[0]=~/^yes$/i);
- $url.='folderpath='.&escape($folderpath);
- my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
- 'parameter_randompick'))[0];
- my $rpckchk;
- if ($rpicknum) {
- $rpckchk = ' checked="checked"';
- }
- my $formname = 'edit_rpick_'.$orderidx;
- $rand_pick_text =
+ $url.='folderpath='.&escape($folderpath);
+ my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
+ 'parameter_randompick'))[0];
+ my $rpckchk;
+ if ($rpicknum) {
+ $rpckchk = ' checked="checked"';
+ }
+ my $formname = 'edit_rpick_'.$orderidx;
+ $rand_pick_text =
'<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
$form_common."\n".
'<span class="LC_nobreak"><label><input type="checkbox" name="randpickon_'.$orderidx.'" id="rpick_'.$orderidx.'" onclick="'."updatePick(this.form,'$orderidx','check');".'"'.$rpckchk.' /> '.&mt('Randomly Pick').'</label><input type="hidden" name="randompick_'.$orderidx.'" id="rpicknum_'.$orderidx.'" value="'.$rpicknum.'" />';
- if ($rpicknum ne '') {
- $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
- }
- $rand_pick_text .= '</span></form>';
- my $ro_set=
- ((&LONCAPA::map::getparameter($orderidx,'parameter_randomorder'))[0]=~/^yes$/i?' checked="checked"':'');
- $rand_order_text =
+ if ($rpicknum ne '') {
+ $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
+ }
+ $rand_pick_text .= '</span></form>';
+ my $ro_set=
+ ((&LONCAPA::map::getparameter($orderidx,'parameter_randomorder'))[0]=~/^yes$/i?' checked="checked"':'');
+ $rand_order_text =
$form_start.
$form_common.'
<span class="LC_nobreak"><label><input type="checkbox" name="randomorder_'.$orderidx.'" onclick="'."this.form.changeparms.value='randomorder';this.form.submit()".'" '.$ro_set.' /> '.&mt('Random Order').' </label></span></form>';
+ }
} elsif ($supplementalflag && !$allowed) {
- $url .= ($url =~ /\?/) ? 'amp;':'?';
+ $url .= ($url =~ /\?/) ? '&':'?';
$url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
+ if ($title) {
+ $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
+ }
+ if ($orderidx) {
+ $url .= '&idx='.$orderidx;
+ }
}
if ($ispage) {
my $pagename=&escape($pagetitle);
@@ -2421,30 +2450,9 @@
if ($allowed) {
my $fileloc =
&Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
-
- if ($external) {
- $editlink = <<"EXTLNK";
-
- <a class="LC_docs_ext_edit" href="javascript:editext('$residx');">
- $lt{'ed'}</a>
- <form action="/adm/coursedocs" method="post" name="editext_$residx">
- <fieldset id="uploadext$residx" style="display: none;" />
- <input type="hidden" name="active" value="aa" />
- <span class="LC_nobreak">
- <span class="LC_docs_ext_edit">$lt{'ul'} </span>
- <input type="text" size="40" name="exturl" id="exturl_$residx" value="$orig_url" />
- <a class="LC_docs_ext_edit" href="javascript:extUrlPreview('exturl_$residx');">$lt{'pr'}</a></span>
- </span><br />
- <span class="LC_nobreak">
- <span class="LC_docs_ext_edit">$lt{'ti'} </span>
- <input type="text" size="40" name="exttitle" value="$title" />
- $pathitem
- <input type="hidden" name="importdetail" value="" />
- <input type="button" value="$lt{'sv'}" onclick="javascript:setExternal(this.form,'$residx')" />
- </span>
- </fieldset>
- </form>
-EXTLNK
+ if ($isexternal) {
+ $editlink =
+ &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem);
} else {
my ($cfile,$home,$switchserver,$forceedit,$forceview) =
&Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
@@ -3215,7 +3223,7 @@
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
['folderpath','pagepath',
'pagesymb','forcesupplement','forcestandard',
- 'tools','symb','command']);
+ 'tools','symb','command','supppath']);
# standard=1: this is a "new-style" course with an uploaded map as top level
# standard=2: this is a "old-style" course, and there is nothing we can do
@@ -3285,21 +3293,31 @@
}
}
}
- $path .= '&'.&Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
- &Apache::lonhtmlcommon::entity_encode($mapresobj->title()).
+ $path =~ s/^\&//;
+ my $maptitle = $mapresobj->title();
+ if ($mapurl eq 'default') {
+ $maptitle = 'Main Course Documents';
+ }
+ $path .= ($path ne '')? '&' : ''.
+ &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
+ &Apache::lonhtmlcommon::entity_encode($maptitle).
':'.$mapresobj->randompick().
':'.$mapresobj->randomout().
':'.$mapresobj->encrypted().
':'.$mapresobj->randomorder();
} else {
my $maptitle = &Apache::lonnet::gettitle($mapurl);
- $path = '&default&...::::'.
- '&'.&Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
- &Apache::lonhtmlcommon::entity_encode($maptitle).'::::';
+ if ($mapurl eq 'default') {
+ $maptitle = 'Main Course Documents';
+ }
+ $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
+ &Apache::lonhtmlcommon::entity_encode($maptitle).'::::';
+ }
+ unless ($mapurl eq 'default') {
+ $path = 'default&'.
+ &Apache::lonhtmlcommon::entity_encode('Main Course Documents').
+ '::::&'.$path;
}
- $path = 'default&'.
- &Apache::lonhtmlcommon::entity_encode('Main Course Documents').
- $path;
if ($type eq 'sequence') {
$env{'form.folderpath'}=$path;
$env{'form.pagepath'}='';
@@ -3326,10 +3344,10 @@
$stored_folderpath='docs_sup_folderpath';
}
-# No folderpath, no pagepath, see if we have something stored
- if ((!$env{'form.folderpath'}) && (!$env{'form.pagepath'})) {
+# No folderpath, no pagepath, and in edit mode, see if we have something stored
+ if ((!$env{'form.folderpath'}) && (!$env{'form.pagepath'}) && $allowed) {
&Apache::loncommon::restore_course_settings($stored_folderpath,
- {'folderpath' => 'scalar'});
+ {'folderpath' => 'scalar'});
}
# If we are not allowed to make changes, all we can see are supplemental docs
@@ -3361,9 +3379,11 @@
# Store this
unless ($toolsflag) {
- &Apache::loncommon::store_course_settings($stored_folderpath,
- {'pagepath' => 'scalar',
- 'folderpath' => 'scalar'});
+ if ($allowed) {
+ &Apache::loncommon::store_course_settings($stored_folderpath,
+ {'pagepath' => 'scalar',
+ 'folderpath' => 'scalar'});
+ }
if ($env{'form.folderpath'}) {
my (@folderpath)=split('&',$env{'form.folderpath'});
$env{'form.foldername'}=&unescape(pop(@folderpath));
@@ -3439,7 +3459,8 @@
$script .= &editing_js($udom,$uname,$supplementalflag).
&history_tab_js().
&inject_data_js().
- &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr);
+ &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr).
+ &Apache::lonextresedit::extedit_javascript();
$addentries = {
onload => "javascript:resize_scrollbox('contentscroll','1','1');",
};
@@ -3461,22 +3482,26 @@
# Breadcrumbs
&Apache::lonhtmlcommon::clear_breadcrumbs();
- unless ($showdoc) {
+
+ if ($showdoc) {
+ $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
+ {'force_register' => $showdoc,}));
+ } elsif ($r->uri eq '/adm/supplemental') {
+ my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
+ $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
+ {'bread_crumbs' => $brcrum,}));
+ } else {
&Apache::lonhtmlcommon::add_breadcrumb({
href=>"/adm/coursedocs",text=>"$crstype Contents"});
$r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
- {'force_register' => $showdoc,
- 'add_entries' => $addentries,
- })
+ {'add_entries' => $addentries}
+ )
.&Apache::loncommon::help_open_menu('','',273,'RAT')
.&Apache::lonhtmlcommon::breadcrumbs(
'Editing '.$crstype.' Contents',
'Docs_Adding_Course_Doc')
);
- } else {
- $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
- {'force_register' => $showdoc,}));
}
my %allfiles = ();
@@ -3672,27 +3697,9 @@
{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap();" />' => $importpubform }
);
$importpubform = &create_form_ul(&create_list_elements(@importpubforma));
-
- my $extresourcesform=(<<ERFORM);
- <a class="LC_menubuttons_link" href="javascript:toggleUpload('ext');">$lt{'extr'}</a>$help{'Adding_External_Resource'}
- <form action="/adm/coursedocs" method="post" name="newext">
- <fieldset id="uploadextform" style="display: none;" />
- <legend>$lt{'extr'}</legend>
- <input type="hidden" name="active" value="aa" />
- $lt{'url'}:<br />
- <input type="text" size="60" name="exturl" id="exturl" value="http://" />
- <input type="button" name="view" value="$lt{'prev'}" onclick="javascript:extUrlPreview('exturl');" /><br />
- $lt{'title'}:<br />
- <input type="text" size="60" name="exttitle" value="$lt{'extr'}" />
- $pathitem
- <br />
- <input type="hidden" name="importdetail" value="" />
- <input type="button" value="$lt{'lnk'}" onclick="javascript:setExternal(this.form,0)" />
- </fieldset>
- </form>
-ERFORM
-
-
+ my $extresourcesform =
+ &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
+ $help{'Adding_External_Resource'});
if ($allowed) {
my $folder = $env{'form.folder'};
if ($folder eq '') {
@@ -3716,11 +3723,16 @@
}
# Generate the tabs
- my $mode;
+ my ($mode,$needs_end);
if (($supplementalflag) && (!$allowed)) {
- &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
+ my @folders = split('&',$env{'form.folderpath'});
+ unless (@folders > 2) {
+ &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
+ $needs_end = 1;
+ }
} else {
$r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
+ $needs_end = 1;
}
#
@@ -4011,24 +4023,9 @@
</form>
SNFFORM
- my $supextform=(<<ERFORM);
- <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppext');">$lt{'extr'}</a>$help{'Adding_External_Resource'}
- <form action="/adm/coursedocs" method="post" name="newsuppext">
- <fieldset id="uploadsuppextform" style="display: none;" />
- <legend>$lt{'extr'}</legend>
- <input type="hidden" name="active" value="ee" />
- $lt{'url'}:<br />
- <input type="text" size="60" name="exturl" id="exturl" value="http://" />
- <input type="button" name="view" value="$lt{'prev'}" onclick="javascript:extUrlPreview('exturl');" /><br />
- $lt{'title'}:<br />
- <input type="text" size="60" name="exttitle" value="$lt{'extr'}" />
- <br />
- $pathitem
- <input type="hidden" name="importdetail" value="" />
- <input type="button" value="$lt{'lnk'}" onclick="javascript:setExternal(this.form,0)" />
- </fieldset>
- </form>
-ERFORM
+ my $supextform =
+ &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
+ $help{'Adding_External_Resource'});
my $supnewsylform=(<<SNSFORM);
<form action="/adm/coursedocs" method="post" name="supnewsyl">
@@ -4087,7 +4084,9 @@
}
}
- $r->print(&endContentScreen());
+ if ($needs_end) {
+ $r->print(&endContentScreen());
+ }
if ($allowed) {
$r->print('
@@ -4465,10 +4464,6 @@
$fieldsets = "'suppext','suppdoc'";
}
- my $urlregexp = <<'ENDREGEXP';
-/^([a-z]([a-z]|\d|\+|-|\.)*):(\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?((\[(|(v[\da-f]{1,}\.(([a-z]|\d|-|\.|_|~)|[!\$&'\(\)\*\+,;=]|:)+))\])|((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=])*)(:\d*)?)(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*|(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|!
@)*)*)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)){0})(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i
-ENDREGEXP
-
return <<ENDNEWSCRIPT;
function makenewfolder(targetform,folderseq) {
var foldername=prompt('$lt{"p_mnf"}','$lt{"t_mnf"}');
@@ -4486,20 +4481,6 @@
}
}
-function editext(residx) {
- if (document.getElementById('uploadext'+residx)) {
- var curr = document.getElementById('uploadext'+residx).style.display;
- if (curr == 'none') {
- disp = 'block';
- } else {
- disp = 'none';
- }
- document.getElementById('uploadext'+residx).style.display=disp;
- }
- resize_scrollbox('contentscroll','1','1');
- return;
-}
-
function makeexamupload() {
var title=prompt('$lt{"p_mxu"}');
if (title) {
@@ -4582,26 +4563,15 @@
function toggleMap() {
var disp = 'none';
- var curr = document.getElementById('importmapform').style.display;
- if (curr == 'none') {
- disp='block';
- }
- document.getElementById('importmapform').style.display=disp;
- resize_scrollbox('contentscroll','1','1');
- return;
-}
-
-
-function extUrlPreview(caller) {
- if (document.getElementById(caller)) {
- var url = document.getElementById(caller).value;
- var regexp = $urlregexp;
- if (regexp.test(url)) {
- openMyModal(url,500,400,'yes');
- } else {
- alert("$lt{'invurl'}");
+ if (document.getElementById('importmapform')) {
+ var curr = document.getElementById('importmapform').style.display;
+ if (curr == 'none') {
+ disp='block';
}
+ document.getElementById('importmapform').style.display=disp;
+ resize_scrollbox('contentscroll','1','1');
}
+ return;
}
function makeims(imsform) {
@@ -4617,31 +4587,6 @@
imsform.submit();
}
-function setExternal(extform,residx) {
- var title=extform.exttitle.value;
- if (!String.trim) {
- String.prototype.trim = function() {return this.replace(\/^\\s+|\\s+$\/g, "");}; }
- var url=extform.exturl.value;
- var regexp = $urlregexp;
- if (title == null || title.trim()=="") {
- alert("$lt{'titbl'}");
- extform.exttitle.focus();
- return;
- }
- if (regexp.test(url)) {
- url = escape(url);
- if (residx > 0) {
- eval("extform.importdetail.value=title+'='+url+'='+residx;extform.submit();");
- } else {
- eval("extform.importdetail.value=title+'='+url;extform.submit();");
- }
- } else {
- alert("$lt{'invurl'}");
- extform.exturl.focus();
- return;
- }
-}
-
function changename(folderpath,index,oldtitle,container,pagesymb) {
var title=prompt('$lt{"p_chn"}',oldtitle);
if (title) {
Index: doc/loncapafiles/loncapafiles.lpml
diff -u doc/loncapafiles/loncapafiles.lpml:1.815 doc/loncapafiles/loncapafiles.lpml:1.816
--- doc/loncapafiles/loncapafiles.lpml:1.815 Fri Nov 16 14:44:44 2012
+++ doc/loncapafiles/loncapafiles.lpml Tue Nov 27 23:34:47 2012
@@ -2,7 +2,7 @@
"http://lpml.sourceforge.net/DTD/lpml.dtd">
<!-- loncapafiles.lpml -->
-<!-- $Id: loncapafiles.lpml,v 1.815 2012/11/16 14:44:44 goltermann Exp $ -->
+<!-- $Id: loncapafiles.lpml,v 1.816 2012/11/27 23:34:47 raeburn Exp $ -->
<!--
@@ -2363,6 +2363,15 @@
<status>works/unverified</status>
</file>
<file>
+<source>loncom/interface/lonextresedit.pm</source>
+<target dist='default'>home/httpd/lib/perl/Apache/lonextresedit.pm</target>
+<categoryname>handler</categoryname>
+<description>
+Handler to edit external resource.
+</description>
+<status>works/unverified</status>
+</file>
+<file>
<source>loncom/interface/lonpickcode.pm</source>
<target dist='default'>home/httpd/lib/perl/Apache/lonpickcode.pm</target>
<categoryname>handler</categoryname>
Index: loncom/interface/lonextresedit.pm
+++ loncom/interface/lonextresedit.pm
# The LearningOnline Network
# Documents
#
# $Id: lonextresedit.pm,v 1.1 2012/11/27 23:34:41 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
package Apache::lonextresedit;
use strict;
use Apache::Constants qw(:common :http);
use HTML::Entities;
use Apache::lonlocal;
use Apache::lonnet;
use Apache::loncommon;
use Apache::lonhtmlcommon;
use Apache::lonuserstate;
use LONCAPA::map();
use LONCAPA qw(:DEFAULT :match);
sub handler {
my $r=shift;
&Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
return OK if $r->header_only;
# Check for access
if (! &Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
$env{'user.error.msg'}=
$r->uri.":mdc:0:0:Cannot modify course content.";
return HTTP_NOT_ACCEPTABLE;
}
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
my ($supplementalflag,$updated,$output,$errormsg,$residx,$url,$title,$symb);
if ((($env{'form.folderpath'} =~ /^supplemental/) && ($env{'form.suppurl'})) ||
($env{'form.symb'} =~ /^uploaded/)) {
$supplementalflag = 1;
($updated,$output,$errormsg,$residx,$url,$title,$symb) =
&process_changes($supplementalflag,$cdom,$cnum,$chome);
if ($supplementalflag) {
if ($url ne $env{'form.suppurl'}) {
$env{'form.suppurl'} = $url;
}
if ($title ne $env{'form.title'}) {
$env{'form.title'} = $title;
}
} else {
if ($symb ne $env{'form.symb'}) {
$env{'form.symb'} = $symb;
}
}
} else {
$errormsg = &mt('Information about external resource to edit is missing.');
}
if ($updated) {
$output = &Apache::lonhtmlcommon::confirm_success(&mt('External Resource updated'));
}
if ($errormsg) {
$errormsg = '<p class="LC_error">'.$errormsg.'</p>';
}
my $js = &Apache::lonhtmlcommon::scripttag(&extedit_javascript());
my $pathitem = '<input type="hidden" name="folderpath" value="'.
&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
$r->print(&Apache::loncommon::start_page('External Resource Editor',$js).
'<div class="LC_left_float">'.
$output.
$errormsg.
&extedit_form($supplementalflag,$residx,$url,$title,$pathitem,undef,
'direct',$env{'form.symb'}).
'</div>'.&Apache::loncommon::end_page());
return OK;
}
sub process_changes {
my ($supplementalflag,$cdom,$cnum,$chome) = @_;
my ($folder,$container,$output,$errormsg,$updated,$symb,$oldidx,$oldurl,
$oldtitle,$residx,$newurl,$newtitle);
if ($env{'form.symb'}) {
$symb = $env{'form.symb'};
(my $map,$oldidx,my $url)=&Apache::lonnet::decode_symb($symb);
if ($map =~ m{^uploaded/$cdom/$cnum/(default(_\d+|))\.(sequence|page)$}) {
$folder = $1;
$container = $3;
}
if ($url =~ m{^ext/(.+)$}) {
$oldurl = $1;
if ($oldurl !~ m{^https://}) {
$oldurl = 'http://'.$oldurl;
}
}
$oldtitle = &Apache::lonnet::gettitle($env{'form.symb'});
} elsif ($env{'form.folderpath'}) {
$folder = &unescape( (split('&',$env{'form.folderpath'}))[-2] );
$oldurl = &unescape($env{'form.suppurl'});
$oldtitle = &unescape($env{'form.title'});
$container = 'sequence';
$supplementalflag = 1;
}
if ($folder && $container) {
if ($env{'form.importdetail'}) {
my ($errtext,$fatal,$mismatchedid);
($newtitle,$newurl, $residx) =
map {&unescape($_)} split(/\=/,$env{'form.importdetail'});
if (!$supplementalflag && $oldidx) {
if ($oldidx != $residx) {
$mismatchedid = 1;
$residx = $oldidx;
}
}
my @imports;
if ($mismatchedid) {
$errormsg = 'Wrong item identifier';
} elsif (($newtitle eq $oldtitle) && ($newurl eq $oldurl)) {
$output = &mt('No change');
} else {
my $map = "/uploaded/$cdom/$cnum/$folder.$container";
my ($errtext,$fatal) = &LONCAPA::map::mapread($map);
if ($fatal) {
$errormsg = &mt('Update failed: [_1].',$errtext);
} else {
my $saveurl = &LONCAPA::map::qtunescape($newurl);
my $savetitle = &LONCAPA::map::qtunescape($newtitle);
$LONCAPA::map::resources[$residx] =
join(':', ($savetitle,$saveurl,'true','normal','res'));
my ($outtext,$errtext) = &LONCAPA::map::storemap($map,1);
if ($errtext) {
$errormsg = &mt('Update failed: [_1].',$errtext);
} else {
$updated = 1;
if (!$supplementalflag) {
if ($newurl ne $oldurl) {
$symb = &Apache::lonnet::encode_symb($map,$residx,"ext/$newurl");
} else {
$symb = $env{'form.symb'};
if ($symb) {
&Apache::lonnet::devalidate_title_cache($symb);
}
}
}
my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
if ($ferr) {
$errormsg = &mt('Reload failed: [_1].',$ferr);
} else {
&Apache::loncommon::update_content_constraints($cdom,$cnum,$chome,
$cdom.'_'.$cnum);
}
}
}
}
} else {
$output = &mt('No change');
}
} else {
$errormsg = &mt('Information about current external resource is incomplete.');
}
if ($updated) {
return ($updated,$output,$errormsg,$residx,$newurl,$newtitle,$symb);
} else {
return ($updated,$output,$errormsg,$residx,$oldurl,$oldtitle,$symb);
}
}
sub extedit_form {
my ($supplementalflag,$residx,$orig_url,$orig_title,$pathitem,$helpitem,$caller,$symb) = @_;
my %lt = &Apache::lonlocal::texthash(
ex => 'External Resource',
ed => 'Edit',
ee => 'External Resource Editor',
pr => 'Preview',
sv => 'Save',
ul => 'URL',
ti => 'Title',
al => 'Add Link',
);
my $formname = 'newext';
my $tabid = 'aa';
my $toggle = 'ext';
my $fieldsetid = 'uploadextform';
my $urlid = 'exturl';
my $size = 60;
if ($supplementalflag) {
$formname = 'newsuppext';
$tabid = 'ee';
$toggle = 'suppext';
$fieldsetid = 'uploadsuppextform';
$urlid = 'suppexturl';
}
my ($link,$legend,$active,$srcclass,$extsrc,$preview,$title,$save,
$fieldsetstyle,$action,$hiddenelem);
$fieldsetstyle = 'display: none;';
$action = '/adm/coursedocs';
if ($residx) {
if ($caller eq 'direct') {
$fieldsetstyle = 'display: block;';
$action = '/adm/extresedit';
$legend = "<legend>$lt{'ee'}</legend>";
if ($symb) {
$hiddenelem = '<input type="hidden" name="symb" value="'.$symb.'" />';
} elsif ($supplementalflag) {
$hiddenelem = '<input type="hidden" name="suppurl" value="'.
&HTML::Entities::encode(&escape($orig_url),'<>&"').'" />'."\n".
'<input type="hidden" name="title" value="'.
&HTML::Entities::encode(&escape($orig_title),'<>&"').'" />';
}
} else {
$link = '<a class="LC_docs_ext_edit" href="javascript:editext('."'$residx'".');">'.$lt{'ed'}.'</a>';
$size = 40;
$active = '<input type="hidden" name="active" value="'.$tabid.'" />';
}
$formname = "editext_$residx";
$fieldsetid = "uploadext$residx";
$urlid = "exturl_$residx";
$srcclass = ' class="LC_nobreak"';
$extsrc = '<span class="LC_docs_ext_edit">'.$lt{'ul'}.' </span>';
$preview = ' <a class="LC_docs_ext_edit" href="javascript:extUrlPreview('."'$urlid'".');">'.$lt{'pr'}.'</a>';
$title = '<span class="LC_docs_ext_edit">'.$lt{'ti'}.' </span>';
$save = $lt{'sv'};
} else {
$link = '<a class="LC_menubuttons_link" href="javascript:toggleUpload('."'$toggle'".');">'.$lt{'ex'}.'</a>'.$helpitem;
$legend = "<legend>$lt{'ex'}</legend>";
$extsrc = $lt{'ul'}.':<br />';
$title = $lt{'ti'}.':<br />';
$residx = 0;
$orig_url = 'http://';
$orig_title = $lt{'ex'};
$preview = '<input type="button" name="view" value="'.$lt{'pr'}.'" onclick="javascript:extUrlPreview('."'$urlid'".');" />';
$save = $lt{'al'};
$pathitem .= '<br />';
}
return <<ENDFORM
$link
<form action="$action" method="post" name="$formname">
<fieldset id="$fieldsetid" style="$fieldsetstyle" />
$legend
$active
<span$srcclass>
$extsrc
<input type="text" size="$size" name="exturl" id="$urlid" value="$orig_url" />
$preview
</span>
<br />
<span$srcclass>
$title
<input type="text" size="$size" name="exttitle" value="$orig_title" />
<input type="hidden" name="importdetail" value="" />
$pathitem
$hiddenelem
<input type="button" value="$save" onclick="javascript:setExternal(this.form,'$residx');" />
</span>
</fieldset>
</form>
ENDFORM
}
sub display_editor {
my ($url,$folderpath,$symb,$idx) = @_;
my ($residx,$supplementalflag,$title,$pathitem,$output);
if ($folderpath =~ /^supplemental/) {
$supplementalflag = 1;
$residx = $idx;
$title = &unescape($env{'form.title'});
$pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
} elsif ($symb =~ /^uploaded/) {
(my $map,$residx,my $res) =
&Apache::lonnet::decode_symb($symb);
$title = &Apache::lonnet::gettitle($symb);
my $path = &Apache::lonnet::getdocspath($symb);
if ($map =~ /\.page$/) {
$pathitem = '<input type="hidden" name="pagepath" value="'.&HTML::Entities::encode($path,'<>&"').'" />';
} else {
$pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($path,'<>&"').'" />';
}
}
my $js = &Apache::lonhtmlcommon::scripttag(&extedit_javascript());
my $args = { 'force_register' => $env{'form.register'} };
return &Apache::loncommon::start_page('External Resource Editor',$js,$args).
'<div class="LC_left_float">'.
&extedit_form($supplementalflag,$residx,$url,$title,$pathitem,undef,'direct',$symb).
'</div>'.
&Apache::loncommon::end_page();
}
sub extedit_javascript {
my %lt = &Apache::lonlocal::texthash(
invurl => 'Invalid URL',
titbl => 'Title is blank',
);
my $urlregexp = <<'ENDREGEXP';
/^([a-z]([a-z]|\d|\+|-|\.)*):(\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?((\[(|(v[\da-f]{1,}\.(([a-z]|\d|-|\.|_|~)|[!\$&'\(\)\*\+,;=]|:)+))\])|((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=])*)(:\d*)?)(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*|(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@!
)*)*)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)){0})(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i
ENDREGEXP
return <<ENDJS;
var regexp = $urlregexp;
function setExternal(extform,residx) {
var title=extform.exttitle.value;
if (!String.trim) {
String.prototype.trim = function() {return this.replace(\/^\\s+|\\s+$\/g, "");}; }
var url=extform.exturl.value;
if (title == null || title.trim()=="") {
alert("$lt{'titbl'}");
extform.exttitle.focus();
return;
}
if (regexp.test(url)) {
url = escape(url);
if (residx > 0) {
eval("extform.importdetail.value=title+'='+url+'='+residx;extform.submit();");
} else {
eval("extform.importdetail.value=title+'='+url;extform.submit();");
}
} else {
alert("$lt{'invurl'}");
extform.exturl.focus();
return;
}
}
function editext(residx) {
if (document.getElementById('uploadext'+residx)) {
var curr = document.getElementById('uploadext'+residx).style.display;
if (curr == 'none') {
disp = 'block';
} else {
disp = 'none';
}
document.getElementById('uploadext'+residx).style.display=disp;
}
resize_scrollbox('contentscroll','1','1');
return;
}
function extUrlPreview(caller) {
if (document.getElementById(caller)) {
var url = document.getElementById(caller).value;
if (regexp.test(url)) {
openMyModal(url,500,400,'yes');
} else {
alert("$lt{'invurl'}");
}
}
}
ENDJS
}
1;
More information about the LON-CAPA-cvs
mailing list