123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- "use strict";
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: admin
- * Copyright IBM Corp. 2015, 2017
- * US Government Users Restricted Rights - Use, duplication or disclosure
- * restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['underscore', 'doT', 'bi/glass/app/ContentView', 'bi/admin/nls/StringResource', 'text!bi/admin/system/templates/RestoreTabTemplate.html', 'bi/admin/system/BackupList', 'bi/admin/system/services/ApiSvc', 'bacontentnav/utils/WidgetNavigator'], function (_, dot, View, StringResource, template, ListView, Api, WidgetNavigator) {
- 'use strict'; //NOSONAR: meant to be strict
- var RestoreTab = View.extend({
- init: function init(options) {
- RestoreTab.inherited('init', this, arguments);
- _.extend(this, options);
- },
- render: function render() {
- this.$el.html(dot.template(template)({
- strings: {
- typePassToRestore: StringResource.get('typePassToRestore'),
- accessDenied: StringResource.get('accessDenied'),
- restoreInformationLabel: StringResource.get('restoreInformationLabel'),
- restoreBtn: StringResource.get('restoreBtn')
- }
- }));
- var elList = this.$el.find('#restoreList');
- elList.empty();
- this.listView = this._getNewListView({
- el: elList,
- glassContext: this.glassContext,
- contentView: this
- });
- return this.listView.render().then(function () {
- this.listView.widgetKeyController = this._getNewWidgetNavigator({
- $el: this.$el.find(".listControl"),
- focusClass: "contentListFocusable",
- fCallBack: this.listView._processRowForMoreDataLoad.bind(this.listView)
- });
- this._bindEvents();
- }.bind(this));
- },
- _getNewListView: function _getNewListView(options) {
- return new ListView(options);
- },
- getAncestors: function getAncestors() {
- return null;
- },
- _bindEvents: function _bindEvents() {
- this.$el.find('#restoreBtn').on('primaryaction', this._restoreAction.bind(this));
- this.$el.find("[required]").on('keyup', function (e) {
- $(e.target.parentNode).find(".invalid").remove();
- });
- },
- _restoreAction: function _restoreAction() {
- this.$el.find(".invalid").remove();
- this.glassContext.appController.showToast(StringResource.get('restoreInprogress'), {
- 'type': 'info',
- 'timeOut': 3000
- });
- var restoreData = {
- password: this.$el.find('#restorePwd').val(),
- type: 'import',
- packageName: this.listView.getSelectedBackupName()
- };
- return Api.generateExportImportDefinition('imports', restoreData).then(function (response) {
- restoreData = response;
- return Api.executeExportImportDefinition('imports', restoreData.id);
- }.bind(this)).then(function () {
- var dfd = $.Deferred();
- var isToastShowed = false;
- var int;
- var func = function () {
- Api.queryStatus('imports', restoreData.id).then(function (data) {
- var restoreStatus = data.status[0].status.toLowerCase();
- if (_.indexOf(['succeeded', 'failed'], restoreStatus) !== -1 && !isToastShowed) {
- isToastShowed = true;
- clearInterval(int);
- var msgKey, type;
- if (restoreStatus === 'succeeded') {
- msgKey = 'restoreSucceeded';
- type = 'success';
- } else {
- msgKey = 'restoreFailed';
- type = 'error';
- }
- this.glassContext.appController.showToast(StringResource.get(msgKey, {
- 'name': data.packageName
- }), {
- 'type': type,
- 'timeOut': 3000
- });
- this.parentView.hide();
- }
- }.bind(this)).then(dfd.resolve, dfd.reject);
- }.bind(this);
- int = setInterval(func, 2000);
- return dfd.promise();
- }.bind(this)).fail(function (dfd, jqXHR) {
- this.logger.error(jqXHR);
- if (jqXHR.responseJSON.errors[0] && jqXHR.responseJSON.errors[0].message) {
- this.glassContext.appController.showErrorMessage(jqXHR.responseJSON.errors[0].message, StringResource.get('error'));
- }
- }.bind(this));
- },
- _getNewWidgetNavigator: function _getNewWidgetNavigator(options) {
- return new WidgetNavigator(options);
- }
- });
- return RestoreTab;
- });
|