Skip to content

Commit

Permalink
! close #1530
Browse files Browse the repository at this point in the history
  • Loading branch information
Spuds committed Apr 30, 2024
1 parent 614354d commit 7f11381
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 44 deletions.
2 changes: 1 addition & 1 deletion sources/ElkArte/Controller/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -1616,7 +1616,7 @@ public function action_jsmodify()
obExit(false);
}

checkSession('get');
checkSession('request');

$row = getTopicInfoByMsg($topic, empty($_REQUEST['msg']) ? 0 : (int) $_REQUEST['msg']);

Expand Down
8 changes: 4 additions & 4 deletions themes/default/Display.template.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function template_messages_informations_above()
<main id="forumposts">
<header class="category_header">
<i class="hdicon ', $context['class'], '"></i>
', $txt['topic'], ': ', $context['subject'], '&nbsp;<span class="views_text">(', $context['num_views_text'], ')</span>
<span id="topic_subject">', $context['subject'], '</span>&nbsp;<span class="views_text">(', $context['num_views_text'], ')</span>
<span class="nextlinks">',
empty($context['links']['go_prev']) ? '' : '<a href="' . $context['links']['go_prev'] . '">' . $txt['previous_next_back'] . '</a>',
empty($context['links']['go_next']) ? '' : ' - <a href="' . $context['links']['go_next'] . '">' . $txt['previous_next_forward'] . '</a>',
Expand Down Expand Up @@ -97,7 +97,7 @@ function template_messages_informations_above()
}

echo '
<form id="quickModForm" action="', $scripturl, '?action=quickmod2;topic=', $context['current_topic'], '.', $context['start'], '" method="post" accept-charset="UTF-8" name="quickModForm" onsubmit="return oQuickModify.bInEditMode ? oQuickModify.modifySave(\'' . $context['session_id'] . "', '" . $context['session_var'] . '\') : false">';
<form id="quickModForm" action="', $scripturl, '?action=quickmod2;topic=', $context['current_topic'], '.', $context['start'], '" method="post" accept-charset="UTF-8" name="quickModForm" onsubmit="return oQuickModify.bInEditMode ? oQuickModify.modifySave() : false">';
}

/**
Expand Down Expand Up @@ -541,10 +541,10 @@ function template_quickreply_below()
<div id="error_box" class="errorbox hide"></div>
<textarea class="editor" name="message" rows="12" tabindex="' . ($context['tabindex']++) . '">%body%</textarea><br />
<div class="submitbutton">
<input type="hidden" name="\' + elk_session_var + \'" value="\' + elk_session_id + \'" />
<input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '" />
<input type="hidden" name="topic" value="' . $context['current_topic'] . '" />
<input type="hidden" name="msg" value="%msg_id%" />
<input type="submit" name="post" value="' . $txt['save'] . '" tabindex="' . ($context['tabindex']++) . '" onclick="return oQuickModify.modifySave(\'' . $context['session_id'] . "', '" . $context['session_var'] . '\');" accesskey="s" />
<input type="submit" name="post" value="' . $txt['save'] . '" tabindex="' . ($context['tabindex']++) . '" onclick="return oQuickModify.modifySave();" accesskey="s" />
<input type="submit" name="cancel" value="' . $txt['modify_cancel'] . '" tabindex="' . ($context['tabindex']++) . '" onclick="return oQuickModify.modifyCancel();" />
</div>
</div>') . ',
Expand Down
77 changes: 38 additions & 39 deletions themes/default/scripts/topic.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,10 @@ QuickModifyTopic.prototype.modify_topic_save = function(cur_session_id, cur_sess
return true;
}

let x = [];
x[x.length] = 'subject=' + document.forms.quickModForm.subject.value.replace(/&#/g, '&#38;#').php_urlencode();
x[x.length] = 'topic=' + parseInt(document.forms.quickModForm.elements.topic.value);
x[x.length] = 'msg=' + parseInt(document.forms.quickModForm.elements.msg.value);

// Send in the call to save the updated topic subject
ajax_indicator(true);
sendXMLDocument.call(this, elk_prepareScriptUrl(elk_scripturl) + 'action=jsmodify;topic=' + parseInt(document.forms.quickModForm.elements.topic.value) + ';' + cur_session_var + '=' + cur_session_id + ';api=xml', x.join('&'), this.modify_topic_done);
let formData = serialize(document.forms.quickModForm); // includes sessionID
sendXMLDocument.call(this, elk_prepareScriptUrl(elk_scripturl) + 'action=jsmodify;api=xml', formData, this.modify_topic_done);

return false;
};
Expand Down Expand Up @@ -538,10 +534,9 @@ QuickModify.prototype.modifyCancel = function() {
};

// The function called after a user wants to save his precious message.
QuickModify.prototype.modifySave = function(sSessionId, sSessionVar) {
QuickModify.prototype.modifySave = function() {
let i = 0,
x = [],
uIds = [];
formData = '';

// We cannot save if we weren't in edit mode.
if (!this.bInEditMode)
Expand All @@ -567,27 +562,10 @@ QuickModify.prototype.modifySave = function(sSessionId, sSessionVar) {
}
}

let oInputs = document.forms.quickModForm.getElementsByTagName('input');
for (i = 0; i < oInputs.length; i++)
{
if (oInputs[i].name === 'uid[]')
{
uIds.push('uid[' + i + ']=' + parseInt(oInputs[i].value));
}
}

x[x.length] = 'subject=' + document.forms.quickModForm.subject.value.replace(/&#/g, '&#38;#').php_urlencode();
x[x.length] = 'message=' + document.forms.quickModForm.message.value.replace(/&#/g, '&#38;#').php_urlencode();
x[x.length] = 'topic=' + parseInt(document.forms.quickModForm.elements.topic.value);
x[x.length] = 'msg=' + parseInt(document.forms.quickModForm.elements.msg.value);
if (uIds.length > 0)
{
x[x.length] = uIds.join('&');
}

// Send in the XMLhttp request and let's hope for the best.
ajax_indicator(true);
sendXMLDocument.call(this, elk_prepareScriptUrl(this.opt.sScriptUrl) + 'action=jsmodify;topic=' + this.opt.iTopicId + ';' + elk_session_var + '=' + elk_session_id + ';api=xml', x.join('&'), this.onModifyDone);
formData = serialize(document.forms.quickModForm); // uses form sessionID
sendXMLDocument.call(this, elk_prepareScriptUrl(this.opt.sScriptUrl) + 'action=jsmodify;;api=xml', formData, this.onModifyDone);

return false;
};
Expand Down Expand Up @@ -617,32 +595,53 @@ QuickModify.prototype.onModifyDone = function(XMLDoc) {
}

let message = XMLDoc.getElementsByTagName('elk')[0].getElementsByTagName('message')[0],
body = message.getElementsByTagName('body')[0],
error = message.getElementsByTagName('error')[0];
oBody = message.getElementsByTagName('body')[0],
oSubject = message.getElementsByTagName('subject')[0],
oModified = message.getElementsByTagName('modified')[0],
oError = message.getElementsByTagName('error')[0];

document.forms.quickModForm.message.classList.remove('border_error');
document.forms.quickModForm.subject.classList.remove('border_error');

if (body)
if (oBody)
{
// Show new body.
let bodyText = '';
for (let i = 0; i < body.childNodes.length; i++)
for (let i = 0; i < oBody.childNodes.length; i++)
{
bodyText += body.childNodes[i].nodeValue;
bodyText += oBody.childNodes[i].nodeValue;
}

this.sMessageBuffer = this.opt.sTemplateBodyNormal.replace(/%body%/, bodyText);
this.oCurMessageDiv.innerHTML = this.sMessageBuffer;

// Show new subject div, update in case it changed
let oSubject = message.getElementsByTagName('subject')[0],
sSubjectText = oSubject.childNodes[0].nodeValue;
let sSubjectText = oSubject.childNodes[0].nodeValue;

this.sSubjectBuffer = this.opt.sTemplateSubjectNormal.replace(/%subject%/, sSubjectText);
this.oCurSubjectDiv.innerHTML = this.sSubjectBuffer;
this.oCurSubjectDiv.style.display = '';

// If this is the first message, also update the category header.
if (oSubject.getAttribute('is_first') === '1')
{
let subjectHeader = document.getElementById('topic_subject');
if (subjectHeader)
{
subjectHeader.innerHTML = this.sSubjectBuffer;
}
}

// Show this message as 'modified'.
if (this.opt.bShowModify)
{
let modifiedSpan = document.querySelector('#modified_' + this.sCurMessageId.substring(4));
if (modifiedSpan)
{
modifiedSpan.innerHTML = oModified.childNodes[0].nodeValue;
}
}

// Restore the info bar div
this.oCurInfoDiv.innerHTML = this.sInfoBuffer;

Expand Down Expand Up @@ -709,18 +708,18 @@ QuickModify.prototype.onModifyDone = function(XMLDoc) {
prettyPrint();
}
}
else if (error)
else if (oError)
{
oErrordiv = document.getElementById('error_box');
oErrordiv.innerHTML = error.childNodes[0].nodeValue;
oErrordiv.innerHTML = oError.childNodes[0].nodeValue;
oErrordiv.style.display = '';

if (error.getAttribute('in_body') === '1')
if (oError.getAttribute('in_body') === '1')
{
document.forms.quickModForm.message.classList.add('border_error');
}

if (error.getAttribute('in_subject') === '1')
if (oError.getAttribute('in_subject') === '1')
{
document.forms.quickModForm.subject.classList.add('border_error');
}
Expand Down

0 comments on commit 7f11381

Please sign in to comment.