"use strict"; /** * Licensed Materials - Property of IBM * IBM Cognos Products: admin * Copyright IBM Corp. 2017 * US Government Users Restricted Rights - Use, duplication or disclosure * restricted by GSA ADP Schedule Contract with IBM Corp. */ define(['underscore', 'bi/content_apps/PropertiesTab', 'bi/admin/nls/StringResource'], function (_, PropertiesTab, StringResource) { 'use strict'; //NOSONAR: meant to be strict var PropertiesSignonTab = PropertiesTab.extend({ init: function init(options) { PropertiesSignonTab.inherited('init', this, arguments); _.extend(this, options); this._id = _.uniqueId('prop_'); }, isEditable: function isEditable() { return this.objectInfo.permissions && this.objectInfo.permissions.indexOf("write") !== -1; }, _getPropertyItems: function _getPropertyItems() { return [{ 'name': 'credentialUserName', 'label': StringResource.get('userId'), 'value': this.objectInfo.credentialsEx.username, 'editable': this.isEditable(), 'type': 'SingleLineValue', 'onChange': function () { this.objectInfo.credentialsEx.password = ''; this._oPropertyUIControl.getProperty('credentialPassword').setValue(''); this._oPropertyUIControl.getProperty('confirmPassword').setValue(''); }.bind(this) }, { 'name': 'credentialPassword', 'inputType': 'password', 'label': StringResource.get('password'), 'ariaLabel': StringResource.get('password'), 'value': this.objectInfo.credentialsEx.password, 'editable': true, 'type': 'SingleLineValue' }, { 'name': 'confirmPassword', 'inputType': 'password', 'label': StringResource.get('confirmPassword'), 'ariaLabel': StringResource.get('confirmPassword'), 'value': this.objectInfo.credentialsEx.password, 'editable': true, 'type': 'SingleLineValue' }]; }, render: function render() { return this.renderPropertyUIControl({ 'el': this.$el, 'glassContext': this.glassContext, 'items': this._getPropertyItems() }).then(this._bindEvents.bind(this)); }, _bindEvents: function _bindEvents() { if (this.isEditable()) { var firstPass = this.$el.find("input[id*='credentialPassword']"); var passEl = this.$el.find("input[id*='confirmPassword']"); firstPass.on("focus", function () { firstPass[0].select(); }); passEl.on("focus", function () { passEl[0].select(); }); //if we change the first password - going to clear the confirm password firstPass.on('keyup', function () { passEl.val(''); this._oPropertyUIControl.getProperty('confirmPassword').setValue(''); }.bind(this)); var $addElem = this.getPropertyUIControl().$el.find(".containerUIControl"); $addElem.append("
"); passEl.on('input', function (evt) { if (this._comparePasswords(passEl, firstPass)) { var newUser = this._oPropertyUIControl.getProperty('credentialUserName'); if (newUser.getModifiedProperties() && newUser.getModifiedProperties().credentialUserName) { this.objectInfo.newUser = newUser.getModifiedProperties().credentialUserName.toString().replace(/[^\u0000-\u007E]/g, ''); } else { this.objectInfo.newUser = newUser.value; } this.objectInfo.newPassword = firstPass.val(); this.slideout.$el.trigger("credentialChanged", this.objectInfo); var sText = StringResource.get('signonToastUpdateMsg', { 'name': this.objectInfo.defaultName }); this.glassContext.appController.showToast(sText, { type: 'success' }); } }.bind(this)); } }, _comparePasswords: function _comparePasswords(passEl, firstPass) { var confPassEl = this.$el.find(".confirmPasswordResult"); if (firstPass.val() !== passEl.val()) { confPassEl.html('