Updated the new character dialog to Polymer 1
This commit is contained in:
@@ -1,13 +1,49 @@
|
||||
Template.newCharacterDialog.events({
|
||||
"tap #addButton": function(event, instance){
|
||||
Characters.insert({
|
||||
name: instance.find("#nameInput").value,
|
||||
gender: instance.find("#genderInput").value,
|
||||
race: instance.find("#raceInput").value,
|
||||
owner: Meteor.userId(),
|
||||
}, function(err, id){
|
||||
if (err) throw err;
|
||||
Router.go("characterSheet", {_id: id});
|
||||
});
|
||||
}
|
||||
Template.newCharacterDialog.onCreated(function(){
|
||||
this.character = {};
|
||||
this.schema = new SimpleSchema({
|
||||
//strings
|
||||
name: {type: String},
|
||||
gender: {type: String, optional: true},
|
||||
race: {type: String, optional: true},
|
||||
});
|
||||
this.context = this.schema.newContext();
|
||||
this.context.runOnce = false;
|
||||
});
|
||||
|
||||
Template.newCharacterDialog.helpers({
|
||||
invalid(){
|
||||
let context = Template.instance().context;
|
||||
let valid = context.isValid() && context.runOnce;
|
||||
return !valid;
|
||||
},
|
||||
errorAtts(key){
|
||||
let error = Template.instance().context.keyErrorMessage(key);
|
||||
if (error){
|
||||
return {
|
||||
invalid: true,
|
||||
["error-message"]: error,
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
changeFunction = function(field){
|
||||
return _.debounce(function(event, instance){
|
||||
instance.character[field] = event.currentTarget.value;
|
||||
instance.schema.clean(instance.character);
|
||||
instance.context.validate(instance.character);
|
||||
if (!instance.context.runOnce) instance.context.runOnce = true;
|
||||
}, 200);
|
||||
};
|
||||
|
||||
Template.newCharacterDialog.events({
|
||||
"input .nameInput": changeFunction("name"),
|
||||
"input .genderInput": changeFunction("gender"),
|
||||
"input .raceInput": changeFunction("race"),
|
||||
"click .cancelButton": function(event, instance){
|
||||
popDialogStack();
|
||||
},
|
||||
"click .addButton": function(event, instance){
|
||||
popDialogStack(instance.character);
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user