This commit is contained in:
mespeche
2013-09-18 15:39:03 +02:00
13 changed files with 392 additions and 89 deletions

View File

@@ -0,0 +1,60 @@
<?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\Core\Event;
/**
* Class GenerateRewrittenUrlEvent
* @package Thelia\Core\Event
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class GenerateRewrittenUrlEvent extends ActionEvent {
protected $object;
protected $locale;
protected $url;
public function __construct($object, $locale)
{
$this->object;
$this->locale;
}
public function setUrl($url)
{
$this->url = $url;
}
public function isRewritten()
{
return null !== $this->url;
}
public function getUrl()
{
return $this->url;
}
}

View File

@@ -441,4 +441,9 @@ final class TheliaEvents
*/ */
const MAILTRANSPORTER_CONFIG = 'action.mailertransporter.config'; const MAILTRANSPORTER_CONFIG = 'action.mailertransporter.config';
/**
* sent when Thelia try to generate a rewriten url
*/
const GENERATE_REWRITTENURL = 'action.generate_rewritenurl';
} }

View File

@@ -27,6 +27,7 @@ use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
use Thelia\Core\Template\Smarty\AbstractSmartyPlugin; use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
use Thelia\Tools\URL; use Thelia\Tools\URL;
use Thelia\Core\HttpFoundation\Request; use Thelia\Core\HttpFoundation\Request;
use Thelia\Core\Translation\Translator;
class UrlGenerator extends AbstractSmartyPlugin class UrlGenerator extends AbstractSmartyPlugin
{ {
@@ -47,11 +48,27 @@ class UrlGenerator extends AbstractSmartyPlugin
public function generateUrlFunction($params, &$smarty) public function generateUrlFunction($params, &$smarty)
{ {
// the path to process // the path to process
$path = $this->getParam($params, 'path'); $path = $this->getParam($params, 'path', null);
$file = $this->getParam($params, 'file', null);
if ($file !== null) {
$path = $file;
$mode = URL::PATH_TO_FILE;
}
else if ($path !== null) {
$mode = URL::WITH_INDEX_PAGE;
}
else {
throw \InvalidArgumentException(Translator::getInstance()->trans("Please specify either 'path' or 'file' parameter in {url} function."));
}
$target = $this->getParam($params, 'target', null); $target = $this->getParam($params, 'target', null);
$url = URL::getInstance()->absoluteUrl($path, $this->getArgsFromParam($params, array('path', 'target'))); $url = URL::getInstance()->absoluteUrl(
$path,
$this->getArgsFromParam($params, array('path', 'file', 'target')),
$mode
);
if ($target != null) $url .= '#'.$target; if ($target != null) $url .= '#'.$target;

View File

@@ -56,9 +56,15 @@ class ConfigQuery extends BaseConfigQuery {
public static function getPageNotFoundView() public static function getPageNotFoundView()
{ {
return self::read("page_not_found_view", '404.html'); return self::read("page_not_found_view", '404');
} }
public static function getPassedUrlView()
{
return self::read('passed_url_view', 'passed-url');
}
public static function getActiveTemplate() public static function getActiveTemplate()
{ {
return self::read('active-template', 'default'); return self::read('active-template', 'default');

View File

@@ -200,6 +200,12 @@ class Product extends BaseProduct
*/ */
public function postDelete(ConnectionInterface $con = null) public function postDelete(ConnectionInterface $con = null)
{ {
RewritingUrlQuery::create()
->filterByView($this->getRewrittenUrlViewName())
->filterByViewId($this->getId())
->update(array(
"View" => ConfigQuery::getPassedUrlView()
));
$this->dispatchEvent(TheliaEvents::AFTER_DELETEPRODUCT, new ProductEvent($this)); $this->dispatchEvent(TheliaEvents::AFTER_DELETEPRODUCT, new ProductEvent($this));
} }
} }

View File

@@ -23,6 +23,8 @@
namespace Thelia\Model\Tools; namespace Thelia\Model\Tools;
use Thelia\Core\Event\GenerateRewrittenUrlEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Exception\UrlRewritingException; use Thelia\Exception\UrlRewritingException;
use Thelia\Model\RewritingUrlQuery; use Thelia\Model\RewritingUrlQuery;
use Thelia\Model\RewritingUrl; use Thelia\Model\RewritingUrl;
@@ -61,7 +63,21 @@ trait UrlRewritingTrait {
$this->setLocale($locale); $this->setLocale($locale);
$title = $this->getTitle() ?: $this->getRef(); $generateEvent = new GenerateRewrittenUrlEvent($this, $locale);
$this->dispatchEvent(TheliaEvents::GENERATE_REWRITTENURL, $generateEvent);
if($generateEvent->isRewritten())
{
return $generateEvent->getUrl();
}
$title = $this->getTitle();
if(null == $title) {
throw new \RuntimeException('Impossible to create an url if title is null');
}
// Replace all weird characters with dashes // Replace all weird characters with dashes
$string = preg_replace('/[^\w\-~_\.]+/u', '-', $title); $string = preg_replace('/[^\w\-~_\.]+/u', '-', $title);
@@ -104,7 +120,7 @@ trait UrlRewritingTrait {
->filterByViewLocale($locale) ->filterByViewLocale($locale)
->filterByView($this->getRewrittenUrlViewName()) ->filterByView($this->getRewrittenUrlViewName())
->filterByViewId($this->getId()) ->filterByViewId($this->getId())
->filterByRedirected(0) ->filterByRedirected(null)
->findOne() ->findOne()
; ;

View File

@@ -0,0 +1,108 @@
<?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\Tests\Rewriting;
/**
* Class BaseRewritingObject
* @package Thelia\Tests\Rewriting
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
abstract class BaseRewritingObject extends \PHPUnit_Framework_TestCase
{
/**
* @return mixed an instance of Product, Folder, Content or Category Model
*/
abstract function getObject();
/**
* @covers Thelia\Model\Tools\UrlRewritingTrait::generateRewrittenUrl
*/
public function testSimpleFrenchRewrittenUrl()
{
$object = $this->getObject();
$object->setVisible(1)
->setPosition(1)
->setLocale('fr_FR')
->setTitle('Mon super titre en français')
->save();
$this->assertRegExp('/^mon-super-titre-en-français(-[0-9]+)?\.html$/', $object->getRewrittenUrl('fr_FR'));
$rewrittenUrl = $object->generateRewrittenUrl('fr_FR');
$this->assertNotNull($rewrittenUrl, "rewritten url can not be null");
$this->assertRegExp('/^mon-super-titre-en-français(-[0-9]+)?\.html$/', $rewrittenUrl);
//mon-super-titre-en-français-2.html
$object->delete();
}
/**
* @covers Thelia\Model\Tools\UrlRewritingTrait::generateRewrittenUrl
*/
public function testSimpleEnglishRewrittenUrl()
{
$object = $this->getObject();
$object->setVisible(1)
->setPosition(1)
->setLocale('en_US')
->setTitle('My english super Title')
->save();
$this->assertRegExp('/^my-english-super-title(-[0-9]+)?\.html$/', $object->getRewrittenUrl('en_US'));
$rewrittenUrl = $object->generateRewrittenUrl('en_US');
$this->assertNotNull($rewrittenUrl, "rewritten url can not be null");
$this->assertRegExp('/^my-english-super-title(-[0-9]+)?\.html$/', $rewrittenUrl);
$object->delete();
}
/**
* @covers Thelia\Model\Tools\UrlRewritingTrait::generateRewrittenUrl
* @expectedException \RuntimeException
* @expectedExceptionMessage Impossible to create an url if title is null
*/
public function testRewrittenWithoutTitle()
{
$object = $this->getObject();
$object->setVisible(1)
->setPosition(1)
->setLocale('en_US')
->setDescription('My english super Description')
->save();
}
/**
* @covers Thelia\Model\Tools\UrlRewritingTrait::generateRewrittenUrl
* @expectedException \RuntimeException
*/
public function testOnNotSavedObject()
{
$object = $this->getObject();
$object->generateRewrittenUrl('fr_FR');
}
}

View File

@@ -0,0 +1,43 @@
<?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\Tests\Rewriting;
use Thelia\Model\Category;
/**
* Class CategoryRewritingTest
* @package Thelia\Tests\Rewriting
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class CategoryRewritingTest extends BaseRewritingObject
{
/**
* @return \Thelia\Model\Category
*/
function getObject()
{
return new Category();
}
}

View File

@@ -0,0 +1,43 @@
<?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\Tests\Rewriting;
use Thelia\Model\Content;
/**
* Class ContentRewritingTest
* @package Thelia\Tests\Rewriting
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class ContentRewritingTest extends BaseRewritingObject
{
/**
* @return \Thelia\Model\Content
*/
function getObject()
{
return new Content();
}
}

View File

@@ -0,0 +1,43 @@
<?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\Tests\Rewriting;
use Thelia\Model\Folder;
/**
* Class FolderRewritingTest
* @package Thelia\Tests\Rewriting
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class FolderRewritingTest extends BaseRewritingObject
{
/**
* @return mixed an instance of Product, Folder, Content or Category Model
*/
function getObject()
{
return new Folder();
}
}

View File

@@ -31,59 +31,14 @@ use Thelia\Model\ProductQuery;
* @package Thelia\Tests\Rewriting * @package Thelia\Tests\Rewriting
* @author Manuel Raynaud <mraynaud@openstudio.fr> * @author Manuel Raynaud <mraynaud@openstudio.fr>
*/ */
class ProductRewriteTest extends \PHPUnit_Framework_TestCase class ProductRewriteTest extends BaseRewritingObject
{ {
protected static $productId;
public static function setUpBeforeClass()
{
$product = new Product();
$product->setRef(sprintf("TestRewrittenProduct%s",uniqid()))
->setPosition(1)
->setVisible(1)
->setLocale('en_US')
->setTitle('My english super Title')
->setLocale('fr_FR')
->setTitle('Mon super titre en français')
->save();
self::$productId = $product->getId();
}
/** /**
* @covers Thelia\Model\Tools\UrlRewritingTrait::generateRewrittenUrl * @return mixed an instance of Product, Folder, Content or Category Model
*/ */
public function testFrenchRewrittenUrl() function getObject()
{ {
$product = ProductQuery::create()->findPk(self::$productId); return new Product();
$rewrittenUrl = $product->generateRewrittenUrl('fr_FR');
$this->assertNotNull($rewrittenUrl, "rewritten url can not be null");
$this->assertRegExp('/^mon-super-titre-en-français(-[0-9]+)?\.html$/', $rewrittenUrl);
//mon-super-titre-en-français-2.html
}
/**
* @covers Thelia\Model\Tools\UrlRewritingTrait::generateRewrittenUrl
*/
public function testEnglishRewrittenUrl()
{
$product = ProductQuery::create()->findPk(self::$productId);
$rewrittenUrl = $product->generateRewrittenUrl('en_US');
$this->assertNotNull($rewrittenUrl, "rewritten url can not be null");
$this->assertRegExp('/^my-english-super-title(-[0-9]+)?\.html$/', $rewrittenUrl);
}
/**
* @covers Thelia\Model\Tools\UrlRewritingTrait::generateRewrittenUrl
* @expectedException \RuntimeException
* @expectedExceptionMessage Object product must be saved before generating url
*/
public function testOnNotSavedProduct()
{
$product = new Product();
$product->generateRewrittenUrl('fr_FR');
} }
} }

View File

@@ -19,7 +19,8 @@ INSERT INTO `config` (`name`, `value`, `secured`, `hidden`, `created_at`, `updat
('image_cache_dir_from_web_root', 'cache/images', 0, 0, NOW(), NOW()), ('image_cache_dir_from_web_root', 'cache/images', 0, 0, NOW(), NOW()),
('document_cache_dir_from_web_root', 'cache/documents', 0, 0, NOW(), NOW()), ('document_cache_dir_from_web_root', 'cache/documents', 0, 0, NOW(), NOW()),
('currency_rate_update_url', 'http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml', 0, 0, NOW(), NOW()), ('currency_rate_update_url', 'http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml', 0, 0, NOW(), NOW()),
('page_not_found_view', '404.html', 0, 0, NOW(), NOW()), ('page_not_found_view', '404', 0, 0, NOW(), NOW()),
('passed_url_view', 'passed-url', 0, 0, NOW(), NOW()),
('use_tax_free_amounts', 0, 0, 0, NOW(), NOW()), ('use_tax_free_amounts', 0, 0, 0, NOW(), NOW()),
('process_assets', '1', 0, 0, NOW(), NOW()), ('process_assets', '1', 0, 0, NOW(), NOW()),
('thelia_admin_remember_me_cookie_name', 'tarmcn', 0, 0, NOW(), NOW()), ('thelia_admin_remember_me_cookie_name', 'tarmcn', 0, 0, NOW(), NOW()),

View File

@@ -7,7 +7,7 @@
<div id="wrapper" class="container"> <div id="wrapper" class="container">
{module_include location='home_top'} {module_include location='home_top'}
<div class="col-md-12 general-block-decorator dashboard"> <div class="col-md-12 general-block-decorator dashboard">
<div class="title title-without-tabs clearfix"> <div class="title title-without-tabs clearfix">
@@ -17,8 +17,8 @@
<button type="button" class="btn btn-default disabled"><span class="glyphicon glyphicon-calendar"></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> <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-chevron-right"></span></button>
</div> </div>
</div> </div>
<div class="text-center clearfix"> <div class="text-center clearfix">
<div class="btn-group"> <div class="btn-group">
<button type="button" class="btn btn-default active" data-toggle="jqplot" data-target="turnover"><span class="glyphicon glyphicon-euro"></span> {intl l="Turnover"}</button> <button type="button" class="btn btn-default active" data-toggle="jqplot" data-target="turnover"><span class="glyphicon glyphicon-euro"></span> {intl l="Turnover"}</button>
@@ -26,11 +26,11 @@
<button type="button" class="btn btn-success" data-toggle="jqplot" data-target="orders"><span class="glyphicon glyphicon-shopping-cart"></span> {intl l="Orders"}</button> <button type="button" class="btn btn-success" data-toggle="jqplot" data-target="orders"><span class="glyphicon glyphicon-shopping-cart"></span> {intl l="Orders"}</button>
<button type="button" class="btn btn-info" data-toggle="jqplot" data-target="first-orders"><span class="glyphicon glyphicon-thumbs-up"></span> {intl l="First orders"}</button> <button type="button" class="btn btn-info" data-toggle="jqplot" data-target="first-orders"><span class="glyphicon glyphicon-thumbs-up"></span> {intl l="First orders"}</button>
<button type="button" class="btn btn-danger" data-toggle="jqplot" data-target="aborted-orders"><span class="glyphicon glyphicon-thumbs-down"></span> {intl l="Aborted orders"}</button> <button type="button" class="btn btn-danger" data-toggle="jqplot" data-target="aborted-orders"><span class="glyphicon glyphicon-thumbs-down"></span> {intl l="Aborted orders"}</button>
</div> </div>
</div> </div>
<hr/> <hr/>
<div class="jqplot-content"> <div class="jqplot-content">
<div id="jqplot"></div> <div id="jqplot"></div>
@@ -42,7 +42,7 @@
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-md-4"> <div class="col-md-4">
@@ -91,10 +91,10 @@
<td>0</td> <td>0</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</div> </div>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<div class="general-block-decorator"> <div class="general-block-decorator">
<div class="title title-without-tabs">{intl l="Sales statistics"}</div> <div class="title title-without-tabs">{intl l="Sales statistics"}</div>
@@ -138,7 +138,7 @@
<td>25.00 €</td> <td>25.00 €</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</div> </div>
<div class="tab-pane fade" id="statmois"> <div class="tab-pane fade" id="statmois">
<table class="table table-striped"> <table class="table table-striped">
@@ -206,7 +206,7 @@
<td>25.00 €</td> <td>25.00 €</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</div> </div>
</div> </div>
</div> </div>
@@ -230,7 +230,7 @@
<td><a href="" target="_blank">{intl l="Click here"}</a></td> <td><a href="" target="_blank">{intl l="Click here"}</a></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</div> </div>
</div> </div>
@@ -245,7 +245,7 @@
{javascripts file='assets/js/jqplot/jquery.jqplot.min.js'} {javascripts file='assets/js/jqplot/jquery.jqplot.min.js'}
<script src="{$asset_url}"></script> <script src="{$asset_url}"></script>
{javascripts file='assets/js/jqplot/plugins/jqplot.highlighter.min.js'} {javascripts file='assets/js/jqplot/plugins/jqplot.highlighter.min.js'}
<script type="text/javascript" src="{$asset_url}"></script> <script type="text/javascript" src="{$asset_url}"></script>
{/javascripts} {/javascripts}
@@ -259,19 +259,19 @@
<script> <script>
(function($, window, document){ (function($, window, document){
$(function(){ $(function(){
var $elem = $('#jqplot'); var $elem = $('#jqplot');
var url = '/web/test_to_remove/admin-stats.json', var url = "{url file='/test_to_remove/admin-stats.json'}",
series = [], series = [],
seriesColors = [], seriesColors = [],
ticks = [], ticks = [],
days = 0, days = 0,
jqplot; jqplot;
var options = { var options = {
animate: true, animate: true,
axesDefaults: { axesDefaults: {
tickOptions: { showMark: true, showGridline: true } tickOptions: { showMark: true, showGridline: true }
@@ -288,13 +288,13 @@
}, },
seriesDefaults: { seriesDefaults: {
lineWidth: 3, lineWidth: 3,
shadow : false, shadow : false,
markerOptions: { shadow : false, style: 'filledCircle', size: 12 } markerOptions: { shadow : false, style: 'filledCircle', size: 12 }
}, },
grid: { grid: {
background: '#FFF', background: '#FFF',
shadow : false, shadow : false,
borderColor : '#FFF' borderColor : '#FFF'
}, },
highlighter: { highlighter: {
show: true, show: true,
@@ -302,7 +302,7 @@
tooltipLocation: 'n', tooltipLocation: 'n',
tooltipContentEditor: function(str, seriesIndex, pointIndex, plot){ tooltipContentEditor: function(str, seriesIndex, pointIndex, plot){
// Return axis value : data value // Return axis value : data value
return ticks[pointIndex][1] + ': ' + plot.data[seriesIndex][pointIndex][1]; return ticks[pointIndex][1] + ': ' + plot.data[seriesIndex][pointIndex][1];
} }
} }
@@ -310,26 +310,26 @@
// Get datas Json // Get datas Json
$.getJSON(url) $.getJSON(url)
.done(function(data) { .done(function(data) {
// Init series datas and colors // Init series datas and colors
initJqplotDatas(series, seriesColors, options, data); initJqplotDatas(series, seriesColors, options, data);
// Add days to xaxis // Add days to xaxis
for(var i = 1; i < (days+1); i++){ for(var i = 1; i < (days+1); i++){
ticks.push([i-1, i]); ticks.push([i-1, i]);
} }
// Start jqplot // Start jqplot
var elementId = $elem.attr('id'); var elementId = $elem.attr('id');
jqplot = $.jqplot(elementId, series, options); jqplot = $.jqplot(elementId, series, options);
$('[data-toggle="jqplot"]').each(function(){ $('[data-toggle="jqplot"]').each(function(){
$(this).click(function(){ $(this).click(function(){
if($('[data-toggle="jqplot-serie"].active').length > 1 || !$(this).hasClass('active')){ if($('[data-toggle="jqplot-serie"].active').length > 1 || !$(this).hasClass('active')){
// Active button and jqplot-serie management // Active button and jqplot-serie management
$(this).toggleClass('active'); $(this).toggleClass('active');
@@ -341,16 +341,16 @@
seriesColors = []; seriesColors = [];
// Init series datas and colors // Init series datas and colors
initJqplotDatas(series, seriesColors, options, data); initJqplotDatas(series, seriesColors, options, data);
// Restart jqplot // Restart jqplot
jqplot.destroy(); jqplot.destroy();
jqplot = $.jqplot(elementId, series, options); jqplot = $.jqplot(elementId, series, options);
} }
}); });
}); });
$(window).bind('resize', function(event, ui) { $(window).bind('resize', function(event, ui) {
jqplot.replot( { resetAxes: true } ); jqplot.replot( { resetAxes: true } );
@@ -359,15 +359,15 @@
}) })
.fail(function() { .fail(function() {
$elem.append('<div class="alert alert-danger">An error occurred while reading from JSON file</div>'); $elem.append('<div class="alert alert-danger">An error occurred while reading from JSON file</div>');
}); });
function initJqplotDatas(series, seriesColors, options, json){ function initJqplotDatas(series, seriesColors, options, json){
$('[data-toggle="jqplot-serie"].active').each(function(i){ $('[data-toggle="jqplot-serie"].active').each(function(i){
var position = $(this).index() - 1; var position = $(this).index() - 1;
series.push(json.series[position].datas); series.push(json.series[position].datas);
seriesColors.push(json.series[position].color); seriesColors.push(json.series[position].color);
}); });
// Number of days to display ( = datas.length in one serie) // Number of days to display ( = datas.length in one serie)
days = json.series[0].datas.length; days = json.series[0].datas.length;
@@ -380,7 +380,7 @@
} }
}); });
}(window.jQuery, window, document)); }(window.jQuery, window, document));
</script> </script>