Render a checkbox field

@param array $config An optional array with configuration options
@return  string  Html
968429
public function checkbox($config = array())
    {
        $config = new ObjectConfigJson($config);
        $config->append(array(
            'entity'  => null,
            'attribs' => array()
        ))->append(array(
            'column' => $config->entity->getIdentityKey()
        ));

        if($config->entity->isLockable() && $config->entity->isLocked())
        {
            $html = $this->createHelper('behavior')->tooltip();
            $html .= '<span class="k-icon-lock-locked"
                            data-k-tooltip
                            title="'.$this->createHelper('grid')->lock_message(array('entity' => $config->entity)).'">
                    </span>';
        }
        else
        {
            $column = $config->column;
            $value  = StringEscaper::attr($config->entity->{$column});

            $attribs = $this->buildAttributes($config->attribs);

            $html = '<input type="checkbox" class="k-js-grid-checkbox" name="%s[]" value="%s" %s />';
            $html = sprintf($html, $column, $value, $attribs);
        }

        return $html;
    }
1156247
public function dialog($config = array())
    {
        $config = new KObjectConfigJson($config);
        $config->append(array(
            'command' => NULL
        ));

        $html = $this->command($config);

        return $html;
    }
16063
public function display($config = array())
    {
        $config = new KObjectConfigJson($config);
        $config->append(array(
            'editor'    => null,
            'name'      => 'description',
            'value'     => '',
            'width'     => '100%',
            'height'    => '500',
            'cols'      => '75',
            'rows'      => '20',
            'buttons'   => true,
            'options'   => array()
        ));

        // Add editor styles and scripts in JDocument to page when rendering
        $this->getIdentifier('com:koowa.view.page.html')->getConfig()->append(['template_filters' => ['document']]);

        $editor  = JFactory::getEditor($config->editor);
        $options = KObjectConfig::unbox($config->options);

        $result = $editor->display($config->name, $config->value, $config->width, $config->height, $config->cols, $config->rows, KObjectConfig::unbox($config->buttons), $config->name, null, null, $options);
        
        // Some editors like CKEditor return inline JS. 
        $result = str_replace('<script', '<script data-inline', $result);

        return $result;
    }
445690
public function renderWidget( $config = [] ) {

		// Limit
		$limit = Yii::$app->request->getQueryParam( $this->limitParam );

		if( isset( $limit ) && in_array( $limit, $this->limits ) ) {

			$this->limit = $limit;
		}

		if( isset( $this->dataProvider ) ) {

			$this->dataProvider->pagination->pageSize = $this->limit;
		}

		// Layout
		$user		= Yii::$app->user->getIdentity();
		$uLayout	= $user->getDataConfigMeta( CoreGlobal::DATA_GRID_LAYOUT );
		$layout		= Yii::$app->request->getQueryParam( 'layout' );

		$gridLayout	= isset( $user ) && isset( $uLayout ) ? $uLayout : $this->layout;
		$gridLayout	= isset( $layout ) && in_array( $layout, [ 'data', 'table', 'list', 'card' ] ) ? $layout : $gridLayout;

		$gridLayout = $this->grid && $gridLayout == 'data' ? 'data' : $gridLayout;
		$gridLayout = $this->table && $gridLayout == 'table' ? 'table' : $gridLayout;
		$gridLayout = $this->list && $gridLayout == 'list' ? 'list' : $gridLayout;
		$gridLayout = $this->card && $gridLayout == 'card' ? 'card' : $gridLayout;

		$this->layout = $gridLayout;

		// Views
		$this->actionView = CodeGenUtil::isAbsolutePath( $this->actionView ) ? $this->actionView : "$this->template/$this->actionView";

		$sortHtml		= $this->sort ? $this->renderSort( $config ) : null;

		$searchHtml		= $this->search ? $this->renderSearch( $config ) : null;

		$filtersHtml	= $this->filter ? $this->renderFilters( $config ) : null;

		$bulkHtml		= $this->bulk ? $this->renderBulk( $config ) : null;

		$reportHtml		= $this->report ? $this->renderReport( $config ) : null;

		$headHtml		= $this->head ? $this->renderHead( $config, [ 'sortHtml' => $sortHtml, 'searchHtml' => $searchHtml, 'filtersHtml' => $filtersHtml, 'bulkHtml' => $bulkHtml ] ) : null;

		$optionsHtml	= $this->option ? $this->renderOptions( $config, [ 'sortHtml' => $sortHtml, 'searchHtml' => $searchHtml, 'filtersHtml' => $filtersHtml, 'bulkHtml' => $bulkHtml ] ) : null;

		$headerHtml		= $this->header ? $this->renderHeader( $config ) : null;

		$dataHtml		= $this->grid && $this->layout == 'data' ? $this->renderData( $config ) : null;
		$dataHtml		= $this->table && $this->layout == 'table' ? $this->renderData( $config ) : $dataHtml;

		$listHtml		= $this->list && $this->layout == 'list' ? $this->renderList( $config ) : null;

		$cardHtml		= $this->card && $this->layout == 'card' ? $this->renderCards( $config ) : null;

		$footerHtml		= $this->footer ? $this->renderFooter( $config ) : null;

		$gridView		= CodeGenUtil::isAbsolutePath( $this->gridView ) ? $this->gridView : "$this->template/$this->gridView";

		$widgetHtml = $this->render( $gridView, [
			'widget' => $this,
			'sortHtml' => $sortHtml, 'searchHtml' => $searchHtml, 'filtersHtml' => $filtersHtml,
			'bulkHtml' => $bulkHtml, 'reportHtml' => $reportHtml, 'headHtml' => $headHtml, 'optionsHtml' => $optionsHtml,
			'headerHtml' => $headerHtml, 'footerHtml' => $footerHtml,
			'dataHtml' => $dataHtml, 'listHtml' => $listHtml, 'cardHtml' => $cardHtml
		]);

		if( $this->wrap ) {

			return Html::tag( $this->wrapper, $widgetHtml, $this->options );
		}

        return $widgetHtml;
	}
495831
protected function processJSTemplateConfig($config)
    {
        $templates = [];
        
        foreach ($config as $key => $value) {
            
            if (is_integer($key)) {
                
                $templates[$value] = [
                    'vars' => $this->getJSVars(),
                    'id'   => $this->getHTMLID()
                ];
                
            } else {
                
                $templates[$key] = [
                    'vars' => $this->getJSTemplateVars(array_shift($value)),
                    'id'   => $this->getJSTemplateID(array_shift($value))
                ];
                
            }
            
        }
        
        return $templates;
    }
1043274
public function renderInfo( $config = [] ) {

		$infoView = CodeGenUtil::isAbsolutePath( $this->infoView, true ) ? $this->infoView : "$this->template/$this->infoView";

		return $this->render( $infoView, [ 'widget' => $this ] );
	}
1162523
public function optionlist($config = array())
    {
        $config = new ObjectConfigJson($config);
        $config->append(array(
            'options'   => array(),
            'name'      => 'id',
            'selected'  => null,
            'disabled'  => null,
            'translate' => false,
            'attribs'   => array('size' => 1),
        ));

        $html = array();

        $html[] = '<select name="'. $config->name .'" '. $this->buildAttributes($config->attribs) .'>';

        foreach($config->options as $group => $options)
        {
            if (is_numeric($group)) {
                $options = array($options);
            } else {
                $html[] = '<optgroup label="' . StringEscaper::attr($group) . '">';
            }

            foreach ($options as $option)
            {
                $value = $option->value;
                $label = $config->translate ? $this->getObject('translator')->translate( $option->label ) : $option->label;

                $extra = '';
                if(isset($option->disabled) && $option->disabled) {
                    $extra .= 'disabled="disabled"';
                }

                if(isset($option->attribs)) {
                    $extra .= ' '.$this->buildAttributes($option->attribs);
                }

                if(!is_null($config->selected))
                {
                    if ($config->selected instanceof ObjectConfig)
                    {
                        foreach ($config->selected as $selected)
                        {
                            $sel = is_object($selected) ? $selected->value : $selected;
                            if ((string) $value == (string) $sel)
                            {
                                $extra .= 'selected="selected"';
                                break;
                            }
                        }
                    }
                    else $extra .= ((string) $value == (string) $config->selected ? ' selected="selected"' : '');
                }

                $html[] = '<option value="'. $value .'" '.$extra.'>' . $label . '</option>';
            }

            if (!is_numeric($group)) {
                $html[] = '</optgroup>';
            }
        }

        $html[] = '</select>';

        return implode(PHP_EOL, $html);
    }
1017158
public function validator($config = array())
    {
        $config = new ObjectConfigJson($config);
        $config->append(array(
            'debug'    => \Kodekit::getInstance()->isDebug(),
            'selector' => '.k-js-form-controller',
            'options_callback' => null,
            'options'  => array(
                'ignoreTitle' => true,
                'onsubmit'    => false // We run the validation ourselves
            )
        ));

        $html = '';

        if(!static::isLoaded('validator'))
        {
            $html .= $this->kodekit();
            $html .= '<ktml:script src="assets://js/'.($config->debug ? 'build/' : 'min/').'jquery.validate.js" />';

            static::setLoaded('validator');
        }

        $options   = (string) $config->options;
        $signature = md5('validator-'.$config->selector.$config->options_callback.$options);

        if (!static::isLoaded($signature))
        {
            if ($config->options_callback) {
                $options = $config->options_callback.'('.$options.')';
            }

            $html .= "<script>
            kQuery(function($){
                $('$config->selector').on('k:validate', function(event){
                    if(!$(this).valid() || $(this).validate().pendingRequest !== 0) {
                        event.preventDefault();
                    }
                }).validate($options);
            });
            </script>";

            static::setLoaded($signature);
        }

        return $html;
    }
143490
private function inputStringGenerator($config)
    {
        $config = $this->prepareObjectValue($config);
        $population = $this->inputCalibrator->getPopulation($config);
        $checkType = $this->inputCalibrator->checkType($config, $this->inputGroups['checkbox']);
        $selected = $this->inputCalibrator->isSelected($config, $checkType);
        $custom = $this->inputCalibrator->getField($config, 'custom');
        $method = $this->getGeneratorMethod($config['inputType']);

        if (in_array($method, $this->standardMethods)) {
            $inputString = $this->htmlGenerator->$method($config, $population, $custom);
        } elseif (in_array($method, $this->selectedMethods)) {
            // add extra class

            $inputString = $this->htmlGenerator->$method($config, $selected, $custom);
        } elseif ($method === 'makeRelationship') {
            $inputString = $this->htmlGenerator->makeRelationship(
                $config,
                $this->inputCalibrator->getField($config, 'label', 'name'),
                $this->inputCalibrator->getField($config, 'value', 'id'),
                $custom
            );
        } else {
            $config = $this->prepareType($config);
            $inputString = $this->htmlGenerator->makeHTMLInputString($config);
        }

        return $inputString;
    }
558609
public function renderWidget( $config = [] ) {

		if( !isset( $this->title ) ) {

			switch( $this->template ) {

				case 'message': {

					$this->title = 'Message';

					break;
				}
				case 'success': {

					$this->title = 'Success';

					break;
				}
				case 'warning': {

					$this->title = 'Alert';

					break;
				}
				case 'error': {

					$this->title = 'Error';

					break;
				}
			}
		}

		if( !isset( $this->size ) ) {

			if( $this->modal && in_array( $this->template, [ 'message', 'success', 'warning', 'error' ] ) ) {

				$this->size = 'medium';
			}
		}

		$widgetHtml = $this->render( $this->template, [
			'widget' => $this
		]);

		return $widgetHtml;
	}
261303
public function render($config = array())
    {
        $config = new ObjectConfigJson($config);
        $config->append(array(
            'toolbar' => null,
            'attribs' => array('class' => array('k-toolbar', 'k-js-toolbar'))
        ));

        $html = '';
        if(isset($config->toolbar) && count($config->toolbar))
        {
            //Force the id
            $config->attribs['id'] = 'toolbar-'.$config->toolbar->getType();

            $html .= '<div '.$this->buildAttributes($config->attribs).'>';

            foreach ($config->toolbar as $command)
            {
                $name = $command->getName();

                if(method_exists($this, $name)) {
                    $html .= $this->$name(ObjectConfig::unbox($command));
                } else {
                    $html .= $this->command(ObjectConfig::unbox($command));
                }
            }

            $html .= '</div>';
        }

        return $html;
    }
358358
public function optionlist($config = array())
    {
        $config = new KObjectConfigJson($config);
        $config->append(array(
            'options'   => array(),
            'selected'  => null,
            'disabled'  => null,
            'translate' => false,
            'attribs'   => array('size' => 1),
        ));

        $html = array();

        $html[] = '<select name="'. $config->name .'" '. $this->buildAttributes($config->attribs) .'>';

        foreach($config->options as $group => $options)
        {
            if (is_numeric($group)) {
                $options = array($options);
            } else {
                $html[] = '<optgroup label="' . $this->getTemplate()->escape($group) . '">';
            }

            foreach ($options as $option)
            {
                $value = $option->value;
                $label = $config->translate ? $this->getObject('translator')->translate( $option->label ) : $option->label;

                $extra = '';
                if(isset($option->disabled) && $option->disabled) {
                    $extra .= 'disabled="disabled"';
                }

                if(isset($option->attribs)) {
                    $extra .= ' '.$this->buildAttributes($option->attribs);
                }

                if(!is_null($config->selected))
                {
                    if ($config->selected instanceof KObjectConfig)
                    {
                        foreach ($config->selected as $selected)
                        {
                            $sel = is_object($selected) ? $selected->value : $selected;
                            if ((string) $value == (string) $sel)
                            {
                                $extra .= 'selected="selected"';
                                break;
                            }
                        }
                    }
                    else $extra .= ((string) $value == (string) $config->selected ? ' selected="selected"' : '');
                }

                $html[] = '<option value="'. $value .'" '.$extra.'>' . $label . '</option>';
            }

            if (!is_numeric($group)) {
                $html[] = '</optgroup>';
            }
        }

        $html[] = '</select>';

        return implode(PHP_EOL, $html);
    }
395823
public function renderContainer( $config = [] ) {

		$containerView = CodeGenUtil::isAbsolutePath( $this->containerView, true ) ? $this->containerView : "$this->template/$this->containerView";

		return $this->render( $containerView, [ 'widget' => $this ] );
	}
218993
public function render($config = array())
    {
        $config = new KObjectConfigJson($config);
        $config->append(array(
            'toolbar' => null
        ));

        $html = '<ul class="k-navigation">';

        foreach ($config->toolbar->getCommands() as $command)
        {
            $command->append(array(
                'attribs' => array(
                    'href' => '#',
                    'class' => array()
                )
            ));

            if(!empty($command->href)) {
                $command->attribs['href'] = $this->getTemplate()->route($command->href);
            }

            $url = KHttpUrl::fromString($command->attribs->href);

            if (isset($url->query['view'])) {
                $command->attribs->class->append('k-navigation-'.$url->query['view']);
            }

            $attribs = clone $command->attribs;
            $attribs->class = implode(" ", KObjectConfig::unbox($attribs->class));

            $html .= '<li'.($command->active ? ' class="k-is-active"' : '').'>';
            $html .= '<a '.$this->buildAttributes($attribs).'>';
            $html .= $this->getObject('translator')->translate($command->label);
            $html .= '</a>';
            $html .= '</li>';
        }

        $html .= '</ul>';

        return $html;
    }
356223
public function formfield_select($config = array())
    {
        $config = new AnConfig($config);

        $config->append(array(
            'class' => 'input-block-level',
            'name' => '',
            'selected' => '',
            'description' => '',
            'id' => '',
            'label' => '',
            'options' => array(),
            'disabled' => false,
        ));

        return $this->_render('formfield_select', $config);
    }
560921
public function renderWidget( $config = [] ) {

		// Form and Fields
		if( !isset( $this->model ) && isset( $this->slug ) ) {

			$this->model = $this->modelService->getBySlugType( $this->slug, $this->type );
		}

		if( isset( $this->model ) && $this->model->isActive() ) {

			// fields and html
			$fieldsHtml		= FormUtil::getApixFieldsHtml( $this->model, $this->form, [ 'label' => $this->labels, 'modelName' => $this->formName ] );
			$captchaHtml	= null;

			// Views Path
			$formPath		= "$this->template/form";
			$captchaPath	= "$this->template/captcha";

			// submit url
			if( !isset( $this->ajaxUrl ) ) {

				$formSlug		= $this->model->slug;
				$this->ajaxUrl	= "form/$formSlug";
			}

			if( $this->model->captcha ) {

				$captchaHtml = $this->render( $captchaPath );
			}

			$formHtml = $this->render( $formPath, [ 'widget' => $this, 'fieldsHtml' => $fieldsHtml, 'captchaHtml' => $captchaHtml ] );

			// Prepare Form Options
			$modelOptions = !empty( $this->model->htmlOptions ) ? json_decode( $this->model->htmlOptions, true ) : [];

			$this->options = \yii\helpers\ArrayHelper::merge( $this->options, $modelOptions );

			$this->options[ 'action' ]			= $this->ajaxUrl;
			$this->options[ 'method' ]			= 'post';
			$this->options[ 'cmt-app' ]			= 'form';
			$this->options[ 'cmt-controller' ]	= 'form';
			$this->options[ 'cmt-action' ]		= 'default';

			if( !isset( $this->options[ 'class' ] ) ) {

				$this->options[ 'class' ] = 'cmg-form';
			}

			if( !isset( $this->options[ 'id' ] ) ) {

				$this->options[ 'id' ] = "frm-$this->slug";
			}

			if( isset( $this->cmtApp ) ) {

				$this->options[ 'cmt-app' ]	= $this->cmtApp;
			}

			if( isset( $this->cmtController ) ) {

				$this->options[ 'cmt-controller' ] = $this->cmtController;
			}

			if( isset( $this->cmtAction ) ) {

				$this->options[ 'cmt-action' ] = $this->cmtAction;
			}

			if( $this->wrap ) {

				return Html::tag( $this->wrapper, $formHtml, $this->options );
			}

			return $formHtml;
		}
		else {

			echo "<div class=\"warning\">Form not found or submission is disabled.</div>";
		}
	}
344052
public function renderWidget( $config = [] ) {

		$widgetHtml = $this->render( $this->template, [
			'login' => $this->login,
			'loginDisabled' => $this->loginDisabled,
			'loginMessage' => $this->loginMessage,
			'forgotPassword' => $this->forgotPassword,
			'registerDisabled' => $this->registerDisabled,
			'registerMessage' => $this->registerMessage,
			'register' => $this->register,
			'label' => $this->label,
			'fieldIcon' => $this->fieldIcon,
			'optionalFields' => $this->optionalFields,
			'actions' => $this->actions,
			'widget' => $this
		]);

		if( $this->wrap ) {

			return Html::tag( $this->wrapper, $widgetHtml, $this->options );
		}

		return $widgetHtml;
	}