import Ember from 'ember';
import {
  validatePresence,
} from 'ember-changeset-validations/validators';

export default Ember.Component.extend({
  validations: {
    'slug': [
      validatePresence(true)
    ],
    'event_name': [
      validatePresence(true)
    ],
    'parent_domain': [
      validatePresence(true)
    ],
    'admin_first_name': [
      validatePresence(true)
    ],
    'admin_last_name': [
      validatePresence(true)
    ]
  },
  store: Ember.inject.service(),
  versionOptions: function () {
    if (!this.get('allVersions.isFulfilled')) {
      return [];
    }
    return this.get('allVersions').toArray();
  }.property('allVersions.isFulfilled'),
  domainOptions: function () {
    if (!this.get('allDomains.isFulfilled')) {
      return [];
    }
    var domainOptions = Ember.A([Ember.Object.create({
      id: null,
      domain: '---',
      domainValue: null
    })]);
    return domainOptions.concat(this.get('allDomains').map(function (domainData) {
      return Ember.Object.create({
        id: domainData.get('id'),
        domain: domainData.get('domain'),
        domainValue: domainData.get('domain')
      });
    }));
  }.property('allDomains.isFulfilled'),
  allVersions: function () {
    return this.get('store').findAll('osversion');
  }.property(),
  allDomains: function () {
    return this.get('store').findAll('osdomain');
  }.property(),
  actions: {
    submit: function (changeset) {
      return changeset.validate().then(function () {
        if (!changeset.get('isValid')) {
          return false;
        }
        if (!this.get('model.osversion.content')) {
          this.set('model.error.osversion', {'validation': ['Cannot be blank']});
          return;
        }
        changeset.save().then(function (instance) {
          this.sendAction('saved', instance);
        }.bind(this));
      }.bind(this));
    }
  }

});

@@ -584,30 +584,40 @@
 ;%0A    %7D%0A    
-return
+const versions =
  this.get('a
@@ -640,16 +640,37 @@
 rray();%0A
+    return versions;%0A
   %7D.prop
@@ -1617,21 +1617,25 @@
 is.get('
-model
+changeset
 .osversi
@@ -1663,97 +1663,112 @@
     
+ const versions =
  this.
-s
+g
 et('
-model.error.osversion', %7B'validation': %5B'Cannot be blank'%5D%7D);%0A          return
+allVersions').toArray();%0A            changeset.set('osversion', versions%5B0%5D)
 ;%0A  

Fix version validation in save form function.