[Tutorial] Automatic message when moving topic
2 posters
Page 1 of 1
[Tutorial] Automatic message when moving topic
The code allows you to add an automated message when you move the topic
Image:
All you have to do is create a new JavaScript with investment on every page.
Tested only in PunBB version
Image:
All you have to do is create a new JavaScript with investment on every page.
- Code:
jQuery(function() {
// Functional only if the user is a moderator and is on the page to move the topic
if(_userdata.user_level > 0 && window.location.href.search('mode=move') >= 0) {
// Variables
var forumID = jQuery('[name="f"]').val();
var topicID = jQuery('[name="t"]').val();
var TID = jQuery('a[href*="tid="]').attr('href').split('tid=')[1].split('&')[0];
// When you click the move button
jQuery('input[name="confirm"]').on('click', function(d) {
var verify = jQuery('[name="new_forum"]').val();
// Check if any forum has been selected
if(verify.indexOf('f') >= 0) {
// Confirmation question
var qst = window.confirm("Add a message on the topic informing about this action?");
// If confirmation is accepted
if(qst) {
d.preventDefault();
// Gets certain content from another page (in this case, just the current forum name)
jQuery.get('/modcp?change_version=punbb&mode=move&t=' + topicID + '&tid=' + TID).done(function(local) {
// Captured value
var currentLocal = jQuery('a.nav[href^="/f"]:last', local).text();
var newLocal = jQuery('[name="new_forum"] option:selected').text().split('--').pop();
var autoMsg = '[b]Automatic message[/b]\n\n\nThis topic has been moved from "[u]' + currentLocal + '[/u]" to "[u]' + newLocal + '[/u]".';
// Move topic
jQuery.post('/modcp?tid=' + TID, {
'new_forum': verify,
'mode': 'move',
'f': forumID,
't': topicID,
'confirm': '1'
}).done(function(move) {
// Send message
jQuery.post('/post?t=' + topicID, {
'mode': 'reply',
'message': autoMsg,
'post': '1',
'attach_sig': '1'
}).done(function(send) {
// Redirect to post
location.href = jQuery(send).find('a[href^="/viewtopic"]').attr('href');
}).fail(function() {
alert("There was an error while trying to send the message");
location.href = jQuery(move).find('a[href^="/viewtopic"]').attr('href');
});
}).fail(function() {
alert("An error occurred while trying to move the topic");
location.reload();
});
});
}
} else {
d.preventDefault();
alert("Select a forum");
}
});
}
});
Tested only in PunBB version
Daemon- Forumember
- Posts : 104
Reputation : 91
Language : Português
HERMAN® likes this post
Similar topics
» Automatic bot message
» How to set an automatic welcome message for new user?
» [Tutorial] Add message before the first post
» How do I create an automatic message to new members?
» Automatic rules message in Chatbox?
» How to set an automatic welcome message for new user?
» [Tutorial] Add message before the first post
» How do I create an automatic message to new members?
» Automatic rules message in Chatbox?
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum