The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

[Tutorial] Automatic message when moving topic

View previous topic View next topic Go down

[Tutorial] Automatic message when moving topic

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

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

Posts : 51
Reputation : 29
Language : Português

Back to top Go down

Re: [Tutorial] Automatic message when moving topic

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

Fabulous
avatar
hamesashek
Forumember

Male Posts : 103
Reputation : 1
Language : hamesashek

http://bestk.forumegypt.net

Back to top Go down

View previous topic View next topic Back to top


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