JS: Replace jquery.find() with pure js

This commit is contained in:
Yonas Habteab 2022-04-01 16:57:59 +02:00
parent 96c3b31686
commit d903b902fc

View File

@ -161,52 +161,53 @@
Dashboard.prototype.onRendered = function (e) { Dashboard.prototype.onRendered = function (e) {
let _this = e.data.self; let _this = e.data.self;
$(e.target).find('.dashboard-settings, .dashboard.content, .dashboard-item-list, .dashlet-item-list').each(function () { e.target.querySelectorAll('.dashboard-settings, .dashboard.content, .dashboard-item-list, .dashlet-item-list')
let groupName = _this.getTypeFor(this), .forEach(sortable => {
draggable, let groupName = _this.getTypeFor(sortable),
handle; draggable,
handle;
switch (groupName) { switch (groupName) {
case WIDGET_TYPES.DashboardHome: { case WIDGET_TYPES.DashboardHome: {
groupName = WIDGET_TYPES.DashboardHome; groupName = WIDGET_TYPES.DashboardHome;
draggable = '.home-list-control'; draggable = '.home-list-control';
handle = '.home-list-control > h1'; handle = '.home-list-control > h1';
break; break;
}
case WIDGET_TYPES.Dashboard: {
groupName = WIDGET_TYPES.Dashboard;
draggable = '.dashboard-list-control';
handle = '.dashboard-list-control > h1'
break;
}
case WIDGET_TYPES.Dashlet: {
groupName = WIDGET_TYPES.Dashlet;
if (this.matches('.dashboard.content')) {
draggable = '> .container';
} else {
draggable = '.dashlet-list-item';
} }
case WIDGET_TYPES.Dashboard: {
groupName = WIDGET_TYPES.Dashboard;
draggable = '.dashboard-list-control';
handle = '.dashboard-list-control > h1'
break;
}
case WIDGET_TYPES.Dashlet: {
groupName = WIDGET_TYPES.Dashlet;
if (sortable.matches('.dashboard.content')) {
draggable = '> .container';
} else {
draggable = '.dashlet-list-item';
}
handle = draggable; handle = draggable;
}
} }
}
let options = { let options = {
scroll : true, scroll : true,
invertSwap : true, invertSwap : true,
delay : 100, delay : 100,
dataIdAttr : 'id', dataIdAttr : 'id',
direction : 'vertical', direction : 'vertical',
draggable : draggable, draggable : draggable,
handle : handle, handle : handle,
group : { group : {
name : groupName, name : groupName,
put : _this['isValid'], put : _this['isValid'],
} }
}; };
Sortable.create(this, options); Sortable.create(sortable, options);
}); });
}; };
Icinga.Behaviors.Dashboard = Dashboard; Icinga.Behaviors.Dashboard = Dashboard;