From f7a3929c056883da8b740588c061505cc6543b88 Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Wed, 25 Jan 2017 08:40:30 +0200 Subject: [PATCH] Fixed toast --- rpg-docs/client/globalHelpers/GlobalUI.js | 156 ++---------------- .../features/featureDialog/featureDialog.js | 2 +- rpg-docs/client/views/layout/layout.html | 4 +- 3 files changed, 20 insertions(+), 142 deletions(-) diff --git a/rpg-docs/client/globalHelpers/GlobalUI.js b/rpg-docs/client/globalHelpers/GlobalUI.js index cbe49002..cf757253 100644 --- a/rpg-docs/client/globalHelpers/GlobalUI.js +++ b/rpg-docs/client/globalHelpers/GlobalUI.js @@ -1,13 +1,18 @@ this.GlobalUI = (function() { function GlobalUI() {} - - GlobalUI.dialog = {}; - - GlobalUI.toast = function(text) { - if (!GlobalUI._toast) - GlobalUI._toast = $("#global-toast")[0]; - GlobalUI._toast.text = text; - return GlobalUI._toast.show(); + var toast; + GlobalUI.toast = function(opts) { + if (!toast) toast = $("#global-toast")[0]; + if (_.isObject(opts)){ + toast.text = opts.text; + Session.set("global.ui.toastTemplate", opts.template); + Session.set("global.ui.toastData", opts.data); + } else { + toast.text = opts; + Session.set("global.ui.toastTemplate"); + Session.set("global.ui.toastData"); + } + return toast.show(); }; GlobalUI.deletedToast = function(id, collection, itemName) { @@ -16,147 +21,18 @@ this.GlobalUI = (function() { template: "undoToast", data: { id: id, - collection: collection - } + 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); - }; - - GlobalUI.showDialog = 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); - return Tracker.afterFlush((function(_this) { - return function() { - return _this.dialog.open(); - }; - })(this)); - }; - - GlobalUI.closeDialog = function() { - return this.dialog.close(); - }; - - //To show a detail, first animate the click, with raising z-depth - //then call this function with a template and data - //the element should have a hero-id of detail-main - GlobalUI.showDetail = function(opts) { - Session.set("global.ui.detailData", opts.data); - Session.set("global.ui.detailTemplate", opts.template); - Session.set("global.ui.detailHeroId", opts.heroId); - Session.set("global.ui.detailShow", true); - }; - - //if setting the detail rather than showing it, - //the template should contain the following in template.rendered - // - //if (!this.alreadyRendered){ - // Session.set("global.ui.detailShow", true); - // this.alreadyRendered = true; - //} - GlobalUI.setDetail = function(opts) { - Session.set("global.ui.detailData", opts.data); - Session.set("global.ui.detailTemplate", opts.template); - Session.set("global.ui.detailHeroId", opts.heroId); - if (window.history && window.history.pushState) { - history.replaceState({detail: "closed", opts: opts}, "Detail Dialog"); - history.pushState({detail: "opened", opts: opts}, "Detail Dialog"); - } - }; - - var throttleBack = _.throttle(function() { - history.back(); - }, 100, {trailing: false}); - - GlobalUI.closeDetail = function() { - if (window.history && history.pushState && history.state.detail === "opened") { - throttleBack(); - } else { - Session.set("global.ui.detailShow", false); - } - }; - - GlobalUI.popStateHandler = function(e) { - var state = e.originalEvent.state; - if (state) { - if (state.detail === "closed") { - Session.set("global.ui.detailShow", false); - } else if (state.detail === "opened") { - var opts = state.opts; - Session.set("global.ui.detailData", opts.data); - Session.set("global.ui.detailTemplate", opts.template); - Session.set("global.ui.detailHeroId", opts.heroId); - } - } - }; - return GlobalUI; - })(); Template.layout.helpers({ - globalDialogTemplate: function() { - return Session.get("global.ui.dialogTemplate"); - }, - globalDialogData: function() { - return Session.get("global.ui.dialogData"); - }, - globalDialogFullOnMobile: function() { - return Session.get("global.ui.dialogFullOnMobile"); - }, - globalDialogHeader: function() { - return Session.get("global.ui.dialogHeader"); - }, - globalDetailSelected: function() { - return Session.get("global.ui.detailShow") ? 1 : 0; - }, - globalDetailTemplate: function() { - return Session.get("global.ui.detailTemplate"); - }, - globalDetailData: function() { - return Session.get("global.ui.detailData"); - }, globalToastTemplate: function() { return Session.get("global.ui.toastTemplate"); }, globalToastData: function() { return Session.get("global.ui.toastData"); - } -}); - -Template.layout.events({ - "core-overlay-close-completed [global-dialog]": function(e) { - Session.set("global.ui.dialogTemplate", null); - Session.set("global.ui.dialogData", null); - return Session.set("global.ui.dialogFullOnMobile", null); - }, - "core-animated-pages-transition-end [detail-pages]": function(e) { - var detailOpened = Session.get("global.ui.detailShow"); - if (!detailOpened) { - Session.set("global.ui.detailData", null); - Session.set("global.ui.detailTemplate", null); - Session.set("global.ui.detailHeroId", null); - } - }, - "core-animated-pages-transition-prepare": function(e) { - var detailOpened = Session.get("global.ui.detailShow"); - if (detailOpened) { - //set up the transition - } else { - //undo hack - $("#mainContentSection").removeClass("fake-selected"); - } - }, - "tap #screenDim": function(e) { - GlobalUI.closeDetail(); - } + }, }); diff --git a/rpg-docs/client/views/character/features/featureDialog/featureDialog.js b/rpg-docs/client/views/character/features/featureDialog/featureDialog.js index 1bd41a68..247574c4 100644 --- a/rpg-docs/client/views/character/features/featureDialog/featureDialog.js +++ b/rpg-docs/client/views/character/features/featureDialog/featureDialog.js @@ -11,7 +11,7 @@ Template.featureDialog.events({ "tap #deleteButton": function(event, instance){ Features.softRemoveNode(instance.data.featureId); GlobalUI.deletedToast(instance.data.featureId, "Features", "Feature"); - GlobalUI.closeDetail(); + popDialogStack(); }, }); diff --git a/rpg-docs/client/views/layout/layout.html b/rpg-docs/client/views/layout/layout.html index 9e06b2e5..279936b4 100644 --- a/rpg-docs/client/views/layout/layout.html +++ b/rpg-docs/client/views/layout/layout.html @@ -51,6 +51,8 @@ {{> yield}} - + + {{> Template.dynamic template=globalToastTemplate data=globalToastData }} + {{> dialogStack}}