Skip to content

Commit

Permalink
Tidied up, added reset options and improved #16.
Browse files Browse the repository at this point in the history
  • Loading branch information
gjb2048 committed Jun 2, 2015
1 parent fe03ac2 commit e1b3a86
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 20 deletions.
7 changes: 5 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,11 @@ Known Issues
History
=============
Version 2.9.0.2.
1. Added the capability to delete a section.
2. Fixed 'Pointless try...catch block in setup_displayed_image() (lib.php)' - #15.
1. Added the capability to delete a section.
2. Fixed 'Pointless try...catch block in setup_displayed_image() (lib.php)' - #15.
3. Add option to fit content popup to window size - #16 - thanks to Anthony Kuske - https://github.com/antriver.
4. Tidied up, added reset options and improved #16.
5. Optimised 'absolute' positioning of shadebox in light of #16.

Version 2.9.0.1.
1. First 'release candidate' version for Moodle 2.9.
Expand Down
8 changes: 6 additions & 2 deletions lang/en/format_grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
$string['defaultcoursedisplay_desc'] = "Either show all the sections on a single page or section zero and the chosen section on page.";

$string['defaultfitsectioncontainertowindow'] = 'Fit section container to window by default';
$string['defaultfitsectioncontainertowindow_desc'] = 'The default setting for "fit section container to window"';
$string['defaultfitsectioncontainertowindow_desc'] = 'The default setting for \'Fit section container to window\'.';

$string['defaultnewactivity'] = 'Show new activity notification image default';
$string['defaultnewactivity_desc'] = "Show the new activity notification image when a new activity or resource are added to a section default.";
Expand Down Expand Up @@ -134,7 +134,7 @@
$string['setnewactivity_help'] = "Show the new activity notification image when a new activity or resource are added to a section.";

$string['setfitsectioncontainertowindow'] = 'Fit the section popup to the window';
$string['setfitsectioncontainertowindow_help'] = 'If enabled, the popup box with the contents of the section will fit to the size of the window and will scroll inside if necessary. If disabled, the entire page will scroll instead.';
$string['setfitsectioncontainertowindow_help'] = 'If enabled, the popup box with the contents of the section will fit to the size of the window and will scroll inside if necessary. If disabled, the entire page will scroll instead.';

$string['colourrule'] = "Please enter a valid RGB colour, six hexadecimal digits.";

Expand All @@ -157,6 +157,10 @@
$string['resetnewactivity_help'] = 'Resets the new activity notification image to the default value so it will be the same as a course the first time it is in the Grid format.';
$string['resetallnewactivity'] = 'New activities';
$string['resetallnewactivity_help'] = 'Resets the new activity notification images to the default value for all courses so it will be the same as a course the first time it is in the Grid format.';
$string['resetfitpopup'] = 'Fit section popup to the window';
$string['resetfitpopup_help'] = 'Resets the \'Fit section popup to the window\' to the default value so it will be the same as a course the first time it is in the Grid format.';
$string['resetallfitpopup'] = 'Fit section popups to the window';
$string['resetallfitpopup_help'] = 'Resets the \'Fit section popup to the window\' to the default value for all courses so it will be the same as a course the first time it is in the Grid format.';

// Capabilities.
$string['grid:changeimagecontainersize'] = 'Change or reset the image container size';
Expand Down
36 changes: 30 additions & 6 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,10 @@ public function create_edit_form_elements(&$mform, $forsection = false) {
$OUTPUT->help_icon('resetnewactivity', 'format_grid');
$resetelements[] = & $mform->createElement('checkbox', 'resetnewactivity', '', $checkboxname);

$checkboxname = get_string('resetfitpopup', 'format_grid') .
$OUTPUT->help_icon('resetfitpopup', 'format_grid');
$resetelements[] = & $mform->createElement('checkbox', 'resetfitpopup', '', $checkboxname);

$elements[] = $mform->addGroup($resetelements, 'resetgroup', get_string('resetgrp', 'format_grid'), null,
false);

Expand All @@ -689,6 +693,10 @@ public function create_edit_form_elements(&$mform, $forsection = false) {
$OUTPUT->help_icon('resetallnewactivity', 'format_grid');
$resetallelements[] = & $mform->createElement('checkbox', 'resetallnewactivity', '', $checkboxname);

$checkboxname = get_string('resetallfitpopup', 'format_grid') .
$OUTPUT->help_icon('resetallfitpopup', 'format_grid');
$resetallelements[] = & $mform->createElement('checkbox', 'resetallfitpopup', '', $checkboxname);

$elements[] = $mform->addGroup($resetallelements, 'resetallgroup', get_string('resetallgrp', 'format_grid'),
null, false);
}
Expand Down Expand Up @@ -780,10 +788,12 @@ public function update_course_format_options($data, $oldcourse = null) {
$resetimageresizemethod = false;
$resetimagecontainerstyle = false;
$resetnewactivity = false;
$resetfitpopup = false;
$resetallimagecontainersize = false;
$resetallimageresizemethod = false;
$resetallimagecontainerstyle = false;
$resetallnewactivity = false;
$resetallfitpopup = false;
if (isset($data->resetimagecontainersize) == true) {
$resetimagecontainersize = true;
unset($data->resetimagecontainersize);
Expand All @@ -800,6 +810,10 @@ public function update_course_format_options($data, $oldcourse = null) {
$resetnewactivity = true;
unset($data->resetnewactivity);
}
if (isset($data->resetfitpopup) == true) {
$resetfitpopup = true;
unset($data->resetfitpopup);
}
if (isset($data->resetallimagecontainersize) == true) {
$resetallimagecontainersize = true;
unset($data->resetallimagecontainersize);
Expand All @@ -816,6 +830,10 @@ public function update_course_format_options($data, $oldcourse = null) {
$resetallnewactivity = true;
unset($data->resetallnewactivity);
}
if (isset($data->resetallfitpopup) == true) {
$resetfitpopup = true;
unset($data->resetallfitpopup);
}

$settings = $this->get_settings();
$changedisplayedimages = false;
Expand Down Expand Up @@ -887,11 +905,11 @@ public function update_course_format_options($data, $oldcourse = null) {
}

// Now we can do the reset.
if (($resetallimagecontainersize) || ($resetallimageresizemethod) || ($resetallimagecontainerstyle) || ($resetallnewactivity)) {
$this->reset_grid_setting(0, $resetallimagecontainersize, $resetallimageresizemethod, $resetallimagecontainerstyle, $resetallnewactivity);
if (($resetallimagecontainersize) || ($resetallimageresizemethod) || ($resetallimagecontainerstyle) || ($resetallnewactivity) || ($resetallfitpopup)) {
$this->reset_grid_setting(0, $resetallimagecontainersize, $resetallimageresizemethod, $resetallimagecontainerstyle, $resetallnewactivity, $resetallfitpopup);
$changes = true;
} else if (($resetimagecontainersize) || ($resetimageresizemethod) || ($resetimagecontainerstyle) || ($resetnewactivity)) {
$this->reset_grid_setting($this->courseid, $resetimagecontainersize, $resetimageresizemethod, $resetimagecontainerstyle, $resetnewactivity);
} else if (($resetimagecontainersize) || ($resetimageresizemethod) || ($resetimagecontainerstyle) || ($resetnewactivity) || ($resetfitpopup)) {
$this->reset_grid_setting($this->courseid, $resetimagecontainersize, $resetimageresizemethod, $resetimagecontainerstyle, $resetnewactivity, $resetfitpopup);
$changes = true;
}

Expand Down Expand Up @@ -961,8 +979,9 @@ public function update_section_format_options($data) {
* @param int $imageresizemethodreset If true, reset the image resize method to the default in the settings for the format.
* @param int $imagecontainerstylereset If true, reset the colour to the default in the settings for the format.
* @param int $newactivity If true, reset the new activity to the default in the settings for the format.
* @param int $fitpopupreset If true, reset the fit popup to the default in the settings for the format.
*/
public function reset_grid_setting($courseid, $imagecontainersizereset, $imageresizemethodreset, $imagecontainerstylereset, $newactivityreset) {
public function reset_grid_setting($courseid, $imagecontainersizereset, $imageresizemethodreset, $imagecontainerstylereset, $newactivityreset, $fitpopupreset) {
global $DB, $USER;

$coursecontext = context_course::instance($this->courseid);
Expand All @@ -982,6 +1001,7 @@ public function reset_grid_setting($courseid, $imagecontainersizereset, $imagere
$updateimageresizemethod = false;
$updateimagecontainerstyle = false;
$updatenewactivity = false;
$updatefitpopup = false;
if ($imagecontainersizereset && has_capability('format/grid:changeimagecontainersize', $coursecontext) && $resetallifall) {
$updatedata['imagecontainerwidth'] = get_config('format_grid', 'defaultimagecontainerwidth');
$updatedata['imagecontainerratio'] = get_config('format_grid', 'defaultimagecontainerratio');
Expand All @@ -1005,9 +1025,13 @@ public function reset_grid_setting($courseid, $imagecontainersizereset, $imagere
$updatedata['newactivity'] = get_config('format_grid', 'defaultnewactivity');
$updatenewactivity = true;
}
if ($fitpopupreset && $resetallifall) {
$updatedata['fitsectioncontainertowindow'] = get_config('format_grid', 'defaultfitsectioncontainertowindow');
$updatefitpopup = true;
}

foreach ($records as $record) {
if (($updateimagecontainersize) || ($updateimageresizemethod) || ($updateimagecontainerstyle) || ($updatenewactivity)) {
if (($updateimagecontainersize) || ($updateimageresizemethod) || ($updateimagecontainerstyle) || ($updatenewactivity) || ($updatefitpopup)) {
$ourcourseid = $this->courseid;
$this->courseid = $record->id;
if (($updateimagecontainersize) || ($updateimageresizemethod)) {
Expand Down
9 changes: 1 addition & 8 deletions module.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,15 +314,8 @@ M.format_grid.shadebox.initialize_shadebox = function() {
}

var gridshadebox_content = M.format_grid.ourYUI.one('#gridshadebox_content');
if (gridshadebox_content.hasClass('fit_to_window_enabled')) {
// Apply the real fit_to_window class now that we know editing is off
gridshadebox_content.addClass('fit_to_window');
} else {
gridshadebox_content.setStyle('position', 'absolute');
gridshadebox_content.setStyle('width', '90%');
if (gridshadebox_content.hasClass('absolute')) {
gridshadebox_content.setStyle('top', '' + top + 'px');
gridshadebox_content.setStyle('left', '5%');
gridshadebox_content.setStyle('zIndex', '1');
}
};

Expand Down
8 changes: 6 additions & 2 deletions renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,12 @@ public function print_multiple_section_page($course, $sections, $mods, $modnames
echo html_writer::tag('div', '', array('id' => 'gridshadebox_overlay', 'style' => 'display: none;'));

$gridshadeboxcontentclasses = array('hide_content');
if ($this->settings['fitsectioncontainertowindow'] == 2) {
$gridshadeboxcontentclasses[] = 'fit_to_window_enabled';
if (!$editing) {
if ($this->settings['fitsectioncontainertowindow'] == 2) {
$gridshadeboxcontentclasses[] = 'fit_to_window';
} else {
$gridshadeboxcontentclasses[] = 'absolute';
}
}

echo html_writer::start_tag('div', array('id' => 'gridshadebox_content', 'class' => implode(' ', $gridshadeboxcontentclasses),
Expand Down
14 changes: 14 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ div#gridshadebox_overlay {
body.jsenabled #gridshadebox_content.hide_content {
display: none;
}

#gridshadebox_content.absolute {
position: absolute;
width: 90%;
left: 5%;
z-index: 1;
}

#gridshadebox_content.fit_to_window {
position: fixed;
top: 10%;
Expand All @@ -181,6 +189,7 @@ body.jsenabled #gridshadebox_content.hide_content {
left: 10%;
z-index: 1;
}

#gridshadebox_content.fit_to_window ul.gtopics {
margin: 0;
padding: 10px;
Expand All @@ -190,18 +199,22 @@ body.jsenabled #gridshadebox_content.hide_content {
overflow: auto;
height: 100%;
}

#gridshadebox_content.fit_to_window ul.gtopics h3.sectionname {
margin-top: 0;
}

#gridshadebox_content .activity {
list-style: none;
border-bottom: 1px dashed #ccc;
padding-bottom: 4px;
padding-top: 2px;
}

#gridshadebox_content ul li.grid_section {
list-style: none;
}

#gridshadebox_content ul li ul li, #gridshadebox_content ul li ol li {
border-bottom: none;
padding-bottom: 4px;
Expand All @@ -211,6 +224,7 @@ body.jsenabled #gridshadebox_content.hide_content {
#gridshadebox_content ul li ul li {
list-style: disc outside none;
}

#gridshadebox_content ul li ol li {
list-style: decimal outside none;
}
Expand Down

0 comments on commit e1b3a86

Please sign in to comment.