Skip to content

Commit

Permalink
ref: format
Browse files Browse the repository at this point in the history
  • Loading branch information
theus77 committed Oct 9, 2024
1 parent dcbd0e9 commit f4df487
Show file tree
Hide file tree
Showing 5 changed files with 406 additions and 792 deletions.
247 changes: 119 additions & 128 deletions EMS/admin-ui-bundle/assets/src/core/core.js
Original file line number Diff line number Diff line change
@@ -1,146 +1,137 @@
import Button from "./plugins/button";
import Choice from "./plugins/choice";
import CodeEditor from "./plugins/codeEditor";
import Collection from "./plugins/collection";
import Datatable from "./plugins/datatable";
import Datetime from "./plugins/datetime";
import File from "./plugins/file";
import Form from "./plugins/form";
import Iframe from "./plugins/iframe";
import Image from "./plugins/image";
import Job from "./plugins/job";
import JsonMenu from "./plugins/jsonMenu";
import JsonMenuNested from "./plugins/jsonMenuNested";
import MediaLibrary from "./plugins/mediaLibrary";
import NestedSortable from "./plugins/nestedSortable";
import ObjectPicker from "./plugins/objectPicker";
import SearchForm from "./plugins/searchForm";
import Select from "./plugins/select";
import SortableList from "./plugins/sortableList";
import SymfonyCollection from "./plugins/symfonyCollection";
import Text from "./plugins/text";
import Tooltip from "./plugins/tooltip";
import WYSIWYG from "./plugins/wysiwyg.ts";
import Button from './plugins/button'
import Choice from './plugins/choice'
import CodeEditor from './plugins/codeEditor'
import Collection from './plugins/collection'
import Datatable from './plugins/datatable'
import Datetime from './plugins/datetime'
import File from './plugins/file'
import Form from './plugins/form'
import Iframe from './plugins/iframe'
import Image from './plugins/image'
import Job from './plugins/job'
import JsonMenu from './plugins/jsonMenu'
import JsonMenuNested from './plugins/jsonMenuNested'
import MediaLibrary from './plugins/mediaLibrary'
import NestedSortable from './plugins/nestedSortable'
import ObjectPicker from './plugins/objectPicker'
import SearchForm from './plugins/searchForm'
import Select from './plugins/select'
import SortableList from './plugins/sortableList'
import SymfonyCollection from './plugins/symfonyCollection'
import Text from './plugins/text'
import Tooltip from './plugins/tooltip'
import WYSIWYG from './plugins/wysiwyg'

import RevisionTask from "./components/revisionTask";
import Modal from "./components/modal";
import Sidebar from "./components/sidebar";
import RevisionTask from './components/revisionTask'
import Modal from './components/modal'
import Sidebar from './components/sidebar'

import { EMS_ADDED_DOM_EVENT } from "./events/addedDomEvent";
import CtrlSaveEvent from "./events/ctrlSaveEvent";
import $ from "jquery";
import { EMS_ADDED_DOM_EVENT } from './events/addedDomEvent'
import CtrlSaveEvent from './events/ctrlSaveEvent'
import $ from 'jquery'

class Core {
constructor() {
this._statusUpdateUrl = document.body.getAttribute("data-status-url");
this._domListeners = [
new Button(),
new Choice(),
new CodeEditor(),
new Collection(),
new Datatable(),
new Datetime(),
new File(),
new Form(),
new Iframe(),
new Image(),
new Job(),
new JsonMenu(),
new JsonMenuNested(),
new MediaLibrary(),
new NestedSortable(),
new ObjectPicker(),
new SearchForm(),
new Select(),
new SortableList(),
new SymfonyCollection(),
new Text(),
new Tooltip(),
new WYSIWYG(),
];
document.addEventListener(EMS_ADDED_DOM_EVENT, (event) =>
this.load(event.detail.target),
);
this.coreReady();
}

load(target) {
if (target === undefined) {
console.log(
"Impossible to add ems listeners as no target is defined",
);
return;
}
this._domListeners.forEach((element) => element.load(target));
}
constructor() {
this._statusUpdateUrl = document.body.getAttribute('data-status-url')
this._domListeners = [
new Button(),
new Choice(),
new CodeEditor(),
new Collection(),
new Datatable(),
new Datetime(),
new File(),
new Form(),
new Iframe(),
new Image(),
new Job(),
new JsonMenu(),
new JsonMenuNested(),
new MediaLibrary(),
new NestedSortable(),
new ObjectPicker(),
new SearchForm(),
new Select(),
new SortableList(),
new SymfonyCollection(),
new Text(),
new Tooltip(),
new WYSIWYG()
]
document.addEventListener(EMS_ADDED_DOM_EVENT, (event) => this.load(event.detail.target))
this.coreReady()
}

coreReady() {
if (
document.readyState === "complete" ||
document.readyState === "interactive"
) {
setTimeout(() => this.load(document), 1);
} else {
document.addEventListener("DOMContentLoaded", () =>
this.load(document),
);
}
this.initStatusRefresh();
this.initCtrlSaveEvent();
this.components = [new RevisionTask(), new Modal(), new Sidebar()];
load(target) {
if (target === undefined) {
console.log('Impossible to add ems listeners as no target is defined')
return
}
this._domListeners.forEach((element) => element.load(target))
}

initStatusRefresh() {
const self = this;
window.setInterval(function () {
self.updateStatus();
}, 180000);
coreReady() {
if (document.readyState === 'complete' || document.readyState === 'interactive') {
setTimeout(() => this.load(document), 1)
} else {
document.addEventListener('DOMContentLoaded', () => this.load(document))
}
this.initStatusRefresh()
this.initCtrlSaveEvent()
this.components = [new RevisionTask(), new Modal(), new Sidebar()]
}

updateStatus() {
const xhr = new XMLHttpRequest();
xhr.open("GET", this._statusUpdateUrl, true);
initStatusRefresh() {
const self = this
window.setInterval(function () {
self.updateStatus()
}, 180000)
}

xhr.onreadystatechange = function () {
if (this.readyState !== 4) {
return;
}
updateStatus() {
const xhr = new XMLHttpRequest()
xhr.open('GET', this._statusUpdateUrl, true)

const statusLink = document.getElementById("status-overview");
if (this.status === 200) {
const json = JSON.parse(xhr.responseText);
statusLink.innerHTML = json.body;
statusLink.setAttribute("title", json.title);
} else {
statusLink.setAttribute("title", `Error ${xhr.status}`);
statusLink.innerHTML = `<i class="fa fa-circle fa-2xs text-red"></i><span class="visually-hidden">Error ${xhr.status}</span>`;
}
};
xhr.onreadystatechange = function () {
if (this.readyState !== 4) {
return
}

xhr.send();
const statusLink = document.getElementById('status-overview')
if (this.status === 200) {
const json = JSON.parse(xhr.responseText)
statusLink.innerHTML = json.body
statusLink.setAttribute('title', json.title)
} else {
statusLink.setAttribute('title', `Error ${xhr.status}`)
statusLink.innerHTML = `<i class="fa fa-circle fa-2xs text-red"></i><span class="visually-hidden">Error ${xhr.status}</span>`
}
}

initCtrlSaveEvent() {
$(document).keydown(function (e) {
let key;
const possible = [e.key, e.keyIdentifier, e.keyCode, e.which];
xhr.send()
}

while (key === undefined && possible.length > 0) {
key = possible.pop();
}
if (
typeof key === "number" &&
(key === 115 || key === 83) &&
(e.ctrlKey || e.metaKey) &&
!e.altKey
) {
const event = new CtrlSaveEvent(e);
event.dispatch();
}
});
}
initCtrlSaveEvent() {
$(document).keydown(function (e) {
let key
const possible = [e.key, e.keyIdentifier, e.keyCode, e.which]

while (key === undefined && possible.length > 0) {
key = possible.pop()
}
if (
typeof key === 'number' &&
(key === 115 || key === 83) &&
(e.ctrlKey || e.metaKey) &&
!e.altKey
) {
const event = new CtrlSaveEvent(e)
event.dispatch()
}
})
}
}

const core = new Core();
const core = new Core()

export default core;
export default core
Loading

0 comments on commit f4df487

Please sign in to comment.