import Route from '@ember/routing/route'; import { inject as service } from '@ember/service'; import BaseRoute from 'hino-hearts/routes/base'; export default BaseRoute.extend({ accountManagement : service(), accountManagementData : service(), accountAddressData: service(), accountContactData: service(), accountTeamData: service(), accountCustomerUioData: service(), accountVehicleData: service(), accountUnitSalesOrderData: service(), store : service(), session: service(), init() { this._super(...arguments); }, model(params) { var backurl = this.get('session.data.prevDetailAccount'); var backId = this.get('session.data.prevDetailAccountId'); if(backurl == null || backurl == undefined || backurl == ""){ backurl = "account-management.detailprofile"; //this.set('backurl',"account-management.detailprofile"); } if(backId == null || backId == undefined || backId == ""){ backId = params.id; //this.set('backId',params.id); } this.set('backurl',backurl); this.set('backId',backId); //console.log(backId); //let current = this.accountManagementData.getData(params.id, { include: 'business-segment' }); //console.log(current); //this.accountManagement.setCurrent(current); this.accountManagement.setModel(null); return this.accountManagementData.getData(params.id, { include: 'business-segment,sub-business-segment,id-type,account-address,account-contact,account-team,account-customer-uio,account-vehicle,account-unit-sales-order' }) .then(response => { this.accountManagement.setModel(response); this.set('session.data.managementId',response.id); this.set('session.data.managementNama',response.customerName); this.set('session.data.partyNumber',response.partyNumber); this.accountAddressData.getList({ include: 'address-type,country,village,province,municipality,sub-district,account-management', filter:{"accountManagement" : {"id" : response.id}}, sort: 'is_primary' }).then(responseDetail => { this.accountManagement.clearDetail("accountAddress"); responseDetail.forEach(item => { this.accountManagement.addRow(item, "accountAddress"); }); }); this.accountContactData.getList({include: 'account-management,contact-resource,tittle', filter:{"accountManagement" : {"id" : response.id}}}).then(responseDetail => { this.accountManagement.clearDetail("accountContact"); responseDetail.forEach(item => { this.accountManagement.addRow(item, "accountContact"); }); }); this.accountTeamData.getList({include: 'team-access,account-management,team-resource', filter:{"accountManagement" : {"id" : response.id}}}).then(responseDetail => { this.accountManagement.clearDetail("accountTeam"); responseDetail.forEach(item => { this.accountManagement.addRow(item, "accountTeam"); }); }); this.accountCustomerUioData.getList({include: 'account-management,category-uio', filter:{"accountManagement" : {"id" : response.id}}}).then(responseDetail => { this.accountManagement.clearDetail("accountCustomerUio"); responseDetail.forEach(item => { this.accountManagement.addRow(item, "accountCustomerUio"); }); }); this.accountVehicleData.getList({include: 'account-management,vehicle-management', filter:{"accountManagement" : {"id" : response.id}}}).then(responseDetail => { this.accountManagement.clearDetail("accountVehicle"); responseDetail.forEach(item => { this.accountManagement.addRow(item, "accountVehicle"); }); }); this.accountUnitSalesOrderData.getList({include: 'account-management,hoyu-sales-order-approval', filter:{"accountManagement" : {"id" : response.id}}}).then(responseDetail => { this.accountManagement.clearDetail("accountUnitSalesOrder"); responseDetail.forEach(item => { this.accountManagement.addRow(item, "accountUnitSalesOrder"); }); }); return response; }); }, setupController(controller, model) { this._super(...arguments); // controller.set('model', this.get('data')); controller.set('backurl',this.get('backurl')); controller.set('backId',this.get('backId')); controller.set('errorMessages', null); }, });