The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

[Tutorial] Automatic message when moving topic

2 posters

Go down

[Tutorial] Automatic message when moving topic Empty [Tutorial] Automatic message when moving topic

Post by Daemon February 24th 2017, 5:36 am

The code allows you to add an automated message when you move the topic

Image:
[Tutorial] Automatic message when moving topic 12310
[Tutorial] Automatic message when moving topic 12345610

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
Daemon
Forumember

Posts : 104
Reputation : 90
Language : Português

HERMAN® likes this post

Back to top Go down

[Tutorial] Automatic message when moving topic Empty Re: [Tutorial] Automatic message when moving topic

Post by hamesashek February 28th 2017, 10:17 pm

Fabulous
hamesashek
hamesashek
Forumember

Male Posts : 111
Reputation : 1
Language : hamesashek

http://bestk.forumegypt.net

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum