From 6b37c2b093cc77ee485a23b3491927a934672f3f Mon Sep 17 00:00:00 2001 From: Sam Hemelryk Date: Tue, 10 Jan 2012 12:21:24 +1300 Subject: [PATCH] MDL-31000 Added comment about the importance of repository array keys and hardened new dnd repository lookup --- lib/form/dndupload.js | 14 ++++++++------ repository/lib.php | 2 ++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/form/dndupload.js b/lib/form/dndupload.js index 990c3a23f35..df0fb1919d7 100644 --- a/lib/form/dndupload.js +++ b/lib/form/dndupload.js @@ -98,7 +98,9 @@ M.form_dndupload = { // file is uploaded this.callback = options.formcallback; } else { - alert('dndupload: Need to define either options.filemanager or options.callback'); + if (M.cfg.developerdebug) { + alert('dndupload: Need to define either options.filemanager or options.callback'); + } return; } @@ -112,10 +114,10 @@ M.form_dndupload = { */ browser_supported: function() { - if (typeof FileReader=='undefined') { + if (typeof FileReader == 'undefined') { return false; } - if (typeof FormData=='undefined') { + if (typeof FormData == 'undefined') { return false; } return true; @@ -128,9 +130,9 @@ M.form_dndupload = { * @param returns int id of upload repository or false if not found */ get_upload_repositoryid: function(repositories) { - for (var id in repositories) { - if(repositories[id].type == "upload") { - return id; + for (var i in repositories) { + if (repositories[i].type == "upload") { + return repositories[i].id; } } diff --git a/repository/lib.php b/repository/lib.php index 67b1a13af41..d390420e2ff 100644 --- a/repository/lib.php +++ b/repository/lib.php @@ -2146,6 +2146,8 @@ function initialise_filepicker($args) { $return->return_types = $args->return_types; foreach ($repositories as $repository) { $meta = $repository->get_meta(); + // Please note that the array keys for repositories are used within + // JavaScript a lot, the key NEEDS to be the repository id. $return->repositories[$repository->id] = $meta; } return $return; -- 2.43.0