hino / app / controllers / contact-resource / index.js
index.js
Raw
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
export default Controller.extend({
	contactResourceData : service(),
	accountContactData : service(),
	accountManagement:service(),
	router: service(),
	errors : service(),
	didValidate: false,
	errorMessages : Array(),
	rightActionInProgress: false,
	queryParams: ['page', 'perPage', 'sort', 'filter'],
	page: 1,
	perPage: 10,
	filter: null,
	init() {
		this._super(...arguments);
		this.table = {
			mode: "list",
			model: "contact-resource",
			columns: [
			{
				name: 'Nama',
				key: 'nama',
				uri: "contact-resource.detail",
				editUri: "contact-resource.edit"
			},
			{
				name: 'Primary Account',
				key: 'account',
			},
			{
				name: 'Job Title',
				key: 'jobTittle',
			},
			{
				name: 'Phone',
				key: 'mobilePhone',
			},
			{
				name: 'Valid Email Address',
				key: 'validEmailAddress',
			},
			{
				name: 'Owner',
				key: 'owner',
			},
			// {
			// 	name: 'Favorite',
			// 	key: 'favorite',
			// },
			
			// {
			// 	name: 'Nama Depan',
			// 	key: 'namaDepan',
			// },
			// {
			// 	name: 'Nama Belakang',
			// 	key: 'namaBelakang',
			// },
			
			
			// {
			// 	name: 'Gender',
			// 	key: 'gender.gender',
			// },
			// {
			// 	name: 'Tanggal Lahir',
			// 	key: 'tanggalLahir',
			// 	type: 'date',
			// },
			// {
			// 	name: 'Mobile Phone',
			// 	key: 'mobilePhone',
			// },
			// {
			// 	name: 'Valid Email Address',
			// 	key: 'validEmailAddress',
			// },
			// {
			// 	name: 'Hobi',
			// 	key: 'hobi',
			// },
			// {
			// 	name: 'Agama',
			// 	key: 'religion.religion',
			// },
			// {
			// 	name: 'Address Type',
			// 	key: 'addressType.addressType',
			// },
			// {
			// 	name: 'Country',
			// 	key: 'country.countryName',
			// },
			// {
			// 	name: 'Alamat1',
			// 	key: 'alamat1',
			// },
			// {
			// 	name: 'Alamat2',
			// 	key: 'alamat2',
			// },
			// {
			// 	name: 'Alamat3',
			// 	key: 'alamat3',
			// },
			// {
			// 	name: 'Kelurahan',
			// 	key: 'village.village',
			// },
			// {
			// 	name: 'Provinsi',
			// 	key: 'province.province',
			// },
			// {
			// 	name: 'Kabupaten/Kotamadya',
			// 	key: 'municipality.municipality',
			// },
			// {
			// 	name: 'Kecamatan',
			// 	key: 'subDistrict.subDistrict',
			// },
			// {
			// 	name: 'Kode Pos',
			// 	key: 'kodePos',
			// },
			// {
			// 	name: 'Government ID Value',
			// 	key: 'governmentIdValue',
			// },
			] 
		};
	},
	actions : {
		deleteRow(data) {
			let result = confirm('Are you sure want to delete this data?');
			if (result) {
				if (data != null) {
					this.contactResourceData.delete(data).then(() => {
						this.router.transitionTo('contact-resource.index');
					});
				}
			}
		},
		setNullError: function(data) {
			this.set('errorMessages',null);
		  },
	
		async saveContactResource() {
			//this.set("rightActionInProgress", true);
			var cr =this.get('model');
			var serviceaccont = this.accountManagement;
			
			let service = this.accountContactData;
			var management = this.get('accountManagement.model');
			if(management == null || management == undefined){
				alert('kosong');
			}
			let _this = this;
			var isvalid =false;
			var exist = Array();
			var index =0;
			var jumlah =cr.filter(obj=>obj.chosee == true).length;
			
			if(jumlah == 0){
				this.set('rightActionInProgress',false);
			}else{
			if(cr != null && cr != undefined  && ( management != null && management != undefined)){
				await cr.forEach(function(item) {
					
					//alert(index);
					if(item.chosee){
						let newData = {};
						
					
						//let newData = service.createRecord();
						//_this.set('newData.namaDepan',item.namaDepan);
						
						//newData.namaDepan = item.namaDepan;
						//newData.isFavoriteContact =item.favorite;
						//  newData.account =item.account;
						//  newData.namaDepan =item.namaDepan;
						//  newData.email =item.email;
						//  newData.namaBelakang =item.namaBelakang;
						//  newData.phone =item.phone;
						// newData.jobTittle =item.jobTitle;
						// newData.owner =item.owner;
						newData.accountManagement = management;
						
						newData.contactResource = item;
						
						
						let newDataObj = service.createRecord(newData);
						//this.set('_this.errorMessages',"testing");
						service.save(newDataObj).then(response => {
							console.log(response.accountManagement.get('id'));
							index++;
							if(index == jumlah){
								_this.set('rightActionInProgress',false);
								_this.router.transitionTo('account-management.detail' ,response.accountManagement.get('id'));
							}
							//set(_this.isvalid,true);
						}) 
						.catch((e) => {
							//alert(_this.errors.getErrorMessages(e));
							_this.set('rightActionInProgress',false);
							_this.set('errorMessages',_this.errors.getErrorMessages(e));
							window.scrollTo(0,0);
							//alert(_this.errorMessages);
							// this.set("rightActionInProgress", false);
							// this.set('_this.errorMessages', _this.errors.getErrorMessages(e));
							// alert(_this.errors.getErrorMessages(e));
							//isvalid = false;
						});
						
					}
					
				});
			
				//this.router.transitionTo('account-management.detail' ,management.id);
				

			}
		}
				
		},
	},
});