Browse Source

add linter and apply linter

develop
Simon Vieille 3 months ago
parent
commit
631281dc3c
  1. 19
      .eslintrc.json
  2. 42
      assets/js/admin/admin.js
  3. 62
      assets/js/admin/components/file-manager/FileIcon.vue
  4. 8
      assets/js/admin/components/file-manager/FileManager.vue
  5. 205
      assets/js/admin/components/file-manager/Files.vue
  6. 28
      assets/js/admin/modules/batch.js
  7. 42
      assets/js/admin/modules/checkbox-checker.js
  8. 12
      assets/js/admin/modules/choices.js
  9. 30
      assets/js/admin/modules/datepicker.js
  10. 12
      assets/js/admin/modules/dbclick.js
  11. 82
      assets/js/admin/modules/document-selector.js
  12. 152
      assets/js/admin/modules/editor.js
  13. 20
      assets/js/admin/modules/file-manager.js
  14. 128
      assets/js/admin/modules/form-collection.js
  15. 24
      assets/js/admin/modules/form-confirm.js
  16. 48
      assets/js/admin/modules/form.js
  17. 76
      assets/js/admin/modules/modal.js
  18. 90
      assets/js/admin/modules/panel.js
  19. 132
      assets/js/admin/modules/password.js
  20. 60
      assets/js/admin/modules/push-state.js
  21. 46
      assets/js/admin/modules/rest-choices.js
  22. 48
      assets/js/admin/modules/sortable.js
  23. 30
      assets/js/admin/modules/table-fixed.js
  24. 213
      assets/js/admin/modules/table-selectable.js
  25. 18
      assets/js/admin/modules/toast.js
  26. 8
      assets/js/admin/modules/tooltip.js
  27. 1011
      package-lock.json
  28. 6
      package.json
  29. 691
      yarn.lock

19
.eslintrc.json

@ -0,0 +1,19 @@
{
"env": {
"browser": true,
"commonjs": true,
"es2021": true
},
"extends": [
"plugin:vue/essential",
"standard"
],
"parserOptions": {
"ecmaVersion": 12
},
"plugins": [
"vue"
],
"rules": {
}
}

42
assets/js/admin/admin.js

@ -1,22 +1,22 @@
import '../../css/admin.scss';
import '../../css/admin.scss'
require('../../../node_modules/bootstrap/dist/js/bootstrap.min.js');
require('./modules/table-fixed.js')();
require('./modules/form-confirm.js')();
require('./modules/form.js')();
require('./modules/dbclick.js')();
require('./modules/toast.js')();
require('./modules/modal.js')();
require('./modules/push-state.js')();
require('./modules/password.js')();
require('./modules/tooltip.js')();
require('./modules/editor.js')();
require('./modules/panel.js')();
require('./modules/choices.js')();
require('./modules/checkbox-checker.js')();
require('./modules/rest-choices.js')();
require('./modules/form-collection.js')();
require('./modules/datepicker.js')();
require('./modules/sortable.js')();
require('./modules/batch.js')();
require('./modules/file-manager.js')();
require('../../../node_modules/bootstrap/dist/js/bootstrap.min.js')
require('./modules/table-fixed.js')()
require('./modules/form-confirm.js')()
require('./modules/form.js')()
require('./modules/dbclick.js')()
require('./modules/toast.js')()
require('./modules/modal.js')()
require('./modules/push-state.js')()
require('./modules/password.js')()
require('./modules/tooltip.js')()
require('./modules/editor.js')()
require('./modules/panel.js')()
require('./modules/choices.js')()
require('./modules/checkbox-checker.js')()
require('./modules/rest-choices.js')()
require('./modules/form-collection.js')()
require('./modules/datepicker.js')()
require('./modules/sortable.js')()
require('./modules/batch.js')()
require('./modules/file-manager.js')()

62
assets/js/admin/components/file-manager/FileIcon.vue

@ -4,42 +4,42 @@
<script>
const map = {
'fa-file-pdf': ['application/pdf'],
'fa-file-image': ['image/png', 'image/jpg', 'image/jpeg', 'image/gif'],
'fa-file-audio': ['application/ogg', 'audio/mp3', 'audio/mpeg', 'audio/wav'],
'fa-file-archive': ['application/zip', 'multipart/x-zip', 'application/rar', 'application/x-rar-compressed', 'application/x-zip-compressed', 'application/tar', 'application/x-tar'],
'fa-file-alt': ['application/rtf'],
'fa-file-excel': ['application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'],
'fa-file-powerpoint': ['application/vnd.ms-powerpoint', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'],
'fa-file-video': ['video/x-msvideo', 'video/mpeg'],
'fa-file-pdf': ['application/pdf'],
'fa-file-image': ['image/png', 'image/jpg', 'image/jpeg', 'image/gif'],
'fa-file-audio': ['application/ogg', 'audio/mp3', 'audio/mpeg', 'audio/wav'],
'fa-file-archive': ['application/zip', 'multipart/x-zip', 'application/rar', 'application/x-rar-compressed', 'application/x-zip-compressed', 'application/tar', 'application/x-tar'],
'fa-file-alt': ['application/rtf'],
'fa-file-excel': ['application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'],
'fa-file-powerpoint': ['application/vnd.ms-powerpoint', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'],
'fa-file-video': ['video/x-msvideo', 'video/mpeg']
}
export default {
name: 'FileIcon',
methods: {
getIcon(mime) {
let icons = ['fa']
let iconFound = false
name: 'FileIcon',
methods: {
getIcon (mime) {
const icons = ['fa']
let iconFound = false
for (let icon in map) {
if (map[icon].indexOf(mime) !== -1) {
iconFound = true
icons.push(icon)
}
}
for (const icon in map) {
if (map[icon].indexOf(mime) !== -1) {
iconFound = true
icons.push(icon)
}
}
if (!iconFound) {
icons.push('fa-file')
}
if (!iconFound) {
icons.push('fa-file')
}
return icons
},
},
props: {
mime: {
type: String,
required: true
},
},
return icons
}
},
props: {
mime: {
type: String,
required: true
}
}
}
</script>

8
assets/js/admin/components/file-manager/FileManager.vue

@ -15,9 +15,9 @@
import Files from './Files'
export default {
name: "FileManager",
components: {
Files,
}
name: 'FileManager',
components: {
Files
}
}
</script>

205
assets/js/admin/components/file-manager/Files.vue

@ -165,121 +165,120 @@ tr {
</style>
<script>
import Routing from '../../../../../vendor/friendsofsymfony/jsrouting-bundle/Resources/public/js/router.min.js'
import FileIcon from './FileIcon'
const axios = require('axios').default
const routes = require('../../../../../public/js/fos_js_routes.json')
import Routing from '../../../../../vendor/friendsofsymfony/jsrouting-bundle/Resources/public/js/router.min.js';
import FileIcon from './FileIcon';
Routing.setRoutingData(routes);
export default {
name: "Files",
components: {
FileIcon,
name: 'Files',
components: {
FileIcon
},
data () {
return {
view: 'list',
directory: null,
directories: [],
breadcrumb: [],
files: [],
parent: null
}
},
methods: {
setDirectory (directory) {
this.directory = directory
},
data() {
return {
view: 'list',
directory: null,
directories: [],
breadcrumb: [],
files: [],
parent: null,
}
setView (view) {
this.view = view
localStorage.setItem('file-manager.view', view)
},
methods: {
setDirectory(directory) {
this.directory = directory
},
setView(view) {
this.view = view
localStorage.setItem('file-manager.view', view)
},
generateInfoLink(item, directory) {
if (directory) {
return Routing.generate('admin_file_manager_info', {
file: item.path
})
} else {
return Routing.generate('admin_file_manager_info', {
file: item.path + '/' + item.basename
})
}
},
generateUploadLink(directory) {
return Routing.generate('admin_file_manager_upload', {
file: directory
})
},
generateNewDirectoryLink(directory) {
return Routing.generate('admin_file_manager_directory_new', {
file: directory
})
},
buildBreadcrum(elements) {
let path = '/'
this.breadcrumb = []
for (let i in elements) {
const element = elements[i]
if (element !== '/') {
path = path + '/' + element
this.breadcrumb.push({
path: path,
label: element,
})
} else {
this.breadcrumb.push({
path: '/',
label: 'Files',
})
}
}
}
generateInfoLink (item, directory) {
if (directory) {
return Routing.generate('admin_file_manager_info', {
file: item.path
})
} else {
return Routing.generate('admin_file_manager_info', {
file: item.path + '/' + item.basename
})
}
},
generateUploadLink (directory) {
return Routing.generate('admin_file_manager_upload', {
file: directory
})
},
generateNewDirectoryLink (directory) {
return Routing.generate('admin_file_manager_directory_new', {
file: directory
})
},
mounted() {
let view = localStorage.getItem('file-manager.view')
buildBreadcrum (elements) {
let path = '/'
this.breadcrumb = []
if (['grid', 'list'].indexOf(view) !== -1) {
this.view = view
}
for (const i in elements) {
const element = elements[i]
const query = new URLSearchParams(window.location.search)
if (element !== '/') {
path = path + '/' + element
if (query.has('path')) {
this.setDirectory(query.get('path'))
this.breadcrumb.push({
path: path,
label: element
})
} else {
this.setDirectory('/')
}
},
watch: {
directory(directory) {
axios.get(Routing.generate('admin_file_manager_api_directory', {
directory: this.directory
}))
.then((response) => {
this.buildBreadcrum(response.data.breadcrumb)
this.parent = response.data.parent
this.directories = response.data.directories
this.files = response.data.files
const query = new URLSearchParams(window.location.search)
query.set('path', directory)
history.pushState(
null,
'',
window.location.pathname + '?' + query.toString()
)
})
.catch(() => {
alert('An error occured')
})
this.breadcrumb.push({
path: '/',
label: 'Files'
})
}
}
}
},
mounted () {
Routing.setRoutingData(routes)
const view = localStorage.getItem('file-manager.view')
if (['grid', 'list'].indexOf(view) !== -1) {
this.view = view
}
const query = new URLSearchParams(window.location.search)
if (query.has('path')) {
this.setDirectory(query.get('path'))
} else {
this.setDirectory('/')
}
},
watch: {
directory (directory) {
axios.get(Routing.generate('admin_file_manager_api_directory', {
directory: this.directory
}))
.then((response) => {
this.buildBreadcrum(response.data.breadcrumb)
this.parent = response.data.parent
this.directories = response.data.directories
this.files = response.data.files
const query = new URLSearchParams(window.location.search)
query.set('path', directory)
history.pushState(
null,
'',
window.location.pathname + '?' + query.toString()
)
})
.catch(() => {
alert('An error occured')
})
}
}
}
</script>

28
assets/js/admin/modules/batch.js

@ -1,23 +1,23 @@
const $ = require('jquery')
module.exports = () => {
$('th.crud-batch-column input').change((e) => {
$('td.crud-batch-column input').prop('checked', $(e.target).is(':checked'));
});
$('th.crud-batch-column input').change((e) => {
$('td.crud-batch-column input').prop('checked', $(e.target).is(':checked'))
})
const form = $('#form-batch')
const form = $('#form-batch')
form.submit((e) => {
e.preventDefault();
form.submit((e) => {
e.preventDefault()
const route = form.attr('action')
const datas = form.serialize()
const route = form.attr('action')
const datas = form.serialize()
form.addClass('is-loading');
form.addClass('is-loading')
$.post(route, datas)
.always(() => {
document.location.href = document.location.href
});
});
$.post(route, datas)
.always(() => {
document.location.href = document.location.href
})
})
}

42
assets/js/admin/modules/checkbox-checker.js

@ -1,31 +1,31 @@
const $ = require('jquery');
const $ = require('jquery')
module.exports = function() {
$('*[data-checkbox-ckecker]').click(function() {
const wrapperName = $(this).attr('data-checkbox-ckecker');
module.exports = function () {
$('*[data-checkbox-ckecker]').click(function () {
const wrapperName = $(this).attr('data-checkbox-ckecker')
if (!wrapperName) {
return;
}
if (!wrapperName) {
return
}
const checkboxes = $('*[data-checkbox-wrapper="' + wrapperName + '"] *[data-checkbox] input[type="checkbox"]');
const checkboxes = $('*[data-checkbox-wrapper="' + wrapperName + '"] *[data-checkbox] input[type="checkbox"]')
$(checkboxes).each(function(i, v) {
$(v).prop('checked', true);
})
$(checkboxes).each(function (i, v) {
$(v).prop('checked', true)
})
})
$('*[data-checkbox-unckecker]').click(function() {
const wrapperName = $(this).attr('data-checkbox-unckecker');
$('*[data-checkbox-unckecker]').click(function () {
const wrapperName = $(this).attr('data-checkbox-unckecker')
if (!wrapperName) {
return;
}
if (!wrapperName) {
return
}
const checkboxes = $('*[data-checkbox-wrapper="' + wrapperName + '"] *[data-checkbox] input[type="checkbox"]');
const checkboxes = $('*[data-checkbox-wrapper="' + wrapperName + '"] *[data-checkbox] input[type="checkbox"]')
$(checkboxes).each(function(i, v) {
$(v).prop('checked', false);
})
$(checkboxes).each(function (i, v) {
$(v).prop('checked', false)
})
};
})
}

12
assets/js/admin/modules/choices.js

@ -1,8 +1,8 @@
const Choices = require('choices.js');
const $ = require('jquery');
const Choices = require('choices.js')
const $ = require('jquery')
module.exports = function() {
$('*[data-jschoice]').each(function(key, item) {
new Choices(item);
});
module.exports = function () {
$('*[data-jschoice]').each(function (key, item) {
new Choices(item)
})
}

30
assets/js/admin/modules/datepicker.js

@ -1,26 +1,26 @@
const Datepicker = require('vanillajs-datepicker')
const isDateSupported = () => {
const input = document.createElement('input');
const value = 'a';
const input = document.createElement('input')
const value = 'a'
input.setAttribute('type', 'date');
input.setAttribute('value', value);
input.setAttribute('type', 'date')
input.setAttribute('value', value)
return input.value !== value;
return input.value !== value
}
module.exports = () => {
if (isDateSupported()) {
return
}
if (isDateSupported()) {
return
}
const inputs = document.querySelectorAll('input[type="date"]')
const size = inputs.length
const inputs = document.querySelectorAll('input[type="date"]')
const size = inputs.length
for (var i = 0, c = inputs.length; i < c; i++) {
new Datepicker.Datepicker(inputs[i], {
format: 'yyyy-mm-dd'
})
}
for (let i = 0, c = inputs.length; i < c; i++) {
new Datepicker.Datepicker(inputs[i], {
format: 'yyyy-mm-dd'
})
}
}

12
assets/js/admin/modules/dbclick.js

@ -1,7 +1,7 @@
const $ = require('jquery');
const $ = require('jquery')
module.exports = function() {
$('*[data-dblclick]').dblclick(function(e) {
document.location.href = $(this).attr('data-dblclick');
})
};
module.exports = function () {
$('*[data-dblclick]').dblclick(function (e) {
document.location.href = $(this).attr('data-dblclick')
})
}

82
assets/js/admin/modules/document-selector.js

@ -1,43 +1,43 @@
const $ = require('jquery');
let DocumentSelector = () => {
let forms = $('.document-selector-form');
let btnSubmit = $('#download-archive-form button');
let handler = function() {
forms.each((fi, f) => {
let form = $(f);
let ids = form.find('.document-selector-ids');
let btn = form.find('.document-selector-button');
ids.html('');
let hasSelection = false;
$('*[data-documents] *[data-selectable-row] input[data-selectable-checkbox]').each((i, c) => {
let checkbox = $(c);
if (checkbox.is(':checked')) {
ids.append(checkbox[0].outerHTML);
hasSelection = true;
}
});
if (hasSelection && btn.length) {
btn.removeAttr('disabled');
ids.find('input').prop('checked', true);
} else {
btn.attr('disabled', 'disabled');
}
})
}
$('*[data-documents] *[data-selectable-row]').click(function() {
window.setTimeout(handler, 100)
});
$('*[data-documents] *[data-selectable-row]').on('clicked', function() {
window.setTimeout(handler, 100)
});
const $ = require('jquery')
const DocumentSelector = () => {
const forms = $('.document-selector-form')
const btnSubmit = $('#download-archive-form button')
const handler = function () {
forms.each((fi, f) => {
const form = $(f)
const ids = form.find('.document-selector-ids')
const btn = form.find('.document-selector-button')
ids.html('')
let hasSelection = false
$('*[data-documents] *[data-selectable-row] input[data-selectable-checkbox]').each((i, c) => {
const checkbox = $(c)
if (checkbox.is(':checked')) {
ids.append(checkbox[0].outerHTML)
hasSelection = true
}
})
if (hasSelection && btn.length) {
btn.removeAttr('disabled')
ids.find('input').prop('checked', true)
} else {
btn.attr('disabled', 'disabled')
}
})
}
$('*[data-documents] *[data-selectable-row]').click(function () {
window.setTimeout(handler, 100)
})
$('*[data-documents] *[data-selectable-row]').on('clicked', function () {
window.setTimeout(handler, 100)
})
}
module.exports = DocumentSelector;
module.exports = DocumentSelector

152
assets/js/admin/modules/editor.js

@ -1,100 +1,100 @@
const $ = require('jquery')
if (typeof tinymce !== 'undefined') {
tinymce.murph = tinymce.murph || {}
tinymce.murph.selector = tinymce.murph.selector || '*[data-tinymce]'
tinymce.murph.configurationBase = tinymce.murph.configurationBase || {
base_url: '/vendor/tinymce/',
cache_suffix: '?v=4.1.6',
importcss_append: true,
image_caption: true,
noneditable_noneditable_class: "mceNonEditable",
toolbar_drawer: 'sliding',
spellchecker_dialog: true,
tinycomments_mode: 'embedded',
convert_urls: false,
init_instance_callback: function (editor) {
editor.on('SetContent', () => {
tinymce.triggerSave(false, true);
});
editor.on('Change', () => {
tinymce.triggerSave(false, true);
});
}
}
tinymce.murph.modes = tinymce.murph.modes || {}
tinymce.murph.modes.default = tinymce.murph.modes.default || {
plugins: 'print preview importcss searchreplace visualblocks visualchars fullscreen template table charmap hr pagebreak nonbreaking toc insertdatetime advlist lists wordcount textpattern noneditable help charmap quickbars link image code autoresize',
menubar: 'file edit view insert format tools table tc help',
toolbar: 'undo redo | bold italic underline strikethrough | link image | fontselect fontsizeselect formatselect | alignleft aligncenter alignright alignjustify | outdent indent | numlist bullist checklist | forecolor backcolor casechange permanentpen formatpainter removeformat | pagebreak | charmap | fullscreen preview',
quickbars_selection_toolbar: 'bold italic | quicklink h2 h3 blockquote quickimage quicktable',
contextmenu: "link image imagetools table configurepermanentpen",
}
tinymce.murph.modes.light = tinymce.murph.modes.light || {
contextmenu: "link image imagetools table configurepermanentpen",
quickbars_selection_toolbar: 'bold italic',
toolbar: 'undo redo | bold italic underline',
tinymce.murph = tinymce.murph || {}
tinymce.murph.selector = tinymce.murph.selector || '*[data-tinymce]'
tinymce.murph.configurationBase = tinymce.murph.configurationBase || {
base_url: '/vendor/tinymce/',
cache_suffix: '?v=4.1.6',
importcss_append: true,
image_caption: true,
noneditable_noneditable_class: 'mceNonEditable',
toolbar_drawer: 'sliding',
spellchecker_dialog: true,
tinycomments_mode: 'embedded',
convert_urls: false,
init_instance_callback: function (editor) {
editor.on('SetContent', () => {
tinymce.triggerSave(false, true)
})
editor.on('Change', () => {
tinymce.triggerSave(false, true)
})
}
}
tinymce.murph.modes = tinymce.murph.modes || {}
tinymce.murph.modes.default = tinymce.murph.modes.default || {
plugins: 'print preview importcss searchreplace visualblocks visualchars fullscreen template table charmap hr pagebreak nonbreaking toc insertdatetime advlist lists wordcount textpattern noneditable help charmap quickbars link image code autoresize',
menubar: 'file edit view insert format tools table tc help',
toolbar: 'undo redo | bold italic underline strikethrough | link image | fontselect fontsizeselect formatselect | alignleft aligncenter alignright alignjustify | outdent indent | numlist bullist checklist | forecolor backcolor casechange permanentpen formatpainter removeformat | pagebreak | charmap | fullscreen preview',
quickbars_selection_toolbar: 'bold italic | quicklink h2 h3 blockquote quickimage quicktable',
contextmenu: 'link image imagetools table configurepermanentpen'
}
tinymce.murph.modes.light = tinymce.murph.modes.light || {
contextmenu: 'link image imagetools table configurepermanentpen',
quickbars_selection_toolbar: 'bold italic',
toolbar: 'undo redo | bold italic underline'
}
}
const buildConfiguration = (conf) => {
return Object.assign({}, tinymce.murph.configurationBase, conf);
return Object.assign({}, tinymce.murph.configurationBase, conf)
}
const makeId = () => {
let result = '';
const characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
const charactersLength = characters.length;
let result = ''
const characters = 'abcdefghijklmnopqrstuvwxyz0123456789'
const charactersLength = characters.length
for ( var i = 0; i < 20; i++ ) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
for (let i = 0; i < 20; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength))
}
return 'tinymce-' + result;
return 'tinymce-' + result
}
const doInitEditor = () => {
$(tinymce.murph.selector).each((i, v) => {
const element = $(v);
let id = null
if (element.attr('id')) {
id = element.attr('id')
} else {
id = makeId()
element.attr('id', makeId)
}
$(tinymce.murph.selector).each((i, v) => {
const element = $(v)
let id = null
if (element.attr('id')) {
id = element.attr('id')
} else {
id = makeId()
element.attr('id', makeId)
}
let mode = element.attr('data-tinymce')
let mode = element.attr('data-tinymce')
if (!mode) {
mode = 'default';
}
if (!mode) {
mode = 'default'
}
if (!tinymce.murph.modes.hasOwnProperty(mode)) {
return;
}
if (!tinymce.murph.modes.hasOwnProperty(mode)) {
return
}
let conf = buildConfiguration(tinymce.murph.modes[mode])
conf.mode = 'exact'
conf.elements = id
const conf = buildConfiguration(tinymce.murph.modes[mode])
conf.mode = 'exact'
conf.elements = id
tinymce.init(conf);
})
tinymce.init(conf)
})
}
module.exports = function() {
if (typeof tinymce === 'undefined') {
return;
}
module.exports = function () {
if (typeof tinymce === 'undefined') {
return
}
const observer = new MutationObserver(doInitEditor);
const config = {attributes: false, childList: true, subtree: true};
observer.observe(document.querySelector('body'), config);
const observer = new MutationObserver(doInitEditor)
const config = { attributes: false, childList: true, subtree: true }
observer.observe(document.querySelector('body'), config)
doInitEditor();
};
doInitEditor()
}

20
assets/js/admin/modules/file-manager.js

@ -4,15 +4,15 @@ const Vue = require('vue').default
const FileManager = require('../components/file-manager/FileManager').default
module.exports = () => {
if (!document.getElementById('file-manager')) {
return
}
if (!document.getElementById('file-manager')) {
return
}
new Vue({
el: '#file-manager',
template: '<FileManager />',
components: {
FileManager
}
});
new Vue({
el: '#file-manager',
template: '<FileManager />',
components: {
FileManager
}
})
}

128
assets/js/admin/modules/form-collection.js

@ -1,84 +1,84 @@
const $ = require('jquery');
const $ = require('jquery')
const DeleteHandler = (e) => {
e.stopPropagation()
const target = e.target;
let button = $(target);
if (button.is('[data-collection-delete-container]')) {
button = button.find('*[data-collection-delete]').first()
}
const id = button.attr('data-collection-delete');
const collection = button.parents('[data-collection]')
const item = collection.find('*[data-collection-item="' + id + '"]')
if (confirm('Validez-vous la suppression ?')) {
item.remove();
collection.trigger('collection.update');
}
e.stopPropagation()
const target = e.target
let button = $(target)
if (button.is('[data-collection-delete-container]')) {
button = button.find('*[data-collection-delete]').first()
}
const id = button.attr('data-collection-delete')
const collection = button.parents('[data-collection]')
const item = collection.find('*[data-collection-item="' + id + '"]')
if (confirm('Validez-vous la suppression ?')) {
item.remove()
collection.trigger('collection.update')
}
}
const CollectionInitilizedAndUpdated = (e) => {
const target = $(e.target)
const target = $(e.target)
target.find('*[data-collection-empty]').toggleClass(
'd-none',
target.find('*[data-collection-item]').length !== 0
);
target.find('*[data-collection-empty]').toggleClass(
'd-none',
target.find('*[data-collection-item]').length !== 0
)
target.find('*[data-collection-nonempty]').toggleClass(
'd-none',
target.find('*[data-collection-item]').length === 0
);
target.find('*[data-collection-nonempty]').toggleClass(
'd-none',
target.find('*[data-collection-item]').length === 0
)
}
const FormCollection = () => {
$('*[data-collection]').on(
'collection.update',
CollectionInitilizedAndUpdated
);
$('*[data-collection]').on(
'collection.init',
CollectionInitilizedAndUpdated
);
$('body').on(
'click',
'*[data-collection-delete], *[data-collection-delete-container]',
DeleteHandler
);
$('body').on('click', '*[data-collection-add]', (e) => {
e.stopPropagation()
$('*[data-collection]').on(
'collection.update',
CollectionInitilizedAndUpdated
)
$('*[data-collection]').on(
'collection.init',
CollectionInitilizedAndUpdated
)
$('body').on(
'click',
'*[data-collection-delete], *[data-collection-delete-container]',
DeleteHandler
)
$('body').on('click', '*[data-collection-add]', (e) => {
e.stopPropagation()
const collectionId = $(e.target).attr('data-collection-add')
const collectionContainer = $('*[data-collection="' + collectionId + '"]')
const prototypeContent = $('#' + collectionId).html()
let name = 0
const collectionId = $(e.target).attr('data-collection-add')
const collectionContainer = $('*[data-collection="' + collectionId + '"]')
const prototypeContent = $('#' + collectionId).html()
let name = 0
collectionContainer.find('*[data-collection-item]').each(function() {
var n = parseInt($(this).attr('data-collection-item'))
collectionContainer.find('*[data-collection-item]').each(function () {
const n = parseInt($(this).attr('data-collection-item'))
if (n >= name) {
name = n + 1
}
})
if (n >= name) {
name = n + 1
}
})
collectionContainer.append(prototypeContent)
collectionContainer.append(prototypeContent)
const item = collectionContainer.children('*[data-collection-item]:last-child')
const deleteBtn = $('<span data-collection-delete="__name__" class="fa fa-trash"></span>')
const item = collectionContainer.children('*[data-collection-item]:last-child')
const deleteBtn = $('<span data-collection-delete="__name__" class="fa fa-trash"></span>')
item.find('*[data-collection-delete-container]').first().append(deleteBtn)
item.html(item.html().replace(/__name__/g, name))
item.attr('data-collection-item', name)
item.find('*[data-collection-delete-container]').first().append(deleteBtn)
item.html(item.html().replace(/__name__/g, name))
item.attr('data-collection-item', name)
collectionContainer.trigger('collection.update');
});
collectionContainer.trigger('collection.update')
})
$('*[data-collection]').trigger('collection.init');
$('*[data-collection]').trigger('collection.init')
}
module.exports = FormCollection;
module.exports = FormCollection

24
assets/js/admin/modules/form-confirm.js

@ -1,15 +1,15 @@
const $ = require('jquery');
const $ = require('jquery')
module.exports = function() {
$('body').on('submit', '*[data-form-confirm]', function(e) {
let message = $(this).attr('data-form-confirm');
module.exports = function () {
$('body').on('submit', '*[data-form-confirm]', function (e) {
let message = $(this).attr('data-form-confirm')
if (!message) {
message = 'Confimez-vous cette action ?';
}
if (!message) {
message = 'Confimez-vous cette action ?'
}
if (!confirm(message)) {
e.preventDefault();
}
})
};
if (!confirm(message)) {
e.preventDefault()
}
})
}

48
assets/js/admin/modules/form.js

@ -1,31 +1,31 @@
const $ = require('jquery');
const $ = require('jquery')
module.exports = function() {
$('body').on('change', '.custom-file-input', function(event) {
let inputFile = event.currentTarget;
module.exports = function () {
$('body').on('change', '.custom-file-input', function (event) {
const inputFile = event.currentTarget
$(inputFile).parent()
.find('.custom-file-label')
.html(inputFile.files[0].name);
});
$(inputFile).parent()
.find('.custom-file-label')
.html(inputFile.files[0].name)
})
$('.nav a').each(function() {
const link = $(this)
const href = link.attr('href')
$('.nav a').each(function () {
const link = $(this)
const href = link.attr('href')
if (href.substr(0, 1) !== '#') {
return
}
if (href.substr(0, 1) !== '#') {
return
}
const tab = $('.tab-pane ' + href)
const tab = $('.tab-pane ' + href)
if (!tab.length) {
return
}
if (!tab.length) {
return
}
if (tab.find('.form-error-message').length) {
link.addClass('border border-danger')
link.click()
}
})
};
if (tab.find('.form-error-message').length) {
link.addClass('border border-danger')
link.click()
}
})
}

76
assets/js/admin/modules/modal.js

@ -1,56 +1,56 @@
const $ = require('jquery');
const $ = require('jquery')
module.exports = function() {
let click = 0;
module.exports = function () {
let click = 0
$('body').on('click', '*[data-modal]', (e) => {
e.preventDefault();
e.stopPropagation();
$('body').on('click', '*[data-modal]', (e) => {
e.preventDefault()
e.stopPropagation()
++click;
++click
window.setTimeout(() => {
if (click !== 1) {
click = 0;
window.setTimeout(() => {
if (click !== 1) {
click = 0
return;
}
return
}
click = 0;
click = 0
let container = $('#modal-container');
const body = $('body')
let container = $('#modal-container')
const body = $('body')
if (!container.length) {
container = $('<div id="modal-container" class="modal">');
if (!container.length) {
container = $('<div id="modal-container" class="modal">')
body.append(container);
}
body.append(container)
}
const loader = $('<div style="position: absolute; top: 25vh; left: 50vw; z-index: 2000">');
loader.html('<div class="spinner-border text-primary" role="status"><span class="sr-only">Loading...</span></div>');
body.append(loader);
const loader = $('<div style="position: absolute; top: 25vh; left: 50vw; z-index: 2000">')
loader.html('<div class="spinner-border text-primary" role="status"><span class="sr-only">Loading...</span></div>')
body.append(loader)
container.html('');
container.html('')
let url = $(e.target).attr('data-modal');
let url = $(e.target).attr('data-modal')
if (!url) {
url = $(e.target).parents('*[data-modal]').first().attr('data-modal');
}
if (!url) {
url = $(e.target).parents('*[data-modal]').first().attr('data-modal')
}
$(container).modal('show');
$(container).modal('show')
container.load(url, function() {
loader.remove()
});
}, 250)
});
container.load(url, function () {
loader.remove()
})
}, 250)
})
const urlParams = new URLSearchParams(window.location.search)
const dataModal = urlParams.get('data-modal')
const urlParams = new URLSearchParams(window.location.search)
const dataModal = urlParams.get('data-modal')
if (dataModal) {
$('*[data-modal="' + dataModal + '"]').first().click();
}
if (dataModal) {
$('*[data-modal="' + dataModal + '"]').first().click()
}
}

90
assets/js/admin/modules/panel.js

@ -1,47 +1,47 @@
const $ = require('jquery');
let Pannel = () => {
let panels = $('.panel');
panels.each((i, p) => {
let panel = $(p);
let content = panel.find('.panel-content').first();
let togglers = panel.find('.panel-toggler');
togglers.each((k, t) => {
let toggler = $(t);
if (!toggler.is('.fa')) {
return;
}
if (content.is('.active')) {
toggler.removeClass('fa-arrow-down');
toggler.addClass('fa-arrow-up');
} else {
toggler.removeClass('fa-arrow-up');
toggler.addClass('fa-arrow-down');
}
})
togglers.click(function(e) {
e.stopPropagation();
content.toggleClass('active');
togglers.each((k, t) => {
let toggler = $(t);
if (!toggler.is('.fa')) {
return;
}
toggler
.toggleClass('fa-arrow-down')
.toggleClass('fa-arrow-up');
})
});
});
const $ = require('jquery')
const Pannel = () => {
const panels = $('.panel')
panels.each((i, p) => {
const panel = $(p)
const content = panel.find('.panel-content').first()
const togglers = panel.find('.panel-toggler')
togglers.each((k, t) => {
const toggler = $(t)
if (!toggler.is('.fa')) {
return
}
if (content.is('.active')) {
toggler.removeClass('fa-arrow-down')
toggler.addClass('fa-arrow-up')
} else {
toggler.removeClass('fa-arrow-up')
toggler.addClass('fa-arrow-down')
}
})
togglers.click(function (e) {
e.stopPropagation()
content.toggleClass('active')
togglers.each((k, t) => {
const toggler = $(t)
if (!toggler.is('.fa')) {
return
}
toggler
.toggleClass('fa-arrow-down')
.toggleClass('fa-arrow-up')
})
})
})
}
module.exports = Pannel;
module.exports = Pannel

132
assets/js/admin/modules/password.js

@ -1,82 +1,82 @@
const $ = require('jquery');
const zxcvbn = require('zxcvbn');
const $ = require('jquery')
const zxcvbn = require('zxcvbn')
let scoreColors = [
'danger',
'danger',
'warning',
'warning',
'success',
];
const scoreColors = [
'danger',
'danger',
'warning',
'warning',
'success'
]
let scoreInfos = {
"This is a top-10 common password": "Parmis le top 10 des mots de passes communs",
"This is a top-100 common password": "Parmis le top 100 des mots de passes communs",
"This is a very common password": "Mot de passe vraiment trop commun",
"This is similar to a commonly used password": "Similaire à un mot de passe commun",
"A word by itself is easy to guess": "Ce mot est trop simple à deviner",
"Names and surnames by themselves are easy to guess": "Les noms ou les surnoms sont simples à deviner",
"Common names and surnames are easy to guess": "Les noms ou les surnoms sont simples à deviner",
"Straight rows of keys are easy to guess": "Combinaison de touches trop simple",
"Short keyboard patterns are easy to guess": "Combinaison de touches trop simple",
"Repeats like \"aaa\" are easy to guess'": "Les répétitions comme \"aaa\" sont simples à deviner",
"Repeats like \"abcabcabc\" are only slightly harder to guess than \"abc\"": "Les répétitions comme \"abcabcabc\" sont simples à deviner",
"Sequences like abc or 6543 are easy to guess": "Les séquences comme \"abc\" ou \"6543\" sont simples à deviner",
"Recent years are easy to guess": "Les années sont simples à deviner",
"Dates are often easy to guess": "Les dates sont souvent simples à deviner",
const scoreInfos = {
'This is a top-10 common password': 'Parmis le top 10 des mots de passes communs',
'This is a top-100 common password': 'Parmis le top 100 des mots de passes communs',
'This is a very common password': 'Mot de passe vraiment trop commun',
'This is similar to a commonly used password': 'Similaire à un mot de passe commun',
'A word by itself is easy to guess': 'Ce mot est trop simple à deviner',
'Names and surnames by themselves are easy to guess': 'Les noms ou les surnoms sont simples à deviner',
'Common names and surnames are easy to guess': 'Les noms ou les surnoms sont simples à deviner',
'Straight rows of keys are easy to guess': 'Combinaison de touches trop simple',
'Short keyboard patterns are easy to guess': 'Combinaison de touches trop simple',
"Repeats like \"aaa\" are easy to guess'": 'Les répétitions comme "aaa" sont simples à deviner',
'Repeats like "abcabcabc" are only slightly harder to guess than "abc"': 'Les répétitions comme "abcabcabc" sont simples à deviner',
'Sequences like abc or 6543 are easy to guess': 'Les séquences comme "abc" ou "6543" sont simples à deviner',
'Recent years are easy to guess': 'Les années sont simples à deviner',
'Dates are often easy to guess': 'Les dates sont souvent simples à deviner'
}
let checkPassword = function(password, confirmation, indicator, submit) {
let result = zxcvbn(password.val());
let score = result.score;
let cols = indicator.children('.col-sm');
let info = indicator.children('.password-strenth-info');
const checkPassword = function (password, confirmation, indicator, submit) {
const result = zxcvbn(password.val())
const score = result.score
const cols = indicator.children('.col-sm')
const info = indicator.children('.password-strenth-info')
info.text('');
cols.attr('class', 'col-sm');
info.text('')
cols.attr('class', 'col-sm')
for (var u = 0; u <= 5; u++) {
let col = cols.eq(u);
if (u <= score) {
col.addClass('bg-' + scoreColors[score]);
} else {
col.addClass('bg-light');
}
for (let u = 0; u <= 5; u++) {
const col = cols.eq(u)
if (u <= score) {
col.addClass('bg-' + scoreColors[score])
} else {
col.addClass('bg-light')
}
}
console.log(result)
console.log(result)
info.text(scoreInfos[result.feedback.warning]);
info.attr('class', 'col-12 password-strenth-info text-' + scoreColors[score]);
info.text(scoreInfos[result.feedback.warning])
info.attr('class', 'col-12 password-strenth-info text-' + scoreColors[score])
if (score < 4 || confirmation.val() !== password.val()) {
submit.attr('disabled', 'disabled');
} else {
submit.removeAttr('disabled');
}
if (score < 4 || confirmation.val() !== password.val()) {
submit.attr('disabled', 'disabled')
} else {
submit.removeAttr('disabled')
}
}
module.exports = function() {
let passwordNew = $('#form-password-new');
let passwordConfirmation = $('#form-password-confirmation');
let passwordSubmit = $('#form-password-submit');
let passwordStrength = $('#form-password-strength');
module.exports = function () {
const passwordNew = $('#form-password-new')
const passwordConfirmation = $('#form-password-confirmation')
const passwordSubmit = $('#form-password-submit')
const passwordStrength = $('#form-password-strength')
if (passwordStrength.length) {
passwordNew.keyup(function() {
checkPassword(passwordNew, passwordConfirmation, passwordStrength, passwordSubmit);
});
if (passwordStrength.length) {
passwordNew.keyup(function () {
checkPassword(passwordNew, passwordConfirmation, passwordStrength, passwordSubmit)
})
passwordNew.change(function() {
checkPassword(passwordNew, passwordConfirmation, passwordStrength, passwordSubmit);
});
passwordNew.change(function () {
checkPassword(passwordNew, passwordConfirmation, passwordStrength, passwordSubmit)
})
passwordConfirmation.keyup(function() {
checkPassword(passwordNew, passwordConfirmation, passwordStrength, passwordSubmit);
});
passwordConfirmation.keyup(function () {
checkPassword(passwordNew, passwordConfirmation, passwordStrength, passwordSubmit)
})
passwordConfirmation.change(function() {
checkPassword(passwordNew, passwordConfirmation, passwordStrength, passwordSubmit);
});
}
};
passwordConfirmation.change(function () {
checkPassword(passwordNew, passwordConfirmation, passwordStrength, passwordSubmit)
})
}
}

60
assets/js/admin/modules/push-state.js

@ -1,44 +1,44 @@
const $ = require('jquery');
const $ = require('jquery')
module.exports = function() {
$('*[data-pushstate]').click((e) => {
var url = $(e.target).attr('data-pushstate');
module.exports = function () {
$('*[data-pushstate]').click((e) => {
const url = $(e.target).attr('data-pushstate')
history.pushState({url: url}, null, url);
history.replaceState({url: url}, null, url);
});
history.pushState({ url: url }, null, url)
history.replaceState({ url: url }, null, url)
})
let forms = $('form[data-formpushstate]');
const forms = $('form[data-formpushstate]')
let checkAndUsePushState = () => {
let state = [window.location.pathname, window.location.search].join('');
const checkAndUsePushState = () => {
const state = [window.location.pathname, window.location.search].join('')
$('*[data-pushstate]').each((i, v) => {
let method = 'compare';
$('*[data-pushstate]').each((i, v) => {
let method = 'compare'
if ($(v).is('[data-pushstate-method]')) {
method = $(v).attr('data-pushstate-method')
}
if ($(v).is('[data-pushstate-method]')) {
method = $(v).attr('data-pushstate-method')
}
var isThisOne = false;
let isThisOne = false
if (method === 'compare' && $(v).attr('data-pushstate') === state) {
isThisOne = true;
}
if (method === 'compare' && $(v).attr('data-pushstate') === state) {
isThisOne = true
}
if (method === 'indexOf' && state.indexOf($(v).attr('data-pushstate')) !== -1) {
isThisOne = true;
}
if (method === 'indexOf' && state.indexOf($(v).attr('data-pushstate')) !== -1) {
isThisOne = true
}
if (isThisOne) {
$(v).click();
if (isThisOne) {
$(v).click()
forms.attr('action', state);
}
});
}
forms.attr('action', state)
}
})
}
checkAndUsePushState();
checkAndUsePushState()
$(window).on('statechange', checkAndUsePushState, false);
$(window).on('statechange', checkAndUsePushState, false)
}

46
assets/js/admin/modules/rest-choices.js