Skip to content

Commit

Permalink
Merge branch 'MDL-30811-master' of git://github.com/andrewnicols/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski committed Feb 29, 2016
2 parents d96a4e2 + 0e8ce68 commit 17ac1b5
Show file tree
Hide file tree
Showing 40 changed files with 1,001 additions and 280 deletions.
20 changes: 2 additions & 18 deletions admin/tool/task/scheduledtasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,9 @@

try {
\core\task\manager::configure_scheduled_task($task);
$url = $PAGE->url;
$url->params(array('success'=>get_string('changessaved')));
redirect($url);
redirect($PAGE->url, get_string('changessaved'), null, \core\output\notification::NOTIFY_SUCCESS);
} catch (Exception $e) {
$url = $PAGE->url;
$url->params(array('error'=>$e->getMessage()));
redirect($url);
redirect($PAGE->url, $e->getMessage(), null, \core\output\notification::NOTIFY_ERROR);
}
} else {
echo $OUTPUT->header();
Expand All @@ -104,19 +100,7 @@

} else {
echo $OUTPUT->header();
$error = optional_param('error', '', PARAM_NOTAGS);
if ($error) {
echo $OUTPUT->notification($error, 'notifyerror');
}
$success = optional_param('success', '', PARAM_NOTAGS);
if ($success) {
echo $OUTPUT->notification($success, 'notifysuccess');
}
$tasks = core\task\manager::get_all_scheduled_tasks();
echo $renderer->scheduled_tasks_table($tasks);
echo $OUTPUT->footer();
}




4 changes: 2 additions & 2 deletions admin/tool/templatelibrary/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ public function test_load_canonical_template() {
// Change the theme to 'base' because it overrides these templates.
$CFG->theme = 'base';

$template = external::load_canonical_template('core', 'notification_problem');
$template = external::load_canonical_template('core', 'notification_error');

// Only the base template should contain the docs.
$this->assertContains('@template core/notification_problem', $template);
$this->assertContains('@template core/notification_error', $template);

// Restore the original theme.
$CFG->theme = $originaltheme;
Expand Down
7 changes: 1 addition & 6 deletions admin/user/user_bulk_cohortadd.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,7 @@
unset($allcohorts);

if (count($cohorts) < 2) {
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('bulkadd', 'core_cohort'));
echo $OUTPUT->notification(get_string('bulknocohort', 'core_cohort'));
echo $OUTPUT->continue_button(new moodle_url('/admin/user/user_bulk.php'));
echo $OUTPUT->footer();
die;
redirect(new moodle_url('/admin/user/user_bulk.php'), get_string('bulknocohort', 'core_cohort'));
}

$countries = get_string_manager()->get_list_of_countries(true);
Expand Down
3 changes: 1 addition & 2 deletions badges/action.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@
$url = new moodle_url('/badges/action.php', $params);

if (!$badge->has_criteria()) {
echo $OUTPUT->notification(get_string('error:cannotact', 'badges') . get_string('nocriteria', 'badges'));
echo $OUTPUT->continue_button($returnurl);
redirect($returnurl, get_string('error:cannotact', 'badges') . get_string('nocriteria', 'badges'), null, \core\output\notification::NOTIFY_ERROR);
} else {
$message = get_string('reviewconfirm', 'badges', $badge->name);
echo $OUTPUT->confirm($message, $url, $returnurl);
Expand Down
2 changes: 1 addition & 1 deletion lib/amd/build/notification.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

190 changes: 162 additions & 28 deletions lib/amd/src/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* A system for displaying notifications to users from the session.
*
* Wrapper for the YUI M.core.notification class. Allows us to
* use the YUI version in AMD code until it is replaced.
*
Expand All @@ -24,20 +26,99 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since 2.9
*/
define(['core/yui'], function(Y) {
define(['core/yui', 'jquery', 'theme_bootstrapbase/bootstrap', 'core/templates', 'core/ajax', 'core/log'],
function(Y, $, bootstrap, templates, ajax, log) {
var notificationModule = {
types: {
'success': 'core/notification_success',
'info': 'core/notification_info',
'warning': 'core/notification_warning',
'error': 'core/notification_error',
},

// Private variables and functions.
fieldName: 'user-notifications',

fetchNotifications: function() {
var promises = ajax.call([{
methodname: 'core_fetch_notifications',
args: {
contextid: notificationModule.contextid
}
}]);

promises[0]
.done(notificationModule.addNotifications)
;

},

addNotifications: function(notifications) {
if (!notifications) {
notifications = [];
}

$.each(notifications, function(i, notification) {
notificationModule.renderNotification(notification.template, notification.variables);
});
},

setupTargetRegion: function() {
var targetRegion = $('#' + notificationModule.fieldName);
if (targetRegion.length) {
return;
}

var newRegion = $('<span>').attr('id', notificationModule.fieldName);

targetRegion = $('#region-main');
if (targetRegion.length) {
return targetRegion.prepend(newRegion);
}

targetRegion = $('[role="main"]');
if (targetRegion.length) {
return targetRegion.prepend(newRegion);
}

targetRegion = $('body');
return targetRegion.prepend(newRegion);
},

addNotification: function(notification) {
var template = notificationModule.types.error;

notification = $.extend({
closebutton: true,
announce: true,
type: 'error'
}, notification);

if (notification.template) {
template = notification.template;
delete notification.template;
} else if (notification.type){
if (typeof notificationModule.types[notification.type] !== 'undefined') {
template = notificationModule.types[notification.type];
}
delete notification.type;
}

return notificationModule.renderNotification(template, notification);
},

renderNotification: function(template, variables) {
if (typeof variables.message === 'undefined' || !variables.message) {
log.debug('Notification received without content. Skipping.');
return;
}
templates.render(template, variables)
.done(function(html) {
$('#' + notificationModule.fieldName).prepend(html);
})
.fail(notificationModule.exception)
;
},

return /** @alias module:core/notification */ {
// Public variables and functions.
/**
* Wrap M.core.alert.
*
* @method alert
* @param {string} title
* @param {string} message
* @param {string} yesLabel
*/
alert: function(title, message, yesLabel) {
// Here we are wrapping YUI. This allows us to start transitioning, but
// wait for a good alternative without having inconsistent dialogues.
Expand All @@ -52,16 +133,6 @@ define(['core/yui'], function(Y) {
});
},

/**
* Wrap M.core.confirm.
*
* @method confirm
* @param {string} title
* @param {string} question
* @param {string} yesLabel
* @param {string} noLabel
* @param {function} callback
*/
confirm: function(title, question, yesLabel, noLabel, callback) {
// Here we are wrapping YUI. This allows us to start transitioning, but
// wait for a good alternative without having inconsistent dialogues.
Expand All @@ -80,12 +151,6 @@ define(['core/yui'], function(Y) {
});
},

/**
* Wrap M.core.exception.
*
* @method exception
* @param {Error} ex
*/
exception: function(ex) {
// Fudge some parameters.
if (ex.backtrace) {
Expand All @@ -102,4 +167,73 @@ define(['core/yui'], function(Y) {
});
}
};

return /** @alias module:core/notification */{
init: function(contextid, notifications) {
notificationModule.contextid = contextid;

// Setup the message target region if it isn't setup already
notificationModule.setupTargetRegion();

// Setup closing of bootstrap alerts.
$().alert();

// Add provided notifications.
notificationModule.addNotifications(notifications);

// Poll for any new notifications.
notificationModule.fetchNotifications();
},

/**
* Poll the server for any new notifications.
*
* @method fetchNotifications
*/
fetchNotifications: notificationModule.fetchNotifications,

/**
* Add a notification to the page.
*
* Note: This does not cause the notification to be added to the session.
*
* @method addNotification
* @param {Object} notification The notification to add.
* @param {string} notification.message The body of the notification
* @param {string} notification.type The type of notification to add (error, warning, info, success).
* @param {Boolean} notification.closebutton Whether to show the close button.
* @param {Boolean} notification.announce Whether to announce to screen readers.
*/
addNotification: notificationModule.addNotification,

/**
* Wrap M.core.alert.
*
* @method alert
* @param {string} title
* @param {string} message
* @param {string} yesLabel
*/
alert: notificationModule.alert,

/**
* Wrap M.core.confirm.
*
* @method confirm
* @param {string} title
* @param {string} question
* @param {string} yesLabel
* @param {string} noLabel
* @param {function} callback
*/
confirm: notificationModule.confirm,

/**
* Wrap M.core.exception.
*
* @method exception
* @param {Error} ex
*/
exception: notificationModule.exception
};
});
Loading

0 comments on commit 17ac1b5

Please sign in to comment.