Browse Source

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

dev
Guillaume Bourgeois 5 years ago
parent
commit
4db896a0d5
5 changed files with 141 additions and 55 deletions
  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 View File

*/ */


use yii\helpers\Html; 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 $this yii\web\View */
/* @var $model app\models\Produit */ /* @var $model app\models\Produit */


<?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?> <?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>
<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"> <div class="form-group">
<?= Html::submitButton($model->isNewRecord ? 'Ajouter' : 'Modifier', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> <?= Html::submitButton($model->isNewRecord ? 'Ajouter' : 'Modifier', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div> </div>

+ 14
- 5
backend/web/css/screen.css View File

background-color: white; background-color: white;
} }


/* line 5, ../sass/product/_form.scss */
/* line 6, ../sass/product/_form.scss */
.product-create #product-active label, .product-create #product-active label,
.product-update #product-active label { .product-update #product-active label {
margin-right: 15px; margin-right: 15px;
} }
/* line 10, ../sass/product/_form.scss */ /* 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 View File

chat_index_commandes_maj_points_vente() ; chat_index_commandes_maj_points_vente() ;
// admin // admin
chat_select_etablissement() ; chat_select_etablissement() ;
chat_products() ;
}) ; }) ;


var UrlManager = { 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() { function chat_tooltip() {
$('[data-toggle="tooltip"]').tooltip({container:'body'}); $('[data-toggle="tooltip"]').tooltip({container:'body'});
} }

+ 8
- 3
backend/web/sass/product/_form.scss View File



.product-create, .product-create,
.product-update { .product-update {
#product-active { #product-active {
label { label {
margin-right: 15px ; margin-right: 15px ;
} }
} }
#days-production { #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 View File

var $apply_distributions = false ; var $apply_distributions = false ;
public static $unitsArray = [ 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],
]; ];
/** /**
[[ 'photo'], 'file'], [[ 'photo'], 'file'],
[['name', 'description', 'photo', 'unit'], 'string', 'max' => 255], [['name', 'description', 'photo', 'unit'], 'string', 'max' => 255],
[['recipe'], 'string', 'max' => 1000], [['recipe'], 'string', 'max' => 1000],
['step', 'required', 'message' => 'Champs obligatoire', 'when' => function($model) {
if($model->unit == 'piece') {
return true ;
}
return false ;
}],
]; ];
} }


'description' => 'Description', 'description' => 'Description',
'active' => 'Actif', 'active' => 'Actif',
'photo' => 'Photo', 'photo' => 'Photo',
'price' => 'Prix',
'weight' => 'Poids (g)',
'price' => 'Prix (€)',
'weight' => 'Poids',
'recipe' => 'Recette', 'recipe' => 'Recette',
'monday' => 'Lundi', 'monday' => 'Lundi',
'tuesday' => 'Mardi', 'tuesday' => 'Mardi',

Loading…
Cancel
Save