Explorar el Código

Vente au kilo : adaptation formulaire modification/création produit

dev
Guillaume Bourgeois hace 5 años
padre
commit
4db896a0d5
Se han modificado 5 ficheros con 141 adiciones y 55 borrados
  1. +55
    -40
      backend/views/product/_form.php
  2. +14
    -5
      backend/web/css/screen.css
  3. +51
    -0
      backend/web/js/lechatdesnoisettes.js
  4. +8
    -3
      backend/web/sass/product/_form.scss
  5. +13
    -7
      common/models/Product.php

+ 55
- 40
backend/views/product/_form.php Ver fichero

@@ -37,7 +37,9 @@ termes.
*/

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\bootstrap\ActiveForm;
use common\models\Product;
use yii\helpers\ArrayHelper ;

/* @var $this yii\web\View */
/* @var $model app\models\Produit */
@@ -48,47 +50,60 @@ use yii\widgets\ActiveForm;

<?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?>

<?= $form->field($model, 'active')->radioList([1 => 'Oui',0 => 'Non' ]) ?>
<?= $form->field($model, 'name')->textInput(['maxlength' => 255]) ?>
<?= $form->field($model, 'description')->textInput(['maxlength' => 255]) ?>
<?= $form->field($model, 'recipe')->textarea() ?>
<?= $form->field($model, 'price')->textInput() ?>
<?= $form->field($model, 'weight')->textInput() ?>
<?= $form->field($model, 'quantity_max')
->hint('Renseignez ce champs si vous souhaitez limiter la quantité commandable pour ce produit.')
->textInput() ?>
<?= $form->field($model, 'photo')->fileInput() ?>
<?php
if(strlen($model->photo)) {
$url = Yii::$app->urlManagerProducer->getHostInfo().'/'.Yii::$app->urlManagerProducer->baseUrl ;
echo '<img class="photo-product" src="'.$url.'/uploads/'.$model->photo.'" width="200px" /><br />' ;
echo '<input type="checkbox" name="delete_photo" id="delete_photo" /> <label for="delete_photo">Supprimer la photo</label><br /><br />' ;
}
?>
<h2>Jours de distribution</h2>
<div id="days-production">
<?= $form->field($model, 'monday')->checkbox() ?>
<?= $form->field($model, 'tuesday')->checkbox() ?>
<?= $form->field($model, 'wednesday')->checkbox() ?>
<?= $form->field($model, 'thursday')->checkbox() ?>
<?= $form->field($model, 'friday')->checkbox() ?>
<?= $form->field($model, 'saturday')->checkbox() ?>
<?= $form->field($model, 'sunday')->checkbox() ?>
<div>
<div class="col-md-8">
<?= $form->field($model, 'active')->radioList([1 => 'Oui',0 => 'Non' ]) ?>
<?= $form->field($model, 'name')->textInput(['maxlength' => 255]) ?>
<?= $form->field($model, 'description')->textInput(['maxlength' => 255]) ?>
<?= $form->field($model, 'recipe')->textarea()->label('Description longue') ?>
<?= $form->field($model, 'unit')
->dropDownList(ArrayHelper::map(Product::$unitsArray, 'unit', 'wording'))
->label('Unité (pièce, poids ou volume)'); ?>
<?= $form->field($model, 'price',[
'inputTemplate' => '<div class="input-group">{input}<span class="input-group-addon"><span class="glyphicon glyphicon-euro"></span></span></div>',
]) ?>
<?= $form->field($model, 'step')->textInput()->hint('Définit ce qui est ajouté ou enlevé lors des changements de quantité.') ?>
<?= $form->field($model, 'weight')->textInput()->label('Poids (g)') ?>
<?= $form->field($model, 'quantity_max')
->hint('Renseignez ce champs si vous souhaitez limiter la quantité commandable pour une distribution.')
->textInput() ?>
<?php
if(!$model->isNewRecord) {
echo $form->field($model, 'apply_distributions')
->checkbox()
->hint('Sélectionnez cette option si vous souhaitez que ces modifications soient répercutées dans les distributions à venir déjà initialisées.');
}
?>
</div>
<div class="col-md-4">
<?= $form->field($model, 'photo')->fileInput() ?>
<?php
if(strlen($model->photo)) {
$url = Yii::$app->urlManagerProducer->getHostInfo().'/'.Yii::$app->urlManagerProducer->baseUrl ;
echo '<img class="photo-product" src="'.$url.'/uploads/'.$model->photo.'" width="200px" /><br />' ;
echo '<input type="checkbox" name="delete_photo" id="delete_photo" /> <label for="delete_photo">Supprimer la photo</label><br /><br />' ;
}
?>

<div id="days-production">
<h2>Jours de distribution</h2>
<?= $form->field($model, 'monday')->checkbox() ?>
<?= $form->field($model, 'tuesday')->checkbox() ?>
<?= $form->field($model, 'wednesday')->checkbox() ?>
<?= $form->field($model, 'thursday')->checkbox() ?>
<?= $form->field($model, 'friday')->checkbox() ?>
<?= $form->field($model, 'saturday')->checkbox() ?>
<?= $form->field($model, 'sunday')->checkbox() ?>
</div>
<div class="clr"></div>
</div>
<div class="clr"></div>
</div>
<div class="clr"></div>
<?= $form->field($model, 'id_producer')->hiddenInput()->label('') ?>
<?php
if(!$model->isNewRecord) {
echo $form->field($model, 'apply_distributions')
->checkbox()
->hint('Sélectionnez cette option si vous souhaitez que ces modifications soient répercutées dans les distributions à venir déjà initialisées.');
}
?>
<?= $form->field($model, 'id_producer')->hiddenInput()->label('') ?>

<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? 'Ajouter' : 'Modifier', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>

+ 14
- 5
backend/web/css/screen.css Ver fichero

@@ -1725,16 +1725,25 @@ body.login-page .login-box .login-box-body a:hover {
background-color: white;
}

/* line 5, ../sass/product/_form.scss */
/* line 6, ../sass/product/_form.scss */
.product-create #product-active label,
.product-update #product-active label {
margin-right: 15px;
}
/* line 10, ../sass/product/_form.scss */
.product-create #days-production .form-group,
.product-update #days-production .form-group {
float: left;
margin-right: 15px;
.product-create #days-production,
.product-update #days-production {
margin-top: 30px;
}
/* line 13, ../sass/product/_form.scss */
.product-create #days-production h2,
.product-update #days-production h2 {
font-size: 20px;
}
/* line 16, ../sass/product/_form.scss */
.product-create #days-production label,
.product-update #days-production label {
font-weight: normal;
}

/**

+ 51
- 0
backend/web/js/lechatdesnoisettes.js Ver fichero

@@ -52,6 +52,7 @@ $(document).ready(function() {
chat_index_commandes_maj_points_vente() ;
// admin
chat_select_etablissement() ;
chat_products() ;
}) ;

var UrlManager = {
@@ -64,6 +65,56 @@ var UrlManager = {
}
};

function chat_products() {
if($('.product-create').size() || $('.product-update').size()) {
chat_products_event_unit(false) ;
$('#product-unit').change(function() {
chat_products_event_unit(true) ;
}) ;
}
}

function chat_products_event_unit(change) {
var unit = $('#product-unit').val() ;
if(unit == 'piece') {
$('.field-product-step').hide() ;
$('.field-product-weight').show() ;
}
else {
$('.field-product-step').show() ;
$('.field-product-weight').hide() ;
}
var label_price = $('.field-product-price .control-label') ;
var label_step = $('.field-product-step .control-label') ;
var label_quantity_max = $('.field-product-quantity_max .control-label') ;
if(unit == 'piece') {
label_price.html('Prix (la pièce)') ;
label_quantity_max.html('Quantité max par défaut (pièces)') ;
}
else if(unit == 'g' || unit == 'kg') {
label_price.html('Prix (au kg)') ;
label_quantity_max.html('Quantité max par défaut (kg)') ;
label_step.html('Pas ('+unit+')') ;
}
else if(unit == 'mL' || unit == 'L') {
label_price.html('Prix (au litre)') ;
label_quantity_max.html('Quantité max par défaut (litres)') ;
label_step.html('Pas ('+unit+')') ;
}
if(change) {
if(unit == 'piece') {
$('#product-step').val(1) ;
}
else {
$('#product-step').val('') ;
}
}
}

function chat_tooltip() {
$('[data-toggle="tooltip"]').tooltip({container:'body'});
}

+ 8
- 3
backend/web/sass/product/_form.scss Ver fichero

@@ -1,15 +1,20 @@

.product-create,
.product-update {
#product-active {
label {
margin-right: 15px ;
}
}
#days-production {
.form-group {
float: left ;
margin-right: 15px ;
margin-top: 30px ;
h2 {
font-size: 20px ;
}
label {
font-weight: normal ;
}
}
}

+ 13
- 7
common/models/Product.php Ver fichero

@@ -61,11 +61,11 @@ class Product extends ActiveRecordCommon
var $apply_distributions = false ;
public static $unitsArray = [
'piece' => ['unit' => 'pièce', 'coefficient' => 1],
'g' => ['unit' => 'g', 'coefficient' => 1000],
'kg' => ['unit' => 'kg', 'coefficient' => 1],
'mL' => ['unit' => 'mL', 'coefficient' => 1000],
'L' => ['unit' => 'L', 'coefficient' => 1],
['unit' => 'piece', 'wording' => 'pièce', 'coefficient' => 1],
['unit' => 'g', 'wording' => 'g', 'coefficient' => 1000],
['unit' => 'kg', 'wording' => 'kg', 'coefficient' => 1],
['unit' => 'mL', 'wording' => 'mL', 'coefficient' => 1000],
['unit' => 'L', 'wording' => 'L', 'coefficient' => 1],
];
/**
@@ -89,6 +89,12 @@ class Product extends ActiveRecordCommon
[[ 'photo'], 'file'],
[['name', 'description', 'photo', 'unit'], 'string', 'max' => 255],
[['recipe'], 'string', 'max' => 1000],
['step', 'required', 'message' => 'Champs obligatoire', 'when' => function($model) {
if($model->unit == 'piece') {
return true ;
}
return false ;
}],
];
}

@@ -103,8 +109,8 @@ class Product extends ActiveRecordCommon
'description' => 'Description',
'active' => 'Actif',
'photo' => 'Photo',
'price' => 'Prix',
'weight' => 'Poids (g)',
'price' => 'Prix (€)',
'weight' => 'Poids',
'recipe' => 'Recette',
'monday' => 'Lundi',
'tuesday' => 'Mardi',

Cargando…
Cancelar
Guardar