MDL-31000 Respect sortorder of repositories when displaying the filepicker
authorAndrew Robert Nicols <andrew.nicols@luns.net.uk>
Tue, 10 Jan 2012 10:48:38 +0000 (10:48 +0000)
committerAndrew Robert Nicols <andrew.nicols@luns.net.uk>
Fri, 13 Jan 2012 15:52:04 +0000 (15:52 +0000)
repository/filepicker.js
repository/lib.php

index 1bfadc8..804ff3f 100644 (file)
@@ -797,16 +797,22 @@ M.core_filepicker.init = function(Y, options) {
             Y.on('contentready', function(el) {
                 var list = Y.one(el);
                 var count = 0;
+                // Resort the repositories by sortorder
+                var sorted_repositories = new Array();
                 for (var i in r) {
-                    var id = 'repository-'+client_id+'-'+r[i].id;
+                    sorted_repositories[r[i].sortorder - 1] = r[i];
+                }
+                for (var i in sorted_repositories){
+                    repository = sorted_repositories[i];
+                    var id = 'repository-'+client_id+'-'+repository.id;
                     var link_id = id + '-link';
-                    list.append('<li id="'+id+'"><a class="fp-repo-name" id="'+link_id+'" href="###">'+r[i].name+'</a></li>');
-                    Y.one('#'+link_id).prepend('<img src="'+r[i].icon+'" width="16" height="16" />&nbsp;');
+                    list.append('<li id="'+id+'"><a class="fp-repo-name" id="'+link_id+'" href="###">'+repository.name+'</a></li>');
+                    Y.one('#'+link_id).prepend('<img src="'+repository.icon+'" width="16" height="16" />&nbsp;');
                     Y.one('#'+link_id).on('click', function(e, scope, repository_id) {
                         YAHOO.util.Cookie.set('recentrepository', repository_id);
                         scope.repository_id = repository_id;
                         this.list({'repo_id':repository_id});
-                    }, this /*handler running scope*/, this/*second argument*/, r[i].id/*third argument of handler*/);
+                    }, this /*handler running scope*/, this/*second argument*/, repository.id/*third argument of handler*/);
                     count++;
                 }
                 if (count==0) {
index d390420..6ef38e3 100644 (file)
@@ -826,6 +826,7 @@ abstract class repository {
             $options['visible'] = $record->visible;
             $options['type']    = $record->repositorytype;
             $options['typeid']  = $record->typeid;
+            $options['sortorder'] = $record->sortorder;
             // tell instance what file types will be accepted by file picker
             $classname = 'repository_' . $record->repositorytype;
 
@@ -1447,6 +1448,7 @@ abstract class repository {
         $meta->icon = $OUTPUT->pix_url('icon', 'repository_'.$meta->type)->out(false);
         $meta->supported_types = $ft->get_extensions($this->supported_filetypes());
         $meta->return_types = $this->supported_returntypes();
+        $meta->sortorder = $this->options['sortorder'];
         return $meta;
     }