Ejemplo n.º 1
0
 /**
  * Converts markdown into HTML
  *
  * @param string $content
  * @param array  $config . Options to configure MarkdownExtra and smarty
  *  - markdown: array for MarkdownExtra configuration parameters
  *  - smarty: array for SmartyPantsTypographer configuration parameters
  *  - custom: array for Custom configuration parameters
  * @param int    $smartyMode the SmartyPantsTypographer processing mode
  *
  * @return string
  * @throws InvalidConfigException if module not set
  */
 public static function convert($content, $config = [], $smartyMode = self::SMARTYPANTS_ATTR_LONG_EM_DASH_SHORT_EN)
 {
     $module = Config::initModule(Module::classname());
     $output = $content;
     if (strlen($output) > 0) {
         $mdConfig = empty($config['markdown']) ? [] : $config['markdown'];
         $output = static::process($content, $mdConfig);
         if ($module->smartyPants) {
             $smConfig = empty($config['smarty']) ? [] : $config['smarty'];
             $smarty = new SmartyPants($smartyMode);
             foreach ($smConfig as $name => $value) {
                 $smarty->{$name} = $value;
             }
             $output = $smarty->transform($output);
             $cuConfig = empty($config['custom']) ? $module->customConversion : $config['custom'];
             $output = static::customProcess($output, $cuConfig);
         }
         if (is_bool($module->smarty) && $module->smarty || (is_string($module->smarty) || is_callable($module->smarty)) && call_user_func($module->smarty, $module)) {
             $smarty = new \Smarty();
             if ($module->smartyYiiApp) {
                 $smarty->assign('app', Yii::$app);
             }
             if ($module->smartyYiiParams) {
                 $smarty->config_vars = Yii::$app->params;
             }
             $output = $smarty->fetch('string:' . $output, null, null, $module->smartyParams);
         }
     }
     return $output;
 }
Ejemplo n.º 2
0
 /**
  * Convert markdown text to HTML for preview
  *
  * @returns JSON encoded HTML output
  */
 public function actionPreview()
 {
     $output = '';
     $module = Config::getModule(Module::MODULE);
     if (isset($_POST['source'])) {
         $output = strlen($_POST['source']) > 0 ? Markdown::convert($_POST['source'], ['custom' => $module->customConversion]) : $_POST['nullMsg'];
     }
     echo Json::encode(HtmlPurifier::process($output));
 }
Ejemplo n.º 3
0
 /**
  * @inheritdoc
  * @throws InvalidConfigException
  */
 public function init()
 {
     parent::init();
     Config::checkDependency('editable\\Editable', 'yii2-editable', 'for GridView EditableColumn');
     $this->_css = 'kv-edcol-' . hash('crc32', uniqid(rand(1, 100), true));
     if ($this->refreshGrid) {
         EditableColumnAsset::register($this->_view);
     }
 }
Ejemplo n.º 4
0
 /**
  * @inheritdoc
  * @throws InvalidConfigException
  */
 public function init()
 {
     parent::init();
     \kartik\base\Config::checkDependency('editable\\Editable', 'yii2-editable', 'for GridView EditableColumn');
     $this->_css = 'kv-edcol-' . hash('crc32', uniqid(rand(1, 100), true));
     if ($this->refreshGrid) {
         EditableColumnAsset::register($this->_view);
         $id = $this->grid->options['id'];
         $this->_view->registerJs("kvRefreshEC('{$id}','{$this->_css}');");
     }
 }
Ejemplo n.º 5
0
 /**
  * Initializes the object
  *
  * @throws InvalidConfigException
  */
 public function init()
 {
     $this->_module = Config::initModule(Module::classname());
     $this->_isMaster = $this->category == self::STORE_GRID ? true : false;
     if ($this->_module == null || !$this->_module instanceof Module) {
         throw new InvalidConfigException('The "dynagrid" module MUST be setup in your Yii configuration file and assigned to "\\kartik\\dynagrid\\Module" class.');
     }
     if (!isset($this->id)) {
         throw new InvalidConfigException('The dynagrid "id" property must be entered.');
     }
     $this->setKey();
 }
Ejemplo n.º 6
0
 /**
  * @inherit doc
  * @throw InvalidConfigException
  */
 public function init()
 {
     if (empty($this->pluginOptions['url'])) {
         throw new InvalidConfigException("The 'pluginOptions[\"url\"]' property has not been set.");
     }
     if (empty($this->pluginOptions['depends']) || !is_array($this->pluginOptions['depends'])) {
         throw new InvalidConfigException("The 'pluginOptions[\"depends\"]' property must be set and must be an array of dependent dropdown element ID.");
     }
     if (empty($this->options['class'])) {
         $this->options['class'] = 'form-control';
     }
     if ($this->type === self::TYPE_SELECT2) {
         Config::checkDependency('select2\\Select2', 'yii2-widget-select2', 'for dependent dropdown for TYPE_SELECT2');
     }
     parent::init();
     if ($this->type !== self::TYPE_SELECT2 && !empty($this->options['placeholder'])) {
         $this->data = ['' => $this->options['placeholder']] + $this->data;
     }
     if ($this->type === self::TYPE_SELECT2 && (!empty($this->options['placeholder']) || !empty($this->select2Options['options']['placeholder']))) {
         $this->pluginOptions['placeholder'] = '';
     } elseif ($this->type === self::TYPE_SELECT2 && !empty($this->pluginOptions['placeholder']) && $this->pluginOptions['placeholder'] !== false) {
         $this->options['placeholder'] = $this->pluginOptions['placeholder'];
         $this->pluginOptions['placeholder'] = '';
     }
     $this->_view = $this->getView();
     $this->registerAssets();
     if ($this->type === self::TYPE_SELECT2) {
         if (empty($this->data)) {
             $this->data = ['' => ''];
         }
         if ($this->hasModel()) {
             $settings = ArrayHelper::merge($this->select2Options, ['model' => $this->model, 'attribute' => $this->attribute, 'data' => $this->data, 'options' => $this->options]);
         } else {
             $settings = ArrayHelper::merge($this->select2Options, ['name' => $this->name, 'value' => $this->value, 'data' => $this->data, 'options' => $this->options]);
         }
         echo Select2::widget($settings);
         $id = 'jQuery("#' . $this->options['id'] . '")';
         $text = ArrayHelper::getValue($this->pluginOptions, 'loadingText', 'Loading ...');
         $this->_view->registerJs("{$id}.on('depdrop.beforeChange',function(e,i,v){{$id}.select2('data',{text: '{$text}'});});");
         $this->_view->registerJs("{$id}.on('depdrop.change',function(e,i,v,c){{$id}.select2('val',{$id}.val());});");
     } else {
         echo $this->getInput(!empty($this->typename) ? $this->typename : 'dropdownList', true);
     }
 }
Ejemplo n.º 7
0
 /**
  * Runs the widget
  *
  * @throws InvalidConfigException
  */
 public function run()
 {
     if (empty($this->pluginOptions['url'])) {
         throw new InvalidConfigException("The 'pluginOptions[\"url\"]' property has not been set.");
     }
     if (empty($this->pluginOptions['depends']) || !is_array($this->pluginOptions['depends'])) {
         throw new InvalidConfigException("The 'pluginOptions[\"depends\"]' property must be set and must be an array of dependent dropdown element identifiers.");
     }
     if (empty($this->options['class'])) {
         $this->options['class'] = 'form-control';
     }
     if ($this->type === self::TYPE_SELECT2) {
         Config::checkDependency('select2\\Select2', 'yii2-widget-select2', 'for dependent dropdown for Select2');
     }
     if ($this->type !== self::TYPE_SELECT2 && !empty($this->options['placeholder'])) {
         $this->data = ['' => $this->options['placeholder']] + $this->data;
     }
     $this->registerAssets();
 }
Ejemplo n.º 8
0
 /**
  * Converts markdown into HTML
  *
  * @param string $content
  * @param array  $config . Options to configure MarkdownExtra and smarty
  *  - markdown: array for MarkdownExtra configuration parameters
  *  - smarty: array for SmartyPantsTypographer configuration parameters
  *  - custom: array for Custom configuration parameters
  * @param int    $smartyMode the SmartyPantsTypographer processing mode
  *
  * @return string
  * @throws InvalidConfigException if module not set
  */
 public static function convert($content, $config = [], $smartyMode = self::SMARTYPANTS_ATTR_LONG_EM_DASH_SHORT_EN)
 {
     $module = Config::initModule(Module::classname());
     $output = $content;
     if (strlen($output) > 0) {
         $mdConfig = empty($config['markdown']) ? [] : $config['markdown'];
         $output = static::process($content, $mdConfig);
         if ($module->smartyPants) {
             $smConfig = empty($config['smarty']) ? [] : $config['smarty'];
             $smarty = new SmartyPantsTypographer($smartyMode);
             foreach ($smConfig as $name => $value) {
                 $smarty->{$name} = $value;
             }
             $output = $smarty->transform($output);
             $cuConfig = empty($config['custom']) ? $module->customConversion : $config['custom'];
             $output = static::customProcess($output, $cuConfig);
         }
     }
     return $output;
 }
Ejemplo n.º 9
0
 /**
  * Gets the module
  *
  * @param string $module the module name
  *
  * @return Module
  */
 public static function fetchModule($module = self::MODULE)
 {
     return Config::getModule($module);
 }
Ejemplo n.º 10
0
 public function validateSettings()
 {
     if (!$this->hasModel() && ($this->name1 === null || $this->name2 === null)) {
         throw new InvalidConfigException("Either 'name1','name2' or 'attribute1', 'attribute2' with 'model' properties must be specified.");
     }
     if (!$this->_isInput && $this->type !== self::INPUT_WIDGET && !in_array($this->type, self::$_inputWidgets)) {
         throw new InvalidConfigException("Invalid value for 'type'. Must be one of the FieldRange::INPUT constants.");
     }
     if (isset($this->form) && $this->useAddons && !$this->form instanceof ActiveForm) {
         Config::checkDependency('form\\ActiveForm', ['yii2-widget-activeform', 'yii2-widgets'], "when 'useAddons' is set to true.");
         throw new InvalidConfigException("The 'form' property must be an instance of '\\kartik\\form\\ActiveForm' or '\\kartik\\widgets\\ActiveForm' when 'useAddons' is set to true.");
     }
     if (isset($this->form) && !$this->useAddons && !$this->form instanceof \yii\widgets\ActiveForm) {
         throw new InvalidConfigException("The 'form' property must be an instance of '\\yii\\widgets\\ActiveForm'.");
     }
     if (isset($this->form) && !$this->hasModel()) {
         throw new InvalidConfigException("The 'model' and 'attribute1', 'attribute2' property must be set when 'form' is set.");
     }
     if ($this->type === self::INPUT_WIDGET && empty($this->widgetClass)) {
         throw new InvalidConfigException("The 'widgetClass' property must be set for widget input type.");
     }
 }
Ejemplo n.º 11
0
 /**
  * Sets the locale using the locales configuration settings
  */
 protected function setLocale()
 {
     if (!$this->_doTranslate || !empty($this->pluginOptions['dateSettings'])) {
         return;
     }
     $s = DIRECTORY_SEPARATOR;
     $file = __DIR__ . "{$s}locales{$s}{$this->language}{$s}dateSettings.php";
     if (!file_exists($file)) {
         $langShort = Config::getLang($this->language);
         $file = __DIR__ . "{$s}locales{$s}$langShort{$s}dateSettings.php";
     }
     if (file_exists($file)) {
         $this->pluginOptions['dateSettings'] = require_once($file);
     }
 }
Ejemplo n.º 12
0
 /**
  * @inheritdoc
  * @throws InvalidConfigException
  */
 public function init()
 {
     parent::init();
     \kartik\base\Config::checkDependency('editable\\Editable', 'yii2-editable', 'for GridView EditableColumn');
     $this->_css = 'kv-edcol-' . hash('crc32', uniqid(rand(1, 100), true));
 }
Ejemplo n.º 13
0
 /**
  * Renders each form attribute
  *
  * @param array $config the attribute config
  *
  * @return mixed
  * @throws \yii\base\InvalidConfigException
  */
 protected function renderFormAttribute($config)
 {
     if (empty($config['attribute'])) {
         return '';
     }
     $model = ArrayHelper::getValue($config, 'editModel', $this->model);
     if (!$model instanceof Model) {
         $model = $this->model;
     }
     $attr = ArrayHelper::getValue($config, 'updateAttr', $config['attribute']);
     $input = ArrayHelper::getValue($config, 'type', self::INPUT_TEXT);
     $fieldConfig = ArrayHelper::getValue($config, 'fieldConfig', []);
     $inputWidth = ArrayHelper::getValue($config, 'inputWidth', '');
     $container = ArrayHelper::getValue($config, 'inputContainer', []);
     if ($inputWidth != '') {
         Html::addCssStyle($container, "width: {$inputWidth}");
         // deprecated since v1.7.4
     }
     $template = ArrayHelper::getValue($fieldConfig, 'template', "{input}\n{error}\n{hint}");
     $row = Html::tag('div', $template, $container);
     if (static::hasGridCol($container)) {
         $row = '<div class="row">' . $row . '</div>';
     }
     $fieldConfig['template'] = $row;
     if (substr($input, 0, 8) == "\\kartik\\") {
         Config::validateInputWidget($input, 'as an input widget for DetailView edit mode');
     } elseif ($input !== self::INPUT_WIDGET && !in_array($input, self::$_inputsList)) {
         throw new InvalidConfigException("Invalid input type '{$input}' defined for the attribute '" . $config['attribute'] . "'.");
     }
     $options = ArrayHelper::getValue($config, 'options', []);
     $widgetOptions = ArrayHelper::getValue($config, 'widgetOptions', []);
     $class = ArrayHelper::remove($widgetOptions, 'class', '');
     if (!empty($config['options'])) {
         $widgetOptions['options'] = $config['options'];
     }
     if (Config::isInputWidget($input)) {
         $class = $input;
         return $this->_form->field($model, $attr, $fieldConfig)->widget($class, $widgetOptions);
     }
     if ($input === self::INPUT_WIDGET) {
         if ($class == '') {
             throw new InvalidConfigException("Widget class not defined in 'widgetOptions' for {$input}'.");
         }
         return $this->_form->field($model, $attr, $fieldConfig)->widget($class, $widgetOptions);
     }
     if (in_array($input, self::$_dropDownInputs)) {
         $items = ArrayHelper::getValue($config, 'items', []);
         return $this->_form->field($model, $attr, $fieldConfig)->{$input}($items, $options);
     }
     if ($input == self::INPUT_HTML5_INPUT) {
         $inputType = ArrayHelper::getValue($config, 'inputType', self::INPUT_TEXT);
         return $this->_form->field($model, $attr, $fieldConfig)->{$input}($inputType, $options);
     }
     return $this->_form->field($model, $attr, $fieldConfig)->{$input}($options);
 }
Ejemplo n.º 14
0
 /**
  * @inheritdoc
  * @throws InvalidConfigException
  */
 public function run()
 {
     $this->initToggleData();
     $this->initExport();
     if ($this->export !== false && isset($this->exportConfig[self::PDF])) {
         \kartik\base\Config::checkDependency('mpdf\\Pdf', 'yii2-mpdf', "for PDF export functionality. To include PDF export, follow the install steps below. If you do not " . "need PDF export functionality, do not include 'PDF' as a format in the 'export' property. You can " . "otherwise set 'export' to 'false' to disable all export functionality");
     }
     $this->initHeader();
     $this->initBootstrapStyle();
     $this->containerOptions['id'] = $this->options['id'] . '-container';
     Html::addCssClass($this->containerOptions, 'kv-grid-container');
     $this->registerAssets();
     $this->renderPanel();
     $this->initLayout();
     $this->beginPjax();
     parent::run();
     $this->endPjax();
 }
Ejemplo n.º 15
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     $this->_module = Config::initModule(Module::classname());
     return [[['id', 'hiddenColumns', 'visibleColumns', 'pageSize', 'filterId', 'sortId', 'theme', 'hiddenKeys', 'visibleKeys'], 'safe'], [['pageSize', 'theme'], 'required'], ['pageSize', 'integer', 'min' => $this->_module->minPageSize, 'max' => $this->_module->maxPageSize], ['pageSize', 'default', 'value' => $this->_module->defaultPageSize], ['theme', 'default', 'value' => $this->_module->defaultTheme]];
 }
Ejemplo n.º 16
0
 /**
  * Renders each form attribute
  *
  * @param array $config the attribute config
  *
  * @return mixed
  * @throws \yii\base\InvalidConfigException
  */
 protected function renderFormAttribute($config)
 {
     if (empty($config['attribute'])) {
         return '';
     }
     $attr = ArrayHelper::getValue($config, 'updateAttr', $config['attribute']);
     $input = ArrayHelper::getValue($config, 'type', self::INPUT_TEXT);
     $fieldConfig = ArrayHelper::getValue($config, 'fieldConfig', []);
     $inputWidth = ArrayHelper::getValue($config, 'inputWidth', '');
     if ($inputWidth != '') {
         $template = ArrayHelper::getValue($fieldConfig, 'template', "{input}\n{error}\n{hint}");
         $fieldConfig['template'] = "<div style='width:{$inputWidth};'>{$template}</div>";
     }
     if (substr($input, 0, 8) == "\\kartik\\") {
         Config::validateInputWidget($input, 'as an input widget for DetailView edit mode');
     } elseif ($input !== self::INPUT_WIDGET && !in_array($input, self::$_inputsList)) {
         throw new InvalidConfigException("Invalid input type '{$input}' defined for the attribute '" . $config['attribute'] . "'.");
     }
     $options = ArrayHelper::getValue($config, 'options', []);
     $widgetOptions = ArrayHelper::getValue($config, 'widgetOptions', []);
     $class = ArrayHelper::remove($widgetOptions, 'class', '');
     if (!empty($config['options'])) {
         $widgetOptions['options'] = $config['options'];
     }
     if (Config::isInputWidget($input)) {
         $class = $input;
         return $this->_form->field($this->model, $attr, $fieldConfig)->widget($class, $widgetOptions);
     }
     if ($input === self::INPUT_WIDGET) {
         if ($class == '') {
             throw new InvalidConfigException("Widget class not defined in 'widgetOptions' for {$input}'.");
         }
         return $this->_form->field($this->model, $attr, $fieldConfig)->widget($class, $widgetOptions);
     }
     if (in_array($input, self::$_dropDownInputs)) {
         $items = ArrayHelper::getValue($config, 'items', []);
         return $this->_form->field($this->model, $attr, $fieldConfig)->{$input}($items, $options);
     }
     if ($input == self::INPUT_HTML5_INPUT) {
         $inputType = ArrayHelper::getValue($config, 'inputType', self::INPUT_TEXT);
         return $this->_form->field($this->model, $attr, $fieldConfig)->{$input}($inputType, $options);
     }
     return $this->_form->field($this->model, $attr, $fieldConfig)->{$input}($options);
 }
Ejemplo n.º 17
0
  /**
  * Registers the asset bundle and locale
  */
 protected function registerAssetBundle() {
     $view = $this->getView();
     if (!empty($this->language) && substr($this->language, 0, 2) != 'en') {
         $path = __DIR__ . '/lib';
         $file = "select2_locale_{$this->language}.js";
         if (!Config::fileExists("{$path}/{$file}")) {
             $file = "select2_locale_{$this->_lang}.js";
         }
         if (Config::fileExists("{$path}/{$file}")) {
             Select2Asset::register($view)->js[] = $file;
             return;
         }
     }
     Select2Asset::register($view);
 }
Ejemplo n.º 18
0
 /**
  * Checks if the filter input types are valid
  *
  * @return void
  */
 protected function checkValidFilters()
 {
     if (isset($this->filterType)) {
         \kartik\base\Config::validateInputWidget($this->filterType, 'for filtering the grid as per your setup');
     }
 }
Ejemplo n.º 19
0
 /**
  * Fetches the locale settings file.
  *
  * @param string $lang the locale/language ISO code.
  *
  * @return string the locale file name.
  */
 protected static function getLocaleFile($lang)
 {
     $s = DIRECTORY_SEPARATOR;
     $file = __DIR__ . "{$s}locales{$s}{$lang}{$s}dateSettings.php";
     if (!file_exists($file)) {
         $langShort = Config::getLang($lang);
         $file = __DIR__ . "{$s}locales{$s}{$langShort}{$s}dateSettings.php";
     }
     return $file;
 }
Ejemplo n.º 20
0
 /**
  * Renders all other HTML inputs (except HTML5)
  *
  * @return string
  */
 protected function renderInput()
 {
     $list = Config::isDropdownInput($this->inputType);
     $input = $this->inputType;
     if ($this->hasModel()) {
         if (isset($this->_form)) {
             return $list ? $this->_form->field($this->model, $this->attribute, $this->inputFieldConfig)->{$input}($this->data, $this->_inputOptions)->label(false) : $this->_form->field($this->model, $this->attribute, $this->inputFieldConfig)->{$input}($this->_inputOptions)->label(false);
         }
         $input = 'active' . ucfirst($this->inputType);
     }
     $checked = false;
     if ($input == 'radio' || $input == 'checkbox') {
         $this->options['value'] = $this->value;
         $checked = ArrayHelper::remove($this->_inputOptions, 'checked', false);
     }
     if ($list) {
         $field = Html::$input($this->name, $this->value, $this->data, $this->_inputOptions);
     } else {
         $field = $input == 'checkbox' || $input == 'radio' ? Html::$input($this->name, $checked, $this->_inputOptions) : Html::$input($this->name, $this->value, $this->_inputOptions);
     }
     return Html::tag('div', $field, $this->inputContainerOptions);
 }
Ejemplo n.º 21
0
 /**
  * Registers the asset bundle and locale
  */
 protected function registerAssetBundle()
 {
     $view = $this->getView();
     if (!empty($this->language) && substr($this->language, 0, 2) != 'en') {
         $path = Yii::getAlias('@vendor/kartik-v/bootstrap-fileinput/js');
         $file = "fileinput_locale_{$this->language}.js";
         if (!Config::fileExists("{$path}/{$file}")) {
             $file = "fileinput_locale_{$this->_lang}.js";
         }
         if (Config::fileExists("{$path}/{$file}")) {
             FileInputAsset::register($view)->js[] = 'js/' . $file;
             return;
         }
     }
     FileInputAsset::register($view);
 }
Ejemplo n.º 22
0
 /**
  * Initializes options and settings
  * @throws InvalidConfigException
  */
 protected function initOptions()
 {
     if ($this->type == self::TYPE_GROWL) {
         Config::checkDependency('growl\\Growl', 'yii2-widget-growl', 'for rendering Growl notifications in the alert block');
     }
     if (empty($this->options['id'])) {
         $this->options['id'] = $this->getId();
     }
     if (!isset($this->delay)) {
         $this->delay = $this->type == self::TYPE_ALERT ? 2000 : 1200;
     }
     if (empty($this->alertSettings) && $this->type == self::TYPE_GROWL) {
         $this->alertSettings = ['error' => ['type' => Growl::TYPE_DANGER], 'success' => ['type' => Growl::TYPE_SUCCESS], 'info' => ['type' => Growl::TYPE_INFO], 'warning' => ['type' => Growl::TYPE_WARNING], 'growl' => ['type' => Growl::TYPE_GROWL]];
     } elseif (empty($this->alertSettings)) {
         $this->alertSettings = ['error' => ['type' => Alert::TYPE_DANGER], 'success' => ['type' => Alert::TYPE_SUCCESS], 'info' => ['type' => Alert::TYPE_INFO], 'warning' => ['type' => Alert::TYPE_WARNING], 'primary' => ['type' => Alert::TYPE_PRIMARY], 'default' => ['type' => Alert::TYPE_DEFAULT]];
     }
 }
Ejemplo n.º 23
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     if (empty($this->model) || !$this->model instanceof Model) {
         throw new InvalidConfigException("You must enter a valid 'model' for DynaGridDetail.");
     }
     parent::init();
     $this->_module = Config::initModule(Module::classname());
     $this->_requestSubmit = $this->options['id'] . '-dynagrid-detail';
     $this->_isSubmit = !empty($_POST[$this->_requestSubmit]) && $this->model->load(Yii::$app->request->post()) && $this->model->validate();
     $this->registerAssets();
 }
Ejemplo n.º 24
0
 /**
  * Returns the tree view module
  *
  * @return Module
  */
 public static function module()
 {
     return Config::getModule(Module::MODULE);
 }
Ejemplo n.º 25
0
 /**
  * Initializes the widget
  *
  * @throws InvalidConfigException
  * @return void
  */
 public function init()
 {
     parent::init();
     if (empty($this->options['id'])) {
         throw new InvalidConfigException("You must setup a unique identifier for DynaGrid within \"options['id']\".");
     }
     $this->_module = Config::initModule(Module::classname());
     $this->_gridModalId = $this->options['id'] . '-grid-modal';
     $this->_filterModalId = $this->options['id'] . '-filter-modal';
     $this->_sortModalId = $this->options['id'] . '-sort-modal';
     $this->_filterKey = $this->options['id'] . '-filter-key';
     $this->_sortKey = $this->options['id'] . '-sort-key';
     $this->_pjaxId = $this->options['id'] . '-pjax';
     foreach ($this->_module->dynaGridOptions as $key => $setting) {
         if (is_array($setting) && !empty($setting) && !empty($this->{$key})) {
             $this->{$key} = ArrayHelper::merge($setting, $this->{$key});
         } elseif (!isset($this->{$key})) {
             $this->{$key} = $setting;
         }
     }
     if (empty($this->columns) || !is_array($this->columns)) {
         throw new InvalidConfigException("The 'columns' configuration must be setup as a valid array.");
     }
     if (empty($this->gridOptions['dataProvider']) && empty($this->gridOptions['filterModel'])) {
         throw new InvalidConfigException("You must setup either the gridOptions['filterModel'] or gridOptions['dataProvider'].");
     }
     if (!empty($this->gridOptions['filterModel']) && !method_exists($this->gridOptions['filterModel'], 'search')) {
         throw new InvalidConfigException("The gridOptions['filterModel'] must implement a 'search' method in order to apply saved filters.");
     }
     if (empty($this->gridOptions['dataProvider'])) {
         $this->initDataProvider($this->gridOptions['filterModel']);
     }
     if (empty($this->gridOptions['filterModel'])) {
         $this->showFilter = false;
         $this->allowFilterSetting = false;
     }
     if (empty($this->theme)) {
         $this->theme = $this->_module->defaultTheme;
     }
     if (empty($this->_pageSize)) {
         $this->_pageSize = $this->_module->defaultPageSize;
     }
     $this->_requestSubmit = $this->options['id'] . '-dynagrid';
     $this->_model = new DynaGridConfig();
     $this->_isSubmit = !empty($_POST[$this->_requestSubmit]) && $this->_model->load(Yii::$app->request->post()) && $this->_model->validate();
     $this->_store = new DynaGridStore(['id' => $this->options['id'], 'storage' => $this->storage, 'userSpecific' => $this->userSpecific]);
     $this->prepareColumns();
     $this->configureColumns();
     $this->applyGridConfig();
     $this->_isPjax = ArrayHelper::getValue($this->gridOptions, 'pjax', false);
     if ($this->_isPjax) {
         $this->gridOptions['pjaxSettings']['options']['id'] = $this->_pjaxId;
     }
     $this->initGrid();
 }
Ejemplo n.º 26
0
 /**
  * Initialize the widget
  */
 public function init()
 {
     parent::init();
     $this->_module = Config::initModule(Module::classname());
     $this->generateId();
     $this->generateMessages();
     $this->registerAssets();
     echo Html::beginTag('div', $this->containerOptions);
     echo Html::beginTag('div', $this->editorOptions);
     echo $this->renderHeader();
     echo $this->renderInput();
     echo $this->renderFooter();
 }
Ejemplo n.º 27
0
 /**
  * Sets the language JS file if it exists
  *
  * @param string $assetPath the path to the assets
  * @param string $filePath the path to the JS file with the file name prefix
  * @param string $suffix the file name suffix - defaults to '.js'
  */
 protected function setLanguage($prefix, $assetPath = null, $filePath = null, $suffix = '.js')
 {
     $pwd = Config::getCurrentDir($this);
     $s = DIRECTORY_SEPARATOR;
     if ($assetPath === null) {
         $assetPath = "{$pwd}{$s}assets{$s}";
     } elseif (substr($assetPath, -1) != $s) {
         $assetPath .= $s;
     }
     if ($filePath === null) {
         $filePath = "js{$s}locales{$s}";
     } elseif (substr($filePath, -1) != $s) {
         $filePath .= $s;
     }
     $full = $filePath . $prefix . $this->language . $suffix;
     $fullLower = $filePath . $prefix . strtolower($this->language) . $suffix;
     $short = $filePath . $prefix . $this->_lang . $suffix;
     if (Config::fileExists($assetPath . $full)) {
         $this->_langFile = $full;
         $this->pluginOptions['language'] = $this->language;
     } elseif (Config::fileExists($assetPath . $fullLower)) {
         $this->_langFile = $fullLower;
         $this->pluginOptions['language'] = strtolower($this->language);
     } elseif (Config::fileExists($assetPath . $short)) {
         $this->_langFile = $short;
         $this->pluginOptions['language'] = $this->_lang;
     } else {
         $this->_langFile = '';
     }
     $this->_langFile = str_replace($s, '/', $this->_langFile);
 }
Ejemplo n.º 28
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     $this->_module = Config::initModule(Module::classname());
 }
Ejemplo n.º 29
0
 /**
  * @inheritdoc
  * @throws InvalidConfigException
  */
 public function init()
 {
     parent::init();
     \kartik\base\Config::checkDependency('editable\Editable', 'yii2-editable', 'for GridView EditableColumn');
 }
Ejemplo n.º 30
0
 /**
  * Renders filter inputs based on the `filterType`
  *
  * @return string
  */
 protected function renderFilterCellContent()
 {
     $content = parent::renderFilterCellContent();
     $chkType = !empty($this->filterType) && $this->filterType !== GridView::FILTER_CHECKBOX && $this->filterType !== GridView::FILTER_RADIO && !class_exists($this->filterType);
     if ($this->filter === false || empty($this->filterType) || $content === $this->grid->emptyCell || $chkType) {
         return $content;
     }
     $widgetClass = $this->filterType;
     $options = ['model' => $this->grid->filterModel, 'attribute' => $this->attribute, 'options' => $this->filterInputOptions];
     if (is_array($this->filter)) {
         if (Config::isInputWidget($this->filterType) && $this->grid->pjax) {
             $options['pjaxContainerId'] = $this->grid->pjaxSettings['options']['id'];
         }
         if ($this->filterType === GridView::FILTER_SELECT2 || $this->filterType === GridView::FILTER_TYPEAHEAD) {
             $options['data'] = $this->filter;
         }
         if ($this->filterType === GridView::FILTER_RADIO) {
             return Html::activeRadioList($this->grid->filterModel, $this->attribute, $this->filter, $this->filterInputOptions);
         }
     }
     if ($this->filterType === GridView::FILTER_CHECKBOX) {
         return Html::activeCheckbox($this->grid->filterModel, $this->attribute, $this->filterInputOptions);
     }
     $options = ArrayHelper::merge($this->filterWidgetOptions, $options);
     /** @var \kartik\base\Widget $widgetClass */
     return $widgetClass::widget($options);
 }