cfmgrv4 init...2
This commit is contained in:
parent
f8ebfb7872
commit
9320123492
@ -57,7 +57,7 @@ class RecordController extends CloudflareController
|
||||
{
|
||||
switch ($field) {
|
||||
case 'hosts':
|
||||
$formDatas[$field] = explode("\n", $this->request->getPost($field));
|
||||
$formDatas[$field] = explode("\n", $this->request->getVar($field));
|
||||
if (!is_array($this->formDatas[$field]) || !count($this->formDatas[$field])) {
|
||||
throw new \Exception("호스트명이 정의되지 않았습니다.");
|
||||
}
|
||||
@ -128,13 +128,16 @@ class RecordController extends CloudflareController
|
||||
throw new \Exception("{$uid} 정보를 찾을수 없습니다.");
|
||||
}
|
||||
//fixed 필드가 있고 값이 변경되었을때
|
||||
if (in_array('fixed', $this->fields) && $this->formDatas['fixed'] !== $this->entity->fixed) {
|
||||
$entity = $this->getModel()->modify($this->entity, $this->formDatas);
|
||||
if (in_array('fixed', $this->fields)) {
|
||||
// dd($this->formDatas, $this->entity->fixed);
|
||||
if (isset($this->formDatas['fixed']) && $this->formDatas['fixed'] !== $this->entity->fixed) {
|
||||
$this->entity = $this->getModel()->modify($this->entity, $this->formDatas);
|
||||
}
|
||||
} else {
|
||||
//부모데이터정의
|
||||
$this->_zone_entity = $this->getZoneModel()->getEntityByPK($this->entity->getParent());
|
||||
//Socket처리
|
||||
$entity = $this->getMyLibrary()->modify($this->entity, $this->formDatas);
|
||||
$this->entity = $this->getMyLibrary()->modify($this->entity, $this->formDatas);
|
||||
}
|
||||
}
|
||||
//일괄처리작업
|
||||
@ -156,7 +159,7 @@ class RecordController extends CloudflareController
|
||||
//부모데이터정의
|
||||
$this->_zone_entity = $this->getZoneModel()->getEntityByPK($this->entity->getParent());
|
||||
//Socket처리
|
||||
$this->getMyLibrary()->sync($this->entity);
|
||||
$this->entity = $this->getMyLibrary()->sync($this->entity);
|
||||
}
|
||||
public function sync(string $uid): RedirectResponse
|
||||
{
|
||||
@ -174,7 +177,7 @@ class RecordController extends CloudflareController
|
||||
//부모데이터정의
|
||||
$this->_zone_entity = $this->getZoneModel()->getEntityByPK($this->formDatas[$this->getModel()::PARENT]);
|
||||
//Cloudflare 삭제
|
||||
$this->getMyLibrary()->delete($this->entity);
|
||||
$this->entity = $this->getMyLibrary()->delete($this->entity);
|
||||
}
|
||||
// 리스트
|
||||
public function index(): string
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Controllers\Admin\Cloudflare;
|
||||
|
||||
use App\Entities\Cloudflare\RecordEntity;
|
||||
use App\Helpers\Cloudflare\ZoneHelper;
|
||||
use App\Libraries\Cloudflare\Record;
|
||||
use App\Libraries\Cloudflare\Zone;
|
||||
@ -62,13 +63,13 @@ class ZoneController extends CloudflareController
|
||||
{
|
||||
switch ($field) {
|
||||
case 'domains':
|
||||
$formDatas[$field] = explode("\n", $this->request->getPost($field));
|
||||
$formDatas[$field] = explode("\n", $this->request->getVar($field));
|
||||
if (!is_array($formDatas[$field]) || !count($formDatas[$field])) {
|
||||
throw new \Exception("도메인명이 정의되지 않았습니다.");
|
||||
}
|
||||
break;
|
||||
case 'hosts':
|
||||
$formDatas[$field] = $this->request->getPost($field);
|
||||
$formDatas[$field] = $this->request->getVar($field);
|
||||
if (!is_array($formDatas[$field]) || !count($formDatas[$field])) {
|
||||
throw new \Exception("호스트명이 정의되지 않았습니다");
|
||||
}
|
||||
@ -172,7 +173,7 @@ class ZoneController extends CloudflareController
|
||||
//부모데이터정의
|
||||
$this->_account_entity = $this->getAccountModel()->getEntityByPK($this->entity->getParent());
|
||||
//Socket처리
|
||||
$entity = $this->getMyLibrary()->modify($this->entity, $this->formDatas);
|
||||
$this->entity = $this->getMyLibrary()->modify($this->entity, $this->formDatas);
|
||||
}
|
||||
//일괄처리작업
|
||||
public function batcjob(): RedirectResponse
|
||||
@ -193,7 +194,7 @@ class ZoneController extends CloudflareController
|
||||
//부모데이터정의
|
||||
$this->_account_entity = $this->getAccountModel()->getEntityByPK($this->entity->getParent());
|
||||
//Socket처리
|
||||
$this->getMyLibrary()->sync($this->entity);
|
||||
$this->entity = $this->getMyLibrary()->sync($this->entity);
|
||||
}
|
||||
public function sync(string $uid): RedirectResponse
|
||||
{
|
||||
@ -211,7 +212,7 @@ class ZoneController extends CloudflareController
|
||||
//부모데이터정의
|
||||
$this->_account_entity = $this->getAccountModel()->getEntityByPK($this->formDatas[$this->getModel()::PARENT]);
|
||||
//Cloudflare 삭제
|
||||
$this->getMyLibrary()->delete($this->entity);
|
||||
$this->entity = $this->getMyLibrary()->delete($this->entity);
|
||||
}
|
||||
// 리스트
|
||||
public function index(): string
|
||||
|
||||
@ -64,7 +64,7 @@ abstract class MVController extends CommonController
|
||||
{
|
||||
switch ($field) {
|
||||
default:
|
||||
$formDatas[$field] = $this->request->getPost($field);
|
||||
$formDatas[$field] = $this->request->getVar($field);
|
||||
break;
|
||||
}
|
||||
return $formDatas;
|
||||
@ -137,7 +137,7 @@ abstract class MVController extends CommonController
|
||||
// 수정
|
||||
protected function modify_validate(string $action, array $fields): void
|
||||
{
|
||||
//변경할 값 확인 : Upload된 파일 검증시 $this->request->getPost()보다 먼처 체크필요
|
||||
//변경할 값 확인 : Upload된 파일 검증시 $this->request->getVar()보다 먼처 체크필요
|
||||
$this->validation = $this->setFormFieldRules($fields, service('validation'), $action);
|
||||
if (!$this->validation->withRequest($this->request)->run()) {
|
||||
throw new \Exception("{$this->class_name} 작업 데이터 검증 오류발생\n" . implode(
|
||||
@ -210,7 +210,7 @@ abstract class MVController extends CommonController
|
||||
$this->getModel()->transStart();
|
||||
try {
|
||||
//변경할 UIDS
|
||||
$uids = $this->request->getPost('batchjob_uids');
|
||||
$uids = $this->request->getVar('batchjob_uids');
|
||||
if ($uids === null || !is_array($uids) || count($uids) === 0) {
|
||||
throw new \Exception("적용할 리스트를 선택하셔야합니다.");
|
||||
}
|
||||
|
||||
@ -17,23 +17,18 @@ class AccountHelper extends CommonHelper
|
||||
$value = $value ?: DEFAULTS['EMPTY'];
|
||||
switch ($field) {
|
||||
case AccountModel::PARENT:
|
||||
$extraClass = isset($extras['class']) ? $extras['class'] . ' select-field' : 'select-field';
|
||||
$form = form_dropdown($field, [
|
||||
"" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택',
|
||||
...$viewDatas['field_options'][$field],
|
||||
], isset($viewDatas[AccountModel::PARENT]) ? $viewDatas[AccountModel::PARENT] : $value, [...$extras, 'class' => "select-field"]);
|
||||
// // return form_multiselect($field, $field_options[$field], is_array($value) ? [...$value] : [$value], [$extras]);
|
||||
// foreach ($viewDatas['field_options'][$field] as $key => $label) {
|
||||
// $checkboxs[] = form_checkbox("{$field}[]", $key, in_array($key, explode(DEFAULTS["DELIMITER_ROLE"], $value))) . $label;
|
||||
// }
|
||||
// return implode(" ", $checkboxs);
|
||||
...$viewDatas['field_options'][$field]
|
||||
], isset($viewDatas[$field]) ? $viewDatas[$field] : $value, ['class' => $extraClass, ...array_diff_key($extras, ['class' => ''])]);
|
||||
break;
|
||||
case AccountModel::TITLE:
|
||||
$form = form_input($field, $value, [
|
||||
"placeholder" => "예)test@exmaple.com",
|
||||
"style" =>
|
||||
"width:100%; ::placeholder{color:silver; opacity: 1;}",
|
||||
"class" => "form-control",
|
||||
"required" => ""
|
||||
"width:100%; ::placeholder{color:silver; opacity: 1;}",
|
||||
...$extras
|
||||
]);
|
||||
break;
|
||||
case 'type':
|
||||
|
||||
@ -19,8 +19,7 @@ class AuthHelper extends CommonHelper
|
||||
$form = form_input($field, $value, [
|
||||
"placeholder" => "예)test@example.com",
|
||||
"style" => "width:100%; ::placeholder{color:silver; opacity: 1;}",
|
||||
"class" => "form-control",
|
||||
"required" => ""
|
||||
...$extras
|
||||
]);
|
||||
break;
|
||||
default:
|
||||
|
||||
@ -17,44 +17,32 @@ class RecordHelper extends CommonHelper
|
||||
$value = $value ?: DEFAULTS['EMPTY'];
|
||||
switch ($field) {
|
||||
case RecordModel::PARENT:
|
||||
$form = form_dropdown(
|
||||
$field,
|
||||
[
|
||||
"" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택',
|
||||
...$viewDatas['field_options'][$field],
|
||||
],
|
||||
isset($viewDatas[RecordModel::PARENT]) ? $viewDatas[RecordModel::PARENT] : $value,
|
||||
[...$extras, 'class' => "select-field"]
|
||||
);
|
||||
// // return form_multiselect($field, $field_options[$field], is_array($value) ? [...$value] : [$value], [$extras]);
|
||||
// foreach ($viewDatas['field_options'][$field] as $key => $label) {
|
||||
// $checkboxs[] = form_checkbox("{$field}[]", $key, in_array($key, explode(DEFAULTS["DELIMITER_ROLE"], $value))) . $label;
|
||||
// }
|
||||
// return implode(" ", $checkboxs);
|
||||
$extraClass = isset($extras['class']) ? $extras['class'] . ' select-field' : 'select-field';
|
||||
$form = form_dropdown($field, [
|
||||
"" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택',
|
||||
...$viewDatas['field_options'][$field]
|
||||
], isset($viewDatas[$field]) ? $viewDatas[$field] : $value, ['class' => $extraClass, ...array_diff_key($extras, ['class' => ''])]);
|
||||
break;
|
||||
case RecordModel::TITLE: //host
|
||||
$form = form_input($field, $value, [
|
||||
"placeholder" => "예)www.example.com",
|
||||
"style" =>
|
||||
"width:200px; ::placeholder{color:silver; opacity: 1;}",
|
||||
"class" => "form-control",
|
||||
"required" => ""
|
||||
"width:200px; ::placeholder{color:silver; opacity: 1;}",
|
||||
...$extras
|
||||
]);
|
||||
break;
|
||||
case 'hosts':
|
||||
$form = form_textarea($field, html_entity_decode($value), [
|
||||
'rows' => '5',
|
||||
"class" => "form-control",
|
||||
"required" => ""
|
||||
...$extras
|
||||
]);
|
||||
break;
|
||||
case 'content':
|
||||
$form = form_input($field, $value, [
|
||||
"placeholder" => "예)123.123.123.123",
|
||||
"style" =>
|
||||
"width:200px; ::placeholder{color:silver; opacity: 1;}",
|
||||
"class" => "form-control",
|
||||
"required" => ""
|
||||
"width:200px; ::placeholder{color:silver; opacity: 1;}",
|
||||
...$extras
|
||||
]);
|
||||
break;
|
||||
case "type":
|
||||
@ -121,4 +109,29 @@ class RecordHelper extends CommonHelper
|
||||
}
|
||||
return $label;
|
||||
}
|
||||
public function getListButton(string $action, array $viewDatas, array $extras = []): string
|
||||
{
|
||||
switch ($action) {
|
||||
case 'modify':
|
||||
$pk = $viewDatas['entity']->getPK();
|
||||
$checkbox = form_checkbox([
|
||||
"id" => "checkbox_uid_{$pk}",
|
||||
"name" => "batchjob_uids[]",
|
||||
"value" => $pk,
|
||||
"class" => "batchjobuids_checkboxs",
|
||||
"checked" => in_array($pk, old("batchjob_uids[]", []))
|
||||
]);
|
||||
$extras = ["target" => "_self", ...$extras];
|
||||
$action = $checkbox . anchor(
|
||||
current_url() . "/sync/" . $viewDatas['entity']->getPK(),
|
||||
$viewDatas['cnt'],
|
||||
$extras
|
||||
);
|
||||
break;
|
||||
default:
|
||||
$action = parent::getListButton($action, $viewDatas, $extras);
|
||||
break;
|
||||
}
|
||||
return $action;
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,46 +17,35 @@ class ZoneHelper extends CommonHelper
|
||||
$value = $value ?: DEFAULTS['EMPTY'];
|
||||
switch ($field) {
|
||||
case ZoneModel::PARENT:
|
||||
$extraClass = isset($extras['class']) ? $extras['class'] . ' select-field' : 'select-field';
|
||||
$form = form_dropdown($field, [
|
||||
"" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택',
|
||||
...$viewDatas['field_options'][$field]
|
||||
], isset($viewDatas[ZoneModel::PARENT]) ? $viewDatas[ZoneModel::PARENT] : $value, [...$extras, 'class' => "select-field"]);
|
||||
// // return form_multiselect($field, $field_options[$field], is_array($value) ? [...$value] : [$value], [$extras]);
|
||||
// foreach ($viewDatas['field_options'][$field] as $key => $label) {
|
||||
// $checkboxs[] = form_checkbox("{$field}[]", $key, in_array($key, explode(DEFAULTS["DELIMITER_ROLE"], $value))) . $label;
|
||||
// }
|
||||
// return implode(" ", $checkboxs);
|
||||
], isset($viewDatas[$field]) ? $viewDatas[$field] : $value, ['class' => $extraClass, ...array_diff_key($extras, ['class' => ''])]);
|
||||
break;
|
||||
case ZoneModel::TITLE:
|
||||
$form = form_input($field, $value, [
|
||||
"placeholder" => "예)exmaple.com",
|
||||
"style" =>
|
||||
"width:100%; ::placeholder{color:silver; opacity: 1;}",
|
||||
"class" => "form-control",
|
||||
"required" => ""
|
||||
"width:100%; ::placeholder{color:silver; opacity: 1;}",
|
||||
...$extras
|
||||
]);
|
||||
break;
|
||||
case 'domains':
|
||||
$form = form_textarea($field, $value, [
|
||||
'rows' => '5',
|
||||
"class" => "form-control",
|
||||
"required" => ""
|
||||
]);
|
||||
$form = form_textarea($field, $value, ['rows' => '5', ...$extras]);
|
||||
break;
|
||||
case 'hosts':
|
||||
$form = form_textarea($field, $value == DEFAULTS['EMPTY'] ? "@\n*\nm\nwww" : $value, [
|
||||
'rows' => '5',
|
||||
"class" => "form-control",
|
||||
"required" => ""
|
||||
...$extras
|
||||
]);
|
||||
break;
|
||||
case 'content':
|
||||
$form = form_input($field, $value, [
|
||||
"placeholder" => "예)123.123.123.123",
|
||||
"style" =>
|
||||
"width:200px; ::placeholder{color:silver; opacity: 1;}",
|
||||
"class" => "form-control",
|
||||
"required" => ""
|
||||
"width:200px; ::placeholder{color:silver; opacity: 1;}",
|
||||
...$extras
|
||||
]);
|
||||
break;
|
||||
case "development_mode":
|
||||
@ -144,4 +133,29 @@ class ZoneHelper extends CommonHelper
|
||||
}
|
||||
return $label;
|
||||
}
|
||||
public function getListButton(string $action, array $viewDatas, array $extras = []): string
|
||||
{
|
||||
switch ($action) {
|
||||
case 'modify':
|
||||
$pk = $viewDatas['entity']->getPK();
|
||||
$checkbox = form_checkbox([
|
||||
"id" => "checkbox_uid_{$pk}",
|
||||
"name" => "batchjob_uids[]",
|
||||
"value" => $pk,
|
||||
"class" => "batchjobuids_checkboxs",
|
||||
"checked" => in_array($pk, old("batchjob_uids[]", []))
|
||||
]);
|
||||
$extras = ["target" => "_self", ...$extras];
|
||||
$action = $checkbox . anchor(
|
||||
current_url() . "/sync/" . $viewDatas['entity']->getPK(),
|
||||
$viewDatas['cnt'],
|
||||
$extras
|
||||
);
|
||||
break;
|
||||
default:
|
||||
$action = parent::getListButton($action, $viewDatas, $extras);
|
||||
break;
|
||||
}
|
||||
return $action;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,9 +2,9 @@
|
||||
|
||||
namespace App\Libraries\Cloudflare;
|
||||
|
||||
use App\Models\Cloudflare\RecordModel;
|
||||
use App\Entities\Cloudflare\ZoneEntity;
|
||||
use App\Entities\Cloudflare\RecordEntity;
|
||||
use App\Entities\Cloudflare\ZoneEntity;
|
||||
use App\Models\Cloudflare\RecordModel;
|
||||
|
||||
class Record extends Cloudflare
|
||||
{
|
||||
@ -101,7 +101,7 @@ class Record extends Cloudflare
|
||||
$formDatas = $this->getArrayByResult($cf->result);
|
||||
return $this->getModel()->modify($entity, $formDatas);
|
||||
}
|
||||
public function delete(RecordEntity $entity): void
|
||||
public function delete(RecordEntity $entity): RecordEntity
|
||||
{
|
||||
$cf = $this->getMySocket()->delete("zones/{$this->_zone_entity->getPK()}/dns_records/{$entity->getPK()}");
|
||||
$cf = json_decode($cf->getBody());
|
||||
@ -113,8 +113,9 @@ class Record extends Cloudflare
|
||||
//DB삭제
|
||||
$this->getModel()->where(RecordModel::PK, $entity->getPK());
|
||||
$this->getModel()->delete();
|
||||
return $entity;
|
||||
}
|
||||
public function sync(RecordEntity $entity): void
|
||||
public function sync(RecordEntity $entity): RecordEntity
|
||||
{
|
||||
// 기존 Sync형태
|
||||
$cf = $this->getMySocket()->get("zones/{$this->_zone_entity->getPK()}/dns_records/{$entity->getPK()}");
|
||||
@ -129,7 +130,7 @@ class Record extends Cloudflare
|
||||
$entity = $this->getModel()->modify($entity, $this->getArrayByResult($cf->result));
|
||||
//Async형태
|
||||
// $promise = $this->getMySocket()getAsync("zones/{$this->_zone_entity->getPK()}/dns_records/{$entity->getPK()}");
|
||||
// $promise->then(
|
||||
// $entity =$promise->then(
|
||||
// onFulfilled: function ($response) use ($entity): RecordEntity {
|
||||
// $record = json_decode($response->getBody(), true)['result'];
|
||||
// log_message("debug", var_export($record));
|
||||
@ -138,10 +139,11 @@ class Record extends Cloudflare
|
||||
// },
|
||||
// onRejected: function ($error) {
|
||||
// log_message('error', 'Failed to fetch DNS records: ' . $error->getMessage());
|
||||
// // throw new \Exception('Failed to fetch DNS records: ' . $error->getMessage());
|
||||
// throw new \Exception('Failed to fetch DNS records: ' . $error->getMessage());
|
||||
// }
|
||||
// );
|
||||
// $promise->wait();
|
||||
return $entity;
|
||||
}
|
||||
//Reload
|
||||
public function reload(): array
|
||||
|
||||
@ -2,9 +2,9 @@
|
||||
|
||||
namespace App\Libraries\Cloudflare;
|
||||
|
||||
use App\Models\Cloudflare\ZoneModel;
|
||||
use App\Entities\Cloudflare\ZoneEntity;
|
||||
use App\Entities\Cloudflare\AccountEntity;
|
||||
use App\Entities\Cloudflare\ZoneEntity;
|
||||
use App\Models\Cloudflare\ZoneModel;
|
||||
|
||||
|
||||
class Zone extends Cloudflare
|
||||
@ -108,7 +108,7 @@ class Zone extends Cloudflare
|
||||
$formDatas = $this->getArrayByResult($cf->result);
|
||||
$entity = $this->getModel()->create($formDatas);
|
||||
|
||||
//초기화값 추가셋팅 ipv6 , development_mode , security_level
|
||||
//초기화값 추가셋팅 ipv6 , development_mode , security_level
|
||||
$formDatas = [];
|
||||
foreach ($this->_setting_fields as $field => $default) {
|
||||
$formDatas[$field] = $this->setCFSetting($entity, $field, $default);
|
||||
@ -126,7 +126,7 @@ class Zone extends Cloudflare
|
||||
//DB수정
|
||||
return $this->getModel()->modify($entity, $formDatas);
|
||||
}
|
||||
public function delete(ZoneEntity $entity): void
|
||||
public function delete(ZoneEntity $entity): ZoneEntity
|
||||
{
|
||||
$cf = $this->getMySocket()->delete("zones/{$entity->getPK()}");
|
||||
$cf = json_decode($cf->getBody());
|
||||
@ -138,8 +138,9 @@ class Zone extends Cloudflare
|
||||
//DB삭제
|
||||
$this->getModel()->where(ZoneModel::PK, $entity->getPK());
|
||||
$this->getModel()->delete();
|
||||
return $entity;
|
||||
}
|
||||
public function sync(ZoneEntity $entity): void
|
||||
public function sync(ZoneEntity $entity): ZoneEntity
|
||||
{
|
||||
$cf = $this->getMySocket()->get("zones/{$entity->getPK()}");
|
||||
$cf = json_decode($cf->getBody());
|
||||
@ -152,7 +153,7 @@ class Zone extends Cloudflare
|
||||
$entity = $this->getModel()->modify($this->getModel()->getEntity(), $formDatas);
|
||||
//추가 셋팅용
|
||||
$formDatas = $this->getCFSetting($entity);
|
||||
$this->getModel()->modify($entity, $formDatas);
|
||||
return $this->getModel()->modify($entity, $formDatas);
|
||||
}
|
||||
//Reload
|
||||
public function reload(): array
|
||||
|
||||
@ -31,4 +31,5 @@
|
||||
<?= form_close(); ?>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript" src="/js/<?= $viewDatas['layout'] ?>/form.js"></script>
|
||||
<?= $this->endSection() ?>
|
||||
61
public/js/admin/form.js
Normal file
61
public/js/admin/form.js
Normal file
@ -0,0 +1,61 @@
|
||||
$(document).ready(function () {
|
||||
//class가 calender인 inputbox용,날짜field용
|
||||
$(".calender").datepicker({
|
||||
changeYear: true,
|
||||
changeMonth: true,
|
||||
yearRange: "-10:+0",
|
||||
dateFormat: "yy-mm-dd"
|
||||
});
|
||||
//id가 batchjobuids_checkbox인 버튼을 클릭시 class가 batchjobuids_checkboxs인 checkbox용
|
||||
$('#batchjobuids_checkbox').click(function (event) {
|
||||
if (this.checked) {
|
||||
$('.batchjobuids_checkboxs').each(function () { //loop checkbox
|
||||
$(this).prop('checked', true); //check
|
||||
});
|
||||
} else {
|
||||
$('.batchjobuids_checkboxs').each(function () { //loop checkbox
|
||||
$(this).prop('checked', false); //uncheck
|
||||
});
|
||||
}
|
||||
});
|
||||
//class가 select-field인 SelectBox용
|
||||
$(".select-field").select2({
|
||||
theme: "classic",
|
||||
width: 'style',
|
||||
dropdownAutoWidth: true
|
||||
});
|
||||
// text editor 초기화
|
||||
//참고: https://phppot.com/menu/php/learn-php/
|
||||
// class가 editor인 textarea용
|
||||
tinymce.init({
|
||||
selector: 'textarea.tinymce',
|
||||
plugins: ['code', 'image', 'preview', 'table', 'emoticons', 'autoresize'],
|
||||
height: 600,
|
||||
// content_style: 'body { font-family:Helvetica,Arial,sans-serif; font-size:16px }'
|
||||
automatic_uploads: false,
|
||||
images_upload_url: '/tinymce_upload.php',
|
||||
// images_upload_base_path: '/upload_images',
|
||||
images_upload_handler: function (blobInfo, success, failure) {
|
||||
var xhr, formData;
|
||||
xhr = new XMLHttpRequest();
|
||||
xhr.withCredentials = false;
|
||||
xhr.open('POST', '/tinymce_upload.php');
|
||||
xhr.onload = function () {
|
||||
var json;
|
||||
if (xhr.status != 200) {
|
||||
failure('HTTP Error: ' + xhr.status);
|
||||
return;
|
||||
}
|
||||
json = JSON.parse(xhr.responseText);
|
||||
if (!json || typeof json.file_path != 'string') {
|
||||
failure('Invalid JSON: ' + xhr.responseText);
|
||||
return;
|
||||
}
|
||||
success(json.file_path);
|
||||
};
|
||||
formData = new FormData();
|
||||
formData.append('file', blobInfo.blob(), blobInfo.filename());
|
||||
xhr.send(formData);
|
||||
},
|
||||
});
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user