MDL-31000 Added comment about the importance of repository array keys and hardened...
authorSam Hemelryk <sam@moodle.com>
Mon, 9 Jan 2012 23:21:24 +0000 (12:21 +1300)
committerSam Hemelryk <sam@moodle.com>
Mon, 9 Jan 2012 23:21:24 +0000 (12:21 +1300)
lib/form/dndupload.js
repository/lib.php

index 990c3a2..df0fb19 100644 (file)
@@ -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;
              }
          }
 
index 67b1a13..d390420 100644 (file)
@@ -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;