import Controller from '@ember/controller'; import { inject as service } from '@ember/service'; export default Controller.extend({ hoyuEventApproval : service(), hoyuEventApprovalData : service(), hoyuEventApprovalListData : service(), attachmentData : service(), hoyuEventApprovalAttachmentData : service(), hoyuEventApprovalBudgetData : service(), session : service(), errors : service(), didValidate: false, rightActionInProgress: false, attachments: Array(), init() { this._super(...arguments); var attachments = this.attachmentData.getList(); this.set("attachments", attachments); }, actions: { onChangeCombo(propertyName, itemCollection) { this.set(propertyName, itemCollection); }, async saveHoyuEventApproval() { this.set("rightActionInProgress", true); this.get('model') .validate() .then(async ({ validations }) => { this.set('didValidate', true); if (validations.get('isValid')) { this.set('hoyuEventApproval.model.isApprovalData', false); this.hoyuEventApprovalData.save(this.hoyuEventApproval.model).then(response => { if (response != undefined) { this.transitionToRoute('hoyu-event-approval.detail', response.id); } }) .catch((e) => { this.set("rightActionInProgress", false); this.set('errorMessages', this.errors.getErrorMessages(e)); }); } else { this.set("rightActionInProgress", false); } }); }, addRowData(modal_type) { if (modal_type == "hoyu-event-approval-list") { let data = this.hoyuEventApprovalListData.createRecord(); this.hoyuEventApproval.addRow(data, "hoyuEventApprovalList"); } if (modal_type == "hoyu-event-approval-attachment") { let data = this.hoyuEventApprovalAttachmentData.createRecord(); this.hoyuEventApproval.addRow(data, "hoyuEventApprovalAttachment"); } if (modal_type == "hoyu-event-approval-budget") { let data = this.hoyuEventApprovalBudgetData.createRecord(); this.hoyuEventApproval.addRow(data, "hoyuEventApprovalBudget"); } }, deleteRowData(modal_type, data) { if (modal_type == "hoyu-event-approval-list") { this.hoyuEventApproval.deleteRow(data, "hoyuEventApprovalList"); } if (modal_type == "hoyu-event-approval-attachment") { this.hoyuEventApproval.deleteRow(data, "hoyuEventApprovalAttachment"); } if (modal_type == "hoyu-event-approval-budget") { this.hoyuEventApproval.deleteRow(data, "hoyuEventApprovalBudget"); } }, }, });