Merge branch 'MDL-68506-master' of git://github.com/andrewnicols/moodle
authorJun Pataleta <jun@moodle.com>
Fri, 1 May 2020 03:20:21 +0000 (11:20 +0800)
committerJun Pataleta <jun@moodle.com>
Fri, 1 May 2020 03:20:21 +0000 (11:20 +0800)
lib/table/amd/build/dynamic.min.js
lib/table/amd/build/dynamic.min.js.map
lib/table/amd/build/local/dynamic/events.min.js [new file with mode: 0644]
lib/table/amd/build/local/dynamic/events.min.js.map [new file with mode: 0644]
lib/table/amd/src/dynamic.js
lib/table/amd/src/local/dynamic/events.js [new file with mode: 0644]

index 4054b65..69210d8 100644 (file)
Binary files a/lib/table/amd/build/dynamic.min.js and b/lib/table/amd/build/dynamic.min.js differ
index 7334d4e..9f3aae9 100644 (file)
Binary files a/lib/table/amd/build/dynamic.min.js.map and b/lib/table/amd/build/dynamic.min.js.map differ
diff --git a/lib/table/amd/build/local/dynamic/events.min.js b/lib/table/amd/build/local/dynamic/events.min.js
new file mode 100644 (file)
index 0000000..2c0a787
Binary files /dev/null and b/lib/table/amd/build/local/dynamic/events.min.js differ
diff --git a/lib/table/amd/build/local/dynamic/events.min.js.map b/lib/table/amd/build/local/dynamic/events.min.js.map
new file mode 100644 (file)
index 0000000..400c659
Binary files /dev/null and b/lib/table/amd/build/local/dynamic/events.min.js.map differ
index 6333385..aa1d030 100644 (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
+};
diff --git a/lib/table/amd/src/local/dynamic/events.js b/lib/table/amd/src/local/dynamic/events.js
new file mode 100644 (file)
index 0000000..115ea69
--- /dev/null
@@ -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'),
+};