Source: components/modals/service.js

  1. define('application/components/modals/service', [
  2. 'application/components/modals/error',
  3. 'application/managers/halo',
  4. 'rofl/lib/l10n',
  5. 'antie/runtimecontext',
  6. 'rofl/lib/utils'
  7. ], function (
  8. Error,
  9. HaloManager,
  10. L10N,
  11. RuntimeContext,
  12. Utils
  13. ) {
  14. 'use strict';
  15. var application = RuntimeContext.getCurrentApplication(),
  16. halo = HaloManager.getInstance();
  17. return Error.extend({
  18. /**
  19. * Initialises the modal.
  20. */
  21. init: function init () {
  22. init.base.call(this);
  23. this._onBlurBound = Utils.bind(this.onBlur, this);
  24. },
  25. /**
  26. * BeforeShow event.
  27. *
  28. * @param {Object} e - The event data.
  29. */
  30. onBeforeShow: function onBeforeShow (e) {
  31. e.args = {
  32. fullscreen: false,
  33. title: halo.getServiceTitle(),
  34. text: halo.getServiceText(),
  35. button: [{
  36. id: 'error-close-button',
  37. label: L10N.getInstance().get('servicemessage.button')
  38. }],
  39. okButton: true,
  40. callback: function () {
  41. if (application.getComponent('detail').outputElement.style.display === 'block') {
  42. application.getComponent('detail').focus();
  43. application.getComponent('detail').getChildWidget(0).focus();
  44. } else {
  45. application.getComponent('main').focus();
  46. application.getComponent('main').getChildWidget(0).focus();
  47. }
  48. }
  49. };
  50. this._preventBlur = true;
  51. this.addEventListener('blur', this._onBlurBound);
  52. onBeforeShow.base.call(this, e);
  53. },
  54. /**
  55. * BeforeHide event.
  56. */
  57. onBeforeHide: function () {
  58. this.removeEventListener('blur', this._onBlurBound);
  59. },
  60. /**
  61. * Blur event.
  62. *
  63. * @param {Object} e - The event data.
  64. */
  65. onBlur: function (e) {
  66. var self = this;
  67. if (this._preventBlur) {
  68. e.preventDefault();
  69. e.stopPropagation();
  70. setTimeout(function () {
  71. self._buttonsList.getChildWidgetByIndex(0).focus();
  72. }, 0);
  73. }
  74. },
  75. /**
  76. * Closes the modal.
  77. *
  78. * @private
  79. */
  80. _onClose: function _onClose () {
  81. this._preventBlur = false;
  82. _onClose.base.call(this);
  83. }
  84. });
  85. });