message/amd/src/message_drawer_view_contact.js

  1. // This file is part of Moodle - http://moodle.org/
  2. //
  3. // Moodle is free software: you can redistribute it and/or modify
  4. // it under the terms of the GNU General Public License as published by
  5. // the Free Software Foundation, either version 3 of the License, or
  6. // (at your option) any later version.
  7. //
  8. // Moodle is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  15. /**
  16. * Controls the contact page in the message drawer.
  17. *
  18. * @module core_message/message_drawer_view_contact
  19. * @copyright 2018 Ryan Wyllie <ryan@moodle.com>
  20. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  21. */
  22. define(
  23. [
  24. 'jquery',
  25. 'core/str',
  26. 'core/templates'
  27. ],
  28. function(
  29. $,
  30. Str,
  31. Templates
  32. ) {
  33. var SELECTORS = {
  34. CONTENT_CONTAINER: '[data-region="content-container"]'
  35. };
  36. var TEMPLATES = {
  37. CONTENT: 'core_message/message_drawer_view_contact_body_content'
  38. };
  39. /**
  40. * Get the content container of the contact view container.
  41. *
  42. * @param {Object} root Contact container element.
  43. * @returns {Object} jQuery object
  44. */
  45. var getContentContainer = function(root) {
  46. return root.find(SELECTORS.CONTENT_CONTAINER);
  47. };
  48. /**
  49. * Render the contact profile in the content container.
  50. *
  51. * @param {Object} root Contact container element.
  52. * @param {Object} profile Contact profile details.
  53. * @returns {Object} jQuery promise
  54. */
  55. var render = function(root, profile) {
  56. return Templates.render(TEMPLATES.CONTENT, profile)
  57. .then(function(html) {
  58. getContentContainer(root).append(html);
  59. return html;
  60. });
  61. };
  62. /**
  63. * Setup the contact page.
  64. *
  65. * @param {string} namespace The route namespace.
  66. * @param {Object} header Contact header element.
  67. * @param {Object} body Contact body container element.
  68. * @param {Object} footer Contact footer container element.
  69. * @param {Object} contact The contact object.
  70. * @returns {Object} jQuery promise
  71. */
  72. var show = function(namespace, header, body, footer, contact) {
  73. var root = $(body);
  74. getContentContainer(root).empty();
  75. return render(root, contact);
  76. };
  77. /**
  78. * String describing this page used for aria-labels.
  79. *
  80. * @param {Object} root Contact container element.
  81. * @param {Object} contact The contact object.
  82. * @return {Object} jQuery promise
  83. */
  84. var description = function(root, contact) {
  85. return Str.get_string('messagedrawerviewcontact', 'core_message', contact.fullname);
  86. };
  87. return {
  88. show: show,
  89. description: description
  90. };
  91. });