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 timeline block.\n *\n * @copyright  2018 Ryan Wyllie <ryan@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 * as View from 'block_timeline/view';\nimport * as Notification from 'core/notification';\nimport * as Utils from 'core/utils';\nimport * as UserRepository from 'core_user/repository';\n\nconst SELECTORS = {\n    TIMELINE_DAY_FILTER: '[data-region=\"day-filter\"]',\n    TIMELINE_DAY_FILTER_OPTION: '[data-from]',\n    TIMELINE_VIEW_SELECTOR: '[data-region=\"view-selector\"]',\n    DATA_DAYS_OFFSET: '[data-days-offset]',\n    DATA_DAYS_LIMIT: '[data-days-limit]',\n    TIMELINE_SEARCH_INPUT: '[data-action=\"search\"]',\n    TIMELINE_SEARCH_CLEAR_ICON: '[data-action=\"clearsearch\"]',\n    NO_COURSES_EMPTY_MESSAGE: '[data-region=\"no-courses-empty-message\"]',\n};\n\n/**\n * Event listener for the day selector (\"Next 7 days\", \"Next 30 days\", etc).\n *\n * @param {object} root The root element for the timeline block\n * @param {object} timelineViewRoot The root element for the timeline view\n */\nconst registerTimelineDaySelector = function(root, timelineViewRoot) {\n    const timelineDaySelectorContainer = root.find(SELECTORS.TIMELINE_DAY_FILTER);\n\n    CustomEvents.define(timelineDaySelectorContainer, [CustomEvents.events.activate]);\n    timelineDaySelectorContainer.on(\n        CustomEvents.events.activate,\n        SELECTORS.TIMELINE_DAY_FILTER_OPTION,\n        function(e, data) {\n            // Update the user preference\n            var filtername = $(e.currentTarget).data('filtername');\n            var type = 'block_timeline_user_filter_preference';\n            UserRepository.setUserPreference(type, filtername)\n                .catch(Notification.exception);\n\n            var option = $(e.target).closest(SELECTORS.TIMELINE_DAY_FILTER_OPTION);\n\n            if (option.attr('aria-current') == 'true') {\n                // If it's already active then we don't need to do anything.\n                return;\n            }\n\n            var daysOffset = option.attr('data-from');\n            var daysLimit = option.attr('data-to');\n            var elementsWithDaysOffset = root.find(SELECTORS.DATA_DAYS_OFFSET);\n\n            elementsWithDaysOffset.attr('data-days-offset', daysOffset);\n\n            if (daysLimit != undefined) {\n                elementsWithDaysOffset.attr('data-days-limit', daysLimit);\n            } else {\n                elementsWithDaysOffset.removeAttr('data-days-limit');\n            }\n\n            if (option.attr('data-filtername') === 'overdue') {\n                elementsWithDaysOffset.attr('data-filter-overdue', true);\n            } else {\n                elementsWithDaysOffset.removeAttr('data-filter-overdue');\n            }\n\n            // Reset the views to reinitialise the event lists now that we've\n            // updated the day limits.\n            View.reset(timelineViewRoot);\n\n            data.originalEvent.preventDefault();\n        }\n    );\n};\n\n/**\n * Event listener for the \"sort\" button in the timeline navigation that allows for\n * changing between the timeline dates and courses views.\n *\n * On a view change we tell the timeline view module that the view has been shown\n * so that it can handle how to display the appropriate view.\n *\n * @param {object} root The root element for the timeline block\n * @param {object} timelineViewRoot The root element for the timeline view\n */\nconst registerViewSelector = function(root, timelineViewRoot) {\n    const viewSelector = root.find(SELECTORS.TIMELINE_VIEW_SELECTOR);\n\n    // Listen for when the user changes tab so that we can show the first set of courses\n    // and load their events when they request the sort by courses view for the first time.\n    viewSelector.on('shown shown.bs.tab', function(e) {\n        View.shown(timelineViewRoot);\n        $(e.target).removeClass('active');\n    });\n\n\n    // Event selector for user_sort\n    CustomEvents.define(viewSelector, [CustomEvents.events.activate]);\n    viewSelector.on(CustomEvents.events.activate, \"[data-toggle='tab']\", function(e) {\n        var filtername = $(e.currentTarget).data('filtername');\n        var type = 'block_timeline_user_sort_preference';\n        UserRepository.setUserPreference(type, filtername)\n            .catch(Notification.exception);\n    });\n};\n\n/**\n * Event listener for the \"search\" input field in the timeline navigation that allows for\n * searching the activity name, course name and activity type.\n *\n * @param {object} root The root element for the timeline block\n * @param {object} timelineViewRoot The root element for the timeline view\n */\nconst registerSearch = (root, timelineViewRoot) => {\n    const searchInput = root.find(SELECTORS.TIMELINE_SEARCH_INPUT);\n    const clearSearchIcon = root.find(SELECTORS.TIMELINE_SEARCH_CLEAR_ICON);\n    searchInput.on('input', Utils.debounce(() => {\n        if (searchInput.val() !== '') {\n            activeSearchState(clearSearchIcon, timelineViewRoot);\n        } else {\n            clearSearchState(clearSearchIcon, timelineViewRoot);\n        }\n    }, 1000));\n    clearSearchIcon.on('click', () => {\n        searchInput.val('');\n        clearSearchState(clearSearchIcon, timelineViewRoot);\n        searchInput.focus();\n    });\n};\n\n/**\n * Show the clear search icon.\n *\n * @param {object} clearSearchIcon Clear search icon element.\n * @param {object} timelineViewRoot The root element for the timeline view\n */\nconst activeSearchState = (clearSearchIcon, timelineViewRoot) => {\n    clearSearchIcon.removeClass('d-none');\n    View.reset(timelineViewRoot);\n};\n\n/**\n * Hide the clear search icon.\n *\n * @param {object} clearSearchIcon Clear search icon element.\n * @param {object} timelineViewRoot The root element for the timeline view\n */\nconst clearSearchState = (clearSearchIcon, timelineViewRoot) => {\n    clearSearchIcon.addClass('d-none');\n    View.reset(timelineViewRoot);\n};\n\n/**\n * Initialise the timeline view navigation by adding event listeners to\n * the navigation elements.\n *\n * @param {jQuery|HTMLElement} root The root element for the timeline block\n * @param {object} timelineViewRoot The root element for the timeline view\n */\nexport const init = function(root, timelineViewRoot) {\n    root = $(root);\n\n    registerViewSelector(root, timelineViewRoot);\n\n    // Only need to handle filtering if the user is actively enrolled in a course.\n    if (!root.find(SELECTORS.NO_COURSES_EMPTY_MESSAGE).length) {\n        registerTimelineDaySelector(root, timelineViewRoot);\n        registerSearch(root, timelineViewRoot);\n    }\n};\n"],"names":["SELECTORS","activeSearchState","clearSearchIcon","timelineViewRoot","removeClass","View","reset","clearSearchState","addClass","root","viewSelector","find","on","e","shown","target","CustomEvents","define","events","activate","filtername","currentTarget","data","UserRepository","setUserPreference","catch","Notification","exception","registerViewSelector","length","timelineDaySelectorContainer","option","closest","attr","daysOffset","daysLimit","elementsWithDaysOffset","undefined","removeAttr","originalEvent","preventDefault","registerTimelineDaySelector","searchInput","Utils","debounce","val","focus","registerSearch"],"mappings":";;;;;;4yCA6BMA,8BACmB,6BADnBA,qCAE0B,cAF1BA,iCAGsB,gCAHtBA,2BAIgB,qBAJhBA,gCAMqB,yBANrBA,qCAO0B,8BAP1BA,mCAQwB,2CAsHxBC,kBAAoB,CAACC,gBAAiBC,oBACxCD,gBAAgBE,YAAY,UAC5BC,KAAKC,MAAMH,mBASTI,iBAAmB,CAACL,gBAAiBC,oBACvCD,gBAAgBM,SAAS,UACzBH,KAAKC,MAAMH,iCAUK,SAASM,KAAMN,mBA1EN,SAASM,KAAMN,wBAClCO,aAAeD,KAAKE,KAAKX,kCAI/BU,aAAaE,GAAG,sBAAsB,SAASC,GAC3CR,KAAKS,MAAMX,sCACTU,EAAEE,QAAQX,YAAY,aAK5BY,aAAaC,OAAOP,aAAc,CAACM,aAAaE,OAAOC,WACvDT,aAAaE,GAAGI,aAAaE,OAAOC,SAAU,uBAAuB,SAASN,OACtEO,YAAa,mBAAEP,EAAEQ,eAAeC,KAAK,cAEzCC,eAAeC,kBADJ,sCAC4BJ,YAClCK,MAAMC,aAAaC,eA4D5BC,CAFAnB,MAAO,mBAAEA,MAEkBN,kBAGtBM,KAAKE,KAAKX,oCAAoC6B,SA1InB,SAASpB,KAAMN,wBACzC2B,6BAA+BrB,KAAKE,KAAKX,+BAE/CgB,aAAaC,O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