Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 24... Línea 24...
24
import CoreFilter from 'core/datafilter';
24
import CoreFilter from 'core/datafilter';
25
import Notification from 'core/notification';
25
import Notification from 'core/notification';
26
import Selectors from 'core/datafilter/selectors';
26
import Selectors from 'core/datafilter/selectors';
27
import Templates from 'core/templates';
27
import Templates from 'core/templates';
28
import Fragment from 'core/fragment';
28
import Fragment from 'core/fragment';
-
 
29
import {getString} from 'core/str';
-
 
30
import {addIconToContainerRemoveOnCompletion} from 'core/loadingicon';
Línea 29... Línea 31...
29
 
31
 
30
/**
32
/**
31
 * Initialise the question bank filter on the element with the given id.
33
 * Initialise the question bank filter on the element with the given id.
32
 *
34
 *
33
 * @param {String} filterRegionId ID of the HTML element containing the filters.
35
 * @param {String} filterRegionId ID of the HTML element containing the filters.
34
 * @param {String} defaultcourseid Course ID for the default course to pass back to the view.
36
 * @param {String} defaultcourseid Course ID for the default course to pass back to the view.
35
 * @param {String} defaultcategoryid Question bank category ID for the default course to pass back to the view.
37
 * @param {String} defaultcategoryid Question bank category ID for the default course to pass back to the view.
36
 * @param {Number} perpage The number of questions to display per page.
38
 * @param {Number} perpage The number of questions to display per page.
-
 
39
 * @param {Number} bankContextId Context ID of the question bank being filtered.
37
 * @param {Number} contextId Context ID of the question bank view.
40
 * @param {Number} quizCmId Course module ID of the quiz as the viewing context.
38
 * @param {string} component Frankenstyle name of the component for the fragment API callback (e.g. core_question)
41
 * @param {string} component Frankenstyle name of the component for the fragment API callback (e.g. core_question)
39
 * @param {string} callback Name of the callback for the fragment API (e.g question_data)
42
 * @param {string} callback Name of the callback for the fragment API (e.g question_data)
40
 * @param {string} view The class name of the question bank view class used for this page.
43
 * @param {string} view The class name of the question bank view class used for this page.
41
 * @param {Number} cmid If we are in an activitiy, the course module ID.
44
 * @param {Number} cmid If we are in an activitiy, the course module ID.
42
 * @param {string} pagevars JSON-encoded parameters from passed from the view, including filters and jointype.
45
 * @param {Object} pagevars JSON-encoded parameters from passed from the view, including filters and jointype.
43
 * @param {string} extraparams JSON-encoded additional parameters specific to this view class, used for re-rendering the view.
46
 * @param {Object} extraparams JSON-encoded additional parameters specific to this view class, used for re-rendering the view.
44
 */
47
 */
45
export const init = (
48
export const init = async(
46
    filterRegionId,
49
    filterRegionId,
47
    defaultcourseid,
50
    defaultcourseid,
48
    defaultcategoryid,
51
    defaultcategoryid,
49
    perpage,
52
    perpage,
-
 
53
    bankContextId,
50
    contextId,
54
    quizCmId,
51
    component,
55
    component,
52
    callback,
56
    callback,
53
    view,
57
    view,
54
    cmid,
58
    cmid,
55
    pagevars,
59
    pagevars,
56
    extraparams
60
    extraparams,
Línea 57... Línea 61...
57
) => {
61
) => {
58
 
62
 
59
    const SELECTORS = {
63
    const SELECTORS = {
Línea 64... Línea 68...
64
        LASTCHANGED_FIELD: '#questionsubmit input[name=lastchanged]',
68
        LASTCHANGED_FIELD: '#questionsubmit input[name=lastchanged]',
65
        BULK_ACTIONS: '#bulkactionsui-container input',
69
        BULK_ACTIONS: '#bulkactionsui-container input',
66
        MENU_ACTIONS: '.menu-action',
70
        MENU_ACTIONS: '.menu-action',
67
        EDIT_SWITCH: '.editmode-switch-form input[name=setmode]',
71
        EDIT_SWITCH: '.editmode-switch-form input[name=setmode]',
68
        EDIT_SWITCH_URL: '.editmode-switch-form input[name=pageurl]',
72
        EDIT_SWITCH_URL: '.editmode-switch-form input[name=pageurl]',
-
 
73
        SHOW_ALL_LINK: '[data-filteraction="showall"]',
69
    };
74
    };
Línea 70... Línea 75...
70
 
75
 
Línea 71... Línea 76...
71
    const filterSet = document.querySelector(`#${filterRegionId}`);
76
    const filterSet = document.querySelector(`#${filterRegionId}`);
72
 
77
 
73
    const viewData = {
78
    const viewData = {
74
        extraparams,
79
        extraparams: JSON.stringify(extraparams),
75
        cmid,
80
        cmid,
76
        view,
81
        view,
77
        cat: defaultcategoryid,
82
        cat: defaultcategoryid,
Línea 88... Línea 93...
88
    const defaultSort = document.querySelector(SELECTORS.QUESTION_TABLE)?.dataset?.defaultsort;
93
    const defaultSort = document.querySelector(SELECTORS.QUESTION_TABLE)?.dataset?.defaultsort;
89
    if (defaultSort) {
94
    if (defaultSort) {
90
        sortData = JSON.parse(defaultSort);
95
        sortData = JSON.parse(defaultSort);
91
    }
96
    }
Línea -... Línea 97...
-
 
97
 
-
 
98
    const [
-
 
99
        showAllText,
-
 
100
        showPerPageText,
-
 
101
    ] = await Promise.all([
-
 
102
        getString('showall', 'core', ''),
-
 
103
        getString('showperpage', 'core', extraparams.defaultqperpage),
-
 
104
    ]);
92
 
105
 
93
    /**
106
    /**
94
     * Retrieve table data.
107
     * Retrieve table data.
95
     *
108
     *
96
     * @param {Object} filterdata data
109
     * @param {Object} filterdata data
Línea 107... Línea 120...
107
            viewData.filter = filterdata;
120
            viewData.filter = filterdata;
108
            if (Object.keys(filterdata).length !== 0) {
121
            if (Object.keys(filterdata).length !== 0) {
109
                if (!isNaN(viewData.jointype)) {
122
                if (!isNaN(viewData.jointype)) {
110
                    filterdata.jointype = viewData.jointype;
123
                    filterdata.jointype = viewData.jointype;
111
                }
124
                }
112
                updateUrlParams(filterdata);
-
 
113
            }
125
            }
114
        }
126
        }
115
        // Load questions for first page.
127
        // Load questions for first page.
116
        viewData.filter = JSON.stringify(filterdata);
128
        viewData.filter = JSON.stringify(filterdata);
117
        viewData.sortdata = JSON.stringify(sortData);
129
        viewData.sortdata = JSON.stringify(sortData);
-
 
130
        viewData.quizcmid = quizCmId;
-
 
131
 
-
 
132
        const questionscontainer = document.querySelector(SELECTORS.QUESTION_CONTAINER_ID);
-
 
133
        // Clear the contents of the element, then append the loading icon.
-
 
134
        questionscontainer.innerHTML = '';
-
 
135
        addIconToContainerRemoveOnCompletion(questionscontainer, pendingPromise);
-
 
136
 
118
        Fragment.loadFragment(component, callback, contextId, viewData)
137
        Fragment.loadFragment(component, callback, bankContextId, viewData)
119
            // Render questions for first page and pagination.
138
            // Render questions for first page and pagination.
120
            .then((questionhtml, jsfooter) => {
139
            .then((questionhtml, jsfooter) => {
121
                const questionscontainer = document.querySelector(SELECTORS.QUESTION_CONTAINER_ID);
140
                updateUrlParams(filterdata);
122
                if (questionhtml === undefined) {
141
                if (questionhtml === undefined) {
123
                    questionhtml = '';
142
                    questionhtml = '';
124
                }
143
                }
125
                if (jsfooter === undefined) {
144
                if (jsfooter === undefined) {
126
                    jsfooter = '';
145
                    jsfooter = '';
Línea 178... Línea 197...
178
            history.pushState({}, '', cleanedUrl);
197
            history.pushState({}, '', cleanedUrl);
179
        }
198
        }
180
    };
199
    };
Línea 181... Línea 200...
181
 
200
 
182
    // Add listeners for the sorting, paging and clear actions.
201
    // Add listeners for the sorting, paging and clear actions.
183
    document.addEventListener('click', e => {
202
    document.querySelector('.questionbankwindow').addEventListener('click', e => {
184
        const sortableLink = e.target.closest(SELECTORS.SORT_LINK);
203
        const sortableLink = e.target.closest(SELECTORS.SORT_LINK);
185
        const paginationLink = e.target.closest(SELECTORS.PAGINATION_LINK);
204
        const paginationLink = e.target.closest(SELECTORS.PAGINATION_LINK);
-
 
205
        const clearLink = e.target.closest(Selectors.filterset.actions.resetFilters);
186
        const clearLink = e.target.closest(Selectors.filterset.actions.resetFilters);
206
        const showallLink = e.target.closest(SELECTORS.SHOW_ALL_LINK);
187
        if (sortableLink) {
207
        if (sortableLink) {
188
            e.preventDefault();
208
            e.preventDefault();
189
            const oldSort = sortData;
209
            const oldSort = sortData;
190
            sortData = {};
210
            sortData = {};
Línea 193... Línea 213...
193
                if (sortname !== sortableLink.dataset.sortname) {
213
                if (sortname !== sortableLink.dataset.sortname) {
194
                    sortData[sortname] = oldSort[sortname];
214
                    sortData[sortname] = oldSort[sortname];
195
                }
215
                }
196
            }
216
            }
197
            viewData.qpage = 0;
217
            viewData.qpage = 0;
198
            coreFilter.updateTableFromFilter();
218
            coreFilter.updateTableFromFilter(false);
199
        }
219
        }
200
        if (paginationLink) {
220
        if (paginationLink) {
201
            e.preventDefault();
221
            e.preventDefault();
202
            const paginationURL = new URL(paginationLink.getAttribute("href"));
222
            const paginationURL = new URL(paginationLink.getAttribute("href"));
203
            const qpage = paginationURL.searchParams.get('qpage');
223
            const qpage = paginationURL.searchParams.get('qpage');
204
            if (paginationURL.search !== null) {
224
            if (paginationURL.search !== null) {
205
                viewData.qpage = qpage;
225
                viewData.qpage = qpage;
206
                coreFilter.updateTableFromFilter();
226
                coreFilter.updateTableFromFilter(false);
207
            }
227
            }
208
        }
228
        }
209
        if (clearLink) {
229
        if (clearLink) {
210
            cleanUrlParams();
230
            cleanUrlParams();
211
        }
231
        }
-
 
232
        if (showallLink) {
-
 
233
 
-
 
234
            e.preventDefault();
-
 
235
 
-
 
236
            // Toggle between showing all and going back to the original qperpage.
-
 
237
            if (Number(showallLink.dataset.status) === 0) {
-
 
238
                viewData.qperpage = extraparams.maxqperpage;
-
 
239
                showallLink.dataset.status = 1;
-
 
240
                showallLink.innerText = showPerPageText;
-
 
241
            } else {
-
 
242
                viewData.qperpage = extraparams.defaultqperpage;
-
 
243
                showallLink.dataset.status = 0;
-
 
244
                showallLink.innerText = showAllText;
-
 
245
            }
-
 
246
            viewData.qpage = 0;
-
 
247
            coreFilter.updateTableFromFilter();
-
 
248
        }
212
    });
249
    });
Línea 213... Línea 250...
213
 
250
 
214
    // Run apply filter at page load.
-
 
215
    pagevars = JSON.parse(pagevars);
251
    // Run apply filter at page load.
216
    let initialFilters;
252
    let initialFilters;
217
    let jointype = null;
253
    let jointype = null;
218
    if (pagevars.filter) {
254
    if (pagevars.filter) {
219
        // Load initial filter based on page vars.
255
        // Load initial filter based on page vars.