hino / app / controllers / sub-business-segment / create.js
create.js
Raw
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';

export default Controller.extend({
	subBusinessSegment : service(),
	subBusinessSegmentData : service(),
	businessSegmentData : service(),
	errors : service(),
	didValidate: false,

	businessSegments: Array(),

	init() {
		this._super(...arguments);
		var businessSegments = this.businessSegmentData.getList();
		this.set("businessSegments", businessSegments);

	},

	actions: {
		onChangeCombo(propertyName, item) {
			this.set(propertyName, item);
		},

		saveSubBusinessSegment() {
			this.get('model')
				.validate()
				.then(({ validations }) => {
					this.set('didValidate', true); 
					if (validations.get('isValid')) {
						this.set('subBusinessSegment.model.isApprovalData', false);
						this.subBusinessSegmentData.save(this.subBusinessSegment.model).then(response => {
							if (response != undefined) {
								this.transitionToRoute('sub-business-segment.detail', response.id); 
							}
						}) 
						.catch((e) => {
							this.set('errorMessages', this.errors.getErrorMessages(e));
						});
					}
			});
		},

	},
});