import Ember from 'ember';
import ComponentVaidation from 'ember-validation/mixins/component';
import layout from '../templates/components/form-validation';

/**
 * @module
 * @augments ember/Component
 * @augments ember-validation/mixins/component
 */
export default Ember.Component.extend(ComponentVaidation, {
  layout: layout,

  /** @type {String} */
  tagName: 'form',

  /**
   * Validate all form on submit
   *
   * @function
   * @param {jQuery.Event} event
   * @returns {undefined}
   */
  submit(event) {
    event.preventDefault();

    this.validate().then(
      () => {
        this.trigger('passed');
        this.sendAction('action');
      },
      (error) => {
        this.trigger('failed');
      });

  },

  showAllErrors() {
    this.get('mediators').forEach((mediator) => {
      let attribute = get(mediator, 'attribute');

      attribute && this.set('visibleErrors.' + attribute, true);
    });
  },

  hideAllErrors() {
    this.get(Ember.keys(this.get('visibleErrors'))).forEach((attribute) => {
      this.set('visibleErrors.' + attribute, true);
    });
  },

});

@@ -644,19 +644,60 @@
 'action'
+, Ember.K, this.onSubmitFailed.bind(this)
 );%0A
-
       %7D,
@@ -765,16 +765,236 @@
 %0A%0A  %7D,%0A%0A
+  /**%0A  * Callback for submit failed%0A  *%0A  * @function%0A  * @returns %7Bundefined%7D%0A  */%0A  onSubmitFailed() %7B%0A    this.showAllErrors();%0A  %7D,%0A%0A  /**%0A  * Make all errors visible%0A  *%0A  * @function%0A  * @returns %7Bundefined%7D%0A  */%0A
   showAl
@@ -1185,16 +1185,97 @@
 ;%0A  %7D,%0A%0A
+  /**%0A  * Make all errors hidden%0A  *%0A  * @function%0A  * @returns %7Bundefined%7D%0A  */%0A
   hideAl

add callbacks in sendAction call