Merge branch 'MDL-68506-master' of git://github.com/andrewnicols/moodle

This commit is contained in:
Jun Pataleta 2020-05-01 11:20:21 +08:00
commit cfcbebaacb
6 changed files with 49 additions and 5 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,2 @@
define ("core_table/local/dynamic/events",["exports"],function(a){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.default=void 0;var b={tableContentRefreshed:function prefixEventName(a){return"core_table/dynamic:".concat(a)}("tableContentRefreshed")};a.default=b;return a.default});
//# sourceMappingURL=events.min.js.map

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../../src/local/dynamic/events.js"],"names":["tableContentRefreshed","prefixEventName","eventName"],"mappings":"uJA0Be,CACXA,qBAAqB,CAHD,QAAlBC,CAAAA,eAAkB,CAAAC,CAAS,qCAA0BA,CAA1B,EAGN,CAAgB,uBAAhB,CADZ,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Dynamic table selectors.\n *\n * @module core_table/local/dynamic/events\n * @package core_table\n * @copyright 2020 Andrew Nicols <andrew@nicols.co.uk>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nconst prefixEventName = eventName => `core_table/dynamic:${eventName}`;\n\nexport default {\n tableContentRefreshed: prefixEventName('tableContentRefreshed'),\n};\n"],"file":"events.min.js"}

View File

@ -23,6 +23,7 @@
*/
import {fetch as fetchTableData} from 'core_table/local/dynamic/repository';
import * as Selectors from 'core_table/local/dynamic/selectors';
import Events from './local/dynamic/events';
let watching = false;
@ -86,7 +87,14 @@ export const refreshTableContent = tableRoot => {
placeholder.innerHTML = data.html;
tableRoot.replaceWith(...placeholder.childNodes);
return data;
// Update the tableRoot.
return getTableFromId(tableRoot.dataset.tableUniqueid);
}).then(tableRoot => {
tableRoot.dispatchEvent(new CustomEvent(Events.tableContentRefreshed, {
bubbles: true,
}));
return tableRoot;
});
};
@ -139,7 +147,7 @@ export const updateTable = (tableRoot, {
if (refreshContent) {
return refreshTableContent(tableRoot);
} else {
return Promise.resolve();
return Promise.resolve(tableRoot);
}
};
@ -301,7 +309,7 @@ export const init = () => {
};
/**
* Fetch the table via its table region id
* Fetch the table via its table region id.
*
* @param {String} tableRegionId
* @returns {HTMLElement}
@ -317,3 +325,7 @@ export const getTableFromId = tableRegionId => {
return tableRoot;
};
export {
Events
};

View File

@ -0,0 +1,29 @@
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Dynamic table selectors.
*
* @module core_table/local/dynamic/events
* @package core_table
* @copyright 2020 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
const prefixEventName = eventName => `core_table/dynamic:${eventName}`;
export default {
tableContentRefreshed: prefixEventName('tableContentRefreshed'),
};