Skip to content

Commit b145eae

Browse files
Adds feature to transfer event to another user
fixes travis failure Introduces async-await
1 parent b32c89f commit b145eae

File tree

9 files changed

+181
-0
lines changed

9 files changed

+181
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import FormMixin from 'open-event-frontend/mixins/form';
2+
import ModalBase from 'open-event-frontend/components/modals/modal-base';
3+
4+
export default ModalBase.extend(FormMixin, {
5+
actions: {
6+
submit() {
7+
this.onValid(() => {
8+
this.sendAction('transferEvent');
9+
});
10+
},
11+
close() {
12+
if (!this.currentInvite.id) {
13+
this.currentInvite.unloadRecord();
14+
}
15+
this.set('isOpen', false);
16+
}
17+
},
18+
19+
getValidationRules() {
20+
21+
return {
22+
inline : true,
23+
delay : false,
24+
on : 'blur',
25+
fields : {
26+
newOwnerEmail: {
27+
identifier : 'user_email',
28+
rules : [
29+
{
30+
type : 'empty',
31+
prompt : this.l10n.t('Please enter an email for new organizer')
32+
},
33+
{
34+
type : 'email',
35+
prompt : this.l10n.t('Please enter a valid email address for new organizer')
36+
}
37+
]
38+
}
39+
}
40+
};
41+
}
42+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { computed } from '@ember/object';
2+
import ModalBase from 'open-event-frontend/components/modals/modal-base';
3+
4+
export default ModalBase.extend({
5+
isSmall : true,
6+
confirmEventName : '',
7+
isNameDifferent : computed('confirmEventName', function() {
8+
return this.eventName ? this.confirmEventName.toLowerCase() !== this.eventName.toLowerCase() : true;
9+
})
10+
});
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import Controller from '@ember/controller';
2+
import { isEqual } from '@ember/utils';
3+
4+
export default Controller.extend({
5+
6+
actions: {
7+
openEventTransferModal(id, name) {
8+
this.setProperties({
9+
'isEventTransferModalOpen' : true,
10+
'confirmEventName' : '',
11+
'eventId' : id,
12+
'eventName' : name
13+
});
14+
},
15+
openConfirmEventTransferModal() {
16+
const currentInvite = this.model.roleInvites.createRecord({});
17+
let { roles } = this.model;
18+
for (const role of roles ? roles.toArray() : []) {
19+
if (role.name === 'owner') {
20+
currentInvite.set('role', role);
21+
}
22+
}
23+
this.setProperties({
24+
'isEventTransferModalOpen' : false,
25+
'isConfirmEventTransferModalOpen' : true,
26+
'checked' : false,
27+
currentInvite
28+
});
29+
},
30+
async transferEvent() {
31+
try {
32+
this.set('isLoading', true);
33+
this.currentInvite.set('roleName', 'owner');
34+
const currentInviteObj = await this.currentInvite.save();
35+
if (isEqual(currentInviteObj, this.currentInvite)) {
36+
this.setProperties({
37+
'isConfirmEventTransferModalOpen' : false,
38+
'checked' : false
39+
});
40+
this.notify.success(this.l10n.t('Owner Role Invite sent successfully.'));
41+
this.set('isLoading', false);
42+
}
43+
} catch (error) {
44+
this.notify.error(this.l10n.t(error.message));
45+
this.set('isLoading', false);
46+
}
47+
}
48+
}
49+
});

app/router.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ router.map(function() {
7070
this.route('sessions-speakers');
7171
});
7272
this.route('export');
73+
this.route('settings');
7374
this.route('sessions', function() {
7475
this.route('list', { path: '/:session_status' });
7576
this.route('create');

app/routes/events/view/settings.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Route from '@ember/routing/route';
2+
3+
export default Route.extend({
4+
titleToken() {
5+
return this.l10n.t('Settings');
6+
},
7+
async model() {
8+
let eventDetails = this.modelFor('events.view');
9+
return {
10+
event : await eventDetails,
11+
roleInvites : await eventDetails.query('roleInvites', {}),
12+
roles : await this.store.findAll('role')
13+
};
14+
}
15+
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<div class="header">
2+
{{t 'You are transferring this event. This action cannot be undone.'}}
3+
<div class="muted small text">
4+
{{t 'All the event rights will be transferred to another user'}}
5+
</div>
6+
</div>
7+
<div class="content">
8+
<form class="ui {{if isLoading 'loading'}} form" id="eventTransferForm" autocomplete="off" {{action 'submit' on='submit' preventDefault=true}}>
9+
<div class="field">
10+
<label class="required">
11+
{{t 'User Email'}}
12+
</label>
13+
{{input type='text' name='user_email' value=currentInvite.email}}
14+
</div>
15+
<div class="field">
16+
{{ui-checkbox label=(t 'Please tick the box to agree and press TRANSFER') type="checkbox" checked=checked onChange=(action (mut checked))}}
17+
</div>
18+
</form>
19+
</div>
20+
<div class="actions">
21+
<button type="button" class="ui black button" {{action 'close'}}>
22+
{{t 'Cancel'}}
23+
</button>
24+
<button type="submit" form="eventTransferForm" class="ui red button {{if (not checked) 'disabled'}}">
25+
{{t 'Transfer'}}
26+
</button>
27+
</div>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<div class="header">
2+
{{t 'Are you sure you would like to transfer this event?'}}
3+
<div class="muted small text">
4+
{{t 'Transferring the event to another user will lead to you losing all the owner rights.'}}
5+
</div>
6+
</div>
7+
<div class="content">
8+
<div class="ui {{if isLoading 'loading'}} form" autocomplete="off">
9+
<div class="field">
10+
<div class="label">
11+
{{t 'Please enter the event-name to confirm that you want to transfer the event'}}
12+
</div>
13+
{{input type='text' name='confirm_name' value=confirmEventName required=true}}
14+
</div>
15+
</div>
16+
</div>
17+
<div class="actions">
18+
<button type="button" class="ui black button" {{action 'close'}}>
19+
{{t 'Cancel'}}
20+
</button>
21+
<button {{action openConfirmEventTransferModal}} class="ui red button {{if isNameDifferent 'disabled'}}">
22+
{{t 'Proceed'}}
23+
</button>
24+
</div>

app/templates/events/view.hbs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@
8181
{{#link-to 'events.view.export' class='item'}}
8282
{{t 'Export'}}
8383
{{/link-to}}
84+
{{#link-to 'events.view.settings' class='item'}}
85+
{{t 'Settings'}}
86+
{{/link-to}}
8487
{{/tabbed-navigation}}
8588
</div>
8689
</div>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<div class="row">
2+
<p>
3+
{{t 'Transfer ownership of this event to another user. You\'ll lose all the owner rights once they accept the ownership.'}}
4+
</p>
5+
<button {{action 'openEventTransferModal' model.event.id model.event.name}} class='ui red button'>
6+
{{t 'Transfer Ownership'}}
7+
</button>
8+
</div>
9+
{{modals/event-transfer-modal isLoading=isLoading isOpen=isEventTransferModalOpen confirmEventName=confirmEventName eventName=eventName openConfirmEventTransferModal=(action 'openConfirmEventTransferModal') transferEvent=(action 'transferEvent' model)}}
10+
{{modals/confirm-event-transfer-modal currentInvite=currentInvite isLoading=isLoading isOpen=isConfirmEventTransferModalOpen checked=checked transferEvent=(action 'transferEvent')}}

0 commit comments

Comments
 (0)