Proyectos de Subversion Moodle

Rev

Autoría | Ultima modificación | Ver Log |

{"version":3,"file":"view_nav.min.js","sources":["../src/view_nav.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 <http://www.gnu.org/licenses/>.\n\n/**\n * Manage the timeline view navigation for the overview block.\n *\n * @copyright  2018 Bas Brands <bas@moodle.com>\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport $ from 'jquery';\nimport * as CustomEvents from 'core/custom_interaction_events';\nimport Notification from 'core/notification';\nimport {setUserPreference} from 'core_user/repository';\nimport * as View from 'block_myoverview/view';\nimport SELECTORS from 'block_myoverview/selectors';\n\n/**\n * Update the user preference for the block.\n *\n * @param {String} filter The type of filter: display/sort/grouping.\n * @param {String} value The current preferred value.\n * @return {Promise}\n */\nconst updatePreferences = (filter, value) => {\n    let type = null;\n    if (filter === 'display') {\n        type = 'block_myoverview_user_view_preference';\n    } else if (filter === 'sort') {\n        type = 'block_myoverview_user_sort_preference';\n    } else if (filter === 'customfieldvalue') {\n        type = 'block_myoverview_user_grouping_customfieldvalue_preference';\n    } else {\n        type = 'block_myoverview_user_grouping_preference';\n    }\n\n    return setUserPreference(type, value)\n        .catch(Notification.exception);\n};\n\n/**\n * Event listener for the Display filter (cards, list).\n *\n * @param {object} root The root element for the overview block\n */\nconst registerSelector = root => {\n\n    const Selector = root.find(SELECTORS.FILTERS);\n\n    CustomEvents.define(Selector, [CustomEvents.events.activate]);\n    Selector.on(\n        CustomEvents.events.activate,\n        SELECTORS.FILTER_OPTION,\n        (e, data) => {\n            const option = $(e.target);\n\n            if (option.hasClass('active')) {\n                // If it's already active then we don't need to do anything.\n                return;\n            }\n\n            const filter = option.attr('data-filter');\n            const pref = option.attr('data-pref');\n            const customfieldvalue = option.attr('data-customfieldvalue');\n\n            root.find(SELECTORS.courseView.region).attr('data-' + filter, option.attr('data-value'));\n            updatePreferences(filter, pref);\n\n            if (customfieldvalue) {\n                root.find(SELECTORS.courseView.region).attr('data-customfieldvalue', customfieldvalue);\n                updatePreferences('customfieldvalue', customfieldvalue);\n            }\n\n            // Reset the views.\n\n            // Check if the user is currently in a searching state, if so we'll reset it.\n            const page = document.querySelector(SELECTORS.region.selectBlock);\n            const input = page.querySelector(SELECTORS.region.searchInput);\n            if (input.value !== '') {\n                const clearIcon = page.querySelector(SELECTORS.region.clearIcon);\n                input.value = '';\n                // Triggers the init so wont need to call it again.\n                View.clearSearch(clearIcon, root);\n            } else {\n                View.init(root);\n            }\n\n            data.originalEvent.preventDefault();\n        }\n    );\n\n    Selector.on(\n        CustomEvents.events.activate,\n        SELECTORS.DISPLAY_OPTION,\n        (e, data) => {\n            const option = $(e.target);\n\n            if (option.hasClass('active')) {\n                return;\n            }\n\n            const filter = option.attr('data-display-option');\n            const pref = option.attr('data-pref');\n\n            root.find(SELECTORS.courseView.region).attr('data-display', option.attr('data-value'));\n            updatePreferences(filter, pref);\n            View.reset(root);\n            data.originalEvent.preventDefault();\n        }\n    );\n};\n\n/**\n * Initialise the timeline view navigation by adding event listeners to\n * the navigation elements.\n *\n * @param {object} root The root element for the myoverview block\n */\nexport const init = root => {\n    root = $(root);\n    registerSelector(root);\n};\n"],"names":["updatePreferences","filter","value","type","catch","Notification","exception","root","Selector","find","SELECTORS","FILTERS","CustomEvents","define","events","activate","on","FILTER_OPTION","e","data","option","target","hasClass","attr","pref","customfieldvalue","courseView","region","page","document","querySelector","selectBlock","input","searchInput","clearIcon","View","clearSearch","init","originalEvent","preventDefault","DISPLAY_OPTION","reset","registerSelector"],"mappings":";;;;;;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