From d573b325d5d857325781d24af21571c5a0949b0d Mon Sep 17 00:00:00 2001 From: Thaum Date: Wed, 25 Mar 2015 07:33:27 +0000 Subject: [PATCH] All delete buttons now soft-delete with toast prompt to undo --- rpg-docs/client/globalHelpers/GlobalUI.js | 10 +++++----- .../views/character/effects/effectEdit/effectEdit.js | 3 ++- .../character/features/featureDialog/featureDialog.js | 5 +++-- .../inventory/containerDialog/containerDialog.js | 3 ++- .../views/character/inventory/itemDialog/itemDialog.js | 3 ++- .../views/character/journal/classDialog/classDialog.js | 3 ++- .../journal/experienceDialog/experienceDialog.js | 3 ++- .../views/character/journal/noteDialog/noteDialog.js | 3 ++- .../views/character/spells/spellDialog/spellDialog.js | 3 ++- .../spells/spellListDialog/spellListDialog.js | 3 ++- rpg-docs/client/views/layout/layout.html | 8 ++++++-- .../client/views/paperTemplates/undoToast/undoToast.js | 5 ++++- 12 files changed, 34 insertions(+), 18 deletions(-) diff --git a/rpg-docs/client/globalHelpers/GlobalUI.js b/rpg-docs/client/globalHelpers/GlobalUI.js index e8f2add9..c101f40c 100644 --- a/rpg-docs/client/globalHelpers/GlobalUI.js +++ b/rpg-docs/client/globalHelpers/GlobalUI.js @@ -11,7 +11,7 @@ this.GlobalUI = (function() { Session.set("global.ui.toastData", opts.data); return toast.show(); }; - + GlobalUI.deletedToast = function(id, collection, itemName){ GlobalUI.toast({ text: itemName? itemName + " deleted" : "Deleted item from" + collection, @@ -20,15 +20,15 @@ this.GlobalUI = (function() { id: id, collection: collection } - }) - } + }); + }; GlobalUI.setDialog = function(opts){ this.dialog = $("[global-dialog]")[0]; Session.set("global.ui.dialogHeader", opts.heading); Session.set("global.ui.dialogData", opts.data); Session.set("global.ui.dialogTemplate", opts.template); - Session.set("global.ui.dialogFullOnMobile", opts.fullOnMobile != null); + Session.set("global.ui.dialogFullOnMobile", opts.fullOnMobile !== null); }; GlobalUI.showDialog = function(opts) { @@ -36,7 +36,7 @@ this.GlobalUI = (function() { Session.set("global.ui.dialogHeader", opts.heading); Session.set("global.ui.dialogData", opts.data); Session.set("global.ui.dialogTemplate", opts.template); - Session.set("global.ui.dialogFullOnMobile", opts.fullOnMobile != null); + Session.set("global.ui.dialogFullOnMobile", opts.fullOnMobile !== null); return Tracker.afterFlush((function(_this) { return function() { return _this.dialog.open(); diff --git a/rpg-docs/client/views/character/effects/effectEdit/effectEdit.js b/rpg-docs/client/views/character/effects/effectEdit/effectEdit.js index ac8a5a47..ec0acf8a 100644 --- a/rpg-docs/client/views/character/effects/effectEdit/effectEdit.js +++ b/rpg-docs/client/views/character/effects/effectEdit/effectEdit.js @@ -144,7 +144,8 @@ Template.regularEffectValue.helpers({ Template.effectEdit.events({ "tap #deleteEffect": function(event){ - Effects.remove(this._id); + Effects.softRemove(this._id); + GlobalUI.deletedToast(this._id, "Effects", "Effect"); }, "core-select #statGroupDropDown": function(event){ var detail = event.originalEvent.detail; diff --git a/rpg-docs/client/views/character/features/featureDialog/featureDialog.js b/rpg-docs/client/views/character/features/featureDialog/featureDialog.js index 9fb190d2..75c5f597 100644 --- a/rpg-docs/client/views/character/features/featureDialog/featureDialog.js +++ b/rpg-docs/client/views/character/features/featureDialog/featureDialog.js @@ -3,8 +3,9 @@ Template.featureDialog.events({ Features.update(instance.data.featureId, {$set: {color: event.color}}); }, "tap #deleteButton": function(event, instance){ - Features.remove(instance.data.featureId); - GlobalUI.closeDetail() + Features.softRemove(instance.data.featureId); + GlobalUI.deletedToast(instance.data.featureId, "Features", "Feature"); + GlobalUI.closeDetail(); }, "change #featureNameInput": function(event){ var name = Template.instance().find("#featureNameInput").value; diff --git a/rpg-docs/client/views/character/inventory/containerDialog/containerDialog.js b/rpg-docs/client/views/character/inventory/containerDialog/containerDialog.js index 2c4647e5..2b791214 100644 --- a/rpg-docs/client/views/character/inventory/containerDialog/containerDialog.js +++ b/rpg-docs/client/views/character/inventory/containerDialog/containerDialog.js @@ -9,7 +9,8 @@ Template.containerDialog.events({ Containers.update(instance.data.containerId, {$set: {color: event.color}}); }, "tap #deleteButton": function(event, instance){ - Containers.remove(instance.data.containerId); + Containers.softRemove(instance.data.containerId); + GlobalUI.deletedToast(instance.data.containerId, "Containers", "Container and contents"); GlobalUI.closeDetail() }, //TODO validate input (integer, non-negative, etc) for these inputs and give validation errors diff --git a/rpg-docs/client/views/character/inventory/itemDialog/itemDialog.js b/rpg-docs/client/views/character/inventory/itemDialog/itemDialog.js index 4a5f56be..1290a3a9 100644 --- a/rpg-docs/client/views/character/inventory/itemDialog/itemDialog.js +++ b/rpg-docs/client/views/character/inventory/itemDialog/itemDialog.js @@ -38,7 +38,8 @@ Template.itemDialog.events({ Items.update(instance.data.itemId, {$set: {color: event.color}}); }, "tap #deleteButton": function(event, instance){ - Items.remove(instance.data.itemId); + Items.softRemove(instance.data.itemId); + GlobalUI.deletedToast(instance.data.itemId, "Items", "Item"); GlobalUI.closeDetail() }, //TODO validate input (integer, non-negative, etc) for these inputs and give validation errors diff --git a/rpg-docs/client/views/character/journal/classDialog/classDialog.js b/rpg-docs/client/views/character/journal/classDialog/classDialog.js index 0a43b849..26b68800 100644 --- a/rpg-docs/client/views/character/journal/classDialog/classDialog.js +++ b/rpg-docs/client/views/character/journal/classDialog/classDialog.js @@ -1,6 +1,7 @@ Template.classDialog.events({ "tap #deleteButton": function(event, instance){ - Classes.remove(instance.data.classId); + Classes.softRemove(instance.data.classId); + GlobalUI.deletedToast(instance.data.classId, "Classes", "Class"); GlobalUI.closeDetail() }, "change #classNameInput": function(event){ diff --git a/rpg-docs/client/views/character/journal/experienceDialog/experienceDialog.js b/rpg-docs/client/views/character/journal/experienceDialog/experienceDialog.js index 1e52a691..99dd4a09 100644 --- a/rpg-docs/client/views/character/journal/experienceDialog/experienceDialog.js +++ b/rpg-docs/client/views/character/journal/experienceDialog/experienceDialog.js @@ -1,6 +1,7 @@ Template.experienceDialog.events({ "tap #deleteButton": function(event, instance){ - Experiences.remove(instance.data.experienceId); + Experiences.softRemove(instance.data.experienceId); + GlobalUI.deletedToast(instance.data.experienceId, "Experiences", "Experience"); GlobalUI.closeDetail() }, //TODO validate input (integer, non-negative, etc) for these inputs and give validation errors diff --git a/rpg-docs/client/views/character/journal/noteDialog/noteDialog.js b/rpg-docs/client/views/character/journal/noteDialog/noteDialog.js index 2bd9177f..28e35d96 100644 --- a/rpg-docs/client/views/character/journal/noteDialog/noteDialog.js +++ b/rpg-docs/client/views/character/journal/noteDialog/noteDialog.js @@ -3,7 +3,8 @@ Template.noteDialog.events({ Notes.update(instance.data.noteId, {$set: {color: event.color}}); }, "tap #deleteButton": function(event, instance){ - Notes.remove(instance.data.noteId); + Notes.softRemove(instance.data.noteId); + GlobalUI.deletedToast(instance.data.noteId, "Notes", "Note"); GlobalUI.closeDetail() }, "change #noteNameInput, input #noteNameInput": function(event){ diff --git a/rpg-docs/client/views/character/spells/spellDialog/spellDialog.js b/rpg-docs/client/views/character/spells/spellDialog/spellDialog.js index ef46a8ca..f89452bd 100644 --- a/rpg-docs/client/views/character/spells/spellDialog/spellDialog.js +++ b/rpg-docs/client/views/character/spells/spellDialog/spellDialog.js @@ -38,7 +38,8 @@ Template.spellDialog.events({ Spells.update(instance.data.spellId, {$set: {color: event.color}}); }, "tap #deleteButton": function(event, instance){ - Spells.remove(instance.data.spellId); + Spells.softRemove(instance.data.spellId); + GlobalUI.deletedToast(instance.data.spellId, "Spells", "Spell"); GlobalUI.closeDetail() }, "change #spellNameInput, input #spellNameInput": function(event){ diff --git a/rpg-docs/client/views/character/spells/spellListDialog/spellListDialog.js b/rpg-docs/client/views/character/spells/spellListDialog/spellListDialog.js index 9c17d93a..efeb9bce 100644 --- a/rpg-docs/client/views/character/spells/spellListDialog/spellListDialog.js +++ b/rpg-docs/client/views/character/spells/spellListDialog/spellListDialog.js @@ -3,7 +3,8 @@ Template.spellListDialog.events({ SpellLists.update(instance.data.spellListId, {$set: {color: event.color}}); }, "tap #deleteButton": function(event, instance){ - SpellLists.remove(instance.data.spellListId); + SpellLists.softRemove(instance.data.spellListId); + GlobalUI.deletedToast(instance.data.spellListId, "SpellLists", "Spell list and contents"); GlobalUI.closeDetail() }, //TODO clean up String -> num here so they don't need casting by Schema.clean diff --git a/rpg-docs/client/views/layout/layout.html b/rpg-docs/client/views/layout/layout.html index 5c154ab2..e29264da 100644 --- a/rpg-docs/client/views/layout/layout.html +++ b/rpg-docs/client/views/layout/layout.html @@ -78,9 +78,13 @@ {{/if}} - - {{#if session globalToastTemplate}} + + {{#if globalToastTemplate}} {{> UI.dynamic template=globalToastTemplate data=globalToastData}} + {{else}} +
+ No Toast template defined +
{{/if}}
\ No newline at end of file diff --git a/rpg-docs/client/views/paperTemplates/undoToast/undoToast.js b/rpg-docs/client/views/paperTemplates/undoToast/undoToast.js index 4a891177..ac3d033d 100644 --- a/rpg-docs/client/views/paperTemplates/undoToast/undoToast.js +++ b/rpg-docs/client/views/paperTemplates/undoToast/undoToast.js @@ -1,7 +1,10 @@ Template.undoToast.events({ 'tap #undoButton': function(event, instance){ var collection = window[this.collection]; - if(!collection) return; + if(!collection){ + console.warn("Collection with name ", this.collection, " could not be found"); + return; + } collection.restore(this.id); } });