diff --git a/models/Account.php b/models/Account.php index 60844c4f..9787d4ff 100644 --- a/models/Account.php +++ b/models/Account.php @@ -19,7 +19,7 @@ class Account extends \hipanel\base\Model public function init() { - $this->on(static::EVENT_BEFORE_INSERT, [$this, 'onBeforeInsert']); + $this->on(static::EVENT_BEFORE_VALIDATE, [$this, 'onBeforeValidate']); } public function rules() @@ -35,7 +35,7 @@ public function rules() [ [ 'login', - 'server_id', + 'server', 'password', 'sshftp_ips', 'type', @@ -46,7 +46,7 @@ public function rules() [ [ 'login', - 'server_id', + 'server', 'password', 'sshftp_ips', 'type', @@ -147,7 +147,7 @@ public function scenarioCommands() ]; } - public function onBeforeInsert() + public function onBeforeValidate() { if ($this->scenario == 'create-user') { $this->type = 'user'; diff --git a/models/Hdomain.php b/models/Hdomain.php index 9410fe73..2d837ad9 100644 --- a/models/Hdomain.php +++ b/models/Hdomain.php @@ -17,10 +17,32 @@ class Hdomain extends \hipanel\base\Model public function rules () { return [ [ - ['id', 'server_id', 'client_id', 'seller_id', 'account_id', 'hdomain_id', 'state_id', 'type_id', 'vhost_id', 'device_id'], + [ + 'id', 'server_id', 'client_id', 'seller_id', + 'account_id', 'hdomain_id', 'state_id', 'type_id', + 'vhost_id', 'device_id' + ], 'integer' ], - [['server', 'vhost', 'device', 'client', 'seller', 'account', 'domain', 'state', 'type', 'ip', 'alias'], 'safe'], + [ + [ + 'server', 'vhost', 'device', 'client', 'seller', + 'account', 'domain', 'state', 'type', 'ip', 'alias', + 'backend_ip', 'backuping_type' + ], + 'safe' + ], + [ + [ + 'server', 'account', 'domain', + 'with_www', 'path', 'ip', + ], + 'required', 'on' => 'create' + ], + [ + ['proxy_enable'], 'safe', 'on' => 'create' + ] + ]; } @@ -32,6 +54,7 @@ function getIsProxied() { public function attributeLabels () { return $this->mergeAttributeLabels([ 'domain' => Yii::t('app', 'Domain Name'), + 'backend_ip' => Yii::t('app', 'Backend IP'), ]); } } diff --git a/models/IpSearch.php b/models/IpSearch.php index 9c5b5959..401ca940 100644 --- a/models/IpSearch.php +++ b/models/IpSearch.php @@ -7,6 +7,27 @@ namespace hipanel\modules\hosting\models; +use hipanel\base\SearchModelTrait; +use yii\helpers\ArrayHelper; + class IpSearch extends Ip{ - use \hipanel\base\SearchModelTrait; + use SearchModelTrait { + searchAttributes as defaultSearchAttributes; + } + + /** + * @inheritdoc + */ + public function searchAttributes() + { + return ArrayHelper::merge($this->defaultSearchAttributes(), [ + 'with_expanded_ips', + 'show_only_device_link', + 'with_links', + 'not_tags', + 'soft_type', + 'server', + 'device', + ]); + } } diff --git a/views/hdomain/_form.php b/views/hdomain/_form.php index e20b8abe..90f3d98a 100644 --- a/views/hdomain/_form.php +++ b/views/hdomain/_form.php @@ -5,15 +5,97 @@ /* @var $type string */ use hipanel\base\View; +use hipanel\models\Ref; use hipanel\modules\client\widgets\combo\ClientCombo; use hipanel\modules\hosting\widgets\combo\AccountCombo; use hipanel\modules\hosting\widgets\combo\DbServiceCombo; +use hipanel\modules\hosting\widgets\ip\BackIpCombo; +use hipanel\modules\hosting\widgets\ip\FrontIpCombo; +use hipanel\modules\hosting\widgets\ip\HdomainIpCombo; use hipanel\modules\server\widgets\combo\ServerCombo; use hipanel\widgets\PasswordInput; +use hiqdev\combo\StaticCombo; use yii\helpers\Html; use yii\bootstrap\ActiveForm; use yii\helpers\Url; +$this->registerJs(<<<'JS' + $('.hdomain-create').on('change', '#hdomain-proxy_enable', function () { + var $checkbox = $(this); + var $scope = $(this).closest('form'); + var $proxied = $scope.find('.field-hdomain-frontend_ip, .field-hdomain-backend_ip'); + var $not_proxied = $scope.find('.field-hdomain-not-proxied_ip'); + + if ($checkbox.prop('checked')) { + $proxied.removeClass('hidden'); + + if ($scope.find('#hdomain-account').select2('data')) { + $proxied.find('input').select2('enable', true); + } else { + $proxied.find('input').select2('enable', false); + } + + $not_proxied.addClass('hidden').find('input').prop({'required': false}).select2('enable', false); + } else { + $proxied.addClass('hidden').find('input').select2('enable', false); + $not_proxied.removeClass('hidden'); + + if ($scope.find('#hdomain-account').select2('data')) { + $not_proxied.find('input').select2('enable', true); + } else { + $not_proxied.find('input').select2('enable', false); + } + } + }); +JS +); + +$this->registerJs(<<<'JS' +/* +TODO: after ABAC - for admin + $('.hdomain-create').find('.field-hdomain-path').on('updatePath', function (e, update) { + var $path = $(this); + var s_path = $path.val().split('/'); + if (s_path.length < 2 || s_path[1] != 'home') { + s_path = ['', 'home', '']; + } + + // 0 - / + // 1 - home + // 2 - user + // 3 - domain + + if (update.account) { + if (s_path.length > 1) { + s_path[2] = update.account; + if (!s_path[3]) s_path[3] = ''; + } + } else if (update.domain) { + s_path[s_path.length - 1] = update.domain.replace(/\\//g, ''); /// удаляем слеши, чтобы не собрать паровоз из пути + } else if (update.clear) { + s_path = []; + } + + $path.val(s_path.join('/')); + }); +*/ + + $('.hdomain-create').find('.field-hdomain-path').on('updatePath', function (e, update) { + var $group = $(this); + var $input = $group.find('input'); + var $span = $group.find('span'); + + if (update.account) $span.text('/home/' + update.account + '/'); + if (update.domain !== undefined) $input.val(update.domain); + if (update.clear) $span.val(''); + }); + + $('.hdomain-create').on('keyup keypress blur change', '.field-hdomain-domain input', function () { + var $scope = $(this).closest('form'); + $scope.find('.field-hdomain-path').trigger('updatePath', {domain: $(this).val()}); + }); +JS +); ?>