Exemplo n.º 1
0
 public static function getSettingValue($code, $moduleName = null)
 {
     $settingFieldsModel = SettingFields::findOne(['setting_code' => $code]);
     if ($settingFieldsModel) {
         return $settingFieldsModel->chosen_value;
     } else {
         throw new Exception(\Yii::t('system', 'the ' . $moduleName . ' Module\'s setting code is not exist:' . $code));
     }
 }
Exemplo n.º 2
0
 /**
  * Lists all Setting models.
  * @return mixed
  */
 public function actionIndex()
 {
     $setting = Yii::createObject(Setting::className());
     if (Yii::$app->getRequest()->getIsPost()) {
         $setting_codes = Yii::$app->request->post('setting_code');
         foreach ($setting_codes as $setting_code => $chosen_value) {
             /** @var \star\system\models\SettingFields $settingField */
             $settingField = Yii::createObject(SettingFields::className());
             $settingField = $settingField::findOne(['setting_code' => $setting_code]);
             if (is_array($chosen_value)) {
                 $chosen_value = json_encode($chosen_value);
             }
             $settingField->chosen_value = $chosen_value;
             $settingField->save();
         }
     }
     return $this->render('index', ['setting' => $setting]);
 }
Exemplo n.º 3
0
    /**
     * get the config
     * @param \yii\bootstrap\ActiveForm $form
     * @param array $options
     * @return string
     */
    public function renderForm($form, $options = [])
    {
        $config = $this->getSystemConfig();
        $tabItems = [];
        foreach ($config as $tabKey => $tab) {
            $groupItems = [];
            foreach ($tab['groups'] as $groupKey => $group) {
                $groupContent = '';
                foreach ($group['fields'] as $fieldKey => $field) {
                    $inlineRadioListTemplate = "<label class = \"control-label col-sm-1\">" . $field['label'] . "</label>\n<div class=\"col-sm-11\">{input}\n{hint}\n{error}</div>";
                    $inlineCheckboxListTemplate = "<label class = \"control-label col-sm-1\">" . $field['label'] . "</label>\n<div class=\"col-sm-11\">{input}\n{hint}\n{error}</div>";
                    $options['template'] = "<label class = \"control-label col-sm-1\">" . $field['label'] . "</label>\n<div class=\"col-sm-11\">{input}\n<div style=\"width:60%\">{hint}\n</div>{error}</div>";
                    $fieldOptions = array_merge($options, ['options' => ['class' => 'form-group'], 'inputOptions' => ['name' => 'setting_code[' . $field['setting_code'] . ']']]);
                    /** @var \yii\bootstrap\ActiveField $activeField */
                    $fieldClass = Yii::createObject(SettingFields::className());
                    $fieldModel = $fieldClass::findOne(['setting_code' => $field['setting_code']]);
                    if ($field['inputType'] == 3) {
                        $fieldModel->chosen_value = json_decode($fieldModel->chosen_value, true);
                    }
                    $activeField = $form->field($fieldModel, 'chosen_value', $fieldOptions);
                    switch ($field['inputType']) {
                        case 3:
                            $activeField->inline()->checkboxList($field['value'], ['name' => 'setting_code[' . $field['setting_code'] . ']', 'template' => $inlineCheckboxListTemplate]);
                            break;
                        case 2:
                            $activeField->inline()->radioList($field['value'], ['name' => 'setting_code[' . $field['setting_code'] . ']', 'template' => $inlineRadioListTemplate]);
                            break;
                        case 1:
                            $activeField->textInput();
                            break;
                            //                        case 'select':
                            //                            $activeField->dropDownList($dataList);
                            //                            break;
                            //                        case 'textarea':
                            //                            $activeField->textarea();
                            //                            break;
                            //                        case 'password':
                            //                            $activeField->passwordInput();
                            //                            break;
                    }
                    if (isset($field['hint'])) {
                        $activeField->hint($field['hint']);
                    }
                    $groupContent .= $activeField->render();
                }
                $groupItems[$group['label']] = ['label' => $group['label'], 'content' => $groupContent];
            }
            $tabContent = Collapse::widget(['items' => $groupItems]);
            $tabItems[] = ['label' => $tab['label'], 'content' => $tabContent];
        }
        $js = <<<JS
var modelName = 'SettingModel'
\$(document).on('change', 'select, input[type=checkbox], input[type=radio]', function() {
    var name = \$(this).attr('name')
    var dataKey = name.substring(modelName.length + 1, name.length - 1);
    var dataValue = \$(this).val();
    if (\$('[data-depend-key='+dataKey+']').length) {
        \$('[data-depend-key='+dataKey+']').hide();
    }
    if (\$('[data-depend-key='+dataKey+'][data-depend-value='+dataValue+']').length) {
        \$('[data-depend-key='+dataKey+'][data-depend-value='+dataValue+']').show();
    }
});

\$('[data-depend-key]').each(function() {
    var input = \$(this);
    var valueInput = \$('[name="'+modelName+'['+input.data('depend-key')+']"]');
    if (valueInput.val() == input.data('depend-key')) {
        input.show();
    } else {
        input.hide();
    }
});
JS;
        Yii::$app->view->registerJs($js);
        return Tabs::widget(['items' => $tabItems]);
    }
Exemplo n.º 4
0
?>

            <h2><a id="add-row" href="javascript:void(0) ">添加属性值</a></h2>
            如果选择type是 radio或者Checklist, value填入的值需要是json数组,例子:{"1":"激活","2":"未激活"} 默认选择放在最后的值
            <fieldset>
                <legend>属性值</legend>
                <div class="PropValues">
                    <table id="add_prop" class="example">
                        <tr>
                            <th>移动</th>
                            <th>属性值名称</th>
                            <th>克隆</th>
                            <th>删除</th>
                        </tr>
                        <?php 
$SettingFieldsModel = Yii::createObject(\star\system\models\SettingFields::className());
if ($model->isNewRecord) {
    ?>
                            <tr id="add-template">
                                <td class="icons">
                                    <img class="drag-handle"
                                         src="<?php 
    echo $url;
    ?>
/img/drag.png"
                                         alt="click and drag to rearrange"/>
                                </td>
                                <td>
                                    <?php 
    echo Html::label(Yii::t('system', 'type') . ':');
    ?>