Skip to content

Commit

Permalink
MDL-49582 core_lib: Add button to allow user to reset table preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyjbutler committed Jul 16, 2015
1 parent e1d4e28 commit bf7c844
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions lang/en/moodle.php
Expand Up @@ -1530,6 +1530,7 @@
$string['resetrecordexpired'] = 'The password reset link you used is more than {$a} minutes old and has expired. Please initiate a new password reset.';
$string['resetstartdate'] = 'Reset start date';
$string['resetstatus'] = 'Status';
$string['resettable'] = 'Reset table preferences';
$string['resettask'] = 'Task';
$string['resettodefaults'] = 'Reset to defaults';
$string['resortsubcategoriesby'] = 'Sort subcategories by {$a} ascending';
Expand Down
36 changes: 36 additions & 0 deletions lib/tablelib.php
Expand Up @@ -34,6 +34,7 @@
define('TABLE_VAR_IFIRST', 4);
define('TABLE_VAR_ILAST', 5);
define('TABLE_VAR_PAGE', 6);
define('TABLE_VAR_RESET', 7);
/**#@-*/

/**#@+
Expand Down Expand Up @@ -138,6 +139,7 @@ function __construct($uniqueid) {
TABLE_VAR_IFIRST => 'tifirst',
TABLE_VAR_ILAST => 'tilast',
TABLE_VAR_PAGE => 'page',
TABLE_VAR_RESET => 'treset'
);
}

Expand Down Expand Up @@ -508,6 +510,17 @@ function setup() {
$this->prefs['i_first'] = $ifirst;
}

// Allow user to reset table preferences.
if (optional_param($this->request[TABLE_VAR_RESET], 0, PARAM_BOOL) === 1) {
$this->prefs = array(
'collapse' => array(),
'sortby' => array(),
'i_first' => '',
'i_last' => '',
'textsort' => $this->column_textsort,
);
}

// Save user preferences if they have changed.
if ($this->prefs != $oldprefs) {
if ($this->persistent) {
Expand Down Expand Up @@ -971,6 +984,10 @@ function print_initials_bar() {
*/
function print_nothing_to_display() {
global $OUTPUT;

// Render button to allow user to reset table preferences.
echo $this->render_reset_button();

$this->print_initials_bar();

echo $OUTPUT->heading(get_string('nothingtodisplay'));
Expand Down Expand Up @@ -1325,6 +1342,10 @@ protected function sort_link($text, $column, $isprimary, $order) {
*/
function start_html() {
global $OUTPUT;

// Render button to allow user to reset table preferences.
echo $this->render_reset_button();

// Do we need to print initial bars?
$this->print_initials_bar();

Expand Down Expand Up @@ -1363,6 +1384,21 @@ function make_styles_string($styles) {
}
return $string;
}

/**
* Generate the HTML for the table preferences reset button.
*
* @return string HTML fragment.
*/
private function render_reset_button() {
$url = $this->baseurl->out(false, array($this->request[TABLE_VAR_RESET] => 1));

$html = html_writer::start_div('mdl-right');
$html .= html_writer::link($url, get_string('resettable'));
$html .= html_writer::end_div();

return $html;
}
}


Expand Down

0 comments on commit bf7c844

Please sign in to comment.