// Date Range picker improvements

This commit is contained in:
Jerome Nadaud
2013-10-17 11:39:02 +02:00
parent 6ed7ffc647
commit f9b115a2f8
5 changed files with 57 additions and 39 deletions
@@ -49,17 +49,17 @@
<div class='form-date-heading'> <div class='form-date-heading'>
<span class="checkbox-title"> <span class="checkbox-title">
<label > <label >
<input type='checkbox' id="datepicker-compare"> <input type='checkbox' id="datepicker-compare" name="datepicker_compare"{if isset($compare_date_from) && isset($compare_date_to)} checked="checked"{/if}>
{l s='Compare to'} {l s='Compare to'}
</label> </label>
</span> </span>
<select id="compare-options" name="compare_date_option" disabled="disabled"> <select id="compare-options" name="compare_date_option"{if is_null($compare_date_from) || is_null($compare_date_to)} disabled="disabled"{/if}>
<option value="1"{if $compare_option == 1}selected="selected"{/if} label="{l s='Previous period'}">{l s='Previous period'}</option> <option value="1"{if $compare_option == 1}selected="selected"{/if} label="{l s='Previous period'}">{l s='Previous period'}</option>
<option value="2"{if $compare_option == 2}selected="selected"{/if} label="{l s='Previous Year'}">{l s='Previous Year'}</option> <option value="2"{if $compare_option == 2}selected="selected"{/if} label="{l s='Previous Year'}">{l s='Previous Year'}</option>
<option value="3"{if $compare_option == 3}selected="selected"{/if} label="{l s='Custom'}">{l s='Custom'}</option> <option value="3"{if $compare_option == 3}selected="selected"{/if} label="{l s='Custom'}">{l s='Custom'}</option>
</select> </select>
</div> </div>
<div class="form-date-body" id="form-date-body-compare" style="display: none;"> <div class="form-date-body" id="form-date-body-compare"{if is_null($compare_date_from) || is_null($compare_date_to)} style="display: none;"{/if}>
<label>{l s='From'}</label> <label>{l s='From'}</label>
<input id="date-start-compare" class="date-input form-control" type="text" placeholder="Start" name="compare_date_from" value="{$compare_date_from}" /> <input id="date-start-compare" class="date-input form-control" type="text" placeholder="Start" name="compare_date_from" value="{$compare_date_from}" />
<label>{l s='to'}</label> <label>{l s='to'}</label>
@@ -152,10 +152,12 @@
function setPreviousPeriod() { function setPreviousPeriod() {
startDate = parseDate($("#date-start").val(), parseFormat('{$date_format}')); startDate = parseDate($("#date-start").val(), parseFormat('{$date_format}'));
startDate = startDate.setDate(startDate.getDate()-1);
endDate = parseDate($("#date-end").val(), parseFormat('{$date_format}')); endDate = parseDate($("#date-end").val(), parseFormat('{$date_format}'));
diff = endDate.getTime() - startDate.getTime(); endDate = endDate.setDate(endDate.getDate()-1);
startDateCompare = startDate.getTime()-diff; diff = endDate - startDate;
$("#date-end-compare").val($("#date-start").val()); startDateCompare = startDate-diff;
$("#date-end-compare").val(formatDate(new Date(startDate), parseFormat('{$date_format}')));
$("#date-start-compare").val(formatDate(new Date(startDateCompare), parseFormat('{$date_format}'))); $("#date-start-compare").val(formatDate(new Date(startDateCompare), parseFormat('{$date_format}')));
} }
@@ -238,6 +240,9 @@
$('#datepicker-compare').click(function() { $('#datepicker-compare').click(function() {
if ($(this).attr("checked")) { if ($(this).attr("checked")) {
if ($("#date-start-compare").val().replace(/^\s+|\s+$/g, '').length == 0)
$('#compare-options').trigger('change');
datepickerStart.setStartCompare($("#date-start-compare").val()); datepickerStart.setStartCompare($("#date-start-compare").val());
datepickerStart.setEndCompare($("#date-end-compare").val()); datepickerStart.setEndCompare($("#date-end-compare").val());
datepickerEnd.setStartCompare($("#date-start-compare").val()); datepickerEnd.setStartCompare($("#date-start-compare").val());
@@ -266,6 +271,18 @@
$('#date-start-compare').focus(); $('#date-start-compare').focus();
}); });
if ($('#datepicker-compare').attr("checked"))
{
if ($("#date-start-compare").val().replace(/^\s+|\s+$/g, '').length == 0)
$('#compare-options').trigger('change');
datepickerStart.setStartCompare($("#date-start-compare").val());
datepickerStart.setEndCompare($("#date-end-compare").val());
datepickerEnd.setStartCompare($("#date-start-compare").val());
datepickerEnd.setEndCompare($("#date-end-compare").val());
datepickerStart.setCompare(true);
datepickerEnd.setCompare(true);
}
{/literal} {/literal}
}); });
</script> </script>
+5 -5
View File
@@ -135,16 +135,16 @@ class EmployeeCore extends ObjectModel
public function getFields() public function getFields()
{ {
if (empty($this->stats_date_from)) if (empty($this->stats_date_from))
$this->stats_date_from = date('Y-m-d 00:00:00'); $this->stats_date_from = date('Y-m-d 00:00:00', strtotime("-1 month"));
if (empty($this->stats_compare_from)) if (empty($this->stats_compare_from) || $this->stats_compare_from == '0000-00-00')
$this->stats_compare_from = date('Y-m-d 00:00:00'); $this->stats_compare_from = null;
if (empty($this->stats_date_to)) if (empty($this->stats_date_to))
$this->stats_date_to = date('Y-m-d 23:59:59'); $this->stats_date_to = date('Y-m-d 23:59:59');
if (empty($this->stats_compare_to)) if (empty($this->stats_compare_to) || $this->stats_compare_to == '0000-00-00')
$this->stats_compare_to = date('Y-m-d 00:00:00'); $this->stats_compare_to = null;
return parent::getFields(); return parent::getFields();
} }
+2 -19
View File
@@ -26,7 +26,8 @@
class HelperCalendarCore extends Helper class HelperCalendarCore extends Helper
{ {
const DEFAULT_DATE_FORMAT = 'Y-m-d'; const DEFAULT_DATE_FORMAT = 'Y-m-d';
const DEFAULT_COMPARE_OPTION = 1;
private $_actions; private $_actions;
private $_compare_actions; private $_compare_actions;
@@ -81,41 +82,23 @@ class HelperCalendarCore extends Helper
public function setCompareDateFrom($value) public function setCompareDateFrom($value)
{ {
if (!isset($value) || $value == '')
$value = date('Y-m-d', strtotime("-31 days"));
if (!is_string($value))
throw new PrestaShopException('Date must be a string');
$this->_compare_date_from = $value; $this->_compare_date_from = $value;
return $this; return $this;
} }
public function getCompareDateFrom() public function getCompareDateFrom()
{ {
if (!isset($this->_compare_date_from))
$this->_compare_date_from = date('Y-m-d', strtotime("-31 days"));
return $this->_compare_date_from; return $this->_compare_date_from;
} }
public function setCompareDateTo($value) public function setCompareDateTo($value)
{ {
if (!isset($value) || $value == '')
$value = date('Y-m-d');
if (!is_string($value))
throw new PrestaShopException('Date must be a string');
$this->_compare_date_to = $value; $this->_compare_date_to = $value;
return $this; return $this;
} }
public function getCompareDateTo() public function getCompareDateTo()
{ {
if (!isset($this->_compare_date_to))
$this->_compare_date_to = date('Y-m-d');
return $this->_compare_date_to; return $this->_compare_date_to;
} }
+27 -5
View File
@@ -152,10 +152,21 @@ class AdminDashboardControllerCore extends AdminController
); );
$calendar_helper = new HelperCalendar(); $calendar_helper = new HelperCalendar();
$calendar_helper->setDateFrom(Tools::getValue('date_from', $this->context->employee->stats_date_from)); $calendar_helper->setDateFrom(Tools::getValue('date_from', $this->context->employee->stats_date_from));
$calendar_helper->setDateTo(Tools::getValue('date_to', $this->context->employee->stats_date_to)); $calendar_helper->setDateTo(Tools::getValue('date_to', $this->context->employee->stats_date_to));
$calendar_helper->setCompareDateFrom(Tools::getValue('compare_date_from', $this->context->employee->stats_compare_from));
$calendar_helper->setCompareDateTo(Tools::getValue('compare_date_to', $this->context->employee->stats_compare_to)); $stats_compare_from = $this->context->employee->stats_compare_from;
$stats_compare_to = $this->context->employee->stats_compare_to;
if (is_null($stats_compare_from) || $stats_compare_from == '0000-00-00')
$stats_compare_from = null;
if (is_null($stats_compare_to) || $stats_compare_to == '0000-00-00')
$stats_compare_to = null;
$calendar_helper->setCompareDateFrom($stats_compare_from);
$calendar_helper->setCompareDateTo($stats_compare_to);
$calendar_helper->setCompareOption(Tools::getValue('compare_date_option', $this->context->employee->stats_compare_option)); $calendar_helper->setCompareOption(Tools::getValue('compare_date_option', $this->context->employee->stats_compare_option));
$this->tpl_view_vars = array( $this->tpl_view_vars = array(
@@ -179,9 +190,20 @@ class AdminDashboardControllerCore extends AdminController
{ {
$this->context->employee->stats_date_from = Tools::getValue('date_from'); $this->context->employee->stats_date_from = Tools::getValue('date_from');
$this->context->employee->stats_date_to = Tools::getValue('date_to'); $this->context->employee->stats_date_to = Tools::getValue('date_to');
$this->context->employee->stats_compare_from = Tools::getValue('compare_date_from');
$this->context->employee->stats_compare_to = Tools::getValue('compare_date_to'); if (Tools::getValue('datepicker_compare'))
$this->context->employee->stats_compare_option = Tools::getValue('compare_date_option'); {
$this->context->employee->stats_compare_from = Tools::getValue('compare_date_from');
$this->context->employee->stats_compare_to = Tools::getValue('compare_date_to');
$this->context->employee->stats_compare_option = Tools::getValue('compare_date_option');
}
else
{
$this->context->employee->stats_compare_from = null;
$this->context->employee->stats_compare_to = null;
$this->context->employee->stats_compare_option = HelperCalendar::DEFAULT_COMPARE_OPTION;
}
$this->context->employee->update(); $this->context->employee->update();
} }
-4
View File
@@ -464,10 +464,6 @@ class InstallModelInstall extends InstallAbstractModel
$employee->bo_theme = 'default'; $employee->bo_theme = 'default';
$employee->default_tab = 1; $employee->default_tab = 1;
$employee->active = true; $employee->active = true;
$employee->stats_date_from = date('Y').'-01-01';
$employee->stats_date_to = date('Y').'-12-31';
$employee->stats_compare_from = date('Y').'-01-01';
$employee->stats_compare_to = date('Y').'-12-31';
$employee->id_profile = 1; $employee->id_profile = 1;
$employee->id_lang = Configuration::get('PS_LANG_DEFAULT'); $employee->id_lang = Configuration::get('PS_LANG_DEFAULT');
$employee->bo_menu = 1; $employee->bo_menu = 1;