Exemplo n.º 1
6
 /**
  * Ham tao giao dien cho column
  * @param string $keyColumn ten truong cua column
  * @param array $column mang setting cua column
  * @param array $gallery mang gia tri cua image
  * @param string $id id cua 1 anh
  * @param string $tdOptions Html Attribute of td column
  * @return string
  */
 private function generateColumnByType($keyColumn, $column, $gallery, $id, $tdOptions = [], $module, $attribute)
 {
     $typeImage = ArrayHelper::getValue($column, 'displayType', 'text');
     $items = ArrayHelper::getValue($column, 'items', []);
     $options = ArrayHelper::getValue($column, 'options', ['class' => 'form-control']);
     $column_name = $module . '[' . $attribute . '][' . $id . '][' . $keyColumn . ']';
     switch ($typeImage) {
         case self::SYA_TYPE_COLUMN_DROPDOWN:
             $template = Html::dropDownList($column_name, ArrayHelper::getValue($gallery, $keyColumn), $items, $options);
             break;
         case self::SYA_TYPE_COLUMN_TEXTAREA:
             $template = Html::textarea($column_name, ArrayHelper::getValue($gallery, $keyColumn), $options);
             break;
         case self::SYA_TYPE_COLUMN_RADIO:
             $template = Html::radio($column_name, ArrayHelper::getValue($gallery, $keyColumn), $options);
             break;
         case self::SYA_TYPE_COLUMN_RADIOLIST:
             $template = Html::radioList($column_name, ArrayHelper::getValue($gallery, $keyColumn), $items, $options);
             break;
         case self::SYA_TYPE_COLUMN_CHECKBOX:
             $template = Html::checkbox($column_name, ArrayHelper::getValue($gallery, $keyColumn), $options);
             break;
         case self::SYA_TYPE_COLUMN_CHECKBOXLIST:
             $template = Html::checkboxList($column_name, ArrayHelper::getValue($gallery, $keyColumn), $items, $options);
             break;
         case self::SYA_TYPE_COLUMN_HIDDEN:
             $tdOptions = ArrayHelper::merge($tdOptions, ['style' => 'display: none;']);
             $template = Html::hiddenInput($column_name, ArrayHelper::getValue($gallery, $keyColumn), $options);
             break;
         default:
             $template = Html::textInput($column_name, ArrayHelper::getValue($gallery, $keyColumn), $options);
             break;
     }
     $templateGallery = Html::beginTag('td', $tdOptions);
     $templateGallery .= $template;
     $templateGallery .= Html::endTag('td');
     return $templateGallery;
 }
 public function renderHtmlInput($input_type_id, $options = [])
 {
     $field = $options['prefix_text'] . " ";
     switch ($input_type_id) {
         case Types::$input_type['small_text']['id']:
             $field .= Html::textInput(sprintf('question_%s', $options['screening_question_id']), '', ['style' => 'width:60px']);
             break;
         case Types::$input_type['med_text']['id']:
             $field .= Html::textInput(sprintf('question_%s', $options['screening_question_id']), '', []);
             break;
         case Types::$input_type['large_text']['id']:
             $field .= Html::textInput(sprintf('question_%s', $options['screening_question_id']), '', ['style' => 'width:240px']);
             break;
         case Types::$input_type['date']['id']:
             $field = sprintf('');
             break;
         case Types::$input_type['radio']['id']:
             // Enable tristate behavior with custom indeterminate value, custom toggle icon, and a custom label for the indeterminate state.
             $options['tristate_option_id'] == Types::$boolean['true']['id'] ? $tristate = true : ($tristate = false);
             $field = Html::radioList(sprintf('question_%s', $options['screening_question_id']), Types::$boolean['null']['id'], [Types::$boolean['true']['description'] => Types::$boolean['true']['description'], Types::$boolean['false']['description'] => Types::$boolean['false']['description']], ['unselect' => Types::$boolean['null']['description'], 'separator' => '   ']);
             break;
         case Types::$input_type['text_agreement']['id']:
         case Types::$input_type['text_agreement']['id']:
             $field = Html::radioList(sprintf('question_%s', $options['screening_question_id']), Types::$boolean['null']['id'], [yii::t('app', 'Agree') => yii::t('app', 'Agree'), yii::t('app', 'Disagree') => yii::t('app', 'Disagree')], ['unselect' => Types::$boolean['null']['description'], 'separator' => '   ']);
             break;
             break;
         case Types::$input_type['image_overlay']['id']:
             $field = sprintf('image overlay');
             break;
     }
     $field .= " " . $options['suffix_text'];
     return $field;
 }
Exemplo n.º 3
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']);
     }
 }
Exemplo n.º 4
0
 /**
  * Ham get html cho input theo type
  * @param string $type input co the la text, textarea, editor, date, datetime, daterange, dropdown, checkbox, radio
  * @param string $templateSetting giao dien input theo type
  * @param string $keySetting ten cua key setting
  * @param string $value gia tri cua key setting
  * @param array $items Mang cac gia tri cua setting neu setting co type la dropdown, checkbox, radio
  * @return string
  */
 private static function getInputByType($type = 'text', $templateSetting = null, $keySetting = null, $value = null, $items = [])
 {
     switch ($type) {
         case 'textarea':
             $templateSetting = Html::textarea($keySetting, $value, ['class' => 'form-control', 'title' => $keySetting]);
             break;
         case 'date':
             $templateSetting = DateControl::widget(['name' => $keySetting, 'value' => $value, 'type' => DateControl::FORMAT_DATE, 'ajaxConversion' => false, 'options' => ['pluginOptions' => ['autoclose' => true], 'options' => ['title' => $keySetting]], 'displayFormat' => 'dd-MM-yyyy', 'saveFormat' => 'yyyy-MM-dd']);
             break;
         case 'datetime':
             $templateSetting = DateControl::widget(['name' => $keySetting, 'value' => $value, 'type' => DateControl::FORMAT_DATETIME, 'ajaxConversion' => false, 'options' => ['pluginOptions' => ['autoclose' => true], 'options' => ['title' => $keySetting]], 'saveFormat' => 'yyyy-MM-dd']);
             break;
         case 'daterange':
             $templateSetting = DateRangePicker::widget(['name' => $keySetting, 'value' => $value, 'presetDropdown' => true, 'hideInput' => true, 'options' => ['title' => $keySetting]]);
             break;
         case 'dropdown':
             $templateSetting = Html::dropDownList($keySetting, $value, $items, ['class' => 'form-control', 'title' => $keySetting]);
             break;
         case 'checkbox':
             $templateSetting = Html::checkboxList($keySetting, $value, $items, ['class' => 'form-control', 'title' => $keySetting]);
             break;
         case 'radio':
             $templateSetting = Html::radioList($keySetting, $value, $items, ['class' => 'form-control', 'title' => $keySetting]);
             break;
         default:
             $templateSetting = Html::textInput($keySetting, $value, ['class' => 'form-control', 'title' => $keySetting]);
             break;
     }
     return $templateSetting;
 }
Exemplo n.º 5
0
     echo Html::beginTag('label', ['class' => 'col-sm-2 control-label']);
     echo ucfirst(Yii::t($model->module, $model->key));
     echo Html::a('', ['setting/update', 'id' => $model->_id], ['class' => 'glyphicon glyphicon-cog m-l-xs']);
     echo Html::endTag('label');
     echo Html::beginTag('div', ['class' => 'col-sm-10']);
     if ($model->type === 'text') {
         echo Html::textInput('setting[' . (string) $model->_id . ']', $model->value, ['class' => 'form-control']);
     } else {
         if ($model->type === 'dropdown') {
             echo Html::dropDownList('setting[' . (string) $model->_id . ']', $model->value, $model->items, ['class' => 'form-control']);
         } else {
             if ($model->type === 'checkbox') {
                 echo Html::checkboxList('setting[' . (string) $model->_id . ']', $model->value, $model->items, ['class' => 'i-checks', 'separator' => '<br />']);
             } else {
                 if ($model->type === 'radio') {
                     echo Html::radioList('setting[' . (string) $model->_id . ']', $model->value, $model->items, ['class' => 'i-checks', 'separator' => '<br />']);
                 }
             }
         }
     }
     echo Html::endTag('div');
     echo Html::endTag('div');
     echo Html::beginTag('div', ['class' => 'hr-line-dashed']);
     echo Html::endTag('div');
 }
 ActiveForm::end();
 ?>
             </div>
         </div>
     </div>
 </div>