diff --git a/src/controllers/AccountController.php b/src/controllers/AccountController.php index 0dffa76d..c4c44043 100644 --- a/src/controllers/AccountController.php +++ b/src/controllers/AccountController.php @@ -15,118 +15,27 @@ public function actions() { return [ 'create' => [ - 'class' => 'hipanel\actions\SwitchAction', - 'success' => Yii::t('app', 'Account create task has been created successfully'), - 'error' => Yii::t('app', 'Error while creating account'), - 'scenario' => 'create-user', - 'GET html | GET pjax' => [ - 'class' => 'hipanel\actions\RenderAction', - 'view' => 'create', - 'params' => [ - 'model' => function ($action) { - return $action->controller->newModel(['scenario' => 'create-user']); - }, - ], - ], - 'POST html | POST pjax' => [ - 'save' => true, - 'success' => [ - 'class' => 'hipanel\actions\RedirectAction', - 'url' => function ($action, $model) { - return ['view', 'id' => $model->id]; - } - ], - 'error' => [ - 'class' => 'hipanel\actions\RenderAction', - 'view' => 'create', - 'params' => [ - 'model' => function ($action, $model) { - return $model; - }, - 'type' => 'user' - ], - ], - ], + 'class' => 'hipanel\actions\SmartCreateAction', + 'success' => Yii::t('app', 'Account creating task has been added to queue'), + 'error' => Yii::t('app', 'An error occurred when trying to create account') ], 'create-ftponly' => [ - 'class' => 'hipanel\actions\SwitchAction', - 'success' => Yii::t('app', 'Account create task has been created successfully'), - 'error' => Yii::t('app', 'Error while creating account'), - 'GET html | GET pjax' => [ - 'class' => 'hipanel\actions\RenderAction', - 'view' => 'create', - 'params' => [ - 'model' => function ($action) { - return $action->controller->newModel(['scenario' => 'create-ftponly']); - } - ], - ], - 'POST html | POST pjax' => [ - 'save' => true, - 'success' => [ - 'class' => 'hipanel\actions\RedirectAction', - 'url' => function ($action, $model) { - return ['view', 'id' => $model->id]; - } - ], - 'error' => [ - 'class' => 'hipanel\actions\RenderAction', - 'view' => 'create', - 'params' => [ - 'model' => function ($action, $model) { - return $model; - } - ], - ], - ], + 'class' => 'hipanel\actions\SmartCreateAction', + 'success' => Yii::t('app', 'Account creating task has been added to queue'), + 'error' => Yii::t('app', 'An error occurred when trying to create account') ], 'set-password' => [ - 'class' => 'hipanel\actions\SwitchAction', - 'success' => Yii::t('app', 'Password changing task has been successfully added to queue'), - 'error' => Yii::t('app', 'An error occurred when trying to change password'), - 'POST html' => [ - 'save' => true, - 'success' => [ - 'class' => 'hipanel\actions\RedirectAction', - 'url' => function ($action, $model) { - return ['view', 'id' => $model->id]; - } - ] - ], - 'POST pjax' => [ - 'save' => true, - 'success' => [ - 'class' => 'hipanel\actions\ProxyAction', - 'action' => 'view', - 'params' => function ($action, $model) { - return ['id' => $model->id]; - }, - ] - ], + 'class' => 'hipanel\actions\SmartUpdateAction', + 'success' => Yii::t('app', 'Password changed'), + 'error' => Yii::t('app', 'Failed to change password'), ], 'set-allowed-ips' => [ - 'class' => 'hipanel\actions\SwitchAction', - 'success' => Yii::t('app', 'Allowed IPs changing task has been successfully added to queue'), - 'error' => Yii::t('app', 'An error occurred when trying to change allowed IPs'), - 'POST html' => [ - 'save' => true, - 'success' => [ - 'class' => 'hipanel\actions\RedirectAction', - 'url' => function ($action, $model) { - return ['view', 'id' => $model->id]; - } - ] - ], - 'POST pjax' => [ - 'save' => true, - 'success' => [ - 'class' => 'hipanel\actions\ProxyAction', - 'action' => 'view', - 'params' => function ($action, $model) { - return ['id' => $model->id]; - }, - ] - ], + 'class' => 'hipanel\actions\SmartUpdateAction', + 'success' => Yii::t('app', 'Allowed IPs changing task has been successfully added to queue'), + 'error' => Yii::t('app', 'An error occurred when trying to change allowed IPs'), + ], + 'validate-form' => [ + 'class' => 'hipanel\actions\ValidateFormAction', ], ]; } diff --git a/src/controllers/DbController.php b/src/controllers/DbController.php index 84c7cba4..b73679e7 100644 --- a/src/controllers/DbController.php +++ b/src/controllers/DbController.php @@ -8,110 +8,37 @@ namespace hipanel\modules\hosting\controllers; use hipanel\base\CrudController; -use yii\filters\VerbFilter; use Yii; class DbController extends CrudController { - public function behaviors() - { - return [ - 'verbs' => [ - 'class' => VerbFilter::className(), - 'actions' => [ - 'create' => ['get', 'post'] - ] - ] - ]; - } - public function actions() { return [ - 'delete' => [ - 'class' => 'hipanel\actions\SwitchAction', - 'success' => Yii::t('app', 'DB delete task has been created successfully'), - 'error' => Yii::t('app', 'Error while deleting DB'), - 'POST' => [ - 'save' => true, - 'success' => [ - 'class' => 'hipanel\actions\RedirectAction', - 'url' => ['index'], - ], - 'error' => [ - 'class' => 'hipanel\actions\RedirectAction', - 'url' => function ($action, $model) { - return ['view', 'id' => $model->id]; - } - ] - ], - ], - 'create' => [ - 'class' => 'hipanel\actions\SwitchAction', - 'success' => Yii::t('app', 'DB create task has been created successfully'), - 'error' => Yii::t('app', 'Error while creating DB'), - 'GET html | GET pjax' => [ - 'class' => 'hipanel\actions\RenderAction', - 'view' => 'create', - 'params' => [ - 'model' => function ($action) { - return $action->controller->newModel(['scenario' => 'create']); - } - ], - ], - 'POST html' => [ - 'save' => true, - 'flash' => true, - 'success' => [ - 'class' => 'hipanel\actions\RedirectAction', - 'url' => function ($action, $model) { - return ['view', 'id' => $model->id]; - } - ], - 'error' => [ - 'class' => 'hipanel\actions\RenderAction', - 'view' => 'create', - 'params' => [ - 'model' => function ($action, $model) { - return $model; - } - ], - ], - ], + 'create' => [ + 'class' => 'hipanel\actions\SmartCreateAction', + 'success' => Yii::t('app', 'DB create task has been created successfully'), + 'error' => Yii::t('app', 'Error while creating DB'), ], - 'set-password' => [ - 'class' => 'hipanel\actions\SwitchAction', + 'set-password' => [ + 'class' => 'hipanel\actions\SmartUpdateAction', 'success' => Yii::t('app', 'DB password change task has been created successfully'), 'error' => Yii::t('app', 'Error while DB password changing'), - 'POST' => [ - 'save' => true, - 'success' => [ - 'class' => 'hipanel\actions\ProxyAction', - 'action' => 'view', - 'params' => function ($action, $model) { - return ['id' => $model->id]; - }, - ] - ], ], - 'truncate' => [ - 'class' => 'hipanel\actions\SwitchAction', + 'truncate' => [ + 'class' => 'hipanel\actions\SmartUpdateAction', 'success' => Yii::t('app', 'DB truncate task has been created successfully'), 'error' => Yii::t('app', 'Error while truncating DB'), - 'POST' => [ - 'save' => true, - 'success' => [ - 'class' => 'hipanel\actions\ProxyAction', - 'action' => 'view', - 'params' => function ($action, $model) { - return ['id' => $model->id]; - } - ], - ] ], 'set-description' => [ - 'class' => 'hipanel\actions\SmartUpdateAction', - 'success' => Yii::t('app', 'Description set successfully'), + 'class' => 'hipanel\actions\SmartUpdateAction', + 'success' => Yii::t('app', 'DB description set successfully'), + 'error' => Yii::t('app', 'Failed to set DB description'), + ], + 'delete' => [ + 'class' => 'hipanel\actions\SmartDeleteAction', + 'success' => Yii::t('app', 'DB delete task has been created successfully'), + 'error' => Yii::t('app', 'Error while deleting DB'), ], ]; } diff --git a/src/controllers/HdomainController.php b/src/controllers/HdomainController.php index babd8f0e..1261f1e5 100644 --- a/src/controllers/HdomainController.php +++ b/src/controllers/HdomainController.php @@ -7,7 +7,6 @@ namespace hipanel\modules\hosting\controllers; -use hipanel\helpers\ArrayHelper; use Yii; class HdomainController extends \hipanel\base\CrudController @@ -15,60 +14,26 @@ class HdomainController extends \hipanel\base\CrudController public function actions() { return [ + 'index' => [ + 'class' => 'hipanel\actions\IndexAction', + 'findOptions' => ['with_aliases' => true, 'with_vhosts' => true, 'with_request' => true] + ], + 'view' => [ + 'class' => 'hipanel\actions\ViewAction', + 'findOptions' => [ + 'with_aliases' => true, + 'with_vhosts' => true, + 'with_request' => true + ] + ], 'create' => [ - 'class' => 'hipanel\actions\SwitchAction', - 'success' => Yii::t('app', 'Account create task has been created successfully'), - 'error' => Yii::t('app', 'Error while creating account'), - 'GET html | GET pjax' => [ - 'class' => 'hipanel\actions\RenderAction', - 'view' => 'create', - 'params' => [ - 'model' => function ($action) { - return $action->controller->newModel(['scenario' => 'create']); - }, - ], - ], - 'POST html | POST pjax' => [ - 'save' => true, - 'success' => [ - 'class' => 'hipanel\actions\RedirectAction', - 'url' => function ($action, $model) { - return ['view', 'id' => $model->id]; - } - ], - 'error' => [ - 'class' => 'hipanel\actions\RenderAction', - 'view' => 'create', - 'params' => [ - 'model' => function ($action, $model) { - return $model; - }, - 'type' => 'user' - ], - ], - ], + 'class' => 'hipanel\actions\SmartCreateAction', + 'success' => Yii::t('app', 'Account create task has been created successfully'), + 'error' => Yii::t('app', 'Error while creating account'), + ], + 'validate-form' => [ + 'class' => 'hipanel\actions\ValidateFormAction', ], ]; } - - /** - * @return string - */ - public function actionIndex() - { - $searchModel = static::searchModel(); - $params = Yii::$app->request->queryParams; - $params[$searchModel->formName()] = ArrayHelper::merge($params[$searchModel->formName()], - ['with_aliases' => true, 'with_vhosts' => true, 'with_request' => true]); - $dataProvider = $searchModel->search($params); - - return $this->render('index', compact('searchModel', 'dataProvider')); - } - - public function actionView ($id) { - $model = $this->findModel(['id' => $id, 'with_aliases' => true, 'with_vhosts' => true, 'with_request' => true]); - - return $this->render('view', compact('model')); - } - } diff --git a/src/models/Account.php b/src/models/Account.php index 9787d4ff..a38890b9 100644 --- a/src/models/Account.php +++ b/src/models/Account.php @@ -41,7 +41,7 @@ public function rules() 'type', ], 'safe', - 'on' => ['create-user', 'create-ftponly'] + 'on' => ['create', 'create-ftponly'] ], [ [ @@ -52,7 +52,7 @@ public function rules() 'type', ], 'required', - 'on' => ['create-user', 'create-ftponly'] + 'on' => ['create', 'create-ftponly'] ], [ ['password'], @@ -65,32 +65,32 @@ public function rules() 'compareAttribute' => 'login', 'message' => Yii::t('app', 'Password must not be equal to login'), 'operator' => '!=', - 'on' => ['create-user', 'create-ftponly', 'update', 'set-password'], + 'on' => ['create', 'create-ftponly', 'update', 'set-password'], ], [ 'login', LoginValidator::className(), - 'on' => ['create-user', 'create-ftponly', 'set-password'] + 'on' => ['create', 'create-ftponly', 'set-password'] ], [ 'login', 'in', 'range' => ['root', 'toor'], 'not' => true, - 'on' => ['create-user', 'create-ftponly'], + 'on' => ['create', 'create-ftponly'], 'message' => Yii::t('app', 'You can not use this login') ], [ 'sshftp_ips', 'filter', 'filter' => function ($value) { return ArrayHelper::csplit($value); }, - 'on' => ['create-user', 'create-ftponly', 'update', 'set-allowed-ips'] + 'on' => ['create', 'create-ftponly', 'update', 'set-allowed-ips'] ], [ 'sshftp_ips', 'each', 'rule' => [IpValidator::className(), 'negationChar' => true, 'subnet' => null], - 'on' => ['create-user', 'create-ftponly', 'update', 'set-allowed-ips'] + 'on' => ['create', 'create-ftponly', 'update', 'set-allowed-ips'] ] ]; } @@ -142,14 +142,13 @@ public function scenarioCommands() { return [ 'set-allowed-ips' => [null, 'SetAllowedIPs'], - 'create-user' => 'create', 'create-ftponly' => 'create', ]; } public function onBeforeValidate() { - if ($this->scenario == 'create-user') { + if ($this->scenario == 'create') { $this->type = 'user'; } elseif ($this->scenario == 'create-ftponly') { $this->type = 'ftponly'; diff --git a/src/views/account/_form.php b/src/views/account/_form.php index 58ab808e..8fd119a0 100644 --- a/src/views/account/_form.php +++ b/src/views/account/_form.php @@ -6,68 +6,63 @@ use hipanel\base\View; use hipanel\modules\client\widgets\combo\ClientCombo; -use hipanel\modules\hosting\widgets\combo\AccountCombo; -use hipanel\modules\hosting\widgets\combo\DbServiceCombo; use hipanel\modules\server\widgets\combo\ServerCombo; use hipanel\widgets\PasswordInput; use yii\helpers\Html; use yii\bootstrap\ActiveForm; use yii\helpers\Url; - - -$type2action = [ - 'user' => 'create', - 'ftponly' => 'create-ftp' -]; ?> -
-
-
-
-
- isNewRecord) { - $action = Url::to(in_array($type, $model->getKnownTypes()) ? $type2action[$type] : 'create'); - } else { - $action = Url::toRoute(['update', 'id' => $model->id]); - } - $form = ActiveForm::begin(['action' => $action]); - ?> - + 'dynamic-form', + 'enableClientValidation' => true, + 'validateOnBlur' => true, + 'enableAjaxValidation' => true, + 'validationUrl' => Url::toRoute(['validate-form', 'scenario' => $model->isNewRecord ? reset($models)->scenario : 'update']), +]) ?> - field($model, 'client')->widget(ClientCombo::className()); - print $form->field($model, 'server')->widget(ServerCombo::className()); +
+ $model) { ?> +
+
+
+
+
+ isNewRecord) { + $model->setScenario('update'); + echo Html::activeHiddenInput($model, "[$i]id"); + }; + ?> - print $form->field($model, 'login'); - print $form->field($model, 'password')->widget(PasswordInput::className()); + field($model, "[$i]client")->widget(ClientCombo::className()); + print $form->field($model, "[$i]server")->widget(ServerCombo::className()); - print $form->field($model, 'sshftp_ips') - ->hint(Yii::t('app', 'Access to the account is opened by default. Please input the IPs, for which the access to the server will be granted')) - ->input('text', [ - 'data' => [ - 'title' => Yii::t('app', 'IP restrictions'), - 'content' => Yii::t('app', 'Text about IP restrictions'), - ], - 'value' => $model->getSshFtpIpsList() - ]); - ?> + print $form->field($model, "[$i]login"); + print $form->field($model, "[$i]password")->widget(PasswordInput::className()); -
- 'btn btn-primary']) ?> + print $form->field($model, "[$i]sshftp_ips")->hint(Yii::t('app', + 'Access to the account is opened by default. Please input the IPs, for which the access to the server will be granted')) + ->input('text', [ + 'data' => [ + 'title' => Yii::t('app', 'IP restrictions'), + 'content' => Yii::t('app', 'Text about IP restrictions'), + ], + 'value' => $model->getSshFtpIpsList() + ]); + ?> +
- -
- - -
+
- - 'btn btn-default']) ?> +   + 'btn btn-default', 'onclick' => 'history.go(-1)']) ?> +registerJs(" $('#account-sshftp_ips').popover({placement: 'top', trigger: 'focus'}); diff --git a/src/views/account/create.php b/src/views/account/create.php index 5e2daf6a..180a4a85 100644 --- a/src/views/account/create.php +++ b/src/views/account/create.php @@ -9,5 +9,5 @@ ?> diff --git a/src/views/account/view.php b/src/views/account/view.php index a98a528b..49a51c0c 100644 --- a/src/views/account/view.php +++ b/src/views/account/view.php @@ -22,94 +22,94 @@ params['pjax']) ?> -
-
- scenario = 'set-password'; - $form = \yii\bootstrap\ActiveForm::begin([ - 'action' => Url::toRoute(['set-password']), - 'options' => [ - 'data' => ['pjax' => 1], - 'class' => 'inline', - ] - ]); - print Html::activeHiddenInput($model, 'id'); - $this->registerJs("$('#{$form->id}').on('beforeSubmit', function (event) { +
+
+ scenario = 'set-password'; + $form = \yii\bootstrap\ActiveForm::begin([ + 'action' => Url::toRoute(['set-password']), + 'options' => [ + 'data' => ['pjax' => 1], + 'class' => 'inline', + ] + ]); + print Html::activeHiddenInput($model, 'id'); + $this->registerJs("$('#{$form->id}').on('beforeSubmit', function (event) { if ($(this).data('yiiActiveForm').validated) { return $(this).find('[type=\"submit\"]').button('loading'); } });"); - Modal::begin([ - 'toggleButton' => [ - 'label' => '  ' . Yii::t('app', 'Change password'), - 'class' => 'btn btn-default', - 'disabled' => !$model->isOperable(), - ], - 'header' => Html::tag('h4', Yii::t('app', 'Enter a new password')), - 'headerOptions' => ['class' => 'label-info'], - 'footer' => Html::submitButton(Yii::t('app', 'Change'), [ - 'class' => 'btn btn-warning', - 'data-loading-text' => Yii::t('app', 'Changing...'), - ]) - ]); - ?> -
-

-
+ Modal::begin([ + 'toggleButton' => [ + 'label' => '  ' . Yii::t('app', 'Change password'), + 'class' => 'btn btn-default', + 'disabled' => !$model->isOperable(), + ], + 'header' => Html::tag('h4', Yii::t('app', 'Enter a new password')), + 'headerOptions' => ['class' => 'label-info'], + 'footer' => Html::submitButton(Yii::t('app', 'Change'), [ + 'class' => 'btn btn-warning', + 'data-loading-text' => Yii::t('app', 'Changing...'), + ]) + ]); + ?> +
+

+
- field($model, 'password')->widget(PasswordInput::className())->label(false); - echo $form->field($model, 'login')->hiddenInput()->label(false); - Modal::end(); - $form->end(); - ?> + field($model, 'password')->widget(PasswordInput::className())->label(false); + echo $form->field($model, 'login')->hiddenInput()->label(false); + Modal::end(); + $form->end(); + ?> - scenario = 'update'; - $form = \yii\bootstrap\ActiveForm::begin([ - 'action' => Url::toRoute(['set-allowed-ips']), - 'options' => [ - 'data' => ['pjax' => 1], - 'class' => 'inline', - ], - ]); - print Html::activeHiddenInput($model, 'id'); - $this->registerJs("$('#{$form->id}').on('beforeSubmit', function (event) { + scenario = 'update'; + $form = \yii\bootstrap\ActiveForm::begin([ + 'action' => Url::toRoute(['set-allowed-ips']), + 'options' => [ + 'data' => ['pjax' => 1], + 'class' => 'inline', + ], + ]); + print Html::activeHiddenInput($model, 'id'); + $this->registerJs("$('#{$form->id}').on('beforeSubmit', function (event) { if ($(this).data('yiiActiveForm').validated) { return $(this).find('[type=\"submit\"]').button('loading'); } });"); - Modal::begin([ - 'toggleButton' => [ - 'label' => '  ' . Yii::t('app', 'Change SSH/FTP IPs'), - 'class' => 'btn btn-default', - 'disabled' => !$model->isOperable(), - ], - 'header' => Html::tag('h4', Yii::t('app', 'Enter new restrictions')), - 'headerOptions' => ['class' => 'label-info'], - 'footer' => Html::submitButton(Yii::t('app', 'Change'), [ - 'class' => 'btn btn-warning', - 'data-loading-text' => Yii::t('app', 'Changing...'), - ]) - ]); - ?> -
-

-
+ Modal::begin([ + 'toggleButton' => [ + 'label' => '  ' . Yii::t('app', 'Change SSH/FTP IPs'), + 'class' => 'btn btn-default', + 'disabled' => !$model->isOperable(), + ], + 'header' => Html::tag('h4', Yii::t('app', 'Enter new restrictions')), + 'headerOptions' => ['class' => 'label-info'], + 'footer' => Html::submitButton(Yii::t('app', 'Change'), [ + 'class' => 'btn btn-warning', + 'data-loading-text' => Yii::t('app', 'Changing...'), + ]) + ]); + ?> +
+

+
- field($model, 'sshftp_ips'); - Modal::end(); - $form->end(); - ?> + field($model, 'sshftp_ips'); + Modal::end(); + $form->end(); + ?> -   ' . Yii::t('app', 'Delete'), ['delete', 'id' => $model->id], [ - 'class' => 'btn btn-danger pull-right', - 'data' => [ - 'confirm' => Yii::t('app', 'Are you sure you want to delete this account?'), - 'method' => 'post', - ], - ]) ?> -
+   ' . Yii::t('app', 'Delete'), ['delete', 'id' => $model->id], [ + 'class' => 'btn btn-danger pull-right', + 'data' => [ + 'confirm' => Yii::t('app', 'Are you sure you want to delete this account?'), + 'method' => 'post', + ], + ]) ?>
+
diff --git a/src/views/db/_form.php b/src/views/db/_form.php index 18c004be..1b3f401a 100644 --- a/src/views/db/_form.php +++ b/src/views/db/_form.php @@ -6,50 +6,50 @@ use hipanel\base\View; use hipanel\modules\client\widgets\combo\ClientCombo; -use hipanel\modules\hosting\widgets\combo\AccountCombo; use hipanel\modules\hosting\widgets\combo\DbServiceCombo; +use hipanel\modules\hosting\widgets\combo\SshAccountCombo; use hipanel\modules\server\widgets\combo\ServerCombo; use hipanel\widgets\PasswordInput; use yii\helpers\Html; use yii\bootstrap\ActiveForm; use yii\helpers\Url; -?> -
-
-
-
-
- $model->isNewRecord ? Url::to('create') : Url::toRoute([ - 'update', - 'id' => $model->id - ]), - ]); - ?> - - - field($model, 'client')->widget(ClientCombo::className()); - print $form->field($model, 'server')->widget(ServerCombo::className()); - print $form->field($model, 'account')->widget(AccountCombo::className()); - print $form->field($model, 'service_id')->widget(DbServiceCombo::className()); - - print $form->field($model, 'name'); - print $form->field($model, 'password')->widget(PasswordInput::className()); - - print $form->field($model, 'description'); - ?> - -
- 'btn btn-primary']) ?> +$form = ActiveForm::begin([ + 'id' => 'dynamic-form', + 'enableClientValidation' => true, + 'validateOnBlur' => true, + 'enableAjaxValidation' => true, + 'validationUrl' => Url::toRoute(['validate-form', 'scenario' => $model->isNewRecord ? reset($models)->scenario : 'update']), +]) ?> + +
+ $model) { ?> +
+
+
+
+
+ field($model, "[$i]client")->widget(ClientCombo::className(), ['formElementSelector' => '.form-instance']); + print $form->field($model, "[$i]server")->widget(ServerCombo::className(), ['formElementSelector' => '.form-instance']); + print $form->field($model, "[$i]account")->widget(SshAccountCombo::className(), ['formElementSelector' => '.form-instance']); + print $form->field($model, "[$i]service_id")->widget(DbServiceCombo::className(), ['formElementSelector' => '.form-instance']); + + print $form->field($model, "[$i]name"); + print $form->field($model, "[$i]password")->widget(PasswordInput::className(), ['formElementSelector' => '.form-instance']); + + print $form->field($model, "[$i]description"); + ?> +
- -
+ +
- - -
-
\ No newline at end of file + +
+ 'btn btn-default']) ?> +   + 'btn btn-default', 'onclick' => 'history.go(-1)']) ?> +title = Yii::t('app', 'Create database'); -$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Databases'), 'url' => ['index']]; -$this->params['breadcrumbs'][] = $this->title; +$this->breadcrumbs->setItems([['label' => Yii::t('app', 'Databases'), 'url' => ['index']]]); +$this->breadcrumbs->setItems([$this->title]); ?>
- render('_form', compact('model')) ?> + render('_form', compact('models')) ?>
diff --git a/src/views/db/index.php b/src/views/db/index.php index eff62bdf..1fca9aa9 100644 --- a/src/views/db/index.php +++ b/src/views/db/index.php @@ -2,19 +2,33 @@ use hipanel\modules\hosting\grid\DbGridView; use hipanel\widgets\ActionBox; +use hipanel\widgets\LinkSorter; use hipanel\widgets\Pjax; use yii\helpers\Html; +use yii\helpers\Url; $this->title = Yii::t('app', 'Databases'); -$this->params['breadcrumbs'][] = $this->title; -$this->params['subtitle'] = Yii::$app->request->queryParams ? 'filtered list' : 'full list'; +$this->breadcrumbs->setItems([$this->title]); +$this->params['subtitle'] = Yii::$app->request->queryParams ? 'filtered list' : 'full list'; Pjax::begin(array_merge(Yii::$app->params['pjax'], ['enablePushState' => true])); -$box = ActionBox::begin(['options' => ['class' => 'box-info']]); +echo Html::beginForm(); +$box = ActionBox::begin(['bulk' => true, 'options' => ['class' => 'box-info']]); $box->beginActions(); echo Html::a(Yii::t('app', 'Create {modelClass}', ['modelClass' => 'DB']), ['create'], ['class' => 'btn btn-success']) . ' '; +echo LinkSorter::widget([ + 'show' => true, + 'sort' => $dataProvider->getSort(), + 'attributes' => [ + 'client', 'account', 'server', 'name', 'description', 'state' + ], +]); $box->endActions(); + +$box->beginBulkActions(); +echo Html::submitButton(Yii::t('app', 'Delete'), ['class' => 'btn btn-danger', 'formmethod' => 'POST', 'formaction' => Url::to('delete')]); +$box->endBulkActions(); $box::end(); echo DbGridView::widget([ diff --git a/src/views/hdomain/_form.php b/src/views/hdomain/_form.php index e628790f..daa19937 100644 --- a/src/views/hdomain/_form.php +++ b/src/views/hdomain/_form.php @@ -7,7 +7,7 @@ use hipanel\base\View; use hipanel\models\Ref; use hipanel\modules\client\widgets\combo\ClientCombo; -use hipanel\modules\hosting\widgets\combo\AccountCombo; +use hipanel\modules\hosting\widgets\combo\SshAccountCombo; use hipanel\modules\hosting\widgets\ip\BackIpCombo; use hipanel\modules\hosting\widgets\ip\FrontIpCombo; use hipanel\modules\hosting\widgets\ip\HdomainIpCombo; @@ -19,20 +19,20 @@ use yii\web\JsExpression; $this->registerJs(<<<'JS' - $('.hdomain-create').on('change', '#hdomain-proxy_enable', function () { + $('#dynamic-form').on('change', '.proxy_enable', function () { var $checkbox = $(this); - var $scope = $(this).closest('form'); - var $proxied = $scope.find('.field-hdomain-frontend_ip, .field-hdomain-backend_ip'); - var $not_proxied = $scope.find('.field-hdomain-not-proxied_ip'); + var $scope = $(this).closest('.form-instance'); + var $proxied = $scope.find(".frontend_ip, .backend_ip"); + var $not_proxied = $scope.find(".not-proxied-ip"); if ($checkbox.prop('checked')) { $proxied.removeClass('hidden'); $not_proxied.addClass('hidden'); - $scope.find('#hdomain-account').trigger('change'); + $scope.find('input[data-field=account]').trigger('change'); } else { $proxied.addClass('hidden').find('input').select2('enable', false); $not_proxied.removeClass('hidden'); - $scope.find('#hdomain-account').trigger('change'); + $scope.find('input[data-field=account]').trigger('change'); } }); JS @@ -68,8 +68,8 @@ }); */ - $('.hdomain-create').find('.field-hdomain-path').on('updatePath', function (e, update) { - var $group = $(this); + $('#dynamic-form').find('input[data-field=path]').on('updatePath', function (e, update) { + var $group = $(this).closest('.form-group'); var $input = $group.find('input'); var $span = $group.find('span'); @@ -78,122 +78,132 @@ if (update.clear) $span.val(''); }); - $('.hdomain-create').on('keyup keypress blur change', '.field-hdomain-domain input', function () { - var $scope = $(this).closest('form'); - $scope.find('.field-hdomain-path').trigger('updatePath', {domain: $(this).val()}); + $('#dynamic-form').on('keyup keypress blur change', 'input[data-field=domain]', function () { + var $scope = $(this).closest('.form-instance'); + $scope.find("input[data-field=path]").trigger('updatePath', {domain: $(this).val()}); }); JS ); -?> -
-
-
-
-
- $model->isNewRecord ? Url::to('create') : Url::toRoute([ - 'update', - 'id' => $model->id - ]), - 'options' => ['class' => 'hdomain-create'] - ]); - ?> - - - field($model, 'client')->widget(ClientCombo::className()); - print $form->field($model, 'server')->widget(ServerCombo::className()); - print $form->field($model, 'account')->widget(AccountCombo::className(), [ - 'pluginOptions' => [ - 'onChange' => new \yii\web\JsExpression(<<<'JS' - function (event) { - var $form = event.element.closest('form'); - var data; - if (event.added) { - data = {account: event.added.text}; - } else { - data = {clear: true}; - } - $form.find('.field-hdomain-path').trigger('updatePath', data); - return true; - } + +$form = ActiveForm::begin([ + 'id' => 'dynamic-form', + 'enableClientValidation' => true, + 'validateOnBlur' => true, + 'enableAjaxValidation' => true, + 'validationUrl' => Url::toRoute(['validate-form', 'scenario' => $model->isNewRecord ? reset($models)->scenario : 'update']), +]) ?> + +
+ $model) { ?> +
+
+
+
+
+ field($model, "[$i]client") + ->widget(ClientCombo::className(), ['formElementSelector' => '.form-instance']); + print $form->field($model, "[$i]server") + ->widget(ServerCombo::className(), ['formElementSelector' => '.form-instance']); + print $form->field($model, "[$i]account")->widget(SshAccountCombo::className(), [ + 'formElementSelector' => '.form-instance', + 'inputOptions' => [ + 'data-field' => 'account' + ], + 'pluginOptions' => [ + 'onChange' => new \yii\web\JsExpression(<<<'JS' + function (event) { + var $form = event.element.closest('.form-instance'); + var data; + if (event.added) { + data = {account: event.added.text}; + } else { + data = {clear: true}; + } + $form.find('input[data-field=path]').trigger('updatePath', data); + return true; + } JS - ) - ] - ]); - print $form->field($model, 'domain'); - print $form->field($model, 'path', [ - 'template' => ' - {label} -
- /home/ - {input} - {hint} - {error} -
- ' - ]); - print $form->field($model, 'with_www')->checkbox(); - - print $form->field($model, 'proxy_enable')->checkbox(); - - print $form->field($model, 'ip', ['options' => ['class' => 'field-hdomain-not-proxied_ip']]) - ->widget(HdomainIpCombo::className(), [ - 'pluginOptions' => [ - 'activeWhen' => [ - new JsExpression("function (self) { - return !self.form.find('#hdomain-proxy_enable').prop('checked'); - }") - ] - ] - ]); - - print $form->field($model, 'ip', ['options' => ['class' => 'field-hdomain-frontend_ip hidden']]) - ->widget(FrontIpCombo::className(), [ - 'inputOptions' => [ - 'id' => 'hdomain-frontend_ip', - ], - 'pluginOptions' => [ - 'activeWhen' => [ - new JsExpression("function (self) { - return self.form.find('#hdomain-proxy_enable').prop('checked'); - }") - ] - ] - ])->label('Frontend IP'); - - print $form->field($model, 'backend_ip', [ - 'options' => [ - 'class' => 'field-hdomain-frontend_ip hidden', - ] - ])->widget(BackIpCombo::className(), [ - 'pluginOptions' => [ - 'activeWhen' => [ - new JsExpression("function (self) { - return self.form.find('#hdomain-proxy_enable').prop('checked'); - }") - ] - ] - ]); - - - print $form->field($model, 'backuping_type')->widget(StaticCombo::className(), [ - 'hasId' => true, - 'data' => Ref::getList('type,backuping') - ]); - ?> -
- 'btn btn-primary']) ?> + ) + ], + ]); + print $form->field($model, "[$i]domain")->input('text', ['data-field' => 'domain']); + print $form->field($model, "[$i]path", [ + 'inputOptions' => [ + 'data-field' => 'path' + ], + 'template' => '{label} +
+ /home/ + {input} + {hint} + {error} +
', + ]); + print $form->field($model, "[$i]with_www")->checkbox(); + + print $form->field($model, "[$i]proxy_enable")->checkbox([ + 'class' => 'proxy_enable' + ]); + + print $form->field($model, "[$i]ip", ['options' => ['class' => 'not-proxied-ip']]) + ->widget(HdomainIpCombo::className(), [ + 'formElementSelector' => '.form-instance', + 'pluginOptions' => [ + 'activeWhen' => [ + new JsExpression("function (self) { + return !self.form.find('.proxy_enable').prop('checked'); + }") + ] + ] + ]); + + print $form->field($model, "[$i]ip", ['options' => ['class' => 'hidden frontend_ip']]) + ->widget(FrontIpCombo::className(), [ + 'formElementSelector' => '.form-instance', + 'inputOptions' => [ + 'data-field' => 'frontend_ip', + ], + 'pluginOptions' => [ + 'activeWhen' => [ + new JsExpression("function (self) { + return self.form.find('.proxy_enable').prop('checked'); + }") + ] + ], + ])->label('Frontend IP'); + + print $form->field($model, "[$i]backend_ip", ['options' => ['class' => 'hidden backend_ip']]) + ->widget(BackIpCombo::className(), [ + 'formElementSelector' => '.form-instance', + 'inputOptions' => [ + 'data-field' => 'backend_ip', + ], + 'pluginOptions' => [ + 'activeWhen' => [ + new JsExpression("function (self) { + return self.form.find('.proxy_enable').prop('checked'); + }") + ] + ], + ]); + + print $form->field($model, "[$i]backuping_type")->widget(StaticCombo::className(), [ + 'formElementSelector' => '.form-instance', + 'hasId' => true, + 'data' => Ref::getList('type,backuping'), + ]); + ?> +
+
- -
-
- - +
-
+ 'btn btn-default']) ?> +   + 'btn btn-default', 'onclick' => 'history.go(-1)']) ?> +registerJs("$('#hdomain-proxy_enable').trigger('change');"); \ No newline at end of file +//$this->registerJs("$('#hdomain-proxy_enable').trigger('change');"); \ No newline at end of file diff --git a/src/views/hdomain/create.php b/src/views/hdomain/create.php index 275fae0c..54abbc08 100644 --- a/src/views/hdomain/create.php +++ b/src/views/hdomain/create.php @@ -3,11 +3,11 @@ /* @var $model hipanel\modules\ticket\models\Thread */ /* @var $type string */ -$this->title = Yii::t('app', 'Create domain'); -$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Domains'), 'url' => ['index']]; -$this->params['breadcrumbs'][] = $this->title; +$this->title = Yii::t('app', 'Create domain'); +$this->breadcrumbs->setItems([['label' => Yii::t('app', 'Databases'), 'url' => ['index']]]); +$this->breadcrumbs->setItems([$this->title]); ?>
- render('_form', compact('model')) ?> + render('_form', compact('models')) ?>
diff --git a/src/widgets/combo/AccountCombo.php b/src/widgets/combo/AccountCombo.php index 08a14cce..1c77fc13 100644 --- a/src/widgets/combo/AccountCombo.php +++ b/src/widgets/combo/AccountCombo.php @@ -25,13 +25,26 @@ class AccountCombo extends Combo /** @inheritdoc */ public $_rename = ['text' => 'login']; + /** + * @var string the type of client + * Used by [[getFilter]] to generate filter + * + * @see getFilter() + */ + public $accountType; + /** @inheritdoc */ - public $_filter = [ - 'client' => 'client/client', - 'server' => 'server/server', - ]; + public function getFilter() + { + return ArrayHelper::merge(parent::getFilter(), [ + 'client' => 'client/client', + 'server' => 'server/server', + 'type' => ['format' => $this->accountType], + ]); + } - public function getPluginOptions($config) { + public function getPluginOptions($config) + { return parent::getPluginOptions([ 'clearWhen' => ['client/client', 'server/server'], 'affects' => [ diff --git a/src/widgets/combo/SshAccountCombo.php b/src/widgets/combo/SshAccountCombo.php new file mode 100644 index 00000000..f9a64fe4 --- /dev/null +++ b/src/widgets/combo/SshAccountCombo.php @@ -0,0 +1,15 @@ +