mirror of
https://github.com/moodle/moodle.git
synced 2025-04-19 07:25:30 +02:00
Merge branch 'MDL-81428-main' of https://github.com/HuongNV13/moodle
This commit is contained in:
commit
2c1af4fd9e
12
.upgradenotes/MDL-81428-2024061009440935.yml
Normal file
12
.upgradenotes/MDL-81428-2024061009440935.yml
Normal file
@ -0,0 +1,12 @@
|
||||
issueNumber: MDL-81428
|
||||
notes:
|
||||
core_message:
|
||||
- message: >
|
||||
The `\core_message\helper::togglecontact_link_params` now accepts a new
|
||||
optional param called `isrequested` to indicate the status of the
|
||||
contact request
|
||||
type: changed
|
||||
- message: >
|
||||
The `core_message/remove_contact_button` template is deprecated and will
|
||||
be removed in the future version
|
||||
type: deprecated
|
@ -269,6 +269,7 @@ $string['viewfullnotification'] = 'View full notification';
|
||||
$string['viewmessageswith'] = 'View messages with {$a}';
|
||||
$string['viewnotificationresource'] = 'Go to: {$a}';
|
||||
$string['viewunreadmessageswith'] = 'View unread messages with {$a}';
|
||||
$string['waitingforcontactaccept'] = 'Waiting for your approval';
|
||||
$string['writeamessage'] = 'Write a message...';
|
||||
$string['wouldliketocontactyou'] = 'Would like to contact you';
|
||||
$string['you'] = 'You:';
|
||||
|
@ -4566,9 +4566,42 @@ EOD;
|
||||
|
||||
if ($USER->id != $user->id) {
|
||||
$iscontact = \core_message\api::is_contact($USER->id, $user->id);
|
||||
$contacttitle = $iscontact ? 'removefromyourcontacts' : 'addtoyourcontacts';
|
||||
$contacturlaction = $iscontact ? 'removecontact' : 'addcontact';
|
||||
$contactimage = $iscontact ? 'removecontact' : 'addcontact';
|
||||
$isrequested = \core_message\api::get_contact_requests_between_users($USER->id, $user->id);
|
||||
$contacturlaction = '';
|
||||
$linkattributes = \core_message\helper::togglecontact_link_params(
|
||||
$user,
|
||||
$iscontact,
|
||||
true,
|
||||
!empty($isrequested),
|
||||
);
|
||||
// If the user is not a contact.
|
||||
if (!$iscontact) {
|
||||
if ($isrequested) {
|
||||
// We just need the first request.
|
||||
$requests = array_shift($isrequested);
|
||||
if ($requests->userid == $USER->id) {
|
||||
// If the user has requested to be a contact.
|
||||
$contacttitle = 'contactrequestsent';
|
||||
} else {
|
||||
// If the user has been requested to be a contact.
|
||||
$contacttitle = 'waitingforcontactaccept';
|
||||
}
|
||||
$linkattributes = array_merge($linkattributes, [
|
||||
'class' => 'disabled',
|
||||
'tabindex' => '-1',
|
||||
]);
|
||||
} else {
|
||||
// If the user is not a contact and has not requested to be a contact.
|
||||
$contacttitle = 'addtoyourcontacts';
|
||||
$contacturlaction = 'addcontact';
|
||||
}
|
||||
$contactimage = 'addcontact';
|
||||
} else {
|
||||
// If the user is a contact.
|
||||
$contacttitle = 'removefromyourcontacts';
|
||||
$contacturlaction = 'removecontact';
|
||||
$contactimage = 'removecontact';
|
||||
}
|
||||
$userbuttons['togglecontact'] = array(
|
||||
'buttontype' => 'togglecontact',
|
||||
'title' => get_string($contacttitle, 'message'),
|
||||
@ -4579,7 +4612,7 @@ EOD;
|
||||
'sesskey' => sesskey())
|
||||
),
|
||||
'image' => $contactimage,
|
||||
'linkattributes' => \core_message\helper::togglecontact_link_params($user, $iscontact),
|
||||
'linkattributes' => $linkattributes,
|
||||
'page' => $this->page
|
||||
);
|
||||
}
|
||||
|
@ -5,6 +5,6 @@
|
||||
* @copyright 2016 Ryan Wyllie <ryan@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
define("core_message/toggle_contact_button",["jquery","core/ajax","core/templates","core/notification","core/custom_interaction_events"],(function($,Ajax,Templates,Notification,CustomEvents){var getUserId=function(element){return element.attr("data-userid")},getCurrentUserId=function(element){return element.attr("data-currentuserid")},displayTextLabel=function(element){return"1"==element.attr("data-display-text-label")},isLoading=function(element){return element.hasClass("loading")||element.attr("disabled")},sendRequest=function(element,request){return isLoading(element)?$.Deferred():(element.addClass("loading"),element.attr("disabled","disabled"),Ajax.call([request])[0].fail(Notification.exception).always((function(){element.removeClass("loading"),element.removeAttr("disabled")})))};return{enhance:function(element){(element=$(element)).children(".loading-icon").length||Templates.render("core/loading",{}).done((function(html,js){element.append(html,js)})),CustomEvents.define(element,[CustomEvents.events.activate]),element.on(CustomEvents.events.activate,(function(e,data){!function(element){return"1"==element.attr("data-is-contact")}(element)?function(element){if(!isLoading(element)){var request={methodname:"core_message_create_contact_request",args:{userid:getCurrentUserId(element),requesteduserid:getUserId(element)}};sendRequest(element,request).done((function(){!function(element){element.attr("data-is-contact","1")}(element);const templateContext={displaytextlabel:displayTextLabel(element)};Templates.render("message/remove_contact_button",templateContext).done((function(html,js){Templates.replaceNodeContents(element,html,js)}))}))}}(element):function(element){if(!isLoading(element)){var request={methodname:"core_message_delete_contacts",args:{userids:[getUserId(element)]}};sendRequest(element,request).done((function(){!function(element){element.attr("data-is-contact","0")}(element);const templateContext={displaytextlabel:displayTextLabel(element)};Templates.render("message/add_contact_button",templateContext).done((function(html,js){Templates.replaceNodeContents(element,html,js)}))}))}}(element),e.preventDefault(),data.originalEvent.preventDefault()}))}}}));
|
||||
define("core_message/toggle_contact_button",["jquery","core/ajax","core/templates","core/notification","core/custom_interaction_events"],(function($,Ajax,Templates,Notification,CustomEvents){let isRequested=element=>"1"==element.attr("data-is-requested");var getUserId=function(element){return element.attr("data-userid")},getCurrentUserId=function(element){return element.attr("data-currentuserid")},displayTextLabel=function(element){return"1"==element.attr("data-display-text-label")},isLoading=function(element){return element.hasClass("loading")||element.attr("disabled")},sendRequest=function(element,request){return isLoading(element)?$.Deferred():(element.addClass("loading"),element.attr("disabled","disabled"),Ajax.call([request])[0].fail(Notification.exception).always((function(){element.removeClass("loading"),element.removeAttr("disabled")})))};return{enhance:function(element){(element=$(element)).children(".loading-icon").length||isRequested(element)||Templates.render("core/loading",{}).done((function(html,js){element.append(html,js)})),CustomEvents.define(element,[CustomEvents.events.activate]),element.on(CustomEvents.events.activate,(function(e,data){!function(element){return"1"==element.attr("data-is-contact")}(element)?isRequested(element)||function(element){if(!isLoading(element)){var request={methodname:"core_message_create_contact_request",args:{userid:getCurrentUserId(element),requesteduserid:getUserId(element)}};sendRequest(element,request).done((function(){!function(element){element.attr("data-is-requested","1")}(element),element.addClass("disabled");const templateContext={displaytextlabel:displayTextLabel(element)};Templates.render("message/contact_request_sent",templateContext).done((function(html,js){Templates.replaceNodeContents(element,html,js)}))}))}}(element):function(element){if(!isLoading(element)){var request={methodname:"core_message_delete_contacts",args:{userids:[getUserId(element)]}};sendRequest(element,request).done((function(){!function(element){element.attr("data-is-contact","0")}(element);const templateContext={displaytextlabel:displayTextLabel(element)};Templates.render("message/add_contact_button",templateContext).done((function(html,js){Templates.replaceNodeContents(element,html,js)}))}))}}(element),e.preventDefault(),data.originalEvent.preventDefault()}))}}}));
|
||||
|
||||
//# sourceMappingURL=toggle_contact_button.min.js.map
|
File diff suppressed because one or more lines are too long
@ -35,13 +35,22 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust
|
||||
};
|
||||
|
||||
/**
|
||||
* Record that the user is a contact.
|
||||
* Check the state of the element, if the current user has sent a contact request or not.
|
||||
*
|
||||
* @method setContact
|
||||
* @method isRequested
|
||||
* @param {object} element jQuery object for the button
|
||||
* @return {bool}
|
||||
*/
|
||||
let isRequested = (element) => element.attr('data-is-requested') == '1';
|
||||
|
||||
/**
|
||||
* Record that the user has sent a contact request.
|
||||
*
|
||||
* @method setContactRequested
|
||||
* @param {object} element jQuery object for the button
|
||||
*/
|
||||
var setContact = function(element) {
|
||||
element.attr('data-is-contact', '1');
|
||||
var setContactRequested = function(element) {
|
||||
element.attr('data-is-requested', '1');
|
||||
};
|
||||
|
||||
/**
|
||||
@ -144,11 +153,12 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust
|
||||
}
|
||||
};
|
||||
sendRequest(element, request).done(function() {
|
||||
setContact(element);
|
||||
setContactRequested(element);
|
||||
element.addClass('disabled');
|
||||
const templateContext = {
|
||||
'displaytextlabel': displayTextLabel(element)
|
||||
};
|
||||
Templates.render('message/remove_contact_button', templateContext).done(function(html, js) {
|
||||
Templates.render('message/contact_request_sent', templateContext).done(function(html, js) {
|
||||
Templates.replaceNodeContents(element, html, js);
|
||||
});
|
||||
});
|
||||
@ -196,7 +206,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust
|
||||
var enhance = function(element) {
|
||||
element = $(element);
|
||||
|
||||
if (!element.children('.loading-icon').length) {
|
||||
if (!element.children('.loading-icon').length && !isRequested(element)) {
|
||||
// Add the loading gif if it isn't already there.
|
||||
Templates.render('core/loading', {}).done(function(html, js) {
|
||||
element.append(html, js);
|
||||
@ -208,7 +218,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust
|
||||
element.on(CustomEvents.events.activate, function(e, data) {
|
||||
if (isContact(element)) {
|
||||
removeContact(element);
|
||||
} else {
|
||||
} else if (!isRequested(element)) {
|
||||
addContact(element);
|
||||
}
|
||||
e.preventDefault();
|
||||
|
@ -309,14 +309,21 @@ class helper {
|
||||
* @param object $user User object.
|
||||
* @param bool $iscontact
|
||||
* @param bool $displaytextlabel Instructs whether to display a text label.
|
||||
* @param bool $isrequested Whether the contact request is sent or not.
|
||||
* @return array
|
||||
*/
|
||||
public static function togglecontact_link_params($user, $iscontact = false, bool $displaytextlabel = true) {
|
||||
public static function togglecontact_link_params(
|
||||
$user,
|
||||
$iscontact = false,
|
||||
bool $displaytextlabel = true,
|
||||
bool $isrequested = false,
|
||||
) {
|
||||
global $USER;
|
||||
$params = array(
|
||||
'data-currentuserid' => $USER->id,
|
||||
'data-userid' => $user->id,
|
||||
'data-is-contact' => $iscontact,
|
||||
'data-is-requested' => $isrequested,
|
||||
'data-display-text-label' => $displaytextlabel,
|
||||
'id' => 'toggle-contact-button',
|
||||
'role' => 'button',
|
||||
|
33
message/templates/contact_request_sent.mustache
Normal file
33
message/templates/contact_request_sent.mustache
Normal file
@ -0,0 +1,33 @@
|
||||
{{!
|
||||
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/>.
|
||||
}}
|
||||
{{!
|
||||
@template core_message/contact_request_sent
|
||||
Template for the contents of the add contact button on the user's profile page.
|
||||
Context variables required for this template:
|
||||
* displaytextlabel - Whether to display text next to the action icon.
|
||||
Example context (json):
|
||||
{
|
||||
"displaytextlabel": true
|
||||
}
|
||||
}}
|
||||
<span>
|
||||
{{^displaytextlabel}}
|
||||
{{#pix}} t/addcontact, core, {{#str}} contactrequestsent, message {{/str}} {{/pix}}
|
||||
{{/displaytextlabel}}
|
||||
{{#displaytextlabel}}
|
||||
{{#pix}} t/addcontact, core {{/pix}}
|
||||
<span class="header-button-title">{{#str}} contactrequestsent, message {{/str}}</span>
|
||||
{{/displaytextlabel}}
|
||||
</span>
|
||||
{{> core/loading }}
|
@ -15,6 +15,7 @@
|
||||
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
}}
|
||||
{{!
|
||||
@deprecated since Moodle 4.5
|
||||
@template core_message/remove_contact_button
|
||||
|
||||
Template for the contents of the add contact button on the user's profile page.
|
||||
|
@ -59,6 +59,25 @@ Feature: Manage contacts
|
||||
And I click on "Contacts" "link"
|
||||
And I should see "Student 4" in the "//*[@data-section='contacts']" "xpath_element"
|
||||
|
||||
Scenario: Send a 'contact request' to someone to add a contact in the profile page
|
||||
Given I am on the "student4" "user > profile" page logged in as student3
|
||||
And I should see "Add to contacts"
|
||||
When I click on "Add to contacts" "link"
|
||||
Then I should see "Contact request sent"
|
||||
And I log out
|
||||
And I am on the "student3" "user > profile" page logged in as student4
|
||||
And I should see "Waiting for your approval"
|
||||
And I open messaging
|
||||
And I click on "Contacts" "link"
|
||||
And I click on "Requests" "link_or_button"
|
||||
And I click on "Student 3 Would like to contact you" "link"
|
||||
And I should see "Accept and add to contacts"
|
||||
And I click on "Accept and add to contacts" "link_or_button"
|
||||
And I should not see "Accept and add to contacts"
|
||||
And I log out
|
||||
And I am on the "student4" "user > profile" page logged in as student3
|
||||
And I should see "Remove from contacts"
|
||||
|
||||
Scenario: Decline a 'contact request' from someone
|
||||
Given I log in as "student1"
|
||||
Then I open messaging
|
||||
|
@ -129,9 +129,42 @@ class core_renderer extends \core_renderer {
|
||||
|
||||
if ($USER->id != $user->id) {
|
||||
$iscontact = \core_message\api::is_contact($USER->id, $user->id);
|
||||
$contacttitle = $iscontact ? 'removefromyourcontacts' : 'addtoyourcontacts';
|
||||
$contacturlaction = $iscontact ? 'removecontact' : 'addcontact';
|
||||
$contactimage = $iscontact ? 'removecontact' : 'addcontact';
|
||||
$isrequested = \core_message\api::get_contact_requests_between_users($USER->id, $user->id);
|
||||
$contacturlaction = '';
|
||||
$linkattributes = \core_message\helper::togglecontact_link_params(
|
||||
$user,
|
||||
$iscontact,
|
||||
true,
|
||||
!empty($isrequested),
|
||||
);
|
||||
// If the user is not a contact.
|
||||
if (!$iscontact) {
|
||||
if ($isrequested) {
|
||||
// We just need the first request.
|
||||
$requests = array_shift($isrequested);
|
||||
if ($requests->userid == $USER->id) {
|
||||
// If the user has requested to be a contact.
|
||||
$contacttitle = 'contactrequestsent';
|
||||
} else {
|
||||
// If the user has been requested to be a contact.
|
||||
$contacttitle = 'waitingforcontactaccept';
|
||||
}
|
||||
$linkattributes = array_merge($linkattributes, [
|
||||
'class' => 'disabled',
|
||||
'tabindex' => '-1',
|
||||
]);
|
||||
} else {
|
||||
// If the user is not a contact and has not requested to be a contact.
|
||||
$contacttitle = 'addtoyourcontacts';
|
||||
$contacturlaction = 'addcontact';
|
||||
}
|
||||
$contactimage = 'addcontact';
|
||||
} else {
|
||||
// If the user is a contact.
|
||||
$contacttitle = 'removefromyourcontacts';
|
||||
$contacturlaction = 'removecontact';
|
||||
$contactimage = 'removecontact';
|
||||
}
|
||||
$userbuttons['togglecontact'] = array(
|
||||
'buttontype' => 'togglecontact',
|
||||
'title' => get_string($contacttitle, 'message'),
|
||||
@ -142,7 +175,7 @@ class core_renderer extends \core_renderer {
|
||||
'sesskey' => sesskey())
|
||||
),
|
||||
'image' => $contactimage,
|
||||
'linkattributes' => \core_message\helper::togglecontact_link_params($user, $iscontact),
|
||||
'linkattributes' => $linkattributes,
|
||||
'page' => $this->page
|
||||
);
|
||||
}
|
||||
|
@ -1974,6 +1974,10 @@ a.disabled {
|
||||
color: $text-muted;
|
||||
}
|
||||
|
||||
a.btn.disabled {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
body.lockscroll {
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
|
@ -24971,6 +24971,10 @@ a.disabled {
|
||||
color: #6a737b;
|
||||
}
|
||||
|
||||
a.btn.disabled {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
body.lockscroll {
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
|
@ -24971,6 +24971,10 @@ a.disabled {
|
||||
color: #6a737b;
|
||||
}
|
||||
|
||||
a.btn.disabled {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
body.lockscroll {
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
|
Loading…
x
Reference in New Issue
Block a user