hino / app / controllers / multiple-attachment / edit.js
edit.js
Raw
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';

export default Controller.extend({
	multipleAttachment : service(),
	multipleAttachmentData : service(),
	coreAttachmentData : service(),
	multipleAttachmentDetailData : service(),
	session : service(),
	errors : service(),
	didValidate: false,
	rightActionInProgress: false,

	coreAttachments: Array(),

	formConfig : {
		name : { isEditable : true }, 
		multipleAttachmentDetails : { 
			multipleAttachment : { isEditable : true }, 
			name : { isEditable : true }, 
			coreAttachment : { isEditable : true }, 
			createdBy : { isEditable : true }, 
			updatedBy : { isEditable : true }, 
		},
		createdBy : { isEditable : true }, 
		updatedBy : { isEditable : true }, 
	},
	init() {
		this._super(...arguments);
		var coreAttachments = this.coreAttachmentData.getList();
		this.set("coreAttachments", coreAttachments);

	},

	actions: {
		onChangeCombo(propertyName, itemCollection) {
			this.set(propertyName, itemCollection);
		},

		async saveMultipleAttachment() {
			this.set("rightActionInProgress", true);
			this.get('model')
				.validate()
				.then(async ({ validations }) => {
					this.set('didValidate', true); 
					if (validations.get('isValid')) {
						this.set('multipleAttachment.model.isApprovalData', false);
						this.multipleAttachmentData.save(this.multipleAttachment.model).then(response => {
							if (response != undefined) {
								this.transitionToRoute('multiple-attachment.detail', response.id); 
							}
						})
						.catch((e) => {
							this.set("rightActionInProgress", false);
							this.set('errorMessages', this.errors.getErrorMessages(e));
						});
					} else {
						this.set("rightActionInProgress", false);
					}
			}); 
		},

		addRowData(modal_type) {
			if (modal_type == "multiple-attachment-details") {
				let data = this.multipleAttachmentDetailsData.createRecord();
				this.multipleAttachment.addRow(data, "multipleAttachmentDetails");
			}
		},
		deleteRowData(modal_type, data) {
			if (modal_type == "multiple-attachment-details") {
				this.multipleAttachment.deleteRow(data, "multipleAttachmentDetails");
			}
		},
	},
});