|
1 | 1 | <template> |
2 | 2 |
|
3 | | - <dropdown-menu |
4 | | - :name="currentLanguageName" |
5 | | - :options="languageOptions" |
6 | | - :inAppBar="inAppBar" |
7 | | - :displayDisabledAsSelected="true" |
8 | | - :disabled="disabled" |
9 | | - type="primary" |
10 | | - color="primary" |
11 | | - icon="language" |
12 | | - @select="switchLanguage" |
13 | | - /> |
| 3 | + <div> |
| 4 | + <div v-if="footer" class="page-footer"> |
| 5 | + <ul class="language-list"> |
| 6 | + <li v-for="language in languageOptions" :class="selectedLanguage===language.code ? 'selected item' : 'choice item'" @click="setAndSwitchLanguage(language.code)"> |
| 7 | + {{ language.name }} |
| 8 | + </li> |
| 9 | + </ul> |
| 10 | + </div> |
| 11 | + <core-modal |
| 12 | + v-if="showModal" |
| 13 | + :title="$tr('changeLanguageModalHeader')" |
| 14 | + @cancel="closeModal"> |
| 15 | + <p>{{ $tr('changeLanguageSubHeader') }}</p> |
| 16 | + <k-radio-button |
| 17 | + v-for="language in languageOptions" |
| 18 | + class="choice" |
| 19 | + :key="language.code" |
| 20 | + :radiovalue="language.code" |
| 21 | + :value="selectedLanguage" |
| 22 | + :label="language.name" |
| 23 | + v-model="selectedLanguage" |
| 24 | + /> |
| 25 | + <div class="footer"> |
| 26 | + <k-button :text="$tr('cancelButtonText')" :raised="false" :disabled="disabled" @click="closeModal"/> |
| 27 | + <k-button :text="$tr('confirmButtonText')" :primary="true" :disabled="disabled" @click="switchLanguage"/> |
| 28 | + </div> |
| 29 | + </core-modal> |
| 30 | + </div> |
14 | 31 |
|
15 | 32 | </template> |
16 | 33 |
|
17 | 34 |
|
18 | 35 | <script> |
19 | 36 |
|
20 | | - import orderBy from 'lodash/orderBy'; |
21 | | - import dropdownMenu from 'kolibri.coreVue.components.dropdownMenu'; |
| 37 | + import coreModal from 'kolibri.coreVue.components.coreModal'; |
| 38 | + import kButton from 'kolibri.coreVue.components.kButton'; |
| 39 | + import kRadioButton from 'kolibri.coreVue.components.kRadioButton'; |
22 | 40 | import { httpClient } from 'kolibri.client'; |
23 | 41 | import { availableLanguages, currentLanguage } from 'kolibri.utils.i18n'; |
24 | 42 | export default { |
25 | | - name: 'languageSwitcher', |
26 | | - components: { dropdownMenu }, |
| 43 | + name: 'languageSwitcherModalDialog', |
| 44 | + components: { coreModal, kButton, kRadioButton }, |
| 45 | + $trs: { |
| 46 | + changeLanguageModalHeader: 'Change language', |
| 47 | + changeLanguageSubHeader: 'Select the language you want to view Kolibri in', |
| 48 | + cancelButtonText: 'Cancel', |
| 49 | + confirmButtonText: 'Confirm', |
| 50 | + }, |
27 | 51 | computed: { |
28 | 52 | languageOptions() { |
29 | | - return orderBy(availableLanguages, language => language.code, ['asc']).map(language => ({ |
30 | | - id: language.code, |
31 | | - label: language.name, |
32 | | - disabled: language.code === currentLanguage, |
33 | | - })); |
| 53 | + return Object.keys(availableLanguages) |
| 54 | + .sort((a, b) => { |
| 55 | + if (a === currentLanguage) { |
| 56 | + return -1; |
| 57 | + } |
| 58 | + if (b === currentLanguage) { |
| 59 | + return 1; |
| 60 | + } |
| 61 | + if (a[0] < b[0]) { |
| 62 | + return -1; |
| 63 | + } |
| 64 | + if (b[0] < a[0]) { |
| 65 | + return 1; |
| 66 | + } |
| 67 | + return 0; |
| 68 | + }) |
| 69 | + .map(key => availableLanguages[key]); |
34 | 70 | }, |
35 | 71 | currentLanguageName() { |
36 | 72 | return availableLanguages[currentLanguage].name; |
37 | 73 | }, |
| 74 | + showModal() { |
| 75 | + return this.modalOpen || this.internalModalOpen; |
| 76 | + }, |
38 | 77 | }, |
39 | 78 | props: { |
40 | | - inAppBar: { |
| 79 | + footer: { |
| 80 | + type: Boolean, |
| 81 | + default: false, |
| 82 | + }, |
| 83 | + modalOpen: { |
41 | 84 | type: Boolean, |
42 | | - default: true, |
| 85 | + default: false, |
43 | 86 | }, |
44 | 87 | }, |
45 | 88 | data: () => ({ |
46 | 89 | disabled: false, |
| 90 | + selectedLanguage: currentLanguage, |
| 91 | + internalModalOpen: false, |
47 | 92 | }), |
48 | 93 | methods: { |
49 | | - switchLanguage(language) { |
| 94 | + switchLanguage() { |
50 | 95 | this.disabled = true; |
51 | 96 | const path = this.Kolibri.urls['kolibri:set_language'](); |
52 | 97 | const entity = { |
53 | | - language: language.id, |
| 98 | + language: this.selectedLanguage, |
54 | 99 | }; |
55 | 100 | httpClient({ |
56 | 101 | path, |
|
59 | 104 | global.location.reload(true); |
60 | 105 | }); |
61 | 106 | }, |
| 107 | + setAndSwitchLanguage(languageCode) { |
| 108 | + if (languageCode != this.selectedLanguage) { |
| 109 | + this.selectedLanguage = languageCode; |
| 110 | + this.switchLanguage(); |
| 111 | + } |
| 112 | + }, |
| 113 | + closeModal() { |
| 114 | + this.internalModalOpen = false; |
| 115 | + this.$emit('close'); |
| 116 | + }, |
| 117 | + setModalOpen() { |
| 118 | + console.log('setting open'); |
| 119 | + this.internalModalOpen = true; |
| 120 | + }, |
62 | 121 | }, |
63 | 122 | }; |
64 | 123 |
|
65 | 124 | </script> |
66 | 125 |
|
67 | 126 |
|
68 | | -<style lang="stylus"></style> |
| 127 | +<style lang="stylus"> |
| 128 | +
|
| 129 | + @require '~kolibri.styles.definitions' |
| 130 | +
|
| 131 | + h1, p |
| 132 | + color: black |
| 133 | +
|
| 134 | + .choice |
| 135 | + color: $core-action-normal |
| 136 | +
|
| 137 | + .selected |
| 138 | + font-weight: bold |
| 139 | +
|
| 140 | + .page-footer |
| 141 | + padding-left: 32px |
| 142 | + padding-top: 16px |
| 143 | + padding-bottom: 16px |
| 144 | + text-align: center |
| 145 | + button |
| 146 | + float: right |
| 147 | + position: absolute |
| 148 | +
|
| 149 | + .prompt |
| 150 | + padding-right: 16px |
| 151 | +
|
| 152 | + .language-list |
| 153 | + list-style: none |
| 154 | + margin: 0 |
| 155 | + padding: 0 |
| 156 | + text-align: initial |
| 157 | + display: inline-block |
| 158 | +
|
| 159 | + .item |
| 160 | + display: inline-block |
| 161 | + padding-top: 6px |
| 162 | + padding-right: 20px |
| 163 | + &.choice |
| 164 | + cursor: pointer |
| 165 | +
|
| 166 | +</style> |
0 commit comments