hino / app / controllers / dms-agreement-service / approval.js
approval.js
Raw
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';

export default Controller.extend({
	dmsAgreementService: service(),
	dmsAgreementServiceData: service(),
	errors: service(),
	approvalConfiguration: service(),
	didValidate: false,
	formConfig: false,

	async init() {
		this._super(...arguments);
		let formConfig = await this.approvalConfiguration.getApprovalConfiguration("dms-agreement-service");
		this.set("formConfig", formConfig);

	},

	actions: {
		async saveDmsAgreementService() {
			this.dmsAgreementService.model
				.validate()
				.then(({ validations }) => {
					this.set('didValidate', true);
					if (validations.get('isValid')) {
						this.set('dmsAgreementService.model.isApprovalData', true);
						this.dmsAgreementServiceData.save(this.dmsAgreementService.model).then(response => {
							if (response != undefined) {
								this.transitionToRoute('inbox.inbox-approval-dms', 'DMS_AGREEMENT_SERVICE');
							}
						})
							.catch((e) => {
								this.set('errorMessages', this.errors.getErrorMessages(e));
								window.scrollTo(0, 0);
							});
					}
				});
		},

	},
});