hino / app / controllers / vehicle-management / view-detail.js
view-detail.js
Raw
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';

export default Controller.extend({
	approvalConfiguration: service(),
	accountManagement:service(),
	vehicleManagement : service(),
	vehicleManagementData : service(),
	brandData : service(),
	vehicleModelData : service(),
	vehicleVariantData : service(),
	subBusinessSegmentData : service(),
	colorData : service(),
	fuelTypeData : service(),
	karoseriTypeData : service(),
	karoseriData : service(),
	vehicleBastData : service(),
	vehicleWarrantyData : service(),
	vehicleWorkOrderData : service(),
	businessSegmentData : service(),
	session : service(),
	errors : service(),
	didValidate: false,
	rightActionInProgress: false,

	brands: Array(),
	vehicleModels: Array(),
	vehicleVariants: Array(),
	subBusinessSegments: Array(),
	warnas: Array(),
	tipeBbms: Array(),
	karoseriTypes: Array(),
	karoseris: Array(),
	businessSegments: Array(),

	formConfig: false,

	async init() {
		this._super(...arguments);
		this.set("parentId", this.accountManagement.model.id);
		let formConfig = await this.approvalConfiguration.getApprovalConfiguration("vehicle-management");
		this.set("formConfig", formConfig);
		var brands = this.brandData.getList();
		this.set("brands", brands);

		var vehicleModels = this.vehicleModelData.getList();
		this.set("vehicleModels", vehicleModels);

		var vehicleVariants = this.vehicleVariantData.getList();
		this.set("vehicleVariants", vehicleVariants);

		var subBusinessSegments = this.subBusinessSegmentData.getList();
		this.set("subBusinessSegments", subBusinessSegments);

		var warnas = this.colorData.getList();
		this.set("warnas", warnas);

		var tipeBbms = this.fuelTypeData.getList();
		this.set("tipeBbms", tipeBbms);

		var karoseriTypes = this.karoseriTypeData.getList();
		this.set("karoseriTypes", karoseriTypes);

		var karoseris = this.karoseriData.getList();
		this.set("karoseris", karoseris);

		var businessSegments = this.businessSegmentData.getList();
		this.set("businessSegments", businessSegments);
	},

	actions: {
		scrollTo(fragmentIdLink) {
			document.querySelector(`#${fragmentIdLink}`).scrollIntoView({
				behavior: 'smooth',
				block: "start",
				inline: "start"
			});
		},
		async saveVehicleManagement() {
			this.set("rightActionInProgress", true);
			this.get('model')
				.validate()
				.then(async ({ validations }) => {
					this.set('didValidate', true); 
					if (validations.get('isValid')) {
						this.set('vehicleManagement.model.isApprovalData', false);
						this.vehicleManagementData.save(this.vehicleManagement.model).then(response => {
							if (response != undefined) {
								this.transitionToRoute('vehicle-management.view-detail', response.id); 
								this.set("rightActionInProgress", false);
							}
						})
						.catch((e) => {
							this.set("rightActionInProgress", false);
							this.set('errorMessages', this.errors.getErrorMessages(e));
						});
					} else {
						this.set("rightActionInProgress", false);
					}
			}); 
		},
	}
});