Proyectos de Subversion Moodle

Rev

Rev 4 | Ir a la última revisión | 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 = $('#id_config_enable_point_views');\n        var $enableDifficultyTracks = $('#id_config_enable_difficultytracks');\n\n        var updateElementsVisibility = function() {\n            var reactionsEnabled = $enableReactions.val() > 0;\n            var difficultyTracksEnabled = $enableDifficultyTracks.val() > 0;\n\n            $('#id_activities_header').toggle(reactionsEnabled || difficultyTracksEnabled);\n\n            $('.reactions, #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    return {\n        init: function(envconf, trackcolors) {\n\n            manageElementsVisibility();\n\n            manageEnableDisableButtons();\n\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            // 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('#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});"],"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","init","envconf","trackcolors","$enableReactions","$enableDifficultyTracks","updateElementsVisibility","updateEnableDisableButtonsFor","reactionsEnabled","val","difficultyTracksEnabled","toggle","change","sectionOrType","$checkboxes","nBoxesChecked","filter","length","toggleClass","this","data","removeClass","each","prop","addClass","css","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,CAEA,MAAO,CACHC,KAAM,SAASC,QAASC,aAnF5B,IACQC,iBACAC,wBAEAC,yBAuBAC,8BA1BAH,iBAAmBxB,EAAE,iCACrByB,wBAA0BzB,EAAE,uCAE5B0B,yBAA2B,WAC3B,IAAIE,iBAAmBJ,iBAAiBK,MAAQ,EAC5CC,wBAA0BL,wBAAwBI,MAAQ,EAE9D7B,EA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