L'ajout des étapes de recette fonctionne.
Reste à faire : - suppression d'étape - déplacement d'étape
This commit is contained in:
@@ -24,5 +24,8 @@
|
||||
<default key="_controller">Recettes\Controller\BackController::addProduct</default>
|
||||
<requirement key="contentId">\d+</requirement>
|
||||
</route>
|
||||
<route id="recipe.add_step" path="/admin/module/Recettes/add-step" methods="post">
|
||||
<default key="_controller">Recettes\Controller\BackController::addStep</default>
|
||||
</route>
|
||||
|
||||
</routes>
|
||||
|
||||
@@ -7,6 +7,7 @@ use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Propel\Runtime\Exception\PropelException;
|
||||
use Propel\Runtime\Propel;
|
||||
use Recettes\Form\RecetteCreateForm;
|
||||
use Recettes\Form\StepCreateForm;
|
||||
use Recettes\Model\Recipe;
|
||||
use Recettes\Model\RecipeProducts;
|
||||
use Recettes\Model\RecipeProductsQuery;
|
||||
@@ -181,4 +182,36 @@ class BackController extends BaseAdminController
|
||||
return $this->render('includes/related-products', [ 'content_id' => $contentId ]);
|
||||
}
|
||||
|
||||
|
||||
public function addStep(Request $request)
|
||||
{
|
||||
$form = new StepCreateForm($request);
|
||||
$errorUrl = "";
|
||||
try {
|
||||
$formValidate = $this->validateForm($form);
|
||||
$data = $formValidate->getData();
|
||||
|
||||
$recipeId = $data['recipe_id'];
|
||||
$step = $data['step'];
|
||||
$description = $data['description'];
|
||||
$errorUrl = $data['error_url'];
|
||||
$successUrl = $data['success_url'];
|
||||
if ($recipeId && $step && $description) {
|
||||
(new RecipeSteps())
|
||||
->setRecipeId($recipeId)
|
||||
->setStep($step)
|
||||
->setDescription($description)
|
||||
->save();
|
||||
|
||||
return new RedirectResponse(URL::getInstance()->absoluteUrl($successUrl));
|
||||
}
|
||||
else
|
||||
return new RedirectResponse(URL::getInstance()->absoluteUrl($errorUrl));
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$error = $e->getMessage();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Recettes\Form;
|
||||
|
||||
use Recettes\Recettes;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Form\BaseForm;
|
||||
|
||||
/**
|
||||
@@ -16,12 +18,18 @@ class StepCreateForm extends BaseForm
|
||||
protected function buildForm()
|
||||
{
|
||||
$this->formBuilder
|
||||
->add(
|
||||
"recipe_id",
|
||||
"integer",
|
||||
[
|
||||
"required" => true
|
||||
])
|
||||
->add(
|
||||
"step",
|
||||
"number",
|
||||
"integer",
|
||||
[
|
||||
"required" => true,
|
||||
"label" => "Step",
|
||||
"label" => $this->trans("Step"),
|
||||
"label_attr" => ['for' => 'step']
|
||||
])
|
||||
->add(
|
||||
@@ -29,8 +37,8 @@ class StepCreateForm extends BaseForm
|
||||
"textarea",
|
||||
[
|
||||
"required" => true,
|
||||
"label" => "Description",
|
||||
"label_attr" => ['for' => 'description']
|
||||
"label" => $this->trans("Description"),
|
||||
"label_attr" => ['for' => 'description'],
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -41,4 +49,14 @@ class StepCreateForm extends BaseForm
|
||||
{
|
||||
return "recette-step-create";
|
||||
}
|
||||
|
||||
|
||||
protected function trans($id, $parameters = [])
|
||||
{
|
||||
if (null === $this->translator) {
|
||||
$this->translator = Translator::getInstance();
|
||||
}
|
||||
|
||||
return $this->translator->trans($id, $parameters, Recettes::MESSAGE_DOMAIN);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,4 +26,6 @@ return array(
|
||||
'Created on' => 'Rédigée le',
|
||||
'Save recipe' => 'Sauvegarder la recette',
|
||||
'Create a new step' => 'Ajouter une étape à votre recette',
|
||||
'No need to step number' => 'Inutile de saisir le numéro de l\'étape dans la description ci-dessus : il sera automatiquement rajouté !',
|
||||
|
||||
);
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
<th colspan="2">{intl l="Detail" d="recettes"}</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
{assign var="last_step" value="0"}
|
||||
{loop name="steps-loop" type="recipe_steps" recipe_id=$recipe_id}
|
||||
<tr>
|
||||
<td>
|
||||
@@ -15,12 +14,11 @@
|
||||
{if $LOOP_COUNT < $LOOP_TOTAL}
|
||||
<a href="{url path='/admin/module/Recettes/update-position?mode=down&step=%step' step=$STEP}" class="u-position-down"><i class="glyphicon glyphicon-arrow-down"></i></a>
|
||||
{/if}</td>
|
||||
<td>{$DESCRIPTION}</td>
|
||||
<td>{$DESCRIPTION|unescape:"html" nofilter}</td>
|
||||
<td class="text-center">
|
||||
<a href="{url path='/admin/module/Recettes/remove-step/%recipeId/%step/%contentId' recipeId=$recipe_id step=$STEP contentId=$content_id}" class="delete-step"><i class="glyphicon glyphicon-trash"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
{if $LOOP_COUNT=$LOOP_TOTAL}{assign var="last_step" value="$STEP"}{/if}
|
||||
{/loop}
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -30,22 +28,3 @@
|
||||
data-target="#add-step-modal" data-toggle="modal">
|
||||
<i class="glyphicon glyphicon-plus-sign"></i>
|
||||
</a>
|
||||
|
||||
{form name="recette-step-create"}
|
||||
{capture "step_create"}
|
||||
{include file="modal/step-edit.html" form_name="recette-step-create" next_step=($last_step+1)}
|
||||
{/capture}
|
||||
|
||||
{include file="includes/generic-create-dialog.html"
|
||||
|
||||
dialog_id = "add-step-modal"
|
||||
dialog_title = {intl l="Create a new step" d="recettes"}
|
||||
dialog_body = {$smarty.capture.step_create nofilter}
|
||||
|
||||
dialog_ok_label = {intl l="Create"}
|
||||
dialog_cancel_label = {intl l="Cancel"}
|
||||
|
||||
form_action = {$current_url}
|
||||
form_enctype = {form_enctype form=$form}
|
||||
}
|
||||
{/form}
|
||||
@@ -2,12 +2,19 @@
|
||||
|
||||
{form_hidden_fields form=$form}
|
||||
|
||||
{render_form_field form=$form field="success_url" value={$success_url|default:{url path="/admin/content/update/$contentId?current_tab=recipe"}}}
|
||||
{render_form_field form=$form field="success_url" value={url path="/admin/content/update/$content_id?current_tab=recipe"}}
|
||||
{render_form_field form=$form field="error_url" value={url path="/admin/content/update/$content_id?current_tab=recipe"}}
|
||||
|
||||
{form_field form=$form field="recipe_id"}
|
||||
<div class="form-group hidden">
|
||||
<input type="hidden" class="form-control" name="{$name}" id="{$label_attr.for}" value="{$recipe_id}">
|
||||
</div>
|
||||
{/form_field}
|
||||
|
||||
{form_field form=$form field="step"}
|
||||
<div class="form-group">
|
||||
<label class="control-label" for="{$label_attr.for}">{intl l=$label d="recettes"}</label>
|
||||
<input type="text" class="etroit" name="{$name}" id="{$label_attr.for}" value="{$next_step}" disabled />
|
||||
<input type="text" class="form-control etroit" name="{$name}" id="{$label_attr.for}" value="{$next_step}" readonly />
|
||||
</div>
|
||||
{/form_field}
|
||||
|
||||
@@ -17,10 +24,10 @@
|
||||
{intl l=$label d="recettes"}
|
||||
{if $required}<span class="required">*</span>{/if}
|
||||
</label>
|
||||
|
||||
{form_error form=$form field="description"}{$message}{/form_error}
|
||||
<textarea id="attr-description" name="{$name}" rows="10" class="form-control wysiwyg">{$DESCRIPTION}</textarea>
|
||||
<textarea id="{$name}" name="{$name}" rows="10" class="form-control wysiwyg">{$DESCRIPTION}</textarea>
|
||||
<span class="help-block">{intl l="No need to step number" d="recettes"}</span>
|
||||
</div>
|
||||
{/form_field}
|
||||
|
||||
{/form}
|
||||
{/form}
|
||||
|
||||
@@ -9,6 +9,12 @@
|
||||
{assign var="other_ingredients" value=$OTHER_INGREDIENTS}
|
||||
{/loop}
|
||||
|
||||
{assign var="last_step" value="0"}
|
||||
{loop name="steps-loop" type="recipe_steps" recipe_id=$recipe_id}
|
||||
{if $LOOP_COUNT=$LOOP_TOTAL}{assign var="last_step" value="$STEP"}{/if}
|
||||
{/loop}
|
||||
|
||||
|
||||
<div class="form-container">
|
||||
{form name="recette_create_form"}
|
||||
<form id="admin-comment-form" method="post" action="{url path='/admin/module/Recettes/save'}" {form_enctype form=$form} class="clearfix">
|
||||
@@ -129,4 +135,21 @@
|
||||
</div>
|
||||
</form>
|
||||
{/form}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{* CREATE Modal *}
|
||||
{form name="recette-step-create"}
|
||||
{capture "step_create"}
|
||||
{include file="modal/step-edit.html" form_name="recette-step-create" next_step=($last_step+1) recipe_id=$recipe_id content_id=$content_id}
|
||||
{/capture}
|
||||
|
||||
{include file="includes/generic-create-dialog.html"
|
||||
dialog_id = "add-step-modal"
|
||||
dialog_title = {intl l="Create a new step" d="recettes"}
|
||||
dialog_body = {$smarty.capture.step_create nofilter}
|
||||
dialog_ok_label = {intl l="Create"}
|
||||
dialog_cancel_label = {intl l="Cancel"}
|
||||
form_action = {url path="/admin/module/Recettes/add-step"}
|
||||
form_enctype = {form_enctype form=$form}
|
||||
}
|
||||
{/form}
|
||||
@@ -347,4 +347,7 @@ span.product-categorie {
|
||||
margin: auto !important;
|
||||
line-height: 1rem !important;
|
||||
height: 1.5rem;
|
||||
}
|
||||
.autres-ingredients {
|
||||
text-align: left;
|
||||
}
|
||||
@@ -99,7 +99,7 @@
|
||||
{loop type="recipe_steps" name="steps-loop" recipe_id=$ID}
|
||||
<tr>
|
||||
<td class="number">{$STEP}</td>
|
||||
<td class="description">{$DESCRIPTION}</td>
|
||||
<td class="description">{$DESCRIPTION|unescape:"html" nofilter}</td>
|
||||
</tr>
|
||||
{/loop}
|
||||
</table>
|
||||
|
||||
Reference in New Issue
Block a user