// Starting development of data range picker

This commit is contained in:
Jerome Nadaud
2013-10-11 16:12:40 +02:00
parent 1849995291
commit bedcacf0b4
5 changed files with 213 additions and 56 deletions
@@ -17,14 +17,6 @@
* limitations under the License.
* ========================================================= */
$(function() {
var currentMonth = new Date(Date.now());
var previousMonth = new Date(new Date(currentMonth).setMonth(currentMonth.getMonth()-1));
$('.datepicker1').datepicker("setValue",previousMonth);
$('.datepicker2').datepicker("setValue",currentMonth);
$("#date-start").focus().addClass("input-selected");
});
//click action
!function( $ ) {
var click, switched, val, start, end, over;
@@ -35,6 +35,11 @@
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
{$calendar}
</div>
</div>
</form>
<script type="text/javascript">
$(document).ready(function() {
@@ -1,48 +1,51 @@
<form class='form-inline' id='datepicker-form'>
<fieldset class='form-date-group' id='date-range'>
<div class='form-date-heading'>
Date range
<div class='btn btn-default btn-xs pull-right dropdown-toggle' data-toggle='dropdown'>
Custom
<i class='icon-angle-down'></i>
<ul class='dropdown-menu'>
<li>
<a>test</a>
</li>
</ul>
</div>
</div>
<div class='form-date-body form-group'>
<label>From</label>
<input class='date-input form-control' id='date-start' placeholder='Start' type='text'>
<label>to</label>
<input class='date-input form-control' id='date-end' placeholder='End' type='text'>
</div>
</fieldset>
<fieldset class='form-date-group' disabled='' id='date-compare'>
<div class='form-date-heading'>
<input type='checkbox'>
Compare to
<div class='btn btn-default btn-xs pull-right dropdown-toggle' data-toggle='dropdown'>
Custom
<i class='icon-angle-down'></i>
</div>
</div>
<div class='form-date-body form-group'>
<label>From</label>
<input class='date-input form-control' id='date-start' placeholder='Start' type='text'>
<label>to</label>
<input class='date-input form-control' id='date-end' placeholder='End' type='text'>
</div>
</fieldset>
<div class='actions'>
<button class='btn-default' type='button'>
<i class='icon-remove'></i>
Cancel
</button>
<button class='btn-primary pull-right' type='submit'>
<i class='icon-ok'></i>
Apply
</button>
<div id="datepicker" class="datepicker-days">
<div class="datepickers-container">
<div class="datepicker1" data-date="{$from_date}" data-date-format="{$date_format}"></div>
<div class="datepicker2" data-date="{$to_date}" data-date-format="{$date_format}"></div>
</div>
</form>
<form class='form-inline' id='datepicker-form'>
<fieldset class='form-date-group' id='date-range'>
<div class='form-date-heading'>
{l s='Date range'}
{if isset($actions) || $actions|count > 0}
{if $actions|count > 1}
<div class='btn btn-default btn-xs pull-right dropdown-toggle' data-toggle='dropdown'>
{l s='Custom'}
<i class='icon-angle-down'></i>
<ul class='dropdown-menu'>
{foreach from=$actions item=action}
<li><a{if isset($action.href)} href="{$action.href}"{/if}{if isset($action.class)} class="{$action.class}"{/if}>{if isset($action.icon)}<i class="{$action.icon}"> {/if}{$action.label}</a></li>
{/foreach}
</ul>
</div>
{else}
<a{if isset($actions[0].href)} href="{$actions[0].href}"{/if} class="btn btn-default btn-xs pull-right{if isset($actions[0].class)} {$actions[0].class}{/if}">{if isset($actions[0].icon)}<i class="{$actions[0].icon}"></i> {/if}{$actions[0].label}</a>
{/if}
{/if}
</div>
<div class='form-date-body form-group'>
<label>{l s='From'}</label>
<input class='date-input form-control' id='date-start' placeholder='Start' type='text'>
<label>{l s='to'}</label>
<input class='date-input form-control' id='date-end' placeholder='End' type='text'>
</div>
</fieldset>
<div class='actions'>
<button class='btn-default' type='button'>
<i class='icon-remove'></i>
{l s='Cancel'}
</button>
<button class='btn-primary pull-right' type='submit'>
<i class='icon-ok'></i>
{l s='Apply'}
</button>
</div>
</form>
</div>
<script type="text/javascript">
$(function() {
$('.datepicker1').datepicker();
$('.datepicker2').datepicker();
$("#date-start").focus().addClass("input-selected");
});
</script>
+154
View File
@@ -0,0 +1,154 @@
<?php
/*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2013 PrestaShop SA
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class HelperCalendarCore extends Helper
{
const DEFAULT_DATE_FORMAT = 'dd-mm-yyyy';
private $_actions;
private $_date_format;
private $_from_date;
private $_to_date;
public function __construct()
{
$this->base_folder = 'helpers/calendar/';
$this->base_tpl = 'calendar.tpl';
parent::__construct();
}
public function setActions($value)
{
if (!is_array($value) && !$value instanceof Traversable)
throw new PrestaShopException('Actions value must be an traversable array');
$this->_actions = $value;
return $this;
}
public function getActions()
{
if (!isset($this->_actions))
$this->_actions = array();
return $this->_actions;
}
public function setDateFormat($value)
{
if (!is_string($value))
throw new PrestaShopException('Date format must be string');
$this->_date_format = $value;
return $this;
}
public function getDateFormat()
{
if (!isset($this->_date_format))
$this->_date_format = self::DEFAULT_DATE_FORMAT;
return $this->_date_format;
}
public function setFromDate($value)
{
if (!is_string($value))
throw new PrestaShopException('Date format must be string');
$this->_from_date = $value;
return $this;
}
public function getFromDate()
{
if (!isset($this->_from_date))
$this->_from_date = date('d-m-Y', strtotime("-31 days"));
return $this->_from_date;
}
public function setToDate($value)
{
if (!is_string($value))
throw new PrestaShopException('Date format must be string');
$this->_to_date = $value;
return $this;
}
public function getToDate()
{
if (!isset($this->_to_date))
$this->_to_date = date('d-m-Y');
return $this->_to_date;
}
public function addAction($action)
{
if (!isset($this->_actions))
$this->_actions = array();
$this->_actions[] = $action;
return $this;
}
public function generate()
{
$context = Context::getContext();
$admin_webpath = str_ireplace(_PS_ROOT_DIR_, '', _PS_ADMIN_DIR_);
$admin_webpath = preg_replace('/^'.preg_quote(DIRECTORY_SEPARATOR, '/').'/', '', $admin_webpath);
$bo_theme = ((Validate::isLoadedObject($context->employee)
&& $context->employee->bo_theme) ? $context->employee->bo_theme : 'default');
if (!file_exists(_PS_BO_ALL_THEMES_DIR_.$bo_theme.DIRECTORY_SEPARATOR
.'template'))
$bo_theme = 'default';
if ($context->controller->ajax)
$html = '<script type="text/javascript" src="'.__PS_BASE_URI__.$admin_webpath
.'/themes/'.$bo_theme.'/js/date-range-picker.js"></script>';
else
{
$html = '';
$context->controller->addJs(__PS_BASE_URI__.$admin_webpath
.'/themes/'.$bo_theme.'/js/date-range-picker.js');
}
$this->tpl = $this->createTemplate($this->base_tpl);
$this->tpl->assign(array(
'date_format' => $this->getDateFormat(),
'from_date' => $this->getFromDate(),
'to_date' => $this->getToDate(),
'actions' => $this->getActions()
));
$html .= parent::generate();
return $html;
}
}
@@ -42,7 +42,7 @@ class AdminDashboardControllerCore extends AdminController
$admin_webpath = str_ireplace(_PS_ROOT_DIR_, '', _PS_ADMIN_DIR_);
$admin_webpath = preg_replace('/^'.preg_quote(DIRECTORY_SEPARATOR, '/').'/', '', $admin_webpath);
parent::setMedia();
$this->addJqueryUI('ui.datepicker');
//$this->addJqueryUI('ui.datepicker');
$this->addJS(array(
_PS_JS_DIR_.'/vendor/d3.js',
__PS_BASE_URI__.$admin_webpath.'/themes/'.$this->bo_theme.'/js/vendor/nv.d3.js',
@@ -150,6 +150,8 @@ class AdminDashboardControllerCore extends AdminController
'To' => $this->l('To:', 'AdminStatsTab'),
'Save' => $this->l('Save', 'AdminStatsTab')
);
$calendar_helper = new HelperCalendar();
$this->tpl_view_vars = array(
'hookDashboardZoneOne' => Hook::exec('dashboardZoneOne'),
@@ -159,6 +161,7 @@ class AdminDashboardControllerCore extends AdminController
'warning' => $this->getWarningDomainName(),
'new_version_url' => Tools::getCurrentUrlProtocolPrefix().'api.prestashop.com/version/check_version.php?v='._PS_VERSION_.'&lang='.$this->context->language->iso_code,
'dashboard_use_push' => Configuration::get('PS_DASHBOARD_USE_PUSH'),
'calendar' => $calendar_helper->generate(),
'datepickerFrom' => Tools::getValue('datepickerFrom', $this->context->employee->stats_date_from),
'datepickerTo' => Tools::getValue('datepickerTo', $this->context->employee->stats_date_to)
);