123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- "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("<div class='confirmPasswordResult' style='35px'/>");
- 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('<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>');
- return false;
- } else {
- 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>');
- return true;
- }
- }
- });
- return PropertiesSignonTab;
- });
|