<commit_before>app.views.EditTranscript = app.views.Transcripts.extend({

  el: 'body',

  events: {
    "click .toggle-play-link": "togglePlay"
  },

  initialize: function(){
    this.part_index = -1;
    this.initAll();
  },

  initKeys: function(){
    var that = this;
    $(window).keydown(function(e){
      switch(e.keyCode) {
        case 9: // tab
          e.preventDefault();
          that.selectTextRange();
          break;
        case 13: // enter
        case 40: // down arrow
          e.preventDefault();
          that.saveChange();
          that.next();
          break;
        case 38: // up arrow
          e.preventDefault();
          that.prev();
          break;
        case 82: // ctrl + r
          if (e.ctrlKey) {
            e.preventDefault();
            that.playSelected();
          }
      }
    });
  },

  clearSelected: function(){
    var $part = $('.part.active').first(),
        end = Math.round($part.attr('data-end') * 1000);

    this.player.clearOnPosition(end);
    if (!this.paused()) {
      this.pause();
    }
  },

  next: function(){
    this.select(this.part_index+1);

    this.logChange('progress', 'line', helper.round((this.part_index+1)/$('.part').length,3));
  },

  onReady: function(){
    var that = this;

    this.initKeys();

    $('#transcript').on('click', '.part', function(e){
      e.preventDefault();
      var i = $('#parts .part').index($(this));
      that.select(i);
    });

    this.next();
  },

  playSelected: function(e){
    e && e.preventDefault();

    var that = this,
        $part = $('.part.active').first(),
        start = Math.round($part.attr('data-start') * 1000),
        end = Math.round($part.attr('data-end') * 1000);

    this.player.setPosition(start);
    this.player.clearOnPosition(end);
    this.player.onPosition(end, function(e){
      that.pause();
      that.player.setPosition(start);
    });
    if (this.paused()) {
      this.player.play();
      $('.toggle-play-link').addClass('active');
    }
  },

  prev: function(){
    this.select(this.part_index-1);
  },

  save: function(){
    var that = this,
        action_url = $('#transcript').attr('data-action'),
        body = {transcript: this.transcript};

    body = JSON.stringify(body);

    $.ajax({
      type: "POST",
      url: action_url,
      data: {body: body},
      complete: function(){
        console.log('Saved current transcript');
        that.flashMessage('Saved changes.');<commit_msg>add more aggressive saving for transcripts<commit_after>app.views.EditTranscript = app.views.Transcripts.extend({

  el: 'body',

  events: {
    "click .toggle-play-link": "togglePlay"
  },

  initialize: function(){
    this.part_index = -1;
    this.initAll();
  },

  initKeys: function(){
    var that = this;
    $(window).keydown(function(e){
      switch(e.keyCode) {
        case 9: // tab
          e.preventDefault();
          that.selectTextRange();
          break;
        case 13: // enter
        case 40: // down arrow
          e.preventDefault();
          that.saveChange();
          that.next();
          break;
        case 38: // up arrow
          e.preventDefault();
          that.saveChange();
          that.prev();
          break;
        case 82: // ctrl + r
          if (e.ctrlKey) {
            e.preventDefault();
            that.playSelected();
          }
      }
    });
  },

  clearSelected: function(){
    var $part = $('.part.active').first(),
        end = Math.round($part.attr('data-end') * 1000);

    this.player.clearOnPosition(end);
    if (!this.paused()) {
      this.pause();
    }
  },

  next: function(){
    this.select(this.part_index+1);

    this.logChange('progress', 'line', helper.round((this.part_index+1)/$('.part').length,3));
  },

  onReady: function(){
    var that = this;

    this.initKeys();

    $('#transcript').on('click', '.part', function(e){
      e.preventDefault();
      var i = $('#parts .part').index($(this));
      that.saveChange();
      that.select(i);
    });

    this.next();
  },

  playSelected: function(e){
    e && e.preventDefault();

    var that = this,
        $part = $('.part.active').first(),
        start = Math.round($part.attr('data-start') * 1000),
        end = Math.round($part.attr('data-end') * 1000);

    this.player.setPosition(start);
    this.player.clearOnPosition(end);
    this.player.onPosition(end, function(e){
      that.pause();
      that.player.setPosition(start);
    });
    if (this.paused()) {
      this.play();
    }
  },

  prev: function(){
    this.select(this.part_index-1);
  },

  save: function(){
    var that = this,
        action_url = $('#transcript').attr('data-action'),
        body = {transcript: this.transcript};

    body = JSON.stringify(body);

    $.ajax({
      type: "POST",
      url: action_url,
      data: {body: body},
      complete: function(){
        console.log('Saved current transcript');
        that.flashMessage('Saved changes.');
{'fraction_non_alphanumeric': 0.1810707840385001, 'fraction_numerical': 0.010427110487266893, 'mean_word_length': 2.152970922882427, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '3010739', 'n_tokens_mistral': 1614, 'n_tokens_neox': 1529, 'n_words': 287}