"use strict"; /** * Licensed Materials - Property of IBM * IBM Cognos Products: Cognos Analytics * Copyright IBM Corp. 2015, 2016 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ define(['jquery', 'doT', 'underscore', 'bi/admin/common/ui/WidgetView', 'bi/commons/utils/Utils', 'bi/admin/nls/StringResource', 'text!bi/admin/common/ui/testflow/templates/TestFlowTemplate.html'], function ($, dot, _, WidgetView, Utils, StringResource, template) { 'use strict'; //NOSONAR: meant to be strict var TestFlowStates = { 'INIT': 'init', 'TESTING': 'testing', 'CANCELED': 'canceled', 'FAILED': 'failed', 'SUCCESS': 'success' }; var TestFlow = WidgetView.extend({ widgetName: 'testflow', state: TestFlowStates.INIT, times: 0, init: function init(options) { TestFlow.inherited('init', this, arguments); var query = '[data-bi-testflow]'; if (this.element.is(query)) { this._create(); this._initEvents(); this._updateUIState(true); } }, _create: function _create() { var tempInfo = { strings: { test: StringResource.get('test'), testing: StringResource.get('testing'), cancel: StringResource.get('cancel'), canceled: StringResource.get('canceled'), failed: StringResource.get('testingFailed'), success: StringResource.get('success'), retry: StringResource.get('retry') } }; var sHtml = dot.template(template)(tempInfo); this.$el.append(sHtml); var $workingIndicator = $(Utils.getLoadingAnimation(1)); $workingIndicator.addClass('loginWorking'); this.$el.find('#indicator').append($workingIndicator[0]); }, _updateTimes: function _updateTimes() { if (this.state === TestFlowStates.TESTING) { this.$el.find('#times').text("(" + this.times++ + ")"); window.setTimeout(function () { this._updateTimes(); }.bind(this), 1000); } else { this.times = 0; } }, _initEvents: function _initEvents() { this.$el.find('#test').on('primaryaction', function () { this.trigger('startTest'); }.bind(this)); this.$el.find('#cancel').on('primaryaction', function () { this.trigger('cancel'); }.bind(this)); this.$el.find('#retry').on('primaryaction', function () { this.trigger('startTest'); }.bind(this)); this.$el.find('#more').on('primaryaction', function (e) { this._toggleDetail($(e.target)); }.bind(this)); }, _toggleDetail: function _toggleDetail() { var hasShow = this.$el.hasClass('showdetail'); var hasHide = this.$el.hasClass('hidedetail'); if (!hasShow && !hasHide) { this.$el.addClass('showdetail'); } else { if (hasShow) { this.$el.removeClass('showdetail'); this.$el.addClass('hidedetail'); } else { if (hasHide) { this.$el.removeClass('hidedetail'); this.$el.addClass('showdetail'); } } } }, _renderMessages: function _renderMessages(messages) { var $primText = this.$el.find('#primaryText'); $primText.text(''); var $detail = this.$el.find('#detail'); $detail.empty(); this.$el.addClass('nodetail'); if (_.isArray(messages) && !_.isEmpty(messages)) { var pt = _.first(messages) || StringResource.get('unknown'); $primText.text(pt); var detail = _.rest(messages, 1); var sHtml = ""; _.each(detail, function (msg) { sHtml = sHtml + "