cfmgrv4 init...2

This commit is contained in:
최준흠 2024-10-14 19:55:54 +09:00
parent 54358289e2
commit f896a478bd
8 changed files with 72 additions and 27 deletions

View File

@ -59,7 +59,7 @@ class RecordController extends CloudflareController
switch ($field) {
case 'hosts':
$formDatas[$field] = explode("\n", $this->request->getVar($field));
if (!is_array($this->formDatas[$field]) || !count($this->formDatas[$field])) {
if (!is_array($formDatas[$field]) || !count($formDatas[$field])) {
throw new \Exception("호스트명이 정의되지 않았습니다.");
}
break;
@ -108,8 +108,13 @@ class RecordController extends CloudflareController
}
//Socket처리
foreach ($this->formDatas['hosts'] as $host) {
$entity = $this->getMyLibrary()->create($host, $this->formDatas['type'], $this->formDatas['content'], $this->formDatas['proxied']);
log_message("debug", "Record:{$entity->getTitle()} 생성 작업을 완료하였습니다.");
$this->entity = $this->getMyLibrary()->create(
$host,
$this->formDatas['type'],
$this->formDatas['content'],
$this->formDatas['proxied']
);
log_message("debug", message: "Record:{$this->entity->getTitle()} 생성 작업을 완료하였습니다.");
}
}
public function create(mixed $zone_uid = false): RedirectResponse|string
@ -176,7 +181,7 @@ class RecordController extends CloudflareController
throw new \Exception("{$uid} 정보를 찾을수 없습니다.");
}
//부모데이터정의
$this->_zone_entity = $this->getZoneModel()->getEntityByPK($this->formDatas[$this->getModel()::PARENT]);
$this->_zone_entity = $this->getZoneModel()->getEntityByPK($this->entity->getParent());
//Cloudflare 삭제
$this->entity = $this->getMyLibrary()->delete($this->entity);
}

View File

@ -138,19 +138,26 @@ class ZoneController extends CloudflareController
//Socket처리
//Zone생성
$cnt = 1;
$zone_entitys = [];
$this->zone_entitys = [];
foreach ($this->formDatas['domains'] as $domain) {
$entity = $this->getMyLibrary()->create($domain);
log_message("debug", "Zone:{$entity->getTitle()} 작업을 완료하였습니다.");
$zone_entitys[] = $entity;
$this->zone_entitys[] = $entity;
$cnt++;
}
//Record생성
foreach ($zone_entitys as $zone_entity) {
$this->record_entitys = [];
foreach ($this->zone_entitys as $zone_entity) {
$record = new Record($zone_entity);
foreach ($this->formDatas['hosts'] as $host) {
$entity = $record->create($host, $this->formDatas['type'], $this->formDatas['content'], $this->formDatas['proxied']);
$entity = $record->create(
$host,
$this->formDatas['type'],
$this->formDatas['content'],
$this->formDatas['proxied']
);
log_message("debug", "Record:{$entity->getTitle()} 작업을 완료하였습니다.");
$this->record_entitys[] = $entity;
}
}
}
@ -210,7 +217,7 @@ class ZoneController extends CloudflareController
throw new \Exception("{$uid} 정보를 찾을수 없습니다.");
}
//부모데이터정의
$this->_account_entity = $this->getAccountModel()->getEntityByPK($this->formDatas[$this->getModel()::PARENT]);
$this->_account_entity = $this->getAccountModel()->getEntityByPK($this->entity->getParent());
//Cloudflare 삭제
$this->entity = $this->getMyLibrary()->delete($this->entity);
}

View File

@ -110,6 +110,13 @@ abstract class MVController extends CommonController
$this->formDatas = $this->getFormDatas();
$this->entity = $this->getModel()->create(formDatas: $this->formDatas);
}
protected function create_result(): string
{
return view(
$this->view_path . "view",
data: ['viewDatas' => $this->getViewDatas()]
);
}
final protected function create_procedure(): RedirectResponse|string
{
//Transaction Start
@ -119,10 +126,7 @@ abstract class MVController extends CommonController
$this->create_process();
$this->getModel()->transCommit();
$this->message = "{$this->class_name} : 생성작업이 완료되었습니다.";
return view(
$this->view_path . "view",
data: ['viewDatas' => $this->getViewDatas()]
);
return $this->create_result();
} catch (\Exception $e) {
//Transaction Rollback
$this->getModel()->transRollback();
@ -175,6 +179,13 @@ abstract class MVController extends CommonController
}
$this->entity = $this->getModel()->modify($this->entity, $this->formDatas);
}
protected function modify_result(): string
{
return view(
$this->view_path . "view",
data: ['viewDatas' => $this->getViewDatas()]
);
}
final protected function modify_procedure(string $uid): RedirectResponse|string
{
//Transaction Start
@ -184,10 +195,7 @@ abstract class MVController extends CommonController
$this->modify_process($uid);
$this->getModel()->transCommit();
$this->message = "{$this->class_name} : 수정작업이 완료되었습니다.";
return view(
$this->view_path . "view",
data: ['viewDatas' => $this->getViewDatas()]
);
return $this->modify_result();
} catch (\Exception $e) {
//Transaction Rollback
$this->getModel()->transRollback();

View File

@ -17,10 +17,13 @@ class AccountHelper extends CommonHelper
$value = $value ?: DEFAULTS['EMPTY'];
switch ($field) {
case AccountModel::PARENT:
$extra_class = isset($extras['class']) ? $extras['class'] . ' select-field' : 'select-field';
$extra_class = isset($extras['class']) ? 'select-field ' . $extras['class'] : 'select-field';
$form = form_dropdown($field, [
"" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택',
] + $viewDatas['field_options'][$field], $value, ['class' => $extra_class, ...array_diff_key($extras, ['class' => ''])]);
] + $viewDatas['field_options'][$field], $value, [
'class' => $extra_class,
...array_diff_key($extras, ['class' => ''])
]);
break;
case AccountModel::TITLE:
$form = form_input($field, $value, ["placeholder" => "예)test@exmaple.com", ...$extras]);

View File

@ -17,10 +17,13 @@ class RecordHelper extends CommonHelper
$value = $value ?: DEFAULTS['EMPTY'];
switch ($field) {
case RecordModel::PARENT:
$extra_class = isset($extras['class']) ? $extras['class'] . ' select-field' : 'select-field';
$extra_class = isset($extras['class']) ? 'select-field ' . $extras['class'] : 'select-field';
$form = form_dropdown($field, [
"" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택',
] + $viewDatas['field_options'][$field], $value, ['class' => $extra_class, ...array_diff_key($extras, ['class' => ''])]);
] + $viewDatas['field_options'][$field], $value, [
'class' => $extra_class,
...array_diff_key($extras, ['class' => ''])
]);
break;
case RecordModel::TITLE: //host
$form = form_input($field, $value, $extras);

View File

@ -17,10 +17,13 @@ class ZoneHelper extends CommonHelper
$value = $value ?: DEFAULTS['EMPTY'];
switch ($field) {
case ZoneModel::PARENT:
$extra_class = isset($extras['class']) ? $extras['class'] . ' select-field' : 'select-field';
$extra_class = isset($extras['class']) ? 'select-field ' . $extras['class'] : 'select-field';
$form = form_dropdown($field, [
"" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택',
] + $viewDatas['field_options'][$field], $value, ['class' => $extra_class, ...array_diff_key($extras, ['class' => ''])]);
] + $viewDatas['field_options'][$field], $value, [
'class' => $extra_class,
...array_diff_key($extras, ['class' => ''])
]);
break;
case ZoneModel::TITLE:
$form = form_input($field, $value, ["placeholder" => "예)exampel.com", ...$extras]);

View File

@ -37,6 +37,19 @@
}
const content = await response.text();
modalBody.innerHTML = content;
// 새로 추가된 스크립트 실행
const scripts = modalBody.getElementsByTagName('script');
for (let script of scripts) {
if (script.src) {
// 외부 스크립트 로드
const newScript = document.createElement('script');
newScript.src = script.src;
document.body.appendChild(newScript);
} else {
// 인라인 스크립트 실행
eval(script.innerHTML);
}
}
setupFormSubmission();
} catch (error) {
console.error('콘텐츠 로드 중 오류 발생:', error);

View File

@ -20,9 +20,12 @@ $(document).ready(function () {
});
//class가 select-field인 SelectBox용
$(".select-field").select2({
theme: "classic",
width: 'style',
dropdownAutoWidth: true
theme: "bootstrap-5",
dropdownParent: $('#index_action_form'),
templateResult: function(data) {
if (!data.id) return data.text;
return $('<span style="text-align: left; display: block;">').text(data.text);
}
});
// text editor 초기화
//참고: https://phppot.com/menu/php/learn-php/
@ -58,4 +61,4 @@ $(document).ready(function () {
xhr.send(formData);
},
});
});
});