<commit_before><?php
/**
 * HiPanel core package.
 *
 * @link      https://hipanel.com/
 * @package   hipanel-core
 * @license   BSD-3-Clause
 * @copyright Copyright (c) 2014-2017, HiQDev (http://hiqdev.com/)
 */

namespace hipanel\widgets;

use hipanel\models\IndexPageUiOptions;
use Yii;
use yii\base\InvalidParamException;
use yii\base\Model;
use yii\base\Widget;
use yii\bootstrap\ButtonDropdown;
use yii\data\DataProviderInterface;
use yii\helpers\Html;
use yii\helpers\Inflector;
use yii\helpers\Json;
use yii\helpers\Url;
use yii\web\View;

class IndexPage extends Widget
{
    /**
     * @var string
     */
    protected $_layout;

    /**
     * @var Model the search model
     */
    public $model;

    /**
     * @var IndexPageUiOptions
     */
    private $uiModel;

    /**
     * @var object original view context.
     * It is used to render sub-views with the same context, as IndexPage
     */
    public $originalContext;

    /**
     * @var DataProviderInterface
     */
    public $dataProvider;

    /**
     * @var array Hash of document blocks, that can be rendered later in the widget's views
     * Blocks can be set explicitly on widget initialisation, or by calling [[beginContent]] and
     * [[endContent]]
     *
     * @see beginContent
     * @see endContent
     */
    public $contents = [];

    /**
     * @var string the name of current content block, that is under the render
     * @see beginContent
     * @see endContent
     */
    protected $_current = null;

    /**
     * @var array
     */
    public $searchFormData = [];

    /**
     * @var array
     */
    public $searchFormOptions = [];

    /**
     * @var string the name of view file that contains search fields for the index page. Defaults to `_search`
     * @see renderSearchForm()
     */
    public $searchView = '_search';

    /** {@inheritdoc} */
    public function init()
    {
        parent::init();
        $searchFormId = Json::htmlEncode("#{$this->getBulkFormId()}");
        $this->originalContext = Yii::$app->view->context;
        $view = $this->getView();
        // Fix a very narrow select2 input in the search tables
        $view->registerCss('#content-pjax .select2-dropdown--below { min-width: 170px!important; }');
        $view->registerJs(<<<"JS"
        // Checkbox
        var bulkcontainer = $('.box-bulk-actions fieldset');
        $(document).on('ifChecked ifUnchecked', 'table input[type="checkbox"]', 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();
            }
        });
        // Do not open select2 when clear
        var el = $('div[role=grid] :input[data-combo-field], .advanced-search :input[data-combo-field]');
        el.on('select2:unselecting', function(e) {
            el.data('unselecting', true);
        }).on('select2:open', function(e) { // note the open event is important
            if (el.data('unselecting')) {
                el.removeData('unselecting'); // you need to unset this before close
                el.select2('close');
            }
        });
JS
        );
    }

    public function getUiModel()
    {
        if ($this->uiModel === null) {
            $this->uiModel = $this->originalContext->indexPageUiOptionsModel;<commit_msg>Fixed IndexPage::init() to make pach for select2 work on page even after ajax update of select2<commit_after><?php
/**
 * HiPanel core package.
 *
 * @link      https://hipanel.com/
 * @package   hipanel-core
 * @license   BSD-3-Clause
 * @copyright Copyright (c) 2014-2017, HiQDev (http://hiqdev.com/)
 */

namespace hipanel\widgets;

use hipanel\models\IndexPageUiOptions;
use Yii;
use yii\base\InvalidParamException;
use yii\base\Model;
use yii\base\Widget;
use yii\bootstrap\ButtonDropdown;
use yii\data\DataProviderInterface;
use yii\helpers\Html;
use yii\helpers\Inflector;
use yii\helpers\Json;
use yii\helpers\Url;
use yii\web\View;

class IndexPage extends Widget
{
    /**
     * @var string
     */
    protected $_layout;

    /**
     * @var Model the search model
     */
    public $model;

    /**
     * @var IndexPageUiOptions
     */
    private $uiModel;

    /**
     * @var object original view context.
     * It is used to render sub-views with the same context, as IndexPage
     */
    public $originalContext;

    /**
     * @var DataProviderInterface
     */
    public $dataProvider;

    /**
     * @var array Hash of document blocks, that can be rendered later in the widget's views
     * Blocks can be set explicitly on widget initialisation, or by calling [[beginContent]] and
     * [[endContent]]
     *
     * @see beginContent
     * @see endContent
     */
    public $contents = [];

    /**
     * @var string the name of current content block, that is under the render
     * @see beginContent
     * @see endContent
     */
    protected $_current = null;

    /**
     * @var array
     */
    public $searchFormData = [];

    /**
     * @var array
     */
    public $searchFormOptions = [];

    /**
     * @var string the name of view file that contains search fields for the index page. Defaults to `_search`
     * @see renderSearchForm()
     */
    public $searchView = '_search';

    /** {@inheritdoc} */
    public function init()
    {
        parent::init();
        $searchFormId = Json::htmlEncode("#{$this->getBulkFormId()}");
        $this->originalContext = Yii::$app->view->context;
        $view = $this->getView();
        // Fix a very narrow select2 input in the search tables
        $view->registerCss('#content-pjax .select2-dropdown--below { min-width: 170px!important; }');
        $view->registerJs(<<<"JS"
        // Checkbox
        var bulkcontainer = $('.box-bulk-actions fieldset');
        $(document).on('ifChecked ifUnchecked', 'table input[type="checkbox"]', 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();
            }
        });

        // Do not open select2 when it is clearing
        var comboSelector = 'div[role=grid] :input[data-combo-field], .advanced-search :input[data-combo-field]';
        $(document).on('select2:unselecting', comboSelector, function(e) {
            $(e.target).data('unselecting', true);
        }).on('select2:open', comboSelector, function(e) { // note the open event is important
            var el = $(e.target);
            if (el.data('unselecting')) {
                el.removeData('unselecting'); // you need to unset this before close
                el.select2('close');
            }
        });
JS
        );
    }

    public function getUiModel()
    {
        if ($this->uiModel === null) {
            $this->uiModel = $this->originalContext->indexPageUiOptionsModel;
{'fraction_non_alphanumeric': 0.14398572884811417, 'fraction_numerical': 0.005351681957186544, 'mean_word_length': 2.2636174636174635, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 27, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '891895', 'n_tokens_mistral': 2332, 'n_tokens_neox': 2288, 'n_words': 597}