RestoreTab.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. "use strict";
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: admin
  5. * Copyright IBM Corp. 2015, 2017
  6. * US Government Users Restricted Rights - Use, duplication or disclosure
  7. * restricted by GSA ADP Schedule Contract with IBM Corp.
  8. */
  9. 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) {
  10. 'use strict'; //NOSONAR: meant to be strict
  11. var RestoreTab = View.extend({
  12. init: function init(options) {
  13. RestoreTab.inherited('init', this, arguments);
  14. _.extend(this, options);
  15. },
  16. render: function render() {
  17. this.$el.html(dot.template(template)({
  18. strings: {
  19. typePassToRestore: StringResource.get('typePassToRestore'),
  20. accessDenied: StringResource.get('accessDenied'),
  21. restoreInformationLabel: StringResource.get('restoreInformationLabel'),
  22. restoreBtn: StringResource.get('restoreBtn')
  23. }
  24. }));
  25. var elList = this.$el.find('#restoreList');
  26. elList.empty();
  27. this.listView = this._getNewListView({
  28. el: elList,
  29. glassContext: this.glassContext,
  30. contentView: this
  31. });
  32. return this.listView.render().then(function () {
  33. this.listView.widgetKeyController = this._getNewWidgetNavigator({
  34. $el: this.$el.find(".listControl"),
  35. focusClass: "contentListFocusable",
  36. fCallBack: this.listView._processRowForMoreDataLoad.bind(this.listView)
  37. });
  38. this._bindEvents();
  39. }.bind(this));
  40. },
  41. _getNewListView: function _getNewListView(options) {
  42. return new ListView(options);
  43. },
  44. getAncestors: function getAncestors() {
  45. return null;
  46. },
  47. _bindEvents: function _bindEvents() {
  48. this.$el.find('#restoreBtn').on('primaryaction', this._restoreAction.bind(this));
  49. this.$el.find("[required]").on('keyup', function (e) {
  50. $(e.target.parentNode).find(".invalid").remove();
  51. });
  52. },
  53. _restoreAction: function _restoreAction() {
  54. this.$el.find(".invalid").remove();
  55. this.glassContext.appController.showToast(StringResource.get('restoreInprogress'), {
  56. 'type': 'info',
  57. 'timeOut': 3000
  58. });
  59. var restoreData = {
  60. password: this.$el.find('#restorePwd').val(),
  61. type: 'import',
  62. packageName: this.listView.getSelectedBackupName()
  63. };
  64. return Api.generateExportImportDefinition('imports', restoreData).then(function (response) {
  65. restoreData = response;
  66. return Api.executeExportImportDefinition('imports', restoreData.id);
  67. }.bind(this)).then(function () {
  68. var dfd = $.Deferred();
  69. var isToastShowed = false;
  70. var int;
  71. var func = function () {
  72. Api.queryStatus('imports', restoreData.id).then(function (data) {
  73. var restoreStatus = data.status[0].status.toLowerCase();
  74. if (_.indexOf(['succeeded', 'failed'], restoreStatus) !== -1 && !isToastShowed) {
  75. isToastShowed = true;
  76. clearInterval(int);
  77. var msgKey, type;
  78. if (restoreStatus === 'succeeded') {
  79. msgKey = 'restoreSucceeded';
  80. type = 'success';
  81. } else {
  82. msgKey = 'restoreFailed';
  83. type = 'error';
  84. }
  85. this.glassContext.appController.showToast(StringResource.get(msgKey, {
  86. 'name': data.packageName
  87. }), {
  88. 'type': type,
  89. 'timeOut': 3000
  90. });
  91. this.parentView.hide();
  92. }
  93. }.bind(this)).then(dfd.resolve, dfd.reject);
  94. }.bind(this);
  95. int = setInterval(func, 2000);
  96. return dfd.promise();
  97. }.bind(this)).fail(function (dfd, jqXHR) {
  98. this.logger.error(jqXHR);
  99. if (jqXHR.responseJSON.errors[0] && jqXHR.responseJSON.errors[0].message) {
  100. this.glassContext.appController.showErrorMessage(jqXHR.responseJSON.errors[0].message, StringResource.get('error'));
  101. }
  102. }.bind(this));
  103. },
  104. _getNewWidgetNavigator: function _getNewWidgetNavigator(options) {
  105. return new WidgetNavigator(options);
  106. }
  107. });
  108. return RestoreTab;
  109. });