Exemplo n.º 1
0
 public static function defaultColumns()
 {
     return ['ip' => ['class' => MainColumn::class, 'filterAttribute' => 'ip_like'], 'tags' => ['format' => 'raw', 'attribute' => 'tag', 'header' => Yii::t('hipanel:hosting', 'Tags'), 'visible' => Yii::$app->user->can('admin'), 'filter' => function ($column, $model) {
         return Html::activeDropDownList($model, 'tag_in', array_merge(['' => Yii::t('hipanel', '---')], static::$ipTags), ['class' => 'form-control']);
     }, 'value' => function ($model) {
         $labels = [];
         foreach ($model->tags as $tag) {
             $labels[] = IpTag::widget(['tag' => $tag]);
         }
         return implode(' ', $labels);
     }], 'counters' => ['format' => 'html', 'header' => Yii::t('hipanel:hosting', 'Counters'), 'value' => function ($model) {
         $html = '';
         foreach ($model->objects_count as $count) {
             if ($count['type'] === 'hdomain') {
                 $url['ok'] = ['@hdomain', (new HdomainSearch())->formName() => ['ip_like' => $model->ip]];
                 $url['deleted'] = ['@hdomain', (new HdomainSearch())->formName() => ['ip_like' => $model->ip, 'state' => 'deleted']];
                 $type = function ($count) {
                     return Yii::t('hipanel:hosting', '{0, plural, one{domain} other{domains}}', (int) $count);
                 };
             } else {
                 throw new InvalidParamException('The object type is not supported', $model);
             }
             if ($count['ok']) {
                 $html .= Html::a((int) $count['ok'] . ' ' . FontIcon::i('fa-check') . ' ' . $type($count['ok']), $url['ok'], ['class' => 'btn btn-success btn-xs']);
             }
             $html .= ' ';
             if ($count['deleted'] > 0) {
                 $html .= Html::a((int) $count['deleted'] . ' ' . FontIcon::i('fa-trash') . ' ' . $type($count['deleted']), $url['deleted'], ['class' => 'btn btn-xs btn-warning']);
             }
         }
         return $html;
     }], 'links' => ['format' => 'html', 'value' => function ($model) {
         $items = [];
         foreach ($model->links as $link) {
             $item = Html::a($link->device, ['@server/view', 'id' => $link->device_id]);
             if ($link->service_id) {
                 $item .= ' ' . FontIcon::i('fa-long-arrow-right');
                 $item .= ' ' . Html::a($link->service ?: $link->soft, ['@service/view', 'id' => $link->service_id]);
             }
             $items[] = $item;
         }
         return ArraySpoiler::widget(['data' => $items, 'visibleCount' => 3]);
     }], 'services' => ['attribute' => 'links', 'format' => 'html', 'label' => Yii::t('hipanel:server', 'Services'), 'value' => function ($model) {
         return ArraySpoiler::widget(['data' => $model->links, 'formatter' => function ($link) {
             if (Yii::$app->user->can('support') && Yii::getAlias('@service', false)) {
                 return Html::a($link->service, ['@service/view', 'id' => $link->service_id]);
             }
             return $link->service;
         }]);
     }], 'actions' => ['class' => MenuColumn::class, 'menuClass' => IpActionsMenu::class], 'ptr' => ['options' => ['style' => 'width: 40%'], 'format' => 'raw', 'value' => function ($model) {
         if ($model->canSetPtr()) {
             return XEditable::widget(['model' => $model, 'attribute' => 'ptr', 'pluginOptions' => ['url' => Url::to('@ip/set-ptr')]]);
         }
         return null;
     }]];
 }
 public static function defaultColumns()
 {
     return ['hdomain' => ['class' => MainColumn::class, 'filterAttribute' => 'domain_like', 'attribute' => 'domain'], 'hdomain_with_aliases' => ['format' => 'raw', 'attribute' => 'domain', 'filterAttribute' => 'domain_like', 'value' => function ($model) {
         $aliases = (array) $model->getAttribute('aliases');
         $html = Html::a($model->domain, ['view', 'id' => $model->id], ['class' => 'bold']) . ' ';
         $html .= ArraySpoiler::widget(['data' => $aliases, 'visibleCount' => 0, 'delimiter' => '<br />', 'button' => ['label' => Yii::t('hipanel', '+{0, plural, one{# alias} other{# aliases}}', count($aliases)), 'class' => 'badge progress-bar-info', 'popoverOptions' => ['html' => true]], 'formatter' => function ($value, $key) {
             return Html::a($value, ['view', 'id' => $key]);
         }]);
         return $html;
     }], 'account' => ['class' => AccountColumn::class], 'server' => ['class' => ServerColumn::class], 'ip' => ['enableSorting' => false, 'filter' => false, 'format' => 'raw', 'value' => function ($model) {
         $vhost = $model->getAttribute('vhost');
         $html = $vhost['ip'];
         if (isset($vhost['port']) && $vhost['port'] !== 80) {
             $html .= ':' . $vhost['port'];
         }
         if ($model->isProxied) {
             $backend = $vhost['backend'];
             $html .= ' ' . Html::tag('i', '', ['class' => 'fa fa-long-arrow-right']) . ' ' . $backend['ip'];
             if ($backend['port'] !== 80) {
                 $html .= ':' . $backend['port'];
             }
         }
         return $html;
     }], 'service' => ['label' => Yii::t('hipanel', 'Service'), 'value' => function ($model) {
         return $model->getAttribute('vhost')['service'];
     }], 'state' => ['class' => RefColumn::class, 'i18nDictionary' => 'hipanel:hosting', 'format' => 'raw', 'value' => function ($model) {
         $html = '';
         if ($model->dns_on && empty($model->dns_hdomain_id)) {
             $html .= Label::widget(['color' => 'success', 'label' => Yii::t('hipanel', 'DNS'), 'tag' => 'span', 'labelOptions' => ['title' => Yii::t('hipanel:hosting', 'DNS is enabled')]]);
         }
         $html .= ' ' . State::widget(compact('model'));
         return $html;
     }, 'gtype' => 'state,hdomain'], 'dns_on' => ['format' => 'raw', 'value' => function ($model) {
         return $model->dns_on ? Yii::t('hipanel', 'Enabled') : Yii::t('hipanel', 'Disabled');
     }], 'dns_switch' => ['attribute' => 'dns_on', 'label' => Yii::t('hipanel:hosting', 'DNS'), 'format' => 'raw', 'value' => function ($model) {
         if (empty($model->dns_hdomain_id)) {
             return XEditable::widget(['model' => $model, 'attribute' => 'dns_on', 'pluginOptions' => ['type' => 'select', 'title' => Yii::t('hipanel:hosting', 'Toggles DNS records upload on NS server'), 'source' => ['' => Yii::t('hipanel', 'Disabled'), '1' => Yii::t('hipanel', 'Enabled')], 'url' => Url::to('set-dns-on'), 'placement' => 'bottom'], 'linkOptions' => ['style' => ['word-break' => 'break-all']]]);
         } else {
             return Yii::t('hipanel:hosting', 'Belongs to {link}', ['link' => Html::a($model->dns_hdomain_domain, Url::to(['@hdomain/view', 'id' => $model->dns_hdomain_id]))]);
         }
     }], 'aliases' => ['label' => Yii::t('hipanel', 'Aliases'), 'format' => 'raw', 'value' => function ($model) {
         return ArraySpoiler::widget(['data' => (array) $model->getAttribute('aliases'), 'delimiter' => '<br />', 'button' => ['popoverOptions' => ['html' => true]]]);
     }], 'backups_widget' => ['label' => Yii::t('hipanel:hosting', 'Backups'), 'format' => 'raw', 'value' => function ($model) {
         return BackupGridRow::widget(['model' => $model]);
     }], 'actions' => ['class' => ActionColumn::class, 'template' => '{view} {delete}']];
 }
Exemplo n.º 3
0
 protected function renderXEditable()
 {
     return \hipanel\widgets\XEditable::widget(['model' => $this->model, 'attribute' => 'level', 'scenario' => $this->scenario, 'linkOptions' => ['id' => $this->getId(), 'data-attribute' => $this->type], 'pluginOptions' => ['selector' => '#' . $this->getId(), 'type' => 'select', 'title' => Yii::t('hipanel:client', 'Verification level'), 'source' => $this->model->getAvailableLevels(), 'params' => new JsExpression("function (params) {\n                    params.type = \$(this).attr('data-attribute');\n                    return params;\n                }"), 'display' => new JsExpression("function (value, sourceData) {\n                    var elem = \$.grep(sourceData, function (o) { return o.value == value; });\n                    var classes = {\n                        unconfirmed: 'text-warning',\n                        confirmed: '',\n                        fullverified: 'text-success',\n                    };\n\n                    \$.map(classes, function(val) {\n                        return \$(this).removeClass(val);\n                    }.bind(this));\n\n                    if (value instanceof String) {\n                        var newClass = classes[value[0]];\n                    } else {\n                        newClass = classes[value];\n                    }\n\n                    \$(this).text(elem[0].text).addClass(newClass);\n                }")]]);
 }
Exemplo n.º 4
0
 /**
  * Renders link to edit note.
  * @param $model
  * @param $key
  * @param $index
  * @return string|null
  */
 public function renderNoteLink($model, $key, $index)
 {
     return $this->note ? Html::tag('span', Yii::t('hipanel', 'Note') . ': ', ['class' => 'bold']) . XEditable::widget(['model' => $model, 'attribute' => $this->note === true ? 'note' : $this->note, 'pluginOptions' => $this->noteOptions]) : null;
 }