import Controller from '@ember/controller'; import { inject as service } from '@ember/service'; export default Controller.extend({ accountManagement : service(), accountManagementData : service(), addressTypeData : service(), countryData : service(), villageData : service(), provinceData : service(), municipalityData : service(), subDistrictData : service(), accountAddressData : service(), accountAddress:service(), session : service(), errors : service(), didValidate: false, rightActionInProgress: false, addressTypes: Array(), countries: Array(), villages: Array(), provinces: Array(), municipalities: Array(), subDistricts: Array(), init() { this._super(...arguments); var addressTypes = this.addressTypeData.getList(); this.set("addressTypes", addressTypes); var countries = this.countryData.getList(); this.set("countries", countries); var villages = this.villageData.getList(); this.set("villages", villages); var provinces = this.provinceData.getList(); this.set("provinces", provinces); var municipalities = this.municipalityData.getList(); this.set("municipalities", municipalities); var subDistricts = this.subDistrictData.getList(); this.set("subDistricts", subDistricts); }, actions: { onChangeCombo(propertyName, item) { //this.set(propertyName, item); var mdl =this.accountAddress.model; if(propertyName == "country") { var filter = "\"country\" : {\"in\" : \"" + mdl.country.get('countryCodeHoyu') + "\"}"; filter = '{' + filter + '}'; filter = JSON.parse(filter); var provinces = this.provinceData.getList({filter: filter}); this.set("provinces", provinces); this.set('accountAddress.model.province',null); } else if(propertyName == "province"){ var filter = "\"province\" : {\"in\" : \"" + mdl.province.get('provinceCodeHoyu') + "\"}"; filter = '{' + filter + '}'; filter = JSON.parse(filter); var municipalities = this.municipalityData.getList({filter: filter}); this.set("municipalities", municipalities); this.set('accountAddress.model.municipality',null); }else if(propertyName == "municipality"){ var filter = "\"municipality\" : {\"in\" : \"" + mdl.municipality.get('municipalityCodeHoyu') + "\"}"; filter = '{' + filter + '}'; filter = JSON.parse(filter); var subDistricts = this.subDistrictData.getList({filter: filter}); this.set("subDistricts", subDistricts); this.set('accountAddress.model.subDistrict',null); } else if(propertyName == "subDistrict"){ var filter = "\"subDistrict\" : {\"in\" : \"" + mdl.subDistrict.get('subDistrictCodeHoyu') + "\"}"; filter = '{' + filter + '}'; filter = JSON.parse(filter); var villages = this.villageData.getList({filter: filter}); this.set("villages", villages); this.set('accountAddress.model.village',null); } }, async saveAccountManagement() { //var management = this.accountManagement.model; // if(management == null || management == undefined){ // alert("kosong"); // } this.set("rightActionInProgress", true); this.get('model') .validate() .then(async ({ validations }) => { this.set('didValidate', true); if (validations.get('isValid')) { //this.set('accountManagement.model.isApprovalData', false); //var current = this.accountAddress.model; //current.accountManagement= management; this.accountAddressData.save(this.accountAddress.model).then(response => { if (response != undefined) { this.set('rightActionInProgress',false); this.set('errorMessages', null); this.transitionToRoute('account-management.detail', this.accountManagement.model.id); } }) .catch((e) => { //this.set("rightActionInProgress", false); this.set('rightActionInProgress',false); this.set('errorMessages', this.errors.getErrorMessages(e)); window.scrollTo(0,0); }); } else { this.set("rightActionInProgress", false); } }); }, }, });