MDL-31656 Open files in a new window when downloading with the filemanager
authorAndrew Robert Nicols <andrew.nicols@luns.net.uk>
Thu, 16 Feb 2012 11:39:44 +0000 (11:39 +0000)
committerAndrew Robert Nicols <andrew.nicols@luns.net.uk>
Mon, 20 Feb 2012 10:50:16 +0000 (10:50 +0000)
We need to open files in a new window rather than the existing window  to
prevent warning messages when files are uploaded and then downloaded
without the form being saved first.

lib/form/filemanager.js

index de89ff3..cd3b3ec 100644 (file)
@@ -450,7 +450,7 @@ M.form_filemanager.init = function(Y, options) {
             var scope = this;
 
             var menuitems = [
-                {text: M.str.moodle.download, url:file.url}
+                {text: M.str.moodle.download, onclick:{fn:open_file_in_new_window, obj:file, scope:this}}
                 ];
             function setmainfile(type, ev, obj) {
                 var file = obj[node.get('id')];
@@ -467,6 +467,11 @@ M.form_filemanager.init = function(Y, options) {
                     }
                 });
             }
+            function open_file_in_new_window(type, ev, obj) {
+                // We open in a new window rather than changing the current windows URL as we don't
+                // want to navigate away from the page
+                window.open(obj.url, 'fm-download-file');
+            }
             if (this.enablemainfile && (file.sortorder != 1)) {
                 var mainid = '#id_'+this.enablemainfile;
                 var menu = {text: M.str.repository.setmainfile, onclick:{fn: setmainfile, obj:data, scope:this}};