Skip to content

Commit

Permalink
Merge pull request #465 from Victoire/1.6
Browse files Browse the repository at this point in the history
Merge 1.6 into master #1.7
  • Loading branch information
Leny BERNARD committed Jun 9, 2016
2 parents 28e213d + 95b3d5c commit 75d594f
Show file tree
Hide file tree
Showing 48 changed files with 145 additions and 228 deletions.
2 changes: 1 addition & 1 deletion Bundle/BlogBundle/Controller/ArticleController.php
Expand Up @@ -180,7 +180,7 @@ public function settingsAction(Request $request, Article $article)
$response = [
'success' => true,
'url' => $this->generateUrl('victoire_core_page_show', [
'_locale' => $page->getLocale(),
'_locale' => $page->getCurrentLocale(),
'url' => $page->getReference()->getUrl(),
]),
];
Expand Down
4 changes: 2 additions & 2 deletions Bundle/BlogBundle/Controller/BlogController.php
Expand Up @@ -156,7 +156,7 @@ public function settingsAction(Request $request, BasePage $blog)
'success' => true,
'url' => $this->generateUrl(
'victoire_core_page_show', [
'_locale' => $blog->getLocale(), 'url' => $reference->getUrl(),
'_locale' => $blog->getCurrentLocale(), 'url' => $reference->getUrl(),
]),
]);
}
Expand Down Expand Up @@ -218,7 +218,7 @@ public function categoryAction(Request $request, BasePage $blog)

return new JsonResponse([
'success' => true,
'url' => $this->generateUrl('victoire_core_page_show', ['_locale' => $blog->getLocale(), 'url' => $blog->getUrl()]), ]);
'url' => $this->generateUrl('victoire_core_page_show', ['_locale' => $blog->getCurrentLocale(), 'url' => $blog->getUrl()]), ]);
}
//we display the form
$errors = $this->get('victoire_form.error_helper')->getRecursiveReadableErrors($form);
Expand Down
2 changes: 1 addition & 1 deletion Bundle/BlogBundle/Entity/Article.php
Expand Up @@ -156,7 +156,7 @@ class Article
*/
public function __toString()
{
return $this->name;
return $this->getName();
}

/**
Expand Down
27 changes: 19 additions & 8 deletions Bundle/CoreBundle/Form/ViewType.php
Expand Up @@ -13,6 +13,8 @@
use Victoire\Bundle\BlogBundle\Entity\ArticleTemplate;
use Victoire\Bundle\BusinessPageBundle\Entity\BusinessTemplate;
use Victoire\Bundle\CoreBundle\Entity\View;
use Victoire\Bundle\FormBundle\Form\Type\UrlvalidatedType;
use Victoire\Bundle\PageBundle\Entity\BasePage;
use Victoire\Bundle\TemplateBundle\Entity\Template;

/**
Expand Down Expand Up @@ -88,15 +90,24 @@ public function buildForm(FormBuilderInterface $builder, array $options)
]
);
}
});

$builder->add('translations', TranslationsType::class, [
'fields' => [
'name' => [
'label' => 'form.view.type.name.label',
],
],
]);
if ($view instanceof BasePage) {
$translationOptions = [
'fields' => [
'name' => [
'label' => 'form.view.type.name.label',
],
],
];
if ($view->getId() && !$view->isHomepage()) {
$translationOptions['fields']['slug'] = [
'label' => 'form.page.type.slug.label',
'field_type' => UrlvalidatedType::class,
];
}
$form->add('translations', TranslationsType::class, $translationOptions);
}
});
}

protected function getAvailableLocales()
Expand Down
3 changes: 2 additions & 1 deletion Bundle/CoreBundle/Resources/public/js/edit/victoire.js
Expand Up @@ -19,8 +19,9 @@ $vic(document).on("keydown", function (e){
$vic('button[data-mode="admin-style"]').click();
} else if ($vic('body').attr('role') == 'admin-style') {
$vic('button[data-mode="admin-readonly"]').click();
} else if ($vic('button[data-mode="admin-readonly"]') != undefined) {
$vic('button[data-mode="admin-readonly"]').click();
}

}
});

Expand Down
127 changes: 15 additions & 112 deletions Bundle/CoreBundle/Resources/public/js/edit/widget.js
Expand Up @@ -20,66 +20,27 @@ $vic(document).on('change', '.vic-new-widget select', function(event) {
$vic(this).parents('.vic-new-widget').first().addClass('vic-creating');
});


// Create new widget after submit
$vic(document).on('click', '.vic-widget-modal *[data-modal="create"]', function(event) {
$vic(document).on('click', '.vic-widget-modal a[data-modal="update"], .vic-widget-modal a[data-modal="create"]', function(event) {
event.preventDefault();
// we remove the prototype picker to avoid persist it
if ($vic("select.picker_entity_select").length != 0 && $vic("select.picker_entity_select").attr('name').indexOf('[items][__name__][entity]') !== -1) {
if ($vic("select.picker_entity_select").length != 0 && $vic("select.picker_entity_select").attr('name').indexOf('appventus_victoirecorebundle_widgetlistingtype[items][__name__][entity]') !== -1) {
$vic("select.picker_entity_select").remove();
}
//we look for the form currently active and visible
var form = $vic(this).parents('.vic-modal-content').find('.vic-tab-pane.vic-active form').filter(":visible");
$vic(form).trigger("victoire_widget_form_create_presubmit");

loading(true);

formData = form.serialize();
var contentType = 'application/x-www-form-urlencoded; charset=UTF-8';
if ($vic(form).attr('enctype') == 'multipart/form-data') {
var formData = new FormData($vic(form)[0]);
var contentType = false;
}
$vic.ajax({
type: form.attr('method'),
url : form.attr('action'),
data : formData,
processData : false,
contentType : contentType
}).done(function(response){
if (true === response.success) {
if (response.hasOwnProperty("redirect")) {
window.location.replace(response.redirect);
} else {
window.location.reload();
}

loading(false);

} else {
warn(response.message, 10000);
//inform user there have been an error
if (response.html) {
$vic('.vic-modal-body .vic-container .vic-tab-pane.vic-active').html(response.html);
}
var forms = [];
$vic('.vic-tab-quantum').each(function(index, quantum) {
// matches widget edit form with more than one mode available
var activeForm = $vic(quantum).find('.vic-tab-mode.vic-active .vic-tab-pane.vic-active > form');
// matches widget edit form with only static mode available
if (activeForm.length == 0) {
activeForm = $vic(quantum).find('.vic-tab-pane.vic-active form, #picker-static-static.vic-active form');
}
}).fail(function(response) {
console.log(response);
error('Oups, une erreur est apparue', 10000);
// matches widget stylize form
if (activeForm.length == 0 && $vic(quantum).hasClass('vic-active')) {
activeForm = $vic(quantum).find('form[name="widget_style"]');
}
forms = $vic.merge(forms, [activeForm]);
});
$vic(form).trigger("victoire_widget_form_create_postsubmit");
});


$vic(document).on('click', '.vic-widget-modal a[data-modal="update-bulk"], .vic-widget-modal a[data-modal="create-bulk"]', function(event) {
event.preventDefault();
// we remove the prototype picker to avoid persist it
if ($vic("select.picker_entity_select").length != 0 && $vic("select.picker_entity_select").attr('name').indexOf('appventus_victoirecorebundle_widgetlistingtype[items][__name__][entity]') !== -1) {
$vic("select.picker_entity_select").remove();
}

var forms = $vic(this).parents('.vic-modal-content').find('.vic-tab-quantum .vic-tab-mode.vic-active > form');
forms = $vic.merge(forms, $vic(this).parents('.vic-modal-content').find('.vic-tab-quantum .vic-tab-mode.vic-active .vic-tab-pane.vic-active > form'));

loading(true);
var calls = [];
Expand Down Expand Up @@ -130,70 +91,12 @@ $vic(document).on('click', '.vic-widget-modal a[data-modal="update-bulk"], .vic-
loading(false);
});
});
$vic(document).on('click', '.vic-widget-modal a[data-modal="update"]', function(event) {
event.preventDefault();

// we remove the prototype picker to avoid persist it
if ($vic("select.picker_entity_select").length != 0 && $vic("select.picker_entity_select").attr('name').indexOf('appventus_victoirecorebundle_widgetlistingtype[items][__name__][entity]') !== -1) {
$vic("select.picker_entity_select").remove();
}
var form = $vic(this).parents('.vic-modal-content').find('form.vic-form-active');
if ($vic(form).length == 0) {
form = $vic(this).parents('.vic-modal-content').find('.vic-tab-pane.vic-active form').filter(":visible");
}
$vic(form).trigger("victoire_widget_form_update_presubmit");

loading(true);

formData = form.serialize();
var contentType = 'application/x-www-form-urlencoded; charset=UTF-8';
if ($vic(form).attr('enctype') == 'multipart/form-data') {
var formData = new FormData($vic(form)[0]);
var contentType = false;
}
$vic.ajax({
type: form.attr('method'),
url : form.attr('action'),
data : formData,
processData : false,
contentType : contentType
}).done(function(response){
if (true === response.success) {
if (response.hasOwnProperty("redirect")) {
window.location.replace(response.redirect);
} else {
if (response.hasOwnProperty("redirect")) {
window.location.replace(response.redirect);
} else {
window.location.reload();
}
}
if(typeof(Storage) !== "undefined") {
var object = {data: response.html, timestamp: new Date().getTime()};
localStorage.setItem('victoire__widget__html__' + response.widgetId, JSON.stringify(object));
}
loading(false);
} else {

//inform user there have been an error
warn(response.message, 10000);

if (response.html) {
$vic(form).parent('div').html(response.html);
}
}
}).fail(function(response) {
console.log(response);
error('Oups, une erreur est apparue', 10000);
});
$vic(form).trigger("victoire_widget_form_update_postsubmit");
});

// Delete a widget after submit
$vic(document).on('click', 'a#widget-new-tab', function(event) {
event.preventDefault();
loading(true);
var url = Routing.generate('victoire_core_widget_new_quantum_item', {
var url = Routing.generate('victoire_core_widget_new', {
type: $vic(this).data('type'),
viewReference: viewReferenceId,
slot: $vic(this).data('slot'),
Expand Down
7 changes: 7 additions & 0 deletions Bundle/CoreBundle/Resources/style/less/ugly.less
Expand Up @@ -20,3 +20,10 @@
color: @green;
}

.vic-quantum-nav {
position: fixed;
bottom: 50px;
}
.quantum-tab-name {
background-color: #fff;
}
Expand Up @@ -16,7 +16,7 @@
<a href="{{ path('victoire_core_widget_delete_bulk', {'id':widget.id, 'viewReference': view.reference.id })}}" class="vic-btn vic-btn-danger vic-pull-left" data-toggle="vic-confirm" data-modal="delete-bulk" data-title="{{ 'modal.button.delete.confirm.title'|trans({}, 'victoire') }}" data-body="{{ 'modal.button.delete.confirm.body'|trans({}, 'victoire') }}" title="{{ 'modal.button.delete.title'|trans({}, 'victoire') }}"><i class="fa fa-trash-o"></i> <span>{{ 'modal.button.delete.title'|trans({}, 'victoire') }}</span></a>
{% endif %}
<a href="#" class="vic-btn vic-btn-default vic-pull-left" data-modal="close"><i class="fa fa-times-circle"></i> {{ 'modal.button.cancel.title'|trans({}, 'victoire') }}</a>
<a href="#" class="vic-btn vic-btn-success" data-modal="{% block action %}create{% endblock action %}-bulk" title="{{ ('modal.button.'~ block('action') ~'.title')|trans({}, 'victoire') }}"><i class="fa fa-check-circle"></i> {{ ('modal.button.'~ block('action') ~'.title')|trans({}, 'victoire') }}</a>
<a href="#" class="vic-btn vic-btn-success" data-modal="{% block action %}create{% endblock action %}" title="{{ ('modal.button.'~ block('action') ~'.title')|trans({}, 'victoire') }}"><i class="fa fa-check-circle"></i> {{ ('modal.button.'~ block('action') ~'.title')|trans({}, 'victoire') }}</a>
{% endblock modal_footer_content %}
</div>
</div>
Expand Down
Expand Up @@ -10,7 +10,7 @@
{% include "VictoireCoreBundle:Widget:Form/new_partial.html.twig" with {forms: forms[key], widget: widget, classes: classes, id: widgets[key].id ? widgets[key].id : id, quantum: forms[key]['quantum'] }%}
{% endfor %}
</div>
<ul class="vic-nav vic-nav-tabs vic-modal-nav-tabs">
<ul class="vic-nav vic-nav-tabs vic-modal-nav-tabs vic-quantum-nav">
{% for key, form in forms %}
{% include "VictoireCoreBundle:Widget:Form/tab.html.twig" with {isLast: loop.last, widget: widgets[key], active: form.active is defined ? form.active : false, id: widgets[key].id ? widgets[key].id : id} %}
{% endfor %}
Expand Down
Expand Up @@ -17,15 +17,15 @@

<div class="vic-tab-content vic-modal-tab-content vic-modal-tab-content-container">
{% for index, form in forms %}
<div class="vic-tab-quantum vic-tab-pane{% if form.vars.data == widget %} vic-active{% endif %}" id="widget-{{ widgets[index].id }}-tab-pane">
<div class="vic-tab-quantum vic-tab-pane{% if form.vars.data.id == widget.id %} vic-active{% endif %}" id="widget-{{ widgets[index].id }}-tab-pane">
{% include 'VictoireCoreBundle:Widget/Form/stylize:form.html.twig' %}
</div>
{% endfor %}
</div>

<ul class="vic-nav vic-nav-tabs vic-modal-nav-tabs">
{% for index, form in forms %}
<li class="{% if not loop.last %}vic-seperate{% endif %}{% if form.vars.data == widget %} vic-active{% endif %}">
<li class="{% if not loop.last %}vic-seperate{% endif %}{% if form.vars.data.id == widget.id %} vic-active{% endif %}">
<a id="widget-{{ widgets[index].id}}-tab" class="quantum-tab-name" href="#widget-{{ widgets[index].id}}-tab-pane" data-toggle="vic-tab"><span>{{ widgets[index].quantum ? widgets[index].quantum : "widget_modal.quantum.tab.default"|trans }}</span></a>
</li>
{% endfor %}
Expand All @@ -50,7 +50,7 @@

{% endblock modal_body_content %}

{% block action %}{% if forms|length > 1 %}update-bulk{% else %}update{% endif %}{% endblock action %}
{% block action %}update{% endblock action %}
{% block modal_footer_content %}
<a href="#" class="vic-btn vic-btn-default vic-pull-left" data-modal="close"><i class="fa fa-times-circle"></i> {{ 'modal.button.cancel.title'|trans({}, 'victoire') }}</a>
<a href="#" class="vic-btn vic-btn-success" data-modal="{{ block('action') }}" title="{{ ('modal.button.'~ block('action') ~'.title')|trans({}, 'victoire') }}"><i class="fa fa-check-circle"></i> {{ ('modal.button.'~ block('action') ~'.title')|trans({}, 'victoire') }}</a>
Expand Down
@@ -1,3 +1,3 @@
<li class="{% if not isLast %}vic-seperate{% endif %}{% if active is defined and active == true %} vic-active{% endif %}">
<a id="widget-{{ id }}-tab" class="quantum-tab-name" href="#widget-{{ id }}-tab-pane" data-toggle="vic-tab"><span>{{ widget.quantum ? widget.quantum : "widget_modal.quantum.tab.default"|trans({}, 'victoire') }}</span><i class="edit fa fa-pencil"></i></a>
<a id="widget-{{ id }}-tab" class="quantum-tab-name" href="#widget-{{ id }}-tab-pane" data-toggle="vic-tab"><span>{{ widget.quantum ? widget.quantum : "widget_modal.quantum.tab.default"|trans({}, 'victoire') }}</span> <i class="edit fa fa-pencil"></i></a>
</li>
2 changes: 1 addition & 1 deletion Bundle/CoreBundle/Twig/Extension/CmsExtension.php
Expand Up @@ -145,7 +145,7 @@ public function cmsSlotWidgets($slotId, $slotOptions = [])
$result = '';
$slotOptions = $this->widgetRenderer->computeOptions($slotId, $slotOptions);

if (!empty($currentView->getBuiltWidgetMap()[$slotId])) {
if ($currentView && !empty($currentView->getBuiltWidgetMap()[$slotId])) {
//parse the widget maps

/* @var WidgetMap $widgetMap */
Expand Down
3 changes: 2 additions & 1 deletion Bundle/FormBundle/Form/Type/UrlvalidatedType.php
Expand Up @@ -40,7 +40,8 @@ public function buildView(FormView $view, FormInterface $form, array $options)
$locale = $page->getCurrentLocale();
}

$url = $this->router->generate('victoire_core_page_show', ['url' => $page->getParent()->getUrl(), '_locale' => $locale], Router::ABSOLUTE_URL);
$parentUrl = $page->getParent() ? $page->getParent()->getUrl() : '';
$url = $this->router->generate('victoire_core_page_show', ['url' => $parentUrl, '_locale' => $locale], Router::ABSOLUTE_URL);
$view->vars['base_url'] = $url;

parent::buildView($view, $form, $options);
Expand Down
13 changes: 9 additions & 4 deletions Bundle/FormBundle/Resources/public/js/form.js
Expand Up @@ -15,11 +15,13 @@ $vic(document).on('change', 'select[data-refreshOnChange="true"], input:checkbox
var form = $vic(this).parents('form');
loading(true);

var targetClass = ".vic-modal-body .vic-container-fluid .vic-tab-pane.vic-active";
var targetClass = ".vic-modal-body .vic-container-fluid .vic-tab-quantum.vic-tab-pane.vic-active";
if ($vic(this).data('target')) {
targetClass = $vic(this).data('target');
} else if ($vic(this).parents('.vic-modal').hasClass('-stylize')) {
targetClass = ".vic-modal-body .vic-container-fluid";
}
var updateStrategy = "html";
if ($vic(this).data('update-strategy')) {
updateStrategy = $vic(this).data('update-strategy');
}

//Get last element of visible target class
Expand All @@ -32,7 +34,10 @@ $vic(document).on('change', 'select[data-refreshOnChange="true"], input:checkbox
data: form.serialize(),
async: true
}).done(function(response){
$target.html(response.html);

//By default, the updateStrategy is html (a simple replace) but you can set your own function
//for example, append, after etc or even a custom one.
eval('$target.' + updateStrategy + '(response.html)');
var scripts = $target.find("script");
loading(false);
}).fail(function(response) {
Expand Down
1 change: 1 addition & 0 deletions Bundle/FormBundle/Resources/views/Form/fields.html.twig
@@ -1,5 +1,6 @@
{% trans_default_domain "victoire" %}
{% use 'form_div_layout.html.twig' %}
{% use 'VictoireFormBundle:Form:localeTabs.html.twig' %}

{% block urlvalidated_widget %}
<div class="vic-form-url-slug">
Expand Down
Expand Up @@ -54,7 +54,6 @@ public function prepend(ContainerBuilder $container)
if (isset($config['available_locales'])) {
$container->prependExtensionConfig('a2lix_translation_form', [
'locales' => $config['available_locales'],
'templating' => 'VictoireFormBundle:Form:localeTabs.html.twig',
]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Bundle/PageBundle/Entity/Traits/WebViewTrait.php
Expand Up @@ -152,7 +152,7 @@ public function isPublished()
*/
public function isHomepage()
{
return $this->homepage;
return (bool) $this->homepage;
}

/**
Expand Down

0 comments on commit 75d594f

Please sign in to comment.