Skip to content

Commit

Permalink
MDL-30790 - Option to collapse or expand sub-folders
Browse files Browse the repository at this point in the history
  • Loading branch information
rlorenzo committed Mar 15, 2013
1 parent 7112729 commit f295727
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 7 deletions.
5 changes: 3 additions & 2 deletions mod/folder/db/install.xml
Original file line number Diff line number Diff line change
@@ -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"
>
Expand All @@ -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"/>
Expand All @@ -23,4 +24,4 @@
</INDEXES>
</TABLE>
</TABLES>
</XMLDB>
</XMLDB>
16 changes: 15 additions & 1 deletion mod/folder/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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;
}
2 changes: 2 additions & 0 deletions mod/folder/lang/en/folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
5 changes: 4 additions & 1 deletion mod/folder/mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
3 changes: 3 additions & 0 deletions mod/folder/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 6 additions & 2 deletions mod/folder/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions mod/folder/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
2 changes: 1 addition & 1 deletion mod/folder/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit f295727

Please sign in to comment.