169 lines
10 KiB
PHP
169 lines
10 KiB
PHP
<?php
|
|
|
|
use humhub\modules\animal_management\models\forms\DisplaySettingsForm;
|
|
use humhub\modules\animal_management\models\forms\FieldDefinitionSettingsForm;
|
|
use humhub\widgets\Button;
|
|
use yii\bootstrap\ActiveForm;
|
|
use yii\helpers\Html;
|
|
|
|
/* @var string|null $subNav */
|
|
/* @var int $animalCount */
|
|
/* @var FieldDefinitionSettingsForm $fieldSettingsForm */
|
|
/* @var DisplaySettingsForm $displaySettingsForm */
|
|
?>
|
|
|
|
<div class="panel panel-default">
|
|
<div class="panel-heading"><?= Yii::t('AnimalManagementModule.base', '<strong>Animal Management</strong> Settings') ?></div>
|
|
|
|
<?php if (!empty($subNav)): ?>
|
|
<?= $subNav ?>
|
|
<?php endif; ?>
|
|
|
|
<div class="panel-body">
|
|
<p><?= Yii::t('AnimalManagementModule.base', 'Configure intake/profile field definitions used by Animal Management.') ?></p>
|
|
|
|
<div class="well well-sm" style="margin-bottom:12px;">
|
|
<strong><?= Yii::t('AnimalManagementModule.base', 'Current animals in this space') ?>:</strong>
|
|
<?= (int)$animalCount ?>
|
|
</div>
|
|
|
|
<h4 style="margin-top:0;"><?= Yii::t('AnimalManagementModule.base', 'Display Settings') ?></h4>
|
|
<?php $displayForm = ActiveForm::begin(); ?>
|
|
<?= $displayForm->errorSummary($displaySettingsForm, ['showAllErrors' => true]) ?>
|
|
<div class="row">
|
|
<div class="col-md-8">
|
|
<?= $displayForm->field($displaySettingsForm, 'search_block_heading')->textInput(['maxlength' => 190]) ?>
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<label class="control-label" style="display:block;"><?= Yii::t('AnimalManagementModule.base', 'Animal Tile Fields') ?></label>
|
|
<?= Html::checkboxList(
|
|
'DisplaySettingsForm[tile_fields]',
|
|
$displaySettingsForm->tile_fields,
|
|
DisplaySettingsForm::fieldOptions(),
|
|
['separator' => '<br>']
|
|
) ?>
|
|
<p class="help-block" style="margin-top:6px;"><?= Yii::t('AnimalManagementModule.base', 'ID is hidden by default unless selected here.') ?></p>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<label class="control-label" style="display:block;"><?= Yii::t('AnimalManagementModule.base', 'Animal Detail Hero Fields') ?></label>
|
|
<?= Html::checkboxList(
|
|
'DisplaySettingsForm[detail_fields]',
|
|
$displaySettingsForm->detail_fields,
|
|
DisplaySettingsForm::fieldOptions(),
|
|
['separator' => '<br>']
|
|
) ?>
|
|
</div>
|
|
</div>
|
|
<div style="margin-bottom:16px;">
|
|
<?= Button::save(Yii::t('AnimalManagementModule.base', 'Save Display Settings'))->submit() ?>
|
|
</div>
|
|
<?php ActiveForm::end(); ?>
|
|
|
|
<?php if (!$fieldSettingsForm->canUseFieldDefinition()): ?>
|
|
<div class="alert alert-warning" style="margin-bottom:0;">
|
|
<?= Yii::t('AnimalManagementModule.base', 'Field definition storage is unavailable. Enable rescue foundation migrations first.') ?>
|
|
</div>
|
|
<?php else: ?>
|
|
<?php $form = ActiveForm::begin(); ?>
|
|
|
|
<?php if ($fieldSettingsForm->hasErrors('rows')): ?>
|
|
<div class="alert alert-danger">
|
|
<?= Html::errorSummary($fieldSettingsForm, ['header' => '', 'footer' => '', 'showAllErrors' => true]) ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<h4 style="margin-top:0;"><?= Yii::t('AnimalManagementModule.base', 'Configured Fields') ?></h4>
|
|
|
|
<?php if (empty($fieldSettingsForm->rows)): ?>
|
|
<div class="alert alert-info"><?= Yii::t('AnimalManagementModule.base', 'No field definitions found for this module.') ?></div>
|
|
<?php else: ?>
|
|
<div class="table-responsive" style="margin-bottom:12px;">
|
|
<table class="table table-condensed table-hover">
|
|
<thead>
|
|
<tr>
|
|
<th><?= Yii::t('AnimalManagementModule.base', 'Field Key') ?></th>
|
|
<th><?= Yii::t('AnimalManagementModule.base', 'Label') ?></th>
|
|
<th><?= Yii::t('AnimalManagementModule.base', 'Group') ?></th>
|
|
<th><?= Yii::t('AnimalManagementModule.base', 'Input Type') ?></th>
|
|
<th><?= Yii::t('AnimalManagementModule.base', 'Required') ?></th>
|
|
<th><?= Yii::t('AnimalManagementModule.base', 'Active') ?></th>
|
|
<th><?= Yii::t('AnimalManagementModule.base', 'Visibility') ?></th>
|
|
<th><?= Yii::t('AnimalManagementModule.base', 'Sort') ?></th>
|
|
<th><?= Yii::t('AnimalManagementModule.base', 'Remove') ?></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($fieldSettingsForm->rows as $index => $row): ?>
|
|
<?php $isCore = ((int)($row['is_core'] ?? 0)) === 1; ?>
|
|
<tr>
|
|
<td>
|
|
<?= Html::hiddenInput("FieldDefinitionSettingsForm[rows][$index][id]", (int)$row['id']) ?>
|
|
<?= Html::hiddenInput("FieldDefinitionSettingsForm[rows][$index][field_key]", (string)$row['field_key']) ?>
|
|
<?= Html::encode((string)$row['field_key']) ?>
|
|
<?php if ($isCore): ?>
|
|
<span class="label label-default" style="margin-left:4px;"><?= Yii::t('AnimalManagementModule.base', 'Core') ?></span>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td><?= Html::textInput("FieldDefinitionSettingsForm[rows][$index][label]", (string)$row['label'], ['class' => 'form-control input-sm']) ?></td>
|
|
<td><?= Html::textInput("FieldDefinitionSettingsForm[rows][$index][group_key]", (string)$row['group_key'], ['class' => 'form-control input-sm']) ?></td>
|
|
<td>
|
|
<?= Html::encode((string)$row['input_type']) ?>
|
|
<?= Html::hiddenInput("FieldDefinitionSettingsForm[rows][$index][input_type]", (string)$row['input_type']) ?>
|
|
</td>
|
|
<td class="text-center" style="vertical-align:middle;">
|
|
<?= Html::checkbox("FieldDefinitionSettingsForm[rows][$index][required]", !empty($row['required']), ['disabled' => $isCore]) ?>
|
|
<?php if ($isCore): ?>
|
|
<?= Html::hiddenInput("FieldDefinitionSettingsForm[rows][$index][required]", !empty($row['required']) ? 1 : 0) ?>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td class="text-center" style="vertical-align:middle;">
|
|
<?= Html::checkbox("FieldDefinitionSettingsForm[rows][$index][is_active]", !empty($row['is_active']), ['disabled' => $isCore]) ?>
|
|
<?php if ($isCore): ?>
|
|
<?= Html::hiddenInput("FieldDefinitionSettingsForm[rows][$index][is_active]", !empty($row['is_active']) ? 1 : 0) ?>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td>
|
|
<?= Html::dropDownList(
|
|
"FieldDefinitionSettingsForm[rows][$index][visibility]",
|
|
(string)$row['visibility'],
|
|
FieldDefinitionSettingsForm::visibilityOptions(),
|
|
['class' => 'form-control input-sm']
|
|
) ?>
|
|
</td>
|
|
<td><?= Html::input('number', "FieldDefinitionSettingsForm[rows][$index][sort_order]", (int)$row['sort_order'], ['class' => 'form-control input-sm', 'style' => 'max-width:90px;']) ?></td>
|
|
<td class="text-center" style="vertical-align:middle;">
|
|
<?php if (!$isCore): ?>
|
|
<?= Html::checkbox("FieldDefinitionSettingsForm[rows][$index][remove]", false) ?>
|
|
<?php else: ?>
|
|
<span class="text-muted">-</span>
|
|
<?php endif; ?>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<h4><?= Yii::t('AnimalManagementModule.base', 'Add Custom Field') ?></h4>
|
|
<div class="row">
|
|
<div class="col-md-3"><?= $form->field($fieldSettingsForm, 'new_field_key')->textInput(['placeholder' => 'e.g. coat_color']) ?></div>
|
|
<div class="col-md-3"><?= $form->field($fieldSettingsForm, 'new_label') ?></div>
|
|
<div class="col-md-2"><?= $form->field($fieldSettingsForm, 'new_input_type')->dropDownList(FieldDefinitionSettingsForm::inputTypeOptions()) ?></div>
|
|
<div class="col-md-2"><?= $form->field($fieldSettingsForm, 'new_group_key') ?></div>
|
|
<div class="col-md-2"><?= $form->field($fieldSettingsForm, 'new_sort_order')->input('number') ?></div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-md-3"><?= $form->field($fieldSettingsForm, 'new_visibility')->dropDownList(FieldDefinitionSettingsForm::visibilityOptions()) ?></div>
|
|
<div class="col-md-3"><?= $form->field($fieldSettingsForm, 'new_required')->checkbox() ?></div>
|
|
<div class="col-md-6"><?= $form->field($fieldSettingsForm, 'new_options')->textInput(['placeholder' => 'Optional JSON options']) ?></div>
|
|
</div>
|
|
|
|
<?= Button::save(Yii::t('AnimalManagementModule.base', 'Save Field Settings'))->submit() ?>
|
|
<?php ActiveForm::end(); ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|