messages MDL-19664 Clean up the messages javascript code
I have cleaned up the message Javascript code, implementing the new PAGE methods and at the same time implemented the new OUTPUT methods
This commit is contained in:
+13
-15
@@ -15,11 +15,11 @@ if (empty($CFG->messaging)) {
|
||||
|
||||
if (has_capability('moodle/site:sendmessage', get_context_instance(CONTEXT_SYSTEM))) {
|
||||
|
||||
$PAGE->set_generaltype('popup');
|
||||
$PAGE->set_title('send');
|
||||
$PAGE->requires->js('message/message.js');
|
||||
|
||||
/// (Don't use print_header, for more speed)
|
||||
/// ehm - we have to use print_header() or else this breaks after any minor change in print_header()!
|
||||
print_header();
|
||||
echo $OUTPUT->header();
|
||||
|
||||
/// Script parameters
|
||||
$userid = required_param('id', PARAM_INT);
|
||||
@@ -34,8 +34,8 @@ if (has_capability('moodle/site:sendmessage', get_context_instance(CONTEXT_SYSTE
|
||||
/// Check that the user is not blocking us!!
|
||||
if ($contact = $DB->get_record('message_contacts', array('userid'=>$user->id, 'contactid'=>$USER->id))) {
|
||||
if ($contact->blocked and !has_capability('moodle/site:readallmessages', get_context_instance(CONTEXT_SYSTEM))) {
|
||||
print_heading(get_string('userisblockingyou', 'message'));
|
||||
print_footer('empty');
|
||||
echo $OUTPUT->heading(get_string('userisblockingyou', 'message'), 1);
|
||||
echo $OUTPUT->footer();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@@ -43,18 +43,18 @@ if (has_capability('moodle/site:sendmessage', get_context_instance(CONTEXT_SYSTE
|
||||
|
||||
if (!empty($userpreferences['message_blocknoncontacts'])) { // User is blocking non-contacts
|
||||
if (empty($contact)) { // We are not a contact!
|
||||
print_heading(get_string('userisblockingyounoncontact', 'message'));
|
||||
print_footer('empty');
|
||||
echo $OUTPUT->heading(get_string('userisblockingyounoncontact', 'message'), 1);
|
||||
echo $OUTPUT->footer();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
if ($message!='' and confirm_sesskey()) { /// Current user has just sent a message
|
||||
|
||||
/// Save it to the database...
|
||||
/// Save it to the database...
|
||||
$messageid = message_post_message($USER, $user, $message, $format, 'direct');
|
||||
|
||||
/// Format the message as HTML
|
||||
/// Format the message as HTML
|
||||
$options = NULL;
|
||||
$options->para = false;
|
||||
$options->newlines = true;
|
||||
@@ -64,10 +64,8 @@ if (has_capability('moodle/site:sendmessage', get_context_instance(CONTEXT_SYSTE
|
||||
$message = '<div class="message me"><span class="author">'.fullname($USER).'</span> '.
|
||||
'<span class="time">['.$time.']</span>: '.
|
||||
'<span class="content">'.$message.'</span></div>';
|
||||
$message = addslashes_js($message); // So Javascript can write it
|
||||
|
||||
/// Then write it to our own message screen immediately
|
||||
$PAGE->requires->js_function_call('parent.messages.document.write', Array($message));
|
||||
//$PAGE->requires->js_function_call('parent.messages.document.write', Array($message));
|
||||
$PAGE->requires->js_function_call('add_message', Array($message));
|
||||
$PAGE->requires->js_function_call('parent.messages.scroll', Array(1,5000000));
|
||||
|
||||
add_to_log(SITEID, 'message', 'write', 'history.php?user1='.$user->id.'&user2='.$USER->id.'#m'.$messageid, $user->id);
|
||||
@@ -93,12 +91,12 @@ if (has_capability('moodle/site:sendmessage', get_context_instance(CONTEXT_SYSTE
|
||||
echo '</div>';
|
||||
echo '</form>';
|
||||
if (!empty($CFG->messagewasjustemailed)) {
|
||||
notify(get_string('mailsent', 'message'), 'notifysuccess');
|
||||
$OUTPUT->notifcation(get_string('mailsent', 'message'), 'notifysuccess');
|
||||
}
|
||||
echo '<div class="noframesjslink"><a target="_parent" href="discussion.php?id='.$userid.'&noframesjs=1">'.get_string('noframesjs', 'message').'</a></div>';
|
||||
|
||||
$PAGE->requires->js_function_call('set_focus', Array('edit-message'));
|
||||
|
||||
print_footer('empty');
|
||||
echo $OUTPUT->footer();
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user