<commit_before>$(function () {
  $('.publication-nav').tabs();
  
  var submit_form = function(form,success) {
     var jq = $.post(
         form.attr('action')+".json",
         form.serialize(),
         success
     ).error( function(data) {
         var errors = $.parseJSON(data.responseText);
         var messages = "There were problems saving this edition: ";
         errors = $.map(errors, function(v,k) {
             return k + " " + v.join(", ");
         });
         messages = messages + errors.join("; ") + ".";
         $("<p class=\"flash-alert\">"+messages+"</p>").insertBefore("#wrapper:first");
     });
   }
  
  var saved = false;
  
  $('#save-edition').submit(function () {
      var edition_form = $('form.edition');
      var publication_form = $('form.publication');
      if (! saved) {
          submit_form(publication_form,function() {
              saved = true;
              edition_form.trigger('submit');
          });
      }
      
      return saved;
  });
  
  $('input.title').
    live('change', function () {
      var title_field = $(this);
      var slug_field = title_field.closest('.part').find('.slug');
      if (slug_field.text() == '') {
        slug_field.val(GovUKGuideUtils.convertToSlug(title_field.val()));
      }
    });
    
  $('#edition_title')[0].focus();
  
  var submitted_forms = false;
  
  $('.also_save_edition').submit(function () {
    var edition_form = $('form.edition');
    var publication_form = $('form.publication');
    
    var this_form = $(this);

    if (! submitted_forms) {
        submit_form(edition_form,function(data) {
            console.log(data);
            submit_form(publication_form,function(data) {
                submitted_forms = true;
                this_form.trigger("submit");
            })
        });
    }
    return submitted_forms;
  });
});<commit_msg>Make sure that clicking preview saves every time, not just the first one<commit_after>$(function () {
  $('.publication-nav').tabs();
  
  var submit_form = function(form,success) {
     var jq = $.post(
         form.attr('action')+".json",
         form.serialize(),
         success
     ).error( function(data) {
         var errors = $.parseJSON(data.responseText);
         var messages = "There were problems saving this edition: ";
         errors = $.map(errors, function(v,k) {
             return k + " " + v.join(", ");
         });
         messages = messages + errors.join("; ") + ".";
         $("<p class=\"flash-alert\">"+messages+"</p>").insertBefore("#wrapper:first");
     });
   }
  
  var saved = false;
  
  $('#save-edition').submit(function () {
      var edition_form = $('form.edition');
      var publication_form = $('form.publication');
      if (! saved) {
          submit_form(publication_form,function() {
              saved = true;
              edition_form.trigger('submit');
          });
      }
      
      return saved;
  });
  
  $('input.title').
    live('change', function () {
      var title_field = $(this);
      var slug_field = title_field.closest('.part').find('.slug');
      if (slug_field.text() == '') {
        slug_field.val(GovUKGuideUtils.convertToSlug(title_field.val()));
      }
    });
    
  $('#edition_title')[0].focus();
  
  var submitted_forms = false;
  
  $('form.edition,form.publication').change(function () {
  	submitted_forms = false;
  });
  
  $('.also_save_edition').submit(function () {
    var edition_form = $('form.edition');
    var publication_form = $('form.publication');
    
    var this_form = $(this);

    if (! submitted_forms) {
        submit_form(edition_form,function(data) {
            submit_form(publication_form,function(data) {
                submitted_forms = true;
                this_form.trigger("submit");
            })
        });
    }
    
    return submitted_forms;
  });
});

{'fraction_non_alphanumeric': 0.17214600051773232, 'fraction_numerical': 0.0005177323323841574, 'mean_word_length': 2.2388935456831516, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3218346', 'n_tokens_mistral': 1165, 'n_tokens_neox': 1162, 'n_words': 192}