hino / app / controllers / account-management / detail.js
detail.js
Raw
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';

export default Controller.extend({
	accountManagement : service(),
	errors : service(),
	accountManagementData:service(),
	businessSegmentData:service(),
	subBusinessSegmentData:service(),
	idTypeData:service(),
	errorMessages :null,
	backurl:null,
	backId:null,





	init() {
		this._super(...arguments);
		var businessSegments = this.businessSegmentData.getList();
		this.set("businessSegments", businessSegments);
		var mdl = null;
		
		if(mdl != null){
			alert("masuk");
			
			// console.log(mdl.businessSegment.get('businessSegmentCode'));
			//  var filter = "\"businessSegment\" : {\"in\" : \"" + mdl.businessSegment.get('businessSegmentCode') + "\"}";
			// filter = '{' + filter + '}';
			// filter = JSON.parse(filter);
			// var subBusinessSegments = this.subBusinessSegmentData.getList({filter: filter});
			// this.set("subBusinessSegments", subBusinessSegments);
		}else{
			//alert('masujk');
			var subBusinessSegments = this.subBusinessSegmentData.getList();
			this.set("subBusinessSegments", subBusinessSegments);
		}

		// alert('masujk');
		// 	var subBusinessSegments = this.subBusinessSegmentData.getList();
		// 	this.set("subBusinessSegments", subBusinessSegments);

		var idTypes = this.idTypeData.getList();
		this.set("idTypes", idTypes);
		
	},

	actions: {
		scrollTo(fragmentIdLink) {
			document.querySelector(`#${fragmentIdLink}`).scrollIntoView({
				behavior: 'smooth',
				block: "start",
				inline: "start"
			});
		},
		onChangeCombo(propertyName, itemCollection){
			var mdl =this.accountManagement.model;
			console.log(mdl.businessSegment.get('businessSegmentCode'));
			 var filter = "\"businessSegment\" : {\"in\" : \"" + mdl.businessSegment.get('businessSegmentCode') + "\"}";
			filter = '{' + filter + '}';
			filter = JSON.parse(filter);
			var subBusinessSegments = this.subBusinessSegmentData.getList({filter: filter});
			this.set("subBusinessSegments", subBusinessSegments);
			this.set('accountManagement.model.subBusinessSegment',null);
			

		},
		
 	formatNpwp(value) {
	if (typeof value === 'string') {
	  return value.replace(/(\d{2})(\d{3})(\d{3})(\d{1})(\d{3})(\d{3})/, '$1.$2.$3.$4-$5.$6');
	}
  	},

		async saveAccountManagement() {
			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);
						this.set('accountManagement.model.isFromCustomer', "false");
						this.accountManagementData.save(this.accountManagement.model).then(response => {
							if (response != undefined) {
								this.set("rightActionInProgress", false);
								this.set('errorMessages', null);
								this.transitionToRoute('account-management.detail', response.id); 
							}
						}) 
						.catch((e) => {
							this.set("rightActionInProgress", false);
							console.log(e);
							this.set('errorMessages', this.errors.getErrorMessages(e));
							window.scrollTo(0,0);
						});
					} else {
						this.set("rightActionInProgress", false);
					}
			});
		},


	}
});