Skip to content

Commit

Permalink
Add bulkSetNote operation
Browse files Browse the repository at this point in the history
  • Loading branch information
tafid committed Dec 2, 2015
1 parent 1a5deac commit 94c2f4c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 47 deletions.
36 changes: 19 additions & 17 deletions src/controllers/DomainController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use RecursiveIteratorIterator;
use Yii;
use yii\base\DynamicModel;
use yii\base\Event;
use yii\data\ArrayDataProvider;

class DomainController extends \hipanel\base\CrudController
Expand Down Expand Up @@ -81,23 +82,24 @@ public function actions()
'class' => 'hipanel\actions\SmartUpdateAction',
'success' => Yii::t('app', 'Note changed'),
'error' => Yii::t('app', 'Failed change note'),
'beforeSave' => function ($action) {
\yii\helpers\VarDumper::dump($action, 10, true);die();
// foreach ($action->collection->models as $model) {
// $model->enable = 0;
// }
//
// $templateModel = null;
// $template = Yii::$app->request->post('check');
// foreach ($action->collection->models as $model) {
// if ($model->id === $template) {
// $templateModel = $model;
// }
// }
//
// foreach ($action->collection->models as $model) {
// $model->nameservers = $templateModel->nameservers;
// }
'POST html' => [
'save' => true,
'success' => [
'class' => 'hipanel\actions\RedirectAction',
'url' => function ($action) {
return $action->redirect($this->redirect(Yii::$app->request->referrer));
}
],
],
'on beforeSave' => function (Event $event) {
/** @var \hipanel\actions\Action $action */
$action = $event->sender;
$bulkNote = Yii::$app->request->post('bulk_note');
if (!empty($bulkNote)) {
foreach ($action->collection->models as $model) {
$model->note = $bulkNote;
}
}
},
],
'set-nss' => [
Expand Down
2 changes: 1 addition & 1 deletion src/models/Domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function rules()
[['url_fwval' ,'mailval', 'parkval', 'soa', 'dns', 'counters'], 'safe'],
[['registrant', 'admin', 'tech', 'billing'], 'integer'],
[['block', 'epp_client_id', 'nameservers', 'nsips'], 'safe'],
[['note', 'ids'], 'safe', 'on' => ['set-note','default']],
[['id', 'note'], 'safe', 'on' => ['set-note', 'default']],

[['registrant','admin','tech','billing'], 'safe', 'on' => ['set-contacts']],
[['registrant','admin','tech','billing'], 'required', 'on' => ['set-contacts']],
Expand Down
39 changes: 10 additions & 29 deletions src/views/domain/_bulkSetNote.php
Original file line number Diff line number Diff line change
@@ -1,67 +1,49 @@
<?php

use hipanel\helpers\Url;
use hipanel\widgets\Pjax;
use yii\bootstrap\ActiveForm;
use yii\helpers\Html;

?>
<?php Pjax::begin(['id' => 'bulkNote-pjax-container', 'enablePushState' => false, 'enableReplaceState' => false]) ?>
<?php $this->registerJs("
var saveButton = $('#bulkNote-save-button');
$(document).on('pjax:send', function(event) {
event.preventDefault()
saveButton.button('loading');

});
$(document).on('pjax:complete', function(event) {
event.preventDefault();
saveButton.button('reset');
});
"); ?>
<?php $form = ActiveForm::begin([
'id' => 'bulk-set-note',
'action' => Url::toRoute('set-note'),
'validateOnBlur' => true,
'validationUrl' => Url::toRoute(['validate-form', 'scenario' => 'set-note']),
'options' => [
'data-pjax' => true,
'data-pjaxPush' => false,
],
]) ?>

<div>

<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active"><a href="#bulk" aria-controls="home" role="tab" data-toggle="tab"><?= Yii::t('app', 'Bulk') ?></a></li>
<li role="presentation"><a href="#by-one" aria-controls="profile" role="tab" data-toggle="tab"><?= Yii::t('app', 'By one') ?></a></li>
<li role="presentation" class="active"><a href="#bulk" aria-controls="home" role="tab" data-toggle="tab"><?= Yii::t('app', 'Set for all') ?></a></li>
<li role="presentation"><a href="#by-one" aria-controls="profile" role="tab" data-toggle="tab"><?= Yii::t('app', 'Edit by one') ?></a></li>
</ul>

<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="bulk">
<div class="row" style="margin-top: 15pt;">
<div class="col-md-12">
<?= Html::textInput("note", null, ['class' => 'form-control', 'placeholder' => Yii::t('app', 'Type your note here')]); ?>
<?= Html::textInput("bulk_note", null, ['class' => 'form-control', 'placeholder' => Yii::t('app', 'Type your note here')]); ?>
<br>
<?php foreach ($models as $model) : ?>
<?= Html::activeHiddenInput($model, "ids[]") ?>
<span class="label label-primary"><?= $model->domain ?></span>
<span><?= $model->domain ?></span>,&nbsp;&nbsp;
<?php endforeach; ?>
</div>
</div>
</div>
<div role="tabpanel" class="tab-pane" id="by-one">
<div class="row" style="margin-top: 15pt;">
<?php foreach ($models as $model) : ?>
<div class="col-md-6">
<div class="col-md-4 text-right">
<?= Html::activeHiddenInput($model, "[$model->id]id") ?>
<?= $form->field($model, "[$model->id]domain")->textInput(['disabled' => true, 'readonly' => true])->label(false) ?>
<?= $model->domain ?>
</div>
<!-- /.col-md-6 -->
<div class="col-md-6">
<?= $form->field($model, "note")->label(false); ?>
<div class="col-md-8">
<?= $form->field($model, "[$model->id]note")->label(false); ?>
</div>
<!-- /.col-md-6 -->
<?php endforeach; ?>
Expand All @@ -70,7 +52,6 @@
</div>

</div>
<hr>
<hr>
<?= Html::submitButton(Yii::t('app', 'Save'), ['class' => 'btn btn-success', 'id' => 'bulkNote-save-button']) ?>
<?php ActiveForm::end() ?>
<?php Pjax::end(); ?>
<?php ActiveForm::end() ?>

0 comments on commit 94c2f4c

Please sign in to comment.