Skip to content
Extraits de code Groupes Projets
Valider 0ec34a44 rédigé par diosmosis's avatar diosmosis
Parcourir les fichiers

Fix bug in UIControl where override template vars are not passed to inner view and have no effect.

parent 6435f2f0
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -27,22 +27,6 @@ class UIControl extends \Piwik\View
*/
const TEMPLATE = '';
/**
* Holds the array of values that are passed to the UIControl JavaScript class.
*
* @var array
*/
public $clientSideProperties = array();
/**
* Holds an array of values that are passed to the UIControl JavaScript class. These values
* differ from those in {@link $clientSideProperties} in that they are meant to passed as
* request parameters when the JavaScript code makes an AJAX request.
*
* @var array
*/
public $clientSideParameters = array();
/**
* The CSS class that is used to map the root element of this control with the JavaScript class.
*
......@@ -86,9 +70,6 @@ class UIControl extends \Piwik\View
$this->innerView = new View(static::TEMPLATE);
parent::__construct("@CoreHome\_uiControl");
$this->clientSideProperties = array();
$this->clientSideParameters = array();
}
/**
......@@ -133,12 +114,54 @@ class UIControl extends \Piwik\View
public function getTemplateVars($override = array())
{
$this->templateVars['implView'] = $this->innerView;
$this->templateVars['clientSideProperties'] = $this->clientSideProperties;
$this->templateVars['clientSideParameters'] = $this->clientSideParameters;
$this->templateVars['cssIdentifier'] = $this->cssIdentifier;
$this->templateVars['cssClass'] = $this->cssClass;
$this->templateVars['jsClass'] = $this->jsClass;
$this->templateVars['implOverride'] = $override;
$innerTemplateVars = $this->innerView->getTemplateVars($override);
$this->templateVars['clientSideProperties'] = array();
foreach ($this->getClientSideProperties() as $name) {
$this->templateVars['clientSideProperties'][$name] = $innerTemplateVars[$name];
}
$this->templateVars['clientSideParameters'] = array();
$clientSideParameters = $this->getClientSideParameters();
foreach ($this->getClientSideParameters() as $name) {
$this->templateVars['clientSideParameters'][$name] = $innerTemplateVars[$name];
}
if ($this instanceof \Piwik\Plugins\SegmentEditor\SegmentSelectorControl) {
\Piwik\Log::warning(print_r($override, true));
}
return parent::getTemplateVars($override);
}
/**
* Returns the array of property names whose values are passed to the UIControl JavaScript class.
*
* Should be overriden by descendants.
*
* @return array
*/
public function getClientSideProperties()
{
return array();
}
/**
* Returns an array of property names whose values are passed to the UIControl JavaScript class.
* These values differ from those in {@link $clientSideProperties} in that they are meant to passed as
* request parameters when the JavaScript code makes an AJAX request.
*
* Should be overriden by descendants.
*
* @return array
*/
public function getClientSideParameters()
{
return array();
}
}
\ No newline at end of file
<div class="{{ cssIdentifier }} {{ cssClass }}"
data-props="{{ clientSideProperties|json_encode }}"
data-params="{{ clientSideParameters|json_encode }}">
{% render implView %}
{% render implView with implOverride %}
</div>
<script>$(document).ready(function () { require('piwik/UI').{{ jsClass }}.initElements(); });</script>
\ No newline at end of file
......@@ -53,23 +53,29 @@ class SegmentSelectorControl extends UIControl
$this->segmentsByCategory = $segmentsByCategory;
$this->nameOfCurrentSegment = '';
$this->clientSideProperties['isSegmentNotAppliedBecauseBrowserArchivingIsDisabled'] = 0;
$this->isSegmentNotAppliedBecauseBrowserArchivingIsDisabled = 0;
$savedSegments = API::getInstance()->getAll($this->idSite);
foreach ($savedSegments as &$savedSegment) {
$this->availableSegments = API::getInstance()->getAll($this->idSite);
foreach ($this->availableSegments as &$savedSegment) {
$savedSegment['name'] = Common::sanitizeInputValue($savedSegment['name']);
if (!empty($this->selectedSegment) && $this->selectedSegment == $savedSegment['definition']) {
$this->nameOfCurrentSegment = $savedSegment['name'];
$this->clientSideProperties['isSegmentNotAppliedBecauseBrowserArchivingIsDisabled']
= $this->wouldApplySegment($savedSegment) ? 0 : 1;
$this->isSegmentNotAppliedBecauseBrowserArchivingIsDisabled =
$this->wouldApplySegment($savedSegment) ? 0 : 1;
}
}
$this->clientSideProperties['availableSegments'] = $savedSegments;
$this->clientSideProperties['segmentTranslations'] = $this->getTranslations();
$this->authorizedToCreateSegments = !Piwik::isUserIsAnonymous();
$this->segmentTranslations = $this->getTranslations();
}
public function getClientSideProperties()
{
return array('availableSegments',
'segmentTranslations',
'isSegmentNotAppliedBecauseBrowserArchivingIsDisabled',
'selectedSegment');
}
private function wouldApplySegment($savedSegment)
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter