diff --git a/modules/backend/lang/en/lang.php b/modules/backend/lang/en/lang.php index 6531fae01..018f9e7f1 100644 --- a/modules/backend/lang/en/lang.php +++ b/modules/backend/lang/en/lang.php @@ -351,7 +351,6 @@ return [ 'all' => 'all', 'options_method_not_exists' => "The model class :model must define a method :method() returning options for the ':filter' filter.", 'date_all' => 'all period', - // 'date_format' =>'Y-m-d', ], 'import_export' => [ 'upload_csv_file' => '1. Upload a CSV file', diff --git a/modules/backend/lang/fr/lang.php b/modules/backend/lang/fr/lang.php index 5f6e3e282..1450f8700 100644 --- a/modules/backend/lang/fr/lang.php +++ b/modules/backend/lang/fr/lang.php @@ -352,7 +352,6 @@ return [ 'all' => 'tous', 'options_method_not_exists' => "La classe du modèle :model doit définir une méthode :method() qui retourne les options pour le filtre ':filter'.", 'date_all' => 'toute la période', - // 'date_format' =>'d/m/Y', ], 'import_export' => [ 'upload_csv_file' => '1. Envoyer un fichier CSV', diff --git a/modules/backend/widgets/filter/partials/_scope_date.htm b/modules/backend/widgets/filter/partials/_scope_date.htm index adeab518e..79ec5ffd4 100644 --- a/modules/backend/widgets/filter/partials/_scope_date.htm +++ b/modules/backend/widgets/filter/partials/_scope_date.htm @@ -3,12 +3,12 @@ class="filter-scope-date value ? 'active' : '' ?>" href="javascript:;" data-scope-name="scopeName ?>" - data-scope-data=" $scope->value && $scope->value instanceof \Carbon\Carbon ? $scope->value->format('Y-m-d') : null, 'minDate' => $scope->minDate ? $scope->minDate : '2000-01-01' , 'maxDate' => $scope->maxDate ? $scope->maxDate : '2099-12-31', ])) ?>"> label)) ?>: - value && $scope->value instanceof \Carbon\Carbon ? $scope->value->format(trans('backend::lang.filter.date.format')) : e(trans('backend::lang.filter.date_all')) ?> + value && $scope->value instanceof \Carbon\Carbon ? $scope->value->format('Y-m-d') : e(trans('backend::lang.filter.date_all')) ?> diff --git a/modules/backend/widgets/filter/partials/_scope_daterange.htm b/modules/backend/widgets/filter/partials/_scope_daterange.htm index fa5be8aa6..9d1332d40 100644 --- a/modules/backend/widgets/filter/partials/_scope_daterange.htm +++ b/modules/backend/widgets/filter/partials/_scope_daterange.htm @@ -3,12 +3,12 @@ class="filter-scope-date range value ? 'active' : '' ?>" href="javascript:;" data-scope-name="scopeName ?>" - data-scope-data=" $scope->value && is_array($scope->value) ? array_map(function($value) { return $value instanceof \Carbon\Carbon ? $value->format('Y-m-d') : null; }, $scope->value) : null, - 'minDate' => $scope->minDate ? $scope->minDate : '2000-01-01' , + 'minDate' => $scope->minDate ? $scope->minDate : '2000-01-01', 'maxDate' => $scope->maxDate ? $scope->maxDate : '2099-12-31', ])) ?>"> label)) ?>: - value && is_array($scope->value) ? join(' → ', array_map(function($value) { return $value instanceof \Carbon\Carbon ? $value->format(trans('backend::lang.filter.date.format')) : null; }, $scope->value)) : e(trans('backend::lang.filter.date_all')) ?> + value && is_array($scope->value) ? join(' → ', array_map(function($value) { return $value instanceof \Carbon\Carbon ? $value->format('Y-m-d') : null; }, $scope->value)) : e(trans('backend::lang.filter.date_all')) ?> diff --git a/modules/system/assets/ui/js/filter.dates.js b/modules/system/assets/ui/js/filter.dates.js index 7400614ca..3f08feba8 100644 --- a/modules/system/assets/ui/js/filter.dates.js +++ b/modules/system/assets/ui/js/filter.dates.js @@ -29,29 +29,30 @@ FilterWidget.prototype.init = function () { overloaded_init.apply(this); - this.initFilterDate(); - }; + this.initRegion() + this.initFilterDate() + } // NEW MODULE // ================= FilterWidget.prototype.initFilterDate = function () { - var self = this; + var self = this this.$el.on('show.oc.popover', 'a.filter-scope-date', function () { - self.initDatePickers($(this).hasClass('range')); + self.initDatePickers($(this).hasClass('range')) }); this.$el.on('hiding.oc.popover', 'a.filter-scope-date', function () { - self.clearDatePickers(); + self.clearDatePickers() }); this.$el.on('hide.oc.popover', 'a.filter-scope-date', function () { - var $scope = $(this); - self.pushOptions(self.activeScopeName); - self.activeScopeName = null; - self.$activeScope = null; + var $scope = $(this) + self.pushOptions(self.activeScopeName) + self.activeScopeName = null + self.$activeScope = null // Second click closes the filter scope setTimeout(function () { @@ -61,17 +62,17 @@ this.$el.on('click', 'a.filter-scope-date', function () { var $scope = $(this), - scopeName = $scope.data('scope-name'); + scopeName = $scope.data('scope-name') // Ignore if already opened - if ($scope.hasClass('filter-scope-open')) return; + if ($scope.hasClass('filter-scope-open')) return // Ignore if another popover is opened - if (null !== self.activeScopeName) return; + if (null !== self.activeScopeName) return - self.$activeScope = $scope; - self.activeScopeName = scopeName; - self.isActiveScopeDirty = false; + self.$activeScope = $scope + self.activeScopeName = scopeName + self.isActiveScopeDirty = false if ($scope.hasClass('range')) { self.displayPopoverRange($scope) @@ -84,19 +85,19 @@ }); $(document).on('click', '#controlFilterPopover [data-trigger="filter"]', function (e) { - e.preventDefault(); - e.stopPropagation(); + e.preventDefault() + e.stopPropagation() self.filterByDate() }); $(document).on('click', '#controlFilterPopover [data-trigger="clear"]', function (e) { - e.preventDefault(); - e.stopPropagation(); + e.preventDefault() + e.stopPropagation() self.filterByDate(true) }) - }; + } /* * Get popover date template @@ -128,7 +129,7 @@ \ \ ' - }; + } /* * Get popover range template @@ -175,23 +176,23 @@ \ \ ' - }; + } FilterWidget.prototype.displayPopoverDate = function ($scope) { var self = this, scopeName = $scope.data('scope-name'), - data = this.scopeValues[scopeName]; + data = this.scopeValues[scopeName] data = $.extend({}, data, { filter_button_text: $.oc.lang.get('filter.dates.filter_button_text'), reset_button_text: $.oc.lang.get('filter.dates.reset_button_text'), - date_placeholder: $.oc.lang.get('filter.dates.date_placeholder') - }); + date_placeholder: this.getLang('filter.dates.date_placeholder', 'Date') + }) - data.scopeName = scopeName; + data.scopeName = scopeName // Destroy any popovers already bound - $scope.data('oc.popover', null); + $scope.data('oc.popover', null) $scope.ocPopover({ content: Mustache.render(self.getPopoverDateTemplate(), data), @@ -203,24 +204,24 @@ return self.onCheckDocumentClickTargetDatePicker(target); } }) - }; + } FilterWidget.prototype.displayPopoverRange = function ($scope) { var self = this, scopeName = $scope.data('scope-name'), - data = this.scopeValues[scopeName]; + data = this.scopeValues[scopeName] data = $.extend({}, data, { filter_button_text: $.oc.lang.get('filter.dates.filter_button_text'), reset_button_text: $.oc.lang.get('filter.dates.reset_button_text'), - after_placeholder: $.oc.lang.get('filter.dates.after_placeholder'), - before_placeholder: $.oc.lang.get('filter.dates.before_placeholder') - }); + after_placeholder: this.getLang('filter.dates.after_placeholder', 'After'), + before_placeholder: this.getLang('filter.dates.before_placeholder', 'Before') + }) - data.scopeName = scopeName; + data.scopeName = scopeName // Destroy any popovers already bound - $scope.data('oc.popover', null); + $scope.data('oc.popover', null) $scope.ocPopover({ content: Mustache.render(self.getPopoverRangeTemplate(), data), @@ -229,16 +230,16 @@ closeOnPageClick: true, placement: 'bottom', onCheckDocumentClickTarget: function (target) { - return self.onCheckDocumentClickTargetDatePicker(target); + return self.onCheckDocumentClickTargetDatePicker(target) } }) - }; + } FilterWidget.prototype.initDatePickers = function (isRange) { var self = this, scopeData = self.$activeScope.data('scope-data'), $inputs = $('.field-datepicker input', '#controlFilterPopover'), - data = self.scopeValues[self.activeScopeName]; + data = self.scopeValues[self.activeScopeName] if (!data) { data = { @@ -256,7 +257,7 @@ setDefaultDate: '' !== defaultValue ? defaultValue.toDate() : '', format: self.getDateFormat(), i18n: $.oc.lang.get('datepicker') - }; + } if (0 <= index && index < data.dates.length) { defaultValue = moment(data.dates[index], 'YYYY-MM-DD') @@ -272,22 +273,22 @@ $datepicker.pikaday(defaults) }) - }; + } FilterWidget.prototype.clearDatePickers = function () { - var $inputs = $('.field-datepicker input', '#controlFilterPopover'); + var $inputs = $('.field-datepicker input', '#controlFilterPopover') $inputs.each(function (index, datepicker) { - var $datepicker = $(datepicker); + var $datepicker = $(datepicker) - $datepicker.data('pikaday').destroy(); + $datepicker.data('pikaday').destroy() }) - }; + } FilterWidget.prototype.updateScopeDateSetting = function ($scope, dates) { var self = this, $setting = $scope.find('.filter-setting'), - dateFormat = self.getDateFormat(); + dateFormat = self.getDateFormat() if (dates && dates.length) { if (dates.length > 1) { @@ -295,21 +296,22 @@ before = moment(dates[1], 'YYYY-MM-DD').format(dateFormat); $setting.text(after + ' → ' + before) - } else { + } + else { $setting.text(moment(dates[0], 'YYYY-MM-DD').format(dateFormat)) } $scope.addClass('active') } else { - $setting.text($.oc.lang.get('filter.dates.all')); + $setting.text(this.getLang('filter.dates.all', 'all')); $scope.removeClass('active') } - }; + } FilterWidget.prototype.filterByDate = function (isReset) { var self = this, - dates = []; + dates = [] if (!isReset) { $('.field-datepicker input', '#controlFilterPopover').each(function (index, datepicker) { @@ -320,17 +322,24 @@ self.updateScopeDateSetting(self.$activeScope, dates); self.scopeValues[self.activeScopeName] = { dates: dates - }; + } self.isActiveScopeDirty = true; self.$activeScope.data('oc.popover').hide() - }; + } FilterWidget.prototype.getDateFormat = function () { - return $.oc.lang.get('filter.dates.format') - }; + if (this.locale) { + return moment() + .locale(this.locale) + .localeData() + .longDateFormat('l') + } + + return 'YYYY-MM-DD' + } FilterWidget.prototype.onCheckDocumentClickTargetDatePicker = function (target) { - var $target = $(target); + var $target = $(target) // If the click happens on a pikaday element, do not close the popover return $target.hasClass('pika-next') || @@ -338,6 +347,21 @@ $target.hasClass('pika-select') || $target.hasClass('pika-button') || $target.parents('.pika-table').length || - $target.parents('.pika-title').length; - }; + $target.parents('.pika-title').length + } + + FilterWidget.prototype.initRegion = function() { + this.locale = $('meta[name="backend-locale"]').attr('content') + this.timezone = $('meta[name="backend-timezone"]').attr('content') + this.appTimezone = $('meta[name="app-timezone"]').attr('content') + + if (!this.appTimezone) { + this.appTimezone = 'UTC' + } + + if (!this.timezone) { + this.timezone = 'UTC' + } + } + }(window.jQuery); \ No newline at end of file diff --git a/modules/system/assets/ui/storm-min.js b/modules/system/assets/ui/storm-min.js index 4430234a0..8fe662e12 100644 --- a/modules/system/assets/ui/storm-min.js +++ b/modules/system/assets/ui/storm-min.js @@ -3013,9 +3013,27 @@ return result?result:this} $.fn.filterWidget.Constructor=FilterWidget $.fn.filterWidget.noConflict=function(){$.fn.filterWidget=old return this} -$(document).render(function(){$('[data-control="filterwidget"]').filterWidget();})}(window.jQuery);+function($){"use strict";var FilterWidget=$.fn.filterWidget.Constructor;var overloaded_init=FilterWidget.prototype.init;FilterWidget.prototype.init=function(){overloaded_init.apply(this);this.initFilterDate();};FilterWidget.prototype.initFilterDate=function(){var self=this;this.$el.on('show.oc.popover','a.filter-scope-date',function(){self.initDatePickers($(this).hasClass('range'));});this.$el.on('hiding.oc.popover','a.filter-scope-date',function(){self.clearDatePickers();});this.$el.on('hide.oc.popover','a.filter-scope-date',function(){var $scope=$(this);self.pushOptions(self.activeScopeName);self.activeScopeName=null;self.$activeScope=null;setTimeout(function(){$scope.removeClass('filter-scope-open')},200)});this.$el.on('click','a.filter-scope-date',function(){var $scope=$(this),scopeName=$scope.data('scope-name');if($scope.hasClass('filter-scope-open'))return;if(null!==self.activeScopeName)return;self.$activeScope=$scope;self.activeScopeName=scopeName;self.isActiveScopeDirty=false;if($scope.hasClass('range')){self.displayPopoverRange($scope)} +$(document).render(function(){$('[data-control="filterwidget"]').filterWidget();})}(window.jQuery);+function($){"use strict";var FilterWidget=$.fn.filterWidget.Constructor;var overloaded_init=FilterWidget.prototype.init;FilterWidget.prototype.init=function(){overloaded_init.apply(this);this.initRegion() +this.initFilterDate()} +FilterWidget.prototype.initFilterDate=function(){var self=this +this.$el.on('show.oc.popover','a.filter-scope-date',function(){self.initDatePickers($(this).hasClass('range'))});this.$el.on('hiding.oc.popover','a.filter-scope-date',function(){self.clearDatePickers()});this.$el.on('hide.oc.popover','a.filter-scope-date',function(){var $scope=$(this) +self.pushOptions(self.activeScopeName) +self.activeScopeName=null +self.$activeScope=null +setTimeout(function(){$scope.removeClass('filter-scope-open')},200)});this.$el.on('click','a.filter-scope-date',function(){var $scope=$(this),scopeName=$scope.data('scope-name') +if($scope.hasClass('filter-scope-open'))return +if(null!==self.activeScopeName)return +self.$activeScope=$scope +self.activeScopeName=scopeName +self.isActiveScopeDirty=false +if($scope.hasClass('range')){self.displayPopoverRange($scope)} else{self.displayPopoverDate($scope)} -$scope.addClass('filter-scope-open')});$(document).on('click','#controlFilterPopover [data-trigger="filter"]',function(e){e.preventDefault();e.stopPropagation();self.filterByDate()});$(document).on('click','#controlFilterPopover [data-trigger="clear"]',function(e){e.preventDefault();e.stopPropagation();self.filterByDate(true)})};FilterWidget.prototype.getPopoverDateTemplate=function(){return' \ +$scope.addClass('filter-scope-open')});$(document).on('click','#controlFilterPopover [data-trigger="filter"]',function(e){e.preventDefault() +e.stopPropagation() +self.filterByDate()});$(document).on('click','#controlFilterPopover [data-trigger="clear"]',function(e){e.preventDefault() +e.stopPropagation() +self.filterByDate(true)})} +FilterWidget.prototype.getPopoverDateTemplate=function(){return' \
\ \
\ @@ -3040,7 +3058,8 @@ $scope.addClass('filter-scope-open')});$(document).on('click','#controlFilterPop
\ \
\ - '};FilterWidget.prototype.getPopoverRangeTemplate=function(){return' \ + '} +FilterWidget.prototype.getPopoverRangeTemplate=function(){return' \
\ \
\ @@ -3080,13 +3099,41 @@ $scope.addClass('filter-scope-open')});$(document).on('click','#controlFilterPop
\ \
\ - '};FilterWidget.prototype.displayPopoverDate=function($scope){var self=this,scopeName=$scope.data('scope-name'),data=this.scopeValues[scopeName];data=$.extend({},data,{filter_button_text:$.oc.lang.get('filter.dates.filter_button_text'),reset_button_text:$.oc.lang.get('filter.dates.reset_button_text'),date_placeholder:$.oc.lang.get('filter.dates.date_placeholder')});data.scopeName=scopeName;$scope.data('oc.popover',null);$scope.ocPopover({content:Mustache.render(self.getPopoverDateTemplate(),data),modal:false,highlightModalTarget:true,closeOnPageClick:true,placement:'bottom',onCheckDocumentClickTarget:function(target){return self.onCheckDocumentClickTargetDatePicker(target);}})};FilterWidget.prototype.displayPopoverRange=function($scope){var self=this,scopeName=$scope.data('scope-name'),data=this.scopeValues[scopeName];data=$.extend({},data,{filter_button_text:$.oc.lang.get('filter.dates.filter_button_text'),reset_button_text:$.oc.lang.get('filter.dates.reset_button_text'),after_placeholder:$.oc.lang.get('filter.dates.after_placeholder'),before_placeholder:$.oc.lang.get('filter.dates.before_placeholder')});data.scopeName=scopeName;$scope.data('oc.popover',null);$scope.ocPopover({content:Mustache.render(self.getPopoverRangeTemplate(),data),modal:false,highlightModalTarget:true,closeOnPageClick:true,placement:'bottom',onCheckDocumentClickTarget:function(target){return self.onCheckDocumentClickTargetDatePicker(target);}})};FilterWidget.prototype.initDatePickers=function(isRange){var self=this,scopeData=self.$activeScope.data('scope-data'),$inputs=$('.field-datepicker input','#controlFilterPopover'),data=self.scopeValues[self.activeScopeName];if(!data){data={dates:isRange?(scopeData.dates?scopeData.dates:[]):(scopeData.date?[scopeData.date]:[])}} -$inputs.each(function(index,datepicker){var defaultValue='',$datepicker=$(datepicker),defaults={minDate:new Date(scopeData.minDate),maxDate:new Date(scopeData.maxDate),yearRange:10,setDefaultDate:''!==defaultValue?defaultValue.toDate():'',format:self.getDateFormat(),i18n:$.oc.lang.get('datepicker')};if(0<=index&&index1){var after=moment(dates[0],'YYYY-MM-DD').format(dateFormat),before=moment(dates[1],'YYYY-MM-DD').format(dateFormat);$setting.text(after+' → '+before)}else{$setting.text(moment(dates[0],'YYYY-MM-DD').format(dateFormat))} +datepicker.value=''!==defaultValue?defaultValue.format(self.getDateFormat()):'';$datepicker.pikaday(defaults)})} +FilterWidget.prototype.clearDatePickers=function(){var $inputs=$('.field-datepicker input','#controlFilterPopover') +$inputs.each(function(index,datepicker){var $datepicker=$(datepicker) +$datepicker.data('pikaday').destroy()})} +FilterWidget.prototype.updateScopeDateSetting=function($scope,dates){var self=this,$setting=$scope.find('.filter-setting'),dateFormat=self.getDateFormat() +if(dates&&dates.length){if(dates.length>1){var after=moment(dates[0],'YYYY-MM-DD').format(dateFormat),before=moment(dates[1],'YYYY-MM-DD').format(dateFormat);$setting.text(after+' → '+before)} +else{$setting.text(moment(dates[0],'YYYY-MM-DD').format(dateFormat))} $scope.addClass('active')} -else{$setting.text($.oc.lang.get('filter.dates.all'));$scope.removeClass('active')}};FilterWidget.prototype.filterByDate=function(isReset){var self=this,dates=[];if(!isReset){$('.field-datepicker input','#controlFilterPopover').each(function(index,datepicker){dates.push($(datepicker).data('pikaday').toString('YYYY-MM-DD'))})} -self.updateScopeDateSetting(self.$activeScope,dates);self.scopeValues[self.activeScopeName]={dates:dates};self.isActiveScopeDirty=true;self.$activeScope.data('oc.popover').hide()};FilterWidget.prototype.getDateFormat=function(){return $.oc.lang.get('filter.dates.format')};FilterWidget.prototype.onCheckDocumentClickTargetDatePicker=function(target){var $target=$(target);return $target.hasClass('pika-next')||$target.hasClass('pika-prev')||$target.hasClass('pika-select')||$target.hasClass('pika-button')||$target.parents('.pika-table').length||$target.parents('.pika-title').length;};}(window.jQuery);(function($){$(document).render(function(){if(Modernizr.touch) +else{$setting.text(this.getLang('filter.dates.all','all'));$scope.removeClass('active')}} +FilterWidget.prototype.filterByDate=function(isReset){var self=this,dates=[] +if(!isReset){$('.field-datepicker input','#controlFilterPopover').each(function(index,datepicker){dates.push($(datepicker).data('pikaday').toString('YYYY-MM-DD'))})} +self.updateScopeDateSetting(self.$activeScope,dates);self.scopeValues[self.activeScopeName]={dates:dates} +self.isActiveScopeDirty=true;self.$activeScope.data('oc.popover').hide()} +FilterWidget.prototype.getDateFormat=function(){if(this.locale){return moment().locale(this.locale).localeData().longDateFormat('l')} +return'YYYY-MM-DD'} +FilterWidget.prototype.onCheckDocumentClickTargetDatePicker=function(target){var $target=$(target);return $target.hasClass('pika-next')||$target.hasClass('pika-prev')||$target.hasClass('pika-select')||$target.hasClass('pika-button')||$target.parents('.pika-table').length||$target.parents('.pika-title').length;} +FilterWidget.prototype.initRegion=function(){this.locale=$('meta[name="backend-locale"]').attr('content') +this.timezone=$('meta[name="backend-timezone"]').attr('content') +this.appTimezone=$('meta[name="app-timezone"]').attr('content') +if(!this.appTimezone){this.appTimezone='UTC'} +if(!this.timezone){this.timezone='UTC'}}}(window.jQuery);(function($){$(document).render(function(){if(Modernizr.touch) return var formatSelectOption=function(state){if(!state.id) return state.text;var $option=$(state.element),iconClass=$option.data('icon'),imageSrc=$option.data('image') diff --git a/modules/system/lang/en/client.php b/modules/system/lang/en/client.php index 631c5b697..f9f92346d 100644 --- a/modules/system/lang/en/client.php +++ b/modules/system/lang/en/client.php @@ -64,8 +64,7 @@ return [ 'all' => 'all' ], 'dates' => [ - 'format' => 'YYYY-MM-DD', // Moment.js date format - 'all' => 'all period', + 'all' => 'all', 'filter_button_text' => 'Filter', 'reset_button_text' => 'Reset', 'date_placeholder' => 'Date', diff --git a/modules/system/lang/fr/client.php b/modules/system/lang/fr/client.php index d1d2841b2..ef37d6a43 100644 --- a/modules/system/lang/fr/client.php +++ b/modules/system/lang/fr/client.php @@ -67,7 +67,6 @@ return [ 'all' => 'tous' ], 'dates' => [ - 'format' => 'DD/MM/YYYY', // Moment.js date format 'all' => 'toute la période', 'filter_button_text' => 'Filtrer', 'reset_button_text' => 'Effacer',