diff options
author | Thuan Pham Quoc <thuanpq.io@gmail.com> | 2017-11-07 22:26:21 +0700 |
---|---|---|
committer | Thuan Pham Quoc <thuanpq.io@gmail.com> | 2017-11-07 22:26:21 +0700 |
commit | 1f6545e411fbe98fc1a0b1d5361c7a2bcc74056a (patch) | |
tree | 27ffa086405f5ea168422406559952926ed51287 /client | |
parent | 29d54f46aa79a5f3fe067717fa418092e150eb47 (diff) | |
download | wekan-1f6545e411fbe98fc1a0b1d5361c7a2bcc74056a.tar.gz wekan-1f6545e411fbe98fc1a0b1d5361c7a2bcc74056a.tar.bz2 wekan-1f6545e411fbe98fc1a0b1d5361c7a2bcc74056a.zip |
Added edit user from admin panel
Diffstat (limited to 'client')
-rw-r--r-- | client/components/settings/peopleBody.jade | 76 | ||||
-rw-r--r-- | client/components/settings/peopleBody.js | 101 |
2 files changed, 155 insertions, 22 deletions
diff --git a/client/components/settings/peopleBody.jade b/client/components/settings/peopleBody.jade index 726cc5ed..3ed2e4c8 100644 --- a/client/components/settings/peopleBody.jade +++ b/client/components/settings/peopleBody.jade @@ -19,18 +19,66 @@ template(name="people") template(name="peopleGeneral") table tbody + tr + th {{_ 'username'}} + th {{_ 'fullname'}} + th {{_ 'isAdmin'}} + th {{_ 'email'}} + th {{_ 'verified'}} + th {{_ 'createdAt'}} + th {{_ 'active'}} + th each user in peopleList - tr - th {{_ 'username'}} - th {{_ 'fullname'}} - th {{_ 'isAdmin'}} - th {{_ 'email'}} - th {{_ 'verified'}} - th {{_ 'createdAt'}} - tr - td {{ user.username }} - td {{ user.profile.fullname }} - td {{ user.isAdmin }} - td {{ user.emails.[0].address }} - td {{ user.emails.[0].verified }} - td {{ user.createdAt }} + +peopleRow(userId=user._id) + +template(name="peopleRow") + tr + td.username {{ userData.username }} + td {{ userData.profile.fullname }} + td + if userData.isAdmin + | true + else + | false + td {{ userData.emails.[0].address }} + td + if userData.emails.[0].verified + | true + else + | false + td {{ userData.createdAt }} + td + if userData.active + | true + else + | false + td + a.edit-user + | edit + +template(name="editUserPopup") + form + label.hide.userId(type="text" value=user._id) + label + | {{_ 'fullname'}} + input.js-profile-fullname(type="text" value=user.profile.fullname autofocus) + label + | {{_ 'username'}} + span.error.hide.username-taken + | {{_ 'error-username-taken'}} + input.js-profile-username(type="text" value=user.username) + label + | {{_ 'initials'}} + input.js-profile-initials(type="text" value=user.profile.initials) + label + | {{_ 'email'}} + span.error.hide.email-taken + | {{_ 'error-email-taken'}} + input.js-profile-email(type="email" value="{{user.emails.[0].address}}") + label + | {{_ 'isAdmin'}} + select.select-role.js-profile-isadmin + option(value="false") No + option(value="true" selected="{{user.isAdmin}}") Yes + + input.primary.wide(type="submit" value="{{_ 'save'}}") 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(); + }, +}); |