New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Currency improvements #1780

Merged
merged 15 commits into from Dec 7, 2015

global code update for the currency improvement

  • Loading branch information...
gillesbourgeat committed Nov 17, 2015
commit 414c187c2316e2a96a278986e276078d301f690d
@@ -104,6 +104,7 @@ public function setDefault(CurrencyUpdateEvent $event)
$currency
->setDispatcher($event->getDispatcher())
->setVisible($event->getVisible())
->setByDefault($event->getIsDefault())
->save()
;
@@ -119,6 +120,18 @@ public function setDefault(CurrencyUpdateEvent $event)
}
}
/**
* @param CurrencyUpdateEvent $event
*/
public function setVisible(CurrencyUpdateEvent $event)
{
if (null !== $currency = CurrencyQuery::create()->findPk($event->getCurrencyId())) {
if (!$currency->getByDefault()) {
$currency->setVisible($event->getVisible())->save();
}
}
}
/**
* Delete a currencyuration entry
*
@@ -191,6 +204,7 @@ public static function getSubscribedEvents()
TheliaEvents::CURRENCY_UPDATE => array("update", 128),
TheliaEvents::CURRENCY_DELETE => array("delete", 128),
TheliaEvents::CURRENCY_SET_DEFAULT => array("setDefault", 128),
TheliaEvents::CURRENCY_SET_VISIBLE => array("setVisible", 128),
TheliaEvents::CURRENCY_UPDATE_RATES => array("updateRates", 128),
TheliaEvents::CURRENCY_UPDATE_POSITION => array("updatePosition", 128)
);
@@ -164,7 +164,7 @@ public function getSummary()
*/
protected function generateInputs()
{
$currencies = CurrencyQuery::create()->find();
$currencies = CurrencyQuery::create()->filterByVisible(true)->find();
$cleanedCurrencies = [];
@@ -660,6 +660,10 @@
<default key="_controller">Thelia\Controller\Admin\CurrencyController::setDefaultAction</default>
</route>
<route id="admin.configuration.currencies.set-visible" path="/admin/configuration/currencies/set-visible">
<default key="_controller">Thelia\Controller\Admin\CurrencyController::setVisibleAction</default>
</route>
<route id="admin.configuration.currencies.update-position" path="/admin/configuration/currencies/update-position">
<default key="_controller">Thelia\Controller\Admin\CurrencyController::updatePositionAction</default>
</route>
@@ -215,10 +215,10 @@ public function setDefaultAction()
return $response;
}
$changeEvent = new CurrencyUpdateEvent($this->getRequest()->get('currency_id', 0));
$changeEvent = new CurrencyUpdateEvent((int) $this->getRequest()->get('currency_id', 0));
// Create and dispatch the change event
$changeEvent->setIsDefault(true);
$changeEvent->setIsDefault(true)->setVisible(1);
try {
$this->dispatch(TheliaEvents::CURRENCY_SET_DEFAULT, $changeEvent);
@@ -229,4 +229,29 @@ public function setDefaultAction()
return $this->redirectToListTemplate();
}
/**
* Sets if the currency is visible for Front
*/
public function setVisibleAction()
{
// Check current user authorization
if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE)) {
return $response;
}
$changeEvent = new CurrencyUpdateEvent((int) $this->getRequest()->get('currency_id', 0));
// Create and dispatch the change event
$changeEvent->setVisible((int) $this->getRequest()->get('visible', 0));
try {
$this->dispatch(TheliaEvents::CURRENCY_SET_VISIBLE, $changeEvent);
} catch (\Exception $ex) {
// Any error
return $this->errorPage($ex);
}
return $this->redirectToListTemplate();
}
}
@@ -17,6 +17,10 @@ class CurrencyUpdateEvent extends CurrencyCreateEvent
/** @var int */
protected $is_default;
/** @var int */
protected $visible;
/**
* @param int $currencyId
*/
@@ -43,4 +47,23 @@ public function setIsDefault($is_default)
return $this;
}
/**
* @return int
*/
public function getVisible()
{
return $this->visible;
}
/**
* @param $visible
* @return $this
*/
public function setVisible($visible)
{
$this->visible = $visible;
return $this;
}
}
@@ -605,6 +605,7 @@ public static function getLoopExtendsEvent($eventName, $loopName)
const CURRENCY_UPDATE = "action.updateCurrency";
const CURRENCY_DELETE = "action.deleteCurrency";
const CURRENCY_SET_DEFAULT = "action.setDefaultCurrency";
const CURRENCY_SET_VISIBLE = "action.setVisibleCurrency";
const CURRENCY_UPDATE_RATES = "action.updateCurrencyRates";
const CURRENCY_UPDATE_POSITION = "action.updateCurrencyPosition";
@@ -37,6 +37,7 @@
* @method int[] getId()
* @method int[] getExclude()
* @method bool getDefaultOnly()
* @method bool|string getVisible()
* @method string[] getOrder()
*/
class Currency extends BaseI18nLoop implements PropelSearchLoopInterface
@@ -52,6 +53,7 @@ protected function getArgDefinitions()
Argument::createIntListTypeArgument('id'),
Argument::createIntListTypeArgument('exclude'),
Argument::createBooleanTypeArgument('default_only', false),
Argument::createBooleanOrBothTypeArgument('visible', true),
new Argument(
'order',
new TypeCollection(
@@ -62,6 +64,7 @@ protected function getArgDefinitions()
'code', 'code_reverse',
'symbol', 'symbol_reverse',
'rate', 'rate_reverse',
'visible', 'visible_reverse',
'is_default', 'is_default_reverse',
'manual', 'manual_reverse')
)
@@ -78,24 +81,22 @@ public function buildModelCriteria()
/* manage translations */
$this->configureI18nProcessing($search, array('NAME'));
$id = $this->getId();
if (null !== $id) {
if (null !== $id = $this->getId()) {
$search->filterById($id, Criteria::IN);
}
$exclude = $this->getExclude();
if (!is_null($exclude)) {
if (null !== $exclude = $this->getExclude()) {
$search->filterById($exclude, Criteria::NOT_IN);
}
$defaultOnly = $this->getDefaultOnly();
if ($defaultOnly === true) {
if ($this->getDefaultOnly() === true) {
$search->filterByByDefault(true);
}
if ('*' !== $visible = $this->getVisible()) {
$search->filterByVisible($visible);
}
$orders = $this->getOrder();
foreach ($orders as $order) {
@@ -135,6 +136,13 @@ public function buildModelCriteria()
$search->orderByRate(Criteria::DESC);
break;
case 'visible':
$search->orderByVisible(Criteria::ASC);
break;
case 'visible_reverse':
$search->orderByVisible(Criteria::DESC);
break;
case 'is_default':
$search->orderByByDefault(Criteria::ASC);
break;
@@ -168,6 +176,7 @@ public function parseResults(LoopResult $loopResult)
->set("SYMBOL", $currency->getSymbol())
->set("FORMAT", $currency->getFormat())
->set("RATE", $currency->getRate())
->set("VISIBLE", $currency->getVisible())
->set("POSITION", $currency->getPosition())
->set("IS_DEFAULT", $currency->getByDefault())
;
@@ -106,6 +106,16 @@
}
</th>
<th class="text-center">
{admin_sortable_header
current_order=$order
order='visible'
reverse_order='visible_reverse'
path='/admin/configuration/currencies'
label="{intl l="Visible"}"
}
</th>
<th class="text-center">
{admin_sortable_header
current_order=$order
@@ -133,7 +143,7 @@
</thead>
<tbody>
{loop name="currencies" type="currency" backend_context="1" lang=$lang_id order=$order}
{loop name="currencies" type="currency" backend_context="1" visible="*" lang=$lang_id order=$order}
<tr>
<td>{$ID}</td>
@@ -152,6 +162,12 @@
<td class="text-center">{format_number number="$RATE" decimals="4"}</td>
<td class="text-center">
<div class="make-switch switch-small change-visible" data-on="success" data-off="danger" data-on-label="<i class='glyphicon glyphicon-ok'></i>" data-off-label="<i class='glyphicon glyphicon-remove'></i>">
<input type="checkbox" name="visible" value="{$ID}" {if $VISIBLE}checked="checked"{/if}/>
</div>
</td>
<td class="text-center">
{admin_position_block
resource="admin.configuration.currency"
@@ -195,7 +211,7 @@
{/loop}
{elseloop rel="currencies"}
<tr>
<td colspan="8">
<td colspan="9">
<div class="alert alert-info">
{intl l="No currency has been created yet. Click the + button to create one."}
</div>
@@ -367,10 +383,7 @@
{* Change default status *}
$('.change-default').on("switch-change", function(event, data) {
var $loader = $('<div class="loader"></div>');
$('body').append($loader);
$loader.show();
var url = "{url path='/admin/configuration/currencies/set-default' currency_id='__ID__'}";
var url = "{url noamp='1' path='/admin/configuration/currencies/set-default' currency_id='__ID__'}";
// Perform ID subtitutions
url = url.replace('__ID__', $("input", this).val());
@@ -379,6 +392,17 @@
location.href = url;
});
$('.change-visible').on("switch-change", function(event, data) {
var url = "{url noamp='1' path='/admin/configuration/currencies/set-visible' currency_id='__ID__' visible='__VISIBLE__'}";
url = url.replace('__ID__', $("input", this).val());
url = url.replace('__VISIBLE__', $("input", this).is(':checked') ? 1 : 0);
// Reload the page
location.href = url;
});
});
</script>
{/block}
@@ -14,7 +14,7 @@
<div id="wrapper" class="container">
{loop name="currency_edit" type="currency" id="$currency_id" backend_context="1" lang="$edit_language_id"}
{loop name="currency_edit" type="currency" id="$currency_id" backend_context="1" visible="*" lang="$edit_language_id"}
<ul class="breadcrumb">
<li><a href="{url path='/admin/home'}">{intl l="Home"}</a></li>
ProTip! Use n and p to navigate between commits in a pull request.