From 3d3bb97dd7092d879711890609eeaaf566eb4e2f Mon Sep 17 00:00:00 2001 From: Jonas Rittershofer Date: Sat, 9 May 2020 13:05:18 +0200 Subject: [PATCH] Fix window title Signed-off-by: Jonas Rittershofer --- src/mixins/WindowTitleMixin.js | 32 ++++++++++++++++++++++++++++++++ src/views/Create.vue | 9 ++++++++- src/views/Results.vue | 4 +++- src/views/Submit.vue | 7 +++++++ 4 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 src/mixins/WindowTitleMixin.js diff --git a/src/mixins/WindowTitleMixin.js b/src/mixins/WindowTitleMixin.js new file mode 100644 index 0000000..499ee7c --- /dev/null +++ b/src/mixins/WindowTitleMixin.js @@ -0,0 +1,32 @@ +/** + * @copyright Copyright (c) 2020 Jonas Rittershofer + * + * @author Jonas Rittershofer + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +export default { + methods: { + setWindowTitle(formTitle) { + if (formTitle === '') { + window.document.title = t('forms', 'Forms') + ' - ' + OC.theme.title + } else { + window.document.title = formTitle + ' - ' + t('forms', 'Forms') + ' - ' + OC.theme.title + } + }, + }, +} diff --git a/src/views/Create.vue b/src/views/Create.vue index f4377ba..6e4f307 100644 --- a/src/views/Create.vue +++ b/src/views/Create.vue @@ -136,6 +136,7 @@ import QuestionMultiple from '../components/Questions/QuestionMultiple' import QuestionShort from '../components/Questions/QuestionShort' import TopBar from '../components/TopBar' import ViewsMixin from '../mixins/ViewsMixin' +import WindowTitleMixin from '../mixins/WindowTitleMixin' window.axios = axios @@ -154,7 +155,7 @@ export default { TopBar, }, - mixins: [ViewsMixin], + mixins: [ViewsMixin, WindowTitleMixin], data() { return { @@ -201,10 +202,16 @@ export default { // TODO: cancel previous request if not done this.fetchFullForm(this.form.id) }, + + // Update Window-Title on title change + 'form.title': function() { + this.setWindowTitle(this.form.title) + }, }, beforeMount() { this.fetchFullForm(this.form.id) + this.setWindowTitle(this.form.title) }, updated() { diff --git a/src/views/Results.vue b/src/views/Results.vue index f75db1d..9557ee4 100644 --- a/src/views/Results.vue +++ b/src/views/Results.vue @@ -96,6 +96,7 @@ import EmptyContent from '../components/EmptyContent' import Submission from '../components/Results/Submission' import TopBar from '../components/TopBar' import ViewsMixin from '../mixins/ViewsMixin' +import WindowTitleMixin from '../mixins/WindowTitleMixin' Vue.use(Clipboard) @@ -111,7 +112,7 @@ export default { TopBar, }, - mixins: [ViewsMixin], + mixins: [ViewsMixin, WindowTitleMixin], data() { return { @@ -129,6 +130,7 @@ export default { beforeMount() { this.loadFormResults() + this.setWindowTitle(this.form.title) }, methods: { diff --git a/src/views/Submit.vue b/src/views/Submit.vue index 7f8645c..d440eb2 100644 --- a/src/views/Submit.vue +++ b/src/views/Submit.vue @@ -85,6 +85,7 @@ import Question from '../components/Questions/Question' import QuestionLong from '../components/Questions/QuestionLong' import QuestionShort from '../components/Questions/QuestionShort' import QuestionMultiple from '../components/Questions/QuestionMultiple' +import WindowTitleMixin from '../mixins/WindowTitleMixin' export default { name: 'Submit', @@ -99,6 +100,8 @@ export default { QuestionMultiple, }, + mixins: [WindowTitleMixin], + data() { return { form: loadState('forms', 'form'), @@ -137,6 +140,10 @@ export default { }, }, + beforeMount() { + this.setWindowTitle(this.form.title) + }, + methods: { /** * Submit the form after the browser validated it 🚀