MDL-30617 Add a javascript interface for adding modules to a course

This interface allows for additional metadata, such as the module's help
and icon, to be displayed.
This commit is contained in:
Andrew Robert Nicols 2011-11-25 10:20:34 +00:00 committed by Dan Poltawski
parent 2e6b68f4a8
commit 01e0e7044a
10 changed files with 713 additions and 15 deletions

View File

@ -1827,10 +1827,10 @@ function print_section_add_menus($course, $section, $modnames, $vertical=false,
$straddactivity = get_string('addactivity');
$straddresource = get_string('addresource');
$output = '<div class="section_add_menus">';
$output = html_writer::start_tag('div', array('class' => 'section_add_menus', 'id' => 'add_menus-section-' . $section));
if (!$vertical) {
$output .= '<div class="horizontal">';
$output .= html_writer::start_tag('div', array('class' => 'horizontal'));
}
if (!empty($resources)) {
@ -1846,10 +1846,31 @@ function print_section_add_menus($course, $section, $modnames, $vertical=false,
}
if (!$vertical) {
$output .= '</div>';
$output .= html_writer::end_tag('div');
}
$output .= '</div>';
$output .= html_writer::end_tag('div');
if (course_ajax_enabled($course)) {
$straddeither = get_string('addresourceoractivity');
// The module chooser link
$modchooser = '<div class="sectionaddmodule">';
$modchooser .= '<div class="section_add_menus"><a class="sectionmodchooserlink" href="#">';
$modchooser .= '<img alt="'.$straddeither.'" src="'.$OUTPUT->pix_url('t/add').'" class="activityicon">&nbsp;';
$modchooser .= '<span class="instancename">'.$straddeither.'</span>';
$modchooser .= '</a></div></div>';
// Wrap the normal output in a noscript div
$usemodchooser = get_user_preferences('usemodchooser', 1);
if ($usemodchooser) {
$output = html_writer::tag('div', $output, array('class' => 'hiddenifjs addresourcedropdown'));
$modchooser = html_writer::tag('div', $modchooser, array('class' => 'visibleifjs addresourcemodchooser'));
} else {
$output = html_writer::tag('div', $output, array('class' => 'visibleifjs addresourcedropdown'));
$modchooser = html_writer::tag('div', $modchooser, array('class' => 'hiddenifjs addresourcemodchooser'));
}
$output = $modchooser . $output;
}
if ($return) {
return $output;
@ -1936,8 +1957,14 @@ function get_module_metadata($course, $modnames) {
$module->name = $modname;
$module->link = $urlbase . $modname;
$module->icon = $OUTPUT->pix_icon('icon', '', $module->name, array('class' => 'icon'));
if (get_string_manager()->string_exists('modulename_help', $modname)) {
$sm = get_string_manager();
if ($sm->string_exists('modulename_help', $modname)) {
$module->help = get_string('modulename_help', $modname);
if ($sm->string_exists('modulename_link', $modname)) { // Link to further info in Moodle docs
$link = get_string('modulename_link', $modname);
$linktext = get_string('morehelp');
$module->help .= html_writer::tag('div', $OUTPUT->doc_link($link, $linktext), array('class' => 'helpdoclink'));
}
}
$module->archetype = plugin_supports('mod', $modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
$modlist[$course->id][$modname] = $module;
@ -4568,6 +4595,17 @@ function include_course_ajax($course, $usedmodules = array(), $enabledmodules =
// Load drag and drop upload AJAX.
dndupload_add_to_course($course, $enabledmodules);
// Add the module chooser
$PAGE->requires->yui_module('moodle-course-modchooser',
'M.course.init_chooser',
array(array('courseid' => $course->id))
);
$PAGE->requires->strings_for_js(array(
'addresourceoractivity',
'modchooserenable',
'modchooserdisable',
), 'moodle');
return true;
}

View File

@ -154,4 +154,155 @@ class core_course_renderer extends plugin_renderer_base {
$content .= html_writer::end_tag('div');
return $content;
}
/**
* Build the HTML for the module chooser javascript popup
*
* @param array $modules A set of modules as returned form @see
* get_module_metadata
* @param object $course The course that will be displayed
* @return string The composed HTML for the module
*/
public function course_modchooser($modules, $course) {
global $OUTPUT;
// Add the header
$header = html_writer::tag('div', get_string('choosemodtype', 'moodle'),
array('id' => 'choosertitle', 'class' => 'hd'));
$formcontent = html_writer::start_tag('form', array('action' => new moodle_url('/course/jumpto.php'),
'id' => 'chooserform', 'method' => 'post'));
$formcontent .= html_writer::start_tag('div', array('id' => 'typeformdiv'));
$formcontent .= html_writer::tag('input', '', array('type' => 'hidden', 'id' => 'course',
'name' => 'course', 'value' => $course->id));
$formcontent .= html_writer::tag('input', '',
array('type' => 'hidden', 'id' => 'jump', 'name' => 'jump', 'value' => ''));
$formcontent .= html_writer::tag('input', '', array('type' => 'hidden', 'name' => 'sesskey',
'value' => sesskey()));
$formcontent .= html_writer::end_tag('div');
// Put everything into one tag 'options'
$formcontent .= html_writer::start_tag('div', array('class' => 'options'));
$formcontent .= html_writer::tag('div', get_string('selectmoduletoviewhelp', 'moodle'),
array('class' => 'instruction'));
// Put all options into one tag 'alloptions' to allow us to handle scrolling
$formcontent .= html_writer::start_tag('div', array('class' => 'alloptions'));
// First display Resources
$resources = array_filter($modules,
create_function('$mod', 'return ($mod->archetype === MOD_CLASS_RESOURCE);'));
if (count($resources)) {
$formcontent .= $this->course_modchooser_title('resources');
$formcontent .= $this->course_modchooser_module_types($resources);
}
// Then activities
$activities = array_filter($modules,
create_function('$mod', 'return ($mod->archetype !== MOD_CLASS_RESOURCE);'));
if (count($activities)) {
$formcontent .= $this->course_modchooser_title('activities');
$formcontent .= $this->course_modchooser_module_types($activities);
}
$formcontent .= html_writer::end_tag('div'); // modoptions
$formcontent .= html_writer::end_tag('div'); // types
$formcontent .= html_writer::start_tag('div', array('class' => 'submitbuttons'));
$formcontent .= html_writer::tag('input', '',
array('type' => 'submit', 'name' => 'submitbutton', 'id' => 'submitbutton', 'value' => get_string('next')));
$formcontent .= html_writer::tag('input', '',
array('type' => 'submit', 'name' => 'addcancel', 'id' => 'addcancel', 'value' => get_string('cancel')));
$formcontent .= html_writer::end_tag('div');
$formcontent .= html_writer::end_tag('form');
// Wrap the whole form in a div
$formcontent = html_writer::tag('div', $formcontent, array('id' => 'chooseform'));
// Put all of the content together
$content = $formcontent;
$content = html_writer::tag('div', $content, array('id' => 'choosercontainer'));
return $header . html_writer::tag('div', $content, array('id' => 'chooserdialogue'));
}
/**
* Build the HTML for a specified set of modules
*
* @param array $modules A set of modules as used by the
* course_modchooser_module function
* @return string The composed HTML for the module
*/
protected function course_modchooser_module_types($modules) {
$return = '';
foreach ($modules as $module) {
if (!isset($module->types)) {
$return .= $this->course_modchooser_module($module);
} else {
$return .= $this->course_modchooser_module($module, array('nonoption'));
foreach ($module->types as $type) {
$return .= $this->course_modchooser_module($type, array('option', 'subtype'));
}
}
}
return $return;
}
/**
* Return the HTML for the specified module adding any required classes
*
* @param object $module An object containing the title, and link. An
* icon, and help text may optionally be specified. If the module
* contains subtypes in the types option, then these will also be
* displayed.
* @param array $classes Additional classes to add to the encompassing
* div element
* @return string The composed HTML for the module
*/
protected function course_modchooser_module($module, $classes = array('option')) {
$output = '';
$output .= html_writer::start_tag('div', array('class' => implode(' ', $classes)));
$output .= html_writer::start_tag('label', array('for' => 'module_' . $module->name));
if (!isset($module->types)) {
$output .= html_writer::tag('input', '', array('type' => 'radio',
'name' => 'jumplink', 'id' => 'module_' . $module->name, 'value' => $module->link));
}
$output .= html_writer::start_tag('span', array('class' => 'modicon'));
if (isset($module->icon)) {
// Add an icon if we have one
$output .= $module->icon;
}
$output .= html_writer::end_tag('span');
$output .= html_writer::tag('span', $module->title, array('class' => 'typename'));
if (!isset($module->help)) {
// Add help if found
$module->help = get_string('nohelpforactivityorresource', 'moodle');
}
// Format the help text using markdown with the following options
$options = new stdClass();
$options->trusted = false;
$options->noclean = false;
$options->smiley = false;
$options->filter = false;
$options->para = true;
$options->newlines = false;
$options->overflowdiv = false;
$module->help = format_text($module->help, FORMAT_MARKDOWN, $options);
$output .= html_writer::tag('span', $module->help, array('class' => 'typesummary'));
$output .= html_writer::end_tag('label');
$output .= html_writer::end_tag('div');
return $output;
}
protected function course_modchooser_title($title, $identifier = null) {
$module = new stdClass();
$module->name = $title;
$module->types = array();
$module->title = get_string($title, $identifier);
$module->help = '';
return $this->course_modchooser_module($module, array('moduletypetitle'));
}
}

0
course/style.css Normal file
View File

View File

@ -18,6 +18,7 @@
$move = optional_param('move', 0, PARAM_INT);
$marker = optional_param('marker',-1 , PARAM_INT);
$switchrole = optional_param('switchrole',-1, PARAM_INT);
$modchooser = optional_param('modchooser', -1, PARAM_BOOL);
$params = array();
if (!empty($name)) {
@ -129,6 +130,11 @@
redirect($PAGE->url);
}
}
if (($modchooser == 1) && confirm_sesskey()) {
set_user_preference('usemodchooser', $modchooser);
} else if (($modchooser == 0) && confirm_sesskey()) {
set_user_preference('usemodchooser', $modchooser);
}
if (has_capability('moodle/course:update', $context)) {
if ($hide && confirm_sesskey()) {
@ -241,7 +247,11 @@
echo html_writer::end_tag('div');
// Include the command toolbox YUI module
include_course_ajax($course, $modnamesused, $modnames);
// Include course AJAX
if (include_course_ajax($course, $modnamesused)) {
// Add the module chooser
$renderer = $PAGE->get_renderer('core', 'course');
echo $renderer->course_modchooser(get_module_metadata($course, $modnames), $course);
}
echo $OUTPUT->footer();

184
course/yui/modchooser/modchooser.js vendored Normal file
View File

@ -0,0 +1,184 @@
YUI.add('moodle-course-modchooser', function(Y) {
var CSS = {
PAGECONTENT : 'div#page-content',
SECTION : 'li.section',
SECTIONMODCHOOSER : 'a.sectionmodchooserlink',
SITEMENU : 'div.block_site_main_menu',
SITETOPIC : 'div.sitetopic'
};
var MODCHOOSERNAME = 'course-modchooser';
var MODCHOOSER = function() {
MODCHOOSER.superclass.constructor.apply(this, arguments);
}
Y.extend(MODCHOOSER, M.core.chooserdialogue, {
// The current section ID
sectionid : null,
// The hidden element holding the jump param
jumplink : null,
initializer : function(config) {
var dialogue = Y.one('#chooserdialogue');
var header = Y.one('#choosertitle');
var params = {
width: '540px'
};
this.setup_chooser_dialogue(dialogue, header, params);
this.jumplink = this.container.one('#jump');
// Initialize existing sections and register for dynamically created sections
this.setup_for_section();
M.course.coursebase.register_module(this);
// Catch the page toggle
Y.all('.block_settings #settingsnav .type_course .modchoosertoggle a').on('click', this.toggle_mod_chooser, this);
// Ensure that help links are opened in an appropriate popup
this.container.all('div.helpdoclink a').on('click', function(e) {
var anchor = e.target.ancestor('a', true);
var args = {
'name' : 'popup',
'url' : anchor.getAttribute('href'),
'option' : ''
};
var options = [
'height=400',
'width=500',
'top=0',
'left=0',
'menubar=0',
'location=0',
'scrollbars',
'resizable',
'toolbar',
'status',
'directories=0',
'fullscreen=0',
'dependent'
]
args.options = options.join(',');
// Note: openpopup is provided by lib/javascript-static.js
openpopup(e, args);
});
},
/**
* Update any section areas within the scope of the specified
* selector with AJAX equivalents
*
* @param baseselector The selector to limit scope to
* @return void
*/
setup_for_section : function(baseselector) {
if (!baseselector) {
var baseselector = CSS.PAGECONTENT;
}
// Setup for site topics
Y.one(baseselector).all(CSS.SITETOPIC).each(function(section) {
// The site topic has a sectionid of 1
this._setup_for_section(section, 1);
}, this);
// Setup for the site menu
Y.one(baseselector).all(CSS.SITEMENU).each(function(section) {
// The site menu has a sectionid of 0
this._setup_for_section(section, 0);
}, this);
// Setup for standard course topics
Y.one(baseselector).all(CSS.SECTION).each(function(section) {
// Determine the sectionid for this section
var sectionid = section.get('id').replace('section-', '');
this._setup_for_section(section, sectionid);
}, this);
},
_setup_for_section : function(section, sectionid) {
var chooserlink = section.one(CSS.SECTIONMODCHOOSER);
chooserlink.on('click', this.display_mod_chooser, this, sectionid);
},
/**
* Display the module chooser
*
* @param e Event Triggering Event
* @param secitonid integer The ID of the section triggering the dialogue
* @return void
*/
display_mod_chooser : function (e, sectionid) {
// Set the section for this version of the dialogue
this.sectionid = sectionid;
this.display_chooser(e);
},
toggle_mod_chooser : function(e) {
// Get the add section link
var modchooserlinks = Y.all('div.addresourcemodchooser');
// Get the dropdowns
var dropdowns = Y.all('div.addresourcedropdown');
if (modchooserlinks.size() == 0) {
// Continue with non-js action if there are no modchoosers to add
return;
}
// We need to update the text and link
var togglelink = Y.one('.block_settings #settingsnav .type_course .modchoosertoggle a');
// The actual text is in the last child
var toggletext = togglelink.get('lastChild');
var usemodchooser;
// Determine whether they're currently hidden
if (modchooserlinks.item(0).hasClass('visibleifjs')) {
// The modchooser is currently visible, hide it
usemodchooser = 0;
modchooserlinks
.removeClass('visibleifjs')
.addClass('hiddenifjs');
dropdowns
.addClass('visibleifjs')
.removeClass('hiddenifjs');
toggletext.set('data', M.util.get_string('modchooserenable', 'moodle'));
togglelink.set('href', togglelink.get('href').replace('off', 'on'));
} else {
// The modchooser is currently not visible, show it
usemodchooser = 1;
modchooserlinks
.addClass('visibleifjs')
.removeClass('hiddenifjs');
dropdowns
.removeClass('visibleifjs')
.addClass('hiddenifjs');
toggletext.set('data', M.util.get_string('modchooserdisable', 'moodle'));
togglelink.set('href', togglelink.get('href').replace('on', 'off'));
}
M.util.set_user_preference('usemodchooser', usemodchooser);
// Prevent the page from reloading
e.preventDefault();
},
option_selected : function(thisoption) {
// Add the sectionid to the URL
this.jumplink.set('value', thisoption.get('value') + '&section=' + this.sectionid);
}
},
{
NAME : MODCHOOSERNAME,
ATTRS : {
}
});
M.course = M.course || {};
M.course.init_chooser = function(config) {
return new MODCHOOSER(config);
}
},
'@VERSION@', {
requires:['base', 'overlay', 'moodle-core-chooserdialogue', 'transition']
}
);

View File

@ -151,8 +151,12 @@
echo $OUTPUT->box_end();
}
}
include_course_ajax($SITE, $modnamesused, $modnames);
// Include course AJAX
if (include_course_ajax($SITE, $modnamesused)) {
// Add the module chooser
$renderer = $PAGE->get_renderer('core', 'course');
echo $renderer->course_modchooser(get_module_metadata($SITE, $modnames), $SITE);
}
if (isloggedin() and !isguestuser() and isset($CFG->frontpageloggedin)) {
$frontpagelayout = $CFG->frontpageloggedin;

View File

@ -66,6 +66,7 @@ $string['addnewuser'] = 'Add a new user';
$string['addnousersrecip'] = 'Add users who haven\'t accessed this {$a} to recipient list';
$string['addpagehere'] = 'Add page here';
$string['addresource'] = 'Add a resource...';
$string['addresourceoractivity'] = 'Add a new resource or activity';
$string['address'] = 'Address';
$string['addstudent'] = 'Add student';
$string['addsubcategory'] = 'Add a sub-category';
@ -224,6 +225,7 @@ $string['idnumbercoursecategory'] = 'Category ID number';
$string['idnumbercoursecategory_help'] = 'The ID number of a course category is only used when matching the category against external systems and is not displayed anywhere on the site. If the category has an official code name it may be entered, otherwise the field can be left blank.';
$string['categoryupdated'] = 'The category \'{$a}\' was updated';
$string['changesmadereallygoaway'] = 'You have made changes. Are you sure you want to navigate away and lose your changes?';
$string['choosemodtype'] = 'Select a resource or activity to add';
$string['city'] = 'City/town';
$string['clambroken'] = 'Your administrator has enabled virus checking for file uploads but has misconfigured something.<br />Your file upload was NOT successful. Your administrator has been emailed to notify them so they can fix it.<br />Maybe try uploading this file later.';
$string['clamdeletedfile'] = 'The file has been deleted';
@ -1053,6 +1055,8 @@ $string['missingurl'] = 'Missing URL';
$string['missingusername'] = 'Missing username';
$string['moddoesnotsupporttype'] = 'Module {$a->modname} does not support uploads of type {$a->type}';
$string['modified'] = 'Modified';
$string['modchooserenable'] = 'Enable module chooser dialogue';
$string['modchooserdisable'] = 'Disable module chooser dialogue';
$string['moduledeleteconfirm'] = 'You are about to completely delete the module \'{$a}\'. This will completely delete everything in the database associated with this activity module. Are you SURE you want to continue?';
$string['moduledeletefiles'] = 'All data associated with the module \'{$a->module}\' has been deleted from the database. To complete the deletion (and prevent the module re-installing itself), you should now delete this directory from your server: {$a->directory}';
$string['moduleintro'] = 'Description';
@ -1167,6 +1171,7 @@ $string['nodstpresets'] = 'The administrator has not enabled Daylight Savings Ti
$string['nofilesselected'] = 'No files have been selected to restore';
$string['nofilesyet'] = 'No files have been uploaded to your course yet';
$string['nograde'] = 'No grade';
$string['nohelpforactivityorresource'] = 'I\'m sorry, but there is currently no help associated with this resource or activity';
$string['nochange'] = 'No change';
$string['noimagesyet'] = 'No images have been uploaded to your course yet';
$string['nologsfound'] = 'No logs have been found';
@ -1489,6 +1494,7 @@ $string['selectdefault'] = 'Select default';
$string['selectedfile'] = 'Selected file';
$string['selectednowmove'] = '{$a} files selected for moving. Now go into the destination folder and press \'Move files to here\'';
$string['selectfiles'] = 'Select files';
$string['selectmoduletoviewhelp'] = 'Select a module to view its help.';
$string['selectnos'] = 'Select all \'no\'';
$string['selectperiod'] = 'Select period';
$string['senddetails'] = 'Send my details via email';

View File

@ -3546,20 +3546,38 @@ class settings_navigation extends navigation_node {
if ($this->page->url->compare(new moodle_url('/course/view.php'), URL_MATCH_BASE)) {
// We are on the course page, retain the current page params e.g. section.
$url = clone($this->page->url);
$url->param('sesskey', sesskey());
$baseurl = clone($this->page->url);
$baseurl->param('sesskey', sesskey());
} else {
// Edit on the main course page.
$url = new moodle_url('/course/view.php', array('id'=>$course->id, 'sesskey'=>sesskey()));
$baseurl = new moodle_url('/course/view.php', array('id'=>$course->id, 'sesskey'=>sesskey()));
}
$editurl = clone($baseurl);
if ($this->page->user_is_editing()) {
$url->param('edit', 'off');
$editurl->param('edit', 'off');
$editstring = get_string('turneditingoff');
} else {
$url->param('edit', 'on');
$editurl->param('edit', 'on');
$editstring = get_string('turneditingon');
}
$coursenode->add($editstring, $url, self::TYPE_SETTING, null, null, new pix_icon('i/edit', ''));
$coursenode->add($editstring, $editurl, self::TYPE_SETTING, null, null, new pix_icon('i/edit', ''));
// Add the module chooser toggle
$modchoosertoggleurl = clone($baseurl);
if ($this->page->user_is_editing() && course_ajax_enabled($course)) {
if ($usemodchooser = get_user_preferences('usemodchooser', 1)) {
$modchoosertogglestring = get_string('modchooserdisable', 'moodle');
$modchoosertoggleurl->param('modchooser', 'off');
} else {
$modchoosertogglestring = get_string('modchooserenable', 'moodle');
$modchoosertoggleurl->param('modchooser', 'on');
}
$modchoosertoggle = $coursenode->add($modchoosertogglestring, $modchoosertoggleurl, self::TYPE_SETTING);
$modchoosertoggle->add_class('modchoosertoggle');
$modchoosertoggle->add_class('visibleifjs');
user_preference_allow_ajax_update('usemodchooser', PARAM_BOOL);
}
if ($this->page->user_is_editing()) {
// Removed as per MDL-22732

View File

@ -0,0 +1,192 @@
YUI.add('moodle-core-chooserdialogue', function(Y) {
var CHOOSERDIALOGUE = function() {
CHOOSERDIALOGUE.superclass.constructor.apply(this, arguments);
}
Y.extend(CHOOSERDIALOGUE, Y.Base, {
// The overlay widget
overlay: null,
// The submit button - we disable this until an element is set
submitbutton : null,
// The chooserdialogue container
container : null,
setup_chooser_dialogue : function(bodycontent, headercontent, config) {
// Set Default options
var params = {
bodyContent : bodycontent.get('innerHTML'),
headerContent : headercontent.get('innerHTML'),
visible : false, // Hide by default
zindex : 100, // Display in front of other items
lightbox : true, // This dialogue should be modal
shim : true
}
// Override with additional options
for (paramkey in config) {
params[paramkey] = config[paramkey];
}
// Create the overlay
this.overlay = new M.core.dialogue(params);
// Remove the template for the chooser
bodycontent.remove();
headercontent.remove();
// Hide and then render the overlay
this.overlay.hide();
this.overlay.render();
// Set useful links
this.container = this.overlay.get('boundingBox').one('#choosercontainer');
this.options = this.container.all('.option input[type=radio]');
},
/**
* Display the module chooser
*
* @param e Event Triggering Event
* @return void
*/
display_chooser : function (e) {
// Stop the default event actions before we proceed
e.preventDefault();
var bb = this.overlay.get('boundingBox');
var dialogue = this.container.one('.alloptions');
// Set the dialogue height
this.calculate_height(dialogue);
// These will trigger a check_options call to display the correct help
this.container.on('click', this.check_options, this);
this.container.on('key_up', this.check_options, this);
this.container.on('dblclick', function(e) {
if (e.target.ancestor('div.option')) {
this.check_options();
this.container.one('form').submit();
}
}, this);
// Hook onto the cancel button to hide the form
this.container.one('#addcancel').on('click', this.cancel_popup, this);
// Grab global keyup events and handle them
Y.one('document').on('keyup', this.handle_key_press, this);
// Add references to various elements we adjust
this.jumplink = this.container.one('#jump');
this.submitbutton = this.container.one('#submitbutton');
// Disable the submit element until the user makes a selection
this.submitbutton.set('disabled', 'true');
// Display the overlay
this.overlay.show();
// Finally, focus the first radio element - this enables form selection via the keyboard
this.container.one('.option input[type=radio]').focus();
// Trigger check_options to set the initial jumpurl
this.check_options();
},
/**
* Calculate the optimum height of the chooser dialogue
*
* This tries to set a sensible maximum and minimum to ensure that some options are always shown, and preferably
* all, whilst fitting the box within the current viewport
*
* @param dialogue Y.Node The dialogue
* @return void
*/
calculate_height : function(dialogue) {
var winheight = this.overlay.get('boundingBox').get('winHeight');
// Try and set a sensible max-height -- this must be done before setting the top
// Set a default height of 640px
var newheight = this.get('maxheight');
if (winheight <= newheight) {
// Deal with smaller window sizes
if (winheight <= this.get('minheight')) {
newheight = this.get('minheight');
} else {
newheight = winheight;
}
}
// Set a fixed position if the window is large enough
if (newheight > this.get('minheight')) {
this.overlay.get('boundingBox').setStyle('position', 'fixed');
} else {
this.overlay.get('boundingBox').setStyle('position', 'absolute');
}
// Take off 15px top and bottom for borders, plus 40px each for the title and button area before setting the
// new max-height
newheight = newheight - (15 + 15 + 40 + 40);
dialogue.setStyle('max-height', newheight + 'px');
// Re-calculate the location now that we've changed the size
this.overlay.centerDialogue();
},
handle_key_press : function(e) {
if (e.keyCode == 27) {
this.cancel_popup(e);
}
},
cancel_popup : function (e) {
// Prevent normal form submission before hiding
e.preventDefault();
this.hide();
},
hide : function() {
// Detach the global keypress handler before hiding
Y.one('document').detach('keyup', this.handle_key_press, this);
this.container.detachAll();
this.overlay.hide();
},
check_options : function(e) {
// Check which options are set, and change the parent class
// to show/hide help as required
this.options.each(function(thisoption) {
var optiondiv = thisoption.get('parentNode').get('parentNode');
if (thisoption.get('checked')) {
optiondiv.addClass('selected');
// Trigger any events for this option
this.option_selected(thisoption);
// Ensure that the form may be submitted
this.submitbutton.removeAttribute('disabled');
// Ensure that the radio remains focus so that keyboard navigation is still possible
thisoption.focus();
} else {
optiondiv.removeClass('selected');
}
}, this);
},
option_selected : function(e) {
}
},
{
NAME : 'moodle-core-chooserdialogue',
ATTRS : {
minheight : {
value : 300
},
maxheight : {
value : 660
}
}
});
M.core = M.core || {};
M.core.chooserdialogue = CHOOSERDIALOGUE;
},
'@VERSION@', {
requires:['base', 'overlay', 'moodle-enrol-notification']
}
);

View File

@ -907,3 +907,98 @@ sup {vertical-align: super;}
#page-admin-setting-enrolsettingsflatfile.dir-rtl .informationbox {direction: ltr;text-align: left;}
#page-admin-grade-edit-scale-edit.dir-rtl .error input#id_name {margin-right: 170px;}
/**
* Chooser Dialogue
*
* This CSS belong to the chooser dialogue which should work both with, and
* without javascript enabled
*/
/* Hide the dialog and it's title */
#chooserdialogue,
#choosertitle {
display:none;
}
/* Center the submit buttons within the area */
#choosercontainer #chooseform .submitbuttons {
margin: 0.7em 0;
text-align: center;
}
/* Various settings for the options area */
#choosercontainer #chooseform .options {
position: relative;
border-bottom: 1px solid grey;
padding: 0.24em 0;
}
/* Only set these options if we're showing the js container */
.jsenabled #choosercontainer #chooseform .alloptions {
max-height: 530px;
overflow-x: hidden;
overflow-y: auto;
max-width: 18.15em;
}
/* Settings for option rows and option subtypes */
#choosercontainer #chooseform .moduletypetitle,
#choosercontainer #chooseform .option,
#choosercontainer #chooseform .nonoption {
margin-bottom: 0;
padding: 0 0 0 0.3em;
}
#choosercontainer #chooseform .moduletypetitle {
font-weight: bold;
text-align : center;
}
#choosercontainer #chooseform .subtype {
margin-bottom: 0;
padding: 0 0 0 1em;
}
#choosercontainer #chooseform .option .typename,
#choosercontainer #chooseform .option span.modicon img.icon {
padding: 0 0 0 0.3em;
}
#choosercontainer #chooseform .option input[type=radio],
#choosercontainer #chooseform .option span.typename,
#choosercontainer #chooseform .option span.modicon {
vertical-align: middle;
}
#choosercontainer #chooseform .option label {
display: block;
padding: 0.2em 0 0.2em 0;
}
/* The instruction/help area */
#choosercontainer #chooseform .instruction,
.jsenabled #choosercontainer #chooseform .typesummary {
display: none;
position: absolute;
top: 0px;
right: 0px;
bottom: 0px;
left: 18.5em;
margin: 0;
border-left: 1px solid grey;
padding: 0.3em 0.5em;
background-color: white;
overflow-x: hidden;
overflow-y: auto;
max-height: 550px;
}
/* Selected option settings */
.jsenabled #choosercontainer #chooseform .instruction,
#choosercontainer #chooseform .selected .typesummary {
display: block;
}
#choosercontainer #chooseform .selected {
background-color: #ddd;
}