<commit_before>/* Pile - Tag Add */
Mailpile.tag_add = function(tag_add, mids, complete) {
  $.ajax({
	  url			 : Mailpile.api.tag,
	  type		 : 'POST',
	  data     : {
      add: tag_add,
      mid: mids
    },
	  dataType : 'json',
    success  : function(response) {
      if (response.status == 'success') {
       complete(response.result);       
      } else {
        Mailpile.notification(response.status, response.message);
      }
    }
  });
};


Mailpile.tag_add_delete = function(tag_add, tag_del, mids, complete) {
  $.ajax({
	  url			 : Mailpile.api.tag,
	  type		 : 'POST',
	  data     : {
      add: tag_add,
      del: tag_del,
      mid: mids
    },
	  dataType : 'json',
    success  : function(response) {
      if (response.status == 'success') {
        complete(response.result);
      } else {
        Mailpile.notification(response.status, response.message);
      }
    }
  });
};


Mailpile.tag_update = function(tid, setting, value, complete) {

  // Prep Update Value
  var key = 'tags.' + tid + '.' + setting;
  var setting = {};
  setting[key] = value;

  $.ajax({
	  url			 : Mailpile.api.tag_update,
	  type		 : 'POST',
	  data     : setting,
	  dataType : 'json',
    success  : function(response) {
      if (response.status == 'success') {
        complete(response.result);
      } else {
        Mailpile.notification(response.status, response.message);
      }
    }
  });
};


$(document).on('click', '#button-tag-change-icon', function() {

  var icons_html = '';
  $.each(Mailpile.theme.icons, function(key, icon) {
    icons_html += '<li class="modal-tag-icon-option ' + icon + '" data-icon="' + icon + '"></li>';
  });

  var modal_html = $("#modal-tag-icon-picker").html();
  $('#modal-full').html(_.template(modal_html, { icons: icons_html }));
  $('#modal-full').modal({ backdrop: true, keyboard: true, show: true, remote: false });
});


$(document).on('click', '.modal-tag-icon-option', function() {

  var tid  = $('#data-tag-tid').val();
  var old  = $('#data-tag-icon').val();
  var icon = $(this).data('icon');

  Mailpile.tag_update(tid, 'icon', icon, function() {

    // Update Sidebar
    $('#sidebar-tag-' + tid).find('span.sidebar-icon').removeClass(old).addClass(icon);

    // Update Tag Editor
    $('#data-tag-icon').val(icon);
    $('#tag-editor-icon').removeClass().addClass(icon);
    $('#modal-full').modal('hide');
  });
});


$(document).on('click', '#button-tag-change-label-color', function(e) {
  
  var sorted_colors =  _.keys(Mailpile.theme.colors).sort();
  var colors_html = '';
  $.each(sorted_colors, function(key, name) {
    var hex = Mailpile.theme.colors[name];
    colors_html += '<li><a href="#" class="modal-tag-color-option" style="background-color: ' + hex + '" data-name="' + name + '" data-hex="' + hex + '"></a></li>';
  });

  var modal_html = $("#modal-tag-color-picker").html();
  $('#modal-full').html(_.template(modal_html, { colors: colors_html }));
  $('#modal-full').modal({ backdrop: true, keyboard: true, show: true, remote: false });
});


$(document).on('click', '.modal-tag-color-option', function(e) {

  var tid   = $('#data-tag-tid').val();
  var old   = $('#data-tag-label-color').val();
  var name = $(this).data('name');
  var hex = $(this).data('hex');

  Mailpile.tag_update(tid, 'label_color', name, function() {

    // Update Sidebar
    $('#sidebar-tag-' + tid).find('span.sidebar-icon').css('color', hex);

    // Update Tag Editor
    $('#data-tag-label-color').val(name);
    $('#tag-editor-icon').css('color', hex);
    $('#modal-full').modal('hide');
  });
});


/* API - Tag Add */
$(document).on('submit', '#form-tag-add', function(e) {
  e.preventDefault();
  var tag_data = $('#form-tag-add').serialize();
  $.ajax({
    url: Mailpile.api.tag_add,
    type: 'POST',
    data: tag_data,
    dataType : 'json',
    success: function(response) {
      if (response.status === 'success') {
        window.location.href = '/tags/edit.html?only=' + $('#data-tag-add-slug').val();
      } else {
        Mailpile.notification(response.status, response.message);
      }
    }
  });
});


/* Tag - Delete Tag */
$(document).on('click', '#button-tag-delete', function(e) {
  if (confirm('Sure you want to delete this tag?') === true) { 
    Mailpile.API.tags_delete_post({ tag: $('#data-tag-add-slug').val() }, function(response) {
      Mailpile.notification(response.status, response.message, 'redirect', Mailpile.urls.tags);
    }, 'POST');
  }
});

<commit_msg>Fixed Delete Tag redirect and updated to use new JSAPI command. Fixes #581<commit_after>/* Pile - Tag Add */
Mailpile.tag_add = function(tag_add, mids, complete) {
  $.ajax({
	  url			 : Mailpile.api.tag,
	  type		 : 'POST',
	  data     : {
      add: tag_add,
      mid: mids
    },
	  dataType : 'json',
    success  : function(response) {
      if (response.status == 'success') {
       complete(response.result);       
      } else {
        Mailpile.notification(response.status, response.message);
      }
    }
  });
};


Mailpile.tag_add_delete = function(tag_add, tag_del, mids, complete) {
  $.ajax({
	  url			 : Mailpile.api.tag,
	  type		 : 'POST',
	  data     : {
      add: tag_add,
      del: tag_del,
      mid: mids
    },
	  dataType : 'json',
    success  : function(response) {
      if (response.status == 'success') {
        complete(response.result);
      } else {
        Mailpile.notification(response.status, response.message);
      }
    }
  });
};


Mailpile.tag_update = function(tid, setting, value, complete) {

  // Prep Update Value
  var key = 'tags.' + tid + '.' + setting;
  var setting = {};
  setting[key] = value;

  $.ajax({
	  url			 : Mailpile.api.tag_update,
	  type		 : 'POST',
	  data     : setting,
	  dataType : 'json',
    success  : function(response) {
      if (response.status == 'success') {
        complete(response.result);
      } else {
        Mailpile.notification(response.status, response.message);
      }
    }
  });
};


$(document).on('click', '#button-tag-change-icon', function() {

  var icons_html = '';
  $.each(Mailpile.theme.icons, function(key, icon) {
    icons_html += '<li class="modal-tag-icon-option ' + icon + '" data-icon="' + icon + '"></li>';
  });

  var modal_html = $("#modal-tag-icon-picker").html();
  $('#modal-full').html(_.template(modal_html, { icons: icons_html }));
  $('#modal-full').modal({ backdrop: true, keyboard: true, show: true, remote: false });
});


$(document).on('click', '.modal-tag-icon-option', function() {

  var tid  = $('#data-tag-tid').val();
  var old  = $('#data-tag-icon').val();
  var icon = $(this).data('icon');

  Mailpile.tag_update(tid, 'icon', icon, function() {

    // Update Sidebar
    $('#sidebar-tag-' + tid).find('span.sidebar-icon').removeClass(old).addClass(icon);

    // Update Tag Editor
    $('#data-tag-icon').val(icon);
    $('#tag-editor-icon').removeClass().addClass(icon);
    $('#modal-full').modal('hide');
  });
});


$(document).on('click', '#button-tag-change-label-color', function(e) {
  
  var sorted_colors =  _.keys(Mailpile.theme.colors).sort();
  var colors_html = '';
  $.each(sorted_colors, function(key, name) {
    var hex = Mailpile.theme.colors[name];
    colors_html += '<li><a href="#" class="modal-tag-color-option" style="background-color: ' + hex + '" data-name="' + name + '" data-hex="' + hex + '"></a></li>';
  });

  var modal_html = $("#modal-tag-color-picker").html();
  $('#modal-full').html(_.template(modal_html, { colors: colors_html }));
  $('#modal-full').modal({ backdrop: true, keyboard: true, show: true, remote: false });
});


$(document).on('click', '.modal-tag-color-option', function(e) {

  var tid   = $('#data-tag-tid').val();
  var old   = $('#data-tag-label-color').val();
  var name = $(this).data('name');
  var hex = $(this).data('hex');

  Mailpile.tag_update(tid, 'label_color', name, function() {

    // Update Sidebar
    $('#sidebar-tag-' + tid).find('span.sidebar-icon').css('color', hex);

    // Update Tag Editor
    $('#data-tag-label-color').val(name);
    $('#tag-editor-icon').css('color', hex);
    $('#modal-full').modal('hide');
  });
});


/* API - Tag Add */
$(document).on('submit', '#form-tag-add', function(e) {
  e.preventDefault();
  var tag_data = $('#form-tag-add').serialize();
  Mailpile.API.tags_add_post(tag_data, function() {
    window.location.href = '/tags/edit.html?only=' + $('#data-tag-add-slug').val();
  });
});


/* Tag - Delete Tag */
$(document).on('click', '#button-tag-delete', function(e) {
  if (confirm('Sure you want to delete this tag?') === true) { 
    Mailpile.API.tags_delete_post({ tag: $('#data-tag-add-slug').val() }, function(response) {
      window.location.href = '/tags/';
    }, 'POST');
  }
});


{'fraction_non_alphanumeric': 0.21581416638059275, 'fraction_numerical': 0.00034328870580157915, 'mean_word_length': 3.0745920745920747, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6876399', 'n_tokens_mistral': 3009, 'n_tokens_neox': 2902, 'n_words': 541}