|
| 1 | + |
| 2 | +/** |
| 3 | + * The array of names of the tooltip messages of the datetime picker. |
| 4 | + * |
| 5 | + * This is a constant and should not be modified. |
| 6 | + */ |
| 7 | +var DATETIME_PICKER_TOOLTIPS = [ |
| 8 | + "today", "clear", "close", |
| 9 | + "selectMonth", "prevMonth", "nextMonth", |
| 10 | + "selectYear", "prevYear", "nextYear", |
| 11 | + "selectDecade", "prevDecade", "nextDecade", |
| 12 | + "prevCentury", "nextCentury", |
| 13 | + "pickHour", "incrementHour", "decrementHour", |
| 14 | + "pickMinute", "incrementMinute", "decrementMinute", |
| 15 | + "pickSecond", "incrementSecond", "decrementSecond", |
| 16 | + "togglePeriod", "selectTime" |
| 17 | +]; |
| 18 | + |
| 19 | +/** |
| 20 | + * The default language used by this component. |
| 21 | + */ |
| 22 | +var DEFAULT_LANGUAGE = "en-US"; |
| 23 | + |
1 | 24 | /**
|
2 | 25 | * A datetime picker control.
|
3 | 26 | *
|
|
11 | 34 | * Default value is "datetime".
|
12 | 35 | * @param language
|
13 | 36 | * the optional language code used to localize the control, which must be
|
14 |
| - * a valid language code supported by the moment.js library. Default value |
15 |
| - * is "en-US". |
| 37 | + * a valid language code supported by the moment.js library. If it is not set, |
| 38 | + * and the [vue-i18n](https://github.com/Haixing-Hu/vue-i18n) plugin is used, |
| 39 | + * the component will use the language code `$language` provided by the |
| 40 | + * [vue-i18n](https://github.com/Haixing-Hu/vue-i18n) plugin; otherwise, the |
| 41 | + * component will use the default value "en-US". |
16 | 42 | * @param datetimeFormat
|
17 | 43 | * the optional format of the datetime this component should display, which
|
18 | 44 | * must be a valid datetime format of the moment.js library. This property
|
@@ -56,7 +82,7 @@ module.exports = {
|
56 | 82 | language: {
|
57 | 83 | type: String,
|
58 | 84 | required: false,
|
59 |
| - default: "en-US" |
| 85 | + default: "" |
60 | 86 | },
|
61 | 87 | datetimeFormat: {
|
62 | 88 | type: String,
|
@@ -84,25 +110,59 @@ module.exports = {
|
84 | 110 | },
|
85 | 111 | ready: function() {
|
86 | 112 | // console.debug("datetime-picker.ready");
|
87 |
| - var format = null; |
| 113 | + var options = { |
| 114 | + useCurrent: false, |
| 115 | + showClear: true, |
| 116 | + icons: { |
| 117 | + time: 'fa fa-clock-o', |
| 118 | + date: 'fa fa-calendar', |
| 119 | + up: 'fa fa-chevron-up', |
| 120 | + down: 'fa fa-chevron-down', |
| 121 | + previous: 'fa fa-chevron-left', |
| 122 | + next: 'fa fa-chevron-right', |
| 123 | + today: 'glyphicon glyphicon-screenshot', |
| 124 | + clear: 'fa fa-trash', |
| 125 | + close: 'fa fa-times' |
| 126 | + } |
| 127 | + }; |
| 128 | + // set the locale |
| 129 | + if (this.language === null || this.language === "") { |
| 130 | + if (this.$language) { |
| 131 | + this.language = this.$language; |
| 132 | + } else { |
| 133 | + this.langauge = DEFAULT_LANGUAGE; |
| 134 | + } |
| 135 | + } |
| 136 | + options.locale = this.getLanguageCode(this.language), |
| 137 | + // set the format |
88 | 138 | switch (this.type) {
|
89 | 139 | case "date":
|
90 |
| - format = this.dateFormat; |
| 140 | + options.format = this.dateFormat; |
91 | 141 | break;
|
92 | 142 | case "time":
|
93 |
| - format = this.timeFormat; |
| 143 | + options.format = this.timeFormat; |
94 | 144 | break;
|
95 | 145 | case "datetime":
|
96 | 146 | default:
|
97 |
| - format = this.datetimeFormat; |
| 147 | + options.format = this.datetimeFormat; |
98 | 148 | break;
|
99 | 149 | }
|
100 |
| - $(this.$el).datetimepicker({ |
101 |
| - locale: this.getLanguageCode(this.language), |
102 |
| - format: format, |
103 |
| - useCurrent: false |
104 |
| - }); |
| 150 | + // use the vue-i18n plugin for localize the tooltips |
| 151 | + if (this.$i18n && this.$i18n.datetime_picker) { |
| 152 | + var messages = this.$i18n.datetime_picker; |
| 153 | + var tooltips = $.fn.datetimepicker.defaults.tooltips; |
| 154 | + for (var i = 0; i < DATETIME_PICKER_TOOLTIPS.length; ++i) { |
| 155 | + var name = DATETIME_PICKER_TOOLTIPS[i]; |
| 156 | + if (messages[name]) { |
| 157 | + tooltips[name] = messages[name]; // localize |
| 158 | + } |
| 159 | + } |
| 160 | + options.tooltips = tooltips; |
| 161 | + } |
| 162 | + // create the control |
| 163 | + $(this.$el).datetimepicker(options); |
105 | 164 | this.control = $(this.$el).data("DateTimePicker");
|
| 165 | + // set the date to the current value of the model |
106 | 166 | this.control.date(this.model);
|
107 | 167 | var me = this;
|
108 | 168 | $(this.$el).on("dp.change", function (e) {
|
|
0 commit comments