From: Matthias Schmidt Date: Wed, 2 Oct 2013 10:36:11 +0000 (+0200) Subject: Improves WCF.Date.Picker X-Git-Tag: 2.0.0_Beta_11~82 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=b9e59fc3b478f7723b2752a74d90226df8cf53b7;p=GitHub%2FWoltLab%2FWCF.git Improves WCF.Date.Picker Closes #1427 --- diff --git a/com.woltlab.wcf/templates/headInclude.tpl b/com.woltlab.wcf/templates/headInclude.tpl index e74ca760fc..ade02b605a 100644 --- a/com.woltlab.wcf/templates/headInclude.tpl +++ b/com.woltlab.wcf/templates/headInclude.tpl @@ -121,6 +121,7 @@ 'wcf.global.page.pageNavigation': '{lang}wcf.global.page.pageNavigation{/lang}', 'wcf.global.page.next': '{capture assign=pageNext}{lang}wcf.global.page.next{/lang}{/capture}{@$pageNext|encodeJS}', 'wcf.global.page.previous': '{capture assign=pagePrevious}{lang}wcf.global.page.previous{/lang}{/capture}{@$pagePrevious|encodeJS}', + 'wcf.global.pageDirection': '{lang}wcf.global.pageDirection{/lang}', 'wcf.global.success': '{lang}wcf.global.success{/lang}', 'wcf.global.success.add': '{lang}wcf.global.success.add{/lang}', 'wcf.global.success.edit': '{lang}wcf.global.success.edit{/lang}', diff --git a/wcfsetup/install/files/acp/templates/header.tpl b/wcfsetup/install/files/acp/templates/header.tpl index 1e888199e2..739297b5fc 100644 --- a/wcfsetup/install/files/acp/templates/header.tpl +++ b/wcfsetup/install/files/acp/templates/header.tpl @@ -91,6 +91,7 @@ 'wcf.global.page.pageNavigation': '{lang}wcf.global.page.pageNavigation{/lang}', 'wcf.global.page.next': '{capture assign=pageNext}{lang}wcf.global.page.next{/lang}{/capture}{@$pageNext|encodeJS}', 'wcf.global.page.previous': '{capture assign=pagePrevious}{lang}wcf.global.page.previous{/lang}{/capture}{@$pagePrevious|encodeJS}', + 'wcf.global.pageDirection': '{lang}wcf.global.pageDirection{/lang}', 'wcf.global.success': '{lang}wcf.global.success{/lang}', 'wcf.global.success.add': '{lang}wcf.global.success.add{/lang}', 'wcf.global.success.edit': '{lang}wcf.global.success.edit{/lang}', diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index d171e857ba..955ec19c91 100755 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -2736,10 +2736,12 @@ WCF.Date.Picker = { * Initializes the date picker for valid fields. */ _initDatePicker: function() { - $('input[type=date]:not(.jsDatePicker)').each($.proxy(function(index, input) { + $('input[type=date]:not(.jsDatePicker), input[type=datetime]:not(.jsDatePicker)').each($.proxy(function(index, input) { var $input = $(input); var $inputName = $input.prop('name'); - var $inputValue = $input.val(); // should be Y-m-d, must be interpretable by Date + var $inputValue = $input.val(); // should be Y-m-d (H:i:s), must be interpretable by Date + + var $hasTime = $input.attr('type') == 'datetime'; // update $input $input.prop('type', 'text').addClass('jsDatePicker'); @@ -2751,8 +2753,12 @@ WCF.Date.Picker = { $input.removeAttr('name'); $input.before(''); + // max- and mindate + var $maxDate = $input.attr('max') ? new Date($input.attr('max').replace(' ', 'T')) : null; + var $minDate = $input.attr('min') ? new Date($input.attr('min').replace(' ', 'T')) : null; + // init date picker - $input.datepicker({ + $options = { altField: '#' + $input.wcfIdentify() + 'DatePicker', altFormat: 'yy-mm-dd', // PHPs strtotime() understands this best beforeShow: function(input, instance) { @@ -2772,89 +2778,52 @@ WCF.Date.Picker = { dayNames: WCF.Language.get('__days'), dayNamesMin: WCF.Language.get('__daysShort'), dayNamesShort: WCF.Language.get('__daysShort'), + isRTL: WCF.Language.get('wcf.global.pageDirection') == 'rtl', + maxDate: $maxDate, + minDate: $minDate, monthNames: WCF.Language.get('__months'), monthNamesShort: WCF.Language.get('__monthsShort'), - showOtherMonths: true, - yearRange: ($input.hasClass('birthday') ? '-100:+0' : '1900:2038'), + showButtonPanel: false, onClose: function(dateText, datePicker) { // clear altField when datepicker is cleared if (dateText == '') { $(datePicker.settings["altField"]).val(dateText); } - } - }); + }, + showOtherMonths: true, + yearRange: ($input.hasClass('birthday') ? '-100:+0' : '1900:2038') + }; - // format default date - if ($inputValue) { - $input.datepicker('setDate', $inputValue); + if ($hasTime) { + // drop the seconds + if (/[0-9]{2}:[0-9]{2}:[0-9]{2}$/.test($inputValue)) { + $inputValue = $inputValue.replace(/:[0-9]{2}$/, ''); + $input.val($inputValue); + } + $inputValue = $inputValue.replace(' ', 'T'); + + $options = $.extend($options, { + altFieldTimeOnly: false, + altTimeFormat: 'HH:mm', + controlType: 'select', + hourText: WCF.Language.get('wcf.date.hour'), + minuteText: WCF.Language.get('wcf.date.minute'), + showTime: false, + timeFormat: this._timeFormat, + yearRange: ($input.hasClass('birthday') ? '-100:+0' : '1900:2038') + }); } - // bug workaround: setDate creates the widget but unfortunately doesn't hide it... - $input.datepicker('widget').hide(); - }, this)); - - $('input[type=datetime]:not(.jsDatePicker)').each($.proxy(function(index, input) { - var $input = $(input); - var $inputName = $input.prop('name'); - var $inputValue = $input.val(); // should be Y-m-d H:i:s, must be interpretable by Date - - // drop the seconds - if (/[0-9]{2}:[0-9]{2}:[0-9]{2}$/.test($inputValue)) { - $inputValue = $inputValue.replace(/:[0-9]{2}$/, ''); - $input.val($inputValue); + if ($hasTime) { + $input.datetimepicker($options); + } + else { + $input.datepicker($options); } - - // update $input - $input.prop('type', 'text').addClass('jsDatePicker'); - - // insert a hidden element representing the actual date - $input.removeAttr('name'); - $input.before(''); - - // init date picker - $input.datetimepicker({ - altField: '#' + $input.wcfIdentify() + 'DatePicker', - altFieldTimeOnly: false, - altFormat: 'yy-mm-dd', // PHPs strtotime() understands this best - altTimeFormat: 'HH:mm', - beforeShow: function(input, instance) { - // dirty hack to force opening below the input - setTimeout(function() { - instance.dpDiv.position({ - my: 'left top', - at: 'left bottom', - collision: 'none', - of: input - }); - }, 1); - }, - changeMonth: true, - changeYear: true, - controlType: 'select', - dateFormat: this._dateFormat, - dayNames: WCF.Language.get('__days'), - dayNamesMin: WCF.Language.get('__daysShort'), - dayNamesShort: WCF.Language.get('__daysShort'), - hourText: WCF.Language.get('wcf.date.hour'), - minuteText: WCF.Language.get('wcf.date.minute'), - monthNames: WCF.Language.get('__months'), - monthNamesShort: WCF.Language.get('__monthsShort'), - showButtonPanel: false, - showTime: false, - showOtherMonths: true, - timeFormat: this._timeFormat, - yearRange: ($input.hasClass('birthday') ? '-100:+0' : '1900:2038'), - onClose: function(dateText, datePicker) { - // clear altField when datepicker is cleared - if (dateText == '') { - $(datePicker.settings.altField).val(''); - } - } - }); // format default date if ($inputValue) { - $input.removeClass('hasDatepicker').datetimepicker('setDate', new Date($inputValue.replace(' ', 'T'))); + $input.datepicker('setDate', $inputValue); } // bug workaround: setDate creates the widget but unfortunately doesn't hide it...