hino / app / controllers / team-resource / index.js
index.js
Raw
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
export default Controller.extend({
	teamResourceData : service(),
	accountTeamData : service(),
	router: service(),
	accountManagement:service(),
	management: '',
	queryParams: ['page', 'perPage', 'sort', 'filter'],
	page: 1,
	perPage: 10,
	filter: null,
	init() {
		this._super(...arguments);
		this.table = {
			mode: "list",
			model: "team-resource",
			columns: [
			{
				name: 'First Name',
				key: 'firstName',
				uri: "team-resource.detail",
				editUri: "team-resource.edit"
			},
			{
				name: 'RegistryID',
				key: 'registryId',
			
			},
			{
				name: 'Roles',
				key: 'teamRole.teamRole',
			},
			{
				name: 'Email',
				key: 'email',
			},
			{
				name: 'Organization',
				key: 'teamOrganizationsTeamOrganization',
			},
			// {
			// 	name: 'Resource Name',
			// 	key: 'resourceName',
				
			// },
			
			// {
			// 	name: 'Last Name',
			// 	key: 'lastName',
			// },
			
			
			// {
			// 	name: 'Phone',
			// 	key: 'phone',
			// },
			
			// {
			// 	name: 'Manager',
			// 	key: 'manager',
			// },
			] 
		};
	},
	actions : {
		deleteRow(data) {
			let result = confirm('Are you sure want to delete this data?');
			if (result) {
				if (data != null) {
					this.teamResourceData.delete(data).then(() => {
						this.router.transitionTo('team-resource.index');
					});
				}
			}
		},
		async saveContactResource() {
			this.set("rightActionInProgress", true);
			var cr =this.get('model');
			var serviceaccont = this.accountManagement;
			if(cr == null || cr == undefined){
				alert('data kosong')
			}
			var index =0;
			var jumlah =cr.filter(obj=>obj.chosee == true).length;
			let service = this.accountTeamData;
			var management = this.get('accountManagement.model');
			if(management == null || management == undefined){
				alert('kosong');
			}
			let _this = this;
			if(jumlah == 0){
				this.set('rightActionInProgress',false);
			}else{
			if(cr != null && cr != undefined  && ( management != null && management != undefined)){
				await cr.forEach(function(item) {
					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.teamResource = item;
						
						
						let newDataObj = service.createRecord(newData);
						//service.save(newDataObj);

						service.save(newDataObj).then(response => {
							console.log(response.accountManagement.get('id'));
							index++;
							console.log(newDataObj);
							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));
							//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);

			}
		}
				
		},
	},
});