SetLanguages.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. "use strict";
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: Cognos Analytics
  5. * Copyright IBM Corp. 2017
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define(['react', 'react-dom', 'underscore', 'bi/admin/nls/StringResource', 'bacontentnav/common/ContentListPageView', 'ba-react-admin/ba-react-admin.min', 'jquery'], function (React, ReactDOM, _, StringResource, ContentView, AdminReact, $) {
  9. 'use strict'; //NOSONAR
  10. var SetLanguagesView = ContentView.extend({
  11. init: function init(options) {
  12. SetLanguagesView.inherited('init', this, arguments);
  13. _.extend(this, options);
  14. this._modified = false;
  15. this._orgValues = $.extend({}, this.values);
  16. },
  17. render: function render() {
  18. this.$el.empty();
  19. return this._getSupportedContentLocales().then(function () {
  20. this.$el.css('height', '100%');
  21. var valuesArray = [],
  22. item;
  23. for (item in this.values) {
  24. valuesArray.push({
  25. locale: item,
  26. value: this.values[item]
  27. });
  28. }
  29. ReactDOM.render(React.createElement(AdminReact.SetLanguagesPane, {
  30. values: valuesArray,
  31. supportedContentLocales: this._supportedContentLocales,
  32. width: this.slideout.width,
  33. saveCallback: this._saveCallback.bind(this),
  34. cancelCallback: this._cancelCallback.bind(this),
  35. el: this.$el,
  36. StringResource: StringResource
  37. }), this.$el[0]);
  38. }.bind(this));
  39. },
  40. _getSupportedContentLocales: function _getSupportedContentLocales() {
  41. return this.glassContext.services.fetch.get('v1/configuration/keys/supportedContentLocales_' + this.glassContext.services.userProfile.preferences.productLocale).then(function (response) {
  42. this._supportedContentLocales = [];
  43. _.map(JSON.parse(response.data['supportedContentLocales_' + this.glassContext.services.userProfile.preferences.productLocale]), function (value, key) {
  44. this._supportedContentLocales.push({
  45. 'icon': '',
  46. 'label': value,
  47. 'key': key,
  48. 'value': value,
  49. 'group': key
  50. });
  51. }.bind(this));
  52. this._supportedContentLocales = _.sortBy(this._supportedContentLocales, function (locale) {
  53. return locale.label;
  54. });
  55. return Promise.resolve(true);
  56. }.bind(this));
  57. },
  58. _saveCallback: function _saveCallback(values) {
  59. this.values = {};
  60. var length = values.length;
  61. for (var i = 0; i < length; i++) {
  62. if (values[i].value !== '') {
  63. this.values[values[i].locale] = values[i].value;
  64. }
  65. }
  66. if (this.saveCallback) {
  67. this.saveCallback(this.values);
  68. this.slideout.hide();
  69. }
  70. },
  71. _cancelCallback: function _cancelCallback() {
  72. this.slideout.hide();
  73. },
  74. _deleteCallBack: function _deleteCallBack(index) {
  75. this.valuesArray.splice(index, 1);
  76. }
  77. });
  78. return SetLanguagesView;
  79. });