Hello,
I have a list of users, and buttons to control these users.
I can easily do things like disable the user, enable the user, as I can pass this._id , which grabs current row’s selected user. However if I try to update some data, eg. change the username’s last name, I can only get his lastname from the database using this.profile.name_last, which doesn’t change if I edit the last name field!
I tried:
main.js - client
email = template.find('#emailselect').value;
main.html - client
<td><input class="form-control input-lg emailselect" id="emailselect" type="email" value={{emails.[0].address}} /></td>
I do get an e-mail from console.log, but only the very first e-mail in the list.
main.js - client
'click .delete-user': function () {
if(confirm('Warning: Same readded user will lose their history. Are you sure?')){
Meteor.users.remove({ _id: this._id }, function (error, result) {
if (error) {
Bert.alert(' '+error+' ', 'danger' );
console.log("Error removing user: ", error);
} else {
Bert.alert('User has been removed!', 'success' );
console.log("Number of users removed: " + result);
}
})
}
},
'click .edit-user': function(event, template){
// var email = this.emails[0].address;
var email = template.find('#emailselect').value;
var username = this.username;
var firstname = this.profile.name_first;
var lastname = this.profile.name_last;
var payment = this.profile.payment;
var role = this.roles[0];
console.log(email, username, firstname, lastname, payment, role);
/*if(confirm('Save settings for this user?')){
Meteor.call('updateUser', this._id, email, username, firstname, lastname, payment, role, function (err, result) {
if (err) {
Bert.alert(' '+err+' ', 'danger' );
return false;
} else {
Bert.alert('User has been disabled successfully', 'success' );
}
})
} */
},
main.html
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th datafield="date">E-mail</th>
<th datefield="norm">Username</th>
<th datafield="over">First name</th>
<th datafield="act">Last name</th>
<th datafield="client">Hourly payment</th>
<th datafield="client">Permissions</th>
<th datafield="client">Disabled</th>
<th datafield="client">Control Panel</th>
</tr>
</thead>
<tbody>
{{#each user_list}}
<tr>
<td><input class="form-control input-lg emailselect" id="emailselect" type="email" value={{emails.[0].address}} /></td>
<td><input class="form-control input-lg username-select" id="userusername" type="text" value={{profile.username}} /></td>
<td><input class="form-control input-lg firstname-select" id="userfirst" type="text" value={{profile.name_first}} /></td>
<td><input class="form-control input-lg lastname-select" id="userlast" type="text" value={{profile.name_last}} /></td>
<td><input class="form-control input-lg payment-select" id="userpayment" type="number" step="0.1" value={{profile.payment}} /></td>
<td>
<select class="form-control role-select userrole" id="userrole">
<option> {{currentRole roles}} </option>
<option> {{otherRole roles}} </option>
</select>
</td>
<td>{{disabled}}</td>
<td>
<a style="text-decoration: inherit;color:inherit;cursor:pointer; margin-left:5px;" class="edit-user"><span class="glyphicon glyphicon-edit"></span></a>
<a style="text-decoration: inherit;color:inherit;cursor:pointer; margin-left:5px;" class="enable-user"><span class="glyphicon glyphicon-ok-circle"></span></a>
<a style="text-decoration: inherit;color:inherit;cursor:pointer; margin-left:5px;" class="disable-user"><span class="glyphicon glyphicon-ban-circle"></span></a>
<a style="text-decoration: inherit;color:inherit;cursor:pointer; margin-left:5px;" class="delete-user"><span class="glyphicon glyphicon-remove-circle"></span></a></td>
</tr>
{{/each}}
</tbody>
</table>
</div>
updateUser: function(userId, email, username, firstname, lastname, payment, role){
Meteor.users.update({_id: userId}, {$set: {"username": username}});
Meteor.users.update({_id: userId}, {$set: {"profile.name_first": firstname}});
Meteor.users.update({_id: userId}, {$set: {"profile.name_last": lastname}});
Meteor.users.update({_id: userId}, {$set: {"profile.payment": "9"}});
//Meteor.users.update({_id: userId}, {$set: {"emails.address": email}});
//Meteor.users.update({_id: userId}, {$set: {"roles": role}});
//Meteor.users.update({ _id: Meteor.userId(), 'emails.address': oldAddress }, { $set: { 'emails.address': newAddress }});
},