55 lines
2.8 KiB
PHP
55 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Helpers\Equipment;
|
|
|
|
use App\Models\Equipment\ServerModel;
|
|
use CodeIgniter\HTTP\IncomingRequest;
|
|
|
|
class ServerHelper extends EquipmentHelper
|
|
{
|
|
protected ?IncomingRequest $request = null;
|
|
public function __construct(?IncomingRequest $request = null)
|
|
{
|
|
parent::__construct($request);
|
|
$this->setTitleField(field: ServerModel::TITLE);
|
|
}
|
|
public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string
|
|
{
|
|
if (in_array($viewDatas['action'], ['create', 'modify'])) {
|
|
$extras = (strpos($viewDatas['field_rules'][$field], 'required') !== false) ? ["class" => "form-control", "required" => "", ...$extras] : ["class" => "form-control", ...$extras];
|
|
}
|
|
switch ($field) {
|
|
case 'cpu_partinfo_uid':
|
|
case 'ram_partinfo_uid':
|
|
case 'disk_partinfo_uid':
|
|
if (!is_array($viewDatas['field_options'][$field])) {
|
|
throw new \Exception(__METHOD__ . "에서 {$field}의 field_options가 array형태가 아닙니다.");
|
|
}
|
|
if (in_array($viewDatas['action'], ['create_form', 'modify_form'])) {
|
|
$form = " <button type=\"button\" class=\"server_partinfo_layer_btn\" onclick=\"openLayer('{$field}')\">" . lang($viewDatas['class_path'] . '.label.' . $field) . " 추가</button>";
|
|
$form .= "<div id=\"{$field}_layer\" class=\"server_partinfo_layer\" style=\"display: none;\">";
|
|
$form .= "<div class=\"server_partinfo_layer_inner\">";
|
|
$form .= "<ul class=\"server_partinfo_item_list\">";
|
|
foreach ($viewDatas['field_options'][$field] as $key => $label) {
|
|
$form .= "<li><label onclick=\"addComponentFromLabel('{$field}', {$key},'{$label}')\">{$label}</label></li>";
|
|
}
|
|
$form .= "</ul>";
|
|
$form .= "<button type=\"button\" onclick=\"closeLayer('{$field}')\">닫기</button>";
|
|
$form .= "</div></div>";
|
|
$form .= "<div id=\"{$field}_list\" class=\"server_partinfo_items\" style=\"border:1px solid silver\"></div>";
|
|
} else {
|
|
$formOptions = ["" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택'];
|
|
foreach ($viewDatas['field_options'][$field] as $key => $label) {
|
|
$formOptions[$key] = $label;
|
|
}
|
|
$form = form_dropdown($field, $formOptions, $value, $extras);
|
|
}
|
|
break;
|
|
default:
|
|
$form = parent::getFieldForm($field, $value, $viewDatas, $extras);
|
|
break;
|
|
}
|
|
return $form;
|
|
} //
|
|
}
|