MDL-31901 filepicker interface changes:

- fixed displaying and dragging of dialog popups;
- fixed error when repository results are filtered;
- added string for image dimensions
This commit is contained in:
Marina Glancy 2012-05-10 15:20:09 +08:00
parent 55089a9d01
commit dd1f051e4a
3 changed files with 32 additions and 40 deletions

View File

@ -115,6 +115,7 @@ $string['hidden'] = 'Hidden';
$string['choosealink'] = 'Choose a link...';
$string['chooselicense'] = 'Choose license';
$string['iconview'] = 'View as icons';
$string['imagesize'] = '{$a->width} x {$a->height} px';
$string['instance'] = 'instance';
$string['instancedeleted'] = 'Instance deleted';
$string['instances'] = 'Repository instances';

View File

@ -518,14 +518,6 @@ M.core_filepicker.init = function(Y, options) {
this.fpnode.one('.fp-content').setContent('');
}
return;
} else if (data && data.event) {
switch (data.event) {
case 'fileexists':
scope.process_existing_file(data);
break;
default:
break;
}
} else {
if (data.msg) {
scope.print_msg(data.msg, 'info');
@ -593,7 +585,8 @@ M.core_filepicker.init = function(Y, options) {
var fileinfo = {'client_id':scope.options.client_id,
'url':data.existingfile.url,
'file':data.existingfile.filename};
scope.options.formcallback.apply(scope, [fileinfo]);
var formcallback_scope = scope.options.magicscope ? scope.options.magicscope : scope;
scope.options.formcallback.apply(formcallback_scope, [fileinfo]);
}
}
}, true);
@ -608,12 +601,7 @@ M.core_filepicker.init = function(Y, options) {
scope.options.editor_target.onchange();
}
scope.hide();
var formcallback_scope = null;
if (scope.options.magicscope) {
formcallback_scope = scope.options.magicscope;
} else {
formcallback_scope = scope;
}
var formcallback_scope = scope.options.magicscope ? scope.options.magicscope : scope;
var fileinfo = {'client_id':scope.options.client_id,
'url':data.newfile.url,
'file':data.newfile.filename};
@ -640,8 +628,10 @@ M.core_filepicker.init = function(Y, options) {
this.selectui.hide();
}
if (!this.process_dlg) {
var node = Y.Node.create(M.core_filepicker.templates.processexistingfile);
this.fpnode.appendChild(node);
this.process_dlg_node = Y.Node.create(M.core_filepicker.templates.processexistingfile);
var node = this.process_dlg_node;
node.generateID();
Y.one(document.body).appendChild(node);
this.process_dlg = new Y.Panel({
srcNode : node,
headerContent: M.str.repository.fileexistsdialogheader,
@ -652,6 +642,7 @@ M.core_filepicker.init = function(Y, options) {
render : true,
buttons : {}
});
this.process_dlg.plug(Y.Plugin.Drag,{handles:['#'+node.get('id')+' .yui3-widget-hd']});
node.one('.fp-dlg-butoverwrite').on('click', handleOverwrite, this);
node.one('.fp-dlg-butrename').on('click', handleRename, this);
node.one('.fp-dlg-butcancel').on('click', handleCancel, this);
@ -663,7 +654,7 @@ M.core_filepicker.init = function(Y, options) {
}
this.selectnode.removeClass('loading');
this.process_dlg.dialogdata = data;
this.fpnode.one('.fp-dlg .fp-dlg-butrename').setContent(M.util.get_string('renameto', 'repository', data.newfile.filename));
this.process_dlg_node.one('.fp-dlg-butrename').setContent(M.util.get_string('renameto', 'repository', data.newfile.filename));
this.process_dlg.show();
},
/** displays error instead of filepicker contents */
@ -681,26 +672,28 @@ M.core_filepicker.init = function(Y, options) {
header = M.str.moodle.info;
}
if (!this.msg_dlg) {
var node = Y.Node.create(M.core_filepicker.templates.message);
this.fpnode.appendChild(node);
this.msg_dlg_node = Y.Node.create(M.core_filepicker.templates.message);
this.msg_dlg_node.generateID();
Y.one(document.body).appendChild(this.msg_dlg_node);
this.msg_dlg = new Y.Panel({
srcNode : node,
srcNode : this.msg_dlg_node,
zIndex : 800000,
centered : true,
modal : true,
visible : false,
render : true
});
node.one('.fp-msg-butok').on('click', function(e) {
this.msg_dlg.plug(Y.Plugin.Drag,{handles:['#'+this.msg_dlg_node.get('id')+' .yui3-widget-hd']});
this.msg_dlg_node.one('.fp-msg-butok').on('click', function(e) {
e.preventDefault();
this.msg_dlg.hide();
}, this);
}
this.msg_dlg.set('headerContent', header);
this.fpnode.one('.fp-msg').removeClass('fp-msg-info').removeClass('fp-msg-error').addClass('fp-msg-'+type)
this.fpnode.one('.fp-msg .fp-msg-text').setContent(msg);
this.msg_dlg_node.removeClass('fp-msg-info').removeClass('fp-msg-error').addClass('fp-msg-'+type)
this.msg_dlg_node.one('.fp-msg-text').setContent(msg);
this.msg_dlg.show();
},
view_files: function(appenditems) {
@ -1095,12 +1088,7 @@ M.core_filepicker.init = function(Y, options) {
}
scope.hide();
obj.client_id = client_id;
var formcallback_scope = null;
if (args.scope.options.magicscope) {
formcallback_scope = args.scope.options.magicscope;
} else {
formcallback_scope = args.scope;
}
var formcallback_scope = args.scope.options.magicscope ? args.scope.options.magicscope : args.scope;
scope.options.formcallback.apply(formcallback_scope, [obj]);
}
}, false);
@ -1539,18 +1527,18 @@ M.core_filepicker.init = function(Y, options) {
scope.create_upload_form(data);
},
callback: function(id, o, args) {
if (o.event == 'fileexists') {
scope.create_upload_form(data);
scope.process_existing_file(o);
return;
}
if (scope.options.editor_target&&scope.options.env=='editor') {
scope.options.editor_target.value=o.url;
scope.options.editor_target.onchange();
}
scope.hide();
o.client_id = client_id;
var formcallback_scope = null;
if (args.scope.options.magicscope) {
formcallback_scope = args.scope.options.magicscope;
} else {
formcallback_scope = args.scope;
}
var formcallback_scope = args.scope.options.magicscope ? args.scope.options.magicscope : args.scope;
scope.options.formcallback.apply(formcallback_scope, [o]);
}
}, true);

View File

@ -1781,16 +1781,18 @@ abstract class repository {
/**
* Prepares list of files before passing it to AJAX, makes sure data is in the correct
* format and stores formatted dates.
* format and stores formatted values.
*
* @param array|stdClass $listing result of get_listing() or search() or file_get_drafarea_files()
* @return array
*/
public static function prepare_listing($listing) {
global $OUTPUT;
if (is_array($listing) && isset($listing['list'])) {
if (is_array($listing) && isset($listing['list']) && is_array(($listing['list']))) {
$listing['list'] = array_values($listing['list']); // convert to array
$files = &$listing['list'];
} else if (is_object($listing) && isset($listing->list)) {
} else if (is_object($listing) && isset($listing->list) && is_array(($listing->list))) {
$listing->list = array_values($listing->list); // convert to array
$files = &$listing->list;
} else {
return $listing;
@ -1813,7 +1815,8 @@ abstract class repository {
$file['license_f'] = get_string($file['license'], 'license');
}
if (isset($file['image_width']) && isset($file['image_height'])) {
$file['dimensions'] = $file['image_width'].'x'.$file['image_height'];
$a = array('width' => $file['image_width'], 'height' => $file['image_height']);
$file['dimensions'] = get_string('imagesize', 'repository', (object)$a);
}
foreach (array('date', 'datemodified', 'datecreated') as $key) {
if (!isset($file[$key]) && isset($file['date'])) {