| Línea 21... |
Línea 21... |
| 21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
| 22 |
*/
|
22 |
*/
|
| Línea 23... |
Línea 23... |
| 23 |
|
23 |
|
| Línea 24... |
Línea -... |
| 24 |
"use strict";
|
- |
|
| 25 |
|
24 |
"use strict";
|
| 26 |
import $ from 'jquery';
|
25 |
|
| 27 |
import 'core/inplace_editable';
|
26 |
import 'core/inplace_editable';
|
| 28 |
import Notification from 'core/notification';
|
27 |
import Notification from 'core/notification';
|
| 29 |
import Pending from 'core/pending';
|
28 |
import Pending from 'core/pending';
|
| Línea 68... |
Línea 67... |
| 68 |
* @param {Number} sortenabled
|
67 |
* @param {Number} sortenabled
|
| 69 |
* @param {Number} sortdirection
|
68 |
* @param {Number} sortdirection
|
| 70 |
* @return {Promise}
|
69 |
* @return {Promise}
|
| 71 |
*/
|
70 |
*/
|
| 72 |
const updateSorting = (reportElement, element, sortenabled, sortdirection) => {
|
71 |
const updateSorting = (reportElement, element, sortenabled, sortdirection) => {
|
| 73 |
const reportId = reportElement.dataset.reportId;
|
- |
|
| 74 |
const listElement = element.closest('li');
|
- |
|
| 75 |
const columnId = listElement.dataset.columnSortId;
|
72 |
const columnSortContainer = element.closest(reportSelectors.regions.activeColumnSort);
|
| 76 |
const columnName = listElement.dataset.columnSortName;
|
73 |
const {columnSortId, columnSortName} = columnSortContainer.dataset;
|
| Línea 77... |
Línea 74... |
| 77 |
|
74 |
|
| 78 |
return toggleColumnSorting(reportId, columnId, sortenabled, sortdirection)
|
75 |
return toggleColumnSorting(reportElement.dataset.reportId, columnSortId, sortenabled, sortdirection)
|
| 79 |
.then(reloadSettingsSortingRegion)
|
76 |
.then(reloadSettingsSortingRegion)
|
| 80 |
.then(() => getString('columnsortupdated', 'core_reportbuilder', columnName))
|
77 |
.then(() => getString('columnsortupdated', 'core_reportbuilder', columnSortName))
|
| 81 |
.then(addToast)
|
78 |
.then(addToast)
|
| 82 |
.then(() => {
|
79 |
.then(() => {
|
| 83 |
dispatchEvent(reportEvents.tableReload, {}, reportElement);
|
80 |
dispatchEvent(reportEvents.tableReload, {}, reportElement);
|
| 84 |
return null;
|
81 |
return null;
|
| Línea 107... |
Línea 104... |
| 107 |
if (toggleSorting) {
|
104 |
if (toggleSorting) {
|
| 108 |
event.preventDefault();
|
105 |
event.preventDefault();
|
| Línea 109... |
Línea 106... |
| 109 |
|
106 |
|
| 110 |
const pendingPromise = new Pending('core_reportbuilder/sorting:toggle');
|
107 |
const pendingPromise = new Pending('core_reportbuilder/sorting:toggle');
|
| - |
|
108 |
const reportElement = toggleSorting.closest(reportSelectors.regions.report);
|
| 111 |
const reportElement = toggleSorting.closest(reportSelectors.regions.report);
|
109 |
const columnSortContainer = toggleSorting.closest(reportSelectors.regions.activeColumnSort);
|
| Línea 112... |
Línea 110... |
| 112 |
const sortdirection = parseInt(toggleSorting.closest('li').dataset.columnSortDirection);
|
110 |
const sortdirection = parseInt(columnSortContainer.dataset.columnSortDirection);
|
| 113 |
|
111 |
|
| 114 |
updateSorting(reportElement, toggleSorting, toggleSorting.checked, sortdirection)
|
112 |
updateSorting(reportElement, toggleSorting, toggleSorting.checked, sortdirection)
|
| 115 |
.then(() => {
|
113 |
.then(() => {
|
| Línea 126... |
Línea 124... |
| 126 |
if (toggleSortDirection) {
|
124 |
if (toggleSortDirection) {
|
| 127 |
event.preventDefault();
|
125 |
event.preventDefault();
|
| Línea 128... |
Línea 126... |
| 128 |
|
126 |
|
| 129 |
const pendingPromise = new Pending('core_reportbuilder/sorting:direction');
|
127 |
const pendingPromise = new Pending('core_reportbuilder/sorting:direction');
|
| 130 |
const reportElement = toggleSortDirection.closest(reportSelectors.regions.report);
|
128 |
const reportElement = toggleSortDirection.closest(reportSelectors.regions.report);
|
| 131 |
const listElement = toggleSortDirection.closest('li');
|
129 |
const columnSortContainer = toggleSortDirection.closest(reportSelectors.regions.activeColumnSort);
|
| Línea 132... |
Línea 130... |
| 132 |
const toggleSorting = listElement.querySelector(reportSelectors.actions.reportToggleColumnSort);
|
130 |
const toggleSorting = columnSortContainer.querySelector(reportSelectors.actions.reportToggleColumnSort);
|
| 133 |
|
131 |
|
| 134 |
let sortdirection = parseInt(listElement.dataset.columnSortDirection);
|
132 |
let sortdirection = parseInt(columnSortContainer.dataset.columnSortDirection);
|
| 135 |
if (sortdirection === SORTORDER.ASCENDING) {
|
133 |
if (sortdirection === SORTORDER.ASCENDING) {
|
| 136 |
sortdirection = SORTORDER.DESCENDING;
|
134 |
sortdirection = SORTORDER.DESCENDING;
|
| 137 |
} else if (sortdirection === SORTORDER.DESCENDING) {
|
135 |
} else if (sortdirection === SORTORDER.DESCENDING) {
|
| Línea 147... |
Línea 145... |
| 147 |
})
|
145 |
})
|
| 148 |
.catch(Notification.exception);
|
146 |
.catch(Notification.exception);
|
| 149 |
}
|
147 |
}
|
| 150 |
});
|
148 |
});
|
| Línea 151... |
Línea 149... |
| 151 |
|
149 |
|
| - |
|
150 |
// Initialize sortable list to handle column sorting moving.
|
| 152 |
// Initialize sortable list to handle column sorting moving (note JQuery dependency, see MDL-72293 for resolution).
|
151 |
const columnsSortingSelector = `${reportSelectors.regions.settingsSorting} ul`;
|
| 153 |
var columnsSortingSortableList = new SortableList(`${reportSelectors.regions.settingsSorting} ul`, {isHorizontal: false});
|
152 |
const columnsSortingSortableList = new SortableList(columnsSortingSelector, {isHorizontal: false});
|
| Línea -... |
Línea 153... |
| - |
|
153 |
columnsSortingSortableList.getElementName = element => Promise.resolve(element.data('columnSortName'));
|
| 154 |
columnsSortingSortableList.getElementName = element => Promise.resolve(element.data('columnSortName'));
|
154 |
|
| 155 |
|
155 |
document.addEventListener(SortableList.EVENTS.elementDrop, event => {
|
| 156 |
$(document).on(SortableList.EVENTS.DROP, `${reportSelectors.regions.report} li[data-column-sort-id]`, (event, info) => {
|
156 |
const toggleSortOrder = event.target.closest(`${columnsSortingSelector} ${reportSelectors.regions.activeColumnSort}`);
|
| - |
|
157 |
if (toggleSortOrder && event.detail.positionChanged) {
|
| 157 |
if (info.positionChanged) {
|
158 |
const pendingPromise = new Pending('core_reportbuilder/sorting:reorder');
|
| 158 |
const pendingPromise = new Pending('core_reportbuilder/sorting:reorder');
|
- |
|
| 159 |
const reportElement = event.target.closest(reportSelectors.regions.report);
|
159 |
|
| Línea 160... |
Línea 160... |
| 160 |
const columnId = info.element.data('columnSortId');
|
160 |
const reportElement = toggleSortOrder.closest(reportSelectors.regions.report);
|
| 161 |
const columnPosition = info.element.data('columnSortPosition');
|
161 |
const {columnSortId, columnSortPosition, columnSortName} = toggleSortOrder.dataset;
|
| - |
|
162 |
|
| 162 |
|
163 |
// Select target position, if moving to the end then count number of element siblings.
|
| 163 |
// Select target position, if moving to the end then count number of element siblings.
|
164 |
let targetColumnSortPosition = event.detail.targetNextElement.data('columnSortPosition')
|
| 164 |
let targetColumnSortPosition = info.targetNextElement.data('columnSortPosition') || info.element.siblings().length + 2;
|
165 |
|| event.detail.element.siblings().length + 2;
|
| Línea 165... |
Línea 166... |
| 165 |
if (targetColumnSortPosition > columnPosition) {
|
166 |
if (targetColumnSortPosition > columnSortPosition) {
|
| 166 |
targetColumnSortPosition--;
|
167 |
targetColumnSortPosition--;
|
| 167 |
}
|
168 |
}
|
| 168 |
|
169 |
|
| 169 |
// Re-order column sorting, giving drop event transition time to finish.
|
170 |
// Re-order column sorting, giving drop event transition time to finish.
|
| 170 |
const reorderPromise = reorderColumnSorting(reportElement.dataset.reportId, columnId, targetColumnSortPosition);
|
171 |
const reorderPromise = reorderColumnSorting(reportElement.dataset.reportId, columnSortId, targetColumnSortPosition);
|
| 171 |
Promise.all([reorderPromise, new Promise(resolve => setTimeout(resolve, 1000))])
|
172 |
Promise.all([reorderPromise, new Promise(resolve => setTimeout(resolve, 1000))])
|
| 172 |
.then(([data]) => reloadSettingsSortingRegion(data))
|
173 |
.then(([data]) => reloadSettingsSortingRegion(data))
|
| 173 |
.then(() => getString('columnsortupdated', 'core_reportbuilder', info.element.data('columnSortName')))
|
174 |
.then(() => getString('columnsortupdated', 'core_reportbuilder', columnSortName))
|
| 174 |
.then(addToast)
|
175 |
.then(addToast)
|