Skip to content

Commit

Permalink
Fixed server_ids combo display, minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tafid authored and hiqsol committed Jun 4, 2019
1 parent 9b100ec commit 7a9d74f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 36 deletions.
47 changes: 30 additions & 17 deletions src/models/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* @license BSD-3-Clause
* @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
*/

namespace hipanel\modules\server\models;

use hipanel\base\Model;
Expand All @@ -18,8 +19,15 @@ class Config extends Model
use ModelTrait;

const SCENARIO_CREATE = 'create';

const SCENARIO_UPDATE = 'update';

const SCENARIO_DELETE = 'delete';

const SCENARIO_ENABLE = 'enable';

const SCENARIO_DISABLE = 'disable';

/**
* {@inheritdoc}
*/
Expand All @@ -28,11 +36,11 @@ public function rules()
return array_merge(parent::rules(), [
[[
'id', 'client_id', 'seller_id', 'type_id', 'state_id',
'us_tariff_id', 'nl_tariff_id', 'servers_num'
'us_tariff_id', 'nl_tariff_id', 'servers_num',
], 'integer'],
[['servers_ids', 'servers'], 'safe'],
[['server_ids', 'servers'], 'safe'],
[['name', 'client', 'seller', 'state', 'state_label', 'type', 'type_label'], 'string'],
[['sort_order'], 'integer', 'min'=>0],
[['sort_order'], 'integer', 'min' => 0],
[
[
'data',
Expand All @@ -51,28 +59,33 @@ public function rules()
], 'string'],
[
['client_id', 'name', 'label', 'cpu', 'ram'],
'required', 'on' => ['create', 'update'],
'required', 'on' => [self::SCENARIO_CREATE, self::SCENARIO_UPDATE],
],

['id', 'required', 'on' => ['delete', 'enable', 'disable']]
['id', 'required', 'on' => [
self::SCENARIO_DELETE,
self::SCENARIO_ENABLE,
self::SCENARIO_DISABLE,
]],
]);
}

public function attributeLabels()
{
return array_merge(parent::attributeLabels(), [
'us_tariff_id' => 'USA tariff',
'nl_tariff_id' => 'Netherlands tariff',
'us_tariff' => 'USA tariff',
'nl_tariff' => 'Netherlands tariff',
'label' => 'Subname',
'cpu' => 'CPU',
'ram' => 'RAM',
'hdd' => 'HDD',
'ssd' => 'SSD',
'lan' => 'LAN',
'raid' => 'RAID',
'sort_order' => 'Sort order',
'server_ids' => Yii::t('hipanel:server:config', 'Servers'),
'us_tariff_id' => Yii::t('hipanel:server:config', 'USA tariff'),
'nl_tariff_id' => Yii::t('hipanel:server:config', 'Netherlands tariff'),
'us_tariff' => Yii::t('hipanel:server:config', 'USA tariff'),
'nl_tariff' => Yii::t('hipanel:server:config', 'Netherlands tariff'),
'label' => Yii::t('hipanel:server:config', 'Subname'),
'cpu' => Yii::t('hipanel:server:config', 'CPU'),
'ram' => Yii::t('hipanel:server:config', 'RAM'),
'hdd' => Yii::t('hipanel:server:config', 'HDD'),
'ssd' => Yii::t('hipanel:server:config', 'SSD'),
'lan' => Yii::t('hipanel:server:config', 'LAN'),
'raid' => Yii::t('hipanel:server:config', 'RAID'),
'sort_order' => Yii::t('hipanel:server:config', 'Sort order'),
]);
}
}
30 changes: 12 additions & 18 deletions src/views/config/_form.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php

/** @var Config $model */
/** @var yii\widgets\ActiveForm $form */

use hipanel\modules\server\models\Config;
use hipanel\widgets\Box;
Expand All @@ -12,6 +11,7 @@
use hipanel\helpers\Url;
use yii\widgets\ActiveForm;

$model->server_ids = $model->server_ids ? explode(',', $model->server_ids) : [];
?>
<?php $form = ActiveForm::begin([
'id' => 'dynamic-form',
Expand All @@ -24,7 +24,6 @@
<?php endif; ?>

<div class="row">
<div class="col-md-12">
<div class="col-md-6">
<?php Box::begin([
'title' => Yii::t('hipanel:server:config', 'Configuration details'),
Expand Down Expand Up @@ -52,32 +51,27 @@
<?= $form->field($model, 'traffic'); ?>
<?= $form->field($model, 'lan'); ?>
<?= $form->field($model, 'raid'); ?>
<?= $form->field($model, 'servers_ids')->widget(ServerCombo::class, [
<?= $form->field($model, 'server_ids')->widget(ServerCombo::class, [
'multiple' => true,
'hasId' => true,
'current' => array_combine((array)$model->server_ids, (array)$model->server_ids),
'pluginOptions' => [],
]) ?>

<?php Box::end() ?>

</div>

</div>
</div>

<div class="row">
<div class="col-md-12">
<?php Box::begin(['options' => ['class' => 'box-widget']]); ?>

<?= Html::submitButton(Yii::t('hipanel', 'Save'), [
'class' => 'btn btn-success'
]) ?>
<?= Html::button(Yii::t('hipanel', 'Cancel'), [
'class' => 'btn btn-default',
'onclick' => 'history.go(-1)'
]) ?>
<?= 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 Box::end(); ?>
</div>
</div>

<?php $form->end() ?>
5 changes: 4 additions & 1 deletion src/views/config/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
$this->title = Yii::t('hipanel', 'Edit');
$this->params['breadcrumbs'][] = [
'label' => Yii::t('hipanel:server:config', 'Configs'),
'url' => ['index']
'url' => ['index'],
];
if (count($models) === 1) {
$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]];
}
$this->params['breadcrumbs'][] = $this->title;

?>
Expand Down

0 comments on commit 7a9d74f

Please sign in to comment.