Skip to content
This repository has been archived by the owner on May 30, 2019. It is now read-only.

Commit

Permalink
Language management fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
rogergros authored and tonipinel committed May 26, 2015
1 parent 39ea1f0 commit 1aab1d6
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,22 @@ protected function enableAction(
/**
* @var EnabledInterface $entity
*/
$entity->setEnabled(true);
$entityManager = $this->getManagerForClass($entity);
$entityManager->flush($entity);
$$this->enableEntity($entity);
});
}

/**
* Enables the given entity
*
* @param EnabledInterface $entity The entity to disable
*/
protected function enableEntity(EnabledInterface $entity)
{
$entity->setEnabled(true);
$entityManager = $this->getManagerForClass($entity);
$entityManager->flush($entity);
}

/**
* Disable entity
*
Expand All @@ -69,15 +79,22 @@ protected function disableAction(
) {
return $this->getResponse($request, function () use ($entity) {

/**
* @var EnabledInterface $entity
*/
$entity->setEnabled(false);
$entityManager = $this->getManagerForClass($entity);
$entityManager->flush($entity);
$this->disableEntity($entity);
});
}

/**
* Disables the given entity
*
* @param EnabledInterface $entity The entity to disable
*/
protected function disableEntity(EnabledInterface $entity)
{
$entity->setEnabled(false);
$entityManager = $this->getManagerForClass($entity);
$entityManager->flush($entity);
}

/**
* Updated edited element action
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,26 @@ FrontendCore.define('on-off-table', ['devicePackage' ], function () {
return {
onStart: function () {

setTimeout( function() {
FrontendCore.requireAndStart('notification');

$('.switch input').change( function() {
$('.switch input').each( function(){

var oTarget = this;

$(oTarget).change( function() {

var sUrl = this.checked === true ? document.getElementById('enable-' + this.id).value : document.getElementById('disable-' + this.id).value ;

$.ajax({
url: sUrl,
type: 'post'
}).done( function( response ) {
FrontendCore.requireAndStart('notification');

setTimeout( function(){
FrontendMediator.publish( 'notification', { type : 'ok', message: response.message } );
}, 500);
}).fail( function( response ) {
FrontendCore.requireAndStart('notification');

setTimeout( function(){
FrontendMediator.publish( 'notification', { type : 'ko', message: response.message } );
}, 500);
var sMessage = response.responseJSON.message != undefined ? response.responseJSON.message : 'Sorry, something was wrong.';
FrontendMediator.publish( 'notification', { type : 'ko', message: sMessage } );
$(oTarget).click();
});
});

} , 1500);
});

}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,13 @@ admin:
iso: ISO
master: Idioma principal
status: Actiu
saved:
enabled: "S'ha habilitat l'idioma"
disabled: "S'ha deshabilitat l'idioma"
master: "S'ha guardat l'idioma principal"
error:
setting_disabled_master_language: No es pot guardar un idioma desactivat
disable_master_language: "No pots desactivar l'idioma principal"

media:
single: Imatge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,13 @@ admin:
iso: ISO
master: Master language
status: Enabled
saved:
enabled: This language has been enabled
disabled: This language has been disabled
master: Main language saved
error:
setting_disabled_master_language: "You can't set a disabled language as master"
disable_master_language: You cannot disable your master language

media:
single: Media
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,13 @@ admin:
iso: ISO
master: Idioma principal
status: Activo
saved:
enabled: El idioma ha sido habilitado
disabled: El idioma ha sido deshabilitado
master: Se ha guardado el idioma principal
error:
setting_disabled_master_language: No se puede guardar un idioma desactivado
disable_master_language: No puedes desactivar tu idioma principal

media:
single: Imagen
Expand Down
104 changes: 71 additions & 33 deletions src/Elcodi/Admin/LanguageBundle/Controller/LanguageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@

namespace Elcodi\Admin\LanguageBundle\Controller;

use Exception;
use Mmoreram\ControllerExtraBundle\Annotation\Entity as EntityAnnotation;
use Mmoreram\ControllerExtraBundle\Annotation\JsonResponse;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\HttpException;

use Elcodi\Admin\CoreBundle\Controller\Abstracts\AbstractAdminController;
use Elcodi\Component\Core\Entity\Interfaces\EnabledInterface;
use Elcodi\Component\Language\Entity\Interfaces\LanguageInterface;

/**
* Class Controller for Language
Expand Down Expand Up @@ -60,85 +60,123 @@ public function listAction()
/**
* Enable entity
*
* @param Request $request Request
* @param EnabledInterface $entity Entity to enable
* @param LanguageInterface $language The language to enable
*
* @return array Result
*
* @Route(
* path = "/{iso}/enable",
* name = "admin_language_enable"
* )
* @Method({"GET", "POST"})
* @Method({"POST"})
*
* @EntityAnnotation(
* class = "elcodi.entity.language.class",
* name = "language",
* mapping = {
* "iso" = "~iso~"
* }
* )
*
* @JsonResponse()
*/
public function enableAction(
Request $request,
EnabledInterface $entity
public function enableLanguageAction(
LanguageInterface $language
) {
$result = parent::enableAction(
$request,
$entity
);
$translator = $this->get('translator');

$this->enableEntity($language);
$this->flushCache();

return $result;
return ['message' => $translator->trans('admin.language.saved.enabled')];
}

/**
* Disable entity
*
* @param Request $request Request
* @param EnabledInterface $entity Entity to disable
* @param LanguageInterface $language The language to disable
*
* @return array Result
*
* @Route(
* path = "/{iso}/disable",
* name = "admin_language_disable"
* )
* @Method({"GET", "POST"})
* @Method({"POST"})
*
* @EntityAnnotation(
* class = "elcodi.entity.language.class",
* name = "language",
* mapping = {
* "iso" = "~iso~"
* }
* )
*
* @JsonResponse()
*/
public function disableAction(
Request $request,
EnabledInterface $entity
public function disableLanguageAction(
LanguageInterface $language
) {
$translator = $this->get('translator');

/**
* We cannot disable the default locale
*/
$masterLanguage = $this
->container
->getParameter('locale');

if ($entity->getIso() == $masterLanguage) {
return $this->getFailResponse(
$request,
new Exception('You cannot disable your master language')
$masterLanguage = $configManager = $this
->get('elcodi.manager.configuration')
->get('store.default_language');

if ($language->getIso() == $masterLanguage) {
throw new HttpException(
'403',
$translator->trans('admin.language.error.disable_master_language')
);
}

$result = parent::disableAction(
$request,
$entity
);
$this->disableEntity($language);
$this->flushCache();

return ['message' => $translator->trans('admin.language.saved.disabled')];
}

/**
* Set the master language.
*
* @param LanguageInterface $language
*
* @return array
*
* @Route(
* path = "/{iso}/master",
* name = "admin_language_master"
* )
* @Method({"POST"})
*
* @EntityAnnotation(
* class = "elcodi.entity.language.class",
* name = "language",
* mapping = {
* "iso" = "~iso~"
* }
* )
*
* @JsonResponse()
*/
public function masterLanguageAction(
LanguageInterface $language
) {
$translator = $this->get('translator');
if (!$language->isEnabled()) {
throw new HttpException(
'403',
$translator->trans('admin.language.error.setting_disabled_master_language')
);
}

$configManager = $this->get('elcodi.manager.configuration');
$configManager->set('store.default_language', $language->getIso());
$this->flushCache();

return $result;
return ['message' => $translator->trans('admin.language.saved.master')];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
</td>
<td>
<div class="switch">
<input id="enable-{{ entity.iso }}-master" type="hidden" value="{{ url('admin_language_enable', { iso: entity.iso }) }}" />
<input id="disable-{{ entity.iso }}-master" type="hidden" value="{{ url('admin_language_disable', { iso: entity.iso }) }}" />
<input id="enable-{{ entity.iso }}-master" type="hidden" value="{{ url('admin_language_master', { iso: entity.iso }) }}" />
<input id="{{ entity.iso }}-master" name="language-master" type="radio" {% if entity.iso == elcodi_config('store.default_language') %}checked="checked"{% endif %} />
<label for="{{ entity.iso }}-master"></label>
</div>
Expand Down

0 comments on commit 1aab1d6

Please sign in to comment.