Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-30790 - Option to collapse or expand sub-folders

  • Loading branch information...
commit f29572785958265d8be6f83d538e3774bffc44e4 1 parent 7112729
@rlorenzo rlorenzo authored
View
5 mod/folder/db/install.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="mod/folder/db" VERSION="20130121" COMMENT="XMLDB file for Folder module"
+<XMLDB PATH="mod/folder/db" VERSION="20130315" COMMENT="XMLDB file for Folder module"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
@@ -14,6 +14,7 @@
<FIELD NAME="revision" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="incremented when after each file changes, solves browser caching issues"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="display" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Display type of folder contents - on a separate page or inline"/>
+ <FIELD NAME="show_expanded" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="false" DEFAULT="1" SEQUENCE="false" COMMENT="1 = expanded, 0 = collapsed for sub-folders"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
@@ -23,4 +24,4 @@
</INDEXES>
</TABLE>
</TABLES>
-</XMLDB>
+</XMLDB>
View
16 mod/folder/db/upgrade.php
@@ -58,7 +58,6 @@ function xmldb_folder_upgrade($oldversion) {
// Moodle v2.3.0 release upgrade line
// Put any upgrade step following this
-
// Moodle v2.4.0 release upgrade line
// Put any upgrade step following this
@@ -77,5 +76,20 @@ function xmldb_folder_upgrade($oldversion) {
upgrade_mod_savepoint(true, 2013012100, 'folder');
}
+ if ($oldversion < 2013031500) {
+
+ // Define field show_expanded to be added to folder
+ $table = new xmldb_table('folder');
+ $field = new xmldb_field('show_expanded', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'revision');
+
+ // Conditionally launch add field show_expanded
+ if (!$dbman->field_exists($table, $field)) {
+ $dbman->add_field($table, $field);
+ }
+
+ // folder savepoint reached
+ upgrade_mod_savepoint(true, 2013031500, 'folder');
+ }
+
return true;
}
View
2  mod/folder/lang/en/folder.php
@@ -51,3 +51,5 @@
$string['displaypage'] = 'On a separate page';
$string['displayinline'] = 'Inline on a course page';
$string['noautocompletioninline'] = 'Automatic completion on viewing of activity can not be selected together with "Display inline" option';
+$string['show_expanded'] = 'Show sub-folders expanded';
+$string['show_expanded_help'] = 'If enabled, will display sub-folders expanded by default. Else, sub-folders will display collapsed.';
View
5 mod/folder/mod_form.php
@@ -55,7 +55,10 @@ function definition() {
$mform->addHelpButton('display', 'display', 'mod_folder');
$mform->setExpanded('content');
-
+ // Adding option to show sub-folders expanded or collapsed by default.
+ $mform->addElement('advcheckbox', 'show_expanded', get_string('show_expanded', 'folder'));
+ $mform->addHelpButton('show_expanded', 'show_expanded', 'mod_folder');
+ $mform->setDefault('show_expanded', $config->show_expanded);
//-------------------------------------------------------
$this->standard_coursemodule_elements();
View
3  mod/folder/module.js
@@ -35,6 +35,9 @@ M.mod_folder.init_tree = function(Y, id, expand_all) {
if (expand_all) {
tree.expandAll();
+ } else {
+ // Else just expand the top node.
+ tree.getNodeByIndex(1).expand();
}
tree.render();
View
8 mod/folder/renderer.php
@@ -78,8 +78,12 @@ public function render_folder_tree(folder_tree $tree) {
$content .= '<div id="'.$id.'" class="filemanager">';
$content .= $this->htmllize_tree($tree, array('files' => array(), 'subdirs' => array($tree->dir)));
$content .= '</div>';
- $this->page->requires->js_init_call('M.mod_folder.init_tree', array($id, true));
- return $content;
+ $show_expanded = true;
+ if (empty($tree->folder->show_expanded)) {
+ $show_expanded = false;
+ }
+ $this->page->requires->js_init_call('M.mod_folder.init_tree', array($id, $show_expanded));
+ return $content;
}
/**
View
4 mod/folder/settings.php
@@ -30,4 +30,8 @@
//--- general settings -----------------------------------------------------------------------------------
$settings->add(new admin_setting_configcheckbox('folder/requiremodintro',
get_string('requiremodintro', 'admin'), get_string('configrequiremodintro', 'admin'), 1));
+
+ $settings->add(new admin_setting_configcheckbox('folder/show_expanded',
+ get_string('show_expanded', 'folder'),
+ get_string('show_expanded_help', 'folder'), 1));
}
View
2  mod/folder/version.php
@@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die();
-$module->version = 2013012100; // The current module version (Date: YYYYMMDDXX)
+$module->version = 2013031500; // The current module version (Date: YYYYMMDDXX)
$module->requires = 2012112900; // Requires this Moodle version
$module->component = 'mod_folder'; // Full name of the plugin (used for diagnostics)
$module->cron = 0;
Please sign in to comment.
Something went wrong with that request. Please try again.