From: dongsheng Date: Wed, 20 Aug 2008 04:24:38 +0000 (+0000) Subject: MDL-13766 X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=5fd3e8f72e15ec91d5f228606451f4ae3b86031e;p=moodle.git MDL-13766 improve action parameter, add comments for local plugin --- diff --git a/repository/boxnet/repository.class.php b/repository/boxnet/repository.class.php index 91cc6709ce..032f7c540b 100755 --- a/repository/boxnet/repository.class.php +++ b/repository/boxnet/repository.class.php @@ -41,6 +41,11 @@ class repository_boxnet extends repository{ } catch (repository_exception $e) { throw $e; } + if ($SESSION->$sess_name) { + $action = 'list'; + } else { + $action = 'login'; + } } // already logged if(!empty($SESSION->$sess_name)) { @@ -53,9 +58,8 @@ class repository_boxnet extends repository{ } } else { $this->box = new boxclient($this->api_key); - if(!empty($action)) { - $action = ''; - } + // print login + $action = 'login'; } } diff --git a/repository/flickr/repository.class.php b/repository/flickr/repository.class.php index 6e424bbfaa..c698917adc 100755 --- a/repository/flickr/repository.class.php +++ b/repository/flickr/repository.class.php @@ -47,8 +47,10 @@ class repository_flickr extends repository{ set_user_preference('flickrmail'.$this->id, $account); } $SESSION->$sess_name = $account; - if(empty($action)) { + if (empty($account)) { $action = 'list'; + } else { + $action = 'login'; } } else { throw new repository_exception('invalidemail', 'repository_flickr'); @@ -59,6 +61,8 @@ class repository_flickr extends repository{ if(empty($action)) { $action = 'list'; } + } else { + $action = 'login'; } } } diff --git a/repository/lib.php b/repository/lib.php index 9a48e7e84d..0af9b7472d 100644 --- a/repository/lib.php +++ b/repository/lib.php @@ -849,6 +849,11 @@ EOD; if(node.children){ tmpNode.isLeaf = false; tmpNode.subfolder = node.children; + if (node.path) { + tmpNode.path = node.path; + } else { + tmpNode.path = ''; + } for(var c in node.children){ _client.buildtree(node.children[c], tmpNode); } @@ -883,7 +888,7 @@ _client.dynload = function (node, fnLoadComplete){ // TODO: need to include filepath here var trans = YAHOO.util.Connect.asyncRequest('GET', '$CFG->wwwroot/repository/ws.php?ctx_id=$context->id&repo_id=' - +_client.repositoryid+'&action=list', + +_client.repositoryid+'&p='+node.path+'&action=list', callback); } _client.viewlist = function(){ @@ -983,7 +988,7 @@ _client.dynload = function (node, fnLoadComplete){ params['ctx_id'] = $context->id; _client.loading(); var trans = YAHOO.util.Connect.asyncRequest('POST', - '$CFG->wwwroot/repository/ws.php', _client.callback, + '$CFG->wwwroot/repository/ws.php?action=sign', _client.callback, _client.postdata(params)); } _client.end = function(str){ @@ -1045,7 +1050,7 @@ _client.dynload = function (node, fnLoadComplete){ _client.viewbar.set('disabled', false); _client.loading(); _client.repositoryid = id; - 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); + var trans = YAHOO.util.Connect.asyncRequest('GET', '$CFG->wwwroot/repository/ws.php?action=list&ctx_id=$context->id&repo_id='+id+'&p='+path+'&reset='+reset+'&env='+_client.env, _client.callback); } _client.search = function(id){ var data = window.prompt("$strsearching"); @@ -1055,7 +1060,7 @@ _client.dynload = function (node, fnLoadComplete){ } _client.viewbar.set('disabled', false); _client.loading(); - var trans = YAHOO.util.Connect.asyncRequest('GET', '$CFG->wwwroot/repository/ws.php?ctx_id=$context->id&repo_id='+id+'&s='+data+'&env='+_client.env, _client.callback); + var trans = YAHOO.util.Connect.asyncRequest('GET', '$CFG->wwwroot/repository/ws.php?action=search&ctx_id=$context->id&repo_id='+id+'&s='+data+'&env='+_client.env, _client.callback); } return _client; })(); diff --git a/repository/local/repository.class.php b/repository/local/repository.class.php index 9b269aa559..82e9b7b9ba 100755 --- a/repository/local/repository.class.php +++ b/repository/local/repository.class.php @@ -12,26 +12,38 @@ class repository_local extends repository{ public function __construct($repositoryid, $context = SITEID, $options = array()){ global $SESSION, $action, $CFG; parent::__construct($repositoryid, $context, $options); + // TODO: // get the parameter from client side // $this->context can be used here. + // When user upload a file, $action == 'upload' + // You can use $_FILES to find that file } public function print_login($ajax = true){ global $SESSION; // TODO // Return file list in moodle - // Also, this plugin should have ability to - // upload files in user's computer, a iframe - // need to be created. return $this->get_listing(); } public function get_listing($path = '/', $search = ''){ global $SESSION; $ret = new stdclass; + + // this statement tells file picker to load files dramanically. $ret->dynload = true; + + // defina upload form in file picker + // Use ajax upload file $ret->upload = array('name'=>get_string('attachment: '), 'id'=>'repo-form'); $ret->list = array(); - // call file api get the list of the file + + // TODO: set path and file area for folders, for example + // + // $ret->list[] = array('title'=>'folder1', 'size'=>0, + // 'date'=>'', 'path'=>'/', 'file_area'=>'course_files'); + // + // call FILE API get the list of the file + // $ret->list[] = array('title'=>'title','source'=>'download url', 'thumbnail'=>'url of thumbnail', 'date'=>'', 'size'=>'unknown'); if(empty($ret)) { throw new repository_exception('emptyfilelist', 'repository_local'); diff --git a/repository/ws.php b/repository/ws.php index de364f4ad1..a1b8b9132a 100644 --- a/repository/ws.php +++ b/repository/ws.php @@ -50,7 +50,7 @@ if(file_exists($CFG->dirroot.'/repository/'. die(json_encode($err)); } -if($action == 'list') { +if ($action == 'list' || $action == 'search') { try { if(!empty($p)) { echo json_encode($repo->get_listing($p)); @@ -85,7 +85,7 @@ if($action == 'list') { $err->e = $e->getMessage(); die(json_encode($err)); } -} else { +} elseif ($action == 'login') { try { echo json_encode($repo->print_login()); } catch (repository_exception $e){