From 8a9345e871532cb6f6409a8bdbf13ebe07519483 Mon Sep 17 00:00:00 2001 From: Henry Castro Date: Tue, 20 Apr 2021 17:31:47 -0400 Subject: [PATCH] loleaflet: add feedback handler Change-Id: I8ef2c1afe4093e9ee867cd3130c82cbd93362eb9 Signed-off-by: Henry Castro Signed-off-by: Pedro Pinto Silva --- loleaflet/Makefile.am | 3 +- loleaflet/src/control/IFrameDialog.js | 2 +- loleaflet/src/map/handler/Map.Feedback.js | 52 +++++++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 loleaflet/src/map/handler/Map.Feedback.js diff --git a/loleaflet/Makefile.am b/loleaflet/Makefile.am index 308d86138..928a5016b 100644 --- a/loleaflet/Makefile.am +++ b/loleaflet/Makefile.am @@ -363,7 +363,8 @@ LOLEAFLET_JS_LST =\ if ENABLE_FEEDBACK LOLEAFLET_JS_LST +=\ - src/control/IFrameDialog.js + src/control/IFrameDialog.js \ + src/map/handler/Map.Feedback.js endif LOLEAFLET_JS_LST +=\ diff --git a/loleaflet/src/control/IFrameDialog.js b/loleaflet/src/control/IFrameDialog.js index c1a54093d..a693f1e59 100644 --- a/loleaflet/src/control/IFrameDialog.js +++ b/loleaflet/src/control/IFrameDialog.js @@ -1,6 +1,6 @@ /* -*- js-indent-level: 8 -*- */ /* - * L.Control.IFrameDialog + * L.IFrameDialog */ L.IFrameDialog = L.Class.extend({ diff --git a/loleaflet/src/map/handler/Map.Feedback.js b/loleaflet/src/map/handler/Map.Feedback.js new file mode 100644 index 000000000..d280dfba6 --- /dev/null +++ b/loleaflet/src/map/handler/Map.Feedback.js @@ -0,0 +1,52 @@ +/* -*- js-indent-level: 8 -*- */ +/* + * L.Map.Feedback. + */ + +L.Map.mergeOptions({ + feedback: true, + feedbackTimeout: 2000 +}); + +L.Map.Feedback = L.Handler.extend({ + + addHooks: function () { + window.localStorage.setItem('WSDFeedbackEnabled', 'true'); + this._map.on('docloaded', this.onDocLoaded, this); + L.DomEvent.on(window, 'message', this.onMessage, this); + }, + + removeHooks: function () { + L.DomEvent.off(window, 'message', this.onMessage, this); + }, + + onDocLoaded: function () { + setTimeout(L.bind(this.onFeedback, this), this._map.options.feedbackTimeout); + }, + + onFeedback: function () { + if (window.localStorage.getItem('WSDFeedbackEnabled')) { + this._iframeDialog = L.iframeDialog(window.feebackLocation); + this._iframeDialog.create(); + } + }, + + onMessage: function (e) { + var data = e.data; + + if (data == 'never') { + window.localStorage.removeItem('WSDFeedbackEnabled'); + this._iframeDialog.remove(); + } else if (data == 'later') { + this._iframeDialog.remove(); + setTimeout(L.bind(this.onFeedback, this), this._map.options.feedbackTimeout); + } else if (data == 'submit') { + window.localStorage.removeItem('WSDFeedbackEnabled'); + this._iframeDialog.remove(); + } + } +}); + +if (window.isLocalStorageAllowed) { + L.Map.addInitHook('addHandler', 'feedback', L.Map.Feedback); +}