diff --git a/.upgradenotes/MDL-84071-2025010603085830.yml b/.upgradenotes/MDL-84071-2025010603085830.yml
new file mode 100644
index 00000000000..c22cc19b983
--- /dev/null
+++ b/.upgradenotes/MDL-84071-2025010603085830.yml
@@ -0,0 +1,9 @@
+issueNumber: MDL-84071
+notes:
+ gradereport_singleview:
+ - message: >
+ The `grade/report/singleview/js/singleview.js` file has been removed. And the
+ `grade/report/singleview/amd/src/singleview.js` file has been added. The new file
+ is converted from YUI to native JS.
+
+ type: improved
diff --git a/grade/report/singleview/amd/build/singleview.min.js b/grade/report/singleview/amd/build/singleview.min.js
new file mode 100644
index 00000000000..92d0edca144
--- /dev/null
+++ b/grade/report/singleview/amd/build/singleview.min.js
@@ -0,0 +1,11 @@
+define("gradereport_singleview/singleview",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=function(){if(initialized)return;initialized=!0,document.addEventListener("keydown",keydownHandler,!0),document.querySelectorAll(selectors_override).forEach((input=>{input.addEventListener("change",(()=>{!function(input){const checked=input.checked,[,itemid,userid]=input.getAttribute("name").split("_"),interest="_".concat(itemid,"_").concat(userid);document.querySelectorAll(selectors_input(interest)).forEach((text=>{text.disabled=!checked})),document.querySelectorAll(selectors_select(interest)).forEach((select=>{select.disabled=!checked}))}(input)}))}))};
+/**
+ * Allow navigation through table cells using Ctrl + arrow keys and handle override toggles.
+ *
+ * @module gradereport_singleview/singleview
+ * @copyright The Open University
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+const selectors_cell="td.cell, th.cell",selectors_col="td, th",selectors_keyboardHandled="table input, table select, table a",selectors_navigableCell='input:not([type="hidden"]):not([disabled]), select, a',selectors_override="input[name^=override_]",selectors_row="tr",selectors_input=interest=>"input[name$='".concat(interest,"'][data-uielement='text']"),selectors_select=interest=>"select[name$='".concat(interest,"']");let initialized=!1;function keydownHandler(event){if(!event.ctrlKey)return;if(!["ArrowLeft","ArrowUp","ArrowRight","ArrowDown"].includes(event.key))return;const activeElement=document.activeElement;if(!activeElement.matches(selectors_keyboardHandled))return;let next=null;switch(event.key){case"ArrowLeft":next=getPrevCell(activeElement.closest(selectors_col));break;case"ArrowUp":next=getAboveCell(activeElement.closest(selectors_col));break;case"ArrowRight":next=getNextCell(activeElement.closest(selectors_col));break;case"ArrowDown":next=getBelowCell(activeElement.closest(selectors_col))}var _next$querySelector;(event.preventDefault(),event.stopImmediatePropagation(),next)&&(null===(_next$querySelector=next.querySelector(selectors_navigableCell))||void 0===_next$querySelector||_next$querySelector.focus())}function getNextCell(cell){var _checkElement$nextEle;const checkElement=cell||document.activeElement,next=null!==(_checkElement$nextEle=checkElement.nextElementSibling)&&void 0!==_checkElement$nextEle&&_checkElement$nextEle.matches(selectors_cell)?checkElement.nextElementSibling:null;return next?next.querySelector(selectors_navigableCell)?next:getNextCell(next):null}function getPrevCell(cell){var _checkElement$previou;const checkElement=cell||document.activeElement,prev=null!==(_checkElement$previou=checkElement.previousElementSibling)&&void 0!==_checkElement$previou&&_checkElement$previou.matches(selectors_cell)?checkElement.previousElementSibling:null;return prev?prev.querySelector(selectors_navigableCell)?prev:getPrevCell(prev):null}function getAboveCell(cell){const checkElement=cell||document.activeElement,tr=checkElement.closest(selectors_row).previousElementSibling,columnIndex=getColumnIndex(checkElement);if(!tr)return null;const next=tr.querySelectorAll(selectors_col)[columnIndex];return null!=next&&next.querySelector(selectors_navigableCell)?next:getAboveCell(next)}function getBelowCell(cell){const checkElement=cell||document.activeElement,tr=checkElement.closest("tr").nextElementSibling,columnIndex=getColumnIndex(checkElement);if(!tr)return null;const next=tr.querySelectorAll("td, th")[columnIndex];return null!=next&&next.querySelector(selectors_navigableCell)?next:getBelowCell(next)}function getColumnIndex(cell){const rowNode=cell.closest(selectors_row);if(!rowNode||!cell)return-1;return Array.from(rowNode.querySelectorAll(selectors_col)).indexOf(cell)}}));
+
+//# sourceMappingURL=singleview.min.js.map
\ No newline at end of file
diff --git a/grade/report/singleview/amd/build/singleview.min.js.map b/grade/report/singleview/amd/build/singleview.min.js.map
new file mode 100644
index 00000000000..261ef618b31
--- /dev/null
+++ b/grade/report/singleview/amd/build/singleview.min.js.map
@@ -0,0 +1 @@
+{"version":3,"file":"singleview.min.js","sources":["../src/singleview.js"],"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 .\n\n/**\n * Allow navigation through table cells using Ctrl + arrow keys and handle override toggles.\n *\n * @module gradereport_singleview/singleview\n * @copyright The Open University\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nconst selectors = {\n cell: 'td.cell, th.cell',\n col: 'td, th',\n keyboardHandled: 'table input, table select, table a',\n navigableCell: 'input:not([type=\"hidden\"]):not([disabled]), select, a',\n override: 'input[name^=override_]',\n row: 'tr',\n // Dyanmic selectors.\n input: (interest) => `input[name$='${interest}'][data-uielement='text']`,\n select: (interest) => `select[name$='${interest}']`,\n};\n\nlet initialized = false;\n\n/**\n * Initializes the module, setting up event listeners for table cell navigation and override toggles.\n */\nexport function init() {\n if (initialized) {\n return;\n }\n initialized = true;\n\n // Add ctrl+arrow controls for navigation.\n // Use capturing phase to intercept events before they reach anchor elements.\n document.addEventListener('keydown', keydownHandler, true);\n\n // Handle override toggles.\n document.querySelectorAll(selectors.override).forEach(input => {\n input.addEventListener('change', () => {\n updateOverrideToggle(input);\n });\n });\n}\n\n/**\n * Handles control+arrow table navigation.\n *\n * @private\n * @param {KeyboardEvent} event The keydown event.\n */\nfunction keydownHandler(event) {\n if (!event.ctrlKey) {\n return;\n }\n\n // Check if it's an arrow key.\n if (!['ArrowLeft', 'ArrowUp', 'ArrowRight', 'ArrowDown'].includes(event.key)) {\n return;\n }\n\n const activeElement = document.activeElement;\n if (!activeElement.matches(selectors.keyboardHandled)) {\n return;\n }\n\n let next = null;\n switch (event.key) {\n case 'ArrowLeft':\n next = getPrevCell(activeElement.closest(selectors.col));\n break;\n case 'ArrowUp':\n next = getAboveCell(activeElement.closest(selectors.col));\n break;\n case 'ArrowRight':\n next = getNextCell(activeElement.closest(selectors.col));\n break;\n case 'ArrowDown':\n next = getBelowCell(activeElement.closest(selectors.col));\n break;\n }\n\n // Immediately prevent default behavior and stop propagation.\n event.preventDefault();\n event.stopImmediatePropagation();\n\n if (next) {\n next.querySelector(selectors.navigableCell)?.focus();\n }\n}\n\n/**\n * Handles changes to override toggles.\n *\n * @private\n * @param {HTMLInputElement} input The override toggle input element.\n */\nfunction updateOverrideToggle(input) {\n const checked = input.checked;\n const [, itemid, userid] = input.getAttribute('name').split('_');\n const interest = `_${itemid}_${userid}`;\n\n // Handle text inputs.\n document.querySelectorAll(selectors.input(interest)).forEach(\n text => {\n text.disabled = !checked;\n }\n );\n\n // Handle select elements.\n document.querySelectorAll(selectors.select(interest)).forEach(\n select => {\n select.disabled = !checked;\n }\n );\n}\n\n/**\n * Helper function to get the next cell in the table.\n *\n * @private\n * @param {HTMLElement} cell The cell of the table.\n * @returns {HTMLElement|null} The next navigable cell or null if none found.\n */\nfunction getNextCell(cell) {\n const checkElement = cell || document.activeElement;\n const next = checkElement.nextElementSibling?.matches(selectors.cell) ? checkElement.nextElementSibling : null;\n if (!next) {\n return null;\n }\n // Continue until we find a navigable cell.\n if (!next.querySelector(selectors.navigableCell)) {\n return getNextCell(next);\n }\n\n return next;\n}\n\n/**\n * Helper function to get the previous cell in the table.\n *\n * @private\n * @param {HTMLElement} cell The cell of the table.\n */\nfunction getPrevCell(cell) {\n const checkElement = cell || document.activeElement;\n const prev = checkElement.previousElementSibling?.matches(selectors.cell) ? checkElement.previousElementSibling : null;\n if (!prev) {\n return null;\n }\n // Continue until we find a navigable cell.\n if (!prev.querySelector(selectors.navigableCell)) {\n return getPrevCell(prev);\n }\n\n return prev;\n}\n\n/**\n * Helper function to get the cell above the current cell in the table.\n *\n * @private\n * @param {HTMLElement} cell The current table cell element.\n * @returns {HTMLElement|null} The cell above or null if none found.\n */\nfunction getAboveCell(cell) {\n const checkElement = cell || document.activeElement;\n const tr = checkElement.closest(selectors.row).previousElementSibling;\n const columnIndex = getColumnIndex(checkElement);\n if (!tr) {\n return null;\n }\n const next = tr.querySelectorAll(selectors.col)[columnIndex];\n // Continue until we find a navigable cell.\n if (!next?.querySelector(selectors.navigableCell)) {\n return getAboveCell(next);\n }\n\n return next;\n}\n\n/**\n * Helper function to get the cell below the current cell in the table.\n *\n * @private\n * @param {HTMLElement} cell The current table cell element.\n * @returns {HTMLElement|null} The cell below or null if none found.\n */\nfunction getBelowCell(cell) {\n const checkElement = cell || document.activeElement;\n const tr = checkElement.closest('tr').nextElementSibling;\n const columnIndex = getColumnIndex(checkElement);\n if (!tr) {\n return null;\n }\n const next = tr.querySelectorAll('td, th')[columnIndex];\n // Continue until we find a navigable cell.\n if (!next?.querySelector(selectors.navigableCell)) {\n return getBelowCell(next);\n }\n\n return next;\n}\n\n/**\n * Helper function to get the column index of a cell.\n *\n * @param {HTMLElement} cell The cell of the table.\n * @returns {number} The index of the cell within its row.\n */\nfunction getColumnIndex(cell) {\n const rowNode = cell.closest(selectors.row);\n if (!rowNode || !cell) {\n return -1;\n }\n const cells = Array.from(rowNode.querySelectorAll(selectors.col));\n\n return cells.indexOf(cell);\n}\n"],"names":["initialized","document","addEventListener","keydownHandler","querySelectorAll","selectors","forEach","input","checked","itemid","userid","getAttribute","split","interest","text","disabled","select","updateOverrideToggle","event","ctrlKey","includes","key","activeElement","matches","next","getPrevCell","closest","getAboveCell","getNextCell","getBelowCell","preventDefault","stopImmediatePropagation","querySelector","focus","cell","checkElement","nextElementSibling","prev","previousElementSibling","tr","columnIndex","getColumnIndex","rowNode","Array","from","indexOf"],"mappings":"+JAyCQA,mBAGJA,aAAc,EAIdC,SAASC,iBAAiB,UAAWC,gBAAgB,GAGrDF,SAASG,iBAAiBC,oBAAoBC,SAAQC,QAClDA,MAAML,iBAAiB,UAAU,eA0DXK,aACpBC,QAAUD,MAAMC,UACbC,OAAQC,QAAUH,MAAMI,aAAa,QAAQC,MAAM,KACtDC,oBAAeJ,mBAAUC,QAG/BT,SAASG,iBAAiBC,gBAAgBQ,WAAWP,SACjDQ,OACIA,KAAKC,UAAYP,WAKzBP,SAASG,iBAAiBC,iBAAiBQ,WAAWP,SAClDU,SACIA,OAAOD,UAAYP,WAxEnBS,CAAqBV;;;;;;;;MA9B3BF,eACI,mBADJA,cAEG,SAFHA,0BAGe,qCAHfA,wBAIa,wDAJbA,mBAKQ,yBALRA,cAMG,KANHA,gBAQMQ,iCAA6BA,sCARnCR,iBASOQ,kCAA8BA,mBAGvCb,aAAc,WA6BTG,eAAee,WACfA,MAAMC,mBAKN,CAAC,YAAa,UAAW,aAAc,aAAaC,SAASF,MAAMG,kBAIlEC,cAAgBrB,SAASqB,kBAC1BA,cAAcC,QAAQlB,sCAIvBmB,KAAO,YACHN,MAAMG,SACL,YACDG,KAAOC,YAAYH,cAAcI,QAAQrB,0BAExC,UACDmB,KAAOG,aAAaL,cAAcI,QAAQrB,0BAEzC,aACDmB,KAAOI,YAAYN,cAAcI,QAAQrB,0BAExC,YACDmB,KAAOK,aAAaP,cAAcI,QAAQrB,yCAKlDa,MAAMY,iBACNZ,MAAMa,2BAEFP,oCACAA,KAAKQ,cAAc3B,6EAA0B4B,kBAqC5CL,YAAYM,sCACXC,aAAeD,MAAQjC,SAASqB,cAChCE,mCAAOW,aAAaC,2EAAoBb,QAAQlB,gBAAkB8B,aAAaC,mBAAqB,YACrGZ,KAIAA,KAAKQ,cAAc3B,yBAIjBmB,KAHII,YAAYJ,MAJZ,cAgBNC,YAAYS,sCACXC,aAAeD,MAAQjC,SAASqB,cAChCe,mCAAOF,aAAaG,+EAAwBf,QAAQlB,gBAAkB8B,aAAaG,uBAAyB,YAC7GD,KAIAA,KAAKL,cAAc3B,yBAIjBgC,KAHIZ,YAAYY,MAJZ,cAiBNV,aAAaO,YACZC,aAAeD,MAAQjC,SAASqB,cAChCiB,GAAKJ,aAAaT,QAAQrB,eAAeiC,uBACzCE,YAAcC,eAAeN,kBAC9BI,UACM,WAELf,KAAOe,GAAGnC,iBAAiBC,eAAemC,oBAE3ChB,MAAAA,MAAAA,KAAMQ,cAAc3B,yBAIlBmB,KAHIG,aAAaH,eAanBK,aAAaK,YACZC,aAAeD,MAAQjC,SAASqB,cAChCiB,GAAKJ,aAAaT,QAAQ,MAAMU,mBAChCI,YAAcC,eAAeN,kBAC9BI,UACM,WAELf,KAAOe,GAAGnC,iBAAiB,UAAUoC,oBAEtChB,MAAAA,MAAAA,KAAMQ,cAAc3B,yBAIlBmB,KAHIK,aAAaL,eAYnBiB,eAAeP,YACdQ,QAAUR,KAAKR,QAAQrB,mBACxBqC,UAAYR,YACL,SAEES,MAAMC,KAAKF,QAAQtC,iBAAiBC,gBAErCwC,QAAQX"}
\ No newline at end of file
diff --git a/grade/report/singleview/amd/src/singleview.js b/grade/report/singleview/amd/src/singleview.js
new file mode 100644
index 00000000000..8004cf45e69
--- /dev/null
+++ b/grade/report/singleview/amd/src/singleview.js
@@ -0,0 +1,232 @@
+// 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 .
+
+/**
+ * Allow navigation through table cells using Ctrl + arrow keys and handle override toggles.
+ *
+ * @module gradereport_singleview/singleview
+ * @copyright The Open University
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+const selectors = {
+ cell: 'td.cell, th.cell',
+ col: 'td, th',
+ keyboardHandled: 'table input, table select, table a',
+ navigableCell: 'input:not([type="hidden"]):not([disabled]), select, a',
+ override: 'input[name^=override_]',
+ row: 'tr',
+ // Dyanmic selectors.
+ input: (interest) => `input[name$='${interest}'][data-uielement='text']`,
+ select: (interest) => `select[name$='${interest}']`,
+};
+
+let initialized = false;
+
+/**
+ * Initializes the module, setting up event listeners for table cell navigation and override toggles.
+ */
+export function init() {
+ if (initialized) {
+ return;
+ }
+ initialized = true;
+
+ // Add ctrl+arrow controls for navigation.
+ // Use capturing phase to intercept events before they reach anchor elements.
+ document.addEventListener('keydown', keydownHandler, true);
+
+ // Handle override toggles.
+ document.querySelectorAll(selectors.override).forEach(input => {
+ input.addEventListener('change', () => {
+ updateOverrideToggle(input);
+ });
+ });
+}
+
+/**
+ * Handles control+arrow table navigation.
+ *
+ * @private
+ * @param {KeyboardEvent} event The keydown event.
+ */
+function keydownHandler(event) {
+ if (!event.ctrlKey) {
+ return;
+ }
+
+ // Check if it's an arrow key.
+ if (!['ArrowLeft', 'ArrowUp', 'ArrowRight', 'ArrowDown'].includes(event.key)) {
+ return;
+ }
+
+ const activeElement = document.activeElement;
+ if (!activeElement.matches(selectors.keyboardHandled)) {
+ return;
+ }
+
+ let next = null;
+ switch (event.key) {
+ case 'ArrowLeft':
+ next = getPrevCell(activeElement.closest(selectors.col));
+ break;
+ case 'ArrowUp':
+ next = getAboveCell(activeElement.closest(selectors.col));
+ break;
+ case 'ArrowRight':
+ next = getNextCell(activeElement.closest(selectors.col));
+ break;
+ case 'ArrowDown':
+ next = getBelowCell(activeElement.closest(selectors.col));
+ break;
+ }
+
+ // Immediately prevent default behavior and stop propagation.
+ event.preventDefault();
+ event.stopImmediatePropagation();
+
+ if (next) {
+ next.querySelector(selectors.navigableCell)?.focus();
+ }
+}
+
+/**
+ * Handles changes to override toggles.
+ *
+ * @private
+ * @param {HTMLInputElement} input The override toggle input element.
+ */
+function updateOverrideToggle(input) {
+ const checked = input.checked;
+ const [, itemid, userid] = input.getAttribute('name').split('_');
+ const interest = `_${itemid}_${userid}`;
+
+ // Handle text inputs.
+ document.querySelectorAll(selectors.input(interest)).forEach(
+ text => {
+ text.disabled = !checked;
+ }
+ );
+
+ // Handle select elements.
+ document.querySelectorAll(selectors.select(interest)).forEach(
+ select => {
+ select.disabled = !checked;
+ }
+ );
+}
+
+/**
+ * Helper function to get the next cell in the table.
+ *
+ * @private
+ * @param {HTMLElement} cell The cell of the table.
+ * @returns {HTMLElement|null} The next navigable cell or null if none found.
+ */
+function getNextCell(cell) {
+ const checkElement = cell || document.activeElement;
+ const next = checkElement.nextElementSibling?.matches(selectors.cell) ? checkElement.nextElementSibling : null;
+ if (!next) {
+ return null;
+ }
+ // Continue until we find a navigable cell.
+ if (!next.querySelector(selectors.navigableCell)) {
+ return getNextCell(next);
+ }
+
+ return next;
+}
+
+/**
+ * Helper function to get the previous cell in the table.
+ *
+ * @private
+ * @param {HTMLElement} cell The cell of the table.
+ */
+function getPrevCell(cell) {
+ const checkElement = cell || document.activeElement;
+ const prev = checkElement.previousElementSibling?.matches(selectors.cell) ? checkElement.previousElementSibling : null;
+ if (!prev) {
+ return null;
+ }
+ // Continue until we find a navigable cell.
+ if (!prev.querySelector(selectors.navigableCell)) {
+ return getPrevCell(prev);
+ }
+
+ return prev;
+}
+
+/**
+ * Helper function to get the cell above the current cell in the table.
+ *
+ * @private
+ * @param {HTMLElement} cell The current table cell element.
+ * @returns {HTMLElement|null} The cell above or null if none found.
+ */
+function getAboveCell(cell) {
+ const checkElement = cell || document.activeElement;
+ const tr = checkElement.closest(selectors.row).previousElementSibling;
+ const columnIndex = getColumnIndex(checkElement);
+ if (!tr) {
+ return null;
+ }
+ const next = tr.querySelectorAll(selectors.col)[columnIndex];
+ // Continue until we find a navigable cell.
+ if (!next?.querySelector(selectors.navigableCell)) {
+ return getAboveCell(next);
+ }
+
+ return next;
+}
+
+/**
+ * Helper function to get the cell below the current cell in the table.
+ *
+ * @private
+ * @param {HTMLElement} cell The current table cell element.
+ * @returns {HTMLElement|null} The cell below or null if none found.
+ */
+function getBelowCell(cell) {
+ const checkElement = cell || document.activeElement;
+ const tr = checkElement.closest('tr').nextElementSibling;
+ const columnIndex = getColumnIndex(checkElement);
+ if (!tr) {
+ return null;
+ }
+ const next = tr.querySelectorAll('td, th')[columnIndex];
+ // Continue until we find a navigable cell.
+ if (!next?.querySelector(selectors.navigableCell)) {
+ return getBelowCell(next);
+ }
+
+ return next;
+}
+
+/**
+ * Helper function to get the column index of a cell.
+ *
+ * @param {HTMLElement} cell The cell of the table.
+ * @returns {number} The index of the cell within its row.
+ */
+function getColumnIndex(cell) {
+ const rowNode = cell.closest(selectors.row);
+ if (!rowNode || !cell) {
+ return -1;
+ }
+ const cells = Array.from(rowNode.querySelectorAll(selectors.col));
+
+ return cells.indexOf(cell);
+}
diff --git a/grade/report/singleview/classes/local/screen/screen.php b/grade/report/singleview/classes/local/screen/screen.php
index c7895c23d47..8032c3bafda 100644
--- a/grade/report/singleview/classes/local/screen/screen.php
+++ b/grade/report/singleview/classes/local/screen/screen.php
@@ -259,15 +259,9 @@ abstract class screen {
public function js() {
global $PAGE;
- $module = [
- 'name' => 'gradereport_singleview',
- 'fullpath' => '/grade/report/singleview/js/singleview.js',
- 'requires' => ['base', 'dom', 'event', 'event-simulate', 'io-base']
- ];
-
$PAGE->requires->strings_for_js(['overridenoneconfirm', 'removeoverride', 'removeoverridesave'],
'gradereport_singleview');
- $PAGE->requires->js_init_call('M.gradereport_singleview.init', [], false, $module);
+ $PAGE->requires->js_call_amd('gradereport_singleview/singleview', 'init');
}
/**
diff --git a/grade/report/singleview/js/singleview.js b/grade/report/singleview/js/singleview.js
deleted file mode 100644
index 7878426fe03..00000000000
--- a/grade/report/singleview/js/singleview.js
+++ /dev/null
@@ -1,119 +0,0 @@
-M.gradereport_singleview = {};
-
-M.gradereport_singleview.init = function(Y) {
- if (this.initialised) {
- return;
- }
- this.initialised = true;
-
- var getColumnIndex = function(cell) {
- var rowNode = cell.ancestor('tr');
- if (!rowNode || !cell) {
- return;
- }
- var cells = rowNode.all('td, th');
- return cells.indexOf(cell);
- },
- getNextCell = function(cell) {
- var n = cell || document.activeElement,
- next = n.next('td.cell, th.cell');
- if (!next) {
- return null;
- }
- // Continue on until we find a navigable cell
- if (!next || !Y.one(next).one('input:not([type="hidden"]):not([disabled="DISABLED"]), select, a')) {
- return getNextCell(next);
- }
- return next;
- },
- getPrevCell = function(cell) {
- var n = cell || document.activeElement,
- next = n.previous('td.cell, th.cell');
- if (!next) {
- return null;
- }
- // Continue on until we find a navigable cell
- if (!Y.one(next).one('input:not([type="hidden"]):not([disabled="DISABLED"]), select, a')) {
- return getPrevCell(next);
- }
- return next;
- },
- getAboveCell = function(cell) {
- var n = cell || document.activeElement,
- tr = n.ancestor('tr').previous('tr'),
- columnIndex = getColumnIndex(n),
- next = null;
- if (tr) {
- next = tr.all('td, th').item(columnIndex);
- } else {
- return null;
- }
- // Continue on until we find a navigable cell
- if (!Y.one(next).one('input:not([type="hidden"]):not([disabled="DISABLED"]), select, a')) {
- return getAboveCell(next);
- }
- return next;
- },
- getBelowCell = function(cell) {
- var n = cell || document.activeElement,
- tr = n.ancestor('tr').next('tr'),
- columnIndex = getColumnIndex(n),
- next = null;
- if (tr) {
- next = tr.all('td, th').item(columnIndex);
- } else {
- return null;
- }
- // Continue on until we find a navigable cell
- if (!Y.one(next).one('input:not([type="hidden"]):not([disabled="DISABLED"]), select, a')) {
- return getBelowCell(next);
- }
- return next;
- };
-
- // Add ctrl+arrow controls for navigation
- Y.one(Y.config.doc.body).delegate('key', function(e) {
- e.preventDefault();
- e.stopPropagation();
- var next = null;
- switch (e.keyCode) {
- case 37:
- next = getPrevCell(this.ancestor('td, th'));
- break;
- case 38:
- next = getAboveCell(this.ancestor('td, th'));
- break;
- case 39:
- next = getNextCell(this.ancestor('td, th'));
- break;
- case 40:
- next = getBelowCell(this.ancestor('td, th'));
- break;
- }
- if (next) {
- Y.one(next).one('input:not([type="hidden"]):not([disabled="DISABLED"]), select, a').focus();
- }
- return;
- }, 'down:37,38,39,40+ctrl', 'table input, table select, table a');
-
- // Override Toggle.
- Y.all('input[name^=override_]').each(function(input) {
- input.on('change', function() {
- var checked = input.getDOMNode().checked;
- var names = input.getAttribute('name').split("_");
-
- var itemid = names[1];
- var userid = names[2];
-
- var interest = '_' + itemid + '_' + userid;
-
- Y.all('input[name$=' + interest + ']').filter('input[data-uielement=text]').each(function(text) {
- text.getDOMNode().disabled = !checked;
- });
- // deal with scales that are not text... UCSB
- Y.all('select[name$=' + interest + ']').each(function(select) {
- select.getDOMNode().disabled = !checked;
- });
- });
- });
-};