hino / app / routes / hoyu-event-approval / approval.js
approval.js
Raw
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';

import BaseRoute from 'hino-hearts/routes/base';

export default BaseRoute.extend({
	hoyuEventApproval: service(),
	hoyuEventApprovalData: service(),
	hoyuEventApprovalListData: service(),
	hoyuEventApprovalAttachmentData: service(),
	hoyuEventApprovalBudgetData: service(),
	store: service(),
	approvalInboxData: service(),

	init() {
		this._super(...arguments);
	},

	model(params) {
		this.hoyuEventApproval.setModel(null);
		let data = this.hoyuEventApprovalData.getData(params.id, { include: 'hoyu-event-approval-list,hoyu-event-approval-attachment,hoyu-event-approval-budget' });
		data.then(response => {
			response.set("approvalActionType", "approve");
			this.hoyuEventApproval.setModel(response);

			// get inbox versi terakhir
			let inbox = this.approvalInboxData.getData(response.sourceSystemNo, { adapterOptions: { query: { last_inbox: true, doc_type: 'HOYU_EVENT_APPROVAL' } } });
			this.hoyuEventApproval.setInbox(inbox);

			this.hoyuEventApprovalListData.getList({ include: 'hoyu-event-approval', filter: { "hoyuEventApproval": { "id": response.id } } }).then(responseDetail => {

				this.hoyuEventApproval.clearDetail("hoyuEventApprovalList");
				responseDetail.forEach(item => {
					this.hoyuEventApproval.addRow(item, "hoyuEventApprovalList");
				});
			});
			this.hoyuEventApprovalAttachmentData.getList({ include: 'attachment,hoyu-event-approval', filter: { "hoyuEventApproval": { "id": response.id } } }).then(responseDetail => {

				this.hoyuEventApproval.clearDetail("hoyuEventApprovalAttachment");
				responseDetail.forEach(item => {
					this.hoyuEventApproval.addRow(item, "hoyuEventApprovalAttachment");
				});
			});
			this.hoyuEventApprovalBudgetData.getList({ include: 'hoyu-event-approval', filter: { "hoyuEventApproval": { "id": response.id } } }).then(responseDetail => {

				this.hoyuEventApproval.clearDetail("hoyuEventApprovalBudget");
				responseDetail.forEach(item => {
					this.hoyuEventApproval.addRow(item, "hoyuEventApprovalBudget");
				});
			});
			return response;
		});

		this.set('data', data);
		return {data: data};
	},

	setupController(controller, model) {
		this._super(...arguments);
		controller.set('errorMessages', null);
		controller.set('model', this.get('data'));
	},

	templateName: 'hoyu-event-approval/input-approval'
});