Skip to content

Commit

Permalink
Added set collective partno for Parts (hiqdev#14)
Browse files Browse the repository at this point in the history
* Added set collective partno for Parts

* Refactored `Set collective partno` -> `change model`
  • Loading branch information
tafid authored and SilverFire committed Jul 6, 2018
1 parent 611d978 commit 45058b1
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/controllers/PartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,23 @@ public function actions()
}
},
],
'change-model' => [
'class' => SmartUpdateAction::class,
'scenario' => 'update',
'success' => Yii::t('hipanel:stock', 'Parts have been updated'),
'view' => 'changeModel',
'on beforeSave' => function (Event $event) {
/** @var \hipanel\actions\Action $action */
$action = $event->sender;
$parts = Yii::$app->request->post('Part');
$model_id = ArrayHelper::remove($parts, 'model_id');
foreach ($parts as $id => $part) {
$parts[$id]['model_id'] = $model_id;
}
$action->collection->setModel($this->newModel(['scenario' => 'update']));
$action->collection->load($parts);
}
],
'update-order-no' => [
'class' => SmartUpdateAction::class,
'scenario' => 'update-order-no',
Expand Down
1 change: 1 addition & 0 deletions src/messages/ru/hipanel:stock.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,5 @@
'Buyers' => 'Покупатели',
'Update Order No.' => 'Редактировать номер заказа',
'This operation will change the description of all the Moves and will affect other parts of the Move, even if they were not selected.' => 'Эта операция изменит описание всего Перемещения и затронет другие детали Перемещения, даже если они не были выбраны.',
'Change model' => 'Изменить модель',
];
3 changes: 3 additions & 0 deletions src/models/Part.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ public function rules()
[['order_no', 'first_move_id'], 'required', 'on' => 'update-order-no'],
[['id', 'first_move_id'], 'integer', 'on' => 'update-order-no'],
[['order_no'], 'string', 'on' => 'update-order-no'],

// Change model
[['id', 'model_id'], 'required', 'on' => 'change-model'],
];
}

Expand Down
57 changes: 57 additions & 0 deletions src/views/part/changeModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

use hipanel\helpers\Url;
use hipanel\modules\stock\widgets\combo\ModelCombo;
use hipanel\widgets\ArraySpoiler;
use yii\bootstrap\ActiveForm;
use yii\bootstrap\Html;

$this->title = Yii::t('hipanel:stock', 'Change model');
$this->params['breadcrumbs'][] = ['label' => Yii::t('hipanel:stock', 'Parts'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;

?>
<?php $form = ActiveForm::begin([
'id' => 'change-model-form',
'action' => Url::toRoute('change-model'),
'validateOnBlur' => true,
'enableAjaxValidation' => true,
'validationUrl' => Url::toRoute(['validate-form', 'scenario' => 'change-model']),
]) ?>

<div class="panel panel-default">
<div class="panel-heading">
<div class="row">
<div class="col-md-2">
<?php $model->model_id = null; print $form->field($model, 'model_id')->widget(ModelCombo::class) ?>
</div>
</div>
</div>
<div class="panel-body">
<?= ArraySpoiler::widget([
'data' => $models,
'visibleCount' => count($models),
'formatter' => function ($model) {
return Html::tag('span', $model->title, ['class' => 'label label-default']);
},
'delimiter' => ',&nbsp; ',
]) ?>
</div>
</div>

<?php foreach ($models as $model) : ?>
<?= Html::activeHiddenInput($model, "[$model->id]id") ?>
<?= Html::activeHiddenInput($model, "[$model->id]model_id") ?>
<?= Html::activeHiddenInput($model, "[$model->id]price") ?>
<?= Html::activeHiddenInput($model, "[$model->id]currency") ?>
<?= Html::activeHiddenInput($model, "[$model->id]company_id") ?>
<?= Html::activeHiddenInput($model, "[$model->id]serial") ?>
<?php endforeach ?>


<?= Html::submitButton(Yii::t('hipanel', 'Save'), ['class' => 'btn btn-success']) ?>
&nbsp;
<?= Html::button(Yii::t('hipanel', 'Cancel'), ['class' => 'btn btn-default', 'onclick' => 'history.go(-1)']) ?>

<?php ActiveForm::end() ?>

1 change: 1 addition & 0 deletions src/views/part/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@

['label' => Yii::t('hipanel:stock', 'Update'), 'url' => '#', 'linkOptions' => ['data-action' => 'update']],
['label' => Yii::t('hipanel:stock', 'Update Order No.'), 'url' => '#', 'linkOptions' => ['data-action' => 'update-order-no']],
['label' => Yii::t('hipanel:stock', 'Change model'), 'url' => '#', 'linkOptions' => ['data-action' => 'change-model']],

'<li role="presentation" class="divider"></li>',

Expand Down

0 comments on commit 45058b1

Please sign in to comment.