APIs

Show:
  1. /**
  2. * @namespace flexygo.ui.wc
  3. */
  4. var flexygo;
  5. (function (flexygo) {
  6. var ui;
  7. (function (ui) {
  8. var wc;
  9. (function (wc) {
  10. /**
  11. * Library for the FlxMailNotificationElement web component.
  12. *
  13. * @class FlxMailNotificationElement
  14. * @constructor
  15. * @return {FlxMailNotificationElement}
  16. */
  17. class FlxMailNotificationElement extends HTMLElement {
  18. constructor() {
  19. super();
  20. }
  21. /**
  22. * Fires when element is attached to DOM
  23. * @method connectedCallback
  24. */
  25. connectedCallback() {
  26. this.init();
  27. }
  28. /**
  29. * Fires when element is detached to DOM
  30. * @method disconnectedCallback
  31. */
  32. disconnectedCallback() {
  33. //Remove event handler
  34. flexygo.events.off(this, 'push', 'notify', function (e) {
  35. if (e.masterIdentity == 'updateMailNotice' && typeof e.sender['pendingMails'] != 'undefined') {
  36. this.updateBadge(e.sender.pendingMails, true);
  37. }
  38. });
  39. }
  40. /**
  41. * Monitor the list of observed attribute for changes.
  42. * @property observedAttributes
  43. */
  44. static get observedAttributes() {
  45. return [];
  46. }
  47. /**
  48. * Fires when the attribute value of the element is changed.
  49. * @method attributeChangedCallback
  50. */
  51. attributeChangedCallback(attrName, oldVal, newVal) {
  52. }
  53. /**
  54. * Initialize Web Control
  55. * @method init
  56. */
  57. init() {
  58. this.refresh();
  59. flexygo.events.on(this, 'push', 'notify', function (e) {
  60. if (e.masterIdentity == 'updateMailNotice' && typeof e.sender['pendingMails'] != 'undefined') {
  61. this.updateBadge(e.sender.pendingMails, true);
  62. }
  63. });
  64. }
  65. /**
  66. * Refreses Web Control
  67. * @method refresh
  68. */
  69. refresh() {
  70. let ctx = $(this);
  71. let notySpan = $('<span class="notify-dropdown"> <i class="flx-icon icon-mail-2 "></i> <b id="notifyMails" class="badge bounceIn animated"></b> </span>');
  72. ctx.append(notySpan);
  73. if (flexygo.utils.isSizeMobile()) {
  74. notySpan.on('click', () => {
  75. flexygo.nav.openPageName('syspage-notify', 'sysNotices', '', null, 'current', false, null);
  76. });
  77. }
  78. else {
  79. let tooltip = '<flx-tooltip container="body" mode="popover" placement="bottom"><div class="notifypopover"><flx-list objectname="sysNotices" objectwhere="" templateId="sysNotiFyListPopup"></flx-list></div></flx-tooltip>';
  80. ctx.prepend(tooltip);
  81. }
  82. this.refreshBadge();
  83. }
  84. // /**
  85. //* Navigates to notify node specification
  86. //* @method goToNotice
  87. //*/
  88. // goToNotice(elm, noticeId) {
  89. // let params: flexygo.api.Notify.NotifyParams = {
  90. // NoticeId: noticeId
  91. // }
  92. // flexygo.ajax.post('~/api/Notify', 'GetNotice', params, (response: string) => {
  93. // if (response) {
  94. // let lfnav = new flexygo.ui.wc.FlxNavElement();
  95. // var itemClick: Function = new Function(lfnav.getTreeNavigate(<flexygo.api.navigation.LoweredNavigationNode>flexygo.utils.lowerKeys(response)))
  96. // itemClick.call(elm);
  97. // }
  98. // })
  99. // }
  100. /**
  101. * Checks and refresh Notify Badge
  102. * @method refreshBadge
  103. */
  104. refreshBadge() {
  105. if ($('#notifyBadge')) {
  106. flexygo.ajax.post('~/api/Notify', 'GetMailBadgeValue', null, (response) => {
  107. this.updateBadge(response, false);
  108. });
  109. }
  110. }
  111. /**
  112. * Refreshes Notify Badge
  113. * @method updateBadge
  114. * @param {number} pendingMails - Number of pending mails
  115. * @param {boolean} sound - Reproduces sound or not.
  116. */
  117. updateBadge(pendingMails, sound) {
  118. var currentMails = $('#notifyMails').html();
  119. if (!currentMails || currentMails == '') {
  120. currentMails = '0';
  121. }
  122. if (pendingMails > parseInt(currentMails)) {
  123. var snd = new Audio(flexygo.utils.resolveUrl('~/js/plugins/lobibox-master/sounds/sound1.ogg'));
  124. if (!flexygo.utils.testMode) {
  125. snd.play();
  126. }
  127. }
  128. if (pendingMails == 0) {
  129. $('#notifyMails').html('');
  130. }
  131. else {
  132. $('#notifyMails').html(pendingMails.toString());
  133. }
  134. }
  135. }
  136. wc.FlxMailNotificationElement = FlxMailNotificationElement;
  137. })(wc = ui.wc || (ui.wc = {}));
  138. })(ui = flexygo.ui || (flexygo.ui = {}));
  139. })(flexygo || (flexygo = {}));
  140. window.customElements.define('flx-mailnotification', flexygo.ui.wc.FlxMailNotificationElement);
  141. //# sourceMappingURL=flx-mailnoification.js.map