<commit_before>(function(L) {
  'use strict';
  /** Handles all communication with the server.
   *
   * It syncs both notes and logs, translating them to and from the protocol
   * representation.
   *
   * This is broken out into a separate model to avoid contaminating the
   * local implementation with the server protocol.
   */
  L.models.Server = Backbone.Model.extend({
    autoFetch: true,
    defaults : function() {
      return {
        url: 'https://welist.it/listit/jv3/',
        syncingNotes: false,
        syncingLogs: false,
        running: false,
        paused: true,
        noteSyncRunning: false,
        logSyncRunning: false,
        registered: false,
        email: '',
        studies: {},
        noteSyncInterval: 10*60*1000, // 10m
        logSyncInterval:  30*60*1000 // 30m
      };
    },
    include: [
      'registered',
      'url',
      'email',
      'noteSyncInterval',
      'logSyncInterval',
      'studies'
    ],
    toJSON: function(options) {
      return _.pick(this.attributes, this.include);
    },
    initialize: function() {
      _(this).bindAll(
        '_syncNotesFailure',
        '_syncNotesSuccess',
        '_syncNotesEnter',
        '_syncNotesReschedule',
        '_syncNotesExit',
        '_syncLogsEnter',
        '_syncLogsReschedule',
        'packageNote',
        'unpackageNote',
        'syncNotes',
        'syncLogs'
      );
    },
    initialized: function() {
      var that = this;
      this.listenTo(this, _.reduce(this.include, function(memo, attr) {
        return memo+" change:"+attr;
      }, ""), _.mask(this.save));

      this.listenTo(this, 'change:registered', function(server, registered) {
        // Don't start if not running.
        if (!that.get('running')) {
          return;
        }
        if (registered) {
          that.resume();
        } else {
          that.pause();
        }
      });

    },
    // Singleton
    url : '/server',
    isNew: function() {
      return false;
    },
    // Defines a translation between a packaged note and a local note.
    noteTransTable : {
      'jid': { here: 'id' },
      'version': {},
      'created': {transIn: Number}, // The server is odd
      'edited': {transIn: Number},
      'contents': {},
      'meta': { transIn: JSON.parse, transOut: JSON.stringify }
    },
    logTopLevelAttributes: [
      "tabid",
      "action",
      "time",
      "url",
      "noteid"
    ],
    logExcludedAttributes: [
      "id"
    ],
    // Make an ajax method call
    ajax : function(options) {
      options = _.clone(options);

      if (options.continuation) {
        var continuation = options.continuation;
        options.success = function(data) {
          continuation(true, data);
        };
        if (!options.error) {
          options.error = function(xhdr, stat) {
            continuation(false, stat);
          };
        }
        delete options.continuation;
      }

      // Call with auth token if needed. Do it this way to allow for
      // asynchronous authentication (password prompts etc.)
      if (options.auth && !options.authToken) {
        var that = this;
        L.authmanager.getToken(function(token) {
          if (token) {
            options.authToken = token;
            that.ajax(options);
          } else {
            (options.error || $.noop)(null, 'User not authenticated');
            (options.complete || $.noop)();
          }
        });
        return;
      }

      if (!options.type) {
        options.type = options.data ? 'POST' : 'GET';
      }

      options.url = this.get('url') + options.method +
        (options.type === 'POST' ? '/' : '') +
        (options.auth ? ('?HTTP_AUTHORIZATION=' + options.authToken) : '');

      options.crossDomain = false; // Force same domain
      options.jsonp = false; // Don't ever use jsonp XXX JQUERY BUG

      $.ajax(options);
    },
    syncNotes : function() {
      if (this._syncNotesEnter()) {
        var that = this;
        this.pullNotes({
          error: that._syncNotesFailure,
          success: function() {
            that.pushNotes({
              error: that._syncNotesFailure,
              success: that._syncNotesSuccess
            });
          }
        });
      }
    },
    _syncNotesEnter: function() {
      // Don't sync if waiting for a past sync.
      if (this.get('syncingNotes') || !this.get('registered')) {
        return false;
      }
      clearTimeout(this.get('noteSyncTimer'));
      debug('syncNotes::start');

      this.trigger('sync:start');
      this.set('syncingNotes', true);
      return true;
    },
    _syncNotesExit: function() {<commit_msg>jQuery 2.0 uses the method attribute internally (ajax)<commit_after>(function(L) {
  'use strict';
  /** Handles all communication with the server.
   *
   * It syncs both notes and logs, translating them to and from the protocol
   * representation.
   *
   * This is broken out into a separate model to avoid contaminating the
   * local implementation with the server protocol.
   */
  L.models.Server = Backbone.Model.extend({
    autoFetch: true,
    defaults : function() {
      return {
        url: 'https://welist.it/listit/jv3/',
        syncingNotes: false,
        syncingLogs: false,
        running: false,
        paused: true,
        noteSyncRunning: false,
        logSyncRunning: false,
        registered: false,
        email: '',
        studies: {},
        noteSyncInterval: 10*60*1000, // 10m
        logSyncInterval:  30*60*1000 // 30m
      };
    },
    include: [
      'registered',
      'url',
      'email',
      'noteSyncInterval',
      'logSyncInterval',
      'studies'
    ],
    toJSON: function(options) {
      return _.pick(this.attributes, this.include);
    },
    initialize: function() {
      _(this).bindAll(
        '_syncNotesFailure',
        '_syncNotesSuccess',
        '_syncNotesEnter',
        '_syncNotesReschedule',
        '_syncNotesExit',
        '_syncLogsEnter',
        '_syncLogsReschedule',
        'packageNote',
        'unpackageNote',
        'syncNotes',
        'syncLogs'
      );
    },
    initialized: function() {
      var that = this;
      this.listenTo(this, _.reduce(this.include, function(memo, attr) {
        return memo+" change:"+attr;
      }, ""), _.mask(this.save));

      this.listenTo(this, 'change:registered', function(server, registered) {
        // Don't start if not running.
        if (!that.get('running')) {
          return;
        }
        if (registered) {
          that.resume();
        } else {
          that.pause();
        }
      });

    },
    // Singleton
    url : '/server',
    isNew: function() {
      return false;
    },
    // Defines a translation between a packaged note and a local note.
    noteTransTable : {
      'jid': { here: 'id' },
      'version': {},
      'created': {transIn: Number}, // The server is odd
      'edited': {transIn: Number},
      'contents': {},
      'meta': { transIn: JSON.parse, transOut: JSON.stringify }
    },
    logTopLevelAttributes: [
      "tabid",
      "action",
      "time",
      "url",
      "noteid"
    ],
    logExcludedAttributes: [
      "id"
    ],
    // Make an ajax method call
    ajax : function(options) {
      options = _.clone(options);

      if (options.continuation) {
        var continuation = options.continuation;
        options.success = function(data) {
          continuation(true, data);
        };
        if (!options.error) {
          options.error = function(xhdr, stat) {
            continuation(false, stat);
          };
        }
        delete options.continuation;
      }

      // Call with auth token if needed. Do it this way to allow for
      // asynchronous authentication (password prompts etc.)
      if (options.auth && !options.authToken) {
        var that = this;
        L.authmanager.getToken(function(token) {
          if (token) {
            options.authToken = token;
            that.ajax(options);
          } else {
            (options.error || $.noop)(null, 'User not authenticated');
            (options.complete || $.noop)();
          }
        });
        return;
      }

      if (!options.type) {
        options.type = options.data ? 'POST' : 'GET';
      }

      options.url = this.get('url') + options.method +
        (options.type === 'POST' ? '/' : '') +
        (options.auth ? ('?HTTP_AUTHORIZATION=' + options.authToken) : '');

      options.crossDomain = false; // Force same domain
      options.jsonp = false; // Don't ever use jsonp XXX JQUERY BUG

      // Ajax uses method internally
      delete options.method;

      $.ajax(options);
    },
    syncNotes : function() {
      if (this._syncNotesEnter()) {
        var that = this;
        this.pullNotes({
          error: that._syncNotesFailure,
          success: function() {
            that.pushNotes({
              error: that._syncNotesFailure,
              success: that._syncNotesSuccess
            });
          }
        });
      }
    },
    _syncNotesEnter: function() {
      // Don't sync if waiting for a past sync.
      if (this.get('syncingNotes') || !this.get('registered')) {
        return false;
      }
      clearTimeout(this.get('noteSyncTimer'));
      debug('syncNotes::start');

      this.trigger('sync:start');
      this.set('syncingNotes', true);
      return true;
    },
    _syncNotesExit: function() {
{'fraction_non_alphanumeric': 0.13450106157112526, 'fraction_numerical': 0.004670912951167728, 'mean_word_length': 1.8828029375764994, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '2815011', 'n_tokens_mistral': 2803, 'n_tokens_neox': 2682, 'n_words': 635}