Moved views out of private folder
This commit is contained in:
49
rpg-docs/client/views/user/profile/usernameDialog.js
Normal file
49
rpg-docs/client/views/user/profile/usernameDialog.js
Normal file
@@ -0,0 +1,49 @@
|
||||
var getUsername = function() {
|
||||
var user = Meteor.user();
|
||||
return user.profile && user.profile.username || user.username;
|
||||
};
|
||||
|
||||
Template.usernameDialog.onCreated(function() {
|
||||
this.errorMessage = new ReactiveVar("");
|
||||
this.username = new ReactiveVar(getUsername());
|
||||
});
|
||||
|
||||
Template.usernameDialog.helpers({
|
||||
profileName: function() {
|
||||
return getUsername();
|
||||
},
|
||||
invalid: function() {
|
||||
return !!Template.instance().errorMessage.get();
|
||||
},
|
||||
errorMessage: function() {
|
||||
return Template.instance().errorMessage.get();
|
||||
},
|
||||
});
|
||||
|
||||
Template.usernameDialog.events({
|
||||
"change #usernameInput, input #usernameInput": function(event, instance) {
|
||||
var username = instance.find("#usernameInput").value;
|
||||
username = username.trim().toLowerCase().replace(/\s+/gm, "");
|
||||
if (username.length < 3){
|
||||
instance.errorMessage.set("Username too short");
|
||||
} else {
|
||||
instance.errorMessage.set("Validating...");
|
||||
Meteor.call("getUserId", username, function(err, userId){
|
||||
if (userId && userId !== Meteor.userId())
|
||||
instance.errorMessage.set("This username is taken");
|
||||
else
|
||||
instance.errorMessage.set("");
|
||||
});
|
||||
}
|
||||
},
|
||||
"tap #changeButton": function(event, instance){
|
||||
var username = instance.find("#usernameInput").value;
|
||||
username = username.trim().replace(/\s+/gm, " ");
|
||||
var profileName = username;
|
||||
username = username.toLowerCase().replace(/\s+/gm, "");
|
||||
Meteor.users.update(
|
||||
Meteor.userId(),
|
||||
{$set: {username: username, "profile.username": profileName}}
|
||||
);
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user