Skip to content

Commit

Permalink
Mail update implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverFire committed Nov 14, 2015
1 parent 906b9c1 commit 2de8ba1
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 54 deletions.
6 changes: 6 additions & 0 deletions src/controllers/MailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@ public function actions() {
];
}
],
'view' => [
'class' => 'hipanel\actions\ViewAction'
],
'create' => [
'class' => 'hipanel\actions\SmartCreateAction',
'success' => Yii::t('app', 'Mailbox creating task has been added to queue'),
'error' => Yii::t('app', 'An error occurred when trying to create mailbox')
],
'update' => [
'class' => 'hipanel\actions\SmartUpdateAction'
],
'validate-form' => [
'class' => 'hipanel\actions\ValidateFormAction',
],
Expand Down
7 changes: 6 additions & 1 deletion src/grid/MailGridView.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static public function defaultColumns()
},
'gtype' => 'state,mail',
],
'server' => [
'server_id' => [
'class' => ServerColumn::className()
],
// 'sshftp_ips' => [
Expand Down Expand Up @@ -76,6 +76,11 @@ static public function defaultColumns()
]);
}
],
'spam_action' => [
'value' => function ($model) {
return $model->spam_action; // TODO
}
],
'actions' => [
'class' => ActionColumn::className(),
'template' => '{view} {delete}'
Expand Down
29 changes: 21 additions & 8 deletions src/models/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,35 @@

class Mail extends \hipanel\base\Model
{

use \hipanel\base\ModelTrait;

const TYPE_FORWARD_ONLY = 'forward_only';
const TYPE_BOX_WITH_FORWARDS = 'mailbox_with_forwards';
const TYPE_MAILBOX = 'mailbox';

/** @inheritdoc */
public function rules()
{
return [
[['id', 'hdomain_id', 'client_id', 'seller_id', 'account_id', 'server_id'], 'integer'],
[['id', 'client_id', 'seller_id', 'account_id', 'server_id'], 'integer'],
[['mail', 'nick', 'hdomain', 'client', 'seller', 'account', 'server', 'domain'], 'safe'],
[['type', 'state', 'state_label', 'password', 'spam_forward_mail'], 'safe'],
[['forwards', 'spam_action', 'autoanswer', 'du_limit'], 'safe'],
[['is_alias'], 'boolean'],
[['server', 'account', 'password'], 'safe', 'on' => ['create', 'update']],
[['nick'], EmailLocalPartValidator::className(), 'on' => ['create', 'update']],
[['server', 'account'], 'safe', 'on' => ['create', 'update']],
[['hdomain_id'], 'integer', 'on' => ['create']],
[['server', 'account'], 'safe', 'on' => ['create']],
[['password'], 'safe', 'on' => ['create']],
[['password'], 'safe', 'on' => ['update'], 'when' => function ($model) {
return !$model->is_alias;
}],
[['nick'], EmailLocalPartValidator::className(), 'on' => ['create']],
[['forwards', 'spam_forward_mail'], 'filter', 'filter' => function ($value) {
$res = StringHelper::explode($value, ',', true, true);
return $res;
}, 'skipOnArray' => true, 'on' => ['create', 'update']],
[['forwards', 'spam_forward_mail'], 'each', 'rule' => ['email'], 'on' => ['create', 'update']],
[['spam_action'], 'safe', 'on' => ['create', 'update']],
[['autoanswer'], 'safe', 'on' => ['create', 'update']],
[['spam_action', 'autoanswer', 'du_limit'], 'safe', 'on' => ['create', 'update']],
[['id'], 'required', 'on' => ['update', 'delete']],
[['hdomain_id', 'server', 'account', 'nick'], 'required', 'on' => ['create']],
];
}

Expand All @@ -55,6 +62,12 @@ public function attributeLabels()
public function attributeHints() {
return [
'forwards' => Yii::t('app', 'All messages will be forwarded on the specified addresses. You can select email from the list of existing or wright down your own.'),
'password' => $this->type === static::TYPE_FORWARD_ONLY
? Yii::t('app', 'Password change is prohibited on forward-only mailboxes')
: ( $this->isNewRecord
? Yii::t('app', 'Leave this field empty to create a forward-only mailbox')
: Yii::t('app', 'Fill this field only if you want to change the password')
),
];
}
}
8 changes: 4 additions & 4 deletions src/views/db/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
'columns' => [
'checkbox',
'name',
'account',
'server',
'client',
'seller',
'account_id',
'server_id',
'client_id',
'seller_id',
'description',
'state',
'actions'
Expand Down
52 changes: 38 additions & 14 deletions src/views/mail/_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,41 @@

<?php
if (Yii::$app->user->can('support')) {
print $form->field($model, "[$i]client")->widget(ClientCombo::className(),
['formElementSelector' => '.form-instance']);
print $form->field($model, "[$i]client")->widget(ClientCombo::className(), [
'formElementSelector' => '.form-instance',
'inputOptions' => [
'readonly' => !$model->isNewRecord
]
]);
}

print $form->field($model, "[$i]server")->widget(ServerCombo::className(),
['formElementSelector' => '.form-instance']);
print $form->field($model, "[$i]server")->widget(ServerCombo::className(), [
'formElementSelector' => '.form-instance',
'inputOptions' => [
'readonly' => !$model->isNewRecord
]
]);

print $form->field($model, "[$i]account")->widget(SshAccountCombo::className(),
['formElementSelector' => '.form-instance']);
print $form->field($model, "[$i]account")->widget(SshAccountCombo::className(),[
'formElementSelector' => '.form-instance',
'inputOptions' => [
'readonly' => !$model->isNewRecord
]
]);

print Html::label(Yii::t('app', 'E-mail'), Html::getInputId($model, "[$i]nick"));
?>
<div class="form-inline">
<?= $form->field($model, "[$i]nick")->input('text',
['data-field' => 'nick'])->label(false) ?>
<?= $form->field($model, "[$i]nick")->input('text', [
'data-field' => 'nick',
'readonly' => !$model->isNewRecord
])->label(false) ?>
<?= Html::tag('span', '@') ?>
<?= $form->field($model, "[$i]hdomain_id")->widget(VhostCombo::className(), [
'formElementSelector' => '.form-instance',
'inputOptions' => [
'data-field' => 'dns_hdomain_id',
'readonly' => !$model->isNewRecord
],
'pluginOptions' => [
'select2Options' => [
Expand All @@ -76,18 +91,27 @@
</div>

<?php
print $form->field($model, "[$i]password")->widget(PasswordInput::className());
print $form->field($model, "[$i]password")->widget(PasswordInput::className(), [
'inputOptions' => [
'disabled' => $model->type === $model::TYPE_FORWARD_ONLY
]
]);

if ($model->spam_action !== '' && $model->spam_action !== 'delete') {
$model->spam_forward_mail = $model->spam_action;
$model->spam_action = 'forward';
}

print $form->field($model, "[$i]spam_action")->radioList([
'' => Yii::t('app', 'Do nothing'),
'remove' => Yii::t('app', 'Remove'),
'delete' => Yii::t('app', 'Delete'),
'forward' => Yii::t('app', 'Forward to'),
], [
'class' => 'spam-action'
'class' => 'spam-action',
]);
print $form->field($model, "[$i]spam_forward_mail", [
'options' => [
'style' => 'display: none'
'style' => $model->spam_action !== 'forward' ? 'display: none' : ''
]
])->widget(MultipleMailCombo::className(), [
'type' => 'hosting/spam-forward',
Expand Down Expand Up @@ -151,9 +175,9 @@ function (combo) {
$forwardInput = $form.find('input[data-attribute=spam_forward_mail]');
if ($(this).find('input[type=radio]:checked').val() == 'forward') {
$forwardInput.trigger('change').parent().show();
$forwardInput.trigger({type: 'change', 'force': true}).parent().show();
} else {
$forwardInput.trigger('change').parent().hide();
$forwardInput.trigger({type: 'change', 'force': true}).parent().hide();
}
});
JS
Expand Down
15 changes: 15 additions & 0 deletions src/views/mail/update.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/* @var $this yii\web\View */
/* @var $model hipanel\modules\hosting\models\Mail */
/* @var $type string */

$this->title = Yii::t('app', 'Mailbox editing');
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Mailboxes'), 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->mail, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = $this->title;

?>

<div class="mailbox-update">
<?= $this->render('_form', compact('models')) ?>
</div>
106 changes: 85 additions & 21 deletions src/views/mail/view.php
Original file line number Diff line number Diff line change
@@ -1,32 +1,96 @@
<?php
/**
* @link http://hiqdev.com/hipanel-module-hosting
* @license http://hiqdev.com/hipanel-module-hosting/license
* @copyright Copyright (c) 2015 HiQDev
*/

use hipanel\modules\hosting\grid\DbGridView;
use hipanel\modules\hosting\grid\MailGridView;
use hipanel\widgets\Pjax;
use hipanel\widgets\Box;
use hipanel\widgets\ModalButton;
use hipanel\widgets\PasswordInput;
use yii\bootstrap\Modal;
use yii\helpers\Html;

$this->title = Html::encode($model->domain);
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Domains'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;

$this->title = $model->mail;
$this->subtitle = Yii::t('app', 'Mailbox detailed information') . ' #' . $model->id;
$this->breadcrumbs->setItems([
['label' => Yii::t('app', 'Mailboxes'), 'url' => ['index']],
$this->title,
]);
?>

<? Pjax::begin(Yii::$app->params['pjax']) ?>
<div class="row">
<div class="col-md-3">
<?php Box::begin([
'options' => [
'class' => 'box-solid',
],
'bodyOptions' => [
'class' => 'no-padding'
]
]); ?>
<div class="profile-user-img text-center">
<i class="fa fa-database fa-5x"></i>
</div>
<p class="text-center">
<span class="profile-user-role"><?= $model->mail ?></span>
<br>
<span class="profile-user-name"><?= $model->client . ' / ' . $model->seller; ?></span>
</p>

<div class="col-md-4">
<?= MailGridView::detailView([
'model' => $model,
'columns' => [
'seller_id','client_id',
['attribute' => 'mail'],
],
]) ?>
</div>
<div class="profile-usermenu">
<ul class="nav">
<li><?= Html::a('<i class="fa fa-pencil"></i>' . Yii::t('app', 'Edit'), ['update', 'id' => $model->id]) ?></li>
<li>
<?= ModalButton::widget([
'model' => $model,
'scenario' => 'delete',
'button' => [
'label' => '<i class="fa fa-trash-o"></i>' . Yii::t('app', 'Delete'),
],
'modal' => [
'header' => Html::tag('h4', Yii::t('app', 'Confirm database deleting')),
'headerOptions' => ['class' => 'label-info'],
'footer' => [
'label' => Yii::t('app', 'Delete database'),
'data-loading-text' => Yii::t('app', 'Deleting database...'),
'class' => 'btn btn-danger',
]
],
'body' => Yii::t('app',
'Are you sure, that you want to delete database {name}? All tables will be dropped, all data will be lost.',
['name' => $model->mail]
)
]) ?>
</li>
</ul>
</div>
<?php Box::end(); ?>
</div>

<div class="col-md-9">
<div class="row">
<div class="col-md-6">
<?php
$box = Box::begin(['renderBody' => false]);
$box->beginHeader();
echo $box->renderTitle(Yii::t('app', 'Mailbox information'));
$box->endHeader();
$box->beginBody();
echo MailGridView::detailView([
'boxed' => false,
'model' => $model,
'columns' => [
'client_id',
'seller_id',
'server_id',
'forwards',
'spam_action',
'state',
'type',
],
]);
$box->endBody();
$box->end();
?>
</div>
</div>
</div>
</div>
<?php Pjax::end() ?>
4 changes: 3 additions & 1 deletion src/widgets/combo/VhostCombo.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class VhostCombo extends Combo
/** @inheritdoc */
public $_rename = ['text' => 'domain'];

public $activeWhen = ['server/server', 'hosting/account'];

/** @inheritdoc */
public function getFilter()
{
Expand All @@ -41,7 +43,7 @@ public function getPluginOptions($options = [])
{
return parent::getPluginOptions([
'clearWhen' => ['server/server'],
'activeWhen' => ['server/server', 'hosting/account'],
'activeWhen' => $this->activeWhen,
'select2Options' => [
'formatResult' => new JsExpression("function (data) {
return data.domain + '<br><small>' + data.service + ' - ' + data.ip + ':' + data.port + '</small>';
Expand Down
Loading

0 comments on commit 2de8ba1

Please sign in to comment.