Skip to content

Commit

Permalink
Continue Mail implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverFire committed Nov 12, 2015
1 parent b3b6fd3 commit 33b1c5b
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 5 deletions.
14 changes: 13 additions & 1 deletion src/controllers/MailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@
namespace hipanel\modules\hosting\controllers;

use hipanel\models\Ref;
use Yii;

class MailController extends \hipanel\base\CrudController
{
public function actions() {
return [
'search' => [
'class' => 'hipanel\actions\SearchAction'
],
'index' => [
'class' => 'hipanel\actions\IndexAction',
'data' => function ($action) {
Expand All @@ -21,7 +25,15 @@ public function actions() {
'typeData' => $action->controller->getTypeData(),
];
}
]
],
'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')
],
'validate-form' => [
'class' => 'hipanel\actions\ValidateFormAction',
],
];
}

Expand Down
12 changes: 11 additions & 1 deletion src/grid/MailGridView.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use hipanel\modules\server\grid\ServerColumn;
use hipanel\widgets\ArraySpoiler;
use Yii;
use yii\helpers\StringHelper;
use yii\helpers\Html;

class MailGridView extends \hipanel\grid\BoxedGridView
{
Expand Down Expand Up @@ -49,6 +49,16 @@ static public function defaultColumns()
// ],
'type' => [
'format' => 'raw',
'filter' => function ($column, $model, $attribute) {
return Html::activeDropDownList($model, $attribute, [
'' => Yii::t('app', '---'),
'mailbox' => Yii::t('app', 'Mailbox'),
'forward_only' => Yii::t('app', 'Forward only'),
'mailbox_with_forwards' => Yii::t('app', 'Mailbox with forwards'),
], [
'class' => 'form-control',
]);
},
'value' => function ($model) {
return Type::widget(compact('model'));
}
Expand Down
2 changes: 1 addition & 1 deletion src/models/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function rules()
return [
[['id', 'hdomain_id', 'client_id', 'seller_id', 'account_id', 'server_id'], 'integer'],
[['mail', 'nick', 'hdomain', 'client', 'seller', 'account', 'server', 'domain'], 'safe'],
[['type', 'state', 'state_label'], 'safe'],
[['type', 'state', 'state_label', 'password', 'spam_forward_mail'], 'safe'],
[['forwards', 'spam_action', 'autoanswer', 'du_limit'], 'safe'],
[['is_alias'], 'boolean'],
];
Expand Down
107 changes: 107 additions & 0 deletions src/views/mail/_form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

/* @var $this View */
/* @var $model hipanel\modules\hosting\models\Mail */
/* @var $type string */

use hipanel\base\View;
use hipanel\modules\client\widgets\combo\ClientCombo;
use hipanel\modules\hosting\widgets\combo\HdomainCombo;
use hipanel\modules\hosting\widgets\combo\MailCombo;
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;
use yii\web\JsExpression;

?>

<?php $form = ActiveForm::begin([
'id' => 'dynamic-form',
'enableAjaxValidation' => true,
'validationUrl' => Url::toRoute([
'validate-form',
'scenario' => $model->isNewRecord ? reset($models)->scenario : 'update'
]),
]) ?>

<div class="container-items"><!-- widgetContainer -->
<?php foreach ($models as $i => $model) { ?>
<div class="row">
<div class="col-md-4">
<div class="box box-danger">
<div class="box-body">
<div class="mail-form" xmlns="http://www.w3.org/1999/html" xmlns="http://www.w3.org/1999/html">
<?php
if (!$model->isNewRecord) {
$model->setScenario('update');
echo Html::activeHiddenInput($model, "[$i]id");
}
?>

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

print $form->field($model, "[$i]server")->widget(ServerCombo::className());

print $form->field($model, "[$i]account")->widget(SshAccountCombo::className());

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) ?>
<?= Html::tag('span', '@') ?>
<?= $form->field($model, "[$i]hdomain_id")->widget(HdomainCombo::className(), [
'activeWhen' => ['hosting/account'],
'inputOptions' => [
'data-field' => 'dns_hdomain_id',
],
'pluginOptions' => [
'select2Options' => [
'width' => '250px',
],
'onChange' => new JsExpression("function () {
$(this).closest('.form-instance').find('input[data-field=\"sub-with-domain\"]').trigger('update');
}
")
]
])->label(false) ?>
</div>

<?php
print $form->field($model, "[$i]password")->widget(PasswordInput::className());

print $form->field($model, "[$i]spam_action")->radioList([
'' => Yii::t('app', 'Do nothing'),
'remove' => Yii::t('app', 'Remove'),
'forward' => Yii::t('app', 'Forward to'),
]);
print $form->field($model, "[$i]spam_forward_mail", [
'inputOptions' => [
'disabled' => true
]
])->widget(MailCombo::className(), [

]);

print $form->field($model, "[$i]forwards")->widget(MailCombo::className());

print $form->field($model, "[$i]autoanswer")->textarea();

print $form->field($model, "[$i]du_limit")->textarea();
?>
</div>
</div>
</div>
</div>
</div>
<?php } ?>
</div>
<?= Html::submitButton(Yii::t('app', 'Save'), ['class' => 'btn btn-default']) ?>
&nbsp;
<?= Html::button(Yii::t('app', 'Cancel'), ['class' => 'btn btn-default', 'onclick' => 'history.go(-1)']) ?>
<?php ActiveForm::end();
13 changes: 13 additions & 0 deletions src/views/mail/create.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/* @var $this yii\web\View */
/* @var $model hipanel\modules\hosting\models\Mail */
/* @var $type string */

$this->title = Yii::t('app', 'Create mailbox');
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Mailboxes'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>

<div class="mailbox-create">
<?= $this->render('_form', compact('models')) ?>
</div>
48 changes: 48 additions & 0 deletions src/widgets/combo/MailCombo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace hipanel\modules\hosting\widgets\combo;

use hiqdev\combo\Combo;
use yii\helpers\ArrayHelper;
use yii\web\JsExpression;

class MailCombo extends Combo
{
/** @inheritdoc */
public $type = 'hosting/mail';

/** @inheritdoc */
public $name = 'mail';

/** @inheritdoc */
public $url = '/hosting/mail/search';

/** @inheritdoc */
public $_return = ['id', 'account', 'server', 'client'];

/** @inheritdoc */
public $_rename = ['text' => 'mail'];

/** @inheritdoc */
public function getFilter()
{
return ArrayHelper::merge(parent::getFilter(), [
'server' => 'server/server',
'account' => 'hosting/account',
'state' => ['format' => 'ok'],
]);
}

/** @inheritdoc */
public function getPluginOptions($options = [])
{
return parent::getPluginOptions([
'activeWhen' => ['server/server'],
'select2Options' => [
'formatResult' => new JsExpression("function (data) {
return data.text;
}")
]
]);
}
}
4 changes: 2 additions & 2 deletions src/widgets/mail/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ class Type extends Label
*/
public function init()
{
if ($this->model->is_alias) {
if ($this->model->type == 'forward_only') {
$this->label = Yii::t('app', 'Forward only');
$this->color = 'primary';
$this->labelOptions = [
'title' => Yii::t('app', 'You can not login ...') // TODO
];
} elseif ($this->model->forwards) {
} elseif ($this->model->type == 'mailbox_with_forwards') {
$this->label = Yii::t('app', 'Mailbox with forwards');
$this->color = 'warning';
} else {
Expand Down

0 comments on commit 33b1c5b

Please sign in to comment.