-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
1,825 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<i class="fa fa-circle-o-notch fa-spin"></i> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import { computed } from '@ember/object'; | ||
import { inject as service } from '@ember/service'; | ||
import Component from '@ember/component'; | ||
|
||
import { task, timeout } from 'ember-concurrency'; | ||
import { validator, buildValidations } from 'ember-cp-validations'; | ||
|
||
|
||
const DEBOUNCE_MS = 250; | ||
|
||
/* Validations for adding unregistered contributor form. | ||
* fullName must be present and have at least three characters but not more than 255 | ||
* username (email) must be present and of appropriate format. | ||
*/ | ||
const Validations = buildValidations({ | ||
fullName: { | ||
description: 'Full name', | ||
validators: [ | ||
validator('presence', true), | ||
validator('length', { | ||
min: 3, | ||
max: 255, | ||
}), | ||
], | ||
}, | ||
email: { | ||
description: 'Email', | ||
validators: [ | ||
validator('presence', true), | ||
validator('format', { | ||
type: 'email', | ||
regex: /^[-a-z0-9~!$%^&*_=+}{'?]+(\.[-a-z0-9~!$%^&*_=+}{'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i, | ||
}), | ||
], | ||
}, | ||
}); | ||
|
||
export default Component.extend(Validations, { | ||
i18n: service(), | ||
store: service(), | ||
theme: service(), | ||
|
||
selectedUser: '', | ||
unregisteredUserName: '', | ||
unregisteredUserEmail: '', | ||
selectedUnregisteredUser: false, | ||
role: '', | ||
|
||
isFormValid: computed.alias('validations.isValid'), | ||
|
||
roleLabel: computed('role', function() { | ||
const roleOption = this.get('roleOptions').findBy('role', this.get('role')); | ||
return roleOption ? roleOption.label : 'Role'; | ||
}), | ||
|
||
selectedUserId: computed('selectedUser', 'unregisteredUserEmail', function() { | ||
return this.get('selectedUser.id') || this.get('unregisteredUserEmail'); | ||
}), | ||
|
||
disableSave: computed('role', 'selectedUser', 'unregisteredUserName', function() { | ||
return !this.get('role') || (!this.get('selectedUser') && !this.get('unregisteredUserName')); | ||
}), | ||
|
||
showInviteForm: computed('selectedUser', 'selectedUnregisteredUser', function() { | ||
return !this.get('selectedUser') && !this.get('selectedUnregisteredUser'); | ||
}), | ||
|
||
actions: { | ||
roleChanged(role) { | ||
this.set('role', role); | ||
}, | ||
cancel() { | ||
this.setProperties({ | ||
editingModerator: false, | ||
addingNewModerator: false, | ||
role: '', | ||
selectedUser: '', | ||
}); | ||
}, | ||
resetInviteForm() { | ||
this.$('#toggle-form').click(); | ||
this.setProperties({ | ||
unregisteredUserName: '', | ||
unregisteredUserEmail: '', | ||
}); | ||
}, | ||
selectUnregistered() { | ||
if (this.get('isFormValid')) { | ||
this.$('#toggle-form').click(); | ||
this.set('selectedUnregisteredUser', true); | ||
} | ||
}, | ||
}, | ||
|
||
searchUsers: task(function* (query) { | ||
yield timeout(DEBOUNCE_MS); | ||
|
||
try { | ||
const users = yield this.get('store').query('user', { | ||
filter: { | ||
'full_name,given_name,middle_names,family_name': query, | ||
}, | ||
page: { | ||
size: 15, | ||
}, | ||
}); | ||
|
||
const usersFullNames = users.content.map((user) => { | ||
const userData = { | ||
fullName: user.__data.fullName, | ||
profileImage: user.__data.links.profile_image, | ||
id: user.id, | ||
}; | ||
if (this.get('moderatorIds').includes(user.id)) { | ||
userData.disabled = true; | ||
} | ||
return userData; | ||
}); | ||
|
||
return usersFullNames; | ||
} catch (e) { | ||
this.get('toast').error(this.get('i18n').t('components.moderatorListAdd.userSearchError')); | ||
} | ||
}).restartable(), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
.ember-power-select-selected-item { | ||
margin-left: 0; | ||
} | ||
|
||
.moderators-add-row-container { | ||
display: inline-grid; | ||
grid-template-columns: 2fr 1fr 1fr; | ||
grid-template-rows: 1; | ||
align-items: center; | ||
justify-items: start; | ||
width: 100%; | ||
min-height: 60px; | ||
} | ||
|
||
.moderator-name { | ||
width: 100%; | ||
display: inline-flex; | ||
align-items: center; | ||
flex-wrap: wrap; | ||
|
||
.ember-power-select-trigger { | ||
min-width: 200px; | ||
background-color: transparent; | ||
} | ||
} | ||
|
||
@media (max-width: 700px) { | ||
.moderators-add-row-container { | ||
display: inline-grid; | ||
grid-template-columns: 2fr 2fr; | ||
grid-template-rows: 1fr 1fr; | ||
align-items: center; | ||
justify-items: start; | ||
width: 100%; | ||
min-height: 60px; | ||
} | ||
|
||
.moderator-name { | ||
grid-column-start: 1; | ||
grid-column-end: 3; | ||
} | ||
} | ||
|
||
.dropdown-link { | ||
color: $brand-primary; | ||
border: none; | ||
background-color: transparent; | ||
padding: 2px 2px; | ||
margin: 0 3px; | ||
|
||
:hover { | ||
background-color: none; | ||
border-color: none; | ||
} | ||
} | ||
|
||
.open > .dropdown-link { | ||
box-shadow: 0 0 3px; | ||
} | ||
|
||
.role-dropdown { | ||
.dropdown-button { | ||
min-width: 115px; | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
} | ||
.invite-dropdown { | ||
background-color: $color-white; | ||
} | ||
} | ||
|
||
.row-controls { | ||
display: flex; | ||
justify-content: flex-end; | ||
flex-wrap: wrap; | ||
justify-self: flex-end; | ||
} | ||
|
||
.unregistered-dropdown { | ||
background-color: $color-white; | ||
width: 275px; | ||
} | ||
|
||
.unregistered-form { | ||
padding: 10px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<div class="moderators-add-row-container p-h-md p-v-sm"> | ||
<div class="moderator-name"> | ||
{{#if (not selectedUnregisteredUser)}} | ||
{{#power-select | ||
disabled=loadingModerators | ||
options=users | ||
search=(perform searchUsers) | ||
placeholder='Search by name' | ||
selected=selectedUser | ||
onchange=(action (mut selectedUser)) as |user|}} | ||
<div style="display: flex; align-items: center;"> | ||
<img class="m-xs" src="{{user.profileImage}}" height=25 width=25 alt="{{user.fullName}} gravatar"> | ||
<div>{{user.fullName}}</div> | ||
</div> | ||
{{/power-select}} | ||
{{else}} | ||
<i>{{unregisteredUserName}}</i> | ||
{{/if}} | ||
{{#if showInviteForm}} | ||
<span class="p-l-xs">or</span> | ||
{{#bs-dropdown classNames="invite-dropdown" closeOnMenuClick=false as |dd|}} | ||
{{#dd.toggle id="toggle-form" classNames="btn dropdown-link"}} | ||
{{t 'components.moderatorListAdd.inviteText'}} | ||
{{/dd.toggle}} | ||
{{#dd.menu classNames="unregistered-dropdown" tagName="div" as |menu|}} | ||
{{#menu.item classNames="unregistered-form" tagName="form"}} | ||
<div> | ||
<label>{{t "components.unregisteredContributorForm.fullNameLabel"}}</label> | ||
<form> | ||
{{validated-input | ||
model=this | ||
valuePath='fullName' | ||
placeholder=(t "components.unregisteredContributorForm.fullNameLabel") | ||
value=unregisteredUserName}} | ||
</form> | ||
</div> | ||
<div> | ||
<label>{{t "components.unregisteredContributorForm.emailLabel"}}</label> | ||
<form> | ||
{{validated-input | ||
model=this | ||
valuePath='email' | ||
placeholder=(t "components.unregisteredContributorForm.emailLabel") | ||
value=unregisteredUserEmail}} | ||
</form> | ||
</div> | ||
<p class="text-muted"> | ||
{{t "components.unregisteredContributorForm.notifyMessage"}} | ||
</p> | ||
<div class="pull-right p-t-xs p-b-sm"> | ||
<button type="button" class="btn btn-default btn-small" {{action 'resetInviteForm'}}> | ||
{{t "global.cancel"}} | ||
</button> | ||
<button type="submit" class="btn btn-success btn-small m-l-xs" {{action 'selectUnregistered'}} disabled={{not isFormValid}}> | ||
{{t "global.add"}} | ||
</button> | ||
</div> | ||
{{/menu.item}} | ||
{{/dd.menu}} | ||
{{/bs-dropdown}} | ||
{{/if}} | ||
</div> | ||
{{#bs-dropdown classNames="role-dropdown" as |dd|}} | ||
{{#dd.button classNames="btn btn-default dropdown-button"}} | ||
{{roleLabel}} | ||
<span class="fa fa-caret-down p-l-xs"></span> | ||
{{/dd.button}} | ||
{{#dd.menu classNames="moderator-dropdown-menu" as |menu|}} | ||
{{#each roleOptions as |roleOption|}} | ||
{{#menu.item}} | ||
<button class="btn" {{action 'roleChanged' roleOption.role}}> | ||
{{roleOption.label}} | ||
<i class='{{if (eq role roleOption.role) 'fa fa-check selected' 'not-selected'}}'></i> | ||
</button> | ||
{{/menu.item}} | ||
{{/each}} | ||
{{/dd.menu}} | ||
{{/bs-dropdown}} | ||
<div class="row-controls"> | ||
<button class="btn btn-default" {{action 'cancel'}} disabled={{addModerator.isRunning}}> | ||
{{t 'global.cancel'}} | ||
</button> | ||
<button class="btn btn-success m-l-xs" disabled={{disableSave}} onclick={{perform addModerator selectedUserId role unregisteredUserName}}> | ||
{{#if addModerator.isRunning}} | ||
{{loading-btn-indicator}} | ||
{{else}} | ||
{{t 'global.save'}} | ||
{{/if}} | ||
</button> | ||
</div> | ||
</div> | ||
<div class="moderators-row-border"></div> |
Oops, something went wrong.