Proyectos de Subversion Moodle

Rev

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

{"version":3,"file":"notification_area_content_area.min.js","sources":["../src/notification_area_content_area.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 * Controls the content area of the notification area on the\n * notification page.\n *\n * @module     message_popup/notification_area_content_area\n * @copyright  2016 Ryan Wyllie <ryan@moodle.com>\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery', 'core/templates', 'core/notification', 'core/custom_interaction_events',\n        'message_popup/notification_repository', 'message_popup/notification_area_events'],\n    function($, Templates, DebugNotification, CustomEvents, NotificationRepo, NotificationAreaEvents) {\n\n    var SELECTORS = {\n        CONTAINER: '[data-region=\"notification-area\"]',\n        CONTENT: '[data-region=\"content\"]',\n        HEADER: '[data-region=\"header\"]',\n        FOOTER: '[data-region=\"footer\"]',\n        TOGGLE_MODE: '[data-action=\"toggle-mode\"]',\n    };\n\n    var TEMPLATES = {\n        HEADER: 'message_popup/notification_area_content_area_header',\n        CONTENT: 'message_popup/notification_area_content_area_content',\n        FOOTER: 'message_popup/notification_area_content_area_footer',\n    };\n\n    /**\n     * Constructor for the ContentArea\n     *\n     * @class\n     * @param {object} root The root element for the content area\n     * @param {int} userId The user id of the current user\n     */\n    var ContentArea = function(root, userId) {\n        this.root = $(root);\n        this.container = this.root.closest(SELECTORS.CONTAINER);\n        this.userId = userId;\n        this.header = this.root.find(SELECTORS.HEADER);\n        this.content = this.root.find(SELECTORS.CONTENT);\n        this.footer = this.root.find(SELECTORS.FOOTER);\n\n        this.registerEventListeners();\n    };\n\n    /**\n     * Get the root element.\n     *\n     * @method getRoot\n     * @return {object} jQuery element\n     */\n    ContentArea.prototype.getRoot = function() {\n        return this.root;\n    };\n\n    /**\n     * Get the container element (which the content area is within).\n     *\n     * @method getContainer\n     * @return {object} jQuery element\n     */\n    ContentArea.prototype.getContainer = function() {\n        return this.container;\n    };\n\n    /**\n     * Get the user id.\n     *\n     * @method getUserId\n     * @return {int}\n     */\n    ContentArea.prototype.getUserId = function() {\n        return this.userId;\n    };\n\n    /**\n     * Get the content area header element.\n     *\n     * @method getHeader\n     * @return {object} jQuery element\n     */\n    ContentArea.prototype.getHeader = function() {\n        return this.header;\n    };\n\n    /**\n     * Get the content area content element.\n     *\n     * @method getContent\n     * @return {object} jQuery element\n     */\n    ContentArea.prototype.getContent = function() {\n        return this.content;\n    };\n\n    /**\n     * Get the content area footer element.\n     *\n     * @method getFooter\n     * @return {object} jQuery element\n     */\n    ContentArea.prototype.getFooter = function() {\n        return this.footer;\n    };\n\n    /**\n     * Display the content area. Typically used with responsive\n     * styling on smaller screens.\n     *\n     * @method show\n     */\n    ContentArea.prototype.show = function() {\n        this.getContainer().addClass('show-content-area');\n    };\n\n    /**\n     * Hide the content area. Typically used with responsive\n     * styling on smaller screens.\n     *\n     * @method hide\n     */\n    ContentArea.prototype.hide = function() {\n        this.getContainer().removeClass('show-content-area');\n    };\n\n    /**\n     * Change the HTML in the content area header element.\n     *\n     * @method setHeaderHTML\n     * @param {string} html The HTML to be set\n     */\n    ContentArea.prototype.setHeaderHTML = function(html) {\n        this.getHeader().empty().html(html);\n    };\n\n    /**\n     * Change the HTML in the content area content element.\n     *\n     * @method setContentHMTL\n     * @param {string} html The HTML to be set.\n     */\n    ContentArea.prototype.setContentHTML = function(html) {\n        this.getContent().empty().html(html);\n    };\n\n    /**\n     * Change the HTML in the content area footer element.\n     *\n     * @method setFooterHTML\n     * @param {string} html The HTML to be set.\n     */\n    ContentArea.prototype.setFooterHTML = function(html) {\n        this.getFooter().empty().html(html);\n    };\n\n    /**\n     * Render the given notification context in the content area.\n     *\n     * @method showNotification\n     * @param {object} notification The notification context (from a webservice)\n     * @return {object} jQuery promise\n     */\n    ContentArea.prototype.showNotification = function(notification) {\n        var headerPromise = Templates.render(TEMPLATES.HEADER, notification).done(function(html) {\n            this.setHeaderHTML(html);\n        }.bind(this));\n\n        var contentPromise = Templates.render(TEMPLATES.CONTENT, notification).done(function(html) {\n            this.setContentHTML(html);\n        }.bind(this));\n\n        var footerPromise = Templates.render(TEMPLATES.FOOTER, notification).done(function(html) {\n            this.setFooterHTML(html);\n        }.bind(this));\n\n        return $.when(headerPromise, contentPromise, footerPromise).done(function() {\n            this.show();\n            this.getContainer().trigger(NotificationAreaEvents.notificationShown, [notification]);\n        }.bind(this));\n    };\n\n    /**\n     * Create the event listeners for the content area.\n     *\n     * @method registerEventListeners\n     */\n    ContentArea.prototype.registerEventListeners = function() {\n        CustomEvents.define(this.getRoot(), [\n            CustomEvents.events.activate\n        ]);\n\n        this.getRoot().on(CustomEvents.events.activate, SELECTORS.VIEW_TOGGLE, function() {\n            this.hide();\n        }.bind(this));\n\n        this.getContainer().on(NotificationAreaEvents.showNotification, function(e, notification) {\n            this.showNotification(notification);\n        }.bind(this));\n    };\n\n    return ContentArea;\n});\n"],"names":["define","$","Templates","DebugNotification","CustomEvents","NotificationRepo","NotificationAreaEvents","SELECTORS","CONTAINER","CONTENT","HEADER","FOOTER","TOGGLE_MODE","TEMPLATES","ContentArea","root","userId","container","this","closest","header","find","content","footer","registerEventListeners","prototype","getRoot","getContainer","getUserId","getHeader","getContent","getFooter","show","addClass","hide","removeClass","setHeaderHTML","html","empty","setContentHTML","setFooterHTML","showNotification","notification","headerPromise","render","done","bind","contentPromise","footerPromise","when","trigger","notificationShown","events","activate","on","VIEW_TOGGLE","e"],"mappings":";;;;;;;;AAuBAA,sDAAO,CAAC,SAAU,iBAAkB,oBAAqB,iCACjD,wCAAy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