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 13, 2015
1 parent c8dc60a commit 906b9c1
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 19 deletions.
19 changes: 19 additions & 0 deletions src/models/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

namespace hipanel\modules\hosting\models;

use hipanel\modules\hosting\validators\EmailLocalPartValidator;
use Yii;
use yii\helpers\StringHelper;

class Mail extends \hipanel\base\Model
{
Expand All @@ -23,6 +25,16 @@ public function rules()
[['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']],
[['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']],
];
}

Expand All @@ -36,6 +48,13 @@ public function attributeLabels()
'du_limit' => Yii::t('app', 'Disk usage limit'),
'mail' => Yii::t('app', 'E-mail'),
'mail_like' => Yii::t('app', 'E-mail'),
'autoanswer' => Yii::t('app', 'Auto answer')
]);
}

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.'),
];
}
}
91 changes: 72 additions & 19 deletions src/views/mail/_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
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\MultipleMailCombo;
use hipanel\modules\hosting\widgets\combo\SshAccountCombo;
use hipanel\modules\hosting\widgets\combo\VhostCombo;
use hipanel\modules\server\widgets\combo\ServerCombo;
use hipanel\widgets\PasswordInput;
use yii\helpers\Html;
Expand All @@ -23,7 +25,7 @@
'enableAjaxValidation' => true,
'validationUrl' => Url::toRoute([
'validate-form',
'scenario' => $model->isNewRecord ? reset($models)->scenario : 'update'
'scenario' => reset($models)->isNewRecord ? reset($models)->scenario : 'update'
]),
]) ?>

Expand All @@ -33,7 +35,8 @@
<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">
<div class="form-instance" xmlns="http://www.w3.org/1999/html"
xmlns="http://www.w3.org/1999/html">
<?php
if (!$model->isNewRecord) {
$model->setScenario('update');
Expand All @@ -43,31 +46,31 @@

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

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

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

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'])->label(false) ?>
<?= Html::tag('span', '@') ?>
<?= $form->field($model, "[$i]hdomain_id")->widget(HdomainCombo::className(), [
'activeWhen' => ['hosting/account'],
<?= $form->field($model, "[$i]hdomain_id")->widget(VhostCombo::className(), [
'formElementSelector' => '.form-instance',
'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>
Expand All @@ -79,20 +82,54 @@
'' => Yii::t('app', 'Do nothing'),
'remove' => Yii::t('app', 'Remove'),
'forward' => Yii::t('app', 'Forward to'),
], [
'class' => 'spam-action'
]);
print $form->field($model, "[$i]spam_forward_mail", [
'options' => [
'style' => 'display: none'
]
])->widget(MultipleMailCombo::className(), [
'type' => 'hosting/spam-forward',
'formElementSelector' => '.form-instance',
'inputOptions' => [
'disabled' => true
'data-attribute' => 'spam_forward_mail',
'disabled' => true,
],
'activeWhen' => [
'server/server',
'spam_action' => new JsExpression('
function (combo) {
var checkbox = combo.form.find(".spam-action input[type=radio]:checked");
return checkbox.val() === "forward" || checkbox.length === 0;
}
')
]
])->widget(MailCombo::className(), [
])->label(false);

]);
print $form->field($model, "[$i]forwards")->widget(MultipleMailCombo::className(), [
'formElementSelector' => '.form-instance',
'inputOptions' => [
'data-attribute' => 'forwards',
],
'activeWhen' => [
'server/server',
]

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

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

print $form->field($model, "[$i]du_limit")->textarea();
print $form->field($model, "[$i]du_limit", [
'template' => <<<HTML
{label}
<div class="input-group">
{input}
<span class="input-group-addon">MB</span>
</div>
{hint}\n{error}
HTML
]);
?>
</div>
</div>
Expand All @@ -104,4 +141,20 @@
<?= 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();
<?php ActiveForm::end();

$this->registerJs(<<<'JS'
$(this).on('change', '.spam-action', function (e) {
console.log(1);
var $form = $(this).closest('.form-instance');
$forwardInput = $form.find('input[data-attribute=spam_forward_mail]');
if ($(this).find('input[type=radio]:checked').val() == 'forward') {
$forwardInput.trigger('change').parent().show();
} else {
$forwardInput.trigger('change').parent().hide();
}
});
JS
);

0 comments on commit 906b9c1

Please sign in to comment.