"MDL-13766, improve search form in file picker, improve error handing"
This commit is contained in:
@@ -208,6 +208,7 @@ class repository_flickr_public extends repository {
|
||||
*/
|
||||
public function search($search_text) {
|
||||
global $SESSION;
|
||||
$ret = array();
|
||||
if (!empty($this->flickr_account)) {
|
||||
$people = $this->flickr->people_findByEmail($this->flickr_account);
|
||||
$this->nsid = $people['nsid'];
|
||||
@@ -218,6 +219,11 @@ class repository_flickr_public extends repository {
|
||||
}
|
||||
if (empty($this->nsid)) {
|
||||
$this->nsid = null;
|
||||
// user specify a flickr account, but it is not valid
|
||||
if (!empty($this->flickr_account) or !empty($SESSION->{$this->sess_account})) {
|
||||
$ret['e'] = get_string('invalidemail', 'repository_flickr_public');
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
$is_paging = optional_param('search_paging', '', PARAM_RAW);
|
||||
if (!empty($is_paging)) {
|
||||
@@ -270,7 +276,6 @@ class repository_flickr_public extends repository {
|
||||
)
|
||||
);
|
||||
}
|
||||
$ret = array();
|
||||
$ret['total'] = $photos['total'];
|
||||
$ret['perpage'] = $photos['perpage'];
|
||||
if (empty($photos)) {
|
||||
@@ -326,8 +331,10 @@ class repository_flickr_public extends repository {
|
||||
$format = 'jpg';
|
||||
}
|
||||
$format = '.'.$format;
|
||||
// append extensions to the files
|
||||
if (substr($p['title'], strlen($p['title'])-strlen($format)) != $format) {
|
||||
// append author id
|
||||
$p['title'] .= '-'.$p['owner'];
|
||||
// append file extension
|
||||
$p['title'] .= $format;
|
||||
}
|
||||
$ret['list'][] = array('title'=>$p['title'], 'source'=>$p['id'],
|
||||
@@ -375,6 +382,10 @@ class repository_flickr_public extends repository {
|
||||
$c = new curl;
|
||||
$c->download(array(array('url'=>$url, 'file'=>$fp)));
|
||||
|
||||
$watermark = get_config('flickr_public', 'watermark');
|
||||
if (!empty($watermark)) {
|
||||
// process watermark
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
|
||||
@@ -405,8 +416,13 @@ class repository_flickr_public extends repository {
|
||||
$api_key = '';
|
||||
}
|
||||
$strrequired = get_string('required');
|
||||
|
||||
$mform->addElement('checkbox', 'watermark', get_string('watermark', 'repository_flickr_public'));
|
||||
|
||||
$mform->addElement('text', 'api_key', get_string('apikey', 'repository_flickr_public'), array('value'=>$api_key,'size' => '40'));
|
||||
$mform->addRule('api_key', $strrequired, 'required', null, 'client');
|
||||
|
||||
|
||||
$mform->addElement('static', null, '', get_string('information','repository_flickr_public'));
|
||||
}
|
||||
|
||||
@@ -415,7 +431,7 @@ class repository_flickr_public extends repository {
|
||||
* @return <type>
|
||||
*/
|
||||
public static function get_type_option_names() {
|
||||
return array('api_key');
|
||||
return array('api_key', 'watermark');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+2
-1
@@ -1482,7 +1482,7 @@ abstract class repository {
|
||||
* Show the search screen, if required
|
||||
* @return null
|
||||
*/
|
||||
public function print_search() {
|
||||
public function print_search($client_id) {
|
||||
$str = '';
|
||||
$str .= '<input type="hidden" name="repo_id" value="'.$this->id.'" />';
|
||||
$str .= '<input type="hidden" name="ctx_id" value="'.$this->context->id.'" />';
|
||||
@@ -1783,6 +1783,7 @@ function repository_get_client($context, $id = '', $accepted_filetypes = '*', $
|
||||
$lang['download'] = get_string('downloadsucc', 'repository');
|
||||
$lang['date'] = get_string('date', 'repository').': ';
|
||||
$lang['error'] = get_string('error', 'repository');
|
||||
$lang['emptylist'] = get_string('emptylist', 'repository');
|
||||
$lang['filenotnull'] = get_string('filenotnull', 'repository');
|
||||
$lang['federatedsearch'] = get_string('federatedsearch', 'repository');
|
||||
$lang['help'] = get_string('help');
|
||||
|
||||
@@ -49,6 +49,7 @@ class repository_local extends repository {
|
||||
global $CFG, $USER;
|
||||
$ret = array();
|
||||
$ret['dynload'] = true;
|
||||
$ret['nosearch'] = true;
|
||||
$list = array();
|
||||
|
||||
// list draft files
|
||||
|
||||
@@ -22,6 +22,7 @@ class repository_picasa extends repository {
|
||||
$gauth = new google_authsub(false, $googletoken); // will throw exception if fails
|
||||
google_picasa::set_sesskey($gauth->get_sessiontoken(), $USER->id);
|
||||
}
|
||||
$this->check_login();
|
||||
}
|
||||
|
||||
public function check_login() {
|
||||
|
||||
@@ -66,8 +66,11 @@
|
||||
.fp-grid p{margin:0;padding:0;background: #FFFFCC}
|
||||
.fp-grid .label{height:48px;text-align:center}
|
||||
.fp-grid span{color:gray}
|
||||
.fp-error {padding: 2em 0; margin: 3em 5px;text-align:center;background: #FFBBBB}
|
||||
/* file picker search dialog */
|
||||
div.bd{text-align:left}
|
||||
|
||||
|
||||
/* TODO: Fix IE6 somehow
|
||||
.yui-skin-sam .yui-panel .hd{}
|
||||
*/
|
||||
*/
|
||||
|
||||
@@ -263,7 +263,7 @@ repository_client.req_cb = {
|
||||
repo.viewbar.set('disabled', false);
|
||||
var panel = new YAHOO.util.Element('panel-'+data.client_id);
|
||||
if(data && data.e) {
|
||||
panel.get('element').innerHTML = data.e;
|
||||
panel.get('element').innerHTML = '<div class="fp-error">'+data.e+'</div>';
|
||||
return;
|
||||
}
|
||||
// save data
|
||||
@@ -339,7 +339,7 @@ repository_client.print_login = function(id, data) {
|
||||
field_id = ' id="'+login[k].id+'"';
|
||||
}
|
||||
if (login[k].label) {
|
||||
str += '<td align="right"><label'+label_id+'>'+login[k].label+'</label> </td>';
|
||||
str += '<td align="right" valign="top"><label'+label_id+'>'+login[k].label+'</label> </td>';
|
||||
} else {
|
||||
str += '<td></td>';
|
||||
}
|
||||
@@ -834,6 +834,9 @@ repository_client.view_as_icons = function(client_id, data) {
|
||||
}
|
||||
count++;
|
||||
}
|
||||
if (list.length == 0) {
|
||||
panel.innerHTML = '<div class="fp-error">'+fp_lang.emptylist+'</div>';
|
||||
}
|
||||
container.appendChild(panel);
|
||||
repository_client.print_footer(client_id);
|
||||
}
|
||||
@@ -1099,23 +1102,23 @@ success: function(o) {
|
||||
var fp = repository_client.fp[data.client_id];
|
||||
if(el) {
|
||||
el.innerHTML = '';
|
||||
} else {
|
||||
var el = document.createElement('DIV');
|
||||
el.id = 'fp-search-dlg';
|
||||
el.parentNode.removeChild(el);
|
||||
}
|
||||
var div1 = document.createElement('DIV');
|
||||
div1.className = 'hd';
|
||||
div1.innerHTML = fp_lang.searching+"\"" + repository_listing[data.client_id][fp.fs.repo_id].name + '"';
|
||||
var div2 = document.createElement('DIV');
|
||||
div2.className = 'bd';
|
||||
var el = document.createElement('DIV');
|
||||
el.id = 'fp-search-dlg';
|
||||
var dlg_title = document.createElement('DIV');
|
||||
dlg_title.className = 'hd';
|
||||
dlg_title.innerHTML = fp_lang.searching+"\"" + repository_listing[data.client_id][fp.fs.repo_id].name + '"';
|
||||
var dlg_body = document.createElement('DIV');
|
||||
dlg_body.className = 'bd';
|
||||
var sform = document.createElement('FORM');
|
||||
sform.method = 'POST';
|
||||
sform.id = "fp-search-form";
|
||||
sform.action = moodle_cfg.wwwroot+'/repository/ws.php?action=search';
|
||||
sform.innerHTML = data['form'];
|
||||
div2.appendChild(sform);
|
||||
el.appendChild(div1);
|
||||
el.appendChild(div2);
|
||||
dlg_body.appendChild(sform);
|
||||
el.appendChild(dlg_title);
|
||||
el.appendChild(dlg_body);
|
||||
document.body.appendChild(el);
|
||||
var dlg_handler = function() {
|
||||
var client_id=dlg_handler.client_id;
|
||||
@@ -1144,7 +1147,7 @@ success: function(o) {
|
||||
handler: dlg_handler,
|
||||
isDefault:true
|
||||
},
|
||||
{text:fp_lang.cancel,handler:function(){this.cancel()}}
|
||||
{text:fp_lang.cancel,handler:function(){this.destroy()}}
|
||||
]
|
||||
});
|
||||
dlg.render();
|
||||
|
||||
+6
-3
@@ -5,6 +5,7 @@
|
||||
require_once('../config.php');
|
||||
require_once('../lib/filelib.php');
|
||||
require_once('lib.php');
|
||||
require_login();
|
||||
|
||||
/// Parameters
|
||||
$page = optional_param('page', '', PARAM_RAW); // page
|
||||
@@ -120,6 +121,8 @@
|
||||
// If Moodle is working on HTTPS mode, then we are not allowed to access
|
||||
// parent window, in this case, we need to alert user to refresh the repository
|
||||
// manually.
|
||||
$strhttpsbug = get_string('cannotaccessparentwin', 'repository');
|
||||
$strrefreshnonjs = get_string('refreshnonjsfilepicker', 'repository');
|
||||
$js =<<<EOD
|
||||
<html><head>
|
||||
<script type="text/javascript">
|
||||
@@ -127,12 +130,12 @@ if(window.opener){
|
||||
window.opener.repository_callback($repo_id);
|
||||
window.close();
|
||||
} else {
|
||||
alert("If parent window is on HTTPS, then we are not allowed to access window.opener object, so we cannot refresh the repository for you automatically, but we already got your session, just go back to file picker and select the repository again, it should work now.");
|
||||
alert("{$strhttpsbug }");
|
||||
}
|
||||
</script>
|
||||
<body>
|
||||
<noscript>
|
||||
Close this window and refresh file picker.
|
||||
{$strrefreshnonjs}
|
||||
</noscript>
|
||||
</body>
|
||||
</html>
|
||||
@@ -178,7 +181,7 @@ EOD;
|
||||
echo json_encode($logout);
|
||||
break;
|
||||
case 'searchform':
|
||||
$search_form['form'] = $repo->print_search();
|
||||
$search_form['form'] = $repo->print_search($client_id);
|
||||
$search_form['client_id'] = $client_id;
|
||||
echo json_encode($search_form);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user