Advertisement
Guest User

Untitled

a guest
Mar 12th, 2016
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var timeout = null;
  2. var escape_event = true;
  3.  
  4. function insertLinks() {
  5.     var grid = $('#task-grid');
  6.     if (grid.length > 0) {
  7.         escape_event = true;
  8.         grid.find('span.close-btn').remove(); //remove old buttons
  9.         grid.find('div.items > .task-item > div.row').each(function() {
  10.             $(this).children('div:first').append('<span class="close-btn"><a href="#"><i class="glyphicon glyphicon-ok"></i></a></span>');     
  11.         });
  12.     }
  13.     escape_event = false;
  14. }
  15.  
  16. $('body').on('click', 'span.close-btn a', function (e) {
  17.     e.preventDefault();
  18.     var link = $(this).parents('.task-item').find('div.row > div a').eq(0);
  19.     var res = link.attr('href').match(/.+\/(\d+)/);
  20.     var url = "/ww/task/" + res[1] + "/comment";
  21.     var data = new FormData();
  22.     data.append('action_type', "close");
  23.     data.append('Comment[content]', "");
  24.     data.append('Comment[attachments]', "");
  25.     $.ajax({
  26.         "url": url,
  27.         "type": "POST",
  28.         "contentType": false,
  29.         "processData": false,
  30.         "data": data,
  31.         "success": function(e) {
  32.             refreshPage();
  33.         },
  34.     });
  35. });
  36.  
  37. function refreshPage() {
  38.     if ($('.pagination-wrapper').length > 0) {
  39.         $('.pagination-wrapper .active a').trigger('click');
  40.     } else {
  41.         $('.search-form form input.btn').trigger('click');
  42.     }
  43. }
  44.  
  45. document.addEventListener("DOMSubtreeModified", function() {
  46.     if (!escape_event) {
  47.         if(timeout) clearTimeout(timeout);
  48.         timeout = setTimeout(insertLinks, 500);
  49.     }
  50. }, false);
  51.  
  52. insertLinks();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement