class SoeFeedbacksView extends EICDomContent { DOMContentLoaded(options) { this.pic = options.pic; this.number = options.number; this.components = ui.eicfy(this.el); for(let model in options.models) this[model] = options.models[model]; this.pic = options.pic this.number = options.number let btAdd = this.components.find(o => o.el.classList.contains('add')); if(this.soe.hasPrivilege('create')) { btAdd.click = this.onAddFeedback.bind(this); } else { btAdd.disabled = true; } this.soe.fundings(this.pic, this.number).then(this.onFundingsUpdate.bind(this)); } onFundingsUpdate(payload) { let totalItems = 0; let totalFundings = 0; this.find('.soe-project > header h1').innerHTML = payload.proposal.acronym; this.find('.soe-project section .number').innerHTML = payload.proposal.number; this.find('.soe-project section .company').innerHTML = payload.company.name; this.find('.soe-project section .pic').innerHTML = payload.company.pic; this.find('.soe-project section .country').innerHTML = payload.company.country; this.find('.soe-project section .abstract').innerHTML = payload.proposal.abstract; let list = this.find('.soe-project .list') list.innerHTML = ''; for(let funding of payload.fundings) { let li = ui.create(`

Source(s): ${funding.fundingSource.map(item => app.meta.getItem( 'soe-fundings', item).label).join(' + ')}

Date: ${ui.format.date(funding.cutoffDate)}

${funding.fundingAmount ? '
Funding: ' + ui.format.currency(funding.fundingAmount) + '
': '' }
Duration: ${funding.duration} month(s)

${funding.additionalDetails}

Success Story: ${funding.successStory ? 'Yes': 'No'}

${funding.successStoryDetails}

creation: ${ui.format.date(funding.statusHistory[funding.statusHistory.length - 1].dateTime)} by ${funding.statusHistory[funding.statusHistory.length - 1].author}
Last update: ${ui.format.date(funding.statusHistory[0].dateTime)} by ${funding.statusHistory[0].author}
`); if(this.soe.hasPrivilege('update')) { let edit = ui.create(``); edit.addEventListener('click', this.onEditFeedback.bind(this)); li.querySelector('[eicmenu]').append(edit); } let history = ui.create(``); history.addEventListener('click', this.onHistoryFeedback.bind(this)); li.querySelector('[eicmenu]').append(history); ui.eicfy(li); list.append(li); totalItems++; totalFundings += funding.fundingAmount; } this.find('.insight .items').innerHTML = totalItems this.find('.insight .fundings').innerHTML = ui.format.currency( totalFundings) this.components.find(o => o.constructor.name == 'Card' && o.el.classList.contains('project')).loading = false; } async onAddFeedback(event) { event.stopPropagation(); event.preventDefault(); let result = await this.openDialog( await this.loadContent( 'projects/soe/dialogs/SoeFeedbackFormDialog', { title: 'Provide a feedback' }, { pic: this.pic, number: this.number, models: { soe: this.soe }, mode: 'create' } ) ); if(result) { this.soe.fundings(this.pic, this.number) .then(this.onFundingsUpdate.bind(this)); app.events.channel.dispatchEvent(new Event('soe_update')) } } async onEditFeedback(event) { //event.stopPropagation(); event.preventDefault(); console.log(event.currentTarget.dataset.id) let result = await this.openDialog( await this.loadContent( 'projects/soe/dialogs/SoeFeedbackFormDialog', { title: 'Editing feedback' }, { pic: this.pic, number: this.number, id: event.currentTarget.dataset.id, models: { soe: this.soe }, mode: 'edit' } ) ); if(result) { this.soe.fundings(this.pic, this.number) .then(this.onFundingsUpdate.bind(this)); app.events.channel.dispatchEvent(new Event('soe_update')); } } async onHistoryFeedback(event) { //event.stopPropagation(); event.preventDefault(); await this.openDialog( await this.loadContent( 'projects/soe/dialogs/SoeFeedbackHistoryDialog', { title: 'Feedbacks History' }, { id: event.currentTarget.dataset.id, models: { soe: this.soe } } ) ); } } app.registerClass('SoeFeedbacksView', SoeFeedbacksView);