MDL-24375, fixed mulilt main files in filemanager
authorDongsheng Cai <unoter@gmail.com>
Wed, 6 Oct 2010 04:17:21 +0000 (04:17 +0000)
committerDongsheng Cai <unoter@gmail.com>
Wed, 6 Oct 2010 04:17:21 +0000 (04:17 +0000)
lib/form/filemanager.js
repository/recent/lib.php

index 8d12718..da876d7 100644 (file)
@@ -505,6 +505,26 @@ M.form_filemanager.init = function(Y, options) {
                 {text: M.str.moodle.download, url:fileinfo.url},
                 {text: M.str.moodle.unzip, onclick: {fn: unzip, obj: data, scope: this}}
                 ];
+            function setmainfile(type, ev, obj) {
+                var file = obj[node.get('id')];
+                //Y.one(mainid).set('value', file.filepath+file.filename);
+                var params = {};
+                params['filepath']   = file.filepath;
+                params['filename']   = file.filename;
+                this.request({
+                    action: 'setmainfile',
+                    scope: scope,
+                    params: params,
+                    callback: function(id, obj, args) {
+                        scope.refresh(scope.currentpath);
+                    }
+                });
+            }
+            if (this.enablemainfile && (fileinfo.sortorder != 1)) {
+                var mainid = '#id_'+this.enablemainfile;
+                var menu = {text: M.str.repository.setmainfile, onclick:{fn: setmainfile, obj:data, scope:this}};
+                menuitems.push(menu);
+            }
             this.create_menu(e, 'zipmenu', menuitems, fileinfo, data);
         },
         create_menu: function(ev, menuid, menuitems, fileinfo, options) {
index 6d9df31..2176940 100755 (executable)
@@ -175,7 +175,7 @@ class repository_recent extends repository {
                 throw new moodle_exception('errornotyourfile', 'repository');
             }
             $file_record = array('contextid'=>$user_context->id, 'component'=>'user', 'filearea'=>'draft',
-                'itemid'=>$draftitemid, 'filepath'=>$new_filepath, 'filename'=>$new_filename);
+                'itemid'=>$draftitemid, 'filepath'=>$new_filepath, 'filename'=>$new_filename, 'sortorder'=>0);
             if ($file = $fs->get_file($user_context->id, 'user', 'draft', $draftitemid, $new_filepath, $new_filename)) {
                 $info = array();
                 $info['title']  = $file->get_filename();