From 972831c73320d5b1b468403f82e75268ffd12efb Mon Sep 17 00:00:00 2001 From: Maurice Williams Date: Sat, 5 Jul 2014 04:06:10 -0400 Subject: [PATCH] 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 --- .../controllers/modals/invite-new-user.js | 52 +++++++++++++++++++ .../controllers/settings/users/index.js | 15 ++---- core/client/models/user.js | 2 +- .../templates/components/gh-modal-dialog.hbs | 2 +- .../templates/modals/invite-new-user.hbs | 17 ++++++ .../client/templates/settings/users/index.hbs | 2 +- 6 files changed, 75 insertions(+), 15 deletions(-) create mode 100644 core/client/controllers/modals/invite-new-user.js create mode 100644 core/client/templates/modals/invite-new-user.hbs diff --git a/core/client/controllers/modals/invite-new-user.js b/core/client/controllers/modals/invite-new-user.js new file mode 100644 index 0000000000..16033e3769 --- /dev/null +++ b/core/client/controllers/modals/invite-new-user.js @@ -0,0 +1,52 @@ +var InviteNewUserController = Ember.Controller.extend({ + + confirm: { + accept: { + text: 'send invitation now' + }, + reject: { + buttonClass: 'hidden' + } + }, + + // @TODO: replace with roles from server - see issue #3196 + roles: [ + { + id: 3, + name: 'Author' + } + ], + + actions: { + confirmAccept: function () { + var email = this.get('email'), + role_id = this.get('role'), + self = this, + newUser; + + newUser = this.store.createRecord('user', { + 'email': email, + 'role': role_id + }); + + newUser.save().then(function () { + var notificationText = 'Invitation sent! (' + email + ')'; + + self.notifications.showSuccess(notificationText, false); + }).fail(function (error) { + self.notifications.closePassive(); + self.notifications.showAPIError(error); + }); + + this.set('email', null); + this.set('role', null); + + }, + + confirmReject: function () { + return false; + } + } +}); + +export default InviteNewUserController; diff --git a/core/client/controllers/settings/users/index.js b/core/client/controllers/settings/users/index.js index f731e21c06..6f1bf7305c 100644 --- a/core/client/controllers/settings/users/index.js +++ b/core/client/controllers/settings/users/index.js @@ -1,18 +1,9 @@ -/*global alert */ var UsersIndexController = Ember.ArrayController.extend({ - activeUsers: function () { - return this.content.filterBy('status', 'active'); - }.property('model'), + users: Ember.computed.alias('model'), - invitedUsers: function () { - return this.content.filterBy('status', 'invited'); - }.property('model'), + activeUsers: Ember.computed.filterBy('users', 'status', 'active'), - actions: { - addUser: function () { - alert('@TODO: needs to show the "add user" modal - see issue #3079 on GitHub'); - } - } + invitedUsers: Ember.computed.filterBy('users', 'status', 'invited') }); export default UsersIndexController; diff --git a/core/client/models/user.js b/core/client/models/user.js index ca4aef9072..13a3d85d91 100644 --- a/core/client/models/user.js +++ b/core/client/models/user.js @@ -11,7 +11,7 @@ var User = DS.Model.extend({ location: DS.attr('string'), accessibility: DS.attr('string'), status: DS.attr('string'), - language: DS.attr('string'), + language: DS.attr('string', {defaultValue: 'en_US'}), meta_title: DS.attr('string'), meta_description: DS.attr('string'), last_login: DS.attr('moment-date'), diff --git a/core/client/templates/components/gh-modal-dialog.hbs b/core/client/templates/components/gh-modal-dialog.hbs index 4a1e973532..93022b4940 100644 --- a/core/client/templates/components/gh-modal-dialog.hbs +++ b/core/client/templates/components/gh-modal-dialog.hbs @@ -1,5 +1,5 @@