<commit_before>/* Setup - Profiles - Model */
var ProfileModel = Backbone.Model.extend({
  defaults: {
    id: 'new',
    action: 'Add',
    name: '',
    email: '',
    pass: '',
    note: '',
    route_id: ''
  },
  validation: {
    name: {
      minLength: 1,
      maxLength: 48,
      required: true,
      msg: 'Enter a name for your profile'
    },
    email: {
      maxLength: 128,
      pattern: 'email',
      required: true,
      msg: 'Enter a valid email address'
    },
    pass: {
      required: false
    },
    route_id: {
      minLength: 1,
      required: true,
      msg: 'Create & select a sending route'
    },
    note: {
      maxLength: 48,
      required: false
    },
    auto_configurable: false,
    pgp_keys: []
  }
});


var ProfilesCollection = Backbone.Collection.extend({
  url: '/setup/profiles/as.json',
  model: ProfileModel
});


/* Setup - Profiles - View */
var ProfilesView = Backbone.View.extend({
  initialize: function() {
    Backbone.Validation.bind(this);
		this.render();
  },
  render: function() {
    return this;
  },
  events: {
    "click #btn-setup-show-add-profile"   : "showAdd",
    "blur #input-setup-profile-email"     : "actionCheckEmailMagic",
    "blur #input-setup-profile-pass"      : "actionCheckAuth",
    "mouseover #btn-setup-profile-save"   : "actionCheckAuth",
    "change #input-setup-profile-route_id": "actionHandleRoute",
    "click .btn-setup-profile-edit-route" : "actionEditRoute",
    "click #btn-setup-profile-save"       : "processSettings",
    "keyup .profile-update"               : "processUpdate",
    "click .setup-profile-remove"         : "processRemove"
  },
  show: function() {

    this.$el.html($('#template-setup-profiles').html());

    // Load Data & Add to Collection
    Mailpile.API.setup_profiles_get({}, function(result) {

      if (_.isEmpty(result.result.profiles)) {
        Backbone.history.navigate('#profiles/add', true);
      }

      _.each(result.result.profiles, function(val, key) {
        var profile = new ProfileModel(_.extend({id: key, action: 'Edit'}, val));
        ProfilesCollection.add(profile);
        $('#setup-profiles-list-items').append(_.template($('#template-setup-profiles-item').html(), profile.attributes));
      });

    });

    return this;
  },
  showAdd: function() {
    $('#setup-profiles-list').removeClass('bounceInUp').addClass('bounceOutLeft');
    var new_model = this.model.attributes;
    Mailpile.API.setup_profiles_get({}, function(result) {
      var add_data = _.extend(new_model, {routes: result.result.routes});
      $('#setup').html(_.template($('#template-setup-profiles-add').html(), add_data));
    });
  },
  showEdit: function(id) {
    $('#setup-profiles-list').removeClass('bounceInUp').addClass('bounceOutUp');

    // Load Data & Add to Collection
    Mailpile.API.setup_profiles_get({}, function(result) {
      var profile = result.result.profiles[id];
      if (profile !== undefined) {        
        _.extend(profile, { id: id, action: 'Edit' });
        var edit_data = _.extend(profile, {routes: result.result.routes});
        $('#setup').html(_.template($('#template-setup-profiles-add').html(), edit_data));
      }
    });
  },<commit_msg>Made Profiles hide delete if only 1 exists<commit_after>/* Setup - Profiles - Model */
var ProfileModel = Backbone.Model.extend({
  defaults: {
    id: 'new',
    action: 'Add',
    name: '',
    email: '',
    pass: '',
    note: '',
    route_id: ''
  },
  validation: {
    name: {
      minLength: 1,
      maxLength: 48,
      required: true,
      msg: 'Enter a name for your profile'
    },
    email: {
      maxLength: 128,
      pattern: 'email',
      required: true,
      msg: 'Enter a valid email address'
    },
    pass: {
      required: false
    },
    route_id: {
      minLength: 1,
      required: true,
      msg: 'Create & select a sending route'
    },
    note: {
      maxLength: 48,
      required: false
    },
    auto_configurable: false,
    pgp_keys: []
  }
});


var ProfilesCollection = Backbone.Collection.extend({
  url: '/setup/profiles/as.json',
  model: ProfileModel
});


/* Setup - Profiles - View */
var ProfilesView = Backbone.View.extend({
  initialize: function() {
    Backbone.Validation.bind(this);
		this.render();
  },
  render: function() {
    return this;
  },
  events: {
    "click #btn-setup-show-add-profile"   : "showAdd",
    "blur #input-setup-profile-email"     : "actionCheckEmailMagic",
    "blur #input-setup-profile-pass"      : "actionCheckAuth",
    "mouseover #btn-setup-profile-save"   : "actionCheckAuth",
    "change #input-setup-profile-route_id": "actionHandleRoute",
    "click .btn-setup-profile-edit-route" : "actionEditRoute",
    "click #btn-setup-profile-save"       : "processSettings",
    "keyup .profile-update"               : "processUpdate",
    "click .setup-profile-remove"         : "processRemove"
  },
  show: function() {

    this.$el.html($('#template-setup-profiles').html());

    // Load Data & Add to Collection
    Mailpile.API.setup_profiles_get({}, function(result) {

      if (_.isEmpty(result.result.profiles)) {
        Backbone.history.navigate('#profiles/add', true);
      }

      _.each(result.result.profiles, function(val, key) {
        var profile = new ProfileModel(_.extend({id: key, action: 'Edit'}, val));
        ProfilesCollection.add(profile);
        $('#setup-profiles-list-items').append(_.template($('#template-setup-profiles-item').html(), profile.attributes));
      });

      // Hide Delete (if only 1 profile)
      if (ProfilesCollection.length === 1) {
        $('.setup-profile-remove').parent().hide();
      }
    });

    return this;
  },
  showAdd: function() {
    $('#setup-profiles-list').removeClass('bounceInUp').addClass('bounceOutLeft');
    var new_model = this.model.attributes;
    Mailpile.API.setup_profiles_get({}, function(result) {
      var add_data = _.extend(new_model, {routes: result.result.routes});
      $('#setup').html(_.template($('#template-setup-profiles-add').html(), add_data));
    });
  },
  showEdit: function(id) {
    $('#setup-profiles-list').removeClass('bounceInUp').addClass('bounceOutUp');

    // Load Data & Add to Collection
    Mailpile.API.setup_profiles_get({}, function(result) {
      var profile = result.result.profiles[id];
      if (profile !== undefined) {        
        _.extend(profile, { id: id, action: 'Edit' });
        var edit_data = _.extend(profile, {routes: result.result.routes});
        $('#setup').html(_.template($('#template-setup-profiles-add').html(), edit_data));
      }
    });
  },
{'fraction_non_alphanumeric': 0.16991391028545538, 'fraction_numerical': 0.0031717263253285004, 'mean_word_length': 2.788329519450801, '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': '4729458', 'n_tokens_mistral': 2115, 'n_tokens_neox': 2081, 'n_words': 395}