Merge branch 'MDL-29801_master' of git://github.com/markn86/moodle

This commit is contained in:
Eloy Lafuente (stronk7)
2015-09-02 19:19:27 +02:00
18 changed files with 813 additions and 18 deletions
+2
View File
@@ -41,6 +41,8 @@ $string['contacts'] = 'Contacts';
$string['context'] = 'context';
$string['defaultmessageoutputs'] = 'Default message outputs';
$string['defaults'] = 'Defaults';
$string['deletemessage'] = 'Delete message';
$string['deletemessageconfirmation'] = 'Are you sure you want to delete this message? It will only be deleted from your messaging history and will still be viewable by the user who sent or received the message.';
$string['deletemessagesdays'] = 'Number of days before old messages are automatically deleted';
$string['disableall'] = 'Temporarily disable notifications';
$string['disableall_help'] = 'Temporarily disable all notifications except those marked as "forced" by the site administrator';
+2
View File
@@ -355,6 +355,8 @@ $string['siteadministrators'] = 'Site administrators';
$string['site:approvecourse'] = 'Approve course creation';
$string['site:backup'] = 'Backup courses';
$string['site:config'] = 'Change site configuration';
$string['site:deleteanymessage'] = 'Delete any messages on the site';
$string['site:deleteownmessage'] = 'Delete messages sent by and to the user';
$string['site:doanything'] = 'Allowed to do everything';
$string['site:doclinks'] = 'Show links to offsite docs';
$string['site:forcelanguage'] = 'Override course language';
+20
View File
@@ -77,6 +77,17 @@ $capabilities = array(
)
),
'moodle/site:deleteanymessage' => array(
'riskbitmask' => RISK_DATALOSS,
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
'manager' => CAP_ALLOW
)
),
'moodle/site:sendmessage' => array(
'riskbitmask' => RISK_SPAM,
@@ -89,6 +100,15 @@ $capabilities = array(
)
),
'moodle/site:deleteownmessage' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
'user' => CAP_ALLOW
)
),
'moodle/site:approvecourse' => array(
'riskbitmask' => RISK_XSS,
+6 -2
View File
@@ -534,13 +534,15 @@
<FIELD NAME="contexturl" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="If this message is a notification of an event contexturl should contain a link to view this event. For example if its a notification of a forum post contexturl should contain a link to the forum post."/>
<FIELD NAME="contexturlname" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Display text for the contexturl"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="timeuserfromdeleted" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="timeusertodeleted" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
</KEYS>
<INDEXES>
<INDEX NAME="useridto" UNIQUE="false" FIELDS="useridto"/>
<INDEX NAME="useridfromto" UNIQUE="false" FIELDS="useridfrom, useridto"/>
<INDEX NAME="useridfromtodeleted" UNIQUE="false" FIELDS="useridfrom, useridto, timeuserfromdeleted, timeusertodeleted"/>
</INDEXES>
</TABLE>
<TABLE NAME="message_read" COMMENT="Stores all messages that have been read">
@@ -558,13 +560,15 @@
<FIELD NAME="contexturlname" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Display text for the contexturl"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="timeread" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="timeuserfromdeleted" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="timeusertodeleted" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
</KEYS>
<INDEXES>
<INDEX NAME="useridto" UNIQUE="false" FIELDS="useridto"/>
<INDEX NAME="useridfromto" UNIQUE="false" FIELDS="useridfrom, useridto"/>
<INDEX NAME="useridfromtodeleted" UNIQUE="false" FIELDS="useridfrom, useridto, timeuserfromdeleted, timeusertodeleted"/>
</INDEXES>
</TABLE>
<TABLE NAME="message_contacts" COMMENT="Maintains lists of relationships between users">
+60
View File
@@ -4470,5 +4470,65 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2015082400.00);
}
if ($oldversion < 2015090200.00) {
$table = new xmldb_table('message');
// Define the deleted fields to be added to the message tables.
$field1 = new xmldb_field('timeuserfromdeleted', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0',
'timecreated');
$field2 = new xmldb_field('timeusertodeleted', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0',
'timecreated');
$oldindex = new xmldb_index('useridfromto', XMLDB_INDEX_NOTUNIQUE,
array('useridfrom', 'useridto'));
$newindex = new xmldb_index('useridfromtodeleted', XMLDB_INDEX_NOTUNIQUE,
array('useridfrom', 'useridto', 'timeuserfromdeleted', 'timeusertodeleted'));
// Conditionally launch add field timeuserfromdeleted.
if (!$dbman->field_exists($table, $field1)) {
$dbman->add_field($table, $field1);
}
// Conditionally launch add field timeusertodeleted.
if (!$dbman->field_exists($table, $field2)) {
$dbman->add_field($table, $field2);
}
// Conditionally launch drop index useridfromto.
if ($dbman->index_exists($table, $oldindex)) {
$dbman->drop_index($table, $oldindex);
}
// Conditionally launch add index useridfromtodeleted.
if (!$dbman->index_exists($table, $newindex)) {
$dbman->add_index($table, $newindex);
}
// Now add them to the message_read table.
$table = new xmldb_table('message_read');
// Conditionally launch add field timeuserfromdeleted.
if (!$dbman->field_exists($table, $field1)) {
$dbman->add_field($table, $field1);
}
// Conditionally launch add field timeusertodeleted.
if (!$dbman->field_exists($table, $field2)) {
$dbman->add_field($table, $field2);
}
// Conditionally launch drop index useridfromto.
if ($dbman->index_exists($table, $oldindex)) {
$dbman->drop_index($table, $oldindex);
}
// Conditionally launch add index useridfromtodeleted.
if (!$dbman->index_exists($table, $newindex)) {
$dbman->add_index($table, $newindex);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2015090200.00);
}
return true;
}
+39
View File
@@ -57,6 +57,11 @@ $addcontact = optional_param('addcontact', 0, PARAM_INT); // adding a co
$removecontact = optional_param('removecontact', 0, PARAM_INT); // removing a contact
$blockcontact = optional_param('blockcontact', 0, PARAM_INT); // blocking a contact
$unblockcontact = optional_param('unblockcontact', 0, PARAM_INT); // unblocking a contact
$deletemessageid = optional_param('deletemessageid', 0, PARAM_INT);
$deletemessageconfirm = optional_param('deletemessageconfirm', 0, PARAM_BOOL);
if ($deletemessageid) {
$deletemessagetype = required_param('deletemessagetype', PARAM_ALPHAEXT);
}
//for search
$advancedsearch = optional_param('advanced', 0, PARAM_INT);
@@ -135,6 +140,17 @@ if (!empty($user2->id) && $user2realuser && ($user2->id != $USER->id)) {
$PAGE->navigation->extend_for_user($user2);
}
$strmessages = get_string('messages', 'message');
if ($user2realuser) {
$user2fullname = fullname($user2);
$PAGE->set_title("$strmessages: $user2fullname");
$PAGE->set_heading("$strmessages: $user2fullname");
} else {
$PAGE->set_title("{$SITE->shortname}: $strmessages");
$PAGE->set_heading("{$SITE->shortname}: $strmessages");
}
/// Process any contact maintenance requests there may be
if ($addcontact and confirm_sesskey()) {
message_add_contact($addcontact);
@@ -149,6 +165,29 @@ if ($blockcontact and confirm_sesskey()) {
if ($unblockcontact and confirm_sesskey()) {
message_unblock_contact($unblockcontact);
}
if ($deletemessageid and confirm_sesskey()) {
// Check that the message actually exists.
if ($message = $DB->get_record($deletemessagetype, array('id' => $deletemessageid))) {
// Check that we are allowed to delete this message.
if (message_can_delete_message($message, $user1->id)) {
if (!$deletemessageconfirm) {
$confirmurl = new moodle_url('/message/index.php', array('user1' => $user1->id, 'user2' => $user2->id,
'viewing' => $viewing, 'deletemessageid' => $message->id, 'deletemessagetype' => $deletemessagetype,
'deletemessageconfirm' => 1, 'sesskey' => sesskey()));
$confirmbutton = new single_button($confirmurl, get_string('delete'), 'post');
$strdeletemessage = get_string('deletemessage', 'message');
$PAGE->set_title($strdeletemessage);
echo $OUTPUT->header();
echo $OUTPUT->heading($strdeletemessage);
echo $OUTPUT->confirm(get_string('deletemessageconfirmation', 'message'), $confirmbutton, $url);
echo $OUTPUT->footer();
exit();
}
message_delete_message($message, $user1->id);
}
}
redirect($url);
}
//was a message sent? Do NOT allow someone looking at someone else's messages to send them.
$messageerror = null;
+129 -8
View File
@@ -748,11 +748,18 @@ function message_get_recent_conversations($user, $limitfrom=0, $limitto=100) {
recentmessages.useridfrom,
recentmessages.useridto
FROM {message_read} recentmessages
WHERE (recentmessages.useridfrom = :userid1 OR recentmessages.useridto = :userid2)
WHERE (
(recentmessages.useridfrom = :userid1 AND recentmessages.timeuserfromdeleted = 0) OR
(recentmessages.useridto = :userid2 AND recentmessages.timeusertodeleted = 0)
)
GROUP BY recentmessages.useridfrom, recentmessages.useridto
) recent ON matchedmessage.useridto = recent.useridto
AND matchedmessage.useridfrom = recent.useridfrom
AND matchedmessage.timecreated = recent.timecreated
WHERE (
(matchedmessage.useridfrom = :userid6 AND matchedmessage.timeuserfromdeleted = 0) OR
(matchedmessage.useridto = :userid7 AND matchedmessage.timeusertodeleted = 0)
)
GROUP BY matchedmessage.useridto, matchedmessage.useridfrom
) messagesubset ON messagesubset.messageid = message.id
JOIN {user} otheruser ON (message.useridfrom = :userid4 AND message.useridto = otheruser.id)
@@ -766,6 +773,8 @@ function message_get_recent_conversations($user, $limitfrom=0, $limitto=100) {
'userid3' => $user->id,
'userid4' => $user->id,
'userid5' => $user->id,
'userid6' => $user->id,
'userid7' => $user->id
);
$read = $DB->get_records_sql($sql, $params, $limitfrom, $limitto);
@@ -1136,6 +1145,78 @@ function message_block_contact($contactid) {
return message_add_contact($contactid, 1);
}
/**
* Checks if a user can delete a message.
*
* @param stdClass $message the message to delete
* @param string $userid the user id of who we want to delete the message for (this may be done by the admin
* but will still seem as if it was by the user)
* @return bool Returns true if a user can delete the message, false otherwise.
*/
function message_can_delete_message($message, $userid) {
global $USER;
if ($message->useridfrom == $userid) {
$userdeleting = 'useridfrom';
} else if ($message->useridto == $userid) {
$userdeleting = 'useridto';
} else {
return false;
}
$systemcontext = context_system::instance();
// Let's check if the user is allowed to delete this message.
if (has_capability('moodle/site:deleteanymessage', $systemcontext) ||
((has_capability('moodle/site:deleteownmessage', $systemcontext) &&
$USER->id == $message->$userdeleting))) {
return true;
}
return false;
}
/**
* Deletes a message.
*
* This function does not verify any permissions.
*
* @param stdClass $message the message to delete
* @param string $userid the user id of who we want to delete the message for (this may be done by the admin
* but will still seem as if it was by the user)
* @return bool
*/
function message_delete_message($message, $userid) {
global $DB;
// The column we want to alter.
if ($message->useridfrom == $userid) {
$coltimedeleted = 'timeuserfromdeleted';
} else if ($message->useridto == $userid) {
$coltimedeleted = 'timeusertodeleted';
} else {
return false;
}
// Don't update it if it's already been deleted.
if ($message->$coltimedeleted > 0) {
return false;
}
// Get the table we want to update.
if (isset($message->timeread)) {
$messagetable = 'message_read';
} else {
$messagetable = 'message';
}
// Mark the message as deleted.
$updatemessage = new stdClass();
$updatemessage->id = $message->id;
$updatemessage->$coltimedeleted = time();
return $DB->update_record($messagetable, $updatemessage);
}
/**
* Load a user's contact record
*
@@ -1791,6 +1872,18 @@ function message_search($searchterms, $fromme=true, $tome=true, $courseid='none'
// b. Messages to user
// c. Messages to and from user
if ($fromme && $tome) {
$searchcond .= " AND ((useridto = :useridto AND timeusertodeleted = 0) OR
(useridfrom = :useridfrom AND timeuserfromdeleted = 0))";
$params['useridto'] = $userid;
$params['useridfrom'] = $userid;
} else if ($fromme) {
$searchcond .= " AND (useridfrom = :useridfrom AND timeuserfromdeleted = 0)";
$params['useridfrom'] = $userid;
} else if ($tome) {
$searchcond .= " AND (useridto = :useridto AND timeusertodeleted = 0)";
$params['useridto'] = $userid;
}
if ($courseid == SITEID) { // Admin is searching all messages.
$m_read = $DB->get_records_sql("SELECT m.id, m.useridto, m.useridfrom, m.smallmessage, m.fullmessage, m.timecreated
FROM {message_read} m
@@ -1977,16 +2070,16 @@ function message_get_history($user1, $user2, $limitnum=0, $viewingnewmessages=fa
//prevent notifications of your own actions appearing in your own message history
$ownnotificationwhere = ' AND NOT (useridfrom=? AND notification=1)';
if ($messages_read = $DB->get_records_select('message_read', "((useridto = ? AND useridfrom = ?) OR
(useridto = ? AND useridfrom = ?)) $notificationswhere $ownnotificationwhere",
$sql = "((useridto = ? AND useridfrom = ? AND timeusertodeleted = 0) OR
(useridto = ? AND useridfrom = ? AND timeuserfromdeleted = 0))";
if ($messages_read = $DB->get_records_select('message_read', $sql . $notificationswhere . $ownnotificationwhere,
array($user1->id, $user2->id, $user2->id, $user1->id, $user1->id),
"timecreated $sort", '*', 0, $limitnum)) {
foreach ($messages_read as $message) {
$messages[] = $message;
}
}
if ($messages_new = $DB->get_records_select('message', "((useridto = ? AND useridfrom = ?) OR
(useridto = ? AND useridfrom = ?)) $ownnotificationwhere",
if ($messages_new = $DB->get_records_select('message', $sql . $ownnotificationwhere,
array($user1->id, $user2->id, $user2->id, $user1->id, $user1->id),
"timecreated $sort", '*', 0, $limitnum)) {
foreach ($messages_new as $message) {
@@ -2016,7 +2109,13 @@ function message_get_history($user1, $user2, $limitnum=0, $viewingnewmessages=fa
* @param bool $viewingnewmessages are we currently viewing new messages?
*/
function message_print_message_history($user1, $user2 ,$search = '', $messagelimit = 0, $messagehistorylink = false, $viewingnewmessages = false, $showactionlinks = true) {
global $CFG, $OUTPUT;
global $OUTPUT, $PAGE;
$PAGE->requires->yui_module(
array('moodle-core_message-toolbox'),
'M.core_message.toolbox.deletemsg.init',
array(array())
);
echo $OUTPUT->box_start('center', 'message_user_pictures');
echo $OUTPUT->box_start('user');
@@ -2069,7 +2168,9 @@ function message_print_message_history($user1, $user2 ,$search = '', $messagelim
$current->year = '';
$messagedate = get_string('strftimetime');
$blockdate = get_string('strftimedaydate');
$messagenumber = 0;
foreach ($messages as $message) {
$messagenumber++;
if ($message->notification) {
$notificationclass = ' notification';
} else {
@@ -2087,7 +2188,6 @@ function message_print_message_history($user1, $user2 ,$search = '', $messagelim
$tablecontents .= $OUTPUT->heading(userdate($message->timecreated, $blockdate), 4, 'mdl-align');
}
$formatted_message = $side = null;
if ($message->useridfrom == $user1->id) {
$formatted_message = message_format_message($message, $messagedate, $search, 'me');
$side = 'left';
@@ -2095,7 +2195,28 @@ function message_print_message_history($user1, $user2 ,$search = '', $messagelim
$formatted_message = message_format_message($message, $messagedate, $search, 'other');
$side = 'right';
}
$tablecontents .= html_writer::tag('div', $formatted_message, array('class' => "mdl-left $side $notificationclass"));
// Check if it is a read message or not.
if (isset($message->timeread)) {
$type = 'message_read';
} else {
$type = 'message';
}
if (message_can_delete_message($message, $user1->id)) {
$usergroup = optional_param('usergroup', MESSAGE_VIEW_UNREAD_MESSAGES, PARAM_ALPHANUMEXT);
$viewing = optional_param('viewing', $usergroup, PARAM_ALPHANUMEXT);
$deleteurl = new moodle_url('/message/index.php', array('user1' => $user1->id, 'user2' => $user2->id,
'viewing' => $viewing, 'deletemessageid' => $message->id, 'deletemessagetype' => $type,
'sesskey' => sesskey()));
$deleteicon = $OUTPUT->action_icon($deleteurl, new pix_icon('t/delete', get_string('delete')));
$deleteicon = html_writer::tag('div', $deleteicon, array('class' => 'deleteicon accesshide'));
$formatted_message .= $deleteicon;
}
$tablecontents .= html_writer::tag('div', $formatted_message, array('class' => "mdl-left messagecontent
$side $notificationclass", 'id' => 'message_' . $messagenumber));
}
echo html_writer::nonempty_tag('div', $tablecontents, array('class' => 'mdl-left messagehistory'));
+124
View File
@@ -0,0 +1,124 @@
@core @core_message
Feature: Check that messages can be deleted
In order to check a user can delete a message
As a user
I can delete a message
Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| user1 | User | 1 | user1@asd.com |
| user2 | User | 2 | user2@asd.com |
And I log in as "admin"
And I set the following administration settings values:
| forceloginforprofiles | 0 |
And I log out
@javascript
Scenario: Test basic functionality of deleting a message
# Send two messages from User 1 to User 2.
And I log in as "user1"
And I send "Hey bud, what's happening?" message to "User 2" user
And I set the field with xpath "//textarea[@id='id_message']" to "Whoops, forgot to mention that I drank all your beers. Lol."
And I press "Send message"
# Confirm that there is a delete link next to each message.
And "Delete" "link" should exist in the "#message_1" "css_element"
And "Delete" "link" should exist in the "#message_2" "css_element"
# Confirm that there is a confirmation box before deleting, and that when we cancel the messages remain.
And I click on "#message_2" "css_element"
And I click on "Delete" "link" in the "#message_2" "css_element"
And I press "Cancel"
And I should see "Hey bud, what's happening?"
And I should see "Whoops, forgot to mention that I drank all your beers. Lol."
# Confirm we can delete a message and then can no longer see it.
And I click on "#message_2" "css_element"
And I click on "Delete" "link" in the "#message_2" "css_element"
And I press "Delete"
And I should see "Hey bud, what's happening?"
And I should not see "Whoops, forgot to mention that I drank all your beers. Lol."
# Check that when we do a search for the keywords in the message we deleted nothing is returned.
And I follow "Messages" in the user menu
And I set the field "Search people and messages" to "beers"
And I press "Search people and messages"
And I should see "Messages found: 0"
# Check that we can still search the message that we did not delete.
And I follow "Messages" in the user menu
And I set the field "Search people and messages" to "bud"
And I press "Search people and messages"
And I should see "Messages found: 1"
# Check that the message we deleted does not show up on the recent conversation.
And I set the field "Message navigation:" to "Recent conversations"
And I should see "Hey bud, what's happening?"
And I log out
# Log in as User 2 and send two replies.
And I log in as "user2"
And I follow "Messages" in the user menu
And I follow "User 1 (2)"
And I set the field with xpath "//textarea[@id='id_message']" to "Not much brah, just writing a behat test and communicating to myself."
And I press "Send message"
And I set the field with xpath "//textarea[@id='id_message']" to "Oh man, I was looking forward to those tonight!"
And I press "Send message"
# Confirm that we can see all messages.
And I should see "Hey bud, what's happening?"
And I should see "Whoops, forgot to mention that I drank all your beers. Lol."
And I should see "Not much brah, just writing a behat test and communicating to myself."
And I should see "Oh man, I was looking forward to those tonight!"
# Confirm that there is a delete link next to each message.
And "Delete" "link" should exist in the "#message_1" "css_element"
And "Delete" "link" should exist in the "#message_2" "css_element"
And "Delete" "link" should exist in the "#message_3" "css_element"
And "Delete" "link" should exist in the "#message_4" "css_element"
# Now, delete one of the messages that User 1 sent and one by User 2.
And I click on "#message_1" "css_element"
And I click on "Delete" "link" in the "#message_1" "css_element"
And I press "Delete"
And I click on "#message_2" "css_element"
And I click on "Delete" "link" in the "#message_2" "css_element"
And I press "Delete"
# Confirm that the messages are no longer listed.
And I should not see "Hey bud, what's happening?"
And I should see "Whoops, forgot to mention that I drank all your beers. Lol."
And I should not see "Not much brah, just writing a behat test and communicating to myself."
And I should see "Oh man, I was looking forward to those tonight!"
# Check that when we do a search for the keywords in the messages we deleted nothing is returned.
And I follow "Messages" in the user menu
And I set the field "Search people and messages" to "bud"
And I press "Search people and messages"
And I should see "Messages found: 0"
And I set the field "Search people and messages" to "brah"
And I press "Search people and messages"
And I should see "Messages found: 0"
# Check that we can still search the message that we did not delete.
And I follow "Messages" in the user menu
And I set the field "Search people and messages" to "Whoops"
And I press "Search people and messages"
And I should see "Messages found: 1"
And I set the field "Search people and messages" to "tonight"
And I press "Search people and messages"
And I should see "Messages found: 1"
# Check that the messages we deleted do not show up on the recent conversation.
And I set the field "Message navigation:" to "Recent conversations"
And I should see "Oh man, I was looking forward to those tonight!"
And I log out
@javascript
Scenario: Check that we can prevent some users from deleting messages
# Prevent the ability to delete messages.
Given I log in as "admin"
And I set the following system permissions of "Authenticated user" role:
| capability | permission |
| moodle/site:deleteownmessage | Prevent |
# Send a message from the admin to User 1
And I send "Hey there, this is the all-powerful administrator. Obey my commands." message to "User 1" user
# Check the admin is still able to delete messages.
And I click on "#message_1" "css_element"
And I click on "Delete" "link" in the "#message_1" "css_element"
And I press "Delete"
And I should not see "Hey there, this is the all-powerful administrator. Obey my commands."
And I log out
# Check that User 1 is unable to delete the message the admin sent.
And I log in as "user1"
And I follow "Messages" in the user menu
And I follow "Admin User (1)"
And I should see "Hey there, this is the all-powerful administrator. Obey my commands."
And "Delete" "link" should not exist in the "#message_1" "css_element"
@@ -0,0 +1,118 @@
YUI.add('moodle-core_message-toolbox', function (Y, NAME) {
// 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/>.
/**
* JS used when deleting messages.
*
* @module moodle-core_message-toolbox
* @package core_message
* @copyright 2015 Mark Nelson <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
var CSS = {
ACCESSHIDE: 'accesshide',
MESSAGEACTIVE: 'messageactive'
};
var SELECTORS = {
DELETEICON: '.deleteicon',
MESSAGEACTIVE: '.messageactive',
MESSAGEHISTORY: '.messagehistory',
MESSAGES: '.messagecontent'
};
M.core_message = M.core_message || {};
M.core_message.toolbox = M.core_message.toolbox || {};
/**
* This class contains the JS related to deleting messages.
*
* @class M.core_message.toolbox.deletemsg
* @constructor
*/
M.core_message.toolbox.deletemsg = {
/**
* The area the messages are contained.
*
* @property messagearea
*/
messagearea: null,
/**
* Initializer.
*
* Sets up event listeners which 'activate' and 'deactivate' a message.
*
* @method init
*/
init: function() {
this.messagearea = Y.one(SELECTORS.MESSAGEHISTORY);
// Set the events.
this.messagearea.delegate('hover', this.over, this.out, SELECTORS.MESSAGES);
this.messagearea.delegate('click', this.click, SELECTORS.MESSAGES, this);
},
/**
* Handles when a mouse hovers over a message.
*
* @private
* @params {EventFacade} e
* @method over
*/
over: function(e) {
// 'Activate' the message area we hovered on.
e.currentTarget.addClass(CSS.MESSAGEACTIVE);
e.currentTarget.one(SELECTORS.DELETEICON).removeClass(CSS.ACCESSHIDE);
},
/**
* Handles when a mouse hovers off a message.
*
* @private
* @params {EventFacade} e
* @method out
*/
out: function(e) {
// 'Deactivate' the message area we hovered off.
e.currentTarget.removeClass(CSS.MESSAGEACTIVE);
e.currentTarget.one(SELECTORS.DELETEICON).addClass(CSS.ACCESSHIDE);
},
/**
* Handles when a mouse clicks on a message.
*
* @private
* @params {EventFacade} e
* @method click
*/
click: function(e) {
// 'Deactivate' the currently active message (if there is one).
var activemessage = this.messagearea.one(SELECTORS.MESSAGEACTIVE);
if (activemessage) {
activemessage.removeClass(CSS.MESSAGEACTIVE);
activemessage.one(SELECTORS.DELETEICON).addClass(CSS.ACCESSHIDE);
}
// 'Activate' the message area we clicked on.
e.currentTarget.addClass(CSS.MESSAGEACTIVE);
e.currentTarget.one(SELECTORS.DELETEICON).removeClass(CSS.ACCESSHIDE);
}
};
}, '@VERSION@');
@@ -0,0 +1 @@
YUI.add("moodle-core_message-toolbox",function(e,t){var n={ACCESSHIDE:"accesshide",MESSAGEACTIVE:"messageactive"},r={DELETEICON:".deleteicon",MESSAGEACTIVE:".messageactive",MESSAGEHISTORY:".messagehistory",MESSAGES:".messagecontent"};M.core_message=M.core_message||{},M.core_message.toolbox=M.core_message.toolbox||{},M.core_message.toolbox.deletemsg={messagearea:null,init:function(){this.messagearea=e.one(r.MESSAGEHISTORY),this.messagearea.delegate("hover",this.over,this.out,r.MESSAGES),this.messagearea.delegate("click",this.click,r.MESSAGES,this)},over:function(e){e.currentTarget.addClass(n.MESSAGEACTIVE),e.currentTarget.one(r.DELETEICON).removeClass(n.ACCESSHIDE)},out:function(e){e.currentTarget.removeClass(n.MESSAGEACTIVE),e.currentTarget.one(r.DELETEICON).addClass(n.ACCESSHIDE)},click:function(e){var t=this.messagearea.one(r.MESSAGEACTIVE);t&&(t.removeClass(n.MESSAGEACTIVE),t.one(r.DELETEICON).addClass(n.ACCESSHIDE)),e.currentTarget.addClass(n.MESSAGEACTIVE),e.currentTarget.one(r.DELETEICON).removeClass(n.ACCESSHIDE)}}},"@VERSION@");
@@ -0,0 +1,118 @@
YUI.add('moodle-core_message-toolbox', function (Y, NAME) {
// 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/>.
/**
* JS used when deleting messages.
*
* @module moodle-core_message-toolbox
* @package core_message
* @copyright 2015 Mark Nelson <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
var CSS = {
ACCESSHIDE: 'accesshide',
MESSAGEACTIVE: 'messageactive'
};
var SELECTORS = {
DELETEICON: '.deleteicon',
MESSAGEACTIVE: '.messageactive',
MESSAGEHISTORY: '.messagehistory',
MESSAGES: '.messagecontent'
};
M.core_message = M.core_message || {};
M.core_message.toolbox = M.core_message.toolbox || {};
/**
* This class contains the JS related to deleting messages.
*
* @class M.core_message.toolbox.deletemsg
* @constructor
*/
M.core_message.toolbox.deletemsg = {
/**
* The area the messages are contained.
*
* @property messagearea
*/
messagearea: null,
/**
* Initializer.
*
* Sets up event listeners which 'activate' and 'deactivate' a message.
*
* @method init
*/
init: function() {
this.messagearea = Y.one(SELECTORS.MESSAGEHISTORY);
// Set the events.
this.messagearea.delegate('hover', this.over, this.out, SELECTORS.MESSAGES);
this.messagearea.delegate('click', this.click, SELECTORS.MESSAGES, this);
},
/**
* Handles when a mouse hovers over a message.
*
* @private
* @params {EventFacade} e
* @method over
*/
over: function(e) {
// 'Activate' the message area we hovered on.
e.currentTarget.addClass(CSS.MESSAGEACTIVE);
e.currentTarget.one(SELECTORS.DELETEICON).removeClass(CSS.ACCESSHIDE);
},
/**
* Handles when a mouse hovers off a message.
*
* @private
* @params {EventFacade} e
* @method out
*/
out: function(e) {
// 'Deactivate' the message area we hovered off.
e.currentTarget.removeClass(CSS.MESSAGEACTIVE);
e.currentTarget.one(SELECTORS.DELETEICON).addClass(CSS.ACCESSHIDE);
},
/**
* Handles when a mouse clicks on a message.
*
* @private
* @params {EventFacade} e
* @method click
*/
click: function(e) {
// 'Deactivate' the currently active message (if there is one).
var activemessage = this.messagearea.one(SELECTORS.MESSAGEACTIVE);
if (activemessage) {
activemessage.removeClass(CSS.MESSAGEACTIVE);
activemessage.one(SELECTORS.DELETEICON).addClass(CSS.ACCESSHIDE);
}
// 'Activate' the message area we clicked on.
e.currentTarget.addClass(CSS.MESSAGEACTIVE);
e.currentTarget.one(SELECTORS.DELETEICON).removeClass(CSS.ACCESSHIDE);
}
};
}, '@VERSION@');
+10
View File
@@ -0,0 +1,10 @@
{
"name": "moodle-core_message-toolbox",
"builds": {
"moodle-core_message-toolbox": {
"jsfiles": [
"delete.js"
]
}
}
}
+113
View File
@@ -0,0 +1,113 @@
// 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/>.
/**
* JS used when deleting messages.
*
* @module moodle-core_message-toolbox
* @package core_message
* @copyright 2015 Mark Nelson <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
var CSS = {
ACCESSHIDE: 'accesshide',
MESSAGEACTIVE: 'messageactive'
};
var SELECTORS = {
DELETEICON: '.deleteicon',
MESSAGEACTIVE: '.messageactive',
MESSAGEHISTORY: '.messagehistory',
MESSAGES: '.messagecontent'
};
M.core_message = M.core_message || {};
M.core_message.toolbox = M.core_message.toolbox || {};
/**
* This class contains the JS related to deleting messages.
*
* @class M.core_message.toolbox.deletemsg
* @constructor
*/
M.core_message.toolbox.deletemsg = {
/**
* The area the messages are contained.
*
* @property messagearea
*/
messagearea: null,
/**
* Initializer.
*
* Sets up event listeners which 'activate' and 'deactivate' a message.
*
* @method init
*/
init: function() {
this.messagearea = Y.one(SELECTORS.MESSAGEHISTORY);
// Set the events.
this.messagearea.delegate('hover', this.over, this.out, SELECTORS.MESSAGES);
this.messagearea.delegate('click', this.click, SELECTORS.MESSAGES, this);
},
/**
* Handles when a mouse hovers over a message.
*
* @private
* @params {EventFacade} e
* @method over
*/
over: function(e) {
// 'Activate' the message area we hovered on.
e.currentTarget.addClass(CSS.MESSAGEACTIVE);
e.currentTarget.one(SELECTORS.DELETEICON).removeClass(CSS.ACCESSHIDE);
},
/**
* Handles when a mouse hovers off a message.
*
* @private
* @params {EventFacade} e
* @method out
*/
out: function(e) {
// 'Deactivate' the message area we hovered off.
e.currentTarget.removeClass(CSS.MESSAGEACTIVE);
e.currentTarget.one(SELECTORS.DELETEICON).addClass(CSS.ACCESSHIDE);
},
/**
* Handles when a mouse clicks on a message.
*
* @private
* @params {EventFacade} e
* @method click
*/
click: function(e) {
// 'Deactivate' the currently active message (if there is one).
var activemessage = this.messagearea.one(SELECTORS.MESSAGEACTIVE);
if (activemessage) {
activemessage.removeClass(CSS.MESSAGEACTIVE);
activemessage.one(SELECTORS.DELETEICON).addClass(CSS.ACCESSHIDE);
}
// 'Activate' the message area we clicked on.
e.currentTarget.addClass(CSS.MESSAGEACTIVE);
e.currentTarget.one(SELECTORS.DELETEICON).removeClass(CSS.ACCESSHIDE);
}
};
@@ -0,0 +1,8 @@
{
"moodle-core_message-deletemessage": {
"requires": [
"node",
"event"
]
}
}
+29 -2
View File
@@ -119,11 +119,38 @@ table.message .searchresults td {padding:5px;}
.message .messagearea .messagehistory .heading,
.message .messagearea .messagehistory h3 {width:100%;clear:both;}
.message .messagearea .messagehistory .left {padding-bottom:10px;width:50%;float:left;clear:both;}
.message .messagearea .messagehistory .left {position:relative;margin-bottom:10px;width:50%;float:left;clear:both;}
.dir-rtl .message .messagearea .messagehistory .left { float: right; }
.message .messagearea .messagehistory .right {padding-bottom:10px;width:50%;float:right;clear:both;}
.message .messagearea .messagehistory .right {position:relative;margin-bottom:10px;width:50%;float:right;clear:both;}
.dir-rtl .message .messagearea .messagehistory .right { float:left; }
.dir-ltr .message .messagearea .messagehistory .message {
margin-right: 20px;
}
.dir-ltr .message .messagearea .messagehistory .right .message {
margin-left: 20px;
}
.dir-rtl .message .messagearea .messagehistory .message {
margin-left: 20px;
}
.dir-rtl .message .messagearea .messagehistory .right .message {
margin-right: 20px;
}
.message .messagearea .messagehistory .messageactive {
background-color: #F5F5F5;
}
.message .messagearea .messagehistory .messagecontent .deleteicon {
width: 20px;
position: absolute;
top: -2px;
}
.dir-ltr .message .messagearea .messagehistory .messagecontent .deleteicon {
right: 0;
}
.dir-rtl .message .messagearea .messagehistory .messagecontent .deleteicon {
left: 0;
}
.message .messagearea .messagehistory .notification {padding:10px;background-color:#EEEEEE;margin-top:5px;}
.message .messagearea .messagesend {padding-top:20px;clear:both;}
.message .messagearea .messagesend .messagesendbox {width:100%}
+32 -4
View File
@@ -236,22 +236,24 @@ table.message .searchresults td {
clear: both;
}
.message .messagearea .messagehistory .left {
padding-bottom: 10px;
margin-bottom: 10px;
width: 50%;
float: left;
position: relative;
clear: both;
}
.dir-rtl .message .messagearea .messagehistory .left {
float:right;
float: right;
}
.message .messagearea .messagehistory .right {
padding-bottom: 10px;
margin-bottom: 10px;
width: 50%;
float: right;
position: relative;
clear: both;
}
.dir-rtl .message .messagearea .messagehistory .right {
float:left;
float: left;
}
.message .messagearea .messagehistory .notification {
.well;
@@ -259,6 +261,32 @@ table.message .searchresults td {
margin-bottom: 0;
margin-top: 5px;
}
.dir-ltr .message .messagearea .messagehistory .message {
margin-right: 20px;
}
.dir-ltr .message .messagearea .messagehistory .right .message {
margin-left: 20px;
}
.dir-rtl .message .messagearea .messagehistory .message {
margin-left: 20px;
}
.dir-rtl .message .messagearea .messagehistory .right .message {
margin-right: 20px;
}
.message .messagearea .messagehistory .messageactive {
background-color: @tableBackgroundHover;
}
.message .messagearea .messagehistory .messagecontent .deleteicon {
width: 20px;
position: absolute;
top: -2px;
}
.dir-ltr .message .messagearea .messagehistory .messagecontent .deleteicon {
right: 0;
}
.dir-rtl .message .messagearea .messagehistory .messagecontent .deleteicon {
left: 0;
}
.message .messagearea .messagesend {
padding-top: 20px;
clear: both;
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2015090100.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2015090200.00; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.