Skip to content

Commit

Permalink
Work with contacts
Browse files Browse the repository at this point in the history
  • Loading branch information
tafid committed Dec 2, 2016
1 parent 73cdf62 commit 634320a
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 156 deletions.
178 changes: 79 additions & 99 deletions src/controllers/DomainController.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,6 @@ public function actions()
'productClass' => DomainTransferProduct::class,
'bulkLoad' => true,
],
'bulk-set-contacts-modal' => [
'class' => PrepareBulkAction::class,
'scenario' => 'bulk-set-contacts',
'view' => '_bulkSetContacts',
],
'domain-push-modal' => [
'class' => PrepareBulkAction::class,
'view' => '_modalPush',
Expand All @@ -130,21 +125,11 @@ public function actions()
$action->setScenario($hasPincode ? 'push-with-pincode' : 'push');
},
],
'validate-set-contacts-form' => [
'class' => ValidateFormAction::class,
'collectionLoader' => function ($action) {
/** @var SmartPerformAction $action */
$request = Yii::$app->request;
$action->collection->load([[
'registrant' => $request->post('registrant'),
'admin' => $request->post('admin'),
'tech' => $request->post('tech'),
'billing' => $request->post('billing'),
]]);
},
'validatedInputId' => function ($action, $model, $id, $attribute, $errors) {
return 'domain-' . $attribute;
},
// Work with contacts
'bulk-set-contacts-modal' => [
'class' => PrepareBulkAction::class,
'scenario' => 'bulk-set-contacts',
'view' => '_bulkSetContacts',
],
'bulk-set-contacts' => [
'class' => SmartPerformAction::class,
Expand All @@ -162,6 +147,7 @@ public function actions()
$action->collection->load($data);
},
],

'push' => [
'class' => SmartPerformAction::class,
'collectionLoader' => function ($action) {
Expand Down Expand Up @@ -215,12 +201,11 @@ public function actions()
'on beforePerform' => function ($event) {
$action = $event->sender;
$action->getDataProvider()->query
->addSelect(['nsips','contacts'])
->addSelect(['nsips', 'contacts'])
->joinWith('registrant')
->joinWith('admin')
->joinWith('tech')
->joinWith('billing')
;
->joinWith('billing');
},
'data' => function ($action) {
return [
Expand Down Expand Up @@ -560,31 +545,6 @@ public function actionGetPassword()
return $return;
}

/**
* @throws \HttpInvalidParamException
*
* @return string
*/
public function actionModalContactsBody()
{
$ids = ArrayHelper::csplit(Yii::$app->request->post('ids'));
$domainContactModels = [];
if ($ids) {
$domainContacts = Domain::perform('GetContacts', ArrayHelper::make_sub($ids, 'id'), true);
foreach ($domainContacts as $item) {
$domainContactModels[] = Domain::find()->populate([$item]);
}
$modelContactInfo = Contact::perform('GetList', ['domain_ids' => $ids, 'limit' => 1000], true);

return $this->renderAjax('_modalContactsBody', [
'domainContacts' => $domainContacts,
'modelContactInfo' => $modelContactInfo,
]);
} else {
return Yii::t('hipanel', 'No items selected');
}
}

public function actionModalNsBody()
{
$ids = ArrayHelper::csplit(Yii::$app->request->post('ids'));
Expand All @@ -600,59 +560,79 @@ public function actionModalNsBody()
}
}

public function actionSetContacts()
{
Yii::$app->response->format = Response::FORMAT_JSON;
$post = Yii::$app->request->post();
$model = DynamicModel::validateData($post, [
[Domain::$contactTypes, 'required'],
]);
// public function actionModalContactsBody()
// {
// $ids = ArrayHelper::csplit(Yii::$app->request->post('ids'));
// $domainContactModels = [];
// if ($ids) {
// $domainContacts = Domain::perform('GetContacts', ArrayHelper::make_sub($ids, 'id'), true);
// foreach ($domainContacts as $item) {
// $domainContactModels[] = Domain::find()->populate([$item]);
// }
// $modelContactInfo = Contact::perform('GetList', ['domain_ids' => $ids, 'limit' => 1000], true);
//
// return $this->renderAjax('_modalContactsBody', [
// 'domainContacts' => $domainContacts,
// 'modelContactInfo' => $modelContactInfo,
// ]);
// } else {
// return Yii::t('hipanel', 'No items selected');
// }
// }

if ($model->hasErrors()) {
return ['errors' => $model->errors];
}
// public function actionSetContacts()
// {
// Yii::$app->response->format = Response::FORMAT_JSON;
// $post = Yii::$app->request->post();
// $model = DynamicModel::validateData($post, [
// [Domain::$contactTypes, 'required'],
// ]);
//
// if ($model->hasErrors()) {
// return ['errors' => $model->errors];
// }
//
// $ids = Yii::$app->request->post('id');
// $data = iterator_to_array(
// new RecursiveIteratorIterator(
// new RecursiveArrayIterator(
// array_map(
// function ($key) use ($post) {
// return [$key => $post[$key]];
// },
// Domain::$contactTypes
// )
// )
// )
// );
// $preparedData = [];
// foreach ($ids as $id) {
// $preparedData[] = ArrayHelper::merge(['id' => $id], $data);
// }
// try {
// $result = Domain::perform('SetContacts', $preparedData, true);
// } catch (\Exception $e) {
// $result = [
// 'errors' => [
// 'title' => $e->getMessage(),
// 'detail' => $e->getMessage(),
// ],
// ];
// }
//
// return $result;
// }

$ids = Yii::$app->request->post('id');
$data = iterator_to_array(
new RecursiveIteratorIterator(
new RecursiveArrayIterator(
array_map(
function ($key) use ($post) {
return [$key => $post[$key]];
},
Domain::$contactTypes
)
)
)
);
$preparedData = [];
foreach ($ids as $id) {
$preparedData[] = ArrayHelper::merge(['id' => $id], $data);
}
try {
$result = Domain::perform('SetContacts', $preparedData, true);
} catch (\Exception $e) {
$result = [
'errors' => [
'title' => $e->getMessage(),
'detail' => $e->getMessage(),
],
];
}

return $result;
}

public function actionGetContactsByAjax($id)
{
if (Yii::$app->request->isAjax) {
$domainContactInfo = Domain::perform('GetContactsInfo', ['id' => $id]);

return $this->renderAjax('_contactsTables', ['domainContactInfo' => $domainContactInfo]);
} else {
Yii::$app->end();
}
}
// public function actionGetContactsByAjax($id)
// {
// if (Yii::$app->request->isAjax) {
// $domainContactInfo = Domain::perform('GetContactsInfo', ['id' => $id]);
//
// return $this->renderAjax('_contactsTables', ['domainContactInfo' => $domainContactInfo]);
// } else {
// Yii::$app->end();
// }
// }

public function getStateData()
{
Expand Down
14 changes: 7 additions & 7 deletions src/models/Domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ class Domain extends \hipanel\base\Model
public static function contactTypesWithLabels()
{
return [
'registrant' => Yii::t('hipanel:domain', 'Registrant contact'),
'admin' => Yii::t('hipanel:domain', 'Admin contact'),
'tech' => Yii::t('hipanel:domain', 'Tech contact'),
'billing' => Yii::t('hipanel:domain', 'Billing contact'),
'registrant' => Yii::t('hipanel:domain', 'Registrant contact'),
'admin' => Yii::t('hipanel:domain', 'Admin contact'),
'tech' => Yii::t('hipanel:domain', 'Tech contact'),
'billing' => Yii::t('hipanel:domain', 'Billing contact'),
];
}

Expand Down Expand Up @@ -75,9 +75,9 @@ public function rules()
[['block', 'epp_client_id', 'nameservers', 'nsips'], 'safe'],
[['note'], 'safe', 'on' => ['set-note', 'default']],

[['registrant_id', 'admin_id', 'tech_id', 'billing_id'], 'integer'],
[['registrant_id', 'admin_id', 'tech_id', 'billing_id'], 'required', 'on' => ['set-contacts']],
[['registrant_id', 'admin_id', 'tech_id', 'billing_id'], 'required', 'on' => ['bulk-set-contacts']],
// Contacts
[['registrant_id', 'admin_id', 'tech_id', 'billing_id'], 'integer', 'on' => ['set-contacts', 'bulk-set-contacts']],
[['registrant_id', 'admin_id', 'tech_id', 'billing_id'], 'required', 'on' => ['set-contacts', 'bulk-set-contacts']],

[['enable'], 'safe', 'on' => ['set-lock', 'set-whois-protect']],
[['domain', 'autorenewal'], 'safe', 'on' => 'set-autorenewal'],
Expand Down
4 changes: 2 additions & 2 deletions src/views/domain/_bulkSetContacts.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
'id' => 'bulk-set-contact-form',
'action' => Url::toRoute('bulk-set-contacts'),
'enableAjaxValidation' => true,
'validationUrl' => Url::toRoute(['validate-set-contacts-form', 'scenario' => 'bulk-set-contacts']),
// 'validationUrl' => Url::toRoute(['validate-set-contacts-form', 'scenario' => 'bulk-set-contacts']),
]) ?>


Expand Down Expand Up @@ -67,6 +67,6 @@
</div>

<hr>
<?= Html::submitButton('Send', ['class' => 'btn btn-success']) ?>
<?= Html::submitButton(Yii::t('hipanel', 'Save'), ['class' => 'btn btn-success']) ?>

<?php ActiveForm::end() ?>
26 changes: 26 additions & 0 deletions src/views/domain/_contacts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

use hipanel\widgets\AjaxModal;
use yii\bootstrap\Modal;
use yii\helpers\Html;

$buttonOptions = [
'label' => '<i class="fa fa-fw fa-pencil"></i> ' . Yii::t('hipanel:domain', 'Change contacts'),
'class' => 'btn btn-success btn-flat',
];
?>

<?php if ($model->isContactChangeable()) : ?>
<?= AjaxModal::widget([
'id' => 'set-contacts-modal',
'bulkPage' => false,
'header' => Html::tag('h4', Yii::t('hipanel:domain', 'Change contacts'), ['class' => 'modal-title']),
'scenario' => 'set-contacts-modal',
'actionUrl' => ['bulk-set-contacts-modal', 'id' => $model->id],
'size' => Modal::SIZE_LARGE,
'toggleButton' => ['label' => '<i class="fa fa-fw fa-pencil"></i> ' . Yii::t('hipanel:domain', 'Change contacts'), 'class' => 'btn btn-sm btn-success btn-flat'],
]); ?>
<?php else: ?>
<?= Html::button($buttonOptions['label'], array_merge($buttonOptions, ['disabled' => 'disabled'])); ?>
<?= Html::tag('span', Yii::t('hipanel:domain', 'Can not change the contact information for this zone.'), ['class' => 'text-danger']) ?>
<?php endif; ?>
47 changes: 0 additions & 47 deletions src/views/domain/_modalContacts.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/views/domain/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
<div class=" tab-pane" id="contacts">
<div class="row">
<div class="col-md-12">
<?= $this->render('_modalContacts', ['model' => $model]) ?>
<?= $this->render('_contacts', ['model' => $model]) ?>
</div>
<div id="contacts-tables">
<?= $this->render('_contactsTables', ['model' => $model]) ?>
Expand Down

0 comments on commit 634320a

Please sign in to comment.