<commit_before>define(function(require) {
  'use strict';

  var can = require('can');

  var models = require('models');
  return can.Control.extend({
    // Initialize the control
    init: function(element) {
      // This data will be available to the template
      this.scope = new can.Map({
        contact: null
      });

      // Render the control using the contact and insert it into the control's DOM element
      var fragment = can.view('edit-contact', this.scope);
      this.element.html(fragment);
    },

    /*
     * Revert all changes made to the contact and stop editing the contact.
     */
    revertContact: function() {
      this.getContact().restore();
    },

    /*
     * Save all changes made to the contact and stop editing the contact.
     */
    saveContact: function() {
      var contact = this.getContact();
      if (contact.isNew() || contact.isDirty()) {
        contact.save();
      }
    },

    /*
     * Return the contact that is currently being edited.
     */
    getContact: function() {
      return this.scope.attr('contact');
    },
    /*
     * Set the contact that is being edited to the provided contact model
     */
    setContact: function(contact) {
      this.scope.attr('contact', contact);
    },

    /*
     * Respond to control events.
     */
    '.save click': function() {
      this.saveContact();
      location.hash = can.route.url({ page: 'contacts' });

      // Prevent the default submit behavior
      return false;
    },
    '.cancel click': function() {
      this.revertContact();
      location.hash = can.route.url({ page: 'contacts' });
    },

    /*
     * Listen for changes to the route's "contactId" attribute.
     */
    '{can.route} contactId': function(route, event, contactId) {
      var contact = null;
      if (contactId === undefined) {
        // Ignore the contactId if it is undefined
      }
      else if (contactId === 'new') {
        // Create a new contact to edit
        contact = new models.Contact();
      }
      else {
        // Lookup the contact in the global list by its contact
        contact = models.Contact.store[contactId];
        if (contact) {
          // Save a copy of the contact's attributes so that it can be reverted later if necessary
          contact.backup();
        }
        else {
          // No contact has that contactId
          console.error('Attempting to navigate to a non-existent contact!');
          can.route.removeAttr('contactId');
        }
      }
      this.setContact(contact);
    }
  });
});<commit_msg>Conform to JSCS rule disallowEmptyBlocks<commit_after>define(function(require) {
  'use strict';

  var can = require('can');

  var models = require('models');
  return can.Control.extend({
    // Initialize the control
    init: function(element) {
      // This data will be available to the template
      this.scope = new can.Map({
        contact: null
      });

      // Render the control using the contact and insert it into the control's DOM element
      var fragment = can.view('edit-contact', this.scope);
      this.element.html(fragment);
    },

    /*
     * Revert all changes made to the contact and stop editing the contact.
     */
    revertContact: function() {
      this.getContact().restore();
    },

    /*
     * Save all changes made to the contact and stop editing the contact.
     */
    saveContact: function() {
      var contact = this.getContact();
      if (contact.isNew() || contact.isDirty()) {
        contact.save();
      }
    },

    /*
     * Return the contact that is currently being edited.
     */
    getContact: function() {
      return this.scope.attr('contact');
    },
    /*
     * Set the contact that is being edited to the provided contact model
     */
    setContact: function(contact) {
      this.scope.attr('contact', contact);
    },

    /*
     * Respond to control events.
     */
    '.save click': function() {
      this.saveContact();
      location.hash = can.route.url({ page: 'contacts' });

      // Prevent the default submit behavior
      return false;
    },
    '.cancel click': function() {
      this.revertContact();
      location.hash = can.route.url({ page: 'contacts' });
    },

    /*
     * Listen for changes to the route's "contactId" attribute.
     */
    '{can.route} contactId': function(route, event, contactId) {
      var contact = null;
      if (contactId === undefined) {
        // Ignore the contactId if it is undefined
        return;
      }
      else if (contactId === 'new') {
        // Create a new contact to edit
        contact = new models.Contact();
      }
      else {
        // Lookup the contact in the global list by its contact
        contact = models.Contact.store[contactId];
        if (contact) {
          // Save a copy of the contact's attributes so that it can be reverted later if necessary
          contact.backup();
        }
        else {
          // No contact has that contactId
          console.error('Attempting to navigate to a non-existent contact!');
          can.route.removeAttr('contactId');
        }
      }
      this.setContact(contact);
    }
  });
});
{'fraction_non_alphanumeric': 0.11981477908547174, 'fraction_numerical': 0.0, 'mean_word_length': 2.071090047393365, 'pattern_counts': {'":': 0, '<': 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': '4309933', 'n_tokens_mistral': 1417, 'n_tokens_neox': 1390, 'n_words': 455}