Proyectos de Subversion Moodle

Rev

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

{"version":3,"file":"main.min.js","sources":["../src/main.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 * Javascript to initialise the starred courses block.\n *\n * @module block_starredcourses/main\n * @copyright   2018 Simey Lameze <simey@moodle.com>\n * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\ndefine(\n[\n    'jquery',\n    'core/notification',\n    'block_starredcourses/repository',\n    'core/pubsub',\n    'core/templates',\n    'core_course/events'\n],\nfunction(\n    $,\n    Notification,\n    Repository,\n    PubSub,\n    Templates,\n    CourseEvents\n) {\n\n    var SELECTORS = {\n        BLOCK_CONTAINER: '[data-region=\"starred-courses\"]',\n        STARRED_COURSES_REGION_VIEW: '[data-region=\"starred-courses-view\"]',\n        STARRED_COURSES_REGION: '[data-region=\"starred-courses-view-content\"]'\n    };\n\n    /**\n     * Render the starred courses.\n     *\n     * @method renderCourses\n     * @param {object} root The root element for the starred view.\n     * @param {array} courses containing array of returned courses.\n     * @returns {promise} Resolved with HTML and JS strings\n     */\n    var renderCourses = function(root, courses) {\n        if (courses.length > 0) {\n            return Templates.render('core_course/view-cards', {\n                courses: courses\n            });\n        } else {\n            var nocoursesimg = root.find(SELECTORS.STARRED_COURSES_REGION_VIEW).attr('data-nocoursesimg');\n            return Templates.render('block_starredcourses/no-courses', {\n                nocoursesimg: nocoursesimg\n            });\n        }\n    };\n\n    /**\n     * Fetch user's starred courses and reload the content of the block.\n     *\n     * @param {object} root The root element for the starred view.\n     * @returns {promise} The updated content for the block.\n     */\n    var reloadContent = function(root) {\n        var content = root.find(SELECTORS.STARRED_COURSES_REGION);\n\n        var args = {\n            limit: 0,\n            offset: 0,\n        };\n\n        return Repository.getStarredCourses(args)\n            .then(function(courses) {\n                // Whether the course category should be displayed in the course item.\n                var showcoursecategory = $(SELECTORS.BLOCK_CONTAINER).data('displaycoursecategory');\n                courses = courses.map(function(course) {\n                    course.showcoursecategory = showcoursecategory;\n                    return course;\n                });\n                return renderCourses(root, courses);\n            }).then(function(html, js) {\n                return Templates.replaceNodeContents(content, html, js);\n            }).catch(Notification.exception);\n    };\n\n    /**\n     * Register event listeners for the block.\n     *\n     * @param {object} root The calendar root element\n     */\n    var registerEventListeners = function(root) {\n        PubSub.subscribe(CourseEvents.favourited, function() {\n            reloadContent(root);\n        });\n\n        PubSub.subscribe(CourseEvents.unfavorited, function() {\n            reloadContent(root);\n        });\n    };\n\n    /**\n     * Initialise all of the modules for the starred courses block.\n     *\n     * @param {object} root The root element for the block.\n     */\n    var init = function(root) {\n        root = $(root);\n\n        registerEventListeners(root);\n        reloadContent(root);\n    };\n\n    return {\n        init: init\n    };\n});\n"],"names":["define","$","Notification","Repository","PubSub","Templates","CourseEvents","SELECTORS","reloadContent","root","content","find","getStarredCourses","limit","offset","then","courses","showcoursecategory","data","map","course","length","render","nocoursesimg","attr","renderCourses","html","js","replaceNodeContents","catch","exception","init","subscribe","favourited","unfavorited","registerEventListeners"],"mappings":";;;;;;;AAuBAA,mCACA,CACI,SACA,oBACA,kCACA,cACA,iBACA,uBAEJ,SACIC,EACAC,aACAC,WACAC,OACAC,UACAC,kBAGIC,0BACiB,kCADjBA,sCAE6B,uCAF7BA,iCAGwB,+CA8BxBC,cAAgB,SAASC,UACrBC,QAAUD,KAAKE,KAAKJ,yCAOjBJ,WAAWS,kBALP,CACPC,MAAO,EACPC,OAAQ,IAIPC,MAAK,SAASC,aAEPC,mBAAqBhB,EAAEM,2BAA2BW,KAAK,gCAC3DF,QAAUA,QAAQG,KAAI,SAASC,eAC3BA,OAAOH,mBAAqBA,mBACrBG,UAjCH,SAASX,KAAMO,YAC3BA,QAAQK,OAAS,SACVhB,UAAUiB,OAAO,yBAA0B,CAC9CN,QAASA,cAGTO,aAAed,KAAKE,KAAKJ,uCAAuCiB,KAAK,4BAClEnB,UAAUiB,OAAO,kCAAmC,CACvDC,aAAcA,eA2BPE,CAAchB,KAAMO,YAC5BD,MAAK,SAASW,KAAMC,WACZtB,UAAUuB,oBAAoBlB,QAASgB,KAAMC,OACrDE,MAAM3B,aAAa4B,kBA8BvB,CACHC,KARO,SAAStB,OAfS,SAASA,MAClCL,OAAO4B,UAAU1B,aAAa2B,YAAY,WACtCzB,cAAcC,SAGlBL,OAAO4B,UAAU1B,aAAa4B,aAAa,WACvC1B,cAAcC,UAYlB0B,CAFA1B,KAAOR,EAAEQ,OAGTD,cAAcC"}