Proyectos de Subversion Moodle

Rev

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

{"version":3,"file":"message_send_bulk.min.js","sources":["../src/message_send_bulk.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 * Send bulk message to the given user ids.\n *\n * @module     core_message/message_send_bulk\n * @copyright  2019 Shamim Rezaie <shamim@moodle.com>\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport {get_string} from 'core/str';\nimport ModalSaveCancel from 'core/modal_save_cancel';\nimport Templates from 'core/templates';\nimport ModalEvents from 'core/modal_events';\nimport Ajax from 'core/ajax';\nimport Notification from 'core/notification';\n\n/**\n * Show the send message popup.\n *\n * @method showModal\n * @param {int[]} users\n * @param {Function} callback A callback to apply after the form is closed.\n * @returns {Promise}\n */\nexport const showModal = (users, callback = null) => {\n    if (!users.length) {\n        // Nothing to do.\n        return Promise.resolve();\n    }\n    let titlePromise = null;\n    if (users.length == 1) {\n        titlePromise = get_string('sendbulkmessagesingle', 'core_message');\n    } else {\n        titlePromise = get_string('sendbulkmessage', 'core_message', users.length);\n    }\n\n    return ModalSaveCancel.create({\n        body: Templates.render('core_message/send_bulk_message', {}),\n        title: titlePromise,\n        show: true,\n        buttons: {\n            save: titlePromise,\n        },\n    })\n    .then(function(modal) {\n        // When the dialog is closed, perform the callback (if provided).\n        modal.getRoot().on(ModalEvents.hidden, function() {\n            if (callback) {\n                callback();\n            }\n            modal.getRoot().remove();\n        });\n\n        modal.getRoot().on(ModalEvents.save, function() {\n            let messageText = modal.getRoot().find('form textarea').val();\n            sendMessage(messageText, users);\n        });\n\n        return modal;\n    });\n};\n\n/**\n * Send a message to these users.\n *\n * @method sendMessage\n * @param {String} messageText\n * @param {Number[]} users\n * @returns {Promise}\n */\nexport const sendMessage = (messageText, users) => {\n    let messages = [];\n\n    users.forEach(user => {\n        messages.push({\n            touserid: user,\n            text: messageText\n        });\n    });\n\n    return Ajax.call([{\n        methodname: 'core_message_send_instant_messages',\n        args: {messages: messages}\n    }])[0]\n    .then(function(messageIds) {\n        if (messageIds.length == 1) {\n            return get_string('sendbulkmessagesentsingle', 'core_message');\n        } else {\n            return get_string('sendbulkmessagesent', 'core_message', messageIds.length);\n        }\n    })\n    .then(function(msg) {\n        Notification.addNotification({\n            message: msg,\n            type: \"success\"\n        });\n        return true;\n    })\n    .catch(Notification.exception);\n};\n"],"names":["users","callback","length","Promise","resolve","titlePromise","ModalSaveCancel","create","body","Templates","render","title","show","buttons","save","then","modal","getRoot","on","ModalEvents","hidden","remove","messageText","find","val","sendMessage","messages","forEach","user","push","touserid","text","Ajax","call","methodname","args","messageIds","msg","addNotification","message","type","catch","Notification","exception"],"mappings":";;;;;;;uXAqCyB,SAACA,WAAOC,gEAAW,SACnCD,MAAME,cAEAC,QAAQC,cAEfC,aAAe,YAEfA,aADgB,GAAhBL,MAAME,QACS,mBAAW,wBAAyB,iBAEpC,mBAAW,kBAAmB,eAAgBF,MAAME,QAGhEI,2BAAgBC,OAAO,CAC1BC,KAAMC,mBAAUC,OAAO,iCAAkC,IACzDC,MAAON,aACPO,MAAM,EACNC,QAAS,CACLC,KAAMT,gBAGbU,MAAK,SAASC,cAEXA,MAAMC,UAAUC,GAAGC,sBAAYC,QAAQ,WAC/BnB,UACAA,WAEJe,MAAMC,UAAUI,YAGpBL,MAAMC,UAAUC,GAAGC,sBAAYL,MAAM,eAC7BQ,YAAcN,MAAMC,UAAUM,KAAK,iBAAiBC,MACxDC,YAAYH,YAAatB,UAGtBgB,gBAYFS,YAAc,CAACH,YAAatB,aACjC0B,SAAW,UAEf1B,MAAM2B,SAAQC,OACVF,SAASG,KAAK,CACVC,SAAUF,KACVG,KAAMT,iBAIPU,cAAKC,KAAK,CAAC,CACdC,WAAY,qCACZC,KAAM,CAACT,SAAUA,aACjB,GACHX,MAAK,SAASqB,mBACc,GAArBA,WAAWlC,QACJ,mBAAW,4BAA6B,iBAExC,mBAAW,sBAAuB,eAAgBkC,WAAWlC,WAG3Ea,MAAK,SAASsB,kCACEC,gBAAgB,CACzBC,QAASF,IACTG,KAAM,aAEH,KAEVC,MAAMC,sBAAaC"}