import RuntimeAuthoring from 'sap/ui/rta/RuntimeAuthoring'; import { PageDescriptorV4 } from './types.js'; import UI5Element from 'sap/ui/core/Element'; import BaseDialog from './BaseDialog.controller.js'; import { QuickActionTelemetryData } from '../../cpe/quick-actions/quick-action-definition.js'; import JSONModel from 'sap/ui/model/json/JSONModel'; import Dialog from 'sap/m/Dialog'; import { getResourceModel, getTextBundle, TextBundle } from '../../i18n.js'; import { MessageBarType } from '@sap-ux-private/control-property-editor-common'; import Button from 'sap/m/Button'; import { sendInfoCenterMessage } from '../../utils/info-center-message.js'; import Input from 'sap/m/Input'; import CommandExecutor from '../command-executor.js'; import Event from 'sap/ui/base/Event'; import { getError } from '../../utils/error.js'; import { ValueState } from 'sap/ui/core/library'; import FlexCommand from 'sap/ui/rta/command/FlexCommand'; import SimpleForm from 'sap/ui/layout/form'; import Control from 'sap/ui/core/Control'; type AddActionFragmentsModel = JSONModel & { getProperty(sPath: '/title'): string; getProperty(sPath: '/buttonText'): string; getProperty(sPath: '/actionId'): string; getProperty(sPath: '/handlerReference'): string; getProperty(sPath: '/hasController'): boolean; }; export interface AddActionOptions { name: string; propertyPath: string; actionType: 'pageAction' | 'tableAction'; title: string; controllerReference: string; appDescriptor?: PageDescriptorV4; validateActionId?: (actionId: string) => boolean; position?: { placement: 'Before' | 'After'; anchor: string; }; } /** * Validates Action ID input. * * @param input control of action ID to validate * @param resource text bundle for messages * @param validateForDuplicateId custom validation function * @return validation result */ function validateActionId( input: Input, resource: TextBundle, validateForDuplicateId?: (actionId: string) => boolean ): { isValid: boolean; errorMessage: string } { const actionId = input.getValue(); // Check if empty if (!actionId || actionId.trim().length === 0) { return { isValid: false, errorMessage: resource.getText('ACTION_ID_REQUIRED') }; } if (typeof validateForDuplicateId === 'function' && !validateForDuplicateId(actionId)) { return { isValid: false, errorMessage: resource.getText('ACTION_WITH_GIVEN_ID_ALREADY_EXISTS', [actionId]) }; } // Check starts and only allowed characters if (!/(^([A-Za-z_][-A-Za-z0-9_.:]*)$)/.test(actionId)) { return { isValid: false, errorMessage: resource.getText('ID_INVALID_FORMAT', ['Action']) }; } return { isValid: true, errorMessage: '' }; } export default class AddActionFragment extends BaseDialog { private bundle: TextBundle; constructor( name: string, overlays: UI5Element, rta: RuntimeAuthoring, readonly options: AddActionOptions, 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