Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct fix window title #375

Merged
merged 1 commit into from
May 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Correct fix window title
Signed-off-by: Jonas Rittershofer <jotoeri@users.noreply.github.com>
  • Loading branch information
jotoeri committed May 10, 2020
commit 3c973b101dce53b15d57ac9bd3208b123eb46725
23 changes: 13 additions & 10 deletions src/mixins/WindowTitleMixin.js → src/utils/SetWindowTitle.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

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
}
},
},
/**
* Set the Window-Title to current FormTitle including suffix.
*
* @param {String} formTitle Title of current form to set on window.
*/
const SetWindowTitle = function(formTitle) {
if (formTitle === '') {
window.document.title = t('forms', 'Forms') + ' - ' + OC.theme.title
} else {
window.document.title = formTitle + ' - ' + t('forms', 'Forms') + ' - ' + OC.theme.title
}
}

export default SetWindowTitle
20 changes: 12 additions & 8 deletions src/views/Create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,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'
import SetWindowTitle from '../utils/SetWindowTitle'

window.axios = axios

Expand All @@ -156,7 +156,7 @@ export default {
TopBar,
},

mixins: [ViewsMixin, WindowTitleMixin],
mixins: [ViewsMixin],

data() {
return {
Expand All @@ -175,13 +175,17 @@ export default {
},

computed: {
title() {
if (this.form.title === '') {
return t('forms', 'Create new form')
} else {
/**
* Return form title, or placeholder if not set
* @returns {string}
*/
formTitle() {
if (this.form.title) {
return this.form.title
}
return t('forms', 'New form')
},

hasQuestions() {
return this.form.questions && this.form.questions.length === 0
},
Expand All @@ -206,13 +210,13 @@ export default {

// Update Window-Title on title change
'form.title': function() {
this.setWindowTitle(this.form.title)
SetWindowTitle(this.formTitle)
},
},

beforeMount() {
this.fetchFullForm(this.form.id)
this.setWindowTitle(this.form.title)
SetWindowTitle(this.formTitle)
},

updated() {
Expand Down
6 changes: 3 additions & 3 deletions src/views/Results.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +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'
import SetWindowTitle from '../utils/SetWindowTitle'

Vue.use(Clipboard)

Expand All @@ -112,7 +112,7 @@ export default {
TopBar,
},

mixins: [ViewsMixin, WindowTitleMixin],
mixins: [ViewsMixin],

data() {
return {
Expand Down Expand Up @@ -141,7 +141,7 @@ export default {

beforeMount() {
this.loadFormResults()
this.setWindowTitle(this.form.title)
SetWindowTitle(this.formTitle)
},

methods: {
Expand Down
6 changes: 2 additions & 4 deletions src/views/Submit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +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'
import SetWindowTitle from '../utils/SetWindowTitle'

export default {
name: 'Submit',
Expand All @@ -100,8 +100,6 @@ export default {
QuestionMultiple,
},

mixins: [WindowTitleMixin],

data() {
return {
form: loadState('forms', 'form'),
Expand Down Expand Up @@ -152,7 +150,7 @@ export default {
},

beforeMount() {
this.setWindowTitle(this.form.title)
SetWindowTitle(this.formTitle)
},

methods: {
Expand Down