Skip to content

Commit

Permalink
Use checkbox for omit year action
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Sep 3, 2019
1 parent 5a1b111 commit 2851043
Showing 1 changed file with 15 additions and 29 deletions.
44 changes: 15 additions & 29 deletions src/components/Actions/ActionToggleYear.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,19 @@
-->

<template>
<ActionButton :icon="icon" @click="toggleYear">
{{ omitYear ? t('contacts', 'Add year') : t('contacts', 'Omit year') }}
</ActionButton>
<ActionCheckbox :checked="omitYear"
@check="removeYear" @uncheck="addYear">
{{ t('contacts', 'Omit year') }}
</ActionCheckbox>
</template>
<script>
import { ActionButton } from 'nextcloud-vue'
import { ActionCheckbox } from 'nextcloud-vue'
import ActionsMixin from 'Mixins/ActionsMixin'

export default {
name: 'ActionToggleYear',
components: {
ActionButton
ActionCheckbox
},
mixins: [ActionsMixin],
data() {
Expand All @@ -41,37 +42,18 @@ export default {
}
},

computed: {
icon() {
return this.omitYear
? 'icon-calendar-dark'
: 'icon-no-calendar'
},
text() {
return this.omitYear
? t('contacts', 'Add year')
: t('contacts', 'Omit year')
}
},

beforeMount() {
this.omitYear = !!this.component.property.getFirstParameter('x-apple-omit-year')
|| !this.component.value.year // if null
},

methods: {
toggleYear() {
removeYear() {
const dateObject = this.component.localValue.toJSON()

// year was already ignored: adding it back
if (this.omitYear) {
this.$nextTick(() => {
this.component.updateValue(dateObject, true)
})

} else if (this.component.localContact.version === '4.0') {
// year was already displayed: removing it
// and use --0124 format
// year was already displayed: removing it
// and use --0124 format
if (this.component.localContact.version === '4.0') {
dateObject.year = null
this.component.updateValue(dateObject)
} else {
Expand All @@ -85,7 +67,11 @@ export default {
})
}
}

this.omitYear = !this.omitYear
},
addYear() {
const dateObject = this.component.localValue.toJSON()
this.component.updateValue(dateObject, true)
this.omitYear = !this.omitYear
}
}
Expand Down

0 comments on commit 2851043

Please sign in to comment.