mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-10 03:49:24 +00:00
Format with biome instead of standard
This commit is contained in:
@ -1,42 +1,121 @@
|
||||
/*--------------------------------RESET--------------------------------*/
|
||||
/*--------------------------------RESET--------------------------------*/
|
||||
html, body, div, span, applet, object, iframe,
|
||||
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
|
||||
a, abbr, acronym, address, big, cite, code,
|
||||
del, dfn, em, img, ins, kbd, q, s, samp,
|
||||
small, strike, sub, sup, tt, var,
|
||||
b, u, i, center,
|
||||
dl, dt, dd, ol, ul, li,
|
||||
fieldset, form, label, legend,
|
||||
table, caption, tbody, tfoot, thead, tr, th, td,
|
||||
article, aside, canvas, details, embed,
|
||||
figure, figcaption, footer, header, hgroup,
|
||||
menu, nav, output, ruby, section, summary,
|
||||
time, mark, audio, video {
|
||||
html,
|
||||
body,
|
||||
div,
|
||||
span,
|
||||
applet,
|
||||
object,
|
||||
iframe,
|
||||
h1,
|
||||
h2,
|
||||
h3,
|
||||
h4,
|
||||
h5,
|
||||
h6,
|
||||
p,
|
||||
blockquote,
|
||||
pre,
|
||||
a,
|
||||
abbr,
|
||||
acronym,
|
||||
address,
|
||||
big,
|
||||
cite,
|
||||
code,
|
||||
del,
|
||||
dfn,
|
||||
em,
|
||||
img,
|
||||
ins,
|
||||
kbd,
|
||||
q,
|
||||
s,
|
||||
samp,
|
||||
small,
|
||||
strike,
|
||||
sub,
|
||||
sup,
|
||||
tt,
|
||||
var,
|
||||
b,
|
||||
u,
|
||||
i,
|
||||
center,
|
||||
dl,
|
||||
dt,
|
||||
dd,
|
||||
ol,
|
||||
ul,
|
||||
li,
|
||||
fieldset,
|
||||
form,
|
||||
label,
|
||||
legend,
|
||||
table,
|
||||
caption,
|
||||
tbody,
|
||||
tfoot,
|
||||
thead,
|
||||
tr,
|
||||
th,
|
||||
td,
|
||||
article,
|
||||
aside,
|
||||
canvas,
|
||||
details,
|
||||
embed,
|
||||
figure,
|
||||
figcaption,
|
||||
footer,
|
||||
header,
|
||||
hgroup,
|
||||
menu,
|
||||
nav,
|
||||
output,
|
||||
ruby,
|
||||
section,
|
||||
summary,
|
||||
time,
|
||||
mark,
|
||||
audio,
|
||||
video {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
font-size: 100%;
|
||||
font: inherit;
|
||||
vertical-align: baseline;
|
||||
}
|
||||
/* HTML5 display-role reset for older browsers */
|
||||
article, aside, details, figcaption, figure,
|
||||
footer, header, hgroup, menu, nav, section {
|
||||
article,
|
||||
aside,
|
||||
details,
|
||||
figcaption,
|
||||
figure,
|
||||
footer,
|
||||
header,
|
||||
hgroup,
|
||||
menu,
|
||||
nav,
|
||||
section {
|
||||
display: block;
|
||||
}
|
||||
body {
|
||||
line-height: 1;
|
||||
}
|
||||
ol, ul {
|
||||
ol,
|
||||
ul {
|
||||
/* list-style: none;*/
|
||||
}
|
||||
blockquote, q {
|
||||
blockquote,
|
||||
q {
|
||||
quotes: none;
|
||||
}
|
||||
blockquote:before, blockquote:after,
|
||||
q:before, q:after {
|
||||
content: '';
|
||||
blockquote:before,
|
||||
blockquote:after,
|
||||
q:before,
|
||||
q:after {
|
||||
content: "";
|
||||
content: none;
|
||||
}
|
||||
table {
|
||||
|
@ -1,60 +1,66 @@
|
||||
/* eslint-disable camelcase */
|
||||
$(function () {
|
||||
// const buttons = $('.choose_file_button')
|
||||
const popups = $('.choose_file_widget')
|
||||
popups.dialog({
|
||||
autoOpen: false,
|
||||
modal: true,
|
||||
width: '90%',
|
||||
create: function (event) {
|
||||
const target = $(event.target)
|
||||
target.parent().css({
|
||||
position: 'fixed',
|
||||
top: '5%',
|
||||
bottom: '5%'
|
||||
})
|
||||
target.css('height', '300px')
|
||||
console.log(target)
|
||||
},
|
||||
buttons: [
|
||||
{
|
||||
text: 'Choose',
|
||||
click: function () {
|
||||
console.log($('#file_id'))
|
||||
$('input[name=' + $(this).attr('name') + ']').attr('value', $('#file_id').attr('value'))
|
||||
$(this).dialog('close')
|
||||
},
|
||||
disabled: true
|
||||
}
|
||||
]
|
||||
})
|
||||
$('.choose_file_button').button().on('click', function () {
|
||||
const popup = popups.filter('[name=' + $(this).attr('name') + ']')
|
||||
console.log(popup)
|
||||
popup.html('<iframe src="/file/popup" width="100%" height="95%"></iframe><div id="file_id" value="null" />')
|
||||
popup.dialog({ title: $(this).text() }).dialog('open')
|
||||
})
|
||||
$('#quick_notif li').click(function () {
|
||||
$(this).hide()
|
||||
})
|
||||
})
|
||||
$(() => {
|
||||
// const buttons = $('.choose_file_button')
|
||||
const popups = $(".choose_file_widget");
|
||||
popups.dialog({
|
||||
autoOpen: false,
|
||||
modal: true,
|
||||
width: "90%",
|
||||
create: (event) => {
|
||||
const target = $(event.target);
|
||||
target.parent().css({
|
||||
position: "fixed",
|
||||
top: "5%",
|
||||
bottom: "5%",
|
||||
});
|
||||
target.css("height", "300px");
|
||||
console.log(target);
|
||||
},
|
||||
buttons: [
|
||||
{
|
||||
text: "Choose",
|
||||
click: function () {
|
||||
console.log($("#file_id"));
|
||||
$(`input[name=${$(this).attr("name")}]`).attr(
|
||||
"value",
|
||||
$("#file_id").attr("value"),
|
||||
);
|
||||
$(this).dialog("close");
|
||||
},
|
||||
disabled: true,
|
||||
},
|
||||
],
|
||||
});
|
||||
$(".choose_file_button")
|
||||
.button()
|
||||
.on("click", function () {
|
||||
const popup = popups.filter(`[name=${$(this).attr("name")}]`);
|
||||
console.log(popup);
|
||||
popup.html(
|
||||
'<iframe src="/file/popup" width="100%" height="95%"></iframe><div id="file_id" value="null" />',
|
||||
);
|
||||
popup.dialog({ title: $(this).text() }).dialog("open");
|
||||
});
|
||||
$("#quick_notif li").click(function () {
|
||||
$(this).hide();
|
||||
});
|
||||
});
|
||||
|
||||
export function createQuickNotif (msg) {
|
||||
const el = document.createElement('li')
|
||||
el.textContent = msg
|
||||
el.addEventListener('click', () => el.parentNode.removeChild(el))
|
||||
document.getElementById('quick_notif').appendChild(el)
|
||||
function createQuickNotif(msg) {
|
||||
const el = document.createElement("li");
|
||||
el.textContent = msg;
|
||||
el.addEventListener("click", () => el.parentNode.removeChild(el));
|
||||
document.getElementById("quick_notif").appendChild(el);
|
||||
}
|
||||
|
||||
export function deleteQuickNotifs () {
|
||||
const el = document.getElementById('quick_notif')
|
||||
while (el.firstChild) {
|
||||
el.removeChild(el.firstChild)
|
||||
}
|
||||
function deleteQuickNotifs() {
|
||||
const el = document.getElementById("quick_notif");
|
||||
while (el.firstChild) {
|
||||
el.removeChild(el.firstChild);
|
||||
}
|
||||
}
|
||||
|
||||
export function display_notif () {
|
||||
$('#header_notif').toggle().parent().toggleClass('white')
|
||||
function display_notif() {
|
||||
$("#header_notif").toggle().parent().toggleClass("white");
|
||||
}
|
||||
|
||||
// You can't get the csrf token from the template in a widget
|
||||
@ -63,21 +69,21 @@ export function display_notif () {
|
||||
// Sadly, getting the cookie is not possible with CSRF_COOKIE_HTTPONLY or CSRF_USE_SESSIONS is True
|
||||
// So, the true workaround is to get the token from the dom
|
||||
// https://docs.djangoproject.com/en/2.0/ref/csrf/#acquiring-the-token-if-csrf-use-sessions-is-true
|
||||
export function getCSRFToken () {
|
||||
return $('[name=csrfmiddlewaretoken]').val()
|
||||
function getCSRFToken() {
|
||||
return $("[name=csrfmiddlewaretoken]").val();
|
||||
}
|
||||
|
||||
export const initialUrlParams = new URLSearchParams(window.location.search)
|
||||
const initialUrlParams = new URLSearchParams(window.location.search);
|
||||
|
||||
/**
|
||||
* @readonly
|
||||
* @enum {number}
|
||||
*/
|
||||
const History = {
|
||||
NONE: 0,
|
||||
PUSH: 1,
|
||||
REPLACE: 2
|
||||
}
|
||||
NONE: 0,
|
||||
PUSH: 1,
|
||||
REPLACE: 2,
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} key
|
||||
@ -85,27 +91,30 @@ const History = {
|
||||
* @param {History} action
|
||||
* @param {URL | null} url
|
||||
*/
|
||||
export function update_query_string (key, value, action = History.REPLACE, url = null) {
|
||||
if (!url) {
|
||||
url = new URL(window.location.href)
|
||||
}
|
||||
if (value === undefined || value === null || value === '') {
|
||||
// If the value is null, undefined or empty => delete it
|
||||
url.searchParams.delete(key)
|
||||
} else if (Array.isArray(value)) {
|
||||
url.searchParams.delete(key)
|
||||
value.forEach((v) => url.searchParams.append(key, v))
|
||||
} else {
|
||||
url.searchParams.set(key, value)
|
||||
}
|
||||
function update_query_string(key, value, action = History.REPLACE, url = null) {
|
||||
let ret = url;
|
||||
if (!ret) {
|
||||
ret = new URL(window.location.href);
|
||||
}
|
||||
if (value === undefined || value === null || value === "") {
|
||||
// If the value is null, undefined or empty => delete it
|
||||
ret.searchParams.delete(key);
|
||||
} else if (Array.isArray(value)) {
|
||||
ret.searchParams.delete(key);
|
||||
for (const v of value) {
|
||||
ret.searchParams.append(key, v);
|
||||
}
|
||||
} else {
|
||||
ret.searchParams.set(key, value);
|
||||
}
|
||||
|
||||
if (action === History.PUSH) {
|
||||
window.history.pushState(null, '', url.toString())
|
||||
} else if (action === History.REPLACE) {
|
||||
window.history.replaceState(null, '', url.toString())
|
||||
}
|
||||
if (action === History.PUSH) {
|
||||
window.history.pushState(null, "", ret.toString());
|
||||
} else if (action === History.REPLACE) {
|
||||
window.history.replaceState(null, "", ret.toString());
|
||||
}
|
||||
|
||||
return url
|
||||
return ret;
|
||||
}
|
||||
|
||||
// TODO : If one day a test workflow is made for JS in this project
|
||||
@ -116,27 +125,29 @@ export function update_query_string (key, value, action = History.REPLACE, url =
|
||||
* @param {string} url The paginated endpoint to fetch
|
||||
* @return {Promise<Object[]>}
|
||||
*/
|
||||
export async function fetch_paginated (url) {
|
||||
const max_per_page = 199
|
||||
const paginated_url = new URL(url, document.location.origin)
|
||||
paginated_url.searchParams.set('page_size', max_per_page.toString())
|
||||
paginated_url.searchParams.set('page', '1')
|
||||
async function fetch_paginated(url) {
|
||||
const max_per_page = 199;
|
||||
const paginated_url = new URL(url, document.location.origin);
|
||||
paginated_url.searchParams.set("page_size", max_per_page.toString());
|
||||
paginated_url.searchParams.set("page", "1");
|
||||
|
||||
const first_page = (await (await fetch(paginated_url)).json())
|
||||
const results = first_page.results
|
||||
const first_page = await (await fetch(paginated_url)).json();
|
||||
const results = first_page.results;
|
||||
|
||||
const nb_pictures = first_page.count
|
||||
const nb_pages = Math.ceil(nb_pictures / max_per_page)
|
||||
const nb_pictures = first_page.count;
|
||||
const nb_pages = Math.ceil(nb_pictures / max_per_page);
|
||||
|
||||
if (nb_pages > 1) {
|
||||
const promises = []
|
||||
for (let i = 2; i <= nb_pages; i++) {
|
||||
paginated_url.searchParams.set('page', i.toString())
|
||||
promises.push(
|
||||
fetch(paginated_url).then(res => res.json().then(json => json.results))
|
||||
)
|
||||
}
|
||||
results.push(...(await Promise.all(promises)).flat())
|
||||
}
|
||||
return results
|
||||
if (nb_pages > 1) {
|
||||
const promises = [];
|
||||
for (let i = 2; i <= nb_pages; i++) {
|
||||
paginated_url.searchParams.set("page", i.toString());
|
||||
promises.push(
|
||||
fetch(paginated_url).then((res) =>
|
||||
res.json().then((json) => json.results),
|
||||
),
|
||||
);
|
||||
}
|
||||
results.push(...(await Promise.all(promises)).flat());
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
104
core/static/core/js/shorten.min.js
vendored
104
core/static/core/js/shorten.min.js
vendored
@ -19,4 +19,106 @@
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
!function(e){e.fn.shorten=function(s){"use strict";var t={showChars:100,minHideChars:10,ellipsesText:"...",moreText:"more",lessText:"less",onLess:function(){},onMore:function(){},errMsg:null,force:!1};return s&&e.extend(t,s),(!e(this).data("jquery.shorten")||!!t.force)&&(e(this).data("jquery.shorten",!0),e(document).off("click",".morelink"),e(document).on({click:function(){var s=e(this);return s.hasClass("less")?(s.removeClass("less"),s.html(t.moreText),s.parent().prev().animate({},function(){s.parent().prev().prev().show()}).hide("fast",function(){t.onLess()})):(s.addClass("less"),s.html(t.lessText),s.parent().prev().animate({},function(){s.parent().prev().prev().hide()}).show("fast",function(){t.onMore()})),!1}},".morelink"),this.each(function(){var s=e(this),n=s.html();if(s.text().length>t.showChars+t.minHideChars){var r=n.substr(0,t.showChars);if(r.indexOf("<")>=0){for(var a=!1,o="",i=0,l=[],h=null,c=0,f=0;f<=t.showChars;c++)if("<"!=n[c]||a||(a=!0,"/"==(h=n.substring(c+1,n.indexOf(">",c)))[0]?h!="/"+l[0]?t.errMsg="ERROR en HTML: the top of the stack should be the tag that closes":l.shift():"br"!=h.toLowerCase()&&l.unshift(h)),a&&">"==n[c]&&(a=!1),a)o+=n.charAt(c);else if(f++,i<=t.showChars)o+=n.charAt(c),i++;else if(l.length>0){for(j=0;j<l.length;j++)o+="</"+l[j]+">";break}r=e("<div/>").html(o+'<span class="ellip">'+t.ellipsesText+"</span>").html()}else r+=t.ellipsesText;var p='<div class="shortcontent">'+r+'</div><div class="allcontent">'+n+'</div><span><a href="javascript://nop/" class="morelink">'+t.moreText+"</a></span>";s.html(p),s.find(".allcontent").hide(),e(".shortcontent p:last",s).css("margin-bottom",0)}}))}}(jQuery);
|
||||
!(function (e) {
|
||||
e.fn.shorten = function (s) {
|
||||
"use strict";
|
||||
var t = {
|
||||
showChars: 100,
|
||||
minHideChars: 10,
|
||||
ellipsesText: "...",
|
||||
moreText: "more",
|
||||
lessText: "less",
|
||||
onLess: function () {},
|
||||
onMore: function () {},
|
||||
errMsg: null,
|
||||
force: !1,
|
||||
};
|
||||
return (
|
||||
s && e.extend(t, s),
|
||||
(!e(this).data("jquery.shorten") || !!t.force) &&
|
||||
(e(this).data("jquery.shorten", !0),
|
||||
e(document).off("click", ".morelink"),
|
||||
e(document).on(
|
||||
{
|
||||
click: function () {
|
||||
var s = e(this);
|
||||
return (
|
||||
s.hasClass("less")
|
||||
? (s.removeClass("less"),
|
||||
s.html(t.moreText),
|
||||
s
|
||||
.parent()
|
||||
.prev()
|
||||
.animate({}, function () {
|
||||
s.parent().prev().prev().show();
|
||||
})
|
||||
.hide("fast", function () {
|
||||
t.onLess();
|
||||
}))
|
||||
: (s.addClass("less"),
|
||||
s.html(t.lessText),
|
||||
s
|
||||
.parent()
|
||||
.prev()
|
||||
.animate({}, function () {
|
||||
s.parent().prev().prev().hide();
|
||||
})
|
||||
.show("fast", function () {
|
||||
t.onMore();
|
||||
})),
|
||||
!1
|
||||
);
|
||||
},
|
||||
},
|
||||
".morelink",
|
||||
),
|
||||
this.each(function () {
|
||||
var s = e(this),
|
||||
n = s.html();
|
||||
if (s.text().length > t.showChars + t.minHideChars) {
|
||||
var r = n.substr(0, t.showChars);
|
||||
if (r.indexOf("<") >= 0) {
|
||||
for (
|
||||
var a = !1, o = "", i = 0, l = [], h = null, c = 0, f = 0;
|
||||
f <= t.showChars;
|
||||
c++
|
||||
)
|
||||
if (
|
||||
("<" != n[c] ||
|
||||
a ||
|
||||
((a = !0),
|
||||
"/" == (h = n.substring(c + 1, n.indexOf(">", c)))[0]
|
||||
? h != "/" + l[0]
|
||||
? (t.errMsg =
|
||||
"ERROR en HTML: the top of the stack should be the tag that closes")
|
||||
: l.shift()
|
||||
: "br" != h.toLowerCase() && l.unshift(h)),
|
||||
a && ">" == n[c] && (a = !1),
|
||||
a)
|
||||
)
|
||||
o += n.charAt(c);
|
||||
else if ((f++, i <= t.showChars)) (o += n.charAt(c)), i++;
|
||||
else if (l.length > 0) {
|
||||
for (j = 0; j < l.length; j++) o += "</" + l[j] + ">";
|
||||
break;
|
||||
}
|
||||
r = e("<div/>")
|
||||
.html(o + '<span class="ellip">' + t.ellipsesText + "</span>")
|
||||
.html();
|
||||
} else r += t.ellipsesText;
|
||||
var p =
|
||||
'<div class="shortcontent">' +
|
||||
r +
|
||||
'</div><div class="allcontent">' +
|
||||
n +
|
||||
'</div><span><a href="javascript://nop/" class="morelink">' +
|
||||
t.moreText +
|
||||
"</a></span>";
|
||||
s.html(p),
|
||||
s.find(".allcontent").hide(),
|
||||
e(".shortcontent p:last", s).css("margin-bottom", 0);
|
||||
}
|
||||
}))
|
||||
);
|
||||
};
|
||||
})(jQuery);
|
||||
|
@ -1,4 +1,3 @@
|
||||
/* eslint-disable camelcase */
|
||||
/**
|
||||
* Builders to use Select2 in our templates.
|
||||
*
|
||||
@ -158,15 +157,15 @@
|
||||
/**
|
||||
* @param {Select2Options} options
|
||||
*/
|
||||
export function sithSelect2 (options) {
|
||||
const elem = $(options.element)
|
||||
return elem.select2({
|
||||
theme: elem[0].multiple ? 'classic' : 'default',
|
||||
minimumInputLength: 2,
|
||||
templateResult: select_item_builder(options.picture_getter),
|
||||
...options.data_source,
|
||||
...(options.overrides || {})
|
||||
})
|
||||
function sithSelect2(options) {
|
||||
const elem = $(options.element);
|
||||
return elem.select2({
|
||||
theme: elem[0].multiple ? "classic" : "default",
|
||||
minimumInputLength: 2,
|
||||
templateResult: select_item_builder(options.picture_getter),
|
||||
...options.data_source,
|
||||
...(options.overrides || {}),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -180,12 +179,12 @@ export function sithSelect2 (options) {
|
||||
* @param {Select2Object[]} source The array containing the data
|
||||
* @param {RemoteSourceOptions} options
|
||||
*/
|
||||
export function local_data_source (source, options) {
|
||||
if (options.excluded) {
|
||||
const ids = options.excluded()
|
||||
return { data: source.filter((i) => !ids.includes(i.id)) }
|
||||
}
|
||||
return { data: source }
|
||||
function local_data_source(source, options) {
|
||||
if (options.excluded) {
|
||||
const ids = options.excluded();
|
||||
return { data: source.filter((i) => !ids.includes(i.id)) };
|
||||
}
|
||||
return { data: source };
|
||||
}
|
||||
|
||||
/**
|
||||
@ -203,38 +202,38 @@ export function local_data_source (source, options) {
|
||||
* @param {string} source The url of the endpoint
|
||||
* @param {RemoteSourceOptions} options
|
||||
*/
|
||||
export function remote_data_source (source, options) {
|
||||
jQuery.ajaxSettings.traditional = true
|
||||
const params = {
|
||||
url: source,
|
||||
dataType: 'json',
|
||||
cache: true,
|
||||
delay: 250,
|
||||
data: function (params) {
|
||||
return {
|
||||
search: params.term,
|
||||
exclude: [
|
||||
...(this.val() || []).map((i) => parseInt(i)),
|
||||
...(options.excluded ? options.excluded() : [])
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
if (options.result_converter) {
|
||||
params.processResults = function (data) {
|
||||
return { results: data.results.map(options.result_converter) }
|
||||
}
|
||||
}
|
||||
if (options.overrides) {
|
||||
Object.assign(params, options.overrides)
|
||||
}
|
||||
return { ajax: params }
|
||||
function remote_data_source(source, options) {
|
||||
jQuery.ajaxSettings.traditional = true;
|
||||
const params = {
|
||||
url: source,
|
||||
dataType: "json",
|
||||
cache: true,
|
||||
delay: 250,
|
||||
data: function (params) {
|
||||
return {
|
||||
search: params.term,
|
||||
exclude: [
|
||||
...(this.val() || []).map((i) => Number.parseInt(i)),
|
||||
...(options.excluded ? options.excluded() : []),
|
||||
],
|
||||
};
|
||||
},
|
||||
};
|
||||
if (options.result_converter) {
|
||||
params.processResults = (data) => ({
|
||||
results: data.results.map(options.result_converter),
|
||||
});
|
||||
}
|
||||
if (options.overrides) {
|
||||
Object.assign(params, options.overrides);
|
||||
}
|
||||
return { ajax: params };
|
||||
}
|
||||
|
||||
export function item_formatter (user) {
|
||||
if (user.loading) {
|
||||
return user.text
|
||||
}
|
||||
function item_formatter(user) {
|
||||
if (user.loading) {
|
||||
return user.text;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -242,21 +241,21 @@ export function item_formatter (user) {
|
||||
* @param {null | function(Object):string} picture_getter
|
||||
* @return {function(string): jQuery|HTMLElement}
|
||||
*/
|
||||
function select_item_builder (picture_getter) {
|
||||
return (item) => {
|
||||
const picture =
|
||||
typeof picture_getter === 'function' ? picture_getter(item) : null
|
||||
const img_html = picture
|
||||
? `<img
|
||||
function select_item_builder(picture_getter) {
|
||||
return (item) => {
|
||||
const picture =
|
||||
typeof picture_getter === "function" ? picture_getter(item) : null;
|
||||
const img_html = picture
|
||||
? `<img
|
||||
src="${picture_getter(item)}"
|
||||
alt="${item.text}"
|
||||
onerror="this.src = '/static/core/img/unknown.jpg'"
|
||||
/>`
|
||||
: ''
|
||||
: "";
|
||||
|
||||
return $(`<div class="select-item">
|
||||
return $(`<div class="select-item">
|
||||
${img_html}
|
||||
<span class="select-item-text">${item.text}</span>
|
||||
</div>`)
|
||||
}
|
||||
</div>`);
|
||||
};
|
||||
}
|
||||
|
@ -1,172 +1,167 @@
|
||||
/* eslint-disable camelcase */
|
||||
/* global cytoscape, initialUrlParams, History, update_query_string */
|
||||
|
||||
async function get_graph_data (url, godfathers_depth, godchildren_depth) {
|
||||
const data = await (
|
||||
await fetch(
|
||||
`${url}?godfathers_depth=${godfathers_depth}&godchildren_depth=${godchildren_depth}`
|
||||
)
|
||||
).json()
|
||||
return [
|
||||
...data.users.map((user) => {
|
||||
return { data: user }
|
||||
}),
|
||||
...data.relationships.map((rel) => {
|
||||
return {
|
||||
data: { source: rel.godfather, target: rel.godchild }
|
||||
}
|
||||
})
|
||||
]
|
||||
async function get_graph_data(url, godfathers_depth, godchildren_depth) {
|
||||
const data = await (
|
||||
await fetch(
|
||||
`${url}?godfathers_depth=${godfathers_depth}&godchildren_depth=${godchildren_depth}`,
|
||||
)
|
||||
).json();
|
||||
return [
|
||||
...data.users.map((user) => {
|
||||
return { data: user };
|
||||
}),
|
||||
...data.relationships.map((rel) => {
|
||||
return {
|
||||
data: { source: rel.godfather, target: rel.godchild },
|
||||
};
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
function create_graph (container, data, active_user_id) {
|
||||
const cy = cytoscape({
|
||||
boxSelectionEnabled: false,
|
||||
autounselectify: true,
|
||||
function create_graph(container, data, active_user_id) {
|
||||
const cy = cytoscape({
|
||||
boxSelectionEnabled: false,
|
||||
autounselectify: true,
|
||||
|
||||
container,
|
||||
elements: data,
|
||||
minZoom: 0.5,
|
||||
container,
|
||||
elements: data,
|
||||
minZoom: 0.5,
|
||||
|
||||
style: [
|
||||
// the stylesheet for the graph
|
||||
{
|
||||
selector: 'node',
|
||||
style: {
|
||||
label: 'data(display_name)',
|
||||
'background-image': 'data(profile_pict)',
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
'background-fit': 'cover',
|
||||
'background-repeat': 'no-repeat',
|
||||
shape: 'ellipse'
|
||||
}
|
||||
},
|
||||
style: [
|
||||
// the stylesheet for the graph
|
||||
{
|
||||
selector: "node",
|
||||
style: {
|
||||
label: "data(display_name)",
|
||||
"background-image": "data(profile_pict)",
|
||||
width: "100%",
|
||||
height: "100%",
|
||||
"background-fit": "cover",
|
||||
"background-repeat": "no-repeat",
|
||||
shape: "ellipse",
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
selector: 'edge',
|
||||
style: {
|
||||
width: 5,
|
||||
'line-color': '#ccc',
|
||||
'target-arrow-color': '#ccc',
|
||||
'target-arrow-shape': 'triangle',
|
||||
'curve-style': 'bezier'
|
||||
}
|
||||
},
|
||||
{
|
||||
selector: "edge",
|
||||
style: {
|
||||
width: 5,
|
||||
"line-color": "#ccc",
|
||||
"target-arrow-color": "#ccc",
|
||||
"target-arrow-shape": "triangle",
|
||||
"curve-style": "bezier",
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
selector: '.traversed',
|
||||
style: {
|
||||
'border-width': '5px',
|
||||
'border-style': 'solid',
|
||||
'border-color': 'red',
|
||||
'target-arrow-color': 'red',
|
||||
'line-color': 'red'
|
||||
}
|
||||
},
|
||||
{
|
||||
selector: ".traversed",
|
||||
style: {
|
||||
"border-width": "5px",
|
||||
"border-style": "solid",
|
||||
"border-color": "red",
|
||||
"target-arrow-color": "red",
|
||||
"line-color": "red",
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
selector: '.not-traversed',
|
||||
style: {
|
||||
'line-opacity': '0.5',
|
||||
'background-opacity': '0.5',
|
||||
'background-image-opacity': '0.5'
|
||||
}
|
||||
}
|
||||
],
|
||||
layout: {
|
||||
name: 'klay',
|
||||
nodeDimensionsIncludeLabels: true,
|
||||
fit: true,
|
||||
klay: {
|
||||
addUnnecessaryBendpoints: true,
|
||||
direction: 'DOWN',
|
||||
nodePlacement: 'INTERACTIVE',
|
||||
layoutHierarchy: true
|
||||
}
|
||||
}
|
||||
})
|
||||
const active_user = cy
|
||||
.getElementById(active_user_id)
|
||||
.style('shape', 'rectangle')
|
||||
/* Reset graph */
|
||||
const reset_graph = () => {
|
||||
cy.elements((element) => {
|
||||
if (element.hasClass('traversed')) {
|
||||
element.removeClass('traversed')
|
||||
}
|
||||
if (element.hasClass('not-traversed')) {
|
||||
element.removeClass('not-traversed')
|
||||
}
|
||||
})
|
||||
}
|
||||
{
|
||||
selector: ".not-traversed",
|
||||
style: {
|
||||
"line-opacity": "0.5",
|
||||
"background-opacity": "0.5",
|
||||
"background-image-opacity": "0.5",
|
||||
},
|
||||
},
|
||||
],
|
||||
layout: {
|
||||
name: "klay",
|
||||
nodeDimensionsIncludeLabels: true,
|
||||
fit: true,
|
||||
klay: {
|
||||
addUnnecessaryBendpoints: true,
|
||||
direction: "DOWN",
|
||||
nodePlacement: "INTERACTIVE",
|
||||
layoutHierarchy: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
const active_user = cy
|
||||
.getElementById(active_user_id)
|
||||
.style("shape", "rectangle");
|
||||
/* Reset graph */
|
||||
const reset_graph = () => {
|
||||
cy.elements((element) => {
|
||||
if (element.hasClass("traversed")) {
|
||||
element.removeClass("traversed");
|
||||
}
|
||||
if (element.hasClass("not-traversed")) {
|
||||
element.removeClass("not-traversed");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const on_node_tap = (el) => {
|
||||
reset_graph()
|
||||
/* Create path on graph if selected isn't the targeted user */
|
||||
if (el === active_user) {
|
||||
return
|
||||
}
|
||||
cy.elements((element) => {
|
||||
element.addClass('not-traversed')
|
||||
})
|
||||
const on_node_tap = (el) => {
|
||||
reset_graph();
|
||||
/* Create path on graph if selected isn't the targeted user */
|
||||
if (el === active_user) {
|
||||
return;
|
||||
}
|
||||
cy.elements((element) => {
|
||||
element.addClass("not-traversed");
|
||||
});
|
||||
|
||||
cy.elements()
|
||||
.aStar({
|
||||
root: el,
|
||||
goal: active_user
|
||||
})
|
||||
.path.forEach((el) => {
|
||||
el.removeClass('not-traversed')
|
||||
el.addClass('traversed')
|
||||
})
|
||||
}
|
||||
for (const traversed of cy.elements().aStar({
|
||||
root: el,
|
||||
goal: active_user,
|
||||
}).path) {
|
||||
traversed.removeClass("not-traversed");
|
||||
traversed.addClass("traversed");
|
||||
}
|
||||
};
|
||||
|
||||
cy.on('tap', 'node', (tapped) => {
|
||||
on_node_tap(tapped.target)
|
||||
})
|
||||
cy.zoomingEnabled(false)
|
||||
cy.on("tap", "node", (tapped) => {
|
||||
on_node_tap(tapped.target);
|
||||
});
|
||||
cy.zoomingEnabled(false);
|
||||
|
||||
/* Add context menu */
|
||||
if (cy.cxtmenu === undefined) {
|
||||
console.error(
|
||||
"ctxmenu isn't loaded, context menu won't be available on graphs"
|
||||
)
|
||||
return cy
|
||||
}
|
||||
cy.cxtmenu({
|
||||
selector: 'node',
|
||||
/* Add context menu */
|
||||
if (cy.cxtmenu === undefined) {
|
||||
console.error(
|
||||
"ctxmenu isn't loaded, context menu won't be available on graphs",
|
||||
);
|
||||
return cy;
|
||||
}
|
||||
cy.cxtmenu({
|
||||
selector: "node",
|
||||
|
||||
commands: [
|
||||
{
|
||||
content: '<i class="fa fa-external-link fa-2x"></i>',
|
||||
select: function (el) {
|
||||
window.open(el.data().profile_url, '_blank').focus()
|
||||
}
|
||||
},
|
||||
commands: [
|
||||
{
|
||||
content: '<i class="fa fa-external-link fa-2x"></i>',
|
||||
select: (el) => {
|
||||
window.open(el.data().profile_url, "_blank").focus();
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
content: '<span class="fa fa-mouse-pointer fa-2x"></span>',
|
||||
select: function (el) {
|
||||
on_node_tap(el)
|
||||
}
|
||||
},
|
||||
{
|
||||
content: '<span class="fa fa-mouse-pointer fa-2x"></span>',
|
||||
select: (el) => {
|
||||
on_node_tap(el);
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
content: '<i class="fa fa-eraser fa-2x"></i>',
|
||||
select: function (el) {
|
||||
reset_graph()
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
{
|
||||
content: '<i class="fa fa-eraser fa-2x"></i>',
|
||||
select: (el) => {
|
||||
reset_graph();
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
return cy
|
||||
return cy;
|
||||
}
|
||||
|
||||
/* global api_url, active_user, depth_min, depth_max */
|
||||
document.addEventListener('alpine:init', () => {
|
||||
/*
|
||||
document.addEventListener("alpine:init", () => {
|
||||
/*
|
||||
This needs some constants to be set before the document has been loaded
|
||||
|
||||
api_url: base url for fetching the tree as a string
|
||||
@ -174,104 +169,104 @@ document.addEventListener('alpine:init', () => {
|
||||
depth_min: minimum tree depth for godfathers and godchildren as an int
|
||||
depth_max: maximum tree depth for godfathers and godchildren as an int
|
||||
*/
|
||||
const default_depth = 2
|
||||
const default_depth = 2;
|
||||
|
||||
if (
|
||||
typeof api_url === 'undefined' ||
|
||||
typeof active_user === 'undefined' ||
|
||||
typeof depth_min === 'undefined' ||
|
||||
typeof depth_max === 'undefined'
|
||||
) {
|
||||
console.error(
|
||||
'Some constants are not set before using the family_graph script, please look at the documentation'
|
||||
)
|
||||
return
|
||||
}
|
||||
if (
|
||||
typeof api_url === "undefined" ||
|
||||
typeof active_user === "undefined" ||
|
||||
typeof depth_min === "undefined" ||
|
||||
typeof depth_max === "undefined"
|
||||
) {
|
||||
console.error(
|
||||
"Some constants are not set before using the family_graph script, please look at the documentation",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
function get_initial_depth (prop) {
|
||||
const value = parseInt(initialUrlParams.get(prop))
|
||||
if (isNaN(value) || value < depth_min || value > depth_max) {
|
||||
return default_depth
|
||||
}
|
||||
return value
|
||||
}
|
||||
function get_initial_depth(prop) {
|
||||
const value = Number.parseInt(initialUrlParams.get(prop));
|
||||
if (Number.isNaN(value) || value < depth_min || value > depth_max) {
|
||||
return default_depth;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
Alpine.data('graph', () => ({
|
||||
loading: false,
|
||||
godfathers_depth: get_initial_depth('godfathers_depth'),
|
||||
godchildren_depth: get_initial_depth('godchildren_depth'),
|
||||
reverse: initialUrlParams.get('reverse')?.toLowerCase?.() === 'true',
|
||||
graph: undefined,
|
||||
graph_data: {},
|
||||
Alpine.data("graph", () => ({
|
||||
loading: false,
|
||||
godfathers_depth: get_initial_depth("godfathers_depth"),
|
||||
godchildren_depth: get_initial_depth("godchildren_depth"),
|
||||
reverse: initialUrlParams.get("reverse")?.toLowerCase?.() === "true",
|
||||
graph: undefined,
|
||||
graph_data: {},
|
||||
|
||||
async init () {
|
||||
const delayed_fetch = Alpine.debounce(async () => {
|
||||
this.fetch_graph_data()
|
||||
}, 100);
|
||||
['godfathers_depth', 'godchildren_depth'].forEach((param) => {
|
||||
this.$watch(param, async (value) => {
|
||||
if (value < depth_min || value > depth_max) {
|
||||
return
|
||||
}
|
||||
update_query_string(param, value, History.REPLACE)
|
||||
delayed_fetch()
|
||||
})
|
||||
})
|
||||
this.$watch('reverse', async (value) => {
|
||||
update_query_string('reverse', value, History.REPLACE)
|
||||
this.reverse_graph()
|
||||
})
|
||||
this.$watch('graph_data', async () => {
|
||||
await this.generate_graph()
|
||||
if (this.reverse) {
|
||||
await this.reverse_graph()
|
||||
}
|
||||
})
|
||||
this.fetch_graph_data()
|
||||
},
|
||||
async init() {
|
||||
const delayed_fetch = Alpine.debounce(async () => {
|
||||
this.fetch_graph_data();
|
||||
}, 100);
|
||||
for (const param of ["godfathers_depth", "godchildren_depth"]) {
|
||||
this.$watch(param, async (value) => {
|
||||
if (value < depth_min || value > depth_max) {
|
||||
return;
|
||||
}
|
||||
update_query_string(param, value, History.REPLACE);
|
||||
delayed_fetch();
|
||||
});
|
||||
}
|
||||
this.$watch("reverse", async (value) => {
|
||||
update_query_string("reverse", value, History.REPLACE);
|
||||
this.reverse_graph();
|
||||
});
|
||||
this.$watch("graph_data", async () => {
|
||||
await this.generate_graph();
|
||||
if (this.reverse) {
|
||||
await this.reverse_graph();
|
||||
}
|
||||
});
|
||||
this.fetch_graph_data();
|
||||
},
|
||||
|
||||
async screenshot () {
|
||||
const link = document.createElement('a')
|
||||
link.href = this.graph.jpg()
|
||||
link.download = interpolate(
|
||||
gettext('family_tree.%(extension)s'),
|
||||
{ extension: 'jpg' },
|
||||
true
|
||||
)
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
document.body.removeChild(link)
|
||||
},
|
||||
async screenshot() {
|
||||
const link = document.createElement("a");
|
||||
link.href = this.graph.jpg();
|
||||
link.download = interpolate(
|
||||
gettext("family_tree.%(extension)s"),
|
||||
{ extension: "jpg" },
|
||||
true,
|
||||
);
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
},
|
||||
|
||||
async reset () {
|
||||
this.reverse = false
|
||||
this.godfathers_depth = default_depth
|
||||
this.godchildren_depth = default_depth
|
||||
},
|
||||
async reset() {
|
||||
this.reverse = false;
|
||||
this.godfathers_depth = default_depth;
|
||||
this.godchildren_depth = default_depth;
|
||||
},
|
||||
|
||||
async reverse_graph () {
|
||||
this.graph.elements((el) => {
|
||||
el.position({ x: -el.position().x, y: -el.position().y })
|
||||
})
|
||||
this.graph.center(this.graph.elements())
|
||||
},
|
||||
async reverse_graph() {
|
||||
this.graph.elements((el) => {
|
||||
el.position({ x: -el.position().x, y: -el.position().y });
|
||||
});
|
||||
this.graph.center(this.graph.elements());
|
||||
},
|
||||
|
||||
async fetch_graph_data () {
|
||||
this.graph_data = await get_graph_data(
|
||||
api_url,
|
||||
this.godfathers_depth,
|
||||
this.godchildren_depth
|
||||
)
|
||||
},
|
||||
async fetch_graph_data() {
|
||||
this.graph_data = await get_graph_data(
|
||||
api_url,
|
||||
this.godfathers_depth,
|
||||
this.godchildren_depth,
|
||||
);
|
||||
},
|
||||
|
||||
async generate_graph () {
|
||||
this.loading = true
|
||||
this.graph = create_graph(
|
||||
$(this.$refs.graph),
|
||||
this.graph_data,
|
||||
active_user
|
||||
)
|
||||
this.loading = false
|
||||
}
|
||||
}))
|
||||
})
|
||||
async generate_graph() {
|
||||
this.loading = true;
|
||||
this.graph = create_graph(
|
||||
$(this.$refs.graph),
|
||||
this.graph_data,
|
||||
active_user,
|
||||
);
|
||||
this.loading = false;
|
||||
},
|
||||
}));
|
||||
});
|
||||
|
@ -1,113 +1,111 @@
|
||||
/* eslint-disable camelcase */
|
||||
/* global DataTransfer */
|
||||
export function alpine_webcam_builder (
|
||||
default_picture,
|
||||
delete_url,
|
||||
can_delete_picture
|
||||
function alpine_webcam_builder(
|
||||
default_picture,
|
||||
delete_url,
|
||||
can_delete_picture,
|
||||
) {
|
||||
return () => ({
|
||||
can_edit_picture: false,
|
||||
return () => ({
|
||||
can_edit_picture: false,
|
||||
|
||||
loading: false,
|
||||
is_camera_enabled: false,
|
||||
is_camera_error: false,
|
||||
picture: null,
|
||||
video: null,
|
||||
picture_form: null,
|
||||
loading: false,
|
||||
is_camera_enabled: false,
|
||||
is_camera_error: false,
|
||||
picture: null,
|
||||
video: null,
|
||||
picture_form: null,
|
||||
|
||||
init () {
|
||||
this.video = this.$refs.video
|
||||
this.picture_form = this.$refs.form.getElementsByTagName('input')
|
||||
if (this.picture_form.length > 0) {
|
||||
this.picture_form = this.picture_form[0]
|
||||
this.can_edit_picture = true
|
||||
init() {
|
||||
this.video = this.$refs.video;
|
||||
this.picture_form = this.$refs.form.getElementsByTagName("input");
|
||||
if (this.picture_form.length > 0) {
|
||||
this.picture_form = this.picture_form[0];
|
||||
this.can_edit_picture = true;
|
||||
|
||||
// Link the displayed element to the form input
|
||||
this.picture_form.onchange = (event) => {
|
||||
const files = event.srcElement.files
|
||||
if (files.length > 0) {
|
||||
this.picture = (window.URL || window.webkitURL).createObjectURL(
|
||||
event.srcElement.files[0]
|
||||
)
|
||||
} else {
|
||||
this.picture = null
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
// Link the displayed element to the form input
|
||||
this.picture_form.onchange = (event) => {
|
||||
const files = event.srcElement.files;
|
||||
if (files.length > 0) {
|
||||
this.picture = (window.URL || window.webkitURL).createObjectURL(
|
||||
event.srcElement.files[0],
|
||||
);
|
||||
} else {
|
||||
this.picture = null;
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
get_picture () {
|
||||
return this.picture || default_picture
|
||||
},
|
||||
get_picture() {
|
||||
return this.picture || default_picture;
|
||||
},
|
||||
|
||||
delete_picture () {
|
||||
// Only remove currently displayed picture
|
||||
if (this.picture) {
|
||||
const list = new DataTransfer()
|
||||
this.picture_form.files = list.files
|
||||
this.picture_form.dispatchEvent(new Event('change'))
|
||||
return
|
||||
}
|
||||
if (!can_delete_picture) {
|
||||
return
|
||||
}
|
||||
// Remove user picture if correct rights are available
|
||||
window.open(delete_url, '_self')
|
||||
},
|
||||
delete_picture() {
|
||||
// Only remove currently displayed picture
|
||||
if (this.picture) {
|
||||
const list = new DataTransfer();
|
||||
this.picture_form.files = list.files;
|
||||
this.picture_form.dispatchEvent(new Event("change"));
|
||||
return;
|
||||
}
|
||||
if (!can_delete_picture) {
|
||||
return;
|
||||
}
|
||||
// Remove user picture if correct rights are available
|
||||
window.open(delete_url, "_self");
|
||||
},
|
||||
|
||||
enable_camera () {
|
||||
this.picture = null
|
||||
this.loading = true
|
||||
this.is_camera_error = false
|
||||
navigator.mediaDevices
|
||||
.getUserMedia({ video: true, audio: false })
|
||||
.then((stream) => {
|
||||
this.loading = false
|
||||
this.is_camera_enabled = true
|
||||
this.video.srcObject = stream
|
||||
this.video.play()
|
||||
})
|
||||
.catch((err) => {
|
||||
this.is_camera_error = true
|
||||
this.loading = false
|
||||
throw (err)
|
||||
})
|
||||
},
|
||||
enable_camera() {
|
||||
this.picture = null;
|
||||
this.loading = true;
|
||||
this.is_camera_error = false;
|
||||
navigator.mediaDevices
|
||||
.getUserMedia({ video: true, audio: false })
|
||||
.then((stream) => {
|
||||
this.loading = false;
|
||||
this.is_camera_enabled = true;
|
||||
this.video.srcObject = stream;
|
||||
this.video.play();
|
||||
})
|
||||
.catch((err) => {
|
||||
this.is_camera_error = true;
|
||||
this.loading = false;
|
||||
throw err;
|
||||
});
|
||||
},
|
||||
|
||||
take_picture () {
|
||||
const canvas = document.createElement('canvas')
|
||||
const context = canvas.getContext('2d')
|
||||
take_picture() {
|
||||
const canvas = document.createElement("canvas");
|
||||
const context = canvas.getContext("2d");
|
||||
|
||||
/* Create the image */
|
||||
const settings = this.video.srcObject.getTracks()[0].getSettings()
|
||||
canvas.width = settings.width
|
||||
canvas.height = settings.height
|
||||
context.drawImage(this.video, 0, 0, canvas.width, canvas.height)
|
||||
/* Create the image */
|
||||
const settings = this.video.srcObject.getTracks()[0].getSettings();
|
||||
canvas.width = settings.width;
|
||||
canvas.height = settings.height;
|
||||
context.drawImage(this.video, 0, 0, canvas.width, canvas.height);
|
||||
|
||||
/* Stop camera */
|
||||
this.video.pause()
|
||||
this.video.srcObject.getTracks().forEach((track) => {
|
||||
if (track.readyState === 'live') {
|
||||
track.stop()
|
||||
}
|
||||
})
|
||||
/* Stop camera */
|
||||
this.video.pause();
|
||||
for (const track of this.video.srcObject.getTracks()) {
|
||||
if (track.readyState === "live") {
|
||||
track.stop();
|
||||
}
|
||||
}
|
||||
|
||||
canvas.toBlob((blob) => {
|
||||
const filename = interpolate(gettext('captured.%s'), ['webp'])
|
||||
const file = new File([blob], filename, {
|
||||
type: 'image/webp'
|
||||
})
|
||||
canvas.toBlob((blob) => {
|
||||
const filename = interpolate(gettext("captured.%s"), ["webp"]);
|
||||
const file = new File([blob], filename, {
|
||||
type: "image/webp",
|
||||
});
|
||||
|
||||
const list = new DataTransfer()
|
||||
list.items.add(file)
|
||||
this.picture_form.files = list.files
|
||||
const list = new DataTransfer();
|
||||
list.items.add(file);
|
||||
this.picture_form.files = list.files;
|
||||
|
||||
// No change event is triggered, we trigger it manually #}
|
||||
this.picture_form.dispatchEvent(new Event('change'))
|
||||
}, 'image/webp')
|
||||
// No change event is triggered, we trigger it manually #}
|
||||
this.picture_form.dispatchEvent(new Event("change"));
|
||||
}, "image/webp");
|
||||
|
||||
canvas.remove()
|
||||
this.is_camera_enabled = false
|
||||
}
|
||||
})
|
||||
canvas.remove();
|
||||
this.is_camera_enabled = false;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import Alpine from 'alpinejs'
|
||||
import Alpine from "alpinejs";
|
||||
|
||||
window.Alpine = Alpine
|
||||
window.Alpine = Alpine;
|
||||
|
||||
window.addEventListener('DOMContentLoaded', (event) => {
|
||||
Alpine.start()
|
||||
})
|
||||
window.addEventListener("DOMContentLoaded", (event) => {
|
||||
Alpine.start();
|
||||
});
|
||||
|
@ -1,6 +1,6 @@
|
||||
import 'codemirror/lib/codemirror.css'
|
||||
import 'easymde/src/css/easymde.css'
|
||||
import EasyMDE from 'easymde'
|
||||
import "codemirror/lib/codemirror.css";
|
||||
import "easymde/src/css/easymde.css";
|
||||
import EasyMDE from "easymde";
|
||||
|
||||
// This scripts dependens on Alpine but it should be loaded on every page
|
||||
|
||||
@ -9,181 +9,181 @@ import EasyMDE from 'easymde'
|
||||
* @param {HTMLTextAreaElement} textarea to use
|
||||
* @param {string} link to the markdown api
|
||||
**/
|
||||
export function easymdeFactory (textarea, markdownApiURL) {
|
||||
const easymde = new EasyMDE({
|
||||
element: textarea,
|
||||
spellChecker: false,
|
||||
autoDownloadFontAwesome: false,
|
||||
previewRender: Alpine.debounce(async (plainText, preview) => {
|
||||
const res = await fetch(markdownApiURL, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ text: plainText })
|
||||
})
|
||||
preview.innerHTML = await res.text()
|
||||
return null
|
||||
}, 300),
|
||||
forceSync: true, // Avoid validation error on generic create view
|
||||
toolbar: [
|
||||
{
|
||||
name: 'heading-smaller',
|
||||
action: EasyMDE.toggleHeadingSmaller,
|
||||
className: 'fa fa-header',
|
||||
title: gettext('Heading')
|
||||
},
|
||||
{
|
||||
name: 'italic',
|
||||
action: EasyMDE.toggleItalic,
|
||||
className: 'fa fa-italic',
|
||||
title: gettext('Italic')
|
||||
},
|
||||
{
|
||||
name: 'bold',
|
||||
action: EasyMDE.toggleBold,
|
||||
className: 'fa fa-bold',
|
||||
title: gettext('Bold')
|
||||
},
|
||||
{
|
||||
name: 'strikethrough',
|
||||
action: EasyMDE.toggleStrikethrough,
|
||||
className: 'fa fa-strikethrough',
|
||||
title: gettext('Strikethrough')
|
||||
},
|
||||
{
|
||||
name: 'underline',
|
||||
action: function customFunction (editor) {
|
||||
const cm = editor.codemirror
|
||||
cm.replaceSelection('__' + cm.getSelection() + '__')
|
||||
},
|
||||
className: 'fa fa-underline',
|
||||
title: gettext('Underline')
|
||||
},
|
||||
{
|
||||
name: 'superscript',
|
||||
action: function customFunction (editor) {
|
||||
const cm = editor.codemirror
|
||||
cm.replaceSelection('^' + cm.getSelection() + '^')
|
||||
},
|
||||
className: 'fa fa-superscript',
|
||||
title: gettext('Superscript')
|
||||
},
|
||||
{
|
||||
name: 'subscript',
|
||||
action: function customFunction (editor) {
|
||||
const cm = editor.codemirror
|
||||
cm.replaceSelection('~' + cm.getSelection() + '~')
|
||||
},
|
||||
className: 'fa fa-subscript',
|
||||
title: gettext('Subscript')
|
||||
},
|
||||
{
|
||||
name: 'code',
|
||||
action: EasyMDE.toggleCodeBlock,
|
||||
className: 'fa fa-code',
|
||||
title: gettext('Code')
|
||||
},
|
||||
'|',
|
||||
{
|
||||
name: 'quote',
|
||||
action: EasyMDE.toggleBlockquote,
|
||||
className: 'fa fa-quote-left',
|
||||
title: gettext('Quote')
|
||||
},
|
||||
{
|
||||
name: 'unordered-list',
|
||||
action: EasyMDE.toggleUnorderedList,
|
||||
className: 'fa fa-list-ul',
|
||||
title: gettext('Unordered list')
|
||||
},
|
||||
{
|
||||
name: 'ordered-list',
|
||||
action: EasyMDE.toggleOrderedList,
|
||||
className: 'fa fa-list-ol',
|
||||
title: gettext('Ordered list')
|
||||
},
|
||||
'|',
|
||||
{
|
||||
name: 'link',
|
||||
action: EasyMDE.drawLink,
|
||||
className: 'fa fa-link',
|
||||
title: gettext('Insert link')
|
||||
},
|
||||
{
|
||||
name: 'image',
|
||||
action: EasyMDE.drawImage,
|
||||
className: 'fa-regular fa-image',
|
||||
title: gettext('Insert image')
|
||||
},
|
||||
{
|
||||
name: 'table',
|
||||
action: EasyMDE.drawTable,
|
||||
className: 'fa fa-table',
|
||||
title: gettext('Insert table')
|
||||
},
|
||||
'|',
|
||||
{
|
||||
name: 'clean-block',
|
||||
action: EasyMDE.cleanBlock,
|
||||
className: 'fa fa-eraser fa-clean-block',
|
||||
title: gettext('Clean block')
|
||||
},
|
||||
'|',
|
||||
{
|
||||
name: 'preview',
|
||||
action: EasyMDE.togglePreview,
|
||||
className: 'fa fa-eye no-disable',
|
||||
title: gettext('Toggle preview')
|
||||
},
|
||||
{
|
||||
name: 'side-by-side',
|
||||
action: EasyMDE.toggleSideBySide,
|
||||
className: 'fa fa-columns no-disable no-mobile',
|
||||
title: gettext('Toggle side by side')
|
||||
},
|
||||
{
|
||||
name: 'fullscreen',
|
||||
action: EasyMDE.toggleFullScreen,
|
||||
className: 'fa fa-expand no-mobile',
|
||||
title: gettext('Toggle fullscreen')
|
||||
},
|
||||
'|',
|
||||
{
|
||||
name: 'guide',
|
||||
action: '/page/Aide_sur_la_syntaxe',
|
||||
className: 'fa fa-question-circle',
|
||||
title: gettext('Markdown guide')
|
||||
}
|
||||
]
|
||||
})
|
||||
function easymdeFactory(textarea, markdownApiURL) {
|
||||
const easymde = new EasyMDE({
|
||||
element: textarea,
|
||||
spellChecker: false,
|
||||
autoDownloadFontAwesome: false,
|
||||
previewRender: Alpine.debounce(async (plainText, preview) => {
|
||||
const res = await fetch(markdownApiURL, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ text: plainText }),
|
||||
});
|
||||
preview.innerHTML = await res.text();
|
||||
return null;
|
||||
}, 300),
|
||||
forceSync: true, // Avoid validation error on generic create view
|
||||
toolbar: [
|
||||
{
|
||||
name: "heading-smaller",
|
||||
action: EasyMDE.toggleHeadingSmaller,
|
||||
className: "fa fa-header",
|
||||
title: gettext("Heading"),
|
||||
},
|
||||
{
|
||||
name: "italic",
|
||||
action: EasyMDE.toggleItalic,
|
||||
className: "fa fa-italic",
|
||||
title: gettext("Italic"),
|
||||
},
|
||||
{
|
||||
name: "bold",
|
||||
action: EasyMDE.toggleBold,
|
||||
className: "fa fa-bold",
|
||||
title: gettext("Bold"),
|
||||
},
|
||||
{
|
||||
name: "strikethrough",
|
||||
action: EasyMDE.toggleStrikethrough,
|
||||
className: "fa fa-strikethrough",
|
||||
title: gettext("Strikethrough"),
|
||||
},
|
||||
{
|
||||
name: "underline",
|
||||
action: function customFunction(editor) {
|
||||
const cm = editor.codemirror;
|
||||
cm.replaceSelection(`__${cm.getSelection()}__`);
|
||||
},
|
||||
className: "fa fa-underline",
|
||||
title: gettext("Underline"),
|
||||
},
|
||||
{
|
||||
name: "superscript",
|
||||
action: function customFunction(editor) {
|
||||
const cm = editor.codemirror;
|
||||
cm.replaceSelection(`^${cm.getSelection()}^`);
|
||||
},
|
||||
className: "fa fa-superscript",
|
||||
title: gettext("Superscript"),
|
||||
},
|
||||
{
|
||||
name: "subscript",
|
||||
action: function customFunction(editor) {
|
||||
const cm = editor.codemirror;
|
||||
cm.replaceSelection(`~${cm.getSelection()}~`);
|
||||
},
|
||||
className: "fa fa-subscript",
|
||||
title: gettext("Subscript"),
|
||||
},
|
||||
{
|
||||
name: "code",
|
||||
action: EasyMDE.toggleCodeBlock,
|
||||
className: "fa fa-code",
|
||||
title: gettext("Code"),
|
||||
},
|
||||
"|",
|
||||
{
|
||||
name: "quote",
|
||||
action: EasyMDE.toggleBlockquote,
|
||||
className: "fa fa-quote-left",
|
||||
title: gettext("Quote"),
|
||||
},
|
||||
{
|
||||
name: "unordered-list",
|
||||
action: EasyMDE.toggleUnorderedList,
|
||||
className: "fa fa-list-ul",
|
||||
title: gettext("Unordered list"),
|
||||
},
|
||||
{
|
||||
name: "ordered-list",
|
||||
action: EasyMDE.toggleOrderedList,
|
||||
className: "fa fa-list-ol",
|
||||
title: gettext("Ordered list"),
|
||||
},
|
||||
"|",
|
||||
{
|
||||
name: "link",
|
||||
action: EasyMDE.drawLink,
|
||||
className: "fa fa-link",
|
||||
title: gettext("Insert link"),
|
||||
},
|
||||
{
|
||||
name: "image",
|
||||
action: EasyMDE.drawImage,
|
||||
className: "fa-regular fa-image",
|
||||
title: gettext("Insert image"),
|
||||
},
|
||||
{
|
||||
name: "table",
|
||||
action: EasyMDE.drawTable,
|
||||
className: "fa fa-table",
|
||||
title: gettext("Insert table"),
|
||||
},
|
||||
"|",
|
||||
{
|
||||
name: "clean-block",
|
||||
action: EasyMDE.cleanBlock,
|
||||
className: "fa fa-eraser fa-clean-block",
|
||||
title: gettext("Clean block"),
|
||||
},
|
||||
"|",
|
||||
{
|
||||
name: "preview",
|
||||
action: EasyMDE.togglePreview,
|
||||
className: "fa fa-eye no-disable",
|
||||
title: gettext("Toggle preview"),
|
||||
},
|
||||
{
|
||||
name: "side-by-side",
|
||||
action: EasyMDE.toggleSideBySide,
|
||||
className: "fa fa-columns no-disable no-mobile",
|
||||
title: gettext("Toggle side by side"),
|
||||
},
|
||||
{
|
||||
name: "fullscreen",
|
||||
action: EasyMDE.toggleFullScreen,
|
||||
className: "fa fa-expand no-mobile",
|
||||
title: gettext("Toggle fullscreen"),
|
||||
},
|
||||
"|",
|
||||
{
|
||||
name: "guide",
|
||||
action: "/page/Aide_sur_la_syntaxe",
|
||||
className: "fa fa-question-circle",
|
||||
title: gettext("Markdown guide"),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const submits = textarea
|
||||
.closest('form')
|
||||
.querySelectorAll('input[type="submit"]')
|
||||
const parentDiv = textarea.parentElement
|
||||
let submitPressed = false
|
||||
const submits = textarea
|
||||
.closest("form")
|
||||
.querySelectorAll('input[type="submit"]');
|
||||
const parentDiv = textarea.parentElement;
|
||||
let submitPressed = false;
|
||||
|
||||
function checkMarkdownInput (e) {
|
||||
// an attribute is null if it does not exist, else a string
|
||||
const required = textarea.getAttribute('required') != null
|
||||
const length = textarea.value.trim().length
|
||||
function checkMarkdownInput(e) {
|
||||
// an attribute is null if it does not exist, else a string
|
||||
const required = textarea.getAttribute("required") != null;
|
||||
const length = textarea.value.trim().length;
|
||||
|
||||
if (required && length === 0) {
|
||||
parentDiv.style.boxShadow = 'red 0px 0px 1.5px 1px'
|
||||
} else {
|
||||
parentDiv.style.boxShadow = ''
|
||||
}
|
||||
}
|
||||
if (required && length === 0) {
|
||||
parentDiv.style.boxShadow = "red 0px 0px 1.5px 1px";
|
||||
} else {
|
||||
parentDiv.style.boxShadow = "";
|
||||
}
|
||||
}
|
||||
|
||||
function onSubmitClick (e) {
|
||||
if (!submitPressed) {
|
||||
easymde.codemirror.on('change', checkMarkdownInput)
|
||||
}
|
||||
submitPressed = true
|
||||
checkMarkdownInput(e)
|
||||
}
|
||||
function onSubmitClick(e) {
|
||||
if (!submitPressed) {
|
||||
easymde.codemirror.on("change", checkMarkdownInput);
|
||||
}
|
||||
submitPressed = true;
|
||||
checkMarkdownInput(e);
|
||||
}
|
||||
|
||||
submits.forEach((submit) => {
|
||||
submit.addEventListener('click', onSubmitClick)
|
||||
})
|
||||
};
|
||||
for (const submit of submits) {
|
||||
submit.addEventListener("click", onSubmitClick);
|
||||
}
|
||||
}
|
||||
|
||||
window.easymdeFactory = easymdeFactory
|
||||
window.easymdeFactory = easymdeFactory;
|
||||
|
@ -1 +1 @@
|
||||
require('@fortawesome/fontawesome-free/css/all.css')
|
||||
require("@fortawesome/fontawesome-free/css/all.css");
|
||||
|
22
core/static/webpack/jquery-index.js
vendored
22
core/static/webpack/jquery-index.js
vendored
@ -1,25 +1,25 @@
|
||||
import $ from 'jquery'
|
||||
import 'jquery.shorten/src/jquery.shorten.min.js'
|
||||
import $ from "jquery";
|
||||
import "jquery.shorten/src/jquery.shorten.min.js";
|
||||
|
||||
// We ship jquery-ui with jquery because when standalone with webpack
|
||||
// JQuery is also included in the jquery-ui package. We do gain space by doing this
|
||||
// We require jquery-ui components manually and not in a loop
|
||||
// Otherwise it increases the output files by a x2 factor !
|
||||
require('jquery-ui/ui/widgets/accordion.js')
|
||||
require('jquery-ui/ui/widgets/autocomplete.js')
|
||||
require('jquery-ui/ui/widgets/button.js')
|
||||
require('jquery-ui/ui/widgets/dialog.js')
|
||||
require('jquery-ui/ui/widgets/tabs.js')
|
||||
require("jquery-ui/ui/widgets/accordion.js");
|
||||
require("jquery-ui/ui/widgets/autocomplete.js");
|
||||
require("jquery-ui/ui/widgets/button.js");
|
||||
require("jquery-ui/ui/widgets/dialog.js");
|
||||
require("jquery-ui/ui/widgets/tabs.js");
|
||||
|
||||
require('jquery-ui/themes/base/all.css')
|
||||
require("jquery-ui/themes/base/all.css");
|
||||
|
||||
/**
|
||||
* Simple wrapper to solve shorten not being able on legacy pages
|
||||
* @param {string} selector to be passed to jQuery
|
||||
* @param {Object} options object to pass to the shorten function
|
||||
**/
|
||||
export function shorten (selector, options) {
|
||||
$(selector).shorten(options)
|
||||
function shorten(selector, options) {
|
||||
$(selector).shorten(options);
|
||||
}
|
||||
|
||||
window.shorten = shorten
|
||||
window.shorten = shorten;
|
||||
|
Reference in New Issue
Block a user