|
1 | 1 | <template> |
2 | 2 |
|
3 | | - <core-modal :title="$tr('changeLanguageModalHeader')" @cancel="$emit('close')"> |
4 | | - <p>{{ $tr('changeLanguageSubHeader') }}</p> |
5 | | - <p v-for="language in languageOptions" :class="selectedLanguage.code===language.code ? 'selected' : 'choice'" @click="selectedLanguage=language"> |
6 | | - {{ language.name }} |
7 | | - </p> |
8 | | - <div class="footer"> |
9 | | - <k-button :text="$tr('cancelButtonText')" :raised="false" :disabled="disabled" @click="$emit('close')"/> |
10 | | - <k-button :text="$tr('confirmButtonText')" :primary="true" :disabled="disabled" @click="switchLanguage"/> |
| 3 | + <div> |
| 4 | + <div class="page-footer"> |
| 5 | + <div class="lang-container"> |
| 6 | + <p class="prompt" v-if="!isMobile">{{ $tr('changeLanguagePrompt') }}</p> |
| 7 | + <p v-for="language in footerLanguageOptions" :class="selectedLanguage.code===language.code ? 'selected' : 'choice'" @click="setAndSwitchLanguage(language)"> |
| 8 | + {{ language.name }} |
| 9 | + </p> |
| 10 | + </div> |
| 11 | + <k-button style="margin-top: 0" :text="$tr('moreLanguageButtonText')" :raised="false" @click="setModalOpen"/> |
11 | 12 | </div> |
12 | | - </core-modal> |
| 13 | + <core-modal |
| 14 | + v-if="showModal" |
| 15 | + :title="$tr('changeLanguageModalHeader')" |
| 16 | + @cancel="closeModal"> |
| 17 | + <p>{{ $tr('changeLanguageSubHeader') }}</p> |
| 18 | + <p v-for="language in languageOptions" :class="selectedLanguage.code===language.code ? 'selected' : 'choice'" @click="selectedLanguage=language"> |
| 19 | + {{ language.name }} |
| 20 | + </p> |
| 21 | + <div class="footer"> |
| 22 | + <k-button :text="$tr('cancelButtonText')" :raised="false" :disabled="disabled" @click="closeModal"/> |
| 23 | + <k-button :text="$tr('confirmButtonText')" :primary="true" :disabled="disabled" @click="switchLanguage"/> |
| 24 | + </div> |
| 25 | + </core-modal> |
| 26 | + </div> |
13 | 27 |
|
14 | 28 | </template> |
15 | 29 |
|
|
20 | 34 | import kButton from 'kolibri.coreVue.components.kButton'; |
21 | 35 | import { httpClient } from 'kolibri.client'; |
22 | 36 | import { availableLanguages, currentLanguage } from 'kolibri.utils.i18n'; |
| 37 | + import responsiveWindow from 'kolibri.coreVue.mixins.responsiveWindow'; |
23 | 38 | export default { |
24 | 39 | name: 'languageSwitcherModalDialog', |
| 40 | + mixins: [responsiveWindow], |
25 | 41 | components: { coreModal, kButton }, |
26 | 42 | $trs: { |
27 | 43 | changeLanguageModalHeader: 'Change language', |
28 | 44 | changeLanguageSubHeader: 'Select the language you want to view Kolibri in', |
| 45 | + changeLanguagePrompt: 'Select language:', |
| 46 | + moreLanguageButtonText: 'More languages', |
29 | 47 | cancelButtonText: 'Cancel', |
30 | 48 | confirmButtonText: 'Confirm', |
31 | 49 | }, |
32 | 50 | computed: { |
33 | 51 | languageOptions() { |
34 | 52 | return Object.keys(availableLanguages) |
35 | 53 | .sort((a, b) => { |
36 | | - if (a === currentLanguage || a[0] > b[0]) { |
| 54 | + if (a === currentLanguage) { |
37 | 55 | return -1; |
38 | 56 | } |
39 | | - if (b === currentLanguage || b[0] > a[0]) { |
| 57 | + if (b === currentLanguage) { |
| 58 | + return 1; |
| 59 | + } |
| 60 | + if (a[0] < b[0]) { |
| 61 | + return -1; |
| 62 | + } |
| 63 | + if (b[0] < a[0]) { |
40 | 64 | return 1; |
41 | 65 | } |
42 | 66 | return 0; |
43 | 67 | }) |
44 | 68 | .map(key => availableLanguages[key]); |
45 | 69 | }, |
| 70 | + footerLanguageOptions() { |
| 71 | + if (this.isMobile) { |
| 72 | + return this.languageOptions.filter(lang => lang.code !== currentLanguage).slice(0, 3); |
| 73 | + } |
| 74 | + return this.languageOptions.slice(0, 6); |
| 75 | + }, |
46 | 76 | currentLanguageName() { |
47 | 77 | return availableLanguages[currentLanguage].name; |
48 | 78 | }, |
| 79 | + showModal() { |
| 80 | + console.log(this.internalModalOpen); |
| 81 | + return this.modalOpen || this.internalModalOpen; |
| 82 | + }, |
| 83 | + isMobile() { |
| 84 | + return this.windowSize.breakpoint <= 1; |
| 85 | + }, |
| 86 | + }, |
| 87 | + props: { |
| 88 | + footer: { |
| 89 | + type: Boolean, |
| 90 | + default: false, |
| 91 | + }, |
| 92 | + modalOpen: { |
| 93 | + type: Boolean, |
| 94 | + default: false, |
| 95 | + }, |
49 | 96 | }, |
50 | 97 | data: () => ({ |
51 | 98 | disabled: false, |
52 | 99 | selectedLanguage: availableLanguages[currentLanguage], |
| 100 | + internalModalOpen: false, |
53 | 101 | }), |
54 | 102 | methods: { |
55 | 103 | switchLanguage() { |
|
65 | 113 | global.location.reload(true); |
66 | 114 | }); |
67 | 115 | }, |
| 116 | + setAndSwitchLanguage(language) { |
| 117 | + this.selectedLanguage = language; |
| 118 | + this.switchLanguage(); |
| 119 | + }, |
| 120 | + closeModal() { |
| 121 | + this.internalModalOpen = false; |
| 122 | + this.$emit('close'); |
| 123 | + }, |
| 124 | + setModalOpen() { |
| 125 | + console.log('setting open'); |
| 126 | + this.internalModalOpen = true; |
| 127 | + }, |
68 | 128 | }, |
69 | 129 | }; |
70 | 130 |
|
|
78 | 138 | h1, p |
79 | 139 | color: black |
80 | 140 |
|
| 141 | + .more-button |
| 142 | + float: left |
| 143 | +
|
81 | 144 | .selected |
82 | 145 | font-weight: bold |
83 | 146 |
|
|
86 | 149 | text-decoration: underline $core-action-normal |
87 | 150 | cursor: pointer |
88 | 151 |
|
| 152 | +
|
| 153 | + .page-footer |
| 154 | + padding-left: 32px |
| 155 | + padding-top: 16px |
| 156 | + padding-bottom: 16px |
| 157 | + .lang-container |
| 158 | + display: inline-block |
| 159 | + width: 40% |
| 160 | + p |
| 161 | + float: left |
| 162 | + padding-left: 10px |
| 163 | + margin: 0 |
| 164 | + button |
| 165 | + float: right |
| 166 | + position: absolute |
| 167 | +
|
| 168 | + .prompt |
| 169 | + padding-right: 16px |
| 170 | +
|
89 | 171 | </style> |
0 commit comments