diff --git a/src/controllers/HdomainController.php b/src/controllers/HdomainController.php index b723f117..2bff603b 100644 --- a/src/controllers/HdomainController.php +++ b/src/controllers/HdomainController.php @@ -61,6 +61,17 @@ public function actions() 'class' => 'hipanel\actions\SmartPerformAction', 'success' => Yii::t('app', 'Premium autorenewal has been disabled'), ], + 'delete' => [ + 'class' => 'hipanel\actions\SmartDeleteAction', + 'success' => Yii::t('app', 'Domain delete task has been created successfully'), + 'error' => Yii::t('app', 'Error while deleting domain'), + ], + 'delete-alias' => [ + 'class' => 'hipanel\actions\SmartDeleteAction', + 'scenario' => 'delete', + 'success' => Yii::t('app', 'Alias delete task has been created successfully'), + 'error' => Yii::t('app', 'Error while deleting alias'), + ] ]; } diff --git a/src/models/Hdomain.php b/src/models/Hdomain.php index de6a269e..34ed3ff8 100644 --- a/src/models/Hdomain.php +++ b/src/models/Hdomain.php @@ -12,6 +12,7 @@ use hipanel\modules\hosting\validators\LoginValidator as AccountLoginValidator; use hipanel\validators\IpValidator; use Yii; +use yii\web\JsExpression; class Hdomain extends \hipanel\base\Model { @@ -27,7 +28,6 @@ class Hdomain extends \hipanel\base\Model */ public $aliases; - /** @inheritdoc */ public function rules() { @@ -56,6 +56,7 @@ public function rules() 'type', 'backuping_type', 'state_label', + 'alias_type', ], 'safe' ], @@ -78,24 +79,40 @@ public function rules() 'on' => ['create'] ], [ - ['sub'], + ['subdomain'], 'match', 'pattern' => '/^(\*|[a-z0-9][a-z0-9-]*)$/i', 'message' => \Yii::t('app', '{attribute} does not look like a domain part'), 'on' => ['create-alias'] ], - [ [ 'server', 'account', 'vhost_id', - 'domain', 'with_www', ], 'required', 'on' => ['create-alias'] ], + [ + [ + 'domain', + ], + 'required', + 'when' => function ($model) { + return $model->alias_type === 'new'; + }, + 'whenClient' => new JsExpression("function (attribute, value) { + return false; + }"), + 'on' => ['create-alias'] + ], + [ + ['id'], + 'required', + 'on' => ['delete'] + ] ]; } diff --git a/src/views/db/view.php b/src/views/db/view.php index 6fdda5c3..1a3bd3c3 100644 --- a/src/views/db/view.php +++ b/src/views/db/view.php @@ -91,7 +91,7 @@
  • $model, - 'scenario' => 'truncate', + 'scenario' => 'delete', 'button' => [ 'label' => '' . Yii::t('app', 'Delete'), ], diff --git a/src/views/hdomain/_form-alias.php b/src/views/hdomain/_form-alias.php index b448e48b..10b57311 100644 --- a/src/views/hdomain/_form-alias.php +++ b/src/views/hdomain/_form-alias.php @@ -21,7 +21,7 @@ 'enableClientValidation' => true, 'validateOnBlur' => true, 'enableAjaxValidation' => true, - 'validationUrl' => Url::toRoute(['validate-form', 'scenario' => $model->isNewRecord ? $model->scenario : 'update']), + 'validationUrl' => Url::toRoute(['validate-form', 'scenario' => $model->scenario]), ]); ?>
    @@ -42,22 +42,22 @@ ]); print $form->field($model, "[$i]vhost_id")->widget(VhostCombo::className(), ['formElementSelector' => '.form-instance']); - print Html::label(Yii::t('app', 'Domain') - . '
    ' . Html::radio("[$i]vhost_type", true, [ + $model->alias_type = 'subdomain'; + print $form->field($model, "[$i]alias_type")->radio([ 'value' => 'subdomain', - 'class' => 'vhost-type', - 'label' => Yii::t('app', 'Subdomain of existing domain') - ]) - . '
    ' . Html::radio("[$i]vhost_type", false, [ + 'class' => 'alias-type', + 'label' => Yii::t('app', 'Subdomain of existing domain'), + ]); + print $form->field($model, "[$i]alias_type")->radio([ + 'id' => $model->formName() . '-' . $i . '-alias_type-new', 'value' => 'new', - 'class' => 'vhost-type', + 'class' => 'alias-type', 'label' => Yii::t('app', 'New domain') - ]) - ); + ]); ?> -
    - field($model, "[$i]sub")->input('text', ['data-field' => 'sub'])->label(false) ?> +
    + field($model, "[$i]subdomain")->input('text', ['data-field' => 'subdomain'])->label(false) ?> field($model, "[$i]dns_hdomain_id")->widget(HdomainCombo::className(), [ 'formElementSelector' => '.form-instance', @@ -71,10 +71,17 @@ ") ] ])->label(false) ?> - field($model, "[$i]domain")->hiddenInput(['data-field' => 'sub-with-domain'])->label(false) ?> + field($model, "[$i]domain")->hiddenInput([ + 'id' => $model->formName() . '-' . $i . '-domain-sub', + 'data-field' => 'sub-with-domain' + ])->label(false) ?>
    -
    - field($model, "[$i]domain")->input('text', ['data-field' => 'domain', 'disabled' => true, 'class' => 'form-control collapse'])->label(false) ?> +
    + field($model, "[$i]domain")->input('text', [ + 'data-field' => 'domain', + 'disabled' => true, + 'class' => 'form-control collapse' + ])->label(false) ?>
    field($model, "[$i]with_www")->checkbox() ?>
    @@ -90,11 +97,11 @@ registerJs(<<<'JS' - $(this).on('change', '.vhost-type', function (e) { + $(this).on('change', '.alias-type', function (e) { var $form = $(this).closest('.form-instance'); - var $sub_inputs = $form.find('.vhost-subdomain, input[data-field="sub"], input[data-field="sub-with-domain"]'); - var $new_inputs = $form.find('.vhost-newdomain, input[data-field="domain"]'); + var $sub_inputs = $form.find('.alias-subdomain, input[data-field="subdomain"], input[data-field="sub-with-domain"]'); + var $new_inputs = $form.find('.alias-newdomain, input[data-field="domain"]'); if ($(this).attr('value') == 'subdomain') { $sub_inputs.show().prop('disabled', false); @@ -107,17 +114,17 @@ $('#dynamic-form').on('update', 'input[data-field="sub-with-domain"]', function (event) { var $form = $(this).closest('.form-instance'); - var sub = $form.find('input[data-field="sub"]').val(); + var subdomain = $form.find('input[data-field="subdomain"]').val(); var domain = $form.find('input[data-field="dns_hdomain_id"]').select2('data'); var value = ''; if (domain && domain.text) { - value = sub + '.' + domain.text; + value = (subdomain.length > 0 ? (subdomain + '.') : '') + domain.text; } $(this).val(value).trigger('change'); }); - $('#dynamic-form').on('change', 'input[data-field="sub"]', function () { + $('#dynamic-form').on('change', 'input[data-field="subdomain"]', function () { var $form = $(this).closest('.form-instance'); $form.find('input[data-field="sub-with-domain"]').trigger('update'); }); diff --git a/src/views/hdomain/view.php b/src/views/hdomain/view.php index a2c76cf9..a1da953e 100644 --- a/src/views/hdomain/view.php +++ b/src/views/hdomain/view.php @@ -1,9 +1,11 @@ title = $model->domain; $this->subtitle = Yii::t('app', 'hosting domain detailed information') . ' #' . $model->id; @@ -35,34 +37,26 @@
    @@ -90,7 +84,51 @@ 'ip', 'state', 'dns_on', - 'aliases', + [ + 'attribute' => 'aliases', + 'format' => 'raw', + 'value' => function ($model) { + $html = []; + foreach ((array)$model->getAttribute('aliases') as $id => $alias) { + $aliasModel = Yii::createObject([ + 'class' => Hdomain::className(), + 'id' => $id, + 'domain' => $alias + ]); + $item = Html::a($aliasModel->domain, ['view', 'id' => $aliasModel->id]) . ' '; + $item .= ModalButton::widget([ + 'model' => $aliasModel, + 'scenario' => 'delete-alias', + 'submit' => ModalButton::SUBMIT_AJAX, + 'button' => [ + 'label' => '', + ], + 'modal' => [ + 'header' => Html::tag('h4', Yii::t('app', 'Confirm alias deleting')), + 'headerOptions' => ['class' => 'label-info'], + 'footer' => [ + 'label' => Yii::t('app', 'Delete alias'), + 'data-loading-text' => Yii::t('app', 'Deleting alias...'), + 'class' => 'btn btn-danger', + ] + ], + 'body' => Yii::t('app', + 'Are you sure, that you want to delete alias {name}?', + ['name' => $aliasModel->domain] + ), + 'ajaxOptions' => [ + 'success' => new JsExpression(" + function (data) { + form.closest('.alias-item').remove(); + } + ") + ] + ]); + $html[] = Html::tag('div', $item, ['class' => 'alias-item']); + } + return implode("\n", $html); + } + ] ], ]); $box->endBody();