123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- "use strict";
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: Cognos Analytics
- * Copyright IBM Corp. 2017,2018
- * US Government Users Restricted Rights -
- * Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['underscore', 'bi/admin/common/slideout/BasePane', 'bi/admin/nls/StringResource', 'bi/admin/common/utils/AJAXUtils', 'bi/commons/ui/properties/PropertyUIControl', 'ba-react-admin/ba-react-admin.min'], function (_, BasePane, StringResource, AJAXUtils, PropertyUIControl, AdminReact) {
- 'use strict'; //NOSONAR: meant to be strict
- var AddOpenIdPane = BasePane.extend({
- /**
- * @constructor
- * @param options.$el - JQuery node to append the table HTML
- * @param options.items {object} - An array of tab metadata. Must provide name,
- * module, and objectInfo (containing all the basic properties of the object)
- */
- init: function init(options) {
- AddOpenIdPane.inherited('init', this, arguments);
- _.extend(this, options);
- this.title = StringResource.get('addUsers');
- },
- _getNewPropertyUIControl: function _getNewPropertyUIControl(options) {
- return new PropertyUIControl(options);
- },
- renderBody: function renderBody($body) {
- this._propertyUIControl = this._getNewPropertyUIControl({
- 'el': this.$el.find(".bi-admin-pane-body"),
- 'glassContext': this.glassContext,
- 'items': [{
- 'id': 'admin-user-email',
- 'name': 'userEmail',
- 'label': StringResource.get('camIdentity'),
- 'type': 'TextArea',
- 'multiline': false,
- 'editable': true,
- 'value': ""
- }, {
- 'id': 'admin-user-preferred-name',
- 'name': 'userPreferredName',
- 'label': StringResource.get('preferredName'),
- 'type': 'TextArea',
- 'multiline': false,
- 'editable': true,
- 'value': ""
- }, {
- 'name': 'footer',
- 'type': 'Footer',
- 'items': [{
- 'name': 'Add',
- 'type': 'Button',
- 'label': StringResource.get('add'),
- 'onSelect': this._addUser.bind(this),
- 'primary': true
- }, {
- 'name': 'cancel',
- 'type': 'Button',
- 'label': StringResource.get('cancel'),
- 'onSelect': this.close.bind(this)
- }]
- }]
- });
- return this._propertyUIControl.render();
- },
- _addUser: function _addUser() {
- var mp = this._propertyUIControl.getModifiedProperties();
- var userEmail = mp.userEmail;
- var userPreferredName = mp.userPreferredName;
- if (!this._validate(userEmail)) {
- return;
- }
- var payload = {
- 'camIdentity': userEmail,
- 'defaultName': userPreferredName
- };
- var options = {
- method: 'POST',
- contentType: 'application/json; charset=utf-8',
- data: JSON.stringify(payload),
- url: 'v1/users?pid=' + this.pid
- };
- this.glassContext.getCoreSvc('.Ajax').ajax(options).then(function (resp, a1, a2) {
- var sText = StringResource.get('userToastCreateMsg', {
- 'name': userEmail
- });
- this.glassContext.appController.showToast(sText, {
- type: 'success'
- });
- this._refreshAccountListPane();
- this._clearInputFields();
- }.bind(this), function (e) {
- this.glassContext.appController.showErrorMessage(e.jqXHR.responseJSON.messages.join('\n'), StringResource.get('error'));
- }.bind(this));
- },
- _validate: function _validate(userEmail) {
- if (!userEmail || userEmail.length === 0) {
- this.glassContext.appController.showErrorMessage(StringResource.get('uniqueIdentifierRequiredErrorMsg'), StringResource.get('error'));
- return false;
- }
- return true;
- },
- _refreshAccountListPane: function _refreshAccountListPane() {
- if (this.parentView.pagingEnabled) {
- AdminReact.PaginationHelper.reloadListViewinPagingContext(this.parentView.glassContext, this.parentView._accountExplorer, this.parentView.listView, this.parentView.listAdaptor, true);
- } else {
- this.parentView.listAdaptor.sortChanged = true;
- this.parentView.listView.reload(false);
- }
- ;
- this.close();
- },
- _clearInputFields: function _clearInputFields() {
- this._propertyUIControl.$el.find('#control_userEmail_admin-user-email').val('');
- this._propertyUIControl.$el.find('#control_userPreferredName_admin-user-preferred-name').val('');
- }
- });
- return AddOpenIdPane;
- });
|