Add showWeekNumbers option to datepicker (#3637)

Fixes #3634. Credit to @mplodowski
This commit is contained in:
Michał Płodowski 2018-07-13 00:10:24 +02:00 committed by Luke Towers
parent dd6a05bdc4
commit 68ee471d39
4 changed files with 13 additions and 3 deletions

View File

@ -52,6 +52,11 @@ class DatePicker extends FormWidgetBase
*/
public $firstDay = 0;
/**
* @var bool show week numbers at head of row
*/
public $showWeekNumber = false;
/**
* @var bool change datetime exactly as is in database
*/
@ -78,6 +83,7 @@ class DatePicker extends FormWidgetBase
'maxDate',
'yearRange',
'firstDay',
'showWeekNumber',
'ignoreTimezone',
]);
@ -126,6 +132,7 @@ class DatePicker extends FormWidgetBase
$this->vars['maxDate'] = $this->maxDate;
$this->vars['yearRange'] = $this->yearRange;
$this->vars['firstDay'] = $this->firstDay;
$this->vars['showWeekNumber'] = $this->showWeekNumber;
$this->vars['ignoreTimezone'] = $this->ignoreTimezone;
$this->vars['format'] = $this->format;
$this->vars['formatMoment'] = $this->getDateFormatMoment();

View File

@ -15,6 +15,7 @@
<?php if ($maxDate): ?>data-max-date="<?= $maxDate ?>"<?php endif ?>
<?php if ($yearRange): ?>data-year-range="<?= $yearRange ?>"<?php endif ?>
<?php if ($firstDay): ?>data-first-day="<?= $firstDay ?>"<?php endif ?>
data-show-week-number="<?= $showWeekNumber ?>"
<?php if ($ignoreTimezone): ?>data-ignore-timezone<?php endif ?>
>

View File

@ -104,6 +104,7 @@
var pikadayOptions = {
yearRange: this.options.yearRange,
firstDay: this.options.firstDay,
showWeekNumber: this.options.showWeekNumber,
format: dateFormat,
setDefaultDate: now,
onOpen: function() {
@ -314,7 +315,8 @@
maxDate: null,
format: null,
yearRange: 10,
firstDay: 0
firstDay: 0,
showWeekNumber: false
}
// PLUGIN DEFINITION

View File

@ -2878,7 +2878,7 @@ this.$el=null
this.options=null
BaseProto.dispose.call(this)}
DatePicker.prototype.initDatePicker=function(){var self=this,dateFormat=this.getDateFormat(),now=moment().tz(this.timezone).format(dateFormat)
var pikadayOptions={yearRange:this.options.yearRange,firstDay:this.options.firstDay,format:dateFormat,setDefaultDate:now,onOpen:function(){var $field=$(this._o.trigger)
var pikadayOptions={yearRange:this.options.yearRange,firstDay:this.options.firstDay,showWeekNumber:this.options.showWeekNumber,format:dateFormat,setDefaultDate:now,onOpen:function(){var $field=$(this._o.trigger)
$(this.el).css({left:'auto',right:$(window).width()-$field.offset().left-$field.outerWidth()})},onSelect:function(){self.onSelectDatePicker.call(self,this.getMoment())}}
var lang=this.getLang('datepicker',false)
if(lang){pikadayOptions.i18n=lang}
@ -2929,7 +2929,7 @@ if(this.ignoreTimezone){this.appTimezone='UTC'
this.timezone='UTC'}}
DatePicker.prototype.getLang=function(name,defaultValue){if($.oc===undefined||$.oc.lang===undefined){return defaultValue}
return $.oc.lang.get(name,defaultValue)}
DatePicker.DEFAULTS={minDate:null,maxDate:null,format:null,yearRange:10,firstDay:0}
DatePicker.DEFAULTS={minDate:null,maxDate:null,format:null,yearRange:10,firstDay:0,showWeekNumber:false}
var old=$.fn.datePicker
$.fn.datePicker=function(option){var args=Array.prototype.slice.call(arguments,1),items,result
items=this.each(function(){var $this=$(this)