/** sap.m */ import Button from 'sap/m/Button'; import type Dialog from 'sap/m/Dialog'; /** sap.ui.core */ import type UI5Element from 'sap/ui/core/Element'; /** sap.ui.base */ import type Event from 'sap/ui/base/Event'; /** sap.ui.model */ import JSONModel from 'sap/ui/model/json/JSONModel'; /** sap.ui.rta */ import type RuntimeAuthoring from 'sap/ui/rta/RuntimeAuthoring'; import { getResourceModel, getTextBundle, TextBundle } from '../../i18n.js'; import CommandExecutor from '../command-executor.js'; import BaseDialog from './BaseDialog.controller.js'; import { QuickActionTelemetryData } from '../../cpe/quick-actions/quick-action-definition.js'; import { MessageBarType, setApplicationRequiresReload } from '@sap-ux-private/control-property-editor-common'; import { CommunicationService } from '../../cpe/communication-service.js'; import FlexCommand from 'sap/ui/rta/command/FlexCommand'; import { sendInfoCenterMessage } from '../../utils/info-center-message.js'; import { getError } from '../../utils/error.js'; import { PageDescriptorV4 } from './types.js'; import Input from 'sap/m/Input'; import { ValueState } from 'sap/ui/core/library'; import SimpleForm from 'sap/ui/layout/form'; import Control from 'sap/ui/core/Control'; import { getFragments } from '../api-handler.js'; export type AddFragmentModel = JSONModel & { getProperty(sPath: '/title'): string; getProperty(sPath: '/newFragmentName'): string; getProperty(sPath: '/isCustomColumnFragment'): boolean; }; export interface AddCustomFragmentOptions { title: string; propertyPath: string; appDescriptor?: PageDescriptorV4; validateId?: (id: string) => boolean; type: 'section' | 'tableColumn'; availability?: 'Default' | 'Adaptation' | 'Hidden'; } /** * Validates Control ID input. * * @param input control of control ID to validate * @param validateForDuplicateId custom validation function * @return validation result */ function validateControlId( input: Input, resource: TextBundle, identifier: 'Column' = 'Column', validateForDuplicateId?: (id: string) => boolean ): { isValid: boolean; errorMessage: string } { const id = input.getValue(); // Check if empty if (!id || id.trim().length === 0) { return { isValid: false, errorMessage: resource.getText('ID_REQUIRED', [identifier]) }; } if (typeof validateForDuplicateId === 'function' && !validateForDuplicateId?.(id)) { return { isValid: false, errorMessage: resource.getText('GIVEN_ID_ALREADY_EXISTS', [identifier, id]) }; } // Check if starts with number if (!/(^([A-Za-z_][-A-Za-z0-9_.:]*)$)/.test(id)) { return { isValid: false, errorMessage: resource.getText('ID_INVALID_FORMAT', [identifier]) }; } return { isValid: true, errorMessage: '' }; } /** * @namespace open.ux.preview.client.adp.controllers */ export default class AddCustomFragment extends BaseDialog { private bundle: TextBundle; constructor( name: string, overlays: UI5Element, rta: RuntimeAuthoring, readonly options: AddCustomFragmentOptions, telemetryData?: QuickActionTelemetryData ) { super(name, telemetryData); this.rta = rta; this.overlays = overlays; this.model = new JSONModel({ title: options.title }); this.commandExecutor = new CommandExecutor(this.rta); } /** * Setups the Dialog and the JSON Model * * @param {Dialog} dialog - Dialog instance */ async setup(dialog: Dialog): Promise { this.dialog = dialog; this.setEscapeHandler(); this.bundle = await getTextBundle(); await this.buildDialogData(); const resourceModel = await getResourceModel('open.ux.preview.client'); this.dialog.setModel(resourceModel, 'i18n'); this.dialog.setModel(this.model); this.dialog.open(); } /** * Handles create button press * * @param event Event */ async onCreateBtnPress(event: Event) { const source = event.getSource