示例#1
0
 /**
  * @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']);
     }
 }
示例#2
0
</p>		
	</div>
    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>
    <hr/>    
    <?php 
$form = ActiveForm::begin();
?>
    
		<?php 
$opt = [];
foreach ($model as $porton) {
    $opt[] = ['label' => $porton->descripcion, 'value' => $porton->id];
}
echo SwitchInput::widget(['name' => 'eligeporton', 'type' => SwitchInput::RADIO, 'items' => $opt, 'value' => \Yii::$app->session->get('porton'), 'pluginOptions' => ['size' => 'large', 'onText' => 'SI', 'offText' => 'NO'], 'labelOptions' => ['style' => 'font-size: 16px']]);
//\Yii::$app->session->set('porton',1);
?>
		<hr/>
		<div class="form-group">
			<?php 
echo Html::submitButton('Confirmar la selección', ['class' => 'btn btn-primary']);
?>
		</div>		
	<?php 
ActiveForm::end();
?>
		
 
</div>
示例#3
0
文件: _form.php 项目: prasgema/cap
/* @var $this yii\web\View */
/* @var $model amilna\cap\models\Transaction */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="transaction-form">

    <?php 
$form = ActiveForm::begin();
?>
	
						
	<div class="pull-right">
	<?php 
echo Yii::t('app', 'Only Template?');
echo SwitchInput::widget(['name' => 'Transaction[template]', 'type' => SwitchInput::CHECKBOX]);
?>
	
	</div>
		
	<div class="row"></div>
		
	<div class="well">
		<div class="row">		
			<div class="col-sm-3">
		<?php 
/*= $form->field($model, 'time')->textInput() */
?>
		<?php 
echo $form->field($model, 'time')->widget(DateTimePicker::classname(), ['options' => ['placeholder' => 'Select transaction time ...', 'readonly' => true], 'removeButton' => false, 'convertFormat' => true, 'pluginOptions' => ['format' => 'yyyy-MM-dd HH:i:s', 'todayHighlight' => true]]);
?>
示例#4
0
        ?>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><?php 
        echo $model->label;
        ?>
</label>
                            <div class="col-sm-10">
                                <?php 
        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;
        ?>