예제 #1
0
 /**
  * Register Script
  */
 public function registerScript()
 {
     ProfileFieldAssets::register($this->view);
     $widgets = self::getWidgets();
     $wgByTypes = ProfileField::itemAlias('field_type');
     foreach ($wgByTypes as $k => $v) {
         $wgByTypes[$k] = [];
     }
     foreach ($widgets[1] as $widget) {
         if (isset($widget['fieldType']) && count($widget['fieldType'])) {
             foreach ($widget['fieldType'] as $type) {
                 $c = explode("\\", $widget['name']);
                 array_push($wgByTypes[$type], $c[count($c) - 1]);
             }
         }
     }
     /** @var string $js */
     $js = "\n\n\tvar name = \$('#name'),\n\tvalue = \$('#value'),\n\tallFields = \$([]).add(name).add(value),\n\ttips = \$('.validateTips');\n\n\n\n\tvar listWidgets = jQuery.parseJSON('" . str_replace("'", "\\'", Json::encode($widgets[0])) . "');\n\tvar widgets = jQuery.parseJSON('" . str_replace("'", "\\'", str_replace("\\", "\\\\", Json::encode($widgets[1]))) . "');\n\tvar wgByType = jQuery.parseJSON('" . str_replace("'", "\\'", str_replace("\\", "\\\\", Json::encode($wgByTypes))) . "');\n\n\n\tvar fieldType = {\n\t\t\t'INTEGER':{\n\t\t\t\t'hide':['match','other_validator','widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':10,\n\t\t\t\t\t'default':'0',\n\t\t\t\t\t'range':'',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t},\n\t\t\t'VARCHAR':{\n\t\t\t\t'hide':['widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':255,\n\t\t\t\t\t'default':'',\n\t\t\t\t\t'range':'',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t},\n\t\t\t'TEXT':{\n\t\t\t\t'hide':['field_size','range','widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':0,\n\t\t\t\t\t'default':'',\n\t\t\t\t\t'range':'',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t},\n\t\t\t'DATE':{\n\t\t\t\t'hide':['field_size','field_size_min','match','range','widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':0,\n\t\t\t\t\t'default':'0000-00-00',\n\t\t\t\t\t'range':'',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t},\n\t\t\t'FLOAT':{\n\t\t\t\t'hide':['match','other_validator','widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':'10.2',\n\t\t\t\t\t'default':'0.00',\n\t\t\t\t\t'range':'',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t},\n\t\t\t'DECIMAL':{\n\t\t\t\t'hide':['match','other_validator','widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':'10,2',\n\t\t\t\t\t'default':'0',\n\t\t\t\t\t'range':'',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t},\n\t\t\t'BOOL':{\n\t\t\t\t'hide':['field_size','field_size_min','match','widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':0,\n\t\t\t\t\t'default':0,\n\t\t\t\t\t'range':'1==" . Module::t('Yes') . ";0==" . Module::t('No') . "',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t},\n\t\t\t'BLOB':{\n\t\t\t\t'hide':['field_size','field_size_min','match','widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':0,\n\t\t\t\t\t'default':'',\n\t\t\t\t\t'range':'',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t},\n\t\t\t'BINARY':{\n\t\t\t\t'hide':['field_size','field_size_min','match','widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':0,\n\t\t\t\t\t'default':'',\n\t\t\t\t\t'range':'',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\n\n\tfunction showWidgetList(type) {\n\t\t\$('div.widget select').empty();\n\t\t\$('div.widget select').append('<option value=\"\">" . Module::t('No') . "</option>');\n\t\tif (wgByType[type]) {\n\t\t\tfor (var k in wgByType[type]) {\n\t\t\t\t\$('div.widget select')\n\t\t\t\t    .append('<option value=\"'+wgByType[type][k]+'\">'+widgets[wgByType[type][k]]['label']+'</option>');\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction setFields(type) {\n\t\tif (fieldType[type]) {\n\t\t\tif (" . (isset($_GET['id']) ? 0 : 1) . ") {\n\t\t\t\tshowWidgetList(type);\n\t\t\t\t\$('#widgetlist option:first').attr('selected', 'selected');\n\t\t\t}\n\n\t\t\t\$('div.form-group').addClass('toshow').removeClass('tohide');\n\t\t\tif (fieldType[type].hide.length) {\n\t\t\t    \$('div.'+fieldType[type].hide.join(', div.')).addClass('tohide').removeClass('toshow');\n\t\t\t}\n\t\t\tif (\$('div.widget select').val()) {\n\t\t\t\t\$('div.widgetparams').removeClass('tohide');\n\t\t\t}\n\t\t\t\$('div.toshow').show(500);\n\t\t\t\$('div.tohide').hide(500);\n\t\t\t" . (!isset($_GET['id']) ? "\n\t\t\tfor (var k in fieldType[type].val) {\n\t\t\t\t\$('div.'+k+' input').val(fieldType[type].val[k]);\n\t\t\t}" : '') . "\n\t\t}\n\t}\n\n\tfunction isArray(obj) {\n\t\tif (obj.constructor.toString().indexOf('Array') == -1)\n\t\t\treturn false;\n\t\telse\n\t\t\treturn true;\n\t}\n\n\t\$('#dialog-form').dialog({\n\t\tautoOpen: false,\n\t\theight: 400,\n\t\twidth: 400,\n\t\tmodal: true,\n\t\tbuttons: {\n\t\t\t'" . Module::t('Save') . "': function() {\n\t\t\t\tvar wparam = {};\n\t\t\t\tvar fparam = {};\n\t\t\t\t\$('#dialog-form fieldset .wparam').each(function(){\n\t\t\t\t\tif (\$(this).val()) wparam[\$(this).attr('name')] = \$(this).val();\n\t\t\t\t});\n\n\t\t\t\tvar tab = \$('#tabs ul li.ui-tabs-active').text();\n\t\t\t\tfparam[tab] = {};\n\t\t\t\t\$('#dialog-form fieldset .tab-'+tab).each(function(){\n\t\t\t\t\tif (\$(this).val()) fparam[tab][\$(this).attr('name')] = \$(this).val();\n\t\t\t\t});\n\n\t\t\t\tif (\$.JSON.encode(wparam)!='{}') \$('div.widgetparams input').val(\$.JSON.encode(wparam));\n\t\t\t\tif (\$.JSON.encode(fparam[tab])!='{}') \$('div.other_validator input').val(\$.JSON.encode(fparam));\n\n\t\t    \$('#widgetparams').blur();\n\t\t\t\t\$(this).dialog('close');\n\t\t    \$('#widgetparams').blur();\n\t\t\t},\n\t\t\t'" . Module::t('Cancel') . "': function() {\n\t\t    \$('#widgetparams').blur();\n\t\t\t\t\$(this).dialog('close');\n\t\t    \$('#widgetparams').blur();\n\t\t\t}\n\t\t},\n\t\tclose: function() {\n\t\t}\n\t});\n\n\n\t\$('#widgetparams').click(function() {\n\t\tvar widget = widgets[\$('#widgetlist').val()];\n\t\tvar html = '';\n\t\tvar wparam = (\$('div.widgetparams input').val())?\$.JSON.decode(\$('div.widgetparams input').val()):{};\n\t\tvar fparam = (\$('div.other_validator input').val())?\$.JSON.decode(\$('div.other_validator input').val()):{};\n\n\t\t// Class params\n\t\tfor (var k in widget.params) {\n\t\t\thtml += '<label for=\"name\">'+((widget.paramsLabels[k])?widget.paramsLabels[k]:k)+'</label>';\n\t\t\thtml += '<input type=\"text\" name=\"'+k+'\" id=\"widget_'+k+\n\t\t\t'\" class=\"text wparam ui-widget-content ui-corner-all\" value=\"'+\n\t\t\t    ((wparam[k])?wparam[k]:widget.params[k])+'\" />';\n\t\t}\n\t\t// Validator params\n\t\tif (widget.other_validator) {\n\t\t\tvar tabs = '';\n\t\t\tvar li = '';\n\t\t\tfor (var t in widget.other_validator) {\n\t\t\t\ttabs += '<div id=\"tab-'+t+'\" class=\"tab\">';\n\t\t\t\tli += '<li'+((fparam[t])?' class=\"ui-tabs-selected\"':'')+'><a href=\"#tab-'+t+'\">'+t+'</a></li>';\n\n\t\t\t\tfor (var k in widget.other_validator[t]) {\n\t\t\t\t    var property = widget.other_validator[t][k];\n\t\t\t\t\tif (typeof property == 'object' && !isArray(property)) {\n\t\t\t\t\t    if(property['label']) {\n\t\t\t\t\t        tabs += '<label for=\"name\">'+(property['label'])+'</label>';\n\t\t\t\t\t    } else {\n\t\t\t\t\t        tabs += '<label for=\"name\">'+((widget.paramsLabels[k])?widget.paramsLabels[k]:k)+'</label>';\n\t\t\t\t\t    }\n\n\t\t\t\t\t    if (isArray(property['value'])) {\n                            tabs += '<select type=\"text\" name=\"'+k+'\" id=\"filter_'+k+\n                            '\" class=\"text fparam ui-widget-content ui-corner-all tab-'+t+'\">';\n                            for (var i in property['value']) {\n                                tabs += '<option value=\"'+property['value'][i]+'\"'+\n                                ((fparam[t]&&fparam[t][k])?' selected=\"selected\"':'')+'>'+\n                                property['value'][i]+'</option>';\n                            }\n                            tabs += '</select>';\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t    tabs += '<input type=\"text\" name=\"'+k+'\" id=\"filter_'+k+\n                            '\" class=\"text fparam ui-widget-content ui-corner-all tab-'+t+'\" value=\"'+\n                            ((fparam[t]&&fparam[t][k])?fparam[t][k]:property['value'])+'\" />';\n                        }\n\t\t\t\t\t} else if (isArray(property)) {\n                            tabs += '<select type=\"text\" name=\"'+k+'\" id=\"filter_'+k+\n                            '\" class=\"text fparam ui-widget-content ui-corner-all tab-'+t+'\">';\n                            for (var i in property) {\n                                tabs += '<option value=\"'+property[i]+'\"'+\n                                ((fparam[t]&&fparam[t][k])?' selected=\"selected\"':'')+'>'+\n                                property['value'][i]+'</option>';\n                            }\n                            tabs += '</select>';\n\t\t\t\t\t} else {\n\t\t\t\t\t    tabs += '<label for=\"name\">'+((widget.paramsLabels[k])?widget.paramsLabels[k]:k)+'</label>';\n\t\t\t\t\t\ttabs += '<input type=\"text\" name=\"'+k+'\" id=\"filter_'+k+\n\t\t\t\t\t\t'\" class=\"text fparam ui-widget-content ui-corner-all tab-'+t+'\" value=\"'+\n\t\t\t\t\t\t((fparam[t]&&fparam[t][k])?fparam[t][k]:widget.other_validator[t][k])+'\" />';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ttabs += '</div>';\n\t\t\t}\n\t\t\thtml += '<div id=\"tabs\"><ul>'+li+'</ul>'+tabs+'</div>';\n\t\t}\n\n\t\t\$('#dialog-form fieldset').html(html);\n\n\t\t\$('#tabs').tabs();\n\n\t\t// Show form\n\t\t\$('#dialog-form').dialog('open');\n\t});\n\n\t\$('#field_type').change(function() {\n\t\tsetFields(\$(this).val());\n\t});\n\n\t\$('#widgetlist').change(function() {\n\t\tif (\$(this).val()) {\n\t\t\t\$('div.widgetparams').show(500);\n\t\t} else {\n\t\t\t\$('div.widgetparams').hide(500);\n\t\t}\n\n\t});\n\n\t// show all function\n\t\$('div.form p.note').append('<br/><a href=\"#\" id=\"showAll\">" . Module::t('Show all') . "</a>');\n \t\$('#showAll').click(function(){\n\t\t\$('div.form-group').show(500);\n\t\treturn false;\n\t});\n\n\t// init\n\tsetFields(\$('#field_type').val());\n\n\t";
     $this->view->registerJs($js);
 }
예제 #2
0
echo $form->field($model, 'default')->textInput(['size' => 60, 'maxlength' => 255]);
?>

    <?php 
echo $form->field($model, 'widget')->textInput(['size' => 60, 'maxlength' => 255]);
?>

    <?php 
echo $form->field($model, 'widgetparams')->textInput(['size' => 60, 'maxlength' => 5000]);
?>

    <?php 
echo $form->field($model, 'position');
?>

    <?php 
echo $form->field($model, 'visible')->dropDownList(ProfileField::itemAlias('visible'));
?>

    <div class="form-group">
        <div class="col-lg-offset-1 col-lg-11">
            <?php 
echo Html::submitButton(\marsoltys\yii2user\Module::t('search'), ['class' => 'btn btn-primary']);
?>
        </div>
    </div>
    <?php 
ActiveForm::end();
?>

</div><!-- search-form --> 
예제 #3
0
</h1>

<p><?php 
echo Module::t("You may optionally enter a comparison operator (<b>&lt;</b>, <b>&lt;=</b>, <b>&gt;</b>, <b>&gt;=</b>, <b>&lt;&gt;</b> or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.");
?>
</p>

<?php 
echo Html::a(Module::t('Advanced Search'), '#', ['class' => 'search-button']);
?>
<div class="search-form" style="display:none">
    <?php 
echo $this->render('_search', ['model' => $searchModel]);
?>
</div><!-- search-form -->

<?php 
\yii\widgets\Pjax::begin();
?>

<?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => ['id', ['attribute' => 'varname', 'format' => 'raw', 'value' => function ($data) {
    return UHtml::markSearch($data, "varname");
}], ['attribute' => 'title', 'value' => function ($data) {
    return Module::t($data->title);
}], ['attribute' => 'field_type', 'filter' => ProfileField::itemAlias("field_type")], 'field_size', ['attribute' => 'required', 'value' => function ($data) {
    return ProfileField::itemAlias("required", $data->required);
}, 'filter' => ProfileField::itemAlias("required")], 'position', ['attribute' => 'visible', 'value' => function ($data) {
    return ProfileField::itemAlias("visible", $data->visible);
}, 'filter' => ProfileField::itemAlias("visible")], ['class' => 'yii\\grid\\ActionColumn']]]);
\yii\widgets\Pjax::end();
예제 #4
0
list($widgetsList) = ProfileFieldController::getWidgets($model->field_type);
?>
        <?php 
echo $form->field($model, 'widget', ['options' => ['class' => 'form-group widget']])->dropDownList($widgetsList, ['id' => 'widgetlist'])->hint(Module::t('Widget name.'));
?>

        <?php 
echo $form->field($model, 'widgetparams', ['options' => ['class' => 'form-group widgetparams']])->textInput(['size' => 60, 'maxlength' => 5000, 'id' => 'widgetparams'])->hint(Module::t('JSON string (example: {example}).', ['{example}' => Json::encode(['param1' => ['val1', 'val2'], 'param2' => ['k1' => 'v1', 'k2' => 'v2']])]));
?>

        <?php 
echo $form->field($model, 'position', ['options' => ['class' => 'form-group position']])->hint(Module::t('Display order of fields.'));
?>

        <?php 
echo $form->field($model, 'visible', ['options' => ['class' => 'form-group visible']])->dropDownList(ProfileField::itemAlias('visible'));
?>

        <div class="form-group">
            <?php 
echo Html::submitButton($model->isNewRecord ? Module::t('Create') : Module::t('Save'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
        </div>

        <?php 
ActiveForm::end();
?>
    </div>

</div><!-- form -->
<div id="dialog-form" title="<?php