1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- 'use strict';
- /**
- * Licensed Materials - Property of IBM IBM Cognos Products: BI Cloud (C)
- *
- * Copyright IBM Corp. 2016, 2019
- *
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['../../../lib/@waca/core-client/js/core-client/ui/core/View', 'jquery', 'underscore', 'text!./templates/RefreshTimerIndicator.html', '../../../widgets/livewidget/nls/StringResources', '../../../lib/@waca/dashboard-common/dist/utils/Flyout', '../../../lib/@waca/core-client/js/core-client/utils/Utils'], function (View, $, _, template, resources, Flyout, Utils) {
- /**
- * Class to set refresh time interval.
- * Possible values are in seconds, minutes and hours.
- */
- var RefreshTimerIndicator = View.extend({
- templateString: template,
- /**
- * @classdesc The timer icon associated with a widget.
- * @constructs
- * @public
- * @param {Boolean} antoRefresh - the flag of auto refresh on or off.
- * @param {String} unit - the unit of the timer.
- * @param {Number} value - the value of the timer.
- *
- */
- init: function init(ownerWidget) {
- this.ownerWidget = ownerWidget;
- var queryRefreshInfo = ownerWidget.get('queryRefresh');
- var spec = queryRefreshInfo ? queryRefreshInfo : { autoRefresh: false };
- _.extend(this, spec);
- RefreshTimerIndicator.inherited('init', this, spec);
- if (this.$icon) {
- this.$icon.remove();
- }
- this.ariaLabel = resources.get('widgetTimer');
- this.title = resources.get('widgetTimer');
- this.clockIcon = this.ownerWidget.dashboardApi.getFeature('Icons').getIcon('common-clock-time').id;
- this.$icon = $(this.dotTemplate(this));
- },
- initEvents: function initEvents() {
- var _onClick = this._onClick.bind(this);
- this.$icon.on('mousedown tap keydown mouseup', _onClick);
- },
- remove: function remove() {
- this.$icon && this.$icon.off();
- this.$icon = null;
- RefreshTimerIndicator.inherited('remove', this, arguments);
- },
- _onClick: function _onClick(evt) {
- //some ancestor nodes were handling the 'mouseup' event causing unexpected behaviour (see 108341)
- if (evt.type === 'mouseup') {
- evt.stopPropagation();
- return;
- }
- if (evt.keyCode && evt.keyCode !== 13) {
- // Keypress and it is not enter.. ignore
- return;
- }
- if (evt.gesture) {
- // prevent the virtual click event from firing. Otherwise this method will be called twice.
- evt.gesture.preventDefault();
- }
- if (this.ownerWidget) {
- var lastRefreshed = this.ownerWidget.get('queryRefresh').lastRefreshed;
- var refreshedDuration = new Date().getTime() - lastRefreshed;
- var formatedDuration = resources.get('lastRefresh', { timeInterval: Utils.formatDuration(refreshedDuration) });
- if (!this.flyout) {
- this.flyout = new Flyout({
- container: document.body,
- selector: this.$icon,
- viewInstance: $('<div>' + formatedDuration + '</div>')
- });
- } else {
- this.flyout.view.empty();
- this.flyout.view.html(formatedDuration);
- }
- this.flyout.open(this.$icon);
- }
- evt.stopPropagation();
- }
- });
- return RefreshTimerIndicator;
- });
- //# sourceMappingURL=RefreshTimerIndicator.js.map
|