/**
  * @inheritdoc
  */
 public function run()
 {
     $inputId = $this->options['id'];
     $hasModel = $this->hasModel();
     if (array_key_exists('value', $this->options)) {
         $value = $this->options['value'];
     } elseif ($hasModel) {
         $value = Html::getAttributeValue($this->model, $this->attribute);
     } else {
         $value = $this->value;
     }
     $options = array_merge($this->options, ['multiple' => true, 'value' => $value]);
     if ($hasModel) {
         $output = Html::activeListBox($this->model, $this->attribute, $this->items, $options);
     } else {
         $output = Html::listBox($this->name, $this->value, $this->items, $options);
     }
     $clientOptions = array_merge(['filter' => $this->filter, 'multiple' => $this->multiple, 'multipleWidth' => $this->multipleWidth], $this->clientOptions);
     if (!array_key_exists('placeholder', $clientOptions) && array_key_exists('placeholder', $options)) {
         $clientOptions['placeholder'] = $options['placeholder'];
     }
     $js = 'jQuery(\'#' . $inputId . '\').multipleSelect(' . Json::htmlEncode($clientOptions) . ');';
     if (Yii::$app->getRequest()->getIsAjax()) {
         $output .= Html::script($js);
     } else {
         $view = $this->getView();
         MultipleSelectAsset::register($view);
         $view->registerJs($js);
     }
     return $output;
 }
 public static function defaultColumns()
 {
     return ['fqdn' => ['attribute' => 'fqdn', 'value' => function ($model) {
         return $model->fqdn;
     }], 'type' => ['value' => function ($model) {
         return strtoupper($model->type);
     }], 'value' => ['value' => function ($model) {
         return $model->getValueText();
     }], 'zone' => ['class' => MainColumn::className(), 'label' => Yii::t('hipanel:dns', 'Zone'), 'attribute' => 'name'], 'actions' => ['class' => ActionColumn::className(), 'template' => '{update} {delete}', 'visibleButtonsCount' => 2, 'options' => ['style' => 'width: 15%'], 'buttons' => ['update' => function ($url, $model, $key) {
         if ($model->is_system) {
             return Html::tag('div', Html::a('<i class="fa fa-pencil"></i> ' . Yii::t('hipanel', 'Update'), null, ['class' => 'btn btn-default btn-xs disabled']), ['data-placement' => 'top', 'data-toggle' => 'tooltip', 'title' => Yii::t('hipanel:dns', 'This record was created by hosting panel automatically and cannot be updated'), 'style' => 'display: inline-block; cursor: not-allowed;']);
         }
         $data = Html::a('<i class="fa fa-pencil"></i> ' . Yii::t('hipanel', 'Update'), null, ['class' => 'btn btn-default btn-xs edit-dns-toggle', 'data' => ['record_id' => $model->id, 'hdomain_id' => $model->hdomain_id, 'load-url' => Url::to(['@dns/record/update', 'hdomain_id' => $model->hdomain_id, 'id' => $model->id])]]);
         $progress = Json::htmlEncode("<tr><td colspan='5'>" . Progress::widget(['id' => 'progress-bar', 'percent' => 100, 'barOptions' => ['class' => 'active progress-bar-striped', 'style' => 'width: 100%']]) . '</td></tr>');
         Yii::$app->view->registerJs("\n                            \$('.edit-dns-toggle').click(function () {\n                                var record_id = \$(this).data('id');\n                                var hdomain_id = \$(this).data('hdomain_id');\n\n                                var currentRow = \$(this).closest('tr');\n                                var newRow = \$({$progress});\n\n                                \$(newRow).data({'record_id': record_id, hdomain_id: hdomain_id});\n                                \$('tr').filter(function () { return \$(this).data('id') == record_id; }).find('.btn-cancel').click();\n                                \$(newRow).insertAfter(currentRow);\n\n                                jQuery.ajax({\n                                    url: \$(this).data('load-url'),\n                                    type: 'GET',\n                                    timeout: 0,\n                                    error: function() {\n\n                                    },\n                                    success: function(data) {\n                                        newRow.find('td').html(data);\n                                        newRow.find('.btn-cancel').on('click', function (event) {\n                                            event.preventDefault();\n                                            newRow.remove();\n                                        });\n                                    }\n                                });\n\n                            });\n                        ");
         return $data;
     }, 'delete' => function ($url, $model, $key) {
         if ($model->type === 'ns' && $model->is_system) {
             return Html::tag('div', Html::a('<i class="fa text-danger fa-trash-o"></i> ' . Yii::t('hipanel', 'Delete'), null, ['class' => 'btn btn-default btn-xs disabled']), ['data-placement' => 'top', 'data-toggle' => 'tooltip', 'title' => Yii::t('hipanel:dns', 'This record is important for the domain zone viability and can not be deleted'), 'style' => 'display: inline-block; cursor: not-allowed;']);
         }
         return ModalButton::widget(['model' => $model, 'scenario' => 'delete', 'submit' => ModalButton::SUBMIT_PJAX, 'form' => ['action' => Url::to('@dns/record/delete')], 'button' => ['class' => 'btn btn-default btn-xs', 'label' => '<i class="fa text-danger fa-trash-o"></i> ' . Yii::t('hipanel', 'Delete')], 'modal' => ['header' => Html::tag('h4', Yii::t('hipanel:dns', 'Confirm DNS record deleting')), 'headerOptions' => ['class' => 'label-danger'], 'footer' => ['label' => Yii::t('hipanel:dns', 'Delete record'), 'data-loading-text' => Yii::t('hipanel:dns', 'Deleting record...'), 'class' => 'btn btn-danger']], 'body' => function ($model) {
             echo Html::activeHiddenInput($model, 'hdomain_id');
             echo Yii::t('hipanel:dns', 'Are you sure, that you want to delete record {name}?', ['name' => $model->fqdn]);
         }]);
     }]]];
 }
 /**
  * @inheritdoc
  */
 public function run()
 {
     Asset::register($this->view);
     $inputId = Html::getInputId($this->model, $this->attribute);
     $field = $this->render('_field', ['fieldClass' => 'field-' . $inputId, 'inputId' => $inputId, 'inputName' => Html::getInputName($this->model, $this->attribute) . '[]', 'inputLabel' => $this->model->getAttributeLabel($this->attribute)]);
     $options = Json::htmlEncode(['field' => $field, 'firstAddTogglerText' => 'добавить свою категорию', 'addTogglerText' => 'добавить ещё', 'values' => $this->model->{$this->attribute}]);
     $this->view->registerJs('jQuery("#' . $this->id . '").kategoriiSlushatelejInputFields(' . $options . ');');
     return Html::tag('div', $this->renderFirstToggler(), ['id' => $this->id, 'class' => 'kategorii-slushatelej-input-fields']);
 }
 /**
  * Registers the needed client script and options.
  */
 public function registerClientScript()
 {
     $selector = $this->_selector;
     $options = Json::htmlEncode($this->pluginOptions);
     $clientScript = new JsExpression("\$('{$selector}').tokenfield({$options});");
     $this->view->registerJs(Json::htmlEncode($clientScript), View::POS_LOAD);
 }
Esempio n. 5
0
 public function init()
 {
     $id = $this->getId();
     $options = Json::htmlEncode(ArrayHelper::merge($this->options, ['uploader' => ['backendUrl' => Url::to($this->url)], 'files' => $this->getFiles(), 'multiple' => $this->multiple]));
     $this->getView()->registerJs("jQuery('#{$id}').fileInput({$options})");
     echo Html::activeHiddenInput($this->model, $this->attribute, ['id' => $id]);
 }
Esempio n. 6
0
 private function registerClientScript()
 {
     $view = $this->getView();
     TemaPickerAsset::register($view);
     $options = Json::htmlEncode(['temaIndexUrl' => Url::to($this->temaIndexAction), 'temaFilterOptionsUrl' => Url::to($this->temaFilterOptionsAction), 'filterAttributes' => ['podrazdel', 'prepodavatel_fiz_lico', 'prepodavatel_strukturnoe_podrazdelenie', 'nedelya']]);
     $view->registerJs('$("#' . $this->getId() . '").temaPicker(' . $options . ');');
 }
Esempio n. 7
0
 public function testHtmlEncode()
 {
     // HTML escaped chars
     $data = '&<>"\'/';
     $this->assertSame('"\\u0026\\u003C\\u003E\\u0022\\u0027\\/"', Json::htmlEncode($data));
     // basic data encoding
     $data = '1';
     $this->assertSame('"1"', Json::htmlEncode($data));
     // simple array encoding
     $data = [1, 2];
     $this->assertSame('[1,2]', Json::htmlEncode($data));
     $data = ['a' => 1, 'b' => 2];
     $this->assertSame('{"a":1,"b":2}', Json::htmlEncode($data));
     // simple object encoding
     $data = new \stdClass();
     $data->a = 1;
     $data->b = 2;
     $this->assertSame('{"a":1,"b":2}', Json::htmlEncode($data));
     // expression encoding
     $expression = 'function () {}';
     $data = new JsExpression($expression);
     $this->assertSame($expression, Json::htmlEncode($data));
     // complex data
     $expression1 = 'function (a) {}';
     $expression2 = 'function (b) {}';
     $data = ['a' => [1, new JsExpression($expression1)], 'b' => new JsExpression($expression2)];
     $this->assertSame("{\"a\":[1,{$expression1}],\"b\":{$expression2}}", Json::htmlEncode($data));
     // https://github.com/yiisoft/yii2/issues/957
     $data = (object) null;
     $this->assertSame('{}', Json::htmlEncode($data));
     // JsonSerializable
     $data = new JsonModel();
     $this->assertSame('{"json":"serializable"}', Json::htmlEncode($data));
 }
Esempio n. 8
0
 public function run()
 {
     $id = $this->options['id'];
     $options = Json::htmlEncode($this->getClientOptions());
     $view = $this->getView();
     EditorGridViewAsset::register($view);
     $view->registerJs("jQuery('#{$id}').yiiGridView({$options});\$(document).off('change.yiiGridView keydown.yiiGridView');");
     if ($this->showOnEmpty || $this->dataProvider->getCount() > 0) {
         $content = preg_replace_callback("/{\\w+}/", function ($matches) {
             $content = $this->renderSection($matches[0]);
             return $content === false ? $matches[0] : $content;
         }, $this->layout);
     } else {
         $content = $this->renderEmpty();
     }
     $options = $this->options;
     $tag = ArrayHelper::remove($options, 'tag', 'div');
     echo Html::tag($tag, $content, $options);
     foreach ($this->columns as $column) {
         if (isset($column->attribute) && $column->editable) {
             $models = $this->dataProvider->getModels();
             if (($model = reset($models)) instanceof Model) {
                 $name = Html::getInputName($model, $column->attribute);
             } else {
                 $name = $column->attribute;
             }
             $attributeName = $column->attribute;
             $view->registerJs("\$('.{$attributeName}').editable({\n                    placement:'right',\n                    ajaxOptions: {\n                        type: 'GET',\n                        dataType: 'json'\n                    },\n                    success: function(response, newValue) {\n                        if(response.status=='success')\n                        {\n                            return jQuery('#{$this->options['id']}').yiiGridView('applyFilter');\n                        }\n                        else\n                        {\n                            return response.msg;\n                        }\n                    },\n                    params: function(rawParams) {\n                        var params = {};\n                        params['{$name}']=rawParams.value;\n                        params['pk']=rawParams.pk;\n                        return params;\n                    }\n                });");
         }
     }
 }
Esempio n. 9
0
 /**
  * Registers widget options
  */
 private function registerClientOptions()
 {
     $id = $this->options['id'];
     $options = empty($this->clientOptions) ? '' : Json::htmlEncode($this->clientOptions);
     $js = "\$('#{$id}').slick({$options});";
     $this->getView()->registerJs($js);
 }
Esempio n. 10
0
 /**
  * @inheritdoc
  * @throw NotSupportedException
  */
 public function run()
 {
     if ($this->hasModel()) {
         if (!is_null($this->value)) {
             if (!in_array($this->attribute, $this->model->attributes())) {
                 throw new NotSupportedException('Unable to set value of the property \'' . $this->attribute . '\'.');
             }
             $stash = $this->model->{$this->attribute};
             $this->model->{$this->attribute} = $this->value;
         }
         $output = Html::activeListBox($this->model, $this->attribute, $this->items, $this->options);
         if (isset($stash)) {
             $this->model->{$this->attribute} = $stash;
         }
     } else {
         $output = Html::listBox($this->name, $this->value, $this->items, $this->options);
     }
     $js = 'jQuery(\'#' . $this->options['id'] . '\').select2(' . Json::htmlEncode($this->clientOptions) . ');';
     if (Yii::$app->getRequest()->getIsAjax()) {
         $output .= Html::script($js);
     } else {
         $view = $this->getView();
         Select2Asset::register($view);
         Select2LanguageAsset::register($view);
         $view->registerJs($js);
     }
     return $output;
 }
Esempio n. 11
0
 /**
  * 注册FileAPI上传控制JS
  */
 public function registerClientScript()
 {
     $options = Json::htmlEncode($this->getClientOptions());
     $view = $this->getView();
     FileApiAsset::register($view);
     $view->registerJs("\$('#{$this->getId()}').fileapi({$options});");
 }
 protected function registerPlugin()
 {
     $this->registerAssets();
     $clientOptions = Json::htmlEncode($this->clientOptions);
     $this->view->registerJs("jQuery('#{$this->options['id']}').clockpicker({$clientOptions});");
     $this->registerClientEvents();
 }
Esempio n. 13
0
 /**
  * Generates a hashed variable to store the plugin `clientOptions`. Helps in reusing the variable for similar
  * options passed for other widgets on the same page. The following special data attribute will also be
  * added to the input field to allow accessing the client options via javascript:
  *
  * @param View $view the view instance
  */
 protected function hashPluginOptions($view)
 {
     $encOptions = empty($this->clientOptions) ? '{}' : Json::htmlEncode($this->clientOptions);
     $this->_hashVar = self::PLUGIN_NAME . '_' . hash('crc32', $encOptions);
     $this->options['data-plugin-' . self::PLUGIN_NAME] = $this->_hashVar;
     $view->registerJs("var {$this->_hashVar} = {$encOptions};", View::POS_READY);
 }
Esempio n. 14
0
    private function registerClientScript()
    {
        $searchFormId = Json::htmlEncode("#{$this->getBulkFormId()}");
        $view = $this->getView();
        $view->registerJs(<<<JS
        // Checkbox
        var checkboxes = \$('table input[type="checkbox"]');
        var bulkcontainer = \$('.box-bulk-actions fieldset');
        checkboxes.on('ifChecked ifUnchecked', function(event) {
            if (event.type == 'ifChecked' && \$('input.icheck').filter(':checked').length > 0) {
                bulkcontainer.prop('disabled', false);
            } else if (\$('input.icheck').filter(':checked').length == 0) {
                bulkcontainer.prop('disabled', true);
            }
        });
        // On/Off Actions TODO: reduce scope
        \$(document).on('click', '.box-bulk-actions a', function (event) {
            var link = \$(this);
            var action = link.data('action');
            var form = \$({$searchFormId});
            if (action) {
                form.attr({'action': action, method: 'POST'}).submit();
            }
        });
JS
, $view::POS_READY);
    }
Esempio n. 15
0
 public function register()
 {
     $this->traitRegister();
     if ($this->jsNotifier) {
         Yii::$app->on(\yii\web\Application::EVENT_BEFORE_ACTION, function ($event) {
             Yii::$app->view->on(\yii\web\View::EVENT_BEFORE_RENDER, function ($event) {
                 $host = $this->errbit['host'];
                 if (Url::isRelative($host)) {
                     $host = '//' . $host;
                 }
                 $event->sender->registerJsFile(rtrim($host, '/') . '/javascripts/notifier.js', ['position' => \yii\web\View::POS_HEAD]);
                 $js = 'Airbrake.setKey(' . Json::htmlEncode($this->errbit['api_key']) . ');';
                 $js .= 'Airbrake.setHost(' . Json::htmlEncode($this->errbit['host']) . ');';
                 if (isset($this->errbit['environment_name'])) {
                     $js .= 'Airbrake.setEnvironment(' . Json::htmlEncode($this->errbit['environment_name']) . ');';
                 }
                 if (is_array($this->jsOptions)) {
                     foreach ($this->jsOptions as $key => $value) {
                         $js .= 'Airbrake.set' . ucfirst($key) . '(' . Json::htmlEncode($value) . ');';
                     }
                 }
                 $controller = Yii::$app->controller;
                 if ($controller !== null && $controller instanceof UserInfoInterface) {
                     $user = $controller->getErrbitUserInfo();
                     if (is_array($user)) {
                         $js .= 'Airbrake.setCurrentUser(' . Json::htmlEncode($user) . ');';
                     }
                 }
                 $event->sender->registerJs($js, \yii\web\View::POS_HEAD);
             });
         });
     }
 }
Esempio n. 16
0
 public function actionIndex()
 {
     Yii::$app->response->format = 'raw';
     Yii::$app->response->getHeaders()->set('Content-Type', 'text/javascript; charset=UTF-8');
     $script = 'var MASTERS = ' . Json::htmlEncode($this->getMasters()) . ';';
     return $script;
 }
 /**
  * @inheritdoc
  */
 public function run()
 {
     $inputId = $this->options['id'];
     $hasModel = $this->hasModel();
     if (array_key_exists('value', $this->options)) {
         $value = $this->options['value'];
     } elseif ($hasModel) {
         $value = Html::getAttributeValue($this->model, $this->attribute);
     } else {
         $value = $this->value;
     }
     $options = array_merge($this->options, ['value' => $value]);
     if ($hasModel) {
         $output = Html::activeTextInput($this->model, $this->attribute, $options);
     } else {
         $output = Html::textInput($this->name, $this->value, $options);
     }
     if (!is_null($this->alias)) {
         $clientOptions = array_merge($this->clientOptions, ['alias' => $this->alias]);
     } else {
         $clientOptions = array_merge($this->clientOptions, ['mask' => $this->mask]);
     }
     if (!array_key_exists('placeholder', $clientOptions) && array_key_exists('placeholder', $options)) {
         $clientOptions['placeholder'] = $options['placeholder'];
     }
     $js = 'jQuery(\'#' . $inputId . '\').inputmask(' . Json::htmlEncode($clientOptions) . ');';
     if (Yii::$app->getRequest()->getIsAjax()) {
         $output .= Html::script($js);
     } else {
         $view = $this->getView();
         InputMaskAsset::register($view);
         $view->registerJs($js);
     }
     return $output;
 }
Esempio n. 18
0
 /**
  * Runs the widget.
  */
 public function run()
 {
     parent::run();
     $options = Json::htmlEncode($this->getClientOptions());
     $view = $this->getView();
     ListViewAsset::register($view);
     $view->registerJs("jQuery('#{$this->id}').yiiListView({$options});");
 }
Esempio n. 19
0
 public function run()
 {
     $tag = ArrayHelper::remove($this->options, 'tag', 'div');
     $options = empty($this->clientOptions) ? '' : Json::htmlEncode($this->clientOptions);
     $this->getView()->registerCss('#' . $this->id . ' iframe { z-index: 9996; }');
     $this->getView()->registerJs("CKFinder.widget( '{$this->id}', {$options});");
     return implode("\n", [Html::beginTag($tag, $this->options), Html::endTag($tag)]);
 }
 public function run()
 {
     echo $this->renderWidget() . "\n";
     $options = Json::htmlEncode($this->options);
     $this->view->registerJs("\$('#" . $this->id . "').masterslider(" . $options . ");");
     $msAsset = MasterSliderAsset::register($this->view);
     $this->view->registerCssFile($msAsset->baseUrl . '/skins/' . $this->skin . '/style.css', ['depends' => MasterSliderAsset::className()]);
 }
Esempio n. 21
0
 /**
  * @return JsExpression
  */
 public function getBaseModelClassAutoComplete()
 {
     $data = [];
     foreach (Helper::getModelDeepNamespaces() as $modelNs) {
         $data[] = $modelNs . '\\base\\*Base';
     }
     return new JsExpression('function (request, response) { response(' . Json::htmlEncode($data) . '); }');
 }
Esempio n. 22
0
 /**
  * Registers a specific jQuery UI widget options
  * @param string $name the name of the jQuery UI widget
  * @param string $id the ID of the widget
  */
 protected function registerClientOptions($name, $id)
 {
     if ($this->clientOptions !== false) {
         $options = empty($this->clientOptions) ? '' : Json::htmlEncode($this->clientOptions);
         $js = "jQuery('#{$id}').{$name}({$options});";
         $this->getView()->registerJs($js);
     }
 }
Esempio n. 23
0
 protected function registerClientOptions($name, $id)
 {
     if ($this->clientOptions !== false) {
         $options = empty($this->clientOptions) ? '' : Json::htmlEncode($this->clientOptions);
         $js = "jQuery('#$id').$name($options)".$this->renderItem;
         $this->getView()->registerJs($js);
     }
 }
 public function run()
 {
     $view = $this->getview();
     LoadingAsset::register($view);
     $options = empty($this->clientOptions) ? '' : Json::htmlEncode($this->clientOptions);
     $js = '$("#' . $this->getId() . '").LoadingWidget(' . $options . ');';
     $view->registerJs($js, $view::POS_END);
     return $this->render('loading', ['widgetID' => $this->getId()]);
 }
Esempio n. 25
0
 /**
  * @inheritDoc
  */
 public function run()
 {
     $view = $this->getView();
     $id = $this->form->id;
     $options = Json::htmlEncode($this->getClientOptions());
     AjaxFormAsset::register($view);
     $view->registerJs("jQuery('#{$id}').ajaxForm({$options});");
     $this->registerClientEvents();
 }
Esempio n. 26
0
 public function run()
 {
     $view = $this->getView();
     SlimScrollAsset::register($view);
     $options = Json::htmlEncode($this->clientOptions);
     $view->registerJs("jQuery('#{$this->options['id']}').slimScroll({$options});");
     $this->registerEvents();
     echo Html::endTag($this->tag);
 }
Esempio n. 27
0
 /**
  * Makes field auto completable
  * @param array $data auto complete data (array of callables or scalars)
  * @return $this the field object itself
  */
 public function autoComplete($data)
 {
     static $counter = 0;
     $this->inputOptions['class'] .= ' typeahead typeahead-' . ++$counter;
     foreach ($data as &$item) {
         $item = ['word' => $item];
     }
     $this->form->getView()->registerJs("yii.gii.autocomplete({$counter}, " . Json::htmlEncode($data) . ");");
     return $this;
 }
Esempio n. 28
0
 public function registerJs()
 {
     $id = $this->options['id'];
     $options = Json::htmlEncode($this->clientOptions);
     $user = Json::htmlEncode($this->user);
     $contact = Json::htmlEncode($this->contact);
     $view = $this->getView();
     MessageAsset::register($view);
     $view->registerJs("jQuery('#{$id}').yiiSimpleChatMessages({$user},{$contact},{$options});");
 }
 public function registerJs()
 {
     $id = $this->options['id'];
     $options = Json::htmlEncode($this->clientOptions);
     $user = Json::htmlEncode($this->user);
     $current = Json::htmlEncode($this->current);
     $view = $this->getView();
     ConversationAsset::register($view);
     $view->registerJs("jQuery('#{$id}').yiiSimpleChatConversations({$user}, {$current}, {$options});");
 }
 /**
  * @inheritdoc
  */
 public function run()
 {
     $hasModel = $this->hasModel();
     if ($hasModel) {
         if (array_key_exists('value', $this->options)) {
             $value = $this->options['value'];
         } else {
             $value = Html::getAttributeValue($this->model, $this->attribute);
         }
     } else {
         $value = $this->value;
     }
     $altValue = $value;
     if ($hasModel) {
         $this->options = array_merge($this->options, ['name' => false, 'value' => $value]);
         $this->altOptions['value'] = $altValue;
         $output = Html::activeTextInput($this->model, $this->attribute, $this->options) . Html::activeHiddenInput($this->model, $this->attribute, $this->altOptions);
     } else {
         $output = Html::textInput(false, $value, $this->options) . Html::hiddenInput($this->name, $altValue, $this->altOptions);
     }
     $js = 'jQuery(\'#' . $this->options['id'] . '\').inputmask(' . Json::htmlEncode($this->clientOptions) . ').keyup(function (event) { jQuery(\'#' . $this->altOptions['id'] . '\').val(jQuery(this).inputmask(\'unmaskedvalue\')); });';
     if (Yii::$app->getRequest()->getIsAjax()) {
         $output .= Html::script($js);
     } else {
         $view = $this->getView();
         InputMaskAsset::register($view);
         $view->registerJs($js);
     }
     return $output;
 }