Proyectos de Subversion Moodle

Rev

Rev 5 | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

{"version":3,"file":"script_config_point_view.min.js","sources":["../src/script_config_point_view.js"],"sourcesContent":["// This file is part of Moodle - https://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 * Defines the behavior of the configuration page of a Point of View block.\n * @copyright  2020 Quentin Fombaron, 2021 Astor Bizard\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery', 'core/ajax', 'core/notification'], function($, ajax, notification) {\n\n    /**\n     * Manage updating of visibility state of elements related to Reactions and Difficulty tracks,\n     * depending on whether they are enabled or not.\n     */\n    function manageElementsVisibility() {\n        var $enableReactions = $('[name=\"config_enable_point_views\"]');\n        var $enableDifficultyTracks = $('[name=\"config_enable_difficultytracks\"]');\n\n        var updateElementsVisibility = function() {\n            var reactionsEnabled = $enableReactions.val() > 0;\n            var difficultyTracksEnabled = $enableDifficultyTracks.val() > 0;\n\n            $('fieldset[id^=id_activities_header]').toggle(reactionsEnabled || difficultyTracksEnabled);\n\n            $('.reactions, fieldset[id^=id_images_header]').toggle(reactionsEnabled);\n            $('.difficultytracks').toggle(difficultyTracksEnabled);\n        };\n\n        updateElementsVisibility();\n\n        $enableReactions.change(updateElementsVisibility);\n        $enableDifficultyTracks.change(updateElementsVisibility);\n    }\n\n    /**\n     * Manage Enable/Disable buttons for sections and module types.\n     */\n    function manageEnableDisableButtons() {\n\n        // Update of Enable/Disable buttons state for a section or module type,\n        // depending on checkboxes state for that section or module type.\n        var updateEnableDisableButtonsFor = function(sectionOrType) {\n            var $checkboxes = $('.cb' + sectionOrType + ':checkbox');\n            var nBoxesChecked = $checkboxes.filter(':checked').length;\n            $('#enableall' + sectionOrType).toggleClass('active', nBoxesChecked === $checkboxes.length);\n            $('#disableall' + sectionOrType).toggleClass('active', nBoxesChecked === 0);\n        };\n\n        $('.enablemodulereactions').change(function() {\n            updateEnableDisableButtonsFor($(this).data('type')); // Update Enable/Disable buttons state for module type.\n            updateEnableDisableButtonsFor($(this).data('section')); // Update Enable/Disable buttons state for section.\n        }).click(function() {\n            $('.enablemodulereactions.highlighted').removeClass('highlighted');\n        });\n\n        $('.enable-disable button').each(function() {\n            var sectionOrType = $(this).data('type') || $(this).data('section');\n\n            updateEnableDisableButtonsFor(sectionOrType); // Update Enable/Disable buttons state on page load.\n\n            $(this).click(function() {\n                $('.enablemodulereactions.highlighted').removeClass('highlighted');\n                $('.cb' + sectionOrType + ':checkbox')\n                .prop('checked', $(this).data('enable')) // Update all corresponding checkboxes.\n                .addClass('highlighted')\n                .change(); // Trigger a change to update Enable/Disable buttons state accordingly.\n            });\n        });\n    }\n\n    /**\n     * Adds a listener to a button click with a confirm dialog and ajax call.\n     * @param {jQuery} $button The button to add the listener to.\n     * @param {String} message Confirmation message, a string component of block_point_view.\n     * @param {String} ajaxmethod Ajax method to be called.\n     * @param {Object} ajaxargs Arguments to be passed to the ajax call.\n     * @param {Function} callback A function called after ajax call completed successfully.\n     */\n    function buttonWithAjaxCall($button, message, ajaxmethod, ajaxargs, callback) {\n        $button.click(function(e) {\n            M.util.show_confirm_dialog(e, {\n                message: M.util.get_string(message, 'block_point_view'),\n                callback: function() {\n                    ajax.call([\n                        {\n                            methodname: 'block_point_view_' + ajaxmethod,\n                            args: ajaxargs,\n                            done: callback,\n                            fail: notification.exception\n                        }\n                    ]);\n                }\n            });\n        });\n    }\n\n    /**\n     * Setup change listener to update track color responsively when it is changed from select.\n     * @param {Object} trackcolors Mapping of trackname => CSS color.\n     */\n    function setupDifficultyTrackChange(trackcolors) {\n        // Difficulty track change.\n        $('.moduletrackselect select').change(function() {\n            $('#track_' + $(this).data('id')).css({\n                'background-color': trackcolors[$(this).val()] // Change track color.\n            });\n        }).change(); // Update track colors once on page load.\n    }\n\n    return {\n        init: function(envconf, trackcolors) {\n\n            manageElementsVisibility();\n\n            manageEnableDisableButtons();\n\n            setupDifficultyTrackChange(trackcolors);\n\n            // Custom emoji deletion.\n            buttonWithAjaxCall(\n                    $('#delete_custom_pix'),\n                    'deleteemojiconfirmation',\n                    'delete_custom_pix',\n                    {\n                        contextid: envconf.contextid,\n                        courseid: envconf.courseid,\n                        draftitemid: $('input[name=\"config_point_views_pix\"]').val()\n                    },\n                    function() {\n                        $('.pix-preview[data-source=\"custom\"], #delete_custom_pix').remove(); // Remove emoji preview and button.\n                        // Refresh draft area files.\n                        // # For an unknown reason, the following instruction with jQuery does not work\n                        // # (or at least does not trigger the expected listener).\n                        document.querySelector('[id^=fitem_id_config_point_views_pix] .fp-path-folder-name').click();\n                    }\n            );\n\n            // Update current emoji on emoji change.\n            $('[name=config_pixselect]').change(function() {\n                var newsource = $(this).val();\n                $('img.currentpix').each(function() {\n                    var $img = $('img[data-source=\"' + newsource + '\"][data-reaction=\"' + $(this).data('reaction') + '\"]');\n                    if ($img.length == 1 && $img.attr('src') > '') {\n                        $(this).attr('src', $img.attr('src'));\n                    }\n                });\n            });\n\n            // Course reactions cleanup.\n            buttonWithAjaxCall(\n                    $('#cleanup_reactions'),\n                    'cleanupreactionsconfirmation',\n                    'update_db',\n                    {\n                        func: 'cleanup',\n                        courseid: envconf.courseid\n                    },\n                    function() {\n                        notification.alert(M.util.get_string('info', 'moodle'),\n                                M.util.get_string('reactionscleanedupsuccessfully', 'block_point_view'),\n                                M.util.get_string('ok', 'moodle'));\n                    }\n            );\n\n            // Course reactions reset.\n            buttonWithAjaxCall(\n                    $('#reset_reactions'),\n                    'resetreactionsconfirmation',\n                    'update_db',\n                    {\n                        func: 'reset',\n                        courseid: envconf.courseid\n                    },\n                    function() {\n                        notification.alert(M.util.get_string('info', 'moodle'),\n                                M.util.get_string('reactionsresetsuccessfully', 'block_point_view'),\n                                M.util.get_string('ok', 'moodle'));\n                    }\n            );\n\n            // Module reactions reset.\n            $('[data-role=reset_module').each(function() {\n                var cmid = $(this).data('cmid');\n                buttonWithAjaxCall(\n                        $(this),\n                        'resetreactionsonmoduleconfirmation',\n                        'update_db',\n                        {\n                            func: 'reset',\n                            courseid: envconf.courseid,\n                            cmid: cmid\n                        },\n                        function() {\n                            notification.alert(M.util.get_string('info', 'moodle'),\n                                    M.util.get_string('reactionsresetsuccessfully', 'block_point_view'),\n                                    M.util.get_string('ok', 'moodle'));\n                        }\n                );\n            });\n        },\n\n        setupDifficultyTrackChange: setupDifficultyTrackChange\n    };\n});"],"names":["define","$","ajax","notification","buttonWithAjaxCall","$button","message","ajaxmethod","ajaxargs","callback","click","e","M","util","show_confirm_dialog","get_string","call","methodname","args","done","fail","exception","setupDifficultyTrackChange","trackcolors","change","this","data","css","val","init","envconf","$enableReactions","$enableDifficultyTracks","updateElementsVisibility","updateEnableDisableButtonsFor","reactionsEnabled","difficultyTracksEnabled","toggle","sectionOrType","$checkboxes","nBoxesChecked","filter","length","toggleClass","removeClass","each","prop","addClass","contextid","courseid","draftitemid","remove","document","querySelector","newsource","$img","attr","func","alert","cmid"],"mappings":";;;;;AAoBAA,OAAO,4CAAA,CAAC,SAAU,YAAa,sBAAsB,SAASC,EAAGC,KAAMC,cAsEnE,SAASC,mBAAmBC,QAASC,QAASC,WAAYC,SAAUC,UAChEJ,QAAQK,OAAM,SAASC,GACnBC,EAAEC,KAAKC,oBAAoBH,EAAG,CAC1BL,QAASM,EAAEC,KAAKE,WAAWT,QAAS,oBACpCG,SAAU,WACNP,KAAKc,KAAK,CACN,CACIC,WAAY,oBAAsBV,WAClCW,KAAMV,SACNW,KAAMV,SACNW,KAAMjB,aAAakB,YAG/B,GAER,GACJ,CAMA,SAASC,2BAA2BC,a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