OTRS: adding a new button to move all messages that you want to Spam

It’s a good ideia to use OTRS to manage tickets and have a good Service Desk in your business, but sometimes you a have a lot of bad messages and you need to move them to Spam. It turns into a nightmare on OTRS, ’cause you can only select a single message and move that. I didn’t know about that before a see a guy using it, so I decided to make his life better and I made this little code and think that it can helps you too.
Edit your OTRS file {YOUR_INSTALL_PATH}/Kernel/Output/HTML/Standard/AgentTicketOverviewPreview.dtl and insert the code below after 27th line:

<ul style="float:left;margin:6px 0 0 5px;">
<li>
<a href="javascript:void(0);" id="spam-all" style="display:inline;">Spam All</a>
<script type="text/javascript">
$(document).ready(function(){
  $('#spam-all').click(function() {
     var t = $("input[name='TicketID']:checked").length;

     if( t > 1 ) {
       var d=0,f=0;

       for(i=0;i<t;i++) {
          var msg = $("input[name='TicketID']:checked").eq(i).val();

          $.ajax({
             url: '/index.pl?Action=AgentTicketMove;TicketID='+msg+';DestQueue=Spam',
             type: 'GET',
             error: function() { f++; }
          });
       }

       if(f == 0) {
          alert('All messages moved!');
       } else {
          alert(f+' messages failed');
       }

       location.reload();
     }
  });
});
</script>
</li>
</ul>
Advertisements