import Controller from '@ember/controller'; import { inject as service } from '@ember/service'; export default Controller.extend({ contactResource : service(), accountManagement:service(), contactResourceData : service(), genderData : service(), tittleData:service(), religionData : service(), addressTypeData : service(), countryData : service(), villageData : service(), provinceData : service(), municipalityData : service(), subDistrictData : service(), session : service(), errors : service(), didValidate: false, rightActionInProgress: false, genders: Array(), religions: Array(), addressTypes: Array(), countries: Array(), villages: Array(), provinces: Array(), municipalities: Array(), subDistricts: Array(), formConfig : { favorite : { isEditable : true }, nama : { isEditable : false }, account : { isEditable : false }, namaDepan : { isEditable : false }, namaBelakang : { isEditable : false }, jobTitle : { isEditable : true }, owner : { isEditable : true }, gender : { isEditable : true }, tanggalLahir : { isEditable : true }, mobilePhone : { isEditable : true }, validEmailAddress : { isEditable : true }, hobi : { isEditable : false }, religion : { isEditable : true }, addressType : { isEditable : true }, country : { isEditable : true }, alamat1 : { isEditable : true }, alamat2 : { isEditable : true }, alamat3 : { isEditable : true }, village : { isEditable : true }, province : { isEditable : true }, municipality : { isEditable : true }, subDistrict : { isEditable : true }, kodePos : { isEditable : true }, governmentIdValue : { isEditable : true }, accountPartyNumber : { isEditable : true }, isPrimary : { isEditable : true }, createdBy : { isEditable : true }, updatedBy : { isEditable : true }, }, edit:true, init() { this._super(...arguments); var genders = this.genderData.getList(); this.set("genders", genders); var tittles = this.tittleData.getList(); this.set("tittles", tittles); var religions = this.religionData.getList(); this.set("religions", religions); 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); this.set('errorMessages',null); }, actions: { onChangeCombo(propertyName, item) { //this.set(propertyName, item); var mdl =this.contactResource.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('contactResource.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('contactResource.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('contactResource.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('contactResource.model.village',null); } }, // onChangeCombo(propertyName, item) { // //this.set(propertyName, item); // var mdl =this.contactResource.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('contactResource.model.province',null); // } // else if(propertyName == "province"){ // if(mdl.province != null){ // var filter = "\"countryCodeHoyu\" : {\"in\" : \"" + mdl.province.get('countriesId') + "\"}"; // filter = '{' + filter + '}'; // filter = JSON.parse(filter); // var countries = this.countryData.getList({filter: filter}); // this.set("countries", countries); // this.set('contactResource.model.country',null); // } // }else if(propertyName == "municipality"){ // if( mdl.municipality != null){ // var filter = "\"provinceCodeHoyu\" : {\"in\" : \"" + mdl.municipality.get('provincesId') + "\"}"; // filter = '{' + filter + '}'; // filter = JSON.parse(filter); // var provinces = this.provinceData.getList({filter: filter}); // this.set("provinces", provinces); // this.set('contactResource.model.province',null); // } // } // else if(propertyName == "subDistrict"){ // if(mdl.subDistrict != null){ // var filter = "\"municipalityCodeHoyu\" : {\"in\" : \"" + mdl.subDistrict.get('municipalitiesId') + "\"}"; // filter = '{' + filter + '}'; // filter = JSON.parse(filter); // var municipalities = this.municipalityData.getList({filter: filter}); // this.set("municipalities", municipalities); // this.set('contactResource.model.municipality',null); // } // }else if(propertyName == "village"){ // if(mdl.village != null ){ // var filter = "\"subDistrictCodeHoyu\" : {\"in\" : \"" + mdl.village.get('subDistrictsId') + "\"}"; // filter = '{' + filter + '}'; // var subDistricts = this.subDistrictData.getList({filter: filter}); // this.set("subDistricts", subDistricts); // this.set('contactResource.model.subDistrict',null); // } // } // }, setNullError: function(data) { this.set('errorMessages',null); }, async saveContactResource() { var management = this.get('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('contactResource.model.isApprovalData', false); this.contactResourceData.save(this.contactResource.model).then(response => { if (response != undefined) { this.set("rightActionInProgress", false); this.set('errorMessages', null); //console.log(this.accountManagement.model.get(id)); this.transitionToRoute('account-management.detail', management.id); } }) .catch((e) => { this.set("rightActionInProgress", false); this.set('errorMessages', this.errors.getErrorMessages(e)); console.log(this.errorMessages); window.scrollTo(0,0); }); } else { this.set("rightActionInProgress", false); } }); }, }, });