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 FlxNotificationElement web component.
  12. *
  13. * @class FlxNotificationElement
  14. * @constructor
  15. * @return {FlxNotificationElement}
  16. */
  17. class FlxNotificationElement 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 == 'updateBadgeNotice' && typeof e.sender['pendingNotices'] != 'undefined') {
  36. this.updateBadge(e.sender.pendingNotices, 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 == 'updateBadgeNotice' && typeof e.sender['pendingNotices'] != 'undefined') {
  61. this.updateBadge(e.sender.pendingNotices, 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-bell-2 "></i> <b id="notifyBadge" 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 = {
  90. NoticeId: noticeId
  91. };
  92. flexygo.ajax.post('~/api/Notify', 'GetNotice', params, (response) => {
  93. if (response) {
  94. let lfnav = new flexygo.ui.wc.FlxNavElement();
  95. var itemClick = new Function(lfnav.getTreeNavigate(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', 'GetBadgeValue', null, (response) => {
  107. this.updateBadge(response, false);
  108. });
  109. }
  110. }
  111. /**
  112. * Refereshes Notify Badge
  113. * @method updateBadge
  114. * @param {number} pendingNotices - Number of pending notices
  115. * @param {boolean} sound - Reproduces sound or not.
  116. */
  117. updateBadge(pendingNotices, sound) {
  118. var currentNotices = $('#notifyBadge').html();
  119. if (!currentNotices || currentNotices == '') {
  120. currentNotices = '0';
  121. }
  122. if (pendingNotices > parseInt(currentNotices)) {
  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 (pendingNotices == 0) {
  129. $('#notifyBadge').html('');
  130. }
  131. else {
  132. $('#notifyBadge').html(pendingNotices.toString());
  133. }
  134. }
  135. /**
  136. * Marks a notification has been read
  137. * @method markAsRead
  138. */
  139. markAsRead(elm, noticeId) {
  140. let ni = noticeId;
  141. let params = {
  142. NoticeId: noticeId
  143. };
  144. flexygo.ajax.post('~/api/Notify', 'SetNoticeIsRead', params, (response) => {
  145. if (response) {
  146. if (ni) {
  147. $(elm).closest('.active').removeClass('active');
  148. }
  149. else {
  150. $(elm).closest('.notifypopover').find('.active').removeClass('active');
  151. }
  152. }
  153. this.refreshBadge();
  154. });
  155. }
  156. }
  157. wc.FlxNotificationElement = FlxNotificationElement;
  158. })(wc = ui.wc || (ui.wc = {}));
  159. })(ui = flexygo.ui || (flexygo.ui = {}));
  160. })(flexygo || (flexygo = {}));
  161. window.customElements.define('flx-notification', flexygo.ui.wc.FlxNotificationElement);
  162. //# sourceMappingURL=flx-notification.js.map