summaryrefslogtreecommitdiffstats
path: root/client/components/settings/peopleBody.js
diff options
context:
space:
mode:
authorThuan Pham Quoc <thuanpq.io@gmail.com>2017-11-07 22:26:21 +0700
committerThuan Pham Quoc <thuanpq.io@gmail.com>2017-11-07 22:26:21 +0700
commit1f6545e411fbe98fc1a0b1d5361c7a2bcc74056a (patch)
tree27ffa086405f5ea168422406559952926ed51287 /client/components/settings/peopleBody.js
parent29d54f46aa79a5f3fe067717fa418092e150eb47 (diff)
downloadwekan-1f6545e411fbe98fc1a0b1d5361c7a2bcc74056a.tar.gz
wekan-1f6545e411fbe98fc1a0b1d5361c7a2bcc74056a.tar.bz2
wekan-1f6545e411fbe98fc1a0b1d5361c7a2bcc74056a.zip
Added edit user from admin panel
Diffstat (limited to 'client/components/settings/peopleBody.js')
-rw-r--r--client/components/settings/peopleBody.js101
1 files changed, 93 insertions, 8 deletions
diff --git a/client/components/settings/peopleBody.js b/client/components/settings/peopleBody.js
index 058cb8d5..85376ebb 100644
--- a/client/components/settings/peopleBody.js
+++ b/client/components/settings/peopleBody.js
@@ -6,21 +6,106 @@ BlazeComponent.extendComponent({
this.loading = new ReactiveVar(false);
this.people = new ReactiveVar(true);
},
-
setError(error) {
this.error.set(error);
},
-
setLoading(w) {
this.loading.set(w);
},
-
peopleList() {
- this.users = Users.find({});
-
- this.users.forEach((user) => {
- console.log(JSON.stringify(user));
+ return Users.find({}, {
+ fields: {_id: true},
});
- return this.users;
},
}).register('people');
+
+Template.peopleRow.helpers({
+ userData() {
+ const userCollection = this.esSearch ? ESSearchResults : Users;
+ return userCollection.findOne(this.userId);
+ },
+});
+
+Template.editUserPopup.helpers({
+ user() {
+ return Users.findOne(this.userId);
+ },
+});
+
+BlazeComponent.extendComponent({
+ onCreated() {
+ },
+ user() {
+ return Users.findOne(this.userId);
+ },
+ events() {
+ return [{
+ 'click a.edit-user': Popup.open('editUser'),
+ }];
+ },
+}).register('peopleRow');
+
+Template.editUserPopup.events({
+ submit(evt, tpl) {
+ evt.preventDefault();
+ const user = Users.findOne(this.userId);
+ const fullname = tpl.find('.js-profile-fullname').value.trim();
+ const username = tpl.find('.js-profile-username').value.trim();
+ const initials = tpl.find('.js-profile-initials').value.trim();
+ const isAdmin = tpl.find('.js-profile-isadmin').value.trim();
+ const email = tpl.find('.js-profile-email').value.trim();
+ console.log('isAdmin', isAdmin);
+ let isChangeUserName = false;
+ let isChangeEmail = false;
+ Users.update(this.userId, {
+ $set: {
+ 'profile.fullname': fullname,
+ 'profile.initials': initials,
+ 'isAdmin': true,
+ },
+ });
+
+ isChangeUserName = username !== user.username;
+ isChangeEmail = email.toLowerCase() !== user.emails[0].address.toLowerCase();
+ if (isChangeUserName && isChangeEmail) {
+ Meteor.call('setUsernameAndEmail', username, email.toLowerCase(), function (error) {
+ const usernameMessageElement = tpl.$('.username-taken');
+ const emailMessageElement = tpl.$('.email-taken');
+ if (error) {
+ const errorElement = error.error;
+ if (errorElement === 'username-already-taken') {
+ usernameMessageElement.show();
+ emailMessageElement.hide();
+ } else if (errorElement === 'email-already-taken') {
+ usernameMessageElement.hide();
+ emailMessageElement.show();
+ }
+ } else {
+ usernameMessageElement.hide();
+ emailMessageElement.hide();
+ Popup.back();
+ }
+ });
+ } else if (isChangeUserName) {
+ Meteor.call('setUsername', username, function (error) {
+ const messageElement = tpl.$('.username-taken');
+ if (error) {
+ messageElement.show();
+ } else {
+ messageElement.hide();
+ Popup.back();
+ }
+ });
+ } else if (isChangeEmail) {
+ Meteor.call('setEmail', email.toLowerCase(), function (error) {
+ const messageElement = tpl.$('.email-taken');
+ if (error) {
+ messageElement.show();
+ } else {
+ messageElement.hide();
+ Popup.back();
+ }
+ });
+ } else Popup.back();
+ },
+});