From db4cdfef6a4e6aee3e46d2e18235e7dcbd3d28db Mon Sep 17 00:00:00 2001 From: hkernbach Date: Tue, 16 May 2017 15:19:24 +0200 Subject: [PATCH] fixed event bug in document view --- .../aardvark/APP/frontend/js/routers/router.js | 14 ++++++++++---- .../aardvark/APP/frontend/js/views/documentView.js | 12 +++++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/js/apps/system/_admin/aardvark/APP/frontend/js/routers/router.js b/js/apps/system/_admin/aardvark/APP/frontend/js/routers/router.js index 02ee67e3fc..39391664b6 100644 --- a/js/apps/system/_admin/aardvark/APP/frontend/js/routers/router.js +++ b/js/apps/system/_admin/aardvark/APP/frontend/js/routers/router.js @@ -655,12 +655,18 @@ this.waitForInit(this.document.bind(this), colid, docid); return; } - if (!this.documentView) { - this.documentView = new window.DocumentView({ - collection: this.arangoDocumentStore - }); + var mode; + if (this.documentView) { + if (this.documentView.defaultMode) { + mode = this.documentView.defaultMode; + } + this.documentView.remove(); } + this.documentView = new window.DocumentView({ + collection: this.arangoDocumentStore + }); this.documentView.colid = colid; + this.documentView.defaultMode = mode; var doc = window.location.hash.split('/')[2]; var test = (doc.split('%').length - 1) % 3; diff --git a/js/apps/system/_admin/aardvark/APP/frontend/js/views/documentView.js b/js/apps/system/_admin/aardvark/APP/frontend/js/views/documentView.js index 1e8a6d63f9..2134289c8e 100644 --- a/js/apps/system/_admin/aardvark/APP/frontend/js/views/documentView.js +++ b/js/apps/system/_admin/aardvark/APP/frontend/js/views/documentView.js @@ -35,6 +35,14 @@ 'click #addDocument': 'addDocument' }, + remove: function () { + this.$el.empty().off(); /* off to unbind the events */ + this.stopListening(); + this.unbind(); + delete this.el; + return this; + }, + checkSearchBox: function (e) { if ($(e.currentTarget).val() === '') { this.editor.expandAll(); @@ -208,7 +216,9 @@ iconlib: 'fontawesome4' }; this.editor = new JSONEditor(container, options); - this.editor.setMode(this.defaultMode); + if (this.defaultMode) { + this.editor.setMode(this.defaultMode); + } return this; },