ErrorView.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. "use strict";
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: admin
  5. * Copyright IBM Corp. 2016, 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', 'bi/commons/ui/View', 'jquery', 'text!bi/admin/common/templates/ErrorViewTemplate.html', 'bi/admin/nls/StringResource'], function (_, BaseView, $, template, StringResource) {
  10. /**
  11. * Error view. This class renders a view with a list of errors.
  12. * @param - options
  13. * {
  14. * errorList: Array of error objects
  15. * }
  16. */
  17. var ErrorView = BaseView.extend({
  18. templateString: template,
  19. events: {},
  20. displayObject: {
  21. errorList: []
  22. },
  23. errorIcons: {
  24. 'ERROR': '#common-failed',
  25. 'WARNING': '#common-warning',
  26. 'INFO': '#common-error'
  27. },
  28. errorIconClass: {
  29. 'ERROR': 'failed',
  30. 'WARNING': 'warning',
  31. 'INFO': 'info'
  32. },
  33. errorIconsTitleMap: {
  34. 'ERROR': 'Error',
  35. 'WARNING': 'Warning',
  36. 'INFO': 'Information'
  37. },
  38. init: function init(options) {
  39. ErrorView.inherited('init', this, arguments);
  40. $.extend(this, options);
  41. this.displayObject.errorList = _.map(options.displayMsgList, function (errorItem) {
  42. return {
  43. severity: errorItem.severity,
  44. msg: errorItem.message,
  45. msgDetail: errorItem.messageDetail,
  46. errorIcon: this.errorIcons[errorItem.severity],
  47. errorIconClass: 'simple-dialog-view-severity-' + this.errorIconClass[errorItem.severity],
  48. severityIconTitle: StringResource.get(this.errorIconsTitleMap[errorItem.severity])
  49. };
  50. }.bind(this));
  51. },
  52. render: function render() {
  53. this.$el.empty();
  54. var sHtml = this.dotTemplate({
  55. displayObject: this.displayObject
  56. });
  57. this.$el.append(sHtml);
  58. this._bindEvents();
  59. },
  60. _bindEvents: function _bindEvents() {
  61. var errorEls = this.$el.find('.simple-dialog-item-header');
  62. errorEls.on('primaryaction', function (e) {
  63. var errorDetailsEl = $(e.target).closest('.simple-dialog-item-header').siblings('.error-view-details');
  64. if (errorDetailsEl && errorDetailsEl.is(':visible')) {
  65. errorDetailsEl.hide(100);
  66. } else {
  67. errorDetailsEl.show(100);
  68. }
  69. });
  70. }
  71. });
  72. return ErrorView;
  73. });