public function color($options = []) { $this->parts['{input}'] = ColorInput::widget(['model' => $this->model, 'attribute' => $this->attribute, 'options' => $options]); return $this; }
/** * @param null $options * @param null $pluginOptions * * @return string * @throws \Exception */ public function getItem($options = null, $pluginOptions = null) { switch ($this->type) { case self::TYPE_TEXT: return Html::input('text', 'Setting[' . $this->code . ']', $this->value, $options != null ? $options : ['placeholder' => $this->getName(), 'class' => 'form-control']); case self::TYPE_EMAIL: return Html::input('email', 'Setting[' . $this->code . ']', $this->value, $options != null ? $options : ['placeholder' => $this->getName(), 'class' => 'form-control']); case self::TYPE_NUMBER: return Html::input('number', 'Setting[' . $this->code . ']', $this->value, $options != null ? $options : ['placeholder' => $this->getName(), 'class' => 'form-control']); case self::TYPE_TEXTAREA: return Html::textarea('Setting[' . $this->code . ']', $this->value, $options != null ? $options : ['placeholder' => $this->getName(), 'class' => 'form-control']); case self::TYPE_COLOR: return ColorInput::widget(['value' => $this->value, 'name' => 'Setting[' . $this->code . ']', 'options' => $options != null ? $options : ['class' => 'form-control']]); case self::TYPE_DATE: return DatePicker::widget(['name' => 'Setting[' . $this->code . ']', 'value' => $this->value, 'options' => $options != null ? $options : ['class' => 'form-control'], 'pluginOptions' => $pluginOptions != null ? $pluginOptions : ['format' => 'yyyy-mm-dd', 'todayHighlight' => true]]); case self::TYPE_TIME: return TimePicker::widget(['name' => 'Setting[' . $this->code . ']', 'value' => $this->value, 'options' => $options != null ? $options : ['class' => 'form-control'], 'pluginOptions' => $pluginOptions != null ? $pluginOptions : ['minuteStep' => 1, 'showSeconds' => true, 'showMeridian' => false]]); case self::TYPE_DATETIME: return DateTimePicker::widget(['name' => 'Setting[' . $this->code . ']', 'value' => $this->value, 'options' => $options != null ? $options : ['class' => 'form-control'], 'pluginOptions' => ['format' => 'yyyy-mm-dd H:i:s', 'todayHighlight' => true]]); case self::TYPE_PASSWORD: return PasswordInput::widget(['name' => 'Setting[' . $this->code . ']', 'value' => $this->value, 'options' => $options != null ? $options : ['class' => 'form-control'], 'pluginOptions' => $pluginOptions != null ? $pluginOptions : ['showMeter' => true, 'toggleMask' => false]]); case self::TYPE_ROXYMCE: return RoxyMceWidget::widget(['id' => 'Setting_' . $this->code, 'name' => 'Setting[' . $this->code . ']', 'value' => $this->value, 'action' => Url::to(['roxymce/default']), 'options' => $options != null ? $options : ['title' => $this->getName()], 'clientOptions' => $pluginOptions != null ? $pluginOptions : []]); case self::TYPE_SELECT: return Select2::widget(['value' => $this->value, 'name' => 'Setting[' . $this->code . ']', 'data' => $this->getStoreRange(), 'options' => $options != null ? $options : ['class' => 'form-control'], 'pluginOptions' => ['allowClear' => true]]); case self::TYPE_MULTI_SELECT: $options['multiple'] = true; if (!isset($options['class'])) { $options['class'] = 'form-control'; } return Select2::widget(['name' => 'Setting[' . $this->code . ']', 'value' => explode(",", $this->value), 'data' => $this->getStoreRange(), 'options' => $options, 'pluginOptions' => ['allowClear' => true]]); case self::TYPE_FILE_PATH: $value = Yii::getAlias($this->store_dir) . DIRECTORY_SEPARATOR . $this->value; return FileInput::widget(['name' => 'Setting[' . $this->code . ']', 'value' => $value, 'options' => $options != null ? $options : ['class' => 'form-control', 'multiple' => false], 'pluginOptions' => $pluginOptions != null ? $pluginOptions : ['previewFileType' => 'any', 'showRemove' => false, 'showUpload' => false, 'initialPreview' => !$this->isNewRecord ? [$this->value] : []]]); case self::TYPE_FILE_URL: $value = $this->store_url . '/' . $this->value; return FileInput::widget(['name' => 'Setting[' . $this->code . ']', 'value' => $value, 'options' => $options != null ? $options : ['class' => 'form-control'], 'pluginOptions' => $pluginOptions != null ? $pluginOptions : ['previewFileType' => 'any', 'showRemove' => false, 'showUpload' => false, 'initialPreviewAsData' => true, 'initialPreviewFileType' => self::fileType(pathinfo($this->value, PATHINFO_EXTENSION)), 'initialPreview' => !$this->isNewRecord ? $value : [], 'initialCaption' => $this->value]]); case self::TYPE_PERCENT: return RangeInput::widget(['name' => 'Setting[' . $this->code . ']', 'value' => $this->value, 'html5Options' => ['min' => 0, 'max' => 100, 'step' => 1], 'options' => $options != null ? $options : ['class' => 'form-control'], 'addon' => ['append' => ['content' => '%']]]); case self::TYPE_SWITCH: $selector = explode(',', $this->store_range); if (count($selector) != 2) { throw new ErrorException(Yii::t('setting', 'Switch Field should have store with 2 value, and negative is first. Example: no,yes'), 500); } return Html::hiddenInput('Setting[' . $this->code . ']', $selector[0]) . SwitchInput::widget(['name' => 'Setting[' . $this->code . ']', 'value' => $selector[1], 'containerOptions' => ['class' => 'nv-switch-container'], 'options' => $options != null ? $options : [], 'pluginOptions' => $pluginOptions != null ? $pluginOptions : ['state' => $this->value == $selector[1], 'size' => 'small', 'offText' => ucfirst($selector[0]), 'onText' => ucfirst($selector[1])]]); case self::TYPE_CHECKBOX: $random = rand(1000, 9999); return Html::checkboxList('Setting[' . $this->code . ']', explode(",", $this->value), $this->getStoreRange(), $options != null ? $options : ['class' => 'nv-checkbox-list checkbox', 'item' => function ($index, $label, $name, $checked, $value) use($random) { $html = Html::beginTag('div'); $html .= Html::checkbox($name, $checked, ['id' => 'Setting_checkbox_' . $label . '_' . $index . '_' . $random, 'value' => $value]); $html .= Html::label($label, 'Setting_checkbox_' . $label . '_' . $index . '_' . $random); $html .= Html::endTag('div'); return $html; }]); case self::TYPE_RADIO: $random = rand(1000, 9999); return Html::radioList('Setting[' . $this->code . ']', $this->value, $this->getStoreRange(), $options != null ? $options : ['class' => 'nv-checkbox-list radio', 'item' => function ($index, $label, $name, $checked, $value) use($random) { $html = Html::beginTag('div'); $html .= Html::radio($name, $checked, ['id' => 'Setting_radio_' . $label . '_' . $index . '_' . $random, 'value' => $value]); $html .= Html::label($label, 'Setting_radio_' . $label . '_' . $index . '_' . $random); $html .= Html::endTag('div'); return $html; }]); case self::TYPE_SEPARATOR: return '<hr>'; default: return Html::input('text', 'Setting[' . $this->code . ']', $this->value, $options != null ? $options : ['placeholder' => $this->getName(), 'class' => 'form-control']); } }
?> <?php echo $form->field($model, 'color')->widget(\kartik\widgets\ColorInput::className(), ['options' => ['placeholder' => '请设置颜色...']]); ?> <?php echo $form->field($model, 'backgroundColor')->widget(\kartik\widgets\ColorInput::className(), ['options' => ['placeholder' => '请设置颜色...']]); ?> <?php echo $form->field($model, 'borderColor')->widget(\kartik\widgets\ColorInput::className(), ['options' => ['placeholder' => '请设置颜色...']]); ?> <?php echo $form->field($model, 'textColor')->widget(\kartik\widgets\ColorInput::className(), ['options' => ['placeholder' => '请设置颜色...']]); ?> <?php echo $form->field($model, 'allDay')->widget(\kartik\widgets\SwitchInput::className(), ['pluginOptions' => ['onText' => '是', 'offText' => '否', 'onColor' => 'success', 'offColor' => 'danger']]); ?> <?php echo $form->field($model, 'editable')->widget(\kartik\widgets\SwitchInput::className(), ['pluginOptions' => ['onText' => '是', 'offText' => '否', 'onColor' => 'success', 'offColor' => 'danger']]); ?> <?php echo $form->field($model, 'startEditable')->widget(\kartik\widgets\SwitchInput::className(), ['pluginOptions' => ['onText' => '是', 'offText' => '否', 'onColor' => 'success', 'offColor' => 'danger']]); ?> <?php
use kartik\icons\Icon; ?> <div class="row"> <div class="col-md-5 col-sm-12"> <?php BackendWidget::begin(['title' => Yii::t('app', 'Colors'), 'options' => ['class' => 'visible-header']]); ?> <?php echo $form->field($model, 'primary_color')->widget(\kartik\widgets\ColorInput::className()); ?> <?php echo $form->field($model, 'secondary_color')->widget(\kartik\widgets\ColorInput::className()); ?> <?php echo $form->field($model, 'action_color')->widget(\kartik\widgets\ColorInput::className()); ?> <?php BackendWidget::end(); ?> </div> <div class="col-md-5 col-sm-12"> <?php BackendWidget::begin(['title' => Yii::t('app', 'Site settings'), 'options' => ['class' => 'visible-header']]); ?> <?php echo $form->field($model, 'siteName'); ?> <?php
?> <?php echo $form->field($model, 'id'); ?> <?php echo $form->field($model, 'name'); ?> <?php echo $form->field($model, 'color')->widget(ColorInput::className(), ['options' => ['placeholder' => Yii::t('backend/status', 'Select color ...')], 'pluginOptions' => ['chooseText' => Yii::t('backend/status', 'Choose'), 'cancelText' => Yii::t('backend/status', 'Cancel')]]); ?> <?php echo $form->field($model, 'background')->widget(ColorInput::className(), ['options' => ['placeholder' => Yii::t('backend/status', 'Select color ...')], 'pluginOptions' => ['chooseText' => Yii::t('backend/status', 'Choose'), 'cancelText' => Yii::t('backend/status', 'Cancel')]]); ?> <div class="form-group"> <?php echo Html::submitButton(Yii::t('backend/status', 'Search'), ['class' => 'btn btn-primary']); ?> <?php echo Html::resetButton(Yii::t('backend/status', 'Reset'), ['class' => 'btn btn-default']); ?> </div> <?php ActiveForm::end(); ?>
<?php $colorPluginOptions = ['showPalette' => true, 'showPaletteOnly' => true, 'showSelectionPalette' => true, 'showAlpha' => false, 'allowEmpty' => false, 'preferredFormat' => 'name', 'palette' => [["white", "black", "grey", "silver", "gold", "brown"], ["red", "orange", "yellow", "indigo", "maroon", "pink"], ["blue", "green", "violet", "cyan", "magenta", "purple"]]]; $gridColumns = [['class' => 'kartik\\grid\\SerialColumn', 'contentOptions' => ['class' => 'kartik-sheet-style'], 'width' => '36px', 'header' => '', 'headerOptions' => ['class' => 'kartik-sheet-style']], ['class' => 'kartik\\grid\\RadioColumn', 'width' => '36px', 'headerOptions' => ['class' => 'kartik-sheet-style']], ['class' => 'kartik\\grid\\ExpandRowColumn', 'width' => '50px', 'value' => function ($model, $key, $index, $column) { return GridView::ROW_COLLAPSED; }, 'detail' => function ($model, $key, $index, $column) { return Yii::$app->controller->renderPartial('_expand-row-details', ['model' => $model]); }, 'headerOptions' => ['class' => 'kartik-sheet-style'], 'expandOneOnly' => true], ['class' => 'kartik\\grid\\EditableColumn', 'attribute' => 'name', 'pageSummary' => 'Total', 'vAlign' => 'middle', 'width' => '210px', 'readonly' => function ($model, $key, $index, $widget) { return !$model->status; // do not allow editing of inactive records }, 'editableOptions' => function ($model, $key, $index) use($colorPluginOptions) { return ['header' => 'Name', 'size' => 'md', 'afterInput' => function ($form, $widget) use($model, $index, $colorPluginOptions) { return $form->field($model, "color")->widget(\kartik\widgets\ColorInput::classname(), ['showDefaultPalette' => false, 'options' => ['id' => "color-{$index}"], 'pluginOptions' => $colorPluginOptions]); }]; }], ['attribute' => 'color', 'value' => function ($model, $key, $index, $widget) { return "<span class='badge' style='background-color: {$model->color}'> </span> <code>" . $model->color . '</code>'; }, 'width' => '8%', 'filterType' => GridView::FILTER_COLOR, 'filterWidgetOptions' => ['showDefaultPalette' => false, 'pluginOptions' => $colorPluginOptions], 'vAlign' => 'middle', 'format' => 'raw', 'noWrap' => $this->noWrapColor], ['attribute' => 'author_id', 'vAlign' => 'middle', 'width' => '180px', 'value' => function ($model, $key, $index, $widget) { return Html::a($model->author->name, '#', ['title' => 'View author detail', 'onclick' => 'alert("This will open the author page.\\n\\nDisabled for this demo!")']); }, 'filterType' => GridView::FILTER_SELECT2, 'filter' => ArrayHelper::map(Author::find()->orderBy('name')->asArray()->all(), 'id', 'name'), 'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true]], 'filterInputOptions' => ['placeholder' => 'Any author'], 'format' => 'raw'], ['class' => 'kartik\\grid\\EditableColumn', 'attribute' => 'publish_date', 'hAlign' => 'center', 'vAlign' => 'middle', 'width' => '9%', 'format' => 'date', 'xlFormat' => "mmm\\-dd\\, \\-yyyy", 'headerOptions' => ['class' => 'kv-sticky-column'], 'contentOptions' => ['class' => 'kv-sticky-column'], 'readonly' => function ($model, $key, $index, $widget) { return !$model->status; // do not allow editing of inactive records }, 'editableOptions' => ['header' => 'Publish Date', 'size' => 'md', 'inputType' => \kartik\editable\Editable::INPUT_WIDGET, 'widgetClass' => 'kartik\\datecontrol\\DateControl', 'options' => ['type' => \kartik\datecontrol\DateControl::FORMAT_DATE, 'displayFormat' => 'dd.MM.yyyy', 'saveFormat' => 'php:Y-m-d', 'options' => ['pluginOptions' => ['autoclose' => true]]]]], ['class' => 'kartik\\grid\\EditableColumn', 'attribute' => 'buy_amount', 'readonly' => function ($model, $key, $index, $widget) { return !$model->status; // do not allow editing of inactive records }, 'editableOptions' => ['header' => 'Buy Amount', 'inputType' => \kartik\editable\Editable::INPUT_SPIN, 'options' => ['pluginOptions' => ['min' => 0, 'max' => 5000]]], 'hAlign' => 'right', 'vAlign' => 'middle', 'width' => '7%', 'format' => ['decimal', 2], 'pageSummary' => true], ['attribute' => 'sell_amount', 'vAlign' => 'middle', 'hAlign' => 'right', 'width' => '7%', 'format' => ['decimal', 2], 'pageSummary' => true], ['class' => 'kartik\\grid\\FormulaColumn', 'header' => 'Buy + Sell<br>(BS)', 'vAlign' => 'middle', 'value' => function ($model, $key, $index, $widget) { $p = compact('model', 'key', 'index'); return $widget->col(7, $p) + $widget->col(8, $p); }, 'headerOptions' => ['class' => 'kartik-sheet-style'], 'hAlign' => 'right', 'width' => '7%', 'format' => ['decimal', 2], 'mergeHeader' => true, 'pageSummary' => true, 'footer' => true], ['class' => 'kartik\\grid\\FormulaColumn', 'header' => 'Buy %<br>(100 * B/BS)', 'vAlign' => 'middle', 'hAlign' => 'right', 'width' => '7%', 'value' => function ($model, $key, $index, $widget) { $p = compact('model', 'key', 'index'); return $widget->col(9, $p) != 0 ? $widget->col(7, $p) * 100 / $widget->col(9, $p) : 0; }, 'format' => ['decimal', 2], 'headerOptions' => ['class' => 'kartik-sheet-style'], 'mergeHeader' => true, 'pageSummary' => true, 'pageSummaryFunc' => GridView::F_AVG, 'footer' => true], ['class' => 'kartik\\grid\\BooleanColumn', 'attribute' => 'status', 'vAlign' => 'middle'], ['class' => 'kartik\\grid\\ActionColumn', 'dropdown' => $this->dropdown, 'dropdownOptions' => ['class' => 'pull-right'], 'urlCreator' => function ($action, $model, $key, $index) {
if ($model->type == 0) { echo Html::textInput('Settings[' . $model->id . ']', $model->value, ['class' => 'form-control', 'placeholder' => $model->default]); } elseif ($model->type == 1) { echo Html::textarea('Settings[' . $model->id . ']', $model->value, ['class' => 'form-control', 'rows' => 3]); } elseif ($model->type == 2) { echo CKEditor::widget(['id' => 'Settings' . $model->id, 'name' => 'Settings[' . $model->id . ']', 'value' => $model->value, 'editorOptions' => ElFinder::ckeditorOptions('elfinder', ['language' => 'ru'])]); } elseif ($model->type == 3) { echo SwitchInput::widget(['name' => 'Settings[' . $model->id . ']', 'value' => (int) $model->value, 'pluginOptions' => ['onColor' => 'success', 'offColor' => 'danger']]); } elseif ($model->type == 4) { $pluginOptions = ['showPreview' => true, 'showCaption' => true, 'showRemove' => true, 'showUpload' => false, 'overwriteInitial' => true]; if (!empty($model->value)) { $pluginOptions['initialPreview'] = [Html::img("/files/settings/" . $model->value, ['class' => 'file-preview-image'])]; } echo FileInput::widget(['name' => 'Settings[' . $model->id . ']', 'language' => 'ru', 'pluginOptions' => $pluginOptions]); } elseif ($model->type == 5) { echo ColorInput::widget(['name' => 'Settings[' . $model->id . ']', 'value' => $model->value, 'options' => ['readonly' => true]]); } else { echo '<strong class="form-control">Не известный тип поля</strong>'; } ?> <span style="font-size: 12px;"><?php echo $model->desc; ?> </span> </div> </div> <?php } ?> </div> <?php