PropertiesSignonTab.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. "use strict";
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: admin
  5. * Copyright IBM Corp. 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/content_apps/PropertiesTab', 'bi/admin/nls/StringResource'], function (_, PropertiesTab, StringResource) {
  10. 'use strict'; //NOSONAR: meant to be strict
  11. var PropertiesSignonTab = PropertiesTab.extend({
  12. init: function init(options) {
  13. PropertiesSignonTab.inherited('init', this, arguments);
  14. _.extend(this, options);
  15. this._id = _.uniqueId('prop_');
  16. },
  17. isEditable: function isEditable() {
  18. return this.objectInfo.permissions && this.objectInfo.permissions.indexOf("write") !== -1;
  19. },
  20. _getPropertyItems: function _getPropertyItems() {
  21. return [{
  22. 'name': 'credentialUserName',
  23. 'label': StringResource.get('userId'),
  24. 'value': this.objectInfo.credentialsEx.username,
  25. 'editable': this.isEditable(),
  26. 'type': 'SingleLineValue',
  27. 'onChange': function () {
  28. this.objectInfo.credentialsEx.password = '';
  29. this._oPropertyUIControl.getProperty('credentialPassword').setValue('');
  30. this._oPropertyUIControl.getProperty('confirmPassword').setValue('');
  31. }.bind(this)
  32. }, {
  33. 'name': 'credentialPassword',
  34. 'inputType': 'password',
  35. 'label': StringResource.get('password'),
  36. 'ariaLabel': StringResource.get('password'),
  37. 'value': this.objectInfo.credentialsEx.password,
  38. 'editable': true,
  39. 'type': 'SingleLineValue'
  40. }, {
  41. 'name': 'confirmPassword',
  42. 'inputType': 'password',
  43. 'label': StringResource.get('confirmPassword'),
  44. 'ariaLabel': StringResource.get('confirmPassword'),
  45. 'value': this.objectInfo.credentialsEx.password,
  46. 'editable': true,
  47. 'type': 'SingleLineValue'
  48. }];
  49. },
  50. render: function render() {
  51. return this.renderPropertyUIControl({
  52. 'el': this.$el,
  53. 'glassContext': this.glassContext,
  54. 'items': this._getPropertyItems()
  55. }).then(this._bindEvents.bind(this));
  56. },
  57. _bindEvents: function _bindEvents() {
  58. if (this.isEditable()) {
  59. var firstPass = this.$el.find("input[id*='credentialPassword']");
  60. var passEl = this.$el.find("input[id*='confirmPassword']");
  61. firstPass.on("focus", function () {
  62. firstPass[0].select();
  63. });
  64. passEl.on("focus", function () {
  65. passEl[0].select();
  66. }); //if we change the first password - going to clear the confirm password
  67. firstPass.on('keyup', function () {
  68. passEl.val('');
  69. this._oPropertyUIControl.getProperty('confirmPassword').setValue('');
  70. }.bind(this));
  71. var $addElem = this.getPropertyUIControl().$el.find(".containerUIControl");
  72. $addElem.append("<div class='confirmPasswordResult' style='35px'/>");
  73. passEl.on('input', function (evt) {
  74. if (this._comparePasswords(passEl, firstPass)) {
  75. var newUser = this._oPropertyUIControl.getProperty('credentialUserName');
  76. if (newUser.getModifiedProperties() && newUser.getModifiedProperties().credentialUserName) {
  77. this.objectInfo.newUser = newUser.getModifiedProperties().credentialUserName.toString().replace(/[^\u0000-\u007E]/g, '');
  78. } else {
  79. this.objectInfo.newUser = newUser.value;
  80. }
  81. this.objectInfo.newPassword = firstPass.val();
  82. this.slideout.$el.trigger("credentialChanged", this.objectInfo);
  83. var sText = StringResource.get('signonToastUpdateMsg', {
  84. 'name': this.objectInfo.defaultName
  85. });
  86. this.glassContext.appController.showToast(sText, {
  87. type: 'success'
  88. });
  89. }
  90. }.bind(this));
  91. }
  92. },
  93. _comparePasswords: function _comparePasswords(passEl, firstPass) {
  94. var confPassEl = this.$el.find(".confirmPasswordResult");
  95. if (firstPass.val() !== passEl.val()) {
  96. confPassEl.html('<div><svg class="bi-admin-signOn-svg svgIcon bi-admin-warning-svgIcon invalid"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#common-error"></use></svg></div><div class="signonTestFail">' + StringResource.get("passwordNotMatchError") + '</div>');
  97. return false;
  98. } else {
  99. confPassEl.html('<div><svg class="svgIcon bi-admin-icon-succeeded bi-admin-signOn-svg"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#common-success"></use></svg></div><div class="signonTestSuccess">' + StringResource.get("passwordsMatch") + '</div>');
  100. return true;
  101. }
  102. }
  103. });
  104. return PropertiesSignonTab;
  105. });