MDL-23308, added mimetype icons to course files tree
authorDongsheng Cai <unoter@gmail.com>
Mon, 13 Sep 2010 07:01:55 +0000 (07:01 +0000)
committerDongsheng Cai <unoter@gmail.com>
Mon, 13 Sep 2010 07:01:55 +0000 (07:01 +0000)
files/filebrowser_ajax.php
files/module.js
files/renderer.php
lang/en/moodle.php

index 4191a2c..8ecc134 100755 (executable)
@@ -70,8 +70,10 @@ switch ($action) {
             if ($child->is_directory()) {
                 $fileitem['isdir'] = true;
                 $fileitem['url'] = $url->out(false);
+                $fileitem['icon'] = $OUTPUT->pix_icon('f/folder', get_string('icon'));
             } else {
                 $fileitem['url'] = $child->get_url();
+                $fileitem['icon'] = $OUTPUT->pix_icon('f/'.mimeinfo('icon', $child->get_visible_name()), get_string('icon'));
             }
             $tree[] = $fileitem;
         }
index a99aef2..0e764fe 100644 (file)
@@ -28,11 +28,7 @@ M.core_filetree = {
                         node.isLeaf = true;
                     } else {
                         for (i in data) {
-                            var mynode = {
-                                label: data[i].filename,
-                                href: data[i].url
-                            };
-                            var tmp = new YAHOO.widget.TextNode(mynode, node, false);
+                            var tmp = new YAHOO.widget.HTMLNode('<div>'+data[i].icon+'&nbsp;<a href="'+data[i].url+'">'+data[i].filename+'</a></div>', node, false);
                             if (data[i].isdir) {
                                 tmp.isLeaf = false;
                             } else {
@@ -72,7 +68,10 @@ M.core_filetree = {
         this.y3 = Y;
     }, 
     dynload: function(node, oncompletecb) {
-        M.core_filetree.request(node.href, node, oncompletecb);
+        var tmp = document.createElement('p');
+        tmp.innerHTML = node.html;
+        var links = tmp.getElementsByTagName('a');
+        M.core_filetree.request(links[0].href, node, oncompletecb);
     },
     onclick: function(e) {
         YAHOO.util.Event.preventDefault(e); 
index 1c6a229..b9158c7 100644 (file)
@@ -64,12 +64,18 @@ class core_files_renderer extends plugin_renderer_base {
                 $link_attributes = array();
                 if (!empty($node['isdir'])) {
                     $class = ' class="file-tree-folder"';
+                    $icon = $this->output->pix_icon('f/folder', 'icon');
                 } else {
                     $class = ' class="file-tree-file"';
+                    $icon = $this->output->pix_icon('f/'.mimeinfo('icon', $node['filename']), get_string('icon'));
                     $link_attributes['target'] = '_blank';
                 }
-                $html .= '<li '.$class.'>';
+                $html .= '<li '.$class.' yuiConfig="{\'type\':\'HTMLNode\'}">';
+                $html .= '<div>';
+                $html .= $icon;
+                $html .= '&nbsp;';
                 $html .= html_writer::link($node['url'], $node['filename'], $link_attributes);
+                $html .= '</div>';
                 $html .= '</li>';
             }
             $html .= '</ul>';
index 02e94cf..a04e29f 100644 (file)
@@ -845,6 +845,7 @@ $string['choosereportfilter'] = 'Choose a filter for the report';
 $string['choosetheme'] = 'Choose theme';
 $string['chooseuser'] = 'Choose a user';
 $string['icqnumber'] = 'ICQ number';
+$string['icon'] = 'Icon';
 $string['idnumber'] = 'ID number';
 $string['idnumbercourse'] = 'Course ID number';
 $string['idnumbercourse_help'] = 'The ID number of a course is only used when matching the course against external systems and is not displayed anywhere on the site. If the course has an official code name it may be entered, otherwise the field can be left blank.';