This commit is contained in:
Franck Allimant
2013-10-31 16:46:20 +01:00
11 changed files with 459 additions and 301 deletions

View File

@@ -9,6 +9,18 @@
<default key="_controller">Thelia\Controller\Admin\AdminController::indexAction</default>
</route>
<!-- home -->
<route id="admin.home.view" path="/admin/home">
<default key="_controller">Thelia\Controller\Admin\HomeController::defaultAction</default>
</route>
<route id="admin.home.stats" path="/admin/home/stats">
<default key="_controller">Thelia\Controller\Admin\HomeController::loadStatsAjaxAction</default>
</route>
<!-- end home -->
<!-- Route to the administration login page -->
<route id="admin.login" path="/admin/login">
<default key="_controller">Thelia\Controller\Admin\SessionController::showLoginAction</default>

View File

@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8" ?>
<config xmlns="http://thelia.net/schema/dic/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://thelia.net/schema/dic/config http://thelia.net/schema/dic/config/thelia-1.0.xsd">
<parameters>
<parameter key="translation.loader.php.class">Symfony\Component\Translation\Loader\PhpFileLoader</parameter>
<parameter key="translation.loader.yml.class">Symfony\Component\Translation\Loader\YamlFileLoader</parameter>
<parameter key="translation.loader.xliff.class">Symfony\Component\Translation\Loader\XliffFileLoader</parameter>
<parameter key="translation.loader.po.class">Symfony\Component\Translation\Loader\PoFileLoader</parameter>
<parameter key="translation.loader.mo.class">Symfony\Component\Translation\Loader\MoFileLoader</parameter>
<parameter key="translation.loader.qt.class">Symfony\Component\Translation\Loader\QtFileLoader</parameter>
<parameter key="translation.loader.csv.class">Symfony\Component\Translation\Loader\CsvFileLoader</parameter>
<parameter key="translation.loader.res.class">Symfony\Component\Translation\Loader\IcuResFileLoader</parameter>
<parameter key="translation.loader.dat.class">Symfony\Component\Translation\Loader\IcuDatFileLoader</parameter>
<parameter key="translation.loader.ini.class">Symfony\Component\Translation\Loader\IniFileLoader</parameter>
</parameters>
<services>
<service id="translation.loader.php" class="%translation.loader.php.class%">
<tag name="translation.loader" alias="php" />
</service>
<service id="translation.loader.yml" class="%translation.loader.yml.class%">
<tag name="translation.loader" alias="yml" legacy-alias="yaml" />
</service>
<service id="translation.loader.xliff" class="%translation.loader.xliff.class%">
<tag name="translation.loader" alias="xlf" legacy-alias="xliff" />
</service>
<service id="translation.loader.po" class="%translation.loader.po.class%">
<tag name="translation.loader" alias="po" />
</service>
<service id="translation.loader.mo" class="%translation.loader.mo.class%">
<tag name="translation.loader" alias="mo" />
</service>
<service id="translation.loader.qt" class="%translation.loader.qt.class%">
<tag name="translation.loader" alias="ts" />
</service>
<service id="translation.loader.csv" class="%translation.loader.csv.class%">
<tag name="translation.loader" alias="csv" />
</service>
<service id="translation.loader.res" class="%translation.loader.res.class%">
<tag name="translation.loader" alias="res" />
</service>
<service id="translation.loader.dat" class="%translation.loader.res.class%">
<tag name="translation.loader" alias="dat" />
</service>
<service id="translation.loader.ini" class="%translation.loader.ini.class%">
<tag name="translation.loader" alias="ini" />
</service>
</services>
</config>

View File

@@ -0,0 +1,102 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Controller\Admin;
use Thelia\Core\Security\AccessManager;
use Thelia\Model\CustomerQuery;
use Thelia\Model\OrderQuery;
class HomeController extends BaseAdminController
{
const RESOURCE_CODE = "admin.home";
public function defaultAction()
{
if (null !== $response = $this->checkAuth(self::RESOURCE_CODE, AccessManager::VIEW)) return $response;
// Render the edition template.
return $this->render('home');
}
public function loadStatsAjaxAction()
{
$data = new \stdClass();
$data->title = "Stats on " . $this->getRequest()->query->get('month', date('m')) . "/" . $this->getRequest()->query->get('year', date('Y'));
/* sales */
$saleSeries = new \stdClass();
$saleSeries->color = $this->getRequest()->query->get('sales_color', '#adadad');
$saleSeries->data = OrderQuery::getSaleStats(
$this->getRequest()->query->get('month', date('m')),
$this->getRequest()->query->get('year', date('Y'))
);
/* new customers */
$newCustomerSeries = new \stdClass();
$newCustomerSeries->color = $this->getRequest()->query->get('customers_color', '#f39922');
$newCustomerSeries->data = CustomerQuery::getNewCustomersStats(
$this->getRequest()->query->get('month', date('m')),
$this->getRequest()->query->get('year', date('Y'))
);
/* orders */
$orderSeries = new \stdClass();
$orderSeries->color = $this->getRequest()->query->get('orders_color', '#5cb85c');
$orderSeries->data = OrderQuery::getOrdersStats(
$this->getRequest()->query->get('month', date('m')),
$this->getRequest()->query->get('year', date('Y'))
);
/* first order */
$firstOrderSeries = new \stdClass();
$firstOrderSeries->color = $this->getRequest()->query->get('first_orders_color', '#5bc0de');
$firstOrderSeries->data = OrderQuery::getFirstOrdersStats(
$this->getRequest()->query->get('month', date('m')),
$this->getRequest()->query->get('year', date('Y'))
);
/* cancelled orders */
$cancelledOrderSeries = new \stdClass();
$cancelledOrderSeries->color = $this->getRequest()->query->get('cancelled_orders_color', '#d9534f');
$cancelledOrderSeries->data = OrderQuery::getOrdersStats(
$this->getRequest()->query->get('month', date('m')),
$this->getRequest()->query->get('year', date('Y')),
array(5)
);
$data->series = array(
$saleSeries,
$newCustomerSeries,
$orderSeries,
$firstOrderSeries,
$cancelledOrderSeries,
);
$json = json_encode($data);
return $this->jsonResponse($json);
}
}

View File

@@ -31,6 +31,7 @@ use Thelia\Core\DependencyInjection\Compiler\RegisterListenersPass;
use Thelia\Core\DependencyInjection\Compiler\RegisterParserPluginPass;
use Thelia\Core\DependencyInjection\Compiler\RegisterRouterPass;
use Thelia\Core\DependencyInjection\Compiler\RegisterCouponConditionPass;
use Thelia\Core\DependencyInjection\Compiler\TranslatorPass;
/**
* First Bundle use in Thelia
@@ -63,6 +64,9 @@ class TheliaBundle extends Bundle
->addCompilerPass(new RegisterParserPluginPass())
->addCompilerPass(new RegisterRouterPass())
->addCompilerPass(new RegisterCouponPass())
->addCompilerPass(new RegisterCouponConditionPass());
->addCompilerPass(new RegisterCouponConditionPass())
->addCompilerPass(new TranslatorPass())
;
}
}

View File

@@ -24,6 +24,7 @@
namespace Thelia\Core\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
/**
@@ -49,8 +50,11 @@ class TranslatorPass implements CompilerPassInterface
$translator = $container->getDefinition('thelia.translator');
foreach($container->findTaggedServiceIds('translator.loader') as $id => $attributes) {
foreach($container->findTaggedServiceIds('translation.loader') as $id => $attributes) {
$translator->addMethodCall('addLoader', array($attributes[0]['alias'], new Reference($id)));
if (isset($attributes[0]['legacy-alias'])) {
$translator->addMethodCall('addLoader', array($attributes[0]['legacy-alias'], new Reference($id)));
}
}
}
}

View File

@@ -47,6 +47,7 @@ use Thelia\Config\DatabaseConfiguration;
use Thelia\Config\DefinePropel;
use Thelia\Core\TheliaContainerBuilder;
use Thelia\Core\DependencyInjection\Loader\XmlFileLoader;
use Thelia\Model\ConfigQuery;
use Symfony\Component\Config\FileLocator;
use Propel\Runtime\Propel;
@@ -122,7 +123,8 @@ class Thelia extends Kernel
if (defined("THELIA_INSTALL_MODE") === false) {
$modules = \Thelia\Model\ModuleQuery::getActivated();
$translator = $container->getDefinition('thelia.translator');
$dirs = array();
foreach ($modules as $module) {
try {
@@ -138,10 +140,38 @@ class Thelia extends Kernel
$loader = new XmlFileLoader($container, new FileLocator(THELIA_MODULE_DIR . "/" . ucfirst($module->getCode()) . "/Config"));
$loader->load("config.xml");
if (is_dir($dir = THELIA_MODULE_DIR . "/" . ucfirst($module->getCode()) . "/I18n")) {
$dirs[] = $dir;
}
} catch (\InvalidArgumentException $e) {
// FIXME: process module configuration exception
}
}
//Load translation from templates
//admin template
if(is_dir($dir = THELIA_TEMPLATE_DIR . '/admin/default/I18n')) {
$dirs[] = $dir;
}
//front template
$template = ConfigQuery::getActiveTemplate();
if(is_dir($dir = THELIA_TEMPLATE_DIR . $template . "/I18n")) {
$dirs[] = $dir;
}
if ($dirs) {
$finder = Finder::create()
->files()
->depth(0)
->in($dirs);
foreach ($finder as $file) {
list($locale, $format) = explode('.', $file->getBaseName(), 2);
$translator->addMethodCall('addResource', array($format, (string) $file, $locale));
}
}
}
}

View File

@@ -2,6 +2,7 @@
namespace Thelia\Model;
use Propel\Runtime\ActiveQuery\Criteria;
use Thelia\Model\Base\CustomerQuery as BaseCustomerQuery;
@@ -21,4 +22,20 @@ class CustomerQuery extends BaseCustomerQuery {
{
return self::create()->findOneByEmail($email);
}
public static function getNewCustomersStats($month, $year)
{
$numberOfDay = cal_days_in_month(CAL_GREGORIAN, $month, $year);
$stats = array();
for($day=1; $day<=$numberOfDay; $day++) {
$dayCustomers = self::create()
->filterByCreatedAt(sprintf("%s-%s-%s 00:00:00", $year, $month, $day), Criteria::GREATER_EQUAL)
->filterByCreatedAt(sprintf("%s-%s-%s 23:59:59", $year, $month, $day), Criteria::LESS_EQUAL)
->count();
$stats[] = array($day-1, $dayCustomers);
}
return $stats;
}
} // CustomerQuery

View File

@@ -3,6 +3,7 @@
namespace Thelia\Model;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\Join;
use Propel\Runtime\Exception\PropelException;
use Propel\Runtime\Propel;
use Thelia\Model\Base\OrderQuery as BaseOrderQuery;
@@ -54,4 +55,71 @@ class OrderQuery extends BaseOrderQuery
return $obj;
}
public static function getSaleStats($month, $year)
{
$numberOfDay = cal_days_in_month(CAL_GREGORIAN, $month, $year);
$stats = array();
for($day=1; $day<=$numberOfDay; $day++) {
$dayAmount = 0;
foreach(self::create()
->filterByStatusId(array(2,3,4), Criteria::IN)
->filterByCreatedAt(sprintf("%s-%s-%s 00:00:00", $year, $month, $day), Criteria::GREATER_EQUAL)
->filterByCreatedAt(sprintf("%s-%s-%s 23:59:59", $year, $month, $day), Criteria::LESS_EQUAL)
->find() as $dayOrders) {
$dayAmount += $dayOrders->getTotalAmount();
}
$stats[] = array($day-1, $dayAmount);
}
return $stats;
}
public static function getOrdersStats($month, $year, $status = null)
{
$numberOfDay = cal_days_in_month(CAL_GREGORIAN, $month, $year);
$stats = array();
for($day=1; $day<=$numberOfDay; $day++) {
$dayOrdersQuery = self::create()
->filterByCreatedAt(sprintf("%s-%s-%s 00:00:00", $year, $month, $day), Criteria::GREATER_EQUAL)
->filterByCreatedAt(sprintf("%s-%s-%s 23:59:59", $year, $month, $day), Criteria::LESS_EQUAL);
if(null !== $status) {
$dayOrdersQuery->filterByStatusId($status, Criteria::IN);
}
$dayOrders = $dayOrdersQuery->count();
$stats[] = array($day-1, $dayOrders);
}
return $stats;
}
public static function getFirstOrdersStats($month, $year)
{
$numberOfDay = cal_days_in_month(CAL_GREGORIAN, $month, $year);
$stats = array();
for($day=1; $day<=$numberOfDay; $day++) {
$dayOrdersQuery = self::create('matching_order')
->filterByCreatedAt(sprintf("%s-%s-%s 00:00:00", $year, $month, $day), Criteria::GREATER_EQUAL)
->filterByCreatedAt(sprintf("%s-%s-%s 23:59:59", $year, $month, $day), Criteria::LESS_EQUAL);
$otherOrderJoin = new Join();
$otherOrderJoin->addExplicitCondition(OrderTableMap::TABLE_NAME, 'CUSTOMER_ID', 'matching_order', OrderTableMap::TABLE_NAME, 'CUSTOMER_ID', 'other_order');
$otherOrderJoin->setJoinType(Criteria::LEFT_JOIN);
$dayOrdersQuery->addJoinObject($otherOrderJoin, 'other_order_join')
->addJoinCondition('other_order_join', '`matching_order`.`ID` <> `other_order`.`ID`')
->addJoinCondition('other_order_join', '`matching_order`.`CREATED_AT` > `other_order`.`CREATED_AT`');
$dayOrdersQuery->where('ISNULL(`other_order`.`ID`)');
$dayOrders = $dayOrdersQuery->count();
$stats[] = array($day-1, $dayOrders);
}
return $stats;
}
} // OrderQuery

View File

@@ -12,10 +12,10 @@
<div class="title title-without-tabs clearfix">
{intl l='Dashboard'}
<div class="btn-group pull-right">
<button type="button" class="btn btn-default"><span class="glyphicon glyphicon-chevron-left"></span></button>
<button type="button" class="btn btn-default disabled"><span class="glyphicon glyphicon-calendar"></span></button>
<button type="button" class="btn btn-default"><span class="glyphicon glyphicon-chevron-right"></span></button>
<div class="btn-group pull-right">
<button type="button" class="btn btn-default js-stats-change-month" data-month-offset="-1"><span class="glyphicon glyphicon-chevron-left"></span></button>
<button type="button" class="btn btn-default" disabled><span class="glyphicon glyphicon-calendar"></span></button>
<button type="button" class="btn btn-default js-stats-change-month" data-month-offset="+1"><span class="glyphicon glyphicon-chevron-right"></span></button>
</div>
</div>
@@ -33,12 +33,6 @@
<div class="jqplot-content">
<div id="jqplot"></div>
<div id="sales" data-toggle="jqplot-serie" class="active"></div>
<div id="registration" data-toggle="jqplot-serie"></div>
<div id="orders" data-toggle="jqplot-serie"></div>
<div id="first-orders" data-toggle="jqplot-serie"></div>
<div id="aborted-orders" data-toggle="jqplot-serie"></div>
</div>
</div>
@@ -255,144 +249,155 @@
{javascripts file='assets/js/jqplot/jquery.jqplot.min.js'}
<script src="{$asset_url}"></script>
{javascripts file='assets/js/jqplot/plugins/jqplot.highlighter.min.js'}
<script type="text/javascript" src="{$asset_url}"></script>
{/javascripts}
{javascripts file='assets/js/jqplot/plugins/jqplot.barRenderer.min.js'}
<script type="text/javascript" src="{$asset_url}"></script>
{/javascripts}
{javascripts file='assets/js/jqplot/plugins/jqplot.pieRenderer.min.js'}
<script type="text/javascript" src="{$asset_url}"></script>
{/javascripts}
<script>
(function($, window, document){
$(function(){
var $elem = $('#jqplot');
var url = "{url file='/test_to_remove/admin-stats.json'}",
series = [],
seriesColors = [],
ticks = [],
days = 0,
jqplot;
var options = {
animate: true,
axesDefaults: {
tickOptions: { showMark: true, showGridline: true }
},
axes: {
xaxis: {
borderColor: '#ccc',
ticks : ticks,
tickOptions: { showGridline: false }
},
yaxis: {
tickOptions: { showGridline: true, showMark: false, showLabel: false, shadow: false }
}
},
seriesDefaults: {
lineWidth: 3,
shadow : false,
markerOptions: { shadow : false, style: 'filledCircle', size: 12 }
},
grid: {
background: '#FFF',
shadow : false,
borderColor : '#FFF'
},
highlighter: {
show: true,
sizeAdjust: 7,
tooltipLocation: 'n',
tooltipContentEditor: function(str, seriesIndex, pointIndex, plot){
// Return axis value : data value
return ticks[pointIndex][1] + ': ' + plot.data[seriesIndex][pointIndex][1];
}
}
};
// Get datas Json
$.getJSON(url)
.done(function(data) {
// Init series datas and colors
initJqplotDatas(series, seriesColors, options, data);
// Add days to xaxis
for(var i = 1; i < (days+1); i++){
ticks.push([i-1, i]);
}
// Start jqplot
var elementId = $elem.attr('id');
jqplot = $.jqplot(elementId, series, options);
$('[data-toggle="jqplot"]').each(function(){
$(this).click(function(){
if($('[data-toggle="jqplot-serie"].active').length > 1 || !$(this).hasClass('active')){
// Active button and jqplot-serie management
$(this).toggleClass('active');
var id = $(this).data('target');
$('[data-toggle="jqplot-serie"]#' + id).toggleClass('active');
// Reinit variables
series = [];
seriesColors = [];
// Init series datas and colors
initJqplotDatas(series, seriesColors, options, data);
// Restart jqplot
jqplot.destroy();
jqplot = $.jqplot(elementId, series, options);
}
});
});
$(window).bind('resize', function(event, ui) {
jqplot.replot( { resetAxes: true } );
});
})
.fail(function() {
$elem.append('<div class="alert alert-danger">An error occurred while reading from JSON file</div>');
});
function initJqplotDatas(series, seriesColors, options, json){
$('[data-toggle="jqplot-serie"].active').each(function(i){
var position = $(this).index() - 1;
series.push(json.series[position].datas);
seriesColors.push(json.series[position].color);
});
// Number of days to display ( = datas.length in one serie)
days = json.series[0].datas.length;
// Graph title
options.title = json.title;
// Graph series colors
options.seriesColors = seriesColors;
}
});
}(window.jQuery, window, document));
</script>
{/javascripts}
{javascripts file='assets/js/jqplot/plugins/jqplot.highlighter.min.js'}
<script type="text/javascript" src="{$asset_url}"></script>
{/javascripts}
{javascripts file='assets/js/jqplot/plugins/jqplot.barRenderer.min.js'}
<script type="text/javascript" src="{$asset_url}"></script>
{/javascripts}
{javascripts file='assets/js/jqplot/plugins/jqplot.pieRenderer.min.js'}
<script type="text/javascript" src="{$asset_url}"></script>
{/javascripts}
<script>
jQuery(function($){
var jQplotDate = new Date();
jQplotDate.setDate(1); // Set day to 1 so we can add month without 30/31 days of month troubles.
var url = "{url path='/admin/home/stats'}";
var jQplotData; // json data
var jQPlotInstance; // global instance
var jQPlotsOptions = {
animate: true,
axesDefaults: {
tickOptions: { showMark: true, showGridline: true }
},
axes: {
xaxis: {
borderColor: '#ccc',
ticks : [],
tickOptions: { showGridline: false }
},
yaxis: {
tickOptions: { showGridline: true, showMark: false, showLabel: false, shadow: false }
}
},
seriesDefaults: {
lineWidth: 3,
shadow : false,
markerOptions: { shadow : false, style: 'filledCircle', size: 12 }
},
grid: {
background: '#FFF',
shadow : false,
borderColor : '#FFF'
},
highlighter: {
show: true,
sizeAdjust: 7,
tooltipLocation: 'n',
tooltipContentEditor: function(str, seriesIndex, pointIndex, plot){
// Return axis value : data value
//return jQPlotsOptions.axes.xaxis.ticks[pointIndex][1] + ': ' + plot.data[seriesIndex][pointIndex][1];
return plot.data[seriesIndex][pointIndex][1];
}
}
};
{literal}
// Get initial data Json
retrieveJQPlotJson(jQplotDate.getMonth()+1, jQplotDate.getFullYear());
$('[data-toggle="jqplot"]').click(function(){
$(this).toggleClass('active');
jsonSuccessLoad();
});
$('.js-stats-change-month').click(function(e){
$('.js-stats-change-month').attr('disabled', true);
jQplotDate.setMonth(parseInt(jQplotDate.getMonth()) + parseInt($(this).data('month-offset')));
retrieveJQPlotJson(jQplotDate.getMonth()+1, jQplotDate.getFullYear(), function(){$('.js-stats-change-month').attr('disabled', false);});
});
function retrieveJQPlotJson(month, year, callback) {
console.log(month, year);
$.getJSON(url, {month: month, year: year})
.done(function(data) {
jQplotData = data;
jsonSuccessLoad();
if(callback) {
callback();
}
})
.fail(jsonFailLoad);
}
function initJqplotData(json) {
var series = [];
var seriesColors = [];
$('[data-toggle="jqplot"].active').each(function(i){
var position = $(this).index();
series.push(json.series[position].data);
seriesColors.push(json.series[position].color);
});
// Number of days to display ( = data.length in one serie)
var days = json.series[0].data.length;
// Add days to xaxis
var ticks = [];
for(var i = 1; i < (days+1); i++){
ticks.push([i-1, i]);
}
jQPlotsOptions.axes.xaxis.ticks = ticks;
// Graph title
jQPlotsOptions.title = json.title;
// Graph series colors
jQPlotsOptions.seriesColors = seriesColors;
return series;
}
function jsonFailLoad(data) {
$('#jqplot').html('<div class="alert alert-danger">An error occurred while reading from JSON file</div>');
}
function jsonSuccessLoad() {
// Init jQPlot
var series = initJqplotData(jQplotData);
console.log('END_INIT', series);
// Start jQPlot
if(jQPlotInstance) {
jQPlotInstance.destroy();
console.log('OLD_DELETED');
}
jQPlotInstance = $.jqplot("jqplot", series, jQPlotsOptions);
console.log('END_LAUNCH');
$(window).bind('resize', function(event, ui) {
jQPlotInstance.replot( { resetAxes: true } );
});
}
{/literal}
});
</script>
{/block}

View File

@@ -295,10 +295,6 @@
{block name="javascript-initialization"}
{javascripts file='assets/js/bootstrap-select/bootstrap-select.js'}
<script src='{$asset_url}'></script>
{/javascripts}
{javascripts file='assets/js/bootstrap-switch/bootstrap-switch.js'}
<script src="{$asset_url}"></script>
{/javascripts}
@@ -307,146 +303,4 @@
<script src='{$asset_url}'></script>
{/javascripts}
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
$(function() {
{if $taxUpdateError == true}
$('#tax_list_update_dialog').modal();
{/if}
$('.js-collapse').each(function(k, v) {
var h = $(v).data('collapse-height');
if( $(v).height() > h ) {
$(v).css('overflow', 'hidden').css('height', h + 'px');
} else {
$('[data-collapse-block=' + $(v).attr('id') + ']').hide();
}
});
$('.js-collapse-btn').click(function(e) {
e.preventDefault();
var block = $(this).data('collapseBlock');
$('#' + block).css('overflow', 'initial').css('height', 'initial');
$(this).unbind().remove();
});
$('.js-uncheck-all').click(function(e) {
e.preventDefault();
var selectId = $(this).data('uncheckSelect');
$('#' + selectId).selectpicker('deselectAll');
});
{literal}
$('#country-selector').change(function(e) {
$('#country-selector-form').submit();
});
// Cache jQuery Objects
var $group = $('#panel');
var $list = $('#panel-list');
// Build array of taxes rules
$('#apply-taxes-rules').click(function(){
var taxesRules = [],
index;
$('.drop-group', $group).each(function(i){
var $this = $(this);
index = i;
taxesRules[index] = [];
$('.drag', $this).each(function(j){
taxesRules[index][j] = [];
taxesRules[index][j] = $(this).data('id'); // retrieve with data
});
});
$('#tax_list').val(JSON.stringify(taxesRules));
});
// Default options for draggable
var dragOptions = {
cursor: 'move',
containment: "document",
opacity: 0.5,
revert: "invalid", // when not dropped, the item will revert back to its initial position
zIndex: 10
};
// Default options for sortabble
var sortOptions = {
cursor: 'move',
cancel: '.drop-message',
update: function( event, ui ){
// Check if we have an empty group
var $zone = $('.add-to-group', $group);
if($zone.size() > 1 && $(this).find('> div').size() == 0){ // Remove empty group only if we have more than 1 group
$(this).slideUp(function(){ $(this).remove(); });
}
}
};
// Default options for droppable
var dropOptions = {
accept: "#panel-list .draggable", // Controls which draggable elements are accepted
hoverClass: "over",
drop: function( event, ui ) {
var $drop = $(this);
if($(this).hasClass('create-group')){
// Check if we have already an empty group
var $empty_group = $group.find('.drop-group:not(:has(> div))');
if($empty_group.size() > 0){ // if yes (Use the first empty group)
$drop = $empty_group.filter(':first');
}else{ //if no (Create a new group)
$drop = $group.find('.drop-group:last-child').clone().appendTo($group.find('.panel-body'));
// Remove taxes
$drop.find('> div').remove();
// Make the new group droppable
$drop
.droppable(dropOptions)
.sortable(sortOptions);
}
}
$("<div></div>").addClass('drag').attr('data-id', ui.draggable.data('id')).text( ui.draggable.text()).appendTo( $drop );
ui.draggable.remove();
}
};
// Make the list of taxes draggable
$('.draggable', $list).draggable(dragOptions);
// let the drop-group be droppable & sortable, accepting the tax items
$('.droppable', $group)
.droppable(dropOptions)
.sortable(sortOptions);
$('.place .panel-body').sortable(sortOptions);
// let the gallery be droppable as well, accepting items from the trash
$('.remove-from-group', $list)
.droppable({
accept: "#panel .drag",
hoverClass: 'over',
drop: function( event, ui ) {
$("<div></div>").addClass('draggable').text( ui.draggable.text() ).attr('data-id', ui.draggable.data('id')).draggable(dragOptions).appendTo( $list.find('.panel-body') );
ui.draggable.remove();
}
});
{/literal}
});
</script>
{/block}

View File

@@ -1,6 +1,6 @@
{extends file="admin-layout.tpl"}
{block name="page-title"}{intl l='Taxes rules'}{/block}
{block name="page-title"}{intl l='Administration profiles'}{/block}
{block name="check-resource"}admin.configuration.profile{/block}
{block name="check-access"}view{/block}
@@ -27,7 +27,7 @@
<div class="table-responsive">
<table class="table table-striped table-condensed table-left-aligned">
<caption class="clearfix">
{intl l="Taxes"}
{intl l="Administration profiles"}
{loop type="auth" name="can_create" role="ADMIN" resource="admin.profile" access="CREATE"}
<a class="btn btn-default btn-primary pull-right" title="{intl l='Create a new profile'}" href="#profile_create_dialog" data-toggle="modal">
<span class="glyphicon glyphicon-plus"></span>