diff --git a/rpg-docs/client/views/character/journal/classDialog/classDialog.html b/rpg-docs/client/views/character/journal/classDialog/classDialog.html index 292c3469..6162104c 100644 --- a/rpg-docs/client/views/character/journal/classDialog/classDialog.html +++ b/rpg-docs/client/views/character/journal/classDialog/classDialog.html @@ -1,8 +1,8 @@ \ No newline at end of file + diff --git a/rpg-docs/client/views/character/journal/classDialog/classDialog.js b/rpg-docs/client/views/character/journal/classDialog/classDialog.js index 09bf7afb..3ecc36d3 100644 --- a/rpg-docs/client/views/character/journal/classDialog/classDialog.js +++ b/rpg-docs/client/views/character/journal/classDialog/classDialog.js @@ -1,28 +1,35 @@ -Template.classDialog.onRendered(function(){ - updatePolymerInputs(this); -}); - -Template.classDialog.events({ - "color-change": function(event, instance){ - Classes.update(instance.data.classId, {$set: {color: event.color}}); - }, - "tap #deleteButton": function(event, instance){ - Classes.softRemoveNode(instance.data.classId); - GlobalUI.deletedToast(instance.data.classId, "Classes", "Class"); - GlobalUI.closeDetail(); - }, - "change #classNameInput": function(event){ - var value = event.currentTarget.value; - Classes.update(this._id, {$set: {name: value}}); - }, - "change #levelValueInput": function(event){ - var value = event.currentTarget.value; - Classes.update(this._id, {$set: {level: value}}); - }, -}); +const debounce = (f) => _.debounce(f, 300); Template.classDialog.helpers({ class: function(){ return Classes.findOne(this.classId); } }); + +Template.classDialog.events({ + "color-change": function(event, instance){ + Classes.update(instance.data.classId, {$set: {color: event.color}}); + }, + "click #deleteButton": function(event, instance){ + Classes.softRemoveNode(instance.data.classId); + GlobalUI.deletedToast(instance.data.classId, "Classes", "Class"); + popDialogStack(); + }, + "input #classNameInput, change #classNameInput": debounce(function(event){ + var value = event.currentTarget.value; + Classes.update(this._id, { + $set: {name: value} + }, { + removeEmptyStrings: false, + trimStrings: false, + }); + }), + "input #levelValueInput, change #levelValueInput": debounce(function(event){ + var value = event.currentTarget.value; + Classes.update(this._id, { + $set: {level: value} + }, { + removeEmptyStrings: false, + }); + }), +}); diff --git a/rpg-docs/client/views/character/journal/experienceDialog/experienceDialog.html b/rpg-docs/client/views/character/journal/experienceDialog/experienceDialog.html index 6573d590..d76a7cd1 100644 --- a/rpg-docs/client/views/character/journal/experienceDialog/experienceDialog.html +++ b/rpg-docs/client/views/character/journal/experienceDialog/experienceDialog.html @@ -1,7 +1,7 @@ diff --git a/rpg-docs/client/views/character/journal/experienceDialog/experienceDialog.js b/rpg-docs/client/views/character/journal/experienceDialog/experienceDialog.js index ef76f017..a4af9661 100644 --- a/rpg-docs/client/views/character/journal/experienceDialog/experienceDialog.js +++ b/rpg-docs/client/views/character/journal/experienceDialog/experienceDialog.js @@ -1,7 +1,3 @@ -Template.experienceEdit.onRendered(function(){ - updatePolymerInputs(this); -}); - Template.experienceDialog.helpers({ experience: function(){ Experiences.findOne(this.experienceId); @@ -20,21 +16,40 @@ Template.experienceDialog.events({ instance.data.experienceId, "Experiences", "Experience" ); - GlobalUI.closeDetail(); + popDialogStack(); }, }); +const debounce = (f) => _.debounce(f, 300); + Template.experienceEdit.events({ - "change #experienceNameInput": function(event){ + "input #experienceNameInput, change #experienceNameInput": + debounce(function(event){ var value = event.currentTarget.value; - Experiences.update(this._id, {$set: {name: value}}); - }, - "change #valueInput": function(event){ + Experiences.update(this._id, { + $set: {name: value} + }, { + removeEmptyStrings: false, + trimStrings: false, + }); + }), + "input #valueInput, change #valueInput": + debounce(function(event){ var value = +event.currentTarget.value; - Experiences.update(this._id, {$set: {value: value}}); - }, - "change #experienceDescriptionInput": function(event){ + Experiences.update(this._id, { + $set: {value: value} + }, { + removeEmptyStrings: false, + }); + }), + "input #experienceDescriptionInput": + debounce(function(event){ var value = event.currentTarget.value; - Experiences.update(this._id, {$set: {description: value}}); - }, + Experiences.update(this._id, { + $set: {description: value} + }, { + removeEmptyStrings: false, + trimStrings: false, + }); + }), }); diff --git a/rpg-docs/client/views/character/journal/journal.html b/rpg-docs/client/views/character/journal/journal.html index f6c09d38..ca5c1c14 100644 --- a/rpg-docs/client/views/character/journal/journal.html +++ b/rpg-docs/client/views/character/journal/journal.html @@ -1,108 +1,91 @@ diff --git a/rpg-docs/client/views/character/journal/journal.js b/rpg-docs/client/views/character/journal/journal.js index 6686e14e..959b0d15 100644 --- a/rpg-docs/client/views/character/journal/journal.js +++ b/rpg-docs/client/views/character/journal/journal.js @@ -53,101 +53,93 @@ Template.journal.helpers({ }); Template.journal.events({ - "tap .noteTop": function(event){ - GlobalUI.setDetail({ + "click .noteTop": function(event){ + pushDialogStack({ template: "noteDialog", data: {noteId: this._id, charId: this.charId}, - heroId: this._id, + element: event.currentTarget.parentElement, }); }, - "tap .experience": function(event){ - GlobalUI.setDetail({ + "click .experience": function(event){ + pushDialogStack({ template: "experienceDialog", data: {experienceId: this._id, charId: this.charId}, - heroId: this._id, + element: event.currentTarget, }); }, - "tap .class": function(event){ - GlobalUI.setDetail({ + "click .class": function(event){ + pushDialogStack({ template: "classDialog", data: {classId: this._id, charId: this.charId}, - heroId: this._id, + element: event.currentTarget, }); }, - "tap .race": function(event){ - GlobalUI.setDetail({ + "click .race": function(event){ + pushDialogStack({ template: "raceDialog", data: {charId: this._id}, - heroId: this._id + "race", + element: event.currentTarget, }); }, - "tap #addNote": function(event){ + "click #addNote": function(event, instance){ var charId = this._id; - Notes.insert({ + var noteId = Notes.insert({ name: "New Note", charId: charId, - }, function(error, id){ - if (!error){ - GlobalUI.setDetail({ - template: "noteDialog", - data: {noteId: id, charId: charId, startEditing: true}, - heroId: id, - }); - } + }); + pushDialogStack({ + template: "noteDialog", + data: {noteId: noteId, charId: charId, startEditing: true}, + element: event.currentTarget, + returnElement: () => instance.find(`.note[data-id='${noteId}']`), }); }, - "tap #addXP": function(event){ + "click #addXP": function(event, instance){ var charId = this._id; - Experiences.insert({ + var expId = Experiences.insert({ charId: charId - }, function(error, id){ - if (!error){ - GlobalUI.setDetail({ - template: "experienceDialog", - data: {experienceId: id, charId: charId, startEditing: true}, - heroId: id, - }); - } + }); + pushDialogStack({ + template: "experienceDialog", + data: {experienceId: expId, charId: charId, startEditing: true}, + element: event.currentTarget, + returnElement: () => instance.find(`.experience[data-id='${expId}']`), }); }, - "tap #addClassButton":function(event){ + "click #addClassButton":function(event, instance){ var charId = this._id; - Classes.insert({ + var classId = Classes.insert({ charId: charId, name: "new Class", level: 1, - }, function(error, id){ - if (!error){ - GlobalUI.setDetail({ - template: "classDialog", - data: {classId: id, charId: charId, startEditing: true}, - heroId: id, - }); - } + }); + pushDialogStack({ + template: "classDialog", + data: {classId: classId, charId: charId, startEditing: true}, + element: event.currentTarget, + returnElement: () => instance.find(`.class[data-id='${classId}']`), }); }, - "tap #moreExperiences": function(event){ - var inst = Template.instance(); - inst.experiencesLimit.set( - inst.experiencesLimit.get() + + "click #moreExperiences": function(event, instance){ + instance.experiencesLimit.set( + instance.experiencesLimit.get() + (this.settings && this.settings.experiencesInc || 10) ); }, - "tap #lessExperiences": function(event){ - var inst = Template.instance(); - inst.experiencesLimit.set( + "click #lessExperiences": function(event, instance){ + instance.experiencesLimit.set( this.settings && this.settings.experiencesInc || 10 ); - //scroll to the top of the div - inst.$(".scroll-y").animate({ + // Scroll to the top of the div + instance.$(".scroll-y").animate({ scrollTop: ( - inst.$(".scroll-y").scrollTop() + - inst.$(".experiencesCard").position().top - + instance.$(".scroll-y").scrollTop() + + instance.$(".experiencesCard").position().top - 8 ) }, 300); - //HACK giggle the columns :( to workaround chrome bug that stops .containers height from updating - var cs = inst.$(".containers").removeClass("containers"); + // HACK jiggle the columns :( to workaround chrome bug that stops .containers height from updating + var cs = instance.$(".containers").removeClass("containers"); _.defer(function(){cs.addClass("containers");}); }, }); diff --git a/rpg-docs/client/views/character/journal/noteDialog/noteDialog.html b/rpg-docs/client/views/character/journal/noteDialog/noteDialog.html index ecb6c682..d099eb44 100644 --- a/rpg-docs/client/views/character/journal/noteDialog/noteDialog.html +++ b/rpg-docs/client/views/character/journal/noteDialog/noteDialog.html @@ -1,7 +1,7 @@ diff --git a/rpg-docs/client/views/character/journal/noteDialog/noteDialog.js b/rpg-docs/client/views/character/journal/noteDialog/noteDialog.js index 84a4a6c8..db566503 100644 --- a/rpg-docs/client/views/character/journal/noteDialog/noteDialog.js +++ b/rpg-docs/client/views/character/journal/noteDialog/noteDialog.js @@ -11,21 +11,36 @@ Template.noteDialog.events({ "tap #deleteButton": function(event, instance){ Notes.softRemove(instance.data.noteId); GlobalUI.deletedToast(instance.data.noteId, "Notes", "Note"); - GlobalUI.closeDetail(); + popDialogStack(); }, }); -Template.noteDialogEdit.onRendered(function(){ - updatePolymerInputs(this); -}); +const debounce = (f) => _.debounce(f, 300); Template.noteDialogEdit.events({ - "change #noteNameInput, input #noteNameInput": function(event){ + "change #noteNameInput, input #noteNameInput": debounce(function(event){ + const input = event.currentTarget; + var name = input.value; + if (!name){ + input.invalid = true; + input.errorMessage = "Name is required"; + } else { + input.invalid = false; + Notes.update(this._id, { + $set: {name: name} + }, { + removeEmptyStrings: false, + trimStrings: false, + }); + } + }), + "input #noteDescriptionInput": debounce(function(event){ var value = event.currentTarget.value; - Notes.update(this._id, {$set: {name: value}}); - }, - "change #noteDescriptionInput": function(event){ - var value = event.currentTarget.value; - Notes.update(this._id, {$set: {description: value}}); - }, + Notes.update(this._id, { + $set: {description: value} + }, { + removeEmptyStrings: false, + trimStrings: false, + }); + }), }); diff --git a/rpg-docs/client/views/character/journal/raceDialog/raceDialog.html b/rpg-docs/client/views/character/journal/raceDialog/raceDialog.html index aa90ee68..ab4c73c5 100644 --- a/rpg-docs/client/views/character/journal/raceDialog/raceDialog.html +++ b/rpg-docs/client/views/character/journal/raceDialog/raceDialog.html @@ -1,13 +1,13 @@ \ No newline at end of file + diff --git a/rpg-docs/client/views/character/journal/raceDialog/raceDialog.js b/rpg-docs/client/views/character/journal/raceDialog/raceDialog.js index abf9eaca..25032676 100644 --- a/rpg-docs/client/views/character/journal/raceDialog/raceDialog.js +++ b/rpg-docs/client/views/character/journal/raceDialog/raceDialog.js @@ -1,12 +1,13 @@ -Template.raceDialog.onRendered(function(){ - updatePolymerInputs(this); -}); - Template.raceDialog.events({ - "change #raceInput": function(event){ + "input #raceInput, change #raceInput": _.debounce(function(event){ var value = event.currentTarget.value; - Characters.update(this.charId, {$set: {race: value}}); - } + Characters.update(this.charId, { + $set: {race: value} + }, { + removeEmptyStrings: false, + trimStrings: false, + }); + }, 300), }); Template.raceDialog.helpers({