<commit_before>import Ember from 'ember';
import layout from './template';

export default Ember.Component.extend({
  submitted: false,

  layout,

  init() {
    this._super(...arguments);
    if (this.get('model') && this.get('model').validate) {
      this.get('model').validate();
    }

    let owner = Ember.getOwner(this);
    let factory = owner.factoryFor ? owner.factoryFor('service:i18n') : owner._lookupFactory('service:i18n');
    this.set('i18n', factory ? factory.create() : null);
  },

  _submitLabel: Ember.computed('config', 'submit-label', function() {
    return this._getLabel('submit') || 'Save';
  }),

  _cancelLabel: Ember.computed('config', function() {
    return this._getLabel('cancel') || 'Cancel';
  }),

  _getLabel(type) {
    const i18n = this.get('i18n');
    const customLabel = this.get(`${type}-label`);
    if (customLabel) {
      return customLabel;
    }
    const defaultLabel = this._config(type);
    return i18n ? i18n.t(defaultLabel) : defaultLabel;
  },

  _config(type) {
    return this.get(`config.label.${type}`);
  },

  actions: {
    submit() {
      this.set('submitted', true);
      const model = this.get('model');
      model.validate().then(() => {
        if (model.get('isInvalid')) {
          return;
        }
        this.attrs['on-submit'](model);
      });
    }
  }
});<commit_msg>Make model optional in submit handler<commit_after>import Ember from 'ember';
import layout from './template';

export default Ember.Component.extend({
  submitted: false,

  layout,

  init() {
    this._super(...arguments);
    if (this.get('model') && this.get('model').validate) {
      this.get('model').validate();
    }

    let owner = Ember.getOwner(this);
    let factory = owner.factoryFor ? owner.factoryFor('service:i18n') : owner._lookupFactory('service:i18n');
    this.set('i18n', factory ? factory.create() : null);
  },

  _submitLabel: Ember.computed('config', 'submit-label', function() {
    return this._getLabel('submit') || 'Save';
  }),

  _cancelLabel: Ember.computed('config', function() {
    return this._getLabel('cancel') || 'Cancel';
  }),

  _getLabel(type) {
    const i18n = this.get('i18n');
    const customLabel = this.get(`${type}-label`);
    if (customLabel) {
      return customLabel;
    }
    const defaultLabel = this._config(type);
    return i18n ? i18n.t(defaultLabel) : defaultLabel;
  },

  _config(type) {
    return this.get(`config.label.${type}`);
  },

  actions: {
    submit() {
      this.set('submitted', true);
      const model = this.get('model');

      if (!model || !model.validate) {
        this.attrs['on-submit'](model);
        return;
      }

      model.validate().then(() => {
        if (model.get('isInvalid')) {
          return;
        }
        this.attrs['on-submit'](model);
      });
    }
  }
});
{'fraction_non_alphanumeric': 0.18249205788916342, 'fraction_numerical': 0.009883515707730321, 'mean_word_length': 3.0084865629420086, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3860241', 'n_tokens_mistral': 936, 'n_tokens_neox': 909, 'n_words': 166}