Skip to content
Permalink
Browse files

MDL-54698 message: move notifications prefs into own page

  • Loading branch information...
ryanwyllie authored and markn86 committed Aug 15, 2016
1 parent bf4c393 commit 8c125526f1ebc10211b91c200b3ba90dc364e434
@@ -121,6 +121,7 @@
$string['notificationpreferences'] = 'Notification preferences';
$string['notificationimage'] = 'Notification image';
$string['notifications'] = 'Notifications';
$string['notificationsnewmessages'] = 'Notifications of new messages';
$string['off'] = 'Off';
$string['offline'] = 'Offline';
$string['offlinecontacts'] = 'Offline contacts ({$a})';
@@ -147,6 +148,7 @@
$string['readmessages'] = '{$a} read messages';
$string['removecontact'] = 'Remove contact';
$string['removefromyourcontacts'] = 'Remove from your contacts';
$string['requiresconfiguration'] = 'Requires configuration';
$string['savemysettings'] = 'Save my settings';
$string['search'] = 'Search';
$string['searchforperson'] = 'Search for a person';
@@ -179,7 +181,6 @@
$string['touserdoesntexist'] = 'You can not send a message to a user id ({$a}) that doesn\'t exist';
$string['unabletomessageuser'] = 'You are not permitted to send a message to that user';
$string['unblockcontact'] = 'Unblock contact';
$string['unblocknoncontacts'] = 'Allow non-contacts to message me';
$string['unreadmessages'] = 'Unread messages ({$a})';
$string['unreadnewmessages'] = 'New messages ({$a})';
$string['unreadnewmessage'] = 'New message from {$a}';
@@ -788,6 +788,14 @@
'type' => 'write',
'ajax' => true,
),
'core_message_get_message_processor' => array(
'classname' => 'core_message_external',
'methodname' => 'get_message_processor',
'classpath' => 'message/externallib.php',
'description' => 'Get a message processor',
'type' => 'read',
'ajax' => true,
),
'core_message_search_contacts' => array(
'classname' => 'core_message_external',
'methodname' => 'search_contacts',
@@ -3207,7 +3207,7 @@ public function notification_menu() {
'userid' => $USER->id,
'allnotificationsdisabled' => !empty($USER->emailstop),
'urls' => [
'preferences' => (new moodle_url('/message/edit.php', ['id' => $USER->id]))->out(),
'preferences' => (new moodle_url('/message/notificationpreferences.php', ['id' => $USER->id]))->out(),
],
];
return $this->render_from_template('message/notification_popover', $context);
@@ -39,7 +39,6 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates'
CONTENT_ITEM_CONTAINER: '.content-item-container',
EMPTY_MESSAGE: '.empty-message',
LINK_URL: '[data-link-url]',
BLOCK_NON_CONTACTS_BUTTON: '[data-block-non-contacts]',
};

/**
@@ -276,70 +275,6 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates'
.always(function() { this.markAllReadButton.removeClass('loading'); }.bind(this));
};

/**
* Update the block messages from non-contacts user preference in the DOM and
* send a request to update on the server.
*
* @method toggleBlockNonContactsStatus
*/
MessagePopoverController.prototype.toggleBlockNonContactsStatus = function() {
var button = this.blockNonContactsButton;
var ischecked = (button.attr('aria-checked') === 'true');
var blockstring = '';
var unblockstring = '';

if (button.hasClass('loading')) {
return $.Deferred().resolve();
}

button.addClass('loading');

return Str.get_strings([
{
key: 'blocknoncontacts',
component: 'message',
},
{
key: 'unblocknoncontacts',
component: 'message',
}
]).then(function(strings) {
// If we could load the strings then update the user preferences.
blockstring = strings[0];
unblockstring = strings[1];

var request = {
methodname: 'core_user_update_user',
args: {
user: {
preferences: [
{
type: button.attr('data-preference-key'),
value: ischecked ? 0 : 1,
}
]
}
}
};

return Ajax.call([request])[0];
})
.done(function() {
// If everything executed correctly then update the DOM.
if (ischecked) {
button.attr('aria-checked', false);
button.attr('data-original-title', blockstring);
} else {
button.attr('aria-checked', true);
button.attr('data-original-title', unblockstring);
}
})
.fail(Notification.exception)
.always(function() {
button.removeClass('loading');
});
};

/**
* Add all of the required event listeners for this messages popover.
*
@@ -391,14 +326,6 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates'
e.stopPropagation();
}.bind(this));

// Update the state of non-contact blocking when button is activated.
this.root.on(CustomEvents.events.activate, SELECTORS.BLOCK_NON_CONTACTS_BUTTON, function(e, data) {
this.toggleBlockNonContactsStatus();

e.stopPropagation();
data.originalEvent.preventDefault();
}.bind(this));

// Mark all messages as read when button is activated.
this.root.on(CustomEvents.events.activate, SELECTORS.MARK_ALL_READ_BUTTON, function(e, data) {
this.markAllAsRead();
@@ -0,0 +1,93 @@
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Controls the message preference page.
*
* @module core_message/notification_preference
* @class notification_preference
* @package message
* @copyright 2016 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since 3.2
*/
define(['jquery', 'core/ajax', 'core/notification',
'core_message/preferences_notifications_list_controller', 'core/custom_interaction_events'],
function($, Ajax, Notification, ListController, CustomEvents) {

var SELECTORS = {
PREFERENCES_CONTAINER: '.preferences-container',
BLOCK_NON_CONTACTS: '.block-non-contacts-container [data-block-non-contacts]',
BLOCK_NON_CONTACTS_CONTAINER: '.block-non-contacts-container',
};

/**
* Constructor for the MessagePreferences.
*
* @return object MessagePreferences
*/
var MessagePreferences = function() {
new ListController($(SELECTORS.PREFERENCES_CONTAINER));
var blockContactsElement = $(SELECTORS.BLOCK_NON_CONTACTS);

CustomEvents.define(blockContactsElement, [
CustomEvents.events.activate
]);

blockContactsElement.on(CustomEvents.events.activate, function(e) {
this.saveBlockNonContactsStatus();
}.bind(this));
};

/**
* Update the block messages from non-contacts user preference in the DOM and
* send a request to update on the server.
*
* @method saveBlockNonContactsStatus
*/
MessagePreferences.prototype.saveBlockNonContactsStatus = function() {
var checkbox = $(SELECTORS.BLOCK_NON_CONTACTS);
var container = $(SELECTORS.BLOCK_NON_CONTACTS_CONTAINER);
var ischecked = checkbox.prop('checked');

if (container.hasClass('loading')) {
return $.Deferred().resolve();
}

container.addClass('loading');

var request = {
methodname: 'core_user_update_user',
args: {
user: {
preferences: [
{
type: checkbox.attr('data-preference-key'),
value: ischecked ? 1 : 0,
}
]
}
}
};

return Ajax.call([request])[0]
.fail(Notification.exception)
.always(function() {
container.removeClass('loading');
});
};

return MessagePreferences;
});
@@ -23,8 +23,14 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since 3.2
*/
define(['jquery', 'core/fragment', 'core/templates', 'core/str', 'tool_lp/dialogue'],
function($, Fragment, Templates, Str, Dialogue) {
define(['jquery', 'core/ajax', 'core/notification', 'core/fragment', 'core/templates', 'core/str', 'tool_lp/dialogue'],
function($, Ajax, Notification, Fragment, Templates, Str, Dialogue) {

var SELECTORS = {
PROCESSOR: '[data-processor-name]',
PREFERENCE_ROW: '.preference-row',
};

/**
* Constructor for the notification processor settings.
*
@@ -64,13 +70,49 @@ define(['jquery', 'core/fragment', 'core/templates', 'core/str', 'tool_lp/dialog

$(document).on('mpp:formsubmitted', function() {
dialogue.close();
});
this.updateConfiguredStatus();
}.bind(this));

$(document).on('mpp:formcancelled', function() {
dialogue.close();
});
}.bind(this));
}.bind(this));
};

/**
* Checks if the processor has been configured. If so then remove the unconfigured
* status from the interface.
*
* @method updateConfiguredStatus
*/
NotificationProcessorSettings.prototype.updateConfiguredStatus = function() {
var processorHeader = this.root.closest(SELECTORS.PROCESSOR);

if (!processorHeader.hasClass('unconfigured')) {
return;
}

var processorName = processorHeader.attr('data-processor-name');
var request = {
methodname: 'core_message_get_message_processor',
args: {
name: processorName,
userid: this.userId,
},
};

return Ajax.call([request])[0]
.fail(Notification.exception)
.done(function(result) {
// Check if the user has figured configuring the processor.
if (result.userconfigured) {
// If they have then we can enable the settings.
var notifications = $(SELECTORS.PREFERENCE_ROW + ' [data-processor-name="' + processorName + '"]');
processorHeader.removeClass('unconfigured');
notifications.removeClass('disabled');
}
});
});
};

return NotificationProcessorSettings;
@@ -0,0 +1,50 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Contains message_notification_list class for displaying on message preferences
* page.
*
* @package core_message
* @copyright 2016 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_message\output\preferences;
/**
* Class to create context for the list of notifications on the message
* preferences page.
*
* @package core_message
* @copyright 2016 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class message_notification_list extends notification_list {
/**
* Create the list component output object.
*
* @param string $component
* @param array $readyprocessors
* @param array $providers
* @param stdClass $preferences
* @param stdClass $user
*/
protected function create_list_component($component, $readyprocessors, $providers, $preferences, $user) {
return new \core_message\output\preferences\message_notification_list_component(
$component, $readyprocessors, $providers, $preferences, $user);
}
}

0 comments on commit 8c12552

Please sign in to comment.
You can’t perform that action at this time.