Skip to content

Commit 972831c

Browse files
committed
Implementation of "invite a new user" modal
Closes #3079 - new controller and template for invite-new-user-modal - actually triggers email invite via POST /ghost/api/v0.1/users/ - setting default language value (on the client) when creating a user - only available role is "Author" - pending 3196 - updates to UsersIndexController to allow dynamic property calculation and template rending
1 parent 7f33eb3 commit 972831c

File tree

6 files changed

+75
-15
lines changed

6 files changed

+75
-15
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
var InviteNewUserController = Ember.Controller.extend({
2+
3+
confirm: {
4+
accept: {
5+
text: 'send invitation now'
6+
},
7+
reject: {
8+
buttonClass: 'hidden'
9+
}
10+
},
11+
12+
// @TODO: replace with roles from server - see issue #3196
13+
roles: [
14+
{
15+
id: 3,
16+
name: 'Author'
17+
}
18+
],
19+
20+
actions: {
21+
confirmAccept: function () {
22+
var email = this.get('email'),
23+
role_id = this.get('role'),
24+
self = this,
25+
newUser;
26+
27+
newUser = this.store.createRecord('user', {
28+
'email': email,
29+
'role': role_id
30+
});
31+
32+
newUser.save().then(function () {
33+
var notificationText = 'Invitation sent! (' + email + ')';
34+
35+
self.notifications.showSuccess(notificationText, false);
36+
}).fail(function (error) {
37+
self.notifications.closePassive();
38+
self.notifications.showAPIError(error);
39+
});
40+
41+
this.set('email', null);
42+
this.set('role', null);
43+
44+
},
45+
46+
confirmReject: function () {
47+
return false;
48+
}
49+
}
50+
});
51+
52+
export default InviteNewUserController;
Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
1-
/*global alert */
21
var UsersIndexController = Ember.ArrayController.extend({
3-
activeUsers: function () {
4-
return this.content.filterBy('status', 'active');
5-
}.property('model'),
2+
users: Ember.computed.alias('model'),
63

7-
invitedUsers: function () {
8-
return this.content.filterBy('status', 'invited');
9-
}.property('model'),
4+
activeUsers: Ember.computed.filterBy('users', 'status', 'active'),
105

11-
actions: {
12-
addUser: function () {
13-
alert('@TODO: needs to show the "add user" modal - see issue #3079 on GitHub');
14-
}
15-
}
6+
invitedUsers: Ember.computed.filterBy('users', 'status', 'invited')
167
});
178

189
export default UsersIndexController;

core/client/models/user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var User = DS.Model.extend({
1111
location: DS.attr('string'),
1212
accessibility: DS.attr('string'),
1313
status: DS.attr('string'),
14-
language: DS.attr('string'),
14+
language: DS.attr('string', {defaultValue: 'en_US'}),
1515
meta_title: DS.attr('string'),
1616
meta_description: DS.attr('string'),
1717
last_login: DS.attr('moment-date'),

core/client/templates/components/gh-modal-dialog.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div id="modal-container" {{action bubbles=false preventDefault=false}}>
2-
<article {{bind-attr class="klass :js-modal"}}>
2+
<article {{bind-attr class="klass :js-modal"}}>
33
<section class="modal-content">
44
{{#if title}}<header class="modal-header"><h1>{{title}}</h1></header>{{/if}}
55
{{#if showClose}}<a class="close" href="" title="Close" {{action "closeModal"}}><span class="hidden">Close</span></a>{{/if}}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{{#gh-modal-dialog action="closeModal" showClose=true type="action" animation="fade"
2+
title="Invite a New User" confirm=confirm class="invite-new-user" }}
3+
4+
<fieldset>
5+
<div class="form-group">
6+
<label for="new-user-email"">Email Address</label>
7+
{{input class="email" id="new-user-email" type="email" placeholder="Email Address" name="email" autofocus="autofocus"
8+
autocapitalize="off" autocorrect="off" value=email }}
9+
</div>
10+
<div class="form-group">
11+
<label for="new-user-role">Role</label>
12+
{{view Ember.Select content=roles id="new-user-role" optionValuePath="content.id" optionLabelPath="content.name" name="role"
13+
value=role}}
14+
</div>
15+
</fieldset>
16+
17+
{{/gh-modal-dialog}}

core/client/templates/settings/users/index.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<button class="button-back">Back</button>
33
<h2 class="title">Users</h2>
44
<section class="page-actions">
5-
<a class="button-add" href="#" {{action "addUser"}} >New&nbsp;User</a>
5+
<a class="button-add" href="" {{action "openModal" "invite-new-user" this}} >New&nbsp;User</a>
66
</section>
77
</header>
88

0 commit comments

Comments
 (0)