<commit_before>/**
 * @fileoverview Describes a bootstrap tab
 */
define([
  'text!templates/noteDetail.html',
  'text!templates/tab.html',
  'backbone',
  'underscore',
  'lib/jquery.hotkeys',
  'codemirror',
  'lib/codemirror/mode/rst/rst'
],
function(noteDetailTemplate, tabTemplate) {
  return Backbone.View.extend({

    initialize: function() {
      this._editor = null;
    },

    render: function(collection) {
      var note = this.model.toJSON(),
        tabs = this.options.tabs,
        tabContent = this.options.tabContent;

      // No tabs are active
      tabs.find('.active').removeClass('active');

      // Add new tab content
      tabContent.append(_.template(noteDetailTemplate, {
        note: note
      }));

      // Use codemirror for the content
      this.el = $(tabContent).find('.editor').last().parent();
      this.$el = $(this.el);
      this._editor = CodeMirror(_.first(this.$el.find('.editor')), {
        mode: 'rst',
        value: note.content,
        extraKeys: {
          'Ctrl-S': _.bind(this.save, this)
        }
      });
      this.$('input').bind('keydown', 'ctrl+s', _.bind(this.save, this));

      // Somehow this seems to result in the right tab saving, but
      // seemms like a defect waiting to happen.
      $(document).bind('keydown', 'ctrl+s', _.bind(this.save, this));

      // Add a new tab
      tabs.append(_.template(tabTemplate, {
        note: note
      }));

      // Set event handlers, and show the tab
      this.getTab().on('shown', _.bind(this.shown, this))
        .tab('show')
        .find('button').on('click', _.bind(this.close, this));

      return this;
    },

    show: function() {
      this.getTab().tab('show');
    },

    shown: function() {
      if (this.model.get('subject')) {
        this._editor.focus();
      } else {
        this.$('.subject input').focus();
      }
    },

    saved: function() {
      $('.saved').fadeIn();
      setTimeout(function() {
        $('.saved').fadeOut();
      }, 2000);
    },

    save: function() {
      if (!this.$el.is(":visible")) {
        return;
      }
      this.model.save({
        content: this._editor.getValue(),
        password: this.$el.find('.password input').val(),
        subject: this.$el.find('.subject input').val(),
        tags: this.$el.find('.tags input').val()
      }, {
        success: this.saved<commit_msg>Remove another setTimeout (use jquery .delay)<commit_after>/**
 * @fileoverview Describes a bootstrap tab
 */
define([
  'text!templates/noteDetail.html',
  'text!templates/tab.html',
  'backbone',
  'underscore',
  'lib/jquery.hotkeys',
  'codemirror',
  'lib/codemirror/mode/rst/rst'
],
function(noteDetailTemplate, tabTemplate) {
  return Backbone.View.extend({

    initialize: function() {
      this._editor = null;
    },

    render: function(collection) {
      var note = this.model.toJSON(),
        tabs = this.options.tabs,
        tabContent = this.options.tabContent;

      // No tabs are active
      tabs.find('.active').removeClass('active');

      // Add new tab content
      tabContent.append(_.template(noteDetailTemplate, {
        note: note
      }));

      // Use codemirror for the content
      this.el = $(tabContent).find('.editor').last().parent();
      this.$el = $(this.el);
      this._editor = CodeMirror(_.first(this.$el.find('.editor')), {
        mode: 'rst',
        value: note.content,
        extraKeys: {
          'Ctrl-S': _.bind(this.save, this)
        }
      });
      this.$('input').bind('keydown', 'ctrl+s', _.bind(this.save, this));

      // Somehow this seems to result in the right tab saving, but
      // seemms like a defect waiting to happen.
      $(document).bind('keydown', 'ctrl+s', _.bind(this.save, this));

      // Add a new tab
      tabs.append(_.template(tabTemplate, {
        note: note
      }));

      // Set event handlers, and show the tab
      this.getTab().on('shown', _.bind(this.shown, this))
        .tab('show')
        .find('button').on('click', _.bind(this.close, this));

      return this;
    },

    show: function() {
      this.getTab().tab('show');
    },

    shown: function() {
      if (this.model.get('subject')) {
        this._editor.focus();
      } else {
        this.$('.subject input').focus();
      }
    },

    saved: function() {
      $('.saved').fadeIn().delay(4000).fadeOut();
    },

    save: function() {
      if (!this.$el.is(":visible")) {
        return;
      }
      this.model.save({
        content: this._editor.getValue(),
        password: this.$el.find('.password input').val(),
        subject: this.$el.find('.subject input').val(),
        tags: this.$el.find('.tags input').val()
      }, {
        success: this.saved
{'fraction_non_alphanumeric': 0.17972544878563887, 'fraction_numerical': 0.001689545934530095, 'mean_word_length': 2.2617079889807163, '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': '2251202', 'n_tokens_mistral': 1493, 'n_tokens_neox': 1431, 'n_words': 295}