Your IP : 192.168.165.1


Current Path : C:/xampp/htdocs/moodle/report/insights/amd/build/
Upload File :
Current File : C:/xampp/htdocs/moodle/report/insights/amd/build/message_users.min.js.map

{"version":3,"sources":["../src/message_users.js"],"names":["define","$","Str","Log","ModalFactory","ModalEvents","Templates","Notification","Ajax","SELECTORS","BULKACTIONSELECT","MessageUsers","rootNode","actionName","attachEventListeners","prototype","modal","on","e","preventDefault","cTarget","currentTarget","users","predictionToUserMapping","data","each","index","value","predictionId","closest","error","userId","Object","keys","length","showSendMessage","bind","userIds","Set","values","Deferred","resolve","promise","titlePromise","size","get_string","when","create","type","types","SAVE_CANCEL","body","render","then","title","setTitle","setSaveButtonText","getRoot","hidden","focus","remove","save","submitSendMessage","show","messageText","find","val","messages","forEach","push","touserid","text","message","call","methodname","args","messageIds","msg","actionname","predictionids","addNotification","catch","exception"],"mappings":"AAuBAA,OAAM,iCAAC,CAAC,QAAD,CAAW,UAAX,CAAuB,UAAvB,CAAmC,oBAAnC,CAAyD,mBAAzD,CAA8E,gBAA9E,CACH,mBADG,CACkB,WADlB,CAAD,CAEE,SAASC,CAAT,CAAYC,CAAZ,CAAiBC,CAAjB,CAAsBC,CAAtB,CAAoCC,CAApC,CAAiDC,CAAjD,CAA4DC,CAA5D,CAA0EC,CAA1E,CAAgF,IAEhFC,CAAAA,CAAS,CAAG,CACZC,gBAAgB,CAAE,eADN,CAFoE,CAYhFC,CAAY,CAAG,SAASC,CAAT,CAAmBC,CAAnB,CAA+B,CAC9C,KAAKA,UAAL,CAAkBA,CAAlB,CACA,KAAKC,oBAAL,CAA0BF,CAA1B,CACH,CAfmF,CAqBpFD,CAAY,CAACI,SAAb,CAAuBF,UAAvB,CAAoC,IAApC,CAMAF,CAAY,CAACI,SAAb,CAAuBC,KAAvB,CAA+B,IAA/B,CAMAL,CAAY,CAACI,SAAb,CAAuBD,oBAAvB,CAA8C,SAASF,CAAT,CAAmB,CAC7DX,CAAC,CAACW,CAAQ,CAAG,gCAAZ,CAAD,C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AAZ,CAFb,CAFQ,CAAD,CAAV,EAMH,CANG,CAOV,CAtBM,EAsBJ+B,IAtBI,CAsBC,UAAW,CACf9C,CAAY,CAACyE,eAAb,CAA6B,CACzBR,OAAO,CAAEA,CADgB,CAEzBxB,IAAI,CAAE,SAFmB,CAA7B,EAIA,QACH,CA5BM,EA4BJiC,KA5BI,CA4BE1E,CAAY,CAAC2E,SA5Bf,CA6BV,CA1CD,CA4CA,MAA0D,CAStD,KAAQ,cAAStE,CAAT,CAAmBC,CAAnB,CAA+B,CACnC,MAAO,IAAIF,CAAAA,CAAJ,CAAiBC,CAAjB,CAA2BC,CAA3B,CACV,CAXqD,CAa7D,CAxLK,CAAN","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 * Message users.\n *\n * @module     report_insights/message_users\n * @package    report_insights\n * @copyright  2019 David Monllao\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery', 'core/str', 'core/log', 'core/modal_factory', 'core/modal_events', 'core/templates',\n    'core/notification', 'core/ajax'],\n        function($, Str, Log, ModalFactory, ModalEvents, Templates, Notification, Ajax) {\n\n    var SELECTORS = {\n        BULKACTIONSELECT: \"#formactionid\"\n    };\n\n    /**\n     * Constructor.\n     *\n     * @param {String} rootNode\n     * @param {String} actionName\n     */\n    var MessageUsers = function(rootNode, actionName) {\n        this.actionName = actionName;\n        this.attachEventListeners(rootNode);\n    };\n\n    /**\n     * @var {String} actionName\n     * @private\n     */\n    MessageUsers.prototype.actionName = null;\n\n    /**\n     * @var {Modal} modal\n     * @private\n     */\n    MessageUsers.prototype.modal = null;\n\n    /**\n     * Attach the event listener to the send message bulk action.\n     * @param {String} rootNode\n     */\n    MessageUsers.prototype.attachEventListeners = function(rootNode) {\n        $(rootNode + ' button[data-bulk-sendmessage]').on('click', function(e) {\n            e.preventDefault();\n            var cTarget = $(e.currentTarget);\n\n            // Using an associative array in case there is more than 1 prediction for the same user.\n            var users = {};\n            var predictionToUserMapping = cTarget.data('prediction-to-user-id');\n\n            var checkedSelector = '.insights-list input[data-togglegroup^=\"insight-bulk-action\"][data-toggle=\"slave\"]:checked';\n            $(checkedSelector).each(function(index, value) {\n                var predictionId = $(value).closest('tr[data-prediction-id]').data('prediction-id');\n\n                if (typeof predictionToUserMapping[predictionId] === 'undefined') {\n                    Log.error('Unknown user for prediction ' + predictionId);\n                    return;\n                }\n\n                var userId = predictionToUserMapping[predictionId];\n                users[predictionId] = userId;\n\n            });\n\n            if (Object.keys(users).length === 0) {\n                return this;\n            }\n\n            this.showSendMessage(users);\n\n            return this;\n        }.bind(this));\n    };\n\n    /**\n     * Show the send message popup.\n     *\n     * @method showSendMessage\n     * @private\n     * @param {Object} users Prediction id to user id mapping.\n     * @return {Promise}\n     */\n    MessageUsers.prototype.showSendMessage = function(users) {\n\n        var userIds = new Set(Object.values(users));\n\n        if (userIds.length == 0) {\n            // Nothing to do.\n            return $.Deferred().resolve().promise();\n        }\n        var titlePromise = null;\n        if (userIds.size == 1) {\n            titlePromise = Str.get_string('sendbulkmessagesingle', 'core_message');\n        } else {\n            titlePromise = Str.get_string('sendbulkmessage', 'core_message', userIds.size);\n        }\n\n        return $.when(\n            ModalFactory.create({\n                type: ModalFactory.types.SAVE_CANCEL,\n                body: Templates.render('core_user/send_bulk_message', {})\n            }),\n            titlePromise\n        ).then(function(modal, title) {\n            // Keep a reference to the modal.\n            this.modal = modal;\n\n            this.modal.setTitle(title);\n            this.modal.setSaveButtonText(title);\n\n            // We want to focus on the action select when the dialog is closed.\n            this.modal.getRoot().on(ModalEvents.hidden, function() {\n                $(SELECTORS.BULKACTIONSELECT).focus();\n                this.modal.getRoot().remove();\n            }.bind(this));\n\n            this.modal.getRoot().on(ModalEvents.save, this.submitSendMessage.bind(this, users));\n\n            this.modal.show();\n\n            return this.modal;\n        }.bind(this));\n    };\n\n    /**\n     * Send a message to these users.\n     *\n     * @method submitSendMessage\n     * @private\n     * @param {Object} users Prediction id to user id mapping.\n     * @param {Event} e Form submission event.\n     * @return {Promise}\n     */\n    MessageUsers.prototype.submitSendMessage = function(users) {\n\n        var messageText = this.modal.getRoot().find('form textarea').val();\n\n        var messages = [];\n\n        var userIds = new Set(Object.values(users));\n        userIds.forEach(function(userId) {\n            messages.push({touserid: userId, text: messageText});\n        });\n\n        var actionName = this.actionName;\n        var message = null;\n        return Ajax.call([{\n            methodname: 'core_message_send_instant_messages',\n            args: {messages: messages}\n        }])[0].then(function(messageIds) {\n            if (messageIds.length == 1) {\n                return Str.get_string('sendbulkmessagesentsingle', 'core_message');\n            } else {\n                return Str.get_string('sendbulkmessagesent', 'core_message', messageIds.length);\n            }\n        }).then(function(msg) {\n\n            // Save this for the following callback. Now that we got everything\n            // done we can flag this action as executed.\n            message = msg;\n\n            return Ajax.call([{\n                methodname: 'report_insights_action_executed',\n                args: {\n                    actionname: actionName,\n                    predictionids: Object.keys(users)\n                }\n            }])[0];\n        }).then(function() {\n            Notification.addNotification({\n                message: message,\n                type: \"success\"\n            });\n            return true;\n        }).catch(Notification.exception);\n    };\n\n    return /** @alias module:report_insights/message_users */ {\n        // Public variables and functions.\n\n        /**\n         * @method init\n         * @param {String} rootNode\n         * @param {String} actionName\n         * @return {MessageUsers}\n         */\n        'init': function(rootNode, actionName) {\n            return new MessageUsers(rootNode, actionName);\n        }\n    };\n});\n"],"file":"message_users.min.js"}