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

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

	async init() {
		this._super(...arguments);
		let formConfig = await this.approvalConfiguration.getApprovalConfiguration("dms-stock-adjustment");
		this.set("formConfig", formConfig);
		console.log(formConfig);
	},

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

	},
});