From 64be2d6ce14149c335f3ac863254faa126f2bea0 Mon Sep 17 00:00:00 2001 From: dongsheng Date: Mon, 11 Aug 2008 03:30:09 +0000 Subject: [PATCH] MDL-13766, some small changes for repository api. --- lang/en_utf8/repository.php | 6 ++++- lib/form/filepicker.php | 8 +++---- repository/lib.php | 44 +++++++++++++++++++++---------------- repository/ws.php | 5 +++-- 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/lang/en_utf8/repository.php b/lang/en_utf8/repository.php index af0dd13e70..21d671ac65 100644 --- a/lang/en_utf8/repository.php +++ b/lang/en_utf8/repository.php @@ -1,13 +1,16 @@ getFrozenHtml(); } else { $strsaved = get_string('filesaved', 'repository'); - $itemid = substr(hexdec(uniqid()), 0, 9)+rand(1,100); if(empty($COURSE->context)) { $ctx = get_context_instance(CONTEXT_SYSTEM); } else { @@ -54,17 +53,16 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_button $ret = get_repository_client($ctx); $suffix = $ret['suffix']; $str = $this->_getTabs(); - $str .= ''; + $str .= ''; $id = $this->_attributes['id']; $str .= << -function updatefile(){ - alert('$strsaved'); +function updatefile_$suffix(){ document.getElementById('repo_info_$suffix').innerHTML = '$strsaved'; } function callpicker_$suffix(){ var el=document.getElementById('${id}_${suffix}'); - openpicker_$suffix({"env":"form", 'itemid': $itemid, 'target':el, 'callback':updatefile}) + openpicker_$suffix({"env":"form", 'target':el, 'callback':updatefile_$suffix}) } EOD; diff --git a/repository/lib.php b/repository/lib.php index 1762960ef5..d6b4f04d3d 100644 --- a/repository/lib.php +++ b/repository/lib.php @@ -395,7 +395,6 @@ function move_to_filepool($path, $name, $itemid) { $fs = get_file_storage(); $browser = get_file_browser(); if ($file = $fs->create_file_from_pathname($entry, $path)) { - $id = json_encode($file->get_itemid()); $ret = $browser->get_file_info($context, $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename()); return array('url'=>$ret->get_url(),'id'=>$file->get_itemid()); } else { @@ -424,6 +423,10 @@ function get_repository_client($context){ $strdownload = get_string('download', 'repository'); $strback = get_string('back', 'repository'); $strclose = get_string('close', 'repository'); + $strdownload = get_string('downloadsucc', 'repository'); + $strnoenter = get_string('noenter', 'repository'); + $strsearching = get_string('searching', 'repository'); + $stradd = get_string('add', 'repository'); $js = << @@ -485,7 +488,7 @@ function get_repository_client($context){ underlay: 'none', width: '510px', zindex: 666666, - xy: [100, 100] + xy: ['50%', YAHOO.util.Dom.getDocumentScrollTop()] }); // construct code section { @@ -600,7 +603,10 @@ function get_repository_client($context){ } _client.loading = function(){ var panel = new YAHOO.util.Element('panel-$suffix'); - panel.get('element').innerHTML = '$strloading'; + panel.get('element').innerHTML = ''; + var content = document.createElement('div'); + content.innerHTML = '$strloading'; + panel.get('element').appendChild(content); } _client.rename = function(oldname, url){ var panel = new YAHOO.util.Element('panel-$suffix'); @@ -743,15 +749,11 @@ function get_repository_client($context){ _client.download = function(){ var title = document.getElementById('newname-$suffix').value; var file = document.getElementById('fileurl-$suffix').value; - var itemid = 1; - if(_client.itemid){ - itemid = _client.itemid; - } _client.loading(); var trans = YAHOO.util.Connect.asyncRequest('POST', - '$CFG->wwwroot/repository/ws.php?ctx_id=$context->id&repo_id='+_client.repositoryid+ - '&action=download', - _client.dlfile, _client.postdata({'itemid': itemid, 'env':_client.env, 'file':file, 'title':title})); + '$CFG->wwwroot/repository/ws.php?ctx_id=$context->id&repo_id=' + +_client.repositoryid+'&action=download', + _client.dlfile, _client.postdata({'env':_client.env, 'file':file, 'title':title})); } _client.login = function(){ var obj = {}; @@ -814,9 +816,16 @@ function get_repository_client($context){ panel.get('element').innerHTML = ret.e; return; } - var html = '

Download Successfully!

'; - html += ''; - panel.get('element').innerHTML = html; + var title = document.createElement('h1'); + title.innerHTML = '$strdownload'; + var btn = document.createElement('button'); + btn.innerHTML = '$stradd'; + btn.onclick = function(){ + repository_client_$suffix.end(ret); + } + panel.get('element').innerHTML = ''; + panel.get('element').appendChild(title); + panel.get('element').appendChild(btn); } } // request file list or login @@ -827,9 +836,9 @@ function get_repository_client($context){ var trans = YAHOO.util.Connect.asyncRequest('GET', '$CFG->wwwroot/repository/ws.php?ctx_id=$context->id&repo_id='+id+'&p='+path+'&reset='+reset+'&env='+_client.env, _client.callback); } _client.search = function(id){ - var data = window.prompt("What are you searching for?"); - if(data == null || data == '') { - alert('nothing entered'); + var data = window.prompt("$strsearching"); + if(data == '') { + alert('$strnoenter'); return; } _client.viewbar.set('disabled', false); @@ -854,9 +863,6 @@ EOD; repository_client_$suffix.target = obj.target; repository_client_$suffix.instance = new repository_client_$suffix(); repository_client_$suffix.instance.create_picker(); - if(obj.itemid){ - repository_client_$suffix.itemid = obj.itemid; - } if(obj.callback){ repository_client_$suffix.formcallback = obj.callback; } else { diff --git a/repository/ws.php b/repository/ws.php index 9cde46dab6..de364f4ad1 100644 --- a/repository/ws.php +++ b/repository/ws.php @@ -10,7 +10,8 @@ $p = optional_param('p', '', PARAM_INT); // opened in editor or moodleform $env = optional_param('env', 'form', PARAM_ALPHA); // file to download -$file = optional_param('file', '', PARAM_URL); +// TODO: which type should be? +$file = optional_param('file', '', PARAM_RAW); // rename the file name $title = optional_param('title', '', PARAM_FILE); $action = optional_param('action', '', PARAM_ALPHA); @@ -21,7 +22,6 @@ $repo_id = optional_param('repo_id', 1, PARAM_INT); // what will happen if user use a fake ctx_id? // Think about using $SESSION save it $ctx_id = optional_param('ctx_id', SITEID, PARAM_INT); -$itemid = optional_param('itemid', 0, PARAM_INT); $userid = $USER->id; if(!$repository = $DB->get_record('repository', array('id'=>$repo_id))) @@ -67,6 +67,7 @@ if($action == 'list') { } elseif($action == 'download') { $path = $repo->get_file($file, $title); + $itemid = (int)substr(hexdec(uniqid()), 0, 9)+rand(1,100); try { $info = move_to_filepool($path, $title, $itemid); if($env == 'form'){ -- 2.39.5